java课程设计职工工资管理系统Word下载.docx
《java课程设计职工工资管理系统Word下载.docx》由会员分享,可在线阅读,更多相关《java课程设计职工工资管理系统Word下载.docx(20页珍藏版)》请在冰点文库上搜索。
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
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("
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(!
if(!
display.sleep();
}
}catch(Exceptione2){
e2.printStackTrace();
}
}
}catch(SQLExceptione1){
//TODOAuto-generatedcatchblock
e1.printStackTrace();
}
});
button.setFont(SWTResourceManager.getFont("
button.setText("
登陆"
button.setBounds(388,255,48,22);
finalButtonbutton_1=newButton(this,SWT.NONE);
button_1.setFont(SWTResourceManager.getFont("
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
}
publicclasszhigonggongziextendsShell{
privateTabletable;
zhigonggongzishell=newzhigonggongzi(display,SWT.SHELL_TRIM);
publiczhigonggongzi(Displaydisplay,intstyle){
职工工资管理系统界面"
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("
所得工资"
Displaydisplay=Display.getDefault();
lurushell=newluru(display,SWT.SHELL_TRIM);
shell.open();
shell.layout();
while(!
if(!
display.sleep();
}catch(Exceptione2){
e2.printStackTrace();
a();
录入"
button.setBounds(604,142,55,31);
button_1.addSelectionListener(newSelectionAdapter(){
TableItem[]item=table.getSelection();
for(inti=0;
i<
item.length;
i++){
Stringid=item[i].getText(0);
deletefrom职工信息表where职工号='
+id+"
db.update(sql);
db.close();
int[]a=table.getSelectionIndices();
table.remove(a);
删除"
button_1.setBounds(604,196,55,31);
finalButtonbutton_2=newButton(this,SWT.NONE);
button_2.addSelectionListener(newSelectionAdapter(){
button_2.setFont(SWTResourceManager.getFont("
button_2.setText("
查询"
button_2.setBounds(604,91,55,31);
text.setBounds(209,314,89,31);
按职工号查找:
label.setBounds(53,314,136,31);
finalButtonbutton_3=newButton(this,SWT.NONE);
button_3.addSelectionListener(newSelectionAdapter(){
table.removeAll();
Stringid=text.getText();
select*from职工信息表"
ResultSetrs=db.query(sql);
booleanbool=true;
if(bool){
try{
if(id.equals(rs.getString("
))){
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