⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 d0bb3ece129e001c12aab15b3d982153

📁 源代码
💻
字号:
/**
 *  @author: Wangmin
 *  School: Computer School
 *  School: Sichuan School
 *  Date: 2007-11
 *  Filename:Employee.java
 **/

package staff.employee;

import staff.database.DBConnect;
import staff.util.*;
import java.sql.*;
import java.util.*;

public class Employee {

	public String EmployeeID, Name, Sex, Branch, NativePlace, 
		    Marriage, IdentityID, Politics, Folk, Education, School,
			Duty, Phone, MobilePhone, Address;

	public java.sql.Date Birthday, EntryTime;

	public Employee() {
	};

	public String getEmployeeID() {
		return EmployeeID;
	}

	public void setEmployeeID(String s) {
		this.EmployeeID = s;
	}

	public String getName() {
		return Name;
	}

	public void setName(String s) {
		this.Name = s;
	}

	public String getSex() {
		return Sex;
	}

	public void setSex(String s) {
		this.Sex = s;
	}

	public String getBranch() {
		return Branch;
	}

	public void setBranch(String s) {
		this.Branch = s;
	}

	public String getNativePlace() {
		return NativePlace;
	}

	public void setNativePlace(String s) {
		this.NativePlace = s;
	}

	public String getMarriage() {
		return Marriage;
	}

	public void setMarriage(String s) {
		this.Marriage = s;
	}

	public String getIdentityID() {
		return IdentityID;
	}

	public void setIdentityID(String s) {
		this.IdentityID = s;
	}

	public String getPolitics() {
		return Politics;
	}

	public void setPolitics(String s) {
		this.Politics = s;
	}

	public String getFolk() {
		return Folk;
	}

	public void setFolk(String s) {
		this.Folk = s;
	}

	public String getEducation() {
		return Education;
	}

	public void setEducation(String s) {
		this.Education = s;
	}

	public String getSchool() {
		return School;
	}

	public void setSchool(String s) {
		this.School = s;
	}

	public String getDuty() {
		return Duty;
	}

	public void setDuty(String s) {
		this.Duty = s;
	}

	public void setPhone(String s) {
		this.Phone = s;
	}

	public String getMobilePhone() {
		return MobilePhone;
	}

	public void setMobilePhone(String s) {
		this.MobilePhone = s;
	}

	public String getAddress() {
		return Address;
	}

	public void setAddress(String s) {
		this.Address = s;
	}

	public String getBirthday() {
		if (this.Birthday != null)
			return DataConvert.sqlDateToStr(Birthday);
		else
			return "";
	}

	public void setBirthday(String strBir) {
		if (strBir != null)
			this.Birthday = DataConvert.StrTosqlDate(strBir);
		else
			this.Birthday = null;
	}

	public String getEntryTime() {
		if (this.EntryTime != null)
			return DataConvert.sqlDateToStr(EntryTime);
		else
			return "";
	}

	public void setEntryTime(String strBir) {
		if (strBir != null)
			this.EntryTime = DataConvert.StrTosqlDate(strBir);
		else
			this.EntryTime = null;
	}

	/*
	 * Find Employee by ID
	 */
	public static Employee FindByID(String _EmployeeID) {
		DBConnect dbc = null;
		Employee employee = new Employee();
		try {
			dbc = new DBConnect();
			Connection conn =dbc.getDBConnection();
			Statement stmt = null;
			stmt=conn.createStatement();
			ResultSet rs = null;
			rs = stmt.executeQuery("SELECT * FROM employee WHERE EmployeeID = ?");
			
			if (rs.next()) {
				employee.setEmployeeID(rs.getString("EmployeeID"));
				employee.setName(rs.getString("Name"));
				employee.setSex(rs.getString("Sex"));
				employee.setBranch(rs.getString("Branch"));
				employee.setBirthday(rs.getString("Birthday"));
				employee.setNativePlace(rs.getString("NativePlace"));
				employee.setMarriage(rs.getString("Marriage"));
				employee.setIdentityID(rs.getString("IdentityID"));
				employee.setPolitics(rs.getString("Politics"));
				employee.setFolk(rs.getString("Folk"));
				employee.setEducation(rs.getString("Education"));
				employee.setEntryTime(rs.getString("EntryTime"));
				employee.setSchool(rs.getString("School"));
				employee.setDuty(rs.getString("Duty"));
				employee.setPhone(rs.getString("Phone"));
				employee.setMobilePhone(rs.getString("MobilePhone"));
				employee.setAddress(rs.getString("Address"));
			} else {
				employee = null;
			}
		} catch (Exception e) {
			System.err.println(e);
		} finally {
			try {
				dbc.close();
			} catch (Exception e) {
				e.printStackTrace();
				employee = null;
			}
		}
		return employee;

	}

