这个系统包含了四块,第一块就是人员管理,经理分配三位分别有“ABC"权限的人,分别管理请假申请,请假审批,门卫登记管理。同时不属于本公司的内部人员,如别的公司的人员如果想到本公司访问,也是先通过这”ABC“权限的三个人代为写来访申请,来访审批,来访门卫登记管理。
具体步骤如下:
因为后面都会用到很多相同的方法,和相同的属性,所以我先建立了两个接口让后面的方法类和属性类都实现这两个接口,这样就降低了耦合度。
属性接口:
package com.jereh.discrepancy; public interface Attribute { }
方法类接口:
package com.jereh.discrepancy; public interface Father { public abstract boolean add(Attribute at); public abstract boolean update(int num); public abstract boolean updateJu(int num); public abstract boolean delete(int num); public abstract void show(); public abstract void read(); public abstract void write(); }
首先确定人员管理:赋予ABC三个等级权利,互不干涉,各自执行各自功能。
1.建立人员管理的属性类:
<span style="font-size:18px;">public class Employeer implements java.io.Serializable{ private String name; private String emp_no; private String pwd; private String lev; public Employeer(String name, String empNo, String pwd, String lev) { super(); this.name = name; this.emp_no = empNo; this.pwd = pwd; this.lev = lev; } public Employeer() { } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getEmp_no() { return emp_no; } public void setEmp_no(String empNo) { emp_no = empNo; } public String getPwd() { return pwd; } public void setPwd(String pwd) { this.pwd = pwd; } public String getLev() { return lev; } public void setLev(String lev) { this.lev = lev; } }</span>
2.人员管理的方法类:方法后面都有介绍介绍方法的用途
<span style="font-size:18px;">package com.jereh.discrepancy; import java.io.*; import java.util.*; public class EmployeerBiz { static List<Employeer> list = new ArrayList<Employeer>(); Employeer emp = new Employeer(); public void as(){ list.add(new Employeer("李忠峰","1001","1314","A")); list.add(new Employeer("李四","1002","1314","B")); list.add(new Employeer("管理员","admin","admin","T")); list.add(new Employeer("刘冰","1003","1314","C")); writeDb(); } public boolean addEmp(Employeer em){ //添加信息,并判断编号是否重复 readDb(); for(int i =0; i<list.size();i++){ emp = (Employeer)list.get(i); if(em.getEmp_no().equals(emp.getEmp_no())){ return false; } } list.add(em); writeDb(); return true; } public boolean deleteEmp(String name){ //删除员工的所有信息,找到删除返回true,找不到返回 readDb(); for(int i =0; i<list.size();i++){ emp = (Employeer)list.get(i); if(emp.getName().equals(name)){ list.remove(i); writeDb(); return true; } } return false; } public boolean updata(String name){ //判断是否有此人 readDb(); for(int i = 0; i<list.size();i++){ emp = (Employeer)list.get(i); if(emp.getName().equals(name)){ return true; } } return false; } public Employeer updataDb(String name,String emp_no,String pwd,String lev){ //修改此人信息 readDb(); for(int i = 0; i<list.size();i++){ emp = (Employeer)list.get(i); if(emp.getName().equals(name)){ emp.setEmp_no(emp_no); emp.setLev(lev); emp.setPwd(pwd); writeDb(); return emp; } } return null; } public void showDb(){ //展示录入的员工信息 包括:编号,名字密码等级 readDb(); for(int i =0;i<list.size();i++){ emp = (Employeer)list.get(i); System.out.println("\t"+emp.getName()+"\t\t"+emp.getEmp_no()+ "\t\t"+emp.getPwd()+"\t\t"+emp.getLev()); } } public Employeer deng(String no,String pwd){ //登录方法,返回权限,根据权限判断进入哪个界面 readDb(); for(int i =0;i<list.size();i++){ emp = (Employeer)list.get(i); if(emp.getEmp_no().equals(no)&&emp.getPwd().equals(pwd)){ return emp; } } return null; } public void readDb(){ //读取123.txt中的文件 ObjectInputStream ois = null; FileInputStream fis = null; File file = new File("E:\\h\\123\\employeer.txt"); try { fis = new FileInputStream(file); ois = new ObjectInputStream(fis); list = (List)ois.readObject(); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (ClassNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); }finally{ try { ois.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } public void writeDb(){ //写入123.txt文件中数据 ObjectOutputStream oos = null; FileOutputStream fos = null; File file = new File("E:\\h\\123\\employeer.txt"); try { if(!file.exists()){ fos = new FileOutputStream(file); oos = new ObjectOutputStream(fos); oos.writeObject(list); }else{ file.createNewFile(); fos = new FileOutputStream(file); oos = new ObjectOutputStream(fos); oos.writeObject(list); } } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); }finally{ try { oos.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } }</span>
<span style="font-size:18px;">package com.jereh.discrepancy; import java.util.*; public class EmployeerView { Scanner input = new Scanner(System.in); EmployeerBiz ebiz = new EmployeerBiz(); Employeer emp = new Employeer(); String name; String num; String pwd; String lev; public void addView() { System.out.print("请输入员工姓名:"); name = input.next(); System.out.print("请输入员工工号:"); num = input.next(); System.out.print("请输入员工密码:"); pwd = input.next(); System.out.print("请输入员工权限:"); lev = input.next(); emp.setEmp_no(num); emp.setLev(lev); emp.setName(name); emp.setPwd(pwd); if(ebiz.addEmp(emp)){ System.out.println("录入成功!"); }else System.out.println("录入失败,该编号已经存在"); } public void updataView() { System.out.println("请输入您要修改的员工姓名:"); name = input.next(); if (ebiz.updata(name)) { System.out.print("请输入员工工号:"); num = input.next(); System.out.print("请输入员工密码:"); pwd = input.next(); System.out.print("请输入员工权限:"); lev = input.next(); emp = ebiz.updataDb(name,num, pwd, lev); System.out.println("修改成功!"); System.out.println("*****************************************************"); System.out.println("\t员工姓名\t\t员工编号\t\t员工密码\t\t员工权限"); System.out.println("\t" + emp.getName() + "\t\t" + emp.getEmp_no() + "\t\t" + emp.getPwd() + "\t\t" + emp.getLev()); System.out.println("*****************************************************"); } else { System.out.println("没找到您要修改的员工!"); } } public void deleteView() { System.out.println("请输入您要删除的员工姓名:"); name = input.next(); if (ebiz.deleteEmp(name)) { System.out.println("删除成功"); } else { System.out.println("没找到您要删除的员工!"); } } public void showView() { System.out.println("*****************************************************"); System.out.println("\t员工姓名\t\t员工编号\t\t员工密码\t\t员工权限"); ebiz.showDb(); System.out.println("*****************************************************"); } public void main(){ EmployeerView ev = new EmployeerView(); while(true){ System.out.println("============员工信息============="); System.out.println("\t\t1.信息录入"); System.out.println("\t\t2.信息修改"); System.out.println("\t\t3.信息删除"); System.out.println("\t\t4.信息查询"); System.out.println("\t\t5.退出"); System.out.println("================================="); System.out.print("请选择您要进行的操作:"); int i = input.nextInt(); switch(i){ case 1: ev.addView(); break; case 2: ev.updataView(); break; case 3: ev.deleteView(); break; case 4: ev.showView(); break; case 5: System.exit(0); System.out.println("退出成功!"); break; } } } } </span>
版权声明:本文为博主原创文章,未经博主允许不得转载。
原文地址:http://blog.csdn.net/j_a_v_a_guan/article/details/48046127