今天学的东西很多,数据多层次的运用连接java编译器:
数据表示层:
package com.lifeng.test;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Scanner;
import com.lifeng.dao.Dao;
import com.lifeng.dao.EmpDao;
import com.lifeng.dao.EmpDao02;
import com.lifeng.dao.EmpDao03;
import com.lifeng.dao.EmpDao04;
import com.lifeng.entity.Employee;
import com.lifeng.entity.User;
public class TestEmpDao {
public static void main(String[] args) {
//ShowAllEmp();
//SelectSingleEmp();
UserLogin();
//AddEmp();}
static EmpDao03 empDao03 = new EmpDao03();
private static void AddEmp() {
try {
Employee emp = new Employee();
Scanner input = new Scanner(System.in);
System.out.print("请输入员工编号:");
int empno=input.nextInt();
System.out.print("请输入员工姓名:");
String ename=input.next();
System.out.print("请输入员工 职位:");
String job=input.next();
System.out.print("请输入上司编号:");
int mgr=input.nextInt();
System.out.print("请输入入职日期(yyyy-MM-dd):");
String date=input.next();
SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
Date hiredate = sdf.parse(date);
System.out.print("请输入基本工资:");
double sal=input.nextDouble();
System.out.print("请输入奖金:");
double comm=input.nextDouble();
System.out.print("请输入部门编号(10,20,30):");
int deptno=input.nextInt();
emp.setEmpno(empno);
emp.setEname(ename);
emp.setJob(job);
emp.setMgr(mgr);
emp.setHiredate(hiredate);
emp.setSal(sal);
emp.setComm(comm);
emp.setDeptno(deptno);
int count = empDao03.addEmp(emp);
if(count > 0) {
System.out.println("员工添加成功!");
System.out.println("如需返回系统界面请按0");
int sc = input.nextInt();
if(sc == 0) {
UserWelcome();
}else {
System.out.println("系统已为你返回界面");
UserWelcome();}
}else {
System.out.println("员工添加错失败!");}
} catch (Exception e) {
e.printStackTrace();}}
static Dao dao = new Dao();
private static void UserLogin() {
Scanner input = new Scanner(System.in);
System.out.println("请输入用户名:");
String username = input.next();
System.out.println("请输入用户密码:");
String pwd = input.next();
User user = dao.FindUserByNamePwd(username, pwd);
if(user != null) {
System.out.println("登陆成功");
UserWelcome();}else {
System.out.println("登陆失败");}}
static EmpDao04 empDao04 = new EmpDao04();
public static void UserWelcome() {
System.out.println("=========员工管理系统项目=========");
System.out.println("请选择操作:");
System.out.println("1.查询所有员工");
System.out.println("2.查询单个员工");
System.out.println("3.添加员工");
System.out.println("4.删除员工");
System.out.println("5.修改员工");
Scanner sc = new Scanner(System.in);
int input = sc.nextInt();
switch(input) {
case 1:
ShowAllEmp();//查询所有员工
break;
case 2:
SelectSingleEmp();//查询单个员工
break;
case 3:
AddEmp();//添加员工
break;