java课程设计职工工资管理系统(共17页).doc
精选优质文档-倾情为你奉上目 录一、 设计目的2二、 功能介绍2三、 程序流程2四、 设计步骤3五、设计总结7六、程序清单8七、参考文献17一、设计目的 通过课程设计,使学生提高理论联系实际解决实际问题的能力;也使学生对基于面向对象的理论进行系统设计过程中的诸多具体问题有感性的认识和深入的理解;进而提高学生的学习兴趣为其将来顺利进入毕业环节作必要的准备。二、功能介绍(1)具有新用户注册功能。(2)具有注册用户登录功能。(3)具有职工工资的录入功能,要求只录入工资各项,自动计算每个职工工资总额。(4)具有数据查询功能,可以实现查询全部信息和按条件执行查询。(5)具有按条件删除数据功能。三、程序流程开始新用户登录?输入用户名和密码进入系统选择操作录入功能查找功能删除功能注册新用户向数据库添加记录可按职工号查询或查询所有数据按选中行的行号删除数据结束YN四、设计步骤 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 java.sql.ResultSet;import java.sql.SQLException;import org.eclipse.swt.SWT;import org.eclipse.swt.events.SelectionAdapter;import org.eclipse.swt.events.SelectionEvent;import org.eclipse.swt.widgets.Button;import org.eclipse.swt.widgets.Display;import org.eclipse.swt.widgets.Label;import org.eclipse.swt.widgets.Shell;import org.eclipse.swt.widgets.Text;import com.swtdesigner.SWTResourceManager;public class denglu extends Shell boolean bool;private Text text_1;private Text text;public static void main(String args) try Display display = Display.getDefault();denglu shell = new denglu(display, SWT.SHELL_TRIM);shell.open();shell.layout();while (!shell.isDisposed() if (!display.readAndDispatch()display.sleep(); catch (Exception e) e.printStackTrace();public denglu(Display display, int style) super(display, style);createContents();protected void createContents() setText("登陆界面");setSize(622, 439);final Label label = new Label(this, SWT.BORDER);label.setFont(SWTResourceManager.getFont("", 12, SWT.BOLD);label.setText("账号:");label.setBounds(90, 112, 60, 27);final Label label_1 = new Label(this, SWT.BORDER);label_1.setFont(SWTResourceManager.getFont("", 12, SWT.BOLD);label_1.setText("密码:");label_1.setBounds(90, 185, 60, 27);text = new Text(this, SWT.BORDER);text.setBounds(208, 112, 125, 27);text_1 = new Text(this, SWT.BORDER | SWT.PASSWORD);text_1.setBounds(208, 185, 125, 27);final Button button = new Button(this, SWT.NONE);button.addSelectionListener(new SelectionAdapter() public void widgetSelected(final SelectionEvent e) String user=text.getText();String password=text_1.getText();DBHelper db=new DBHelper();String sql="select 密码 from user_Table where 账号='"+user+"'"ResultSet rs=db.query(sql);try while(rs.next()String pass=rs.getString("密码");if(password.equals(pass)bool=true;elsebool=false;if(bool=true)try Display display = Display.getDefault();zhigonggongzi shell = new zhigonggongzi(display, SWT.SHELL_TRIM);shell.open();shell.layout();while (!shell.isDisposed() if (!display.readAndDispatch()display.sleep(); catch (Exception e2) e2.printStackTrace(); catch (SQLException e1) / TODO Auto-generated catch blocke1.printStackTrace(););button.setFont(SWTResourceManager.getFont("", 12, SWT.BOLD);button.setText("登陆");button.setBounds(388, 255, 48, 22);final Button button_1 = new Button(this, SWT.NONE);button_1.setFont(SWTResourceManager.getFont("", 12, SWT.BOLD);button_1.setText("注册");button_1.setBounds(388, 306, 48, 22);final Label label_2 = new Label(this, SWT.BORDER);label_2.setFont(SWTResourceManager.getFont("", 15, SWT.BOLD);label_2.setText("欢迎使用员工工资管理系统");label_2.setBounds(90, 37, 271, 27);/Overrideprotected void checkSubclass() / Disable the check that prevents subclassing of SWT componentsimport java.sql.ResultSet;import java.sql.SQLException;import org.eclipse.swt.SWT;import org.eclipse.swt.events.SelectionAdapter;import org.eclipse.swt.events.SelectionEvent;import org.eclipse.swt.widgets.Button;import org.eclipse.swt.widgets.Display;import org.eclipse.swt.widgets.Label;import org.eclipse.swt.widgets.Shell;import org.eclipse.swt.widgets.Table;import org.eclipse.swt.widgets.TableColumn;import org.eclipse.swt.widgets.TableItem;import org.eclipse.swt.widgets.Text;import com.swtdesigner.SWTResourceManager;public class zhigonggongzi extends Shell private Text text;private Table table;public static void main(String args) try Display display = Display.getDefault();zhigonggongzi shell = new zhigonggongzi(display, SWT.SHELL_TRIM);shell.open();shell.layout();while (!shell.isDisposed() if (!display.readAndDispatch()display.sleep(); catch (Exception e) e.printStackTrace();public zhigonggongzi(Display display, int style) super(display, style);createContents();protected void createContents() setText("职工工资管理系统界面");setSize(697, 458);table = new Table(this, SWT.FULL_SELECTION | SWT.BORDER);table.setLinesVisible(true);table.setHeaderVisible(true);table.setBounds(10, 67, 573, 214);final TableColumn newColumnTableColumn = new TableColumn(table, SWT.NONE);newColumnTableColumn.setWidth(73);newColumnTableColumn.setText("职工号");final TableColumn newColumnTableColumn_1 = new TableColumn(table, SWT.NONE);newColumnTableColumn_1.setWidth(76);newColumnTableColumn_1.setText("职工姓名");final TableColumn newColumnTableColumn_2 = new TableColumn(table, SWT.NONE);newColumnTableColumn_2.setWidth(76);newColumnTableColumn_2.setText("基本工资");final TableColumn newColumnTableColumn_3 = new TableColumn(table, SWT.NONE);newColumnTableColumn_3.setWidth(80);newColumnTableColumn_3.setText("职位提成");final TableColumn newColumnTableColumn_4 = new TableColumn(table, SWT.NONE);newColumnTableColumn_4.setWidth(79);newColumnTableColumn_4.setText("迟到天数");final TableColumn newColumnTableColumn_5 = new TableColumn(table, SWT.NONE);newColumnTableColumn_5.setWidth(83);newColumnTableColumn_5.setText("旷工天数"); final TableColumn newColumnTableColumn_6 = new TableColumn(table, SWT.NONE);newColumnTableColumn_6.setWidth(100);newColumnTableColumn_6.setText("所得工资");final Button button = new Button(this, SWT.NONE);button.addSelectionListener(new SelectionAdapter() public void widgetSelected(final SelectionEvent e) try Display display = Display.getDefault();luru shell = new luru(display, SWT.SHELL_TRIM);shell.open();shell.layout();while (!shell.isDisposed() if (!display.readAndDispatch()display.sleep(); catch (Exception e2) e2.printStackTrace();a(););button.setFont(SWTResourceManager.getFont("", 12, SWT.BOLD);button.setText("录入");button.setBounds(604, 142, 55, 31);final Button button_1 = new Button(this, SWT.NONE);button_1.addSelectionListener(new SelectionAdapter() public void widgetSelected(final SelectionEvent e) TableItem item=table.getSelection();DBHelper db=new DBHelper();for(int i=0;i<item.length;i+)String id=itemi.getText(0); String sql="delete from 职工信息表 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);final Button button_2 = new Button(this, SWT.NONE);button_2.addSelectionListener(new SelectionAdapter() public void widgetSelected(final SelectionEvent e) a(););button_2.setFont(SWTResourceManager.getFont("", 12, SWT.BOLD);button_2.setText("查询");button_2.setBounds(604, 91, 55, 31);text = new Text(this, SWT.BORDER);text.setBounds(209, 314, 89, 31);final Label label = new Label(this, SWT.BORDER);label.setFont(SWTResourceManager.getFont("", 12, SWT.BOLD);label.setText("按职工号查找:");label.setBounds(53, 314, 136, 31);final Button button_3 = new Button(this, SWT.NONE);button_3.addSelectionListener(new SelectionAdapter() public void widgetSelected(final SelectionEvent e) table.removeAll();String id=text.getText();DBHelper db=new DBHelper();String sql="select * from 职工信息表 " ResultSet rs=db.query(sql); boolean bool=true; if(bool) try while(rs.next()if(id.equals(rs.getString("职工号")bool=false;final TableItem newItemTableItem = new TableItem(table, SWT.BORDER); newItemTableItem.setText(0,rs.getString("职工号"); newItemTableItem.setText(1,rs.getString("姓名"); newItemTableItem.setText(2,rs.getString("基本工资"); double money1=Double.parseDouble(rs.getString("基本工资"); newItemTableItem.setText(3,rs.getString("职位提成"); double money2=Double.parseDouble(rs.getString("职位提成"); newItemTableItem.setText(4,rs.getString("迟到天数"); int day1=Integer.parseInt(rs.getString("迟到天数"); newItemTableItem.setText(5,rs.getString("旷工天数"); int day2=Integer.parseInt(rs.getString("旷工天数"); double money=money1+money2-day1*50-day2*100; if(money<0) money=0; String Money=String.valueOf(money); newItemTableItem.setText(6,Money); catch (SQLException e1) / TODO Auto-generated catch blocke1.printStackTrace(); );button_3.setFont(SWTResourceManager.getFont("", 12, SWT.BOLD);button_3.setText("查找");button_3.setBounds(347, 312, 73, 33);final Label label_1 = new Label(this, SWT.BORDER);label_1.setFont(SWTResourceManager.getFont("", 15, SWT.BOLD);label_1.setText("职工工资管理系统");label_1.setBounds(189, 24, 177, 31);/public void a()table.removeAll();DBHelper db=new DBHelper();String sql="select * from 职工信息表"ResultSet rs=db.query(sql);try while(rs.next()final TableItem newItemTableItem = new TableItem(table, SWT.BORDER); newItemTableItem.setText(0,rs.getString("职工号"); newItemTableItem.setText(1,rs.getString("姓名"); newItemTableItem.setText(2,rs.getString("基本工资"); double money1=Double.parseDouble(rs.getString("基本工资"); newItemTableItem.setText(3,rs.getString("职位提成"); double money2=Double.parseDouble(rs.getString("职位提成"); newItemTableItem.setText(4,rs.getString("迟到天数"); int day1=Integer.parseInt(rs.getString("迟到天数"); newItemTableItem.setText(5,rs.getString("旷工天数"); int day2=Integer.parseInt(rs.getString("旷工天数"); double money=money1+money2-day1*50-day2*100; if(money<0) money=0; String Money=String.valueOf(money); newItemTableItem.setText(6,Money); catch (SQLException e) / TODO Auto-generated catch blocke.printStackTrace();Overrideprotected void checkSubclass() / Disable the check that prevents subclassing of SWT componentsimport org.eclipse.swt.SWT;import org.eclipse.swt.events.SelectionAdapter;import org.eclipse.swt.events.SelectionEvent;import org.eclipse.swt.widgets.Button;import org.eclipse.swt.widgets.Display;import org.eclipse.swt.widgets.Label;import org.eclipse.swt.widgets.Shell;import org.eclipse.swt.widgets.Text;import com.swtdesigner.SWTResourceManager;public class luru extends Shell private Text text_5;private Text text_4;private Text text_3;private Text text_2;private Text text_1;private Text text;public static void main(String args) try Display display = Display.getDefault();luru shell = new luru(display, SWT.SHELL_TRIM);shell.open();shell.layout();while (!shell.isDisposed() if (!display.readAndDispatch()display.sleep(); catch (Exception e) e.printStackTrace();public luru(Display display, int style) super(display, style);createContents();protected void createContents() setText("职工工资录入界面");setSize(660, 451);final Label label = new Label(this, SWT.BORDER);label.setFont(SWTResourceManager.getFont("", 12, SWT.BOLD);label.setText("职工号:");label.setBounds(87, 82, 87, 26);final Label label_1 = new Label(this, SWT.BORDER);label_1.setFont(SWTResourceManager.getFont("", 12, SWT.BOLD);label_1.setText("姓名:");label_1.setBounds(87, 119, 87, 24);final Label label_2 = new Label(this, SWT.BORDER);label_2.setFont(SWTResourceManager.getFont("", 12, SWT.BOLD);label_2.setText("基本工资:");label_2.setBounds(87, 149, 87, 24);final Label label_3 = new Label(this, SWT.BORDER);label_3.setFont(SWTResourceManager.getFont("", 12, SWT.BOLD);label_3.setText("职位提成:");label_3.setBounds(87, 179, 87, 26);final Label label_4 = new Label(this, SWT.BORDER);label_4.setFont(SWTResourceManager.getFont("", 12, SWT.BOLD);label_4.setText("迟到