




已阅读5页,还剩51页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
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 com.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(=);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 (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(您输入的部门不存在);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.next();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();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.printStackTrace();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 != 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.print(请输入要查找的部门号: );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 = getDepartmentById(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.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) System.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.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 + Value() + 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.printStackTrace();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+ empCountMap.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.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 = 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.getDepartmentWithoutEmp(); 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();System.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();break;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 repeatDept = 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.println(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.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.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();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.ts017.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.out.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.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); catch (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.findByDepartment();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 findByDepartment() 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.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();System.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(empId);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();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 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 = 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.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.inputDepartmentId();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;private 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();return 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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 【正版授权】 IEC 60068-2-1:2007 EN-D Environmental testing - Part 2-1: Tests - Test A: Cold
- 农村人才引进与培养合作框架协议
- 高中物理实验技能强化课
- 合作开发技术合同协议书要求
- 农村用地规划利用与管理协议
- 法律职业资格考试大纲卷样题集
- 银行历史考试试题及答案
- 仪器qc考试试题及答案
- 六一儿童公开课活动方案
- 六一公司食堂活动方案
- 【上料机械手结构中的真空系统的设计计算案例1100字】
- 西方美术史试题及答案
- 七年级数学下学期期末测试卷(1)(学生版+解析)-2025年七年级数学下学期期末总复习(北师大版)
- 校园短剧创作与演出指导行业跨境出海项目商业计划书
- 2025年北京丰台区九年级中考二模英语试卷试题(含答案详解)
- 【7历期末】安徽省合肥市包河区2023-2024学年部编版七年级下学期期末历史试卷
- 新生儿收治流程规范与实施
- T/CBMCA 017-2021建筑用覆膜钢板
- 《重症监护病房的临终关怀和姑息治疗指南》解读
- 2025年初中地理会考试卷
- 中国钛基复合材料行业市场前景预测及投资价值评估分析报告
评论
0/150
提交评论