	/*
	 * Add Employee
	 */
	public static String Add(String _EmployeeID, String _Name, String _Sex,
			String _Branch, String _NativePlace, String _Marriage,
			String _IdentityID, String _Politics, String _Folk,
			String _Education, String _School, String _Duty,
			String _Phone, String _MobilePhone,	String _Address,
		    String _Birthday, String _EntryTime) {
		DBConnect dbc = null;
		try {
			dbc = new DBConnect();
			Connection conn =dbc.getDBConnection();
			Statement stmt = null;
			stmt=conn.createStatement();
			
			stmt.executeUpdate("INSERT INTO employee (EmployeeID,Name,Sex,Branch,NativePlace,"
							+ "Marriage,IdentityID,Politics,Folk,Education,School,Duty,Phone,"
							+ "MobilePhone,Address,Birthday,EntryTime) VALUES "
							+ "(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");

			DataConvert.StrTosqlDate(_Birthday);
			DataConvert.StrTosqlDate(_EntryTime);
			System.out.println(DataConvert.StrTosqlDate(_Birthday));
			System.out.println(DataConvert.StrTosqlDate(_EntryTime));
			
			dbc.close();
			return "1";

		} catch (Exception e) {
			System.err.println(e);
			return e.toString();
		}

	}

	/*
	 * Modify Employee
	 */

	public static String Modify(String _EmployeeID, String _Name, String _Sex,
			String _Branch, String _NativePlace, String _Marriage,
			String _IdentityID, String _Politics, String _Folk,
			String _Education, String _School, String _Duty,
			String _Phone, String _MobilePhone,	String _Address,
		    String _Birthday, String _EntryTime) {
		DBConnect dbc = null;
		try {
			dbc = new DBConnect();
			Connection conn =dbc.getDBConnection();
			Statement stmt = null;
			stmt=conn.createStatement();
			
			stmt.executeUpdate("UPDATE Employee SET Name=?,Sex=?,Branch=?,NativePlace=?,"
							+ "Marriage=?,IdentityID=?,Politics=?,Folk=?,Education=?,School=?,"
							+ "Duty=?,Phone=?,MobilePhone=?,Address=?,Birthday=?, EntryTime=?"
							+ " WHERE EmployeeID=?");
			DataConvert.StrTosqlDate(_Birthday);
			DataConvert.StrTosqlDate(_EntryTime);
			
			dbc.close();
			return "1";
		} catch (Exception e) {
			e.printStackTrace();
			return e.toString();
		}
	}

	/*
	 * Delete Employee
	 */
	public static String Delete(String _EmployeeID) {
		try {
			DBConnect dbc = new DBConnect();
			dbc.prepareStatement("DELETE FROM employee WHERE EmployeeID=?");
			dbc.setString(1, _EmployeeID);
			dbc.executeUpdate();
			dbc.close();
			return "1";
		} catch (Exception e) {
			e.printStackTrace();
			return e.toString();
		}
	}

