java开发的ERP

上传人:每**** 文档编号:57098242 上传时间:2022-02-23 格式:DOC 页数:56 大小:177.50KB
返回 下载 相关 举报
java开发的ERP_第1页
第1页 / 共56页
java开发的ERP_第2页
第2页 / 共56页
java开发的ERP_第3页
第3页 / 共56页
点击查看更多>>
资源描述
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 + id.intValue() + 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 + id.intValue() + 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 + id.intValue() + 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 getDepartmentById(int deptId) IDeptDAO deptDAO = DAOFactory.getIDemptDAOInstance();Department dept = null;try dept = deptDAO.findById(deptId); catch (Exception e1) e1.printStackTrace();return dept;private void showEmp(Employee emp) System.out.println();System.out.println(t );System.out.println(=);System.out.println(t: + emp.getEmpId();System.out.println(t: + emp.getEmpName();System.out.println(t: + emp.getEmpSex();IDeptDAO dao = DAOFactory.getIDemptDAOInstance();Department dept = null;try dept = dao.findById(emp.getDeptId(); catch (Exception e) e.printStackTrace();System.out.println(t: + dept.getDeptName();System.out.println(t: + emp.getPassport();System.out.println(t: + getFormatedNumber(emp.getSalary();System.out.println();private void showEmp(List emps) System.out.println();System.out.println(tttt);System.out.println();System.out.println(tttttttt);System.out.println(=);Map map = null;IDeptDAO deptDAO = DAOFactory.getIDemptDAOInstance();try map = deptDAO.getDepartmentMap(); catch (Exception e1) e1.printStackTrace();Iterator it = emps.iterator();while (it.hasNext() Employee emp = it.next();System.out.print(t + emp.getEmpId() + t);System.out.print(emp.getEmpName() + t);System.out.print(emp.getEmpSex() + t);System.out.print(map.get(emp.getDeptId().getDeptName() + t);System.out.print(emp.getPassport() + t);System.out.println(getFormatedNumber(emp.getSalary() + t);System.out.println();private String getFormatedNumber(double d)N
展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 图纸专区 > 成人自考


copyright@ 2023-2025  zhuangpeitu.com 装配图网版权所有   联系电话:18123376007

备案号:ICP2024067431-1 川公网安备51140202000466号


本站为文档C2C交易模式,即用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知装配图网,我们立即给予删除!