实验设备管理系统
- 格式:docx
- 大小:367.24 KB
- 文档页数:21
1 一、 需求分析 每学年要对实验室的设备使用情况进行统计,更新.其中:
1) 对于已彻底损坏的做报废处理,同时详细记录有关信息; 2) 对于有严重问题(故障)的要及时处理,并记录修理日期,设备名,编号,修理厂家,修理费用, 3) 责任人等; 4) 对于急需使用但又缺少的设备,需以"申请表"的形式送交上级领导请求批准购买; 5) 新设备购入后要立即进行设备登记(包括类名,设备名,编号,序号,规格,单价,数量,购置日期,生产厂家,保质期和经办人等信息)。 需要有添加,删除,修改等设置,以方便客户的需求,最主要是将数据库中的信息有条理地展示给客户。因此我就运用所学的数据库原理,编写了一个程序,主要是设计关于实验室的设备使用情况进行统计。 第一, 别人肯定不会希望是看到没有窗口的程序,所以我选择有窗体的JFrame语句。 第二, 为了更好的使用这个程序,我决定添加快捷键,这也是创新点。 第三, 基础功能不能少: a) 增加、修改、删除一个设备信息、修理信息、购置申请信息。 b) 修改设备状态信息。 c) 查询设备信息、修理信息和购置申请(条件有按设备编号、设备名称等)。
二、 概要设计 主要运用AWT设计UI,使信息更加直观,然后jdbcodbc桥连接数据库。 主窗体中有菜单栏、表单、按钮,菜单上主要分两个子菜单,第一个子菜单有更新、退出,第二个子菜单有添加申请、修改、删除、查找,和下方的按钮起相同作用。中间有由JTable语句建成的表格,并且显示数据库中的内容,也就是实验室的器材记录信息。下方,刚才提过,有四个按钮,分别起到添加申请、修改、删除、查找的事件。 文件: 更新(F5):可以更新当前表格中的数据信息,因为添加修改删除都会影响到数据内容,就必须重新刷新一下。 退出(ALT+F4):顾名思义,就是可以直接推出程序,并且有快捷键ALT+F4。 编辑: 添加申请:添加申请单内容包括编号、类名、设备名、规格、单价、数量、购置日期、生产厂家、保质期、负责人、经办人。 修改:先弹出一个窗口,要求输入序号,因为序号是不重复的,所以在数据库中找到对应序号的信息,并显示在第二个窗口中的文本中。客户可以修改文本中的数据,按下修改按钮可以保存修改的对应数据。 删除:同样跳出一个窗口,输入对应序号可以删除信息。 查找:在弹出的文本框中填入设备编号或者设备名称就可以模糊查找对应信息,在新窗口中以表格的形式呈现出来。 2
三、 详细设计 publicclass mainclass { publicstaticvoid main(String args[]){ new WindowFlow("实验设备管理系统"); } } 添加主类,生成一个新的的窗口,也就是主窗体: import java.awt.*; import javax.swing.*; import java.awt.event.*; import java.sql.*; public class WindowFlow extends JFrame implements ActionListener{ Connection con; Statement sql; ResultSet rs; JMenuBar menubar; JMenu menu1,menu2; JMenuItem itemrefresh,itemexit,itemadd,itemfix,itemdel,itemfind; JTable table; JScrollPane JSPTable; JPanel pNorth,pSouth; JLabel title; Object a[][]; Object name[]={"序号","编号","类名","设备名","规格","单价","数量","购置日期","生产厂家","保质期","状态","负责人","经办人"}; JButton buttonadd,buttonfix,buttondel,buttonfind; Winadd winadd; Winfix1 winfix1; Windel1 windel1; Winfind1 winfind1; 这里以上是定义变量,控件,连接数据库的一些准备。 WindowFlow(String s){ setTitle(s); //menu menubar=new JMenuBar(); menu1=new JMenu(" 文件 "); menu1.setFont(new Font("微软雅黑",Font.LAYOUT_RIGHT_TO_LEFT,15)); menu2=new JMenu(" 编辑 "); menu2.setFont(new Font("微软雅黑",Font.LAYOUT_RIGHT_TO_LEFT,15)); menubar.setBackground(Color.white); itemrefresh=new JMenuItem("刷新",new ImageIcon("Icon/refresh.png")); itemexit=new JMenuItem("退出",new ImageIcon("Icon/exit.png")); itemadd=new JMenuItem("添加申请",new ImageIcon("Icon/add.png")); itemfix=new JMenuItem("修改",new ImageIcon("Icon/fix.png")); 3
itemdel=new JMenuItem("删除",new ImageIcon("Icon/del.png")); itemfind=new JMenuItem("查找",new ImageIcon("Icon/find.png")); itemrefresh.setFont(new Font("微软雅黑",Font.LAYOUT_RIGHT_TO_LEFT,14)); itemexit.setFont(new Font("微软雅黑",Font.LAYOUT_RIGHT_TO_LEFT,14)); itemadd.setFont(new Font("微软雅黑",Font.LAYOUT_RIGHT_TO_LEFT,14)); itemfix.setFont(new Font("微软雅黑",Font.LAYOUT_RIGHT_TO_LEFT,14)); itemdel.setFont(new Font("微软雅黑",Font.LAYOUT_RIGHT_TO_LEFT,14)); itemfind.setFont(new Font("微软雅黑",Font.LAYOUT_RIGHT_TO_LEFT,14)); itemrefresh.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F5,0));
itemexit.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F4,InputEvent.ALT_MASK));
itemfind.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F,InputEvent.CTRL_MASK)); menu1.add(itemrefresh); menu1.add(itemexit); menu2.add(itemadd); menu2.add(itemfix); menu2.add(itemdel); menu2.addSeparator(); menu2.add(itemfind); menubar.add(menu1); menubar.add(menu2); setJMenuBar(menubar); //ActionEvent itemrefresh.addActionListener(this); itemexit.addActionListener(this); itemadd.addActionListener(this); itemfix.addActionListener(this); itemdel.addActionListener(this); itemfind.addActionListener(this); //ActionEvent end //menu end 这里以上是菜单的建立,并且在最后添加了ActionListener触发事件,因为连接了ActionListener类方法,所以在最后添加了ActionPerformed方法,以解决触发事件
//pNorth //pNorth=new JPanel(); //title=new JLabel("实验设备管理系统"); //pNorth.add(title); //add(pNorth,BorderLayout.NORTH); //pNorth end 4
//JSPTable table //数据库 try{ Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");} catch(ClassNotFoundException e){System.out.println(""+e);} try{ con=DriverManager.getConnection("jdbc:odbc:shebei","",""); sql=con.createStatement(); rs=sql.executeQuery("SELECT*FROM message"); int k=0; while(rs.next()){k++;} a=new Object[k][13]; rs=sql.executeQuery("SELECT*FROM message"); for(int i=0;rs.next();i++){ for(int j=0;j<13;j++){ a[i][j]=rs.getString(j+1); } } con.close(); } catch(SQLException e){System.out.println(e);} //数据库 end table=new JTable(a,name); table.setRowHeight(20); JSPTable=new JScrollPane(table); JSPTable.setPreferredSize(new Dimension(975,321)); add(JSPTable,BorderLayout.CENTER); //JSPTable table end 以上连接jdbcodbc桥,建成以数据库之间的联系,并且用循环语句生成表格的行数,再一次读取数据库内容并且运用循环语句在表格中添加数据,让表格在窗口中间显示。设置表格大小,位置,加载。 //pSouth pSouth=new JPanel(); buttonadd=new JButton("添加申请"); buttonfix=new JButton("修改"); buttondel=new JButton("删除"); buttonfind=new JButton("查找"); pSouth.add(buttonadd); pSouth.add(buttonfix); pSouth.add(buttondel); pSouth.add(buttonfind); add(pSouth,BorderLayout.SOUTH); //pSouth end