中小型超市综合信息管理系统-毕业设计(java源程序)_第1页
中小型超市综合信息管理系统-毕业设计(java源程序)_第2页
中小型超市综合信息管理系统-毕业设计(java源程序)_第3页
中小型超市综合信息管理系统-毕业设计(java源程序)_第4页
中小型超市综合信息管理系统-毕业设计(java源程序)_第5页
已阅读5页,还剩33页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、燕山大学本科生毕业设计(源程序)第1章 JavaBean部分1.1 数据库连接(DataBase.java)package common;import java.sql.*;import javax.naming.*;import javax.sql.*;import java.util.*;public class DataBase private String dbUrl = jdbc:microsoft:sqlserver:/localhost:1433;DatabaseName=ManagermentDB; private String dbUser = ren; private St

2、ring dbPwd = ren;/定义数据库的连接 public DataBase() throws Exception Class.forName(com.microsoft.jdbc.sqlserver.SQLServerDriver); /加载数据库的驱动 public Connection getConnection()throws Exception return java.sql.DriverManager.getConnection(dbUrl,dbUser,dbPwd); /建立数据库的连接 public void closeConnection(Connection con

3、) try if(con!=null) con.close(); catch(Exception e) e.printStackTrace(); public void closePrepStmt(PreparedStatement prepStmt) try if(prepStmt!=null) prepStmt.close(); catch(Exception e) e.printStackTrace(); public void closeResultSet(ResultSet rs)/关闭当前记录集 try if(rs!=null) rs.close(); catch(Exceptio

4、n e) e.printStackTrace(); public static void close( ResultSet rs, Statement st, Connection conn )/关闭数据库的连接tryif( rs!=null ) rs.close();catch( SQLException ex ) ;tryif( st!=null ) st.close();catch( SQLException ex ) ;tryif( conn!=null ) conn.close(); catch( SQLException ex ) ;1.2 人事管理部门1.2.1员工实体的定义(E

5、mployees.java)package employees;public class Employees implements Comparable private String EmpId; private String DepId; private String EmpName; private String Sex; private String Nationality; private String Birth; private String Academic; private String Marital; private String Original; private Str

6、ing Id_Card; private String Mobile; private String Memo;/员工实体的属性 Employees(String EmpId,String DepId,String EmpName ,String Sex, String Nationality,String Birth,String Academic,String Marital, String Original,String Id_Card,String Mobile,String Memo) /初始化操作 this.EmpId = EmpId; this.DepId = DepId; th

7、is.EmpName = EmpName; this.Sex = Sex; this.Nationality = Nationality; this.Birth = Birth; this.Academic = Academic ; this.Marital = Marital; this.Original = Original; this.Id_Card = Id_Card; this.Mobile = Mobile ; this.Memo = Memo; /对每一个属性赋值和取值操作 public void setEmpId(String newEmpId) this.EmpId = ne

8、wEmpId; public String getEmpId() return EmpId; public void setDepId(String newDepId) this.DepId = newDepId; public String getDepId() return DepId; public void setEmpName(String newEmpName) this.EmpName = newEmpName; public String getEmpName() return EmpName; public void setSex(String newSex) this.Se

9、x = newSex; public String getSex() return Sex; public void setNationality(String newNationality) this.Nationality = newNationality; public String getNationality() return Nationality; public void setBirth(String newBirth) this.Birth = newBirth; public String getBirth() return Birth; public void setAc

10、ademic(String newAcademic) this.Academic = newAcademic; public String getAcademic() return Academic; public void setMarital(String newMarital) this.Marital = newMarital; public String getMarital() return Marital; public void setOriginal(String newOriginal) this.Original = newOriginal; public String

11、getOriginal() return Original; public void setId_Card(String newId_Card) this.Id_Card = newId_Card; public String getId_Card() return Id_Card; public void setMobile(String newMobile) this.Mobile = newMobile; public String getMobile() return Mobile; public void setMemo(String newMemo) this.Memo = new

12、Memo; public String getMemo() return Memo; public int compareTo(Object o) Employees n = (Employees)o; int lastCmp = EmpNpareTo(n.EmpName); return(lastCmp); 1.2.2员工实体的操作(EmployeesBean.java)package employees;import java.sql.*;import java.util.*;import javax.naming.*;import javax.sql.*;import em

13、ployees.*;import common.*;public class EmployeesBean /得到员工的详细信息 public Employees getEmployeesDetails(String EmpId) throws Exception DataBase database = new DataBase();boolean result = false; Connection con = null; PreparedStatement prepStmt = null; ResultSet rs = null; try con = database.getConnecti

