企业员工管理系统 五:控制层

参考资料:

项目介绍
工具类
实体类
服务层
控制层
UI层

controller

DeptController.java

public class DeptController {
	private DeptService deptService = new DeptServiceImpl();

	public void deleteDept(Scanner scanner) throws IOException {
		System.out.println("请输入待删除的部门的编号:");
		int deptno = scanner.nextInt();
		boolean res = deptService.deleteDeptByDeptno(deptno);
		String tip = res ? "删除成功" : "删除失败";
		System.out.println(tip);
	}

	public void updateDept(Scanner scanner) throws IOException {
		System.out.println("请输入待修改的部门的编号:");
		int deptno = scanner.nextInt();
		System.out.println("请输入待修改的部门的名称:");
		String dname = scanner.next();
		System.out.println("请输入待修改的部门的地址:");
		String loc = scanner.next();
		Dept dept = new Dept(deptno, dname, loc);

		boolean res = deptService.updateDept(dept);
		String tip = res ? "修改成功" : "添加成功";
		System.out.println(tip);
	}

	public void addDept(Scanner scanner) throws IOException {
		System.out.println("请输入待增加的部门的名称:");
		String dname = scanner.next();
		System.out.println("请输入待增加的部门的地址:");
		String loc = scanner.next();
		int deptno = new Random().nextInt(9000) + 1000;
		Dept dept = new Dept(deptno, dname, loc);

		boolean res = deptService.addDept(dept);
		String tip = res ? "添加成功" : "添加失败";
		System.out.println(tip);
	}

	public void listDeptByDname(Scanner scanner) throws IOException {
		System.out.println("请输入待查找的部门的名称:");
		String dname = scanner.next();
		Dept dept = deptService.getDeptByDname(dname);
		System.out.println(dept);
	}

	public void listDeptByDeptno(Scanner scanner) throws IOException {
		System.out.println("请输入待查找的部门的编号:");
		int deptno = scanner.nextInt();
		Dept dept = deptService.getDeptByDeptno(deptno);
		System.out.println(dept);
	}

	public void listAllDept() throws IOException {
		List<Dept> allDept = deptService.getAllDept();
		for (Dept dept : allDept) {
			System.out.println(dept);
		}
	}
}

EmpController.java

public class EmpController {
	private EmpService empService = new EmpServiceImpl();

	public void listAllEmp() throws IOException {
		List<Emp> empList = empService.getAllEmp();
		for(Emp emp : empList) {
			System.out.println(emp);
		}
	}

	public void getEmpByEmpno(Scanner scanner) throws IOException {
		System.out.println("请输入待查找的员工的编号:");
		int empno = scanner.nextInt();
		Emp emp = empService.getEmpByEmpno(empno);
		System.out.println(emp);
	}

	public void getEmpByEname(Scanner scanner) throws IOException {
		System.out.println("请输入待查找的员工的名称:");
		String ename = scanner.next();
		Emp emp = empService.getEmpByEname(ename);
		System.out.println(emp);
	}

	public void getEmpByDeptno(Scanner scanner) throws IOException {
		System.out.println("请输入待查找的员工的部门编号:");
		int deptno = scanner.nextInt();
		List<Emp> empList = empService.getEmpByDeptno(deptno);
		for(Emp emp : empList) {
			System.out.println(emp);
		}
	}

	public void addEmp(Scanner scanner) throws IOException {
		int empno = new Random().nextInt(1000)+9000;
		System.out.println("请输入待添加的员工的名称:");
		String ename = scanner.next();
		System.out.println("请输入待添加的员工的工作:");
		String job = scanner.next();
		
		System.out.println("请输入待添加的员工的入职日期,格式:yyyy-MM-dd:");
		String hiredateStr = scanner.next();
		String[] split = hiredateStr.split("-");
		LocalDate hiredate = LocalDate.of(Integer.parseInt(split[0]), Integer.parseInt(split[1]), Integer.parseInt(split[2]));
		
		System.out.println("请输入待添加的员工的领导编号:");
		int mgr = scanner.nextInt();
		System.out.println("请输入待添加的员工的工资:");
		double sal = scanner.nextDouble();
		System.out.println("请输入待添加的员工的奖金:");
		double comm = scanner.nextDouble();
		System.out.println("请输入待添加的员工的部门编号:");
		int deptno = scanner.nextInt();
		
		Emp emp = new Emp(empno, ename, job, mgr, hiredate, sal, comm, deptno);
		
		boolean flag = empService.addEmp(emp);
		String res  = flag?"添加成功":"添加失败";
		System.out.println(res);
	}

	public void updateEmp(Scanner scanner) throws IOException {
		int empno = new Random().nextInt(1000)+9000;
		System.out.println("请输入待添加的员工的名称:");
		String ename = scanner.next();
		System.out.println("请输入待添加的员工的工作:");
		String job = scanner.next();
		
		System.out.println("请输入待添加的员工的入职日期,格式:yyyy-MM-dd:");
		String hiredateStr = scanner.next();
		String[] split = hiredateStr.split("-");
		LocalDate hiredate = LocalDate.of(Integer.parseInt(split[0]), Integer.parseInt(split[1]), Integer.parseInt(split[2]));
		
		System.out.println("请输入待添加的员工的领导编号:");
		int mgr = scanner.nextInt();
		System.out.println("请输入待添加的员工的工资:");
		double sal = scanner.nextDouble();
		System.out.println("请输入待添加的员工的奖金:");
		double comm = scanner.nextDouble();
		System.out.println("请输入待添加的员工的部门编号:");
		int deptno = scanner.nextInt();
		
		Emp emp = new Emp(empno, ename, job, mgr, hiredate, sal, comm, deptno);
		boolean flag = empService.updateEmp(emp);
		String res = flag?"修改成功":"添加成功";
		System.out.println(res);
	}

	public void deletEmpByEmpno(Scanner scanner) throws IOException {
		System.out.println("请输入待删除的员工的编号:");
		int empno = scanner.nextInt();
		boolean flag = empService.deleteEmpByEmpno(empno);
		String res = flag?"删除成功":"删除失败";
		System.out.println(res);
	}

}

ManagerController.java

public class ManagerController {
	private ManagerService managerService = new ManagerServiceImpl();

	public boolean login(Scanner scanner) {
		System.out.println("请输入用户名:");
		String name = scanner.next();
		System.out.println("请输入用密码:");
		String password = scanner.next();
		boolean res = managerService.login(name, password);
		return res;
	}
}
发布了253 篇原创文章 · 获赞 666 · 访问量 5万+

猜你喜欢

转载自blog.csdn.net/lianghecai52171314/article/details/103909729
今日推荐