毕业设计源程序中小型超市综合信息管理系统.docx
《毕业设计源程序中小型超市综合信息管理系统.docx》由会员分享,可在线阅读,更多相关《毕业设计源程序中小型超市综合信息管理系统.docx(44页珍藏版)》请在冰豆网上搜索。
毕业设计源程序中小型超市综合信息管理系统
第1章JavaBean部分
1.1数据库连接(DataBase.java)
packagecommon;
importjava.sql.*;
importjavax.naming.*;
importjavax.sql.*;
importjava.util.*;
publicclassDataBase{
privateStringdbUrl="jdbc:
microsoft:
sqlserver:
//localhost:
1433;DatabaseName=ManagermentDB";
privateStringdbUser="ren";
privateStringdbPwd="ren";//定义数据库的连接
publicDataBase()throwsException{
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
}//加载数据库的驱动
publicConnectiongetConnection()throwsException{
returnjava.sql.DriverManager.getConnection(dbUrl,dbUser,dbPwd);
}//建立数据库的连接
publicvoidcloseConnection(Connectioncon){
try{
if(con!
=null)con.close();
}catch(Exceptione){
e.printStackTrace();
}
}
publicvoidclosePrepStmt(PreparedStatementprepStmt){
try{
if(prepStmt!
=null)prepStmt.close();
}catch(Exceptione){
e.printStackTrace();
}
}
publicvoidcloseResultSet(ResultSetrs){//关闭当前记录集
try{
if(rs!
=null)rs.close();
}catch(Exceptione){
e.printStackTrace();
}
}
publicstaticvoidclose(ResultSetrs,Statementst,Connectionconn)//关闭数据库的连接
{
try
{
if(rs!
=null)rs.close();
}
catch(SQLExceptionex){};
try
{
if(st!
=null)st.close();
}
catch(SQLExceptionex){};
try
{
if(conn!
=null)conn.close();}
catch(SQLExceptionex){};
}
}
1.2人事管理部门
1.2.1员工实体的定义(Employees.java)
packageemployees;
publicclassEmployeesimplementsComparable{
privateStringEmpId;
privateStringDepId;
privateStringEmpName;
privateStringSex;
privateStringNationality;
privateStringBirth;
privateStringAcademic;
privateStringMarital;
privateStringOriginal;
privateStringId_Card;
privateStringMobile;
privateStringMemo;
//员工实体的属性
Employees(StringEmpId,StringDepId,StringEmpName,StringSex,
StringNationality,StringBirth,StringAcademic,StringMarital,
StringOriginal,StringId_Card,StringMobile,StringMemo){//初始化操作
this.EmpId=EmpId;
this.DepId=DepId;
this.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;
}
//对每一个属性赋值和取值操作
publicvoidsetEmpId(StringnewEmpId){
this.EmpId=newEmpId;
}
publicStringgetEmpId(){
returnEmpId;
}
publicvoidsetDepId(StringnewDepId){
this.DepId=newDepId;
}
publicStringgetDepId(){
returnDepId;
}
publicvoidsetEmpName(StringnewEmpName){
this.EmpName=newEmpName;
}
publicStringgetEmpName(){
returnEmpName;
}
publicvoidsetSex(StringnewSex){
this.Sex=newSex;
}
publicStringgetSex(){
returnSex;
}
publicvoidsetNationality(StringnewNationality){
this.Nationality=newNationality;
}
publicStringgetNationality(){
returnNationality;
}
publicvoidsetBirth(StringnewBirth){
this.Birth=newBirth;
}
publicStringgetBirth(){
returnBirth;
}
publicvoidsetAcademic(StringnewAcademic){
this.Academic=newAcademic;
}
publicStringgetAcademic(){
returnAcademic;
}
publicvoidsetMarital(StringnewMarital){
this.Marital=newMarital;
}
publicStringgetMarital(){
returnMarital;
}
publicvoidsetOriginal(StringnewOriginal){
this.Original=newOriginal;
}
publicStringgetOriginal(){
returnOriginal;
}
publicvoidsetId_Card(StringnewId_Card){
this.Id_Card=newId_Card;
}
publicStringgetId_Card(){
returnId_Card;
}
publicvoidsetMobile(StringnewMobile){
this.Mobile=newMobile;
}
publicStringgetMobile(){
returnMobile;
}
publicvoidsetMemo(StringnewMemo){
this.Memo=newMemo;
}
publicStringgetMemo(){
returnMemo;
}
publicintcompareTo(Objecto){
Employeesn=(Employees)o;
intlastCmp=EmpNpareTo(n.EmpName);
return(lastCmp);
}
}
1.2.2员工实体的操作(EmployeesBean.java)
packageemployees;
importjava.sql.*;
importjava.util.*;
importjavax.naming.*;
importjavax.sql.*;
importemployees.*;
importcommon.*;
publicclassEmployeesBean{
////-----得到员工的详细信息-------
publicEmployeesgetEmployeesDetails(StringEmpId)throwsException{
DataBasedatabase=newDataBase();
booleanresult=false;
Connectioncon=null;
PreparedStatementprepStmt=null;
ResultSetrs=null;
try{
con=database.getConnection();
Stringsql="selectEmpId,DepId,EmpName,Sex,Nationality,Birth,Academic,Marital,Original,Id_Card,Mobile,Memo"+"fromEmployeeswhereEmpId=?
";
prepStmt=con.prepareStatement(sql);
prepStmt.setString(1,EmpId);
rs=prepStmt.executeQuery();
if(rs.next()){
Employeesemployees=newEmployees(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();
returnemployees;
}
else{
returnnull;
}
}
finally{
database.closeResultSet(rs);
database.closePrepStmt(prepStmt);
database.closeConnection(con);
}
}
////-------getEmployees()//得到所有员工的详细信息---
publicCollectiongetEmployees()throwsException{
DataBasedatabase=newDataBase();
booleanresult=false;
Connectioncon=null;
PreparedStatementprepStmt=null;
ResultSetrs=null;
Employees=newArrayList();
try{
con=database.getConnection();
Stringsql="selectEmpId,DepId,EmpName,Sex,Nationality,Birth,Academic,Marital,Original,Id_Card,Mobile,Memo"+"fromEmployees";
prepStmt=con.prepareStatement(sql);
rs=prepStmt.executeQuery();
while(rs.next()){
Employeesbd=newEmployees(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));
Employees.add(bd);
}
}
finally{
database.closeResultSet(rs);
database.closePrepStmt(prepStmt);
database.closeConnection(con);
}
Collections.sort(Employees);
returnEmployees;
}
/////nsertEmployees插入员工的信息
publicintInsertEmployees(StringEmpId,StringEmpName,StringSex,StringNationality,StringBirth,
StringAcademic,StringMarital,StringOriginal,StringId_Card,
StringMobile,StringMemo,StringDepId)throwsException
{
Connectioncon=null;
StatementStmt=null;
ResultSetrs=null;
DataBasedatabase=newDataBase();
intnResult=0;
try{
con=database.getConnection();
Stringsql="SELECTEmpIdFROMEmployeesWHEREEmpId='"+EmpId+"'";
Stmt=con.createStatement();
rs=Stmt.executeQuery(sql);
if(rs.next())
{
nResult=2;
}
else
{
sql="insertintoEmployees(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="insertintoUsers(UserId,UserName,PassWords)values('"+EmpId+"','"+EmpName+"','"+666666+"')";
nResult=Stmt.executeUpdate(sql);
}
returnnResult;
}
catch(SQLExceptionex)
{
ex.printStackTrace(System.err);
nResult=0;
returnnResult;
}
finally{
database.close(null,Stmt,con);
}
}
//删除一个员工的所有信息
publicintdeleteOneEmployees(StringEmpId)throwsException
{
booleanresult=false;
Connectioncon=null;
StatementStmt=null;
ResultSetrs=null;
DataBasedatabase=newDataBase();
intnResult=0;
try{
con=database.getConnection();
Stringsql="SELECTEmpIdFROMEmployeesWHEREEmpId='"+EmpId+"'";
Stmt=con.createStatement();
rs=Stmt.executeQuery(sql);
if(rs.next())
{
sql="DELETEfromEmployeeswhereEmpId='"+EmpId+"'";
nResult=Stmt.executeUpdate(sql);
sql="DELETEfromUserswhereUserId='"+EmpId+"'";
nResult=Stmt.executeUpdate(sql);
}
else
{
nResult=2;
}
returnnResult;
}
catch(SQLExceptionex)
{
ex.printStackTrace(System.err);
nResult=0;
returnnResult;
}
finally{
database.close(null,Stmt,con);
}
}
//修改员工的信息
publicintupdateEmployees(StringEmpId,StringEmpName,StringSex,StringNationality,StringBirth,
StringAcademic,StringMarital,StringOriginal,StringId_Card,
StringMobile,StringMemo,StringDepId)throwsException
{
Connectioncon=null;
StatementStmt=null;
ResultSetrs=null;
DataBasedatabase=newDataBase();
intnResult=0;
try{
con=database.getConnection();
Stringsql="UPDATEEmployeesSETEmpId='"+EmpId+"',EmpName='"+EmpName+"',Sex='"
+Sex+"',Nationality='"+Nationality+"',Birth='"+Birth+"',Academic='"+Academic+"',Marital='"
+Marital+"',Original='"+Original+"',Id_Card='"+Id_Card+"',Mobile='"+Mobile+"',Memo='"
+Memo+"',DepId='"+DepId+"'WHEREEmpId='"+EmpId+"'";
Stmt=con.createStatement();
nResult=Stmt.executeUpdate(sql);
sql="updateUserssetUserId='"+EmpId+"',UserName='"+EmpName+"'whereUserId='"+EmpId+"'";
nResult=Stmt.executeUpdate(sql);
returnnResult;
}
catch(SQLExceptionex)
{
ex.printStackTrace(System.err);
nResult=0;
returnnResult;
}
finally
{
database.close(null,Stmt,con);
}
}
}
1.2.3部门实体的定义(departments.java)
packagedepartments;
/***部门类*/
publicclassDepartments{
privateStringDepId;//部门的编号
privateStringDepName;//部门的名称
Departments(StringDepId,StringDepName)
{//部门的初始化
this.DepId=DepId;
this.DepName=DepName;
}
publicvoidsetDepId(StringnewId){
this.DepId=newId;
}
publicStringgetDepId(){
returnDepId;
}
publicvoidsetDepName(StringnewDepName){
this.DepName=newDepName;
}