java课程设计职工工资管理系统.docx
《java课程设计职工工资管理系统.docx》由会员分享,可在线阅读,更多相关《java课程设计职工工资管理系统.docx(20页珍藏版)》请在冰点文库上搜索。
java课程设计职工工资管理系统
一、设计目的…………………………………………………………………2
二、功能介绍…………………………………………………………………2
三、程序流程…………………………………………………………………2
四、设计步骤…………………………………………………………………3
五、设计总结…………………………………………………………………7
六、程序清单…………………………………………………………………8
七、参考文献…………………………………………………………………17
一、设计目的
通过课程设计,使学生提高理论联系实际解决实际问题的能力;也使学生对基于面向对象的理论进行系统设计过程中的诸多具体问题有感性的认识和深入的理解;进而提高学生的学习兴趣为其将来顺利进入毕业环节作必要的准备。
二、功能介绍
(1)具有新用户注册功能。
(2)具有注册用户登录功能。
(3)具有职工工资的录入功能,要求只录入工资各项,自动计算每个职工工资总额。
(4)具有数据查询功能,可以实现查询全部信息和按条件执行查询。
(5)具有按条件删除数据功能。
三、程序流程
四、设计步骤
4.1、登陆界面
进入系统首先进入登陆界面如图4.1,输入账号和密码,点击登录就会进入职工工资管理系统,点击注册进入新用户注册界面,定义了局部变量String类型的user,password和pass分别记录界面输入的账号,密码和数据库查找的密码,定义了成员变量boolean型的bool记录输入账号和密码是否匹配。
图4.1登陆界面
4.2、职工工资管理系统
登陆成功后进入的界面如图4.2,界面有增删改查的功能。
widgetSelected()
方法创建button的点击事件,创建DBHelper类的对象db连接数据库,进行查找,删除修改功能,增删改用update()方法,查询用query()方法。
图4.2职工工资管理界面
4.3、全部查找功能
点击右边的查询按钮可以查找出所有员工的工资信息如图4.3,通过自己封装的连接数据库的类DBHelper类的对象db,传递sql语句查找数据库的所有信息,用getString()方法导出从数据库中查找到的数据,所得工资=基本工资+职位提成-50*迟到天数-100*旷工天数,通过查找的数据和自己定义的公式得到所得工资。
图4.3全部查找界面
4.4、按条件查找功能
在文本框中输入职工号,点击查找能找到对应职工的工资情况,如图4.4。
用getText()方法获得text文本框中的的输入信息,定义局部变量boolean型的数据bool,记录数据库中是否有对应的职工号,如果查到则为true,并且在表格中先用removeAll()方法清空表的信息,然后用sql语句找出text中的职工号对应的数据。
图4.4按条件查找界面
4.5、录入功能
点击录入键进入录入界面如图4.5,输入职工信息,点击录入修改数据库的信息,并且能更新查找的结果。
用getText()方法获得text文本框的信息,定义局部变量String类型的s1,s2,s3,s4,s5,s6记录六个文本框的信息,通过DBHelper的对象db调用update方法把信息传入数据库。
图4.5录入功能界面
4.6、删除功能
点击选中行,然后点击删除按钮就会将选种的行删除掉,例如删除图4.3中第三行数据如图4.6。
定义局部变量TableItem[]数组用table.getSelection()方法查找并存储选中行的信息,定义int[]型数组用table.getSelectionIndices()方法查找并存储选中行的行号,用这两个信息分别删除数据库和界面的选中信息。
图4.6删除功能界面
4.7、注册功能
点击注册键后进入如图4.7所示的界面,输入新用户账号和密码,如果两次密码输入相同就注册成功。
定义局部变量String类型的user,password和pass分别记录三个文本框输入的内容,用equals方法判断pass和password是否相同,如果相同,则注册成功,并用dispose()方法关闭此窗口。
图4.7注册功能界面
五、设计总结
这次课程设计,我们知道了成员变量和局部变量的不同,有些变量如果不设成成员变量就无法把数据传递出去,我们学会了封装,将连接数据库的方法封装到DBHelper类中,封装的便利让我们写程序更快捷,但是界面的功能还不够人性化。
六、程序清单
import
import
import
import
import
import
import
import
import
import
import
publicclassdengluextendsShell{
booleanbool;
privateTexttext_1;
privateTexttext;
publicstaticvoidmain(Stringargs[]){
try{
Displaydisplay=Display.getDefault();
denglushell=newdenglu(display,SWT.SHELL_TRIM);
shell.open();
shell.layout();
while(!
shell.isDisposed()){
if(!
display.readAndDispatch())
display.sleep();
}
}catch(Exceptione){
e.printStackTrace();
}
}
publicdenglu(Displaydisplay,intstyle){
super(display,style);
createContents();
}
protectedvoidcreateContents(){
setText("登陆界面");
setSize(622,439);
finalLabellabel=newLabel(this,SWT.BORDER);
label.setFont(SWTResourceManager.getFont("",12,SWT.BOLD));
label.setText("账号:
");
label.setBounds(90,112,60,27);
finalLabellabel_1=newLabel(this,SWT.BORDER);
label_1.setFont(SWTResourceManager.getFont("",12,SWT.BOLD));
label_1.setText("密码:
");
label_1.setBounds(90,185,60,27);
text=newText(this,SWT.BORDER);
text.setBounds(208,112,125,27);
text_1=newText(this,SWT.BORDER|SWT.PASSWORD);
text_1.setBounds(208,185,125,27);
finalButtonbutton=newButton(this,SWT.NONE);
button.addSelectionListener(newSelectionAdapter(){
publicvoidwidgetSelected(finalSelectionEvente){
Stringuser=text.getText();
Stringpassword=text_1.getText();
DBHelperdb=newDBHelper();
Stringsql="select密码fromuser_Tablewhere账号='"+user+"'";
ResultSetrs=db.query(sql);
try{
while(rs.next()){
Stringpass=rs.getString("密码");
if(password.equals(pass)){
bool=true;
}else{
bool=false;
}
if(bool==true){
try{
Displaydisplay=Display.getDefault();
zhigonggongzishell=newzhigonggongzi(display,SWT.SHELL_TRIM);
shell.open();
shell.layout();
while(!
shell.isDisposed()){
if(!
display.readAndDispatch())
display.sleep();
}
}catch(Exceptione2){
e2.printStackTrace();
}
}
}
}catch(SQLExceptione1){
//TODOAuto-generatedcatchblock
e1.printStackTrace();
}
}
});
button.setFont(SWTResourceManager.getFont("",12,SWT.BOLD));
button.setText("登陆");
button.setBounds(388,255,48,22);
finalButtonbutton_1=newButton(this,SWT.NONE);
button_1.setFont(SWTResourceManager.getFont("",12,SWT.BOLD));
button_1.setText("注册");
button_1.setBounds(388,306,48,22);
finalLabellabel_2=newLabel(this,SWT.BORDER);
label_2.setFont(SWTResourceManager.getFont("",15,SWT.BOLD));
label_2.setText("欢迎使用员工工资管理系统");
label_2.setBounds(90,37,271,27);
//
}
@Override
protectedvoidcheckSubclass(){
//DisablethecheckthatpreventssubclassingofSWTcomponents
}
}
import
import
import
import
import
import
import
import
import
import
import
import
import
import
publicclasszhigonggongziextendsShell{
privateTexttext;
privateTabletable;
publicstaticvoidmain(Stringargs[]){
try{
Displaydisplay=Display.getDefault();
zhigonggongzishell=newzhigonggongzi(display,SWT.SHELL_TRIM);
shell.open();
shell.layout();
while(!
shell.isDisposed()){
if(!
display.readAndDispatch())
display.sleep();
}
}catch(Exceptione){
e.printStackTrace();
}
}
publiczhigonggongzi(Displaydisplay,intstyle){
super(display,style);
createContents();
}
protectedvoidcreateContents(){
setText("职工工资管理系统界面");
setSize(697,458);
table=newTable(this,SWT.FULL_SELECTION|SWT.BORDER);
table.setLinesVisible(true);
table.setHeaderVisible(true);
table.setBounds(10,67,573,214);
finalTableColumnnewColumnTableColumn=newTableColumn(table,SWT.NONE);
newColumnTableColumn.setWidth(73);
newColumnTableColumn.setText("职工号");
finalTableColumnnewColumnTableColumn_1=newTableColumn(table,SWT.NONE);
newColumnTableColumn_1.setWidth(76);
newColumnTableColumn_1.setText("职工姓名");
finalTableColumnnewColumnTableColumn_2=newTableColumn(table,SWT.NONE);
newColumnTableColumn_2.setWidth(76);
newColumnTableColumn_2.setText("基本工资");
finalTableColumnnewColumnTableColumn_3=newTableColumn(table,SWT.NONE);
newColumnTableColumn_3.setWidth(80);
newColumnTableColumn_3.setText("职位提成");
finalTableColumnnewColumnTableColumn_4=newTableColumn(table,SWT.NONE);
newColumnTableColumn_4.setWidth(79);
newColumnTableColumn_4.setText("迟到天数");
finalTableColumnnewColumnTableColumn_5=newTableColumn(table,SWT.NONE);
newColumnTableColumn_5.setWidth(83);
newColumnTableColumn_5.setText("旷工天数");
finalTableColumnnewColumnTableColumn_6=newTableColumn(table,SWT.NONE);
newColumnTableColumn_6.setWidth(100);
newColumnTableColumn_6.setText("所得工资");
finalButtonbutton=newButton(this,SWT.NONE);
button.addSelectionListener(newSelectionAdapter(){
publicvoidwidgetSelected(finalSelectionEvente){
try{
Displaydisplay=Display.getDefault();
lurushell=newluru(display,SWT.SHELL_TRIM);
shell.open();
shell.layout();
while(!
shell.isDisposed()){
if(!
display.readAndDispatch())
display.sleep();
}
}catch(Exceptione2){
e2.printStackTrace();
}
a();
}
});
button.setFont(SWTResourceManager.getFont("",12,SWT.BOLD));
button.setText("录入");
button.setBounds(604,142,55,31);
finalButtonbutton_1=newButton(this,SWT.NONE);
button_1.addSelectionListener(newSelectionAdapter(){
publicvoidwidgetSelected(finalSelectionEvente){
TableItem[]item=table.getSelection();
DBHelperdb=newDBHelper();
for(inti=0;iStringid=item[i].getText(0);
Stringsql="deletefrom职工信息表where职工号='"+id+"'";
db.update(sql);
}
db.close();
int[]a=table.getSelectionIndices();
table.remove(a);
}
});
button_1.setFont(SWTResourceManager.getFont("",12,SWT.BOLD));
button_1.setText("删除");
button_1.setBounds(604,196,55,31);
finalButtonbutton_2=newButton(this,SWT.NONE);
button_2.addSelectionListener(newSelectionAdapter(){
publicvoidwidgetSelected(finalSelectionEvente){
a();
}
});
button_2.setFont(SWTResourceManager.getFont("",12,SWT.BOLD));
button_2.setText("查询");
button_2.setBounds(604,91,55,31);
text=newText(this,SWT.BORDER);
text.setBounds(209,314,89,31);
finalLabellabel=newLabel(this,SWT.BORDER);
label.setFont(SWTResourceManager.getFont("",12,SWT.BOLD));
label.setText("按职工号查找:
");
label.setBounds(53,314,136,31);
finalButtonbutton_3=newButton(this,SWT.NONE);
button_3.addSelectionListener(newSelectionAdapter(){
publicvoidwidgetSelected(finalSelectionEvente){
table.removeAll();
Stringid=text.getText();
DBHelperdb=newDBHelper();
Stringsql="select*from职工信息表";
ResultSetrs=db.query(sql);
booleanbool=true;
if(bool){
try{
while(rs.next()){
if(id.equals(rs.getString("职工号"))){
bool=false;
finalTableItemnewItemTableItem=newTableItem(table,SWT.BORDER);
newItemTableItem.setText(0,rs.getString("职工号"));
newItemTableItem.setText(1,rs.getString("姓名"));
newItemTableItem.setText(2,rs.getString("基本工资"));
doublemoney1=Double.parseDouble(rs.getString("基本工资"));
newItemTableItem.setText(3,rs.getString("职位提成"));
doublemoney2=Double.parseDouble(rs.getString("职位提成"));
newItemTableItem.setText(4,rs.getString("迟到天数"));
intday1=Integer.parseInt(rs.getString("迟到天数"));
newItemTableItem.setText(5,rs.getString("旷工天数"));
intday2=Integer.parseInt(rs.getString("旷工天数"));
doublemoney=money1+money2-day1*50-day2*100;
if(money<0){
money=0;
}
Str