14、on(); String sql = select EmpId, DepId, EmpName , Sex, Nationality, Birth, Academic, Marital,Original, Id_Card, Mobile, Memo +from Employees where EmpId =?; prepStmt = con.prepareStatement(sql); prepStmt.setString(1,EmpId); rs = prepStmt.executeQuery(); if(rs.next() Employees employees = new Employe

15、es(rs.getString(1),rs.getString(2),rs.getString(3), rs.getString(4),rs.getString(5),rs.getString(6),rs.getString(7),rs.getString(8), rs.getString(9),rs.getString(10),rs.getString(11),rs.getString(12); prepStmt.close(); return employees; else return null; finally database.closeResultSet(rs); database

16、.closePrepStmt(prepStmt); database.closeConnection(con); /getEmployees()/得到所有员工的详细信息 public Collection getEmployees() throws Exception DataBase database = new DataBase();boolean result = false; Connection con = null; PreparedStatement prepStmt = null; ResultSet rs = null; Employees = new ArrayList()

17、; try con = database.getConnection(); String sql = select EmpId, DepId, EmpName , Sex, Nationality, Birth, Academic, Marital,Original, Id_Card, Mobile, Memo +from Employees ; prepStmt = con.prepareStatement(sql); rs = prepStmt.executeQuery(); while(rs.next() Employees bd = new Employees(rs.getString

18、(1),rs.getString(2),rs.getString(3), rs.getString(4),rs.getString(5),rs.getString(6),rs.getString(7),rs.getString(8), rs.getString(9),rs.getString(10),rs.getString(11),rs.getString(12); Employees.add(bd); finally database.closeResultSet(rs); database.closePrepStmt(prepStmt); database.closeConnection

19、(con); Collections.sort(Employees); return Employees; /nsertEmployees 插入员工的信息 public int InsertEmployees(String EmpId,String EmpName,String Sex,String Nationality,String Birth, String Academic,String Marital,String Original,String Id_Card, String Mobile,String Memo,String DepId) throws Exception Con

20、nection con = null; Statement Stmt = null; ResultSet rs=null; DataBase database = new DataBase(); int nResult = 0; try con = database.getConnection(); String sql = SELECT EmpId FROM Employees WHERE EmpId=+EmpId+; Stmt = con.createStatement(); rs = Stmt.executeQuery( sql ); if(rs.next() nResult=2; el

21、se sql=insert into Employees(EmpId,EmpName,Sex,Nationality,Birth,Academic,Marital,Original,Id_Card,Mobile,Memo,DepId)VALUES( +EmpId+,+EmpName+,+Sex+,+Nationality+,+Birth+,+Academic+,+Marital+, +Original+,+Id_Card+,+Mobile+,+Memo+,+DepId+); nResult = Stmt.executeUpdate(sql); sql= insert into Users(Us

22、erId,UserName,PassWords)values(+EmpId+,+EmpName+,+666666+); nResult = Stmt.executeUpdate(sql); return nResult; catch( SQLException ex ) ex.printStackTrace( System.err ); nResult=0; return nResult; finally database.close(null,Stmt,con); /删除一个员工的所有信息 public int deleteOneEmployees(String EmpId) throws

23、Exception boolean result = false; Connection con = null; Statement Stmt = null; ResultSet rs=null; DataBase database = new DataBase(); int nResult = 0; try con = database.getConnection(); String sql = SELECT EmpId FROM Employees WHERE EmpId=+EmpId+; Stmt = con.createStatement(); rs = Stmt.executeQue

24、ry( sql ); if(rs.next() sql=DELETE from Employees where EmpId=+EmpId+; nResult = Stmt.executeUpdate(sql); sql=DELETE from Users where UserId=+EmpId+; nResult = Stmt.executeUpdate(sql); else nResult=2; return nResult; catch( SQLException ex ) ex.printStackTrace( System.err ); nResult=0; return nResul

25、t; finally database.close(null,Stmt,con); / 修改员工的信息 public int updateEmployees(String EmpId,String EmpName,String Sex,String Nationality,String Birth, String Academic,String Marital,String Original,String Id_Card, String Mobile,String Memo,String DepId) throws Exception Connection con = null; Statem

26、ent Stmt = null; ResultSet rs=null; DataBase database = new DataBase(); int nResult = 0; try con = database.getConnection(); String sql = UPDATE Employees SET EmpId=+EmpId+,EmpName=+EmpName+, Sex= +Sex+,Nationality=+Nationality+,Birth=+Birth+,Academic=+Academic+, Marital= +Marital+,Original=+Origina

27、l+, Id_Card=+Id_Card+,Mobile=+Mobile+, Memo= +Memo+, DepId=+DepId+ WHERE EmpId=+EmpId+; Stmt = con.createStatement(); nResult = Stmt.executeUpdate(sql); sql= update Users set UserId=+EmpId+,UserName=+EmpName+ where UserId=+EmpId+; nResult = Stmt.executeUpdate(sql); return nResult; catch( SQLExceptio

28、n ex ) ex.printStackTrace( System.err ); nResult=0; return nResult; finally database.close(null,Stmt,con); 1.2.3部门实体的定义(departments.java)package departments;/* 部门类 */public class Departments private String DepId;/部门的编号 private String DepName;/部门的名称 Departments(String DepId,String DepName) /部门的初始化 th

29、is.DepId =DepId; this.DepName = DepName; public void setDepId(String newId) this.DepId = newId; public String getDepId() return DepId; public void setDepName(String newDepName) this.DepName = newDepName; public String getDepName() return DepName; 1.2.4部门实体的操作(DepartmentsBean.java)package departments

30、;import java.sql.*;import java.util.*;import javax.naming.*;import javax.sql.*;import common.*;public class DepartmentsBean/插入部门的信息 public int InsertDepartments(String DepId,String DepName) throws Exception boolean result = false; Connection con = null; Statement Stmt = null; ResultSet rs=null; Data

31、Base database = new DataBase(); int nResult = 0; try con = database.getConnection(); String sql = SELECT DepId FROM Departments WHERE DepId=+DepId+; Stmt = con.createStatement(); rs = Stmt.executeQuery( sql ); if(rs.next() nResult=2; else sql=insert into Departments(DepId,DepName)VALUES(+DepId+,+Dep

32、Name+); nResult = Stmt.executeUpdate(sql); if(nResult=1) nResult=1; return nResult; catch( SQLException ex ) ex.printStackTrace( System.err ); nResult=0; return nResult; finally database.close(null,Stmt,con); / 查询部门的信息public Vector queryDepartments()throws ExceptionVector vt = new Vector();Connectio

33、n conn = null;Statement st = null;ResultSet rs = null;DataBase database = new DataBase();tryconn = database.getConnection();st = conn.createStatement();String sql = SELECT DepId,DepName FROM Departments ;sql = sql + ORDER BY DepId ASC;rs = st.executeQuery( sql );while( rs.next() ) Departments Dep =

34、new Departments(rs.getString(1),rs.getString(2); vt.add(Dep);catch( SQLException ex )ex.printStackTrace( System.err );finallydatabase.close( rs, st, conn );return vt; /按照部门的编号进行查询某一个部门的详细信息 public Departments getDepartmentsDetails(String DepId) throws Exception Connection con=null; PreparedStatement

35、 prepStmt=null; DataBase database = new DataBase(); ResultSet rs =null; try con=database.getConnection(); String selectStatement = select * + from Departments where DepId = ? ; prepStmt = con.prepareStatement(selectStatement); prepStmt.setString(1, DepId); rs = prepStmt.executeQuery(); if (rs.next()

36、 Departments bd = new Departments(rs.getString(1), rs.getString(2); prepStmt.close(); return bd; else return null; finally database.closeResultSet(rs); database.closePrepStmt(prepStmt); database.closeConnection(con); /按照部门的编号进行修改某一个部门的详细信息 public int updateDepartments(String DepId,String DepName) th

37、rows Exception Connection con = null; Statement Stmt = null; ResultSet rs=null; DataBase database = new DataBase(); int nResult = 0; try con = database.getConnection(); String sql = Update Departments set DepId=+DepId+, DepName=+DepName + where DepId=+DepId+; Stmt = con.createStatement(); nResult =

38、Stmt.executeUpdate(sql); return nResult; catch( SQLException ex ) ex.printStackTrace( System.err ); nResult=0; return nResult; finally database.close(null,Stmt,con); /删除一个部门的所有信息 public int deleteOneDepartments(String DepId) throws Exception boolean result = false; Connection con = null; Statement S

39、tmt = null; ResultSet rs=null; DataBase database = new DataBase(); int nResult = 0; try con = database.getConnection(); String sql = SELECT DepId FROM Employees WHERE DepId=+DepId+; Stmt = con.createStatement(); rs = Stmt.executeQuery( sql ); if(rs.next() nResult=2; else sql=DELETE from Departments

40、where DepId=+DepId+; nResult = Stmt.executeUpdate(sql); return nResult; catch( SQLException ex ) ex.printStackTrace( System.err ); nResult=0; return nResult; finally database.close(null,Stmt,con); 1.2.5员工考勤实体的定义(Evaluation.java) package evaluation;public class Evaluation private String EvaId; privat

41、e String EmpId; private String EvaDate; private String Subject; private String Result; private String Score; private String Memo; Evaluation(String EvaId,String EmpId,String EvaDate ,String Subject, String Result,String Score,String Memo) this.EvaId = EvaId; this.EmpId = EmpId; this.EvaDate = EvaDate; this.Subject = Subject; this.Result = Result; this.Score = Score; this.Memo

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论