	/*
	 * the Employee exists?
	 */
	public static boolean IsExist(String _EmployeeID) throws Exception {
		DBConnect dbc = null;
		boolean IsExist = false;
		try {
			dbc = new DBConnect();
			dbc.prepareStatement("SELECT * FROM employee WHERE EmployeeID=?");
			dbc.setString(1, _EmployeeID);
			ResultSet rs = dbc.executeQuery();
			if (!rs.next()) {
				IsExist = false;
			} else {
				IsExist = true;
			}
		} catch (Exception e) {
			System.err.println(e);
		} finally {
			try {
				dbc.close();
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		return IsExist;
	}

	/*
	 * List All Employee
	 */
	public static Vector ListAll() {
		DBConnect dbc = null;
		Vector EmployeeVector = new Vector();

		String strSQL = "SELECT * FROM employee ORDER BY EmployeeID ASC";

		try {
			dbc = new DBConnect();
			dbc.prepareStatement(strSQL);
			ResultSet rs = dbc.executeQuery();
			while (rs.next()) {
				Employee employee = new Employee();
				employee.setEmployeeID(rs.getString("EmployeeID"));
				employee.setName(rs.getString("Name"));
				employee.setSex(rs.getString("Sex"));
				employee.setBranch(rs.getString("Branch"));
				employee.setBirthday(rs.getString("Birthday"));
				employee.setNativePlace(rs.getString("NativePlace"));
				employee.setMarriage(rs.getString("Marriage"));
				employee.setIdentityID(rs.getString("IdentityID"));
				employee.setPolitics(rs.getString("Politics"));
				employee.setFolk(rs.getString("Folk"));
				employee.setEducation(rs.getString("Education"));
				employee.setEntryTime(rs.getString("EntryTime"));
				employee.setSchool(rs.getString("School"));
				employee.setDuty(rs.getString("Duty"));
				employee.setPhone(rs.getString("Phone"));
				employee.setMobilePhone(rs.getString("MobilePhone"));
				employee.setAddress(rs.getString("Address"));
				EmployeeVector.add(employee);
			}
		} catch (Exception e) {
			System.err.println(e);
		} finally {
			try {
				dbc.close();
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		return EmployeeVector;

	}

	
	/*
	 * search Employee
	 */
	public static Vector Search(String _EmployeeID, String _Name, String _Sex,
			String _Branch, String _NativePlace, String _Marriage,
			String _Politics, String _Folk, String _Education,
			String _Duty) {
		DBConnect dbc = null;
		Vector EmployeeVector = new Vector();

		String strSQL = "SELECT * FROM employee WHERE";

		if ((_EmployeeID.equals("")) & (_Name.equals("")) & (_Sex.equals(""))
				& (_Branch.equals("")) & (_NativePlace.equals("")) & (_Marriage.equals("")) & (_Politics.equals(""))
				& (_Folk.equals("")) & (_Education.equals("")) & (_Duty.equals(""))) {
			strSQL = "SELECT * FROM employee ";
		} else {
			if (!_EmployeeID.equals(""))
				strSQL = strSQL + " EmployeeID LIKE '%" + _EmployeeID + "%' AND";
			if (!_Name.equals(""))
				strSQL = strSQL + " Name='" + _Name + "' AND";
			if (!_Sex.equals(""))
				strSQL = strSQL + " Sex='" + _Sex + "' AND";
			if (!_Branch.equals(""))
				strSQL = strSQL + " Branch='" + _Branch + "' AND";
			if (!_NativePlace.equals(""))
				strSQL = strSQL + " NativePlace LIKE '%" + _NativePlace + "%' AND";
			if (!_Marriage.equals(""))
				strSQL = strSQL + " Marriage='" + _Marriage + "' AND";
			if (!_Politics.equals(""))
				strSQL = strSQL + " Politics='" + _Politics + "' AND";
			if (!_Folk.equals(""))
				strSQL = strSQL + " Folk LIKE '%" + _Folk + "%' AND";
			if (!_Education.equals(""))
				strSQL = strSQL + " Education='" + _Education + "' AND";
			if (!_Duty.equals(""))
				strSQL = strSQL + " Duty='" + _Duty + "' AND";
			strSQL = strSQL + " 1=1 ";
		}

		strSQL = strSQL + "ORDER BY EmployeeID ASC";

		System.out.println(strSQL);

		try {
			dbc = new DBConnect();
			dbc.prepareStatement(strSQL);
			ResultSet rs = dbc.executeQuery();
			while (rs.next()) {
				Employee employee = new Employee();
				employee.setEmployeeID(rs.getString("EmployeeID"));
				employee.setName(rs.getString("Name"));
				employee.setSex(rs.getString("Sex"));
				employee.setBranch(rs.getString("Branch"));
				employee.setBirthday(rs.getString("Birthday"));
				employee.setNativePlace(rs.getString("NativePlace"));
				employee.setMarriage(rs.getString("Marriage"));
				employee.setIdentityID(rs.getString("IdentityID"));
				employee.setPolitics(rs.getString("Politics"));
				employee.setFolk(rs.getString("Folk"));
				employee.setEducation(rs.getString("Education"));
				employee.setEntryTime(rs.getString("EntryTime"));
				employee.setSchool(rs.getString("School"));
				employee.setDuty(rs.getString("Duty"));
				employee.setPhone(rs.getString("Phone"));
				employee.setMobilePhone(rs.getString("MobilePhone"));
				employee.setAddress(rs.getString("Address"));
				EmployeeVector.add(employee);
			}
		} catch (Exception e) {
			System.err.println(e);
		} finally {
			try {
				dbc.close();
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		return EmployeeVector;

	}

	/*
	 * Update Employee Duty
	 */
	public static String UpdateDuty(String _EmployeeID, String _Duty) {
		DBConnect dbc = null;
		try {
			dbc = new DBConnect();
			dbc.prepareStatement("UPDATE Employee SET Duty=? WHERE EmployeeID=?");
			dbc.setString(1, _Duty);			
			dbc.setString(2, _EmployeeID);
			dbc.executeUpdate();
			dbc.close();
			return "1";
		} catch (Exception e) {
			e.printStackTrace();
			return e.toString();
		}
	}

	/*
	 * Update Employee
	 */
	public static String UpdateBranch(String _EmployeeID, String _Branch) {
		DBConnect dbc = null;
		try {
			dbc = new DBConnect();
			dbc.prepareStatement("UPDATE Employee SET Branch=? WHERE EmployeeID=?");
			dbc.setString(1, _Branch);			
			dbc.setString(2, _EmployeeID);
			dbc.executeUpdate();
			dbc.close();
			return "1";
		} catch (Exception e) {
			e.printStackTrace();
			return e.toString();
		}
	}
	
	
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -