java开发的ERP_第1页
java开发的ERP_第2页
java开发的ERP_第3页
java开发的ERP_第4页
java开发的ERP_第5页
已阅读5页,还剩51页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、package com.ts017.zjh;import java.text.NumberFormat;import java.util.Iterator;import java.util.List;import java.util.Map;import java.util.Scanner;import com.ts017.zjh.dao.IDeptDAO;import com.ts017.zjh.dao.IEmpDAO;import com.ts017.zjh.dao.factory.DAOFactory;import com.ts017.zjh.vo.Department;import c

2、om.ts017.zjh.vo.Employee;public class DepartmentOperate private IDeptDAO dao = null;Scanner scn = null;public DepartmentOperate() this.dao = DAOFactory.getIDemptDAOInstance();scn = new Scanner(System.in);public void addDepartment() System.out.println();System.out.println( 添加部门信息);System.out.println(

3、=);System.out.print(请输入部门名称: );String deptName = scn.next();Department repeatDept = getDepartmentByName(deptName);if (repeatDept != null) System.out.println(您输入的部门名已存在);return;Department dept = new Department();dept.setDeptName(deptName);boolean flag = false;try flag = this.dao.doCreate(dept); catch

4、 (Exception e) e.printStackTrace();if (flag) System.out.println(添加部门成功); else System.out.println(添加部门失败);public void delDepartment() System.out.println();System.out.print(请输入要删除的部门编号: );int deptId = scn.nextInt();Department dept = getDepartmentById(deptId);if (dept = null) System.out.println(您输入的部门不

5、存在);return;IEmpDAO empDAO = DAOFactory.getIEmpDAOInstance();List emps = null;try emps = empDAO.findByDeptId(deptId); catch (Exception e) e.printStackTrace();if (emps != null) this.showDepartment(dept);if (emps.size() 0) System.out.println(该部门中有员工存在,若删除该部门,则相应的员工也会被删除,确定要删除吗(y/n)?);String opt = scn.n

6、ext();if (opt.equalsIgnoreCase(y) boolean flag = false;try empDAO.doDeleteByDeptId(deptId);flag = this.dao.doDelete(deptId); catch (Exception e) e.printStackTrace();if (flag) System.out.println(删除部门成功); else System.out.println(删除部门失败); else System.out.println(确定要删除该部门信息吗(y/n)?);String opt = scn.next

7、();if (opt.equalsIgnoreCase(y) boolean flag = false;try flag = this.dao.doDelete(deptId); catch (Exception e) e.printStackTrace();if (flag) System.out.println(删除部门成功); else System.out.println(删除部门失败);public void findAll() List depts = null;try depts = this.dao.findAll(); catch (Exception e) e.printS

8、tackTrace();if (depts != null & depts.size() != 0) this.showDepartment(depts); else System.out.println(没有部门信息);public void findDepartment() int opt;do this.showFindMenu();opt = scn.nextInt();switch (opt) case 1:this.findByDeptId();break;case 2:this.findByDeptname();break;case 0:return; while (opt !=

9、 0);public void findByDeptname() System.out.println();System.out.print(请输入查找的部门名称: );String deptName = scn.next();Department dept = getDepartmentByName(deptName);if (dept != null) this.showDepartment(dept); else System.out.println(相关信息不存在);public void findByDeptId() System.out.println();System.out.p

10、rint(请输入要查找的部门号: );int deptId = scn.nextInt();Department dept = getDepartmentById(deptId);if (dept != null) this.showDepartment(dept); else System.out.println(相关信息不存在);public void updateDepartment() System.out.println();System.out.print(请输入要更新的部门编号: );int deptId = scn.nextInt();Department dept = get

11、DepartmentById(deptId);if (dept = null) System.out.println(您输入的部门不存在);return;this.showDepartment(dept);System.out.println( 更新部门信息);System.out.println(=);System.out.print(请输入新的部门名称: );String deptName = scn.next();Department repeatDept = getDepartmentByName(deptName);while(repeatDept!=null)System.out.

12、println(您输入的部门名称已存在,请重新输入);deptName = scn.next();repeatDept = getDepartmentByName(deptName);Department newDept = new Department();newDept.setDeptId(deptId);newDept.setDeptName(deptName);boolean flag = false;try flag = this.dao.doUpdate(newDept); catch (Exception e) e.printStackTrace();if (flag) Syst

13、em.out.println(更新员工信息成功); else System.out.println(更新员工信息失败);public void showGroupAvgSalaryAboutDept() Map deptMap = null;Map avgSalary = null;try deptMap = this.dao.getDepartmentMap();avgSalary = this.dao.getAverageSalaryByGroup(); catch (Exception e) e.printStackTrace();System.out.println();System.

14、out.println(t 部门平均薪水);System.out.println();System.out.println(t部门编号t部门名称t平均薪水);System.out.println(=);Iterator it = avgSalary.keySet().iterator();NumberFormat format = NumberFormat.getInstance();format.setMaximumFractionDigits(1);while (it.hasNext() Integer id = it.next();System.out.println(t + id.in

15、tValue() + t+ deptMap.get(id).getDeptName() + t+ format.format(avgSalary.get(id);System.out.println();public void showEmpCountAboutDept() Map empCountMap = null;Map deptMap = null;try empCountMap = this.dao.getEmpCountByGroup();deptMap = this.dao.getDepartmentMap(); catch (Exception e) e.printStackT

16、race();System.out.println();System.out.println(t 部门员工信息);System.out.println();System.out.println(t编号t名称t人数);System.out.println(=);Iterator it = empCountMap.keySet().iterator();while (it.hasNext() Integer id = it.next();System.out.println(t + Value() + t+ deptMap.get(id).getDeptName() + t+ empC

17、ountMap.get(id);System.out.println();public void showTopAndLowSalaryAboutDept() Map topSalaryMap = null;Map lowSalaryMap = null;Map depts = null;try topSalaryMap = this.dao.getTopSalaryByGroup();lowSalaryMap = this.dao.getLowSalaryByGroup();depts = this.dao.getDepartmentMap(); catch (Exception e) e.

18、printStackTrace();System.out.println(tt部门最高薪水与最低薪水);System.out.println();System.out.println(t部门编号t部门名称t最高薪水t最低薪水);System.out.println(=);Iterator it = topSalaryMap.keySet().iterator();NumberFormat format = NumberFormat.getInstance();format.setMaximumFractionDigits(1);while (it.hasNext() Integer id =

19、it.next();System.out.println(t + Value() + t+ depts.get(id).getDeptName() + t+ format.format(topSalaryMap.get(id).floatValue() + t+ format.format(lowSalaryMap.get(id).floatValue();System.out.println();public void showDepartmentNoEmp() List depts = null;try depts = this.dao.getDepartmentWithout

20、Emp(); catch (Exception e) e.printStackTrace();System.out.println(t 员工数为零的部门);System.out.println();System.out.println(t部门编号t部门名称);System.out.println(=);Iterator it = depts.iterator();while (it.hasNext() Department dept = it.next();System.out.println(t + dept.getDeptId() + t+ dept.getDeptName();Syste

21、m.out.println();public void showDepartmentSummarize() int opt;do this.showSummarizeMenu();opt = scn.nextInt();switch (opt) case 1:this.showGroupAvgSalaryAboutDept();break;case 2:this.showEmpCountAboutDept();break;case 3:this.showTopAndLowSalaryAboutDept();break;case 4:this.showDepartmentNoEmp();brea

22、k;case 0:return;default:System.out.println(您的输入 有误); while (opt != 0);private Department getDepartmentById(int deptId) Department dept = null;try dept = this.dao.findById(deptId); catch (Exception e) e.printStackTrace();return dept;private Department getDepartmentByName(String deptName) Department r

23、epeatDept = null;try repeatDept = this.dao.findByName(deptName); catch (Exception e1) e1.printStackTrace();return repeatDept;private void showDepartment(Department dept) System.out.println();System.out.println(t 部门信息);System.out.println(=);System.out.println(t部门编号: + dept.getDeptId();System.out.prin

24、tln(t部门名称: + dept.getDeptName();System.out.println();private void showDepartment(List depts) System.out.println();System.out.println(t 部门信息);System.out.println();System.out.println(t编号t名称);System.out.println(=);Iterator it = depts.iterator();while (it.hasNext() Department dept = it.next();System.out

25、.println(t + dept.getDeptId() + t+ dept.getDeptName();System.out.println();private void showFindMenu() System.out.println();System.out.println(t 部门信息查询);System.out.println(=);System.out.println(t1. 按部门编号查询);System.out.println(t2. 按部门名称查询);System.out.println(t0. 退出查询);System.out.println();System.out.

26、print( 请选择: );private void showSummarizeMenu() System.out.println();System.out.println(t 查看部门汇总);System.out.println(=);System.out.println(t1. 查看部门平均薪水);System.out.println(t2. 查看部门员工数);System.out.println(t3. 查看部门最高最低工资);System.out.println(t4. 查看没有员工的部门);System.out.println(t0. 退出操作);System.out.println

27、();System.out.print( 请选择: );package com.ts017.zjh;import java.text.NumberFormat;import java.util.HashSet;import java.util.Iterator;import java.util.List;import java.util.Map;import java.util.Scanner;import java.util.Set;import com.ts017.zjh.dao.IDeptDAO;import com.ts017.zjh.dao.IEmpDAO;import com.ts

28、017.zjh.dao.factory.DAOFactory;import com.ts017.zjh.vo.Department;import com.ts017.zjh.vo.Employee;public class EmployeeOperate private IEmpDAO dao = null;Scanner scn = null;public EmployeeOperate() this.dao = DAOFactory.getIEmpDAOInstance();scn = new Scanner(System.in);public void addEmp() System.o

29、ut.println();System.out.println(t);System.out.println(=);Employee emp = inputNewEmpInfo();boolean flag = false;try flag = this.dao.doCreate(emp); catch (Exception e) e.printStackTrace();if (flag) System.out.println(); else System.out.println();public void updateEmp() System.out.println();System.out.

30、print(: );int empId = scn.nextInt();Employee emp = getEmployeeById(empId);if (emp = null) System.out.println();return;this.showEmp(emp);System.out.println(t);System.out.println(=);Employee newEmp = inputNewEmpInfo();newEmp.setEmpId(empId);boolean flag = false;try flag = this.dao.doUpdate(newEmp); ca

31、tch (Exception e) e.printStackTrace();if (flag) System.out.println(); else System.out.println();public void findEmp() int opt;do showFindMenu();opt = scn.nextInt();switch (opt) case 1:this.findByEmpId();break;case 2:this.findByEmpName();break;case 3:this.findBySex();break;case 4:this.findByDepartmen

32、t();break;case 5:this.findByPassport();break;case 0:return; while (opt != 0);public void findByPassport() System.out.println();System.out.print(: );String passport = scn.next();Employee emp = getEmployeeByPassport(passport);if (emp != null) this.showEmp(emp); else System.out.println();public void fi

33、ndByDepartment() System.out.println();int deptId = inputDepartmentId();Department dept = getDepartmentById(deptId);if (dept = null) System.out.println();return;List emps = null;try emps = this.dao.findByDeptId(deptId); catch (Exception e) e.printStackTrace();if (emps != null & emps.size() != 0) this

34、.showEmp(emps); else System.out.println();public void findBySex() System.out.println();System.out.print(: );String sex = scn.next();List emps = getEmployeesBySex(sex);if (emps != null & emps.size() != 0) this.showEmp(emps); else System.out.println();public void findByEmpName() System.out.println();S

35、ystem.out.print(: );String empName = scn.next();List emps = getEmployeesByName(empName);if (emps != null & emps.size() != 0) this.showEmp(emps); else System.out.println();public void findByEmpId() System.out.println();System.out.print(: );int empId = scn.nextInt();Employee emp = getEmployeeById(empI

36、d);if (emp != null) this.showEmp(emp); else System.out.println();public void findAll() List emps = null;try emps = this.dao.findAll(); catch (Exception e) e.printStackTrace();if (emps != null & emps.size() != 0) this.showEmp(emps); else System.out.println();public void deleteEmp() System.out.println

37、();System.out.print();int empId = scn.nextInt();Employee emp = getEmployeeById(empId);if (emp = null) System.out.println();return;this.showEmp(emp);System.out.print(y/n)? );String opt = scn.next();if (opt.equalsIgnoreCase(Y) boolean flag = false;try flag = this.dao.doDelete(empId); catch (Exception

38、e) e.printStackTrace();if (flag) System.out.println(); else System.out.println();private int inputDepartmentId() IDeptDAO deptDAO = DAOFactory.getIDemptDAOInstance();List depts = null;try depts = deptDAO.findAll(); catch (Exception e) e.printStackTrace();int deptId;boolean valid = false;Set empIds =

39、 new HashSet();do System.out.println();System.out.println(t);System.out.println(tt);System.out.println(=);Iterator it = depts.iterator();Department dept = null;while (it.hasNext() dept = it.next();empIds.add(dept.getDeptId();System.out.println(t + dept.getDeptId() + t+ dept.getDeptName();System.out.

40、print(: );deptId = scn.nextInt();valid = empIds.contains(deptId);if(!valid)System.out.println(); while (!valid);return deptId;private Employee inputNewEmpInfo() System.out.print(: );String empName = scn.next();System.out.print(: );String empSex = scn.next();System.out.print(: );int deptId = this.inp

41、utDepartmentId();System.out.print(: );String passport = scn.next();System.out.print(: );double salary = scn.nextDouble();Employee newEmp = new Employee();newEmp.setEmpName(empName);newEmp.setEmpSex(empSex);newEmp.setDeptId(deptId);newEmp.setPassport(passport);newEmp.setSalary(salary);return newEmp;p

42、rivate Employee getEmployeeById(int empId) Employee emp = null;try emp = this.dao.findById(empId); catch (Exception e) e.printStackTrace();return emp;private List getEmployeesByName(String empName) List emps = null;try emps = this.dao.findByName(empName); catch (Exception e) e.printStackTrace();retu

43、rn emps;private List getEmployeesBySex(String sex) List emps = null;try emps = this.dao.findBySex(sex); catch (Exception e) e.printStackTrace();return emps;private Employee getEmployeeByPassport(String passport) Employee emp = null;try emp = this.dao.findByPassport(passport); catch (Exception e) e.printStackTrace();return emp;private Department getDepartme

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论