




已阅读5页,还剩35页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
苏州科技学院电子信息与信息实验中心面向对象课程设计报告(题目实验室设备信息管理系统)专业年级班级学号姓名成绩指导教师目录1 课程设计任务和概述31.1 设计目的31.2设计意义31.3 设计任务31.4 开发环境32 系统分析与建模42.1 系统功能分析42.2 用例图及用例说明52.2.1用户登录用例52.2.2 整体用例框图63 系统设计73.1 系统类图73.2 系统活动图103.2.1 用例“用户登录”活动图103.2.2用例“用户登录成功”活动图113.3 系统时序图123.3.1查询设备信息时序图123.3.2添加设备信息时序图133.3.3修改设备信息时序图143.3.4删除设备信息时序图144 系统实现154.1系统管理员模块154.2查询设备所有信息模块214.3添加设备信息模块294.4修改设备信息模块314.5删除设备信息模块325 系统测试346 课程设计总结397 参考文献39实验室设备信息管理系统设计报告1 课程设计任务和概述1.1 设计目的“面向对象技术”是计算机科学与技术专业的核心专业课,面向对象程序设计技术也是软件工程师的基本技能,“面向对象课程设计”的目的是理解和巩固面向对象程序设计的基本理论、原理和方法的重要的实践环节。 本课程设计综合应用学生所学知识,结合小型应用系统的设计,建立面向对象程序设计的概念,理解和巩固封装、类与对象、继承与多态、JAVA数据结构、多线程、IO、UI设计及UML等知识,为后续课程的学习打下良好的基础。 1.2设计意义使用实验室管理系统使得查询工作更系统化、规范化、自动化。从而在一方面提高了管理人员的工作效率,减少了传统人工管理方式所带来的人力,物力的浪费,另一方面由于本软件具有查找方便、可靠性高、存储量大等优点,大大地减少了系统的富复杂性。1.3 设计任务该系统主要任务是实现实验室设备基本信息的增加、删除、修改查询,包括设备型号、设备名称、生产厂商,单价等。管理员可以根据设备的名称、设备型号等关键字进行设备信息的查询;大大提高了管理设备的效率,实时性的观察设备信息更新。1.4 开发环境操作系统:Windows7 32位/64位软件:eclipse 3.7数据库:MySQL 5.02 系统分析与建模2.1 系统功能分析实验室设备管理系统设备添加设备浏览设备查询设备删除设备信息设备信息主要功能包括:设备添加信息:该部分功能主要是用于系统设备管理员输入设备的各种信息,加强系统的可扩展性和延续性,使系统信息保持更新。浏览设备信息:浏览全部的设备信息,将所有的设备信息都展示出来方便用户调用,只要适用于实验室管理员查询设备信息:查询设备信息,以及相关资料,查询分两种方式,一种是按设备型号查询,另一种是按设备名称查询。删除设备信息:删除设备信息功能主要用于更新设备信息数据,对于不必要的信息和错误的过时的信息进行相关处理,有利于简化系统,对于系统的运行速度的提升有着良好的加速效果。修改设备信息:此功能用于修改设备信息,使用权限均适用于普通用户。进行设备信息的相关修改对于系统的正常运行有着显著的作用。系统登录:合法的用户和系统的管理员才可以进入系统,他们具有权限不一样,管理员可以操作该系统的一切功能,而用户只能查看和浏览设备的信息。2.2 用例图及用例说明2.2.1用户登录用例(1)用户登录用例描述用户登录,是本系统提供的一项基本服务。在实验室设备信息管理系统的建模过程中,将这一行为抽象为一个用例。在不考虑软件的具体实现细节基础上,给出如下的用例描述。Use Case 名称用户登录执行者管理员(用户)前置条件管理员(用户)通过系统验证后,成功登陆系统事件流A输入用户名; 若输入不正确,则提示“您输入的用户名有误,请重新输入!” 输入正确,则提示“请您输入您的密码!”B输入密码; 若输入不正确,则提示“您输入的密码有误,请重新输入!”C. 点击“退出”,退出系统。后置条件管理员(用户)成功登录系统,实验室设备信息管理系统保存记录并修改设备名称、数量、金额。(2)用户登录用例图根据(1)的用例描述,画出用户登录用例图,见图1。图1用户登录模块的用例图用户登录模块用例主要提供两个基本功能:(1)用户通过登录界面输入“用户名”和“密码”;(2)系统对用户输入的“用户名”和“密码”进行验证,以判断用户身份的合法性。2.2.2 整体用例框图图2设备信息系统的整体用例框图3 系统设计3.1 系统类图(1)Device类和User类的UML图 (2)MainFrameUI类和LoginIU类UML图 (3)QueryUI查询类、AddDevice添加类、UpdateUI修改类的UML图 (4)整个系统的UML框架图3.2 系统活动图3.2.1 用例“用户登录”活动图3.2.2 用例“用户登录成功”活动图3.3 系统时序图3.3.1 查询设备信息时序图3.3.2添加设备信息时序图3.3.3修改设备信息时序图3.3.4删除设备信息时序图4 系统实现4.1系统管理员模块本模块主要是为了往数据库中管理设备信息记录,以及添加新的设备信息记录、修改需要变更的信息、删除已经停行的设备记录等,对现有的系统进行管理操作,保证实验室设备信息管理的合理性。详细代码:(1)User类:package dao;public class User /1 两个属性private int id;private String uname;private String passwd;/2 构造方法public User(int id, String uname, String passwd) super();this.id = id;this.uname = uname;this.passwd = passwd;public User(String uname, String passwd) super();this.uname = uname;this.passwd = passwd;/3 get和set方法public String getUname() return uname;public int getId() return id;public void setId(int id) this.id = id;public void setUname(String uname) this.uname = uname;public String getPasswd() return passwd;public void setPasswd(String passwd) this.passwd = passwd;(2)界面LoginUI类import service.IDeviceService;import dao.User;public class LoginUI extends JDialog static final int OK=1,CANCEL=0;private int ModalResult = -1;private final JPanel contentPanel = new JPanel();private JLabel lblLogon; private JLabel lblUserName; private JLabel lblPassWd; private JTextField txtUserName; private JPasswordField txtPassWd; private JButton btnLogon; private JButton btnCancel;/* * Launch the application. */public static void main(String args) try LoginUI dialog = new LoginUI();dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);dialog.setVisible(true); catch (Exception e) e.printStackTrace();/* * Create the dialog. */public LoginUI() /设置模式对话框setModal(true);setTitle(用户登录);setBounds(100, 100, 277, 189);getContentPane().setLayout(new BorderLayout();contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5);getContentPane().add(contentPanel, BorderLayout.CENTER);contentPanel.setLayout(null);lblUserName = new JLabel(用户名);lblUserName.setBounds(27, 31, 54, 15);contentPanel.add(lblUserName);lblPassWd = new JLabel(密码);lblPassWd.setBounds(27, 69, 54, 15);contentPanel.add(lblPassWd);txtUserName = new JTextField();txtUserName.setBounds(106, 28, 120, 21);contentPanel.add(txtUserName);txtUserName.setColumns(10);txtPassWd = new JPasswordField();txtPassWd.setBounds(106, 66, 120, 21);contentPanel.add(txtPassWd);JPanel buttonPane = new JPanel();buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT);getContentPane().add(buttonPane, BorderLayout.SOUTH);btnLogon = new JButton(登录);/登录按钮的功能btnLogon.addActionListener(new ActionListener() public void actionPerformed(ActionEvent arg0) /设置返回状态码ModalResult = OK ;/隐藏对话框setVisible(false););btnLogon.setActionCommand(OK);buttonPane.add(btnLogon);getRootPane().setDefaultButton(btnLogon);btnCancel = new JButton(取消);/取消按钮的功能btnCancel.addActionListener(new ActionListener() public void actionPerformed(ActionEvent e) ModalResult = CANCEL ;setVisible(false););btnCancel.setActionCommand(Cancel);buttonPane.add(btnCancel);/获得登录用户信息public User getUser()return new User(txtUserName.getText(),new String(txtPassWd.getPassword();/* * return the modalResult * 获取返回状态码 */public int getModalResult() return ModalResult;/清除登录痕迹public void clear()txtUserName.setText();txtPassWd.setText();(3)DeviceUserDao接口(考虑到有多个方法功能,我们用接口实现多继承)public interface DeviceUserDao extends IBaseDao/这个接口里会实现两个方法 1.查找用户名和密码的方法 public abstract User findByNamePassword(String uname,String passwd);/ 2. 显示用户表的所有的值public abstract List findAll();/ 3.显示设备查询的所有值public abstract List findDeviceAll();(4)实现接口DeviceUserDao里的具体方法public class DeviceServiceImpl implements IDeviceService/实现登录用户功能的结果Overridepublic User findByNamePassword(String uname, String passwd)return devicedao.findByNamePassword(uname, passwd);/实现用户查询的结果 Overridepublic List findAll()return devicedao.findAll();/ 下面来写查找用户名和密码的方法findByNamePassword()实现登陆功能!Overridepublic User findByNamePassword(String uname, String passwd) User user = null;Connection con = JDBCConnectionFactory.getConnection();try PreparedStatement pstmt = con.prepareStatement(select name,password from user where name=? and password=?);pstmt.setString(1, uname);pstmt.setString(2, passwd);ResultSet rs = pstmt.executeQuery();if (rs.next() user = new User(rs.getString(1),rs.getString(2); catch (SQLException e) e.printStackTrace(); finally if (con != null)try con.close(); catch (SQLException e) e.printStackTrace();return user;/ 接下来我们就要实现这个(User)表的查询啦 和上面类似Overridepublic List findAll() List list = new ArrayList();Connection conn = JDBCConnectionFactory.getConnection();try Statement stmt = conn.createStatement();String sql = select id, name, password from user order by id asc;ResultSet rs = stmt.executeQuery(sql);while (rs.next() list.add(new User(rs.getInt(1), rs.getString(2),rs.getString(3); catch (SQLException e) / TODO Auto-generated catch blocke.printStackTrace(); finally if (conn != null) try conn.close(); catch (SQLException e) / TODO Auto-generated catch blocke.printStackTrace();return list;4.2查询设备所有信息模块管理员可以浏览设备的所有信息,实时观察设备信息的动态性(1) 设备类(Device类)package dao;public class Device /1 7个属性 private int id;private String dno;private String dname;private String dproducer;private String dprice;private String dcount;private String dsum;/2 构造方法public Device(String dno, String dname, String dproducer, String dprice,String dcount, String dsum) super();this.dno = dno;this.dname = dname;this.dproducer = dproducer;this.dprice = dprice;this.dcount = dcount;this.dsum = dsum;public Device(int id, String dno, String dname, String dproducer,String dprice, String dcount, String dsum) super();this.id = id;this.dno = dno;this.dname = dname;this.dproducer = dproducer;this.dprice = dprice;this.dcount = dcount;this.dsum = dsum;/ 3 7个set和get方法public int getId() return id;public void setId(int id) this.id = id;public String getDno() return dno;public void setDno(String dno) this.dno = dno;public String getDname() return dname;public void setDname(String dname) this.dname = dname;public String getDproducer() return dproducer;public void setDproducer(String dproducer) this.dproducer = dproducer;public String getDprice() return dprice;public void setDprice(String dprice) this.dprice = dprice;public String getDcount() return dcount;public void setDcount(String dcount) this.dcount = dcount;public String getDsum() return dsum;public void setDsum(String dsum) this.dsum = dsum;(2)IDeviceService设备接口类(根据设计模式直接调用接口就行)【考虑到多个方法,这里还是选用接口,实现多继承完成具体功能】 public interface IDeviceService public void setDevicedao(deviceDaoImpl devicedao);public List findAll();public User findByNamePassword(String uname, String passwd);public List findDeviceAll();public boolean delete(Integer id);public boolean update(Device device);public Device findById(Integer id);public boolean insert(Device device);(3)实现接口(DeviceServiceImpl)的具体方法package service;import java.util.List;import dao.Device;import dao.User;import dao.deviceDaoImpl;public class DeviceServiceImpl implements IDeviceService/定义一个具体方法的类的一个private deviceDaoImpl devicedao; Overridepublic void setDevicedao(deviceDaoImpl devicedao) this.devicedao = devicedao;/返回所有查询的结果Overridepublic List findDeviceAll()return devicedao.findDeviceAll();(4)具体的方法/这是查询所有设备信息的方法Overridepublic List findDeviceAll() List list = new ArrayList();Connection conn = JDBCConnectionFactory.getConnection();try Statement stmt = conn.createStatement();String sql = select id,D_no,D_name,D_producer,D_price,D_count,D_sum from euipinfo order by id asc;ResultSet rs = stmt.executeQuery(sql);while(rs.next()list.add(new Device(rs.getInt(1),rs.getString(2), rs.getString(3), rs.getString(4),rs.getString(5), rs.getString(6), rs.getString(7); catch (SQLException e) / TODO Auto-generated catch blocke.printStackTrace();finallyif(conn != null)try conn.close(); catch (SQLException e) / TODO Auto-generated catch blocke.printStackTrace();return list;(4)界面UIpackage SourceCode;/import java.awt.event.*;import javax.swing.*;import javax.swing.table.DefaultTableModel;import java.awt.*;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.io.File;import java.io.IOException;import java.util.*;import java.sql.*;class BrowerDeviceFrame implements ActionListener JFrame f;Container cp;JPanel jpS, jpanelWest;JButton jbt1, jbt2, input;static JButton output;JLabel label, L;static JTable table;Object columnName = 设备名称, 型号, 生产厂家, 单价, 数量, 金额 ;Object ar = new Object10006;String sno;String count = 1000;BrowerDeviceFrame() f = new JFrame(预览仪器设备);cp = f.getContentPane();jpS = new JPanel();jpanelWest = new JPanel();jbt1 = new JButton(确定);input = new JButton(导入);output = new JButton(导出);jbt1.setBackground(Color.lightGray);jbt2 = new JButton(返回);jbt2.setBackground(Color.lightGray);label = new JLabel( + 预览设备以下是设备的所有信息,SwingConstants.CENTER);label.setForeground(Color.black);L = new JLabel(实验室现在共有设备 + count + 台);table = new JTable(ar, columnName);JScrollPane scrollpane = new JScrollPane(table);jpS.add(jbt1);jpS.add(jbt2);/jpS.add(input);/jpS.add(output);JPanel jpanel = new JPanel();jpanel.add(label);JPanel pp4 = new JPanel();JPanel jpE = new JPanel();cp.add(jpanel, North);JPanel jp = new JPanel();JPanel p = new JPanel();/ 用来放两个表p.setLayout(new BorderLayout();p.add(L, North);p.add(scrollpane);cp.add(pp4, West);cp.add(p, Center);cp.add(jpS, South);cp.add(jpE, East);jpanel.setBackground(Color.lightGray);jpS.setBackground(Color.lightGray);jpanelWest.setBackground(Color.lightGray);f.setSize(1000, 600);f.setVisible(true);jbt1.addActionListener(this);/ 注册监听器jbt2.addActionListener(this);input.addActionListener(this);int i = 0;public void showRecord() while (i = 0) ari0 = ;ari1 = ;ari2 = ;ari3 = ;ari4 = ;ari5 = ;i-;i = 0;try Class.forName(com.mysql.jdbc.Driver).newInstance(); catch (Exception e) e.printStackTrace();try Connection con = DriverManager.getConnection(jdbc:mysql:/localhost:3306/Device?user=root&password=);String s = select * from device ;Statement sql = con.createStatement();ResultSet rs = sql.executeQuery(s);while (rs.next() String dname=rs.getString(1);String dno=rs.getString(2);String dproducer=rs.getString(3);String dprice=rs.getString(4);String dcount=rs.getString(5);String dsum=rs.getString(6);ari0=dname;ari1=dno;ari2=dproducer;ari3=dprice;ari4=dcount;ari5=dsum;i+;count = + i + ;L.setText(实验室现在共有设备 + count + 台);f.repaint();con.close(); catch (SQLException g) System.out.println(g.getErrorCode();System.out.println(g.getMessage();public void actionPerformed(ActionEvent e) String cmd = e.getActionCommand();if (cmd.equals(确定) f.hide();if (cmd.equals(返回) f.hide();if (cmd.equals(导出) public static void main(String arg) BrowerDeviceFrame a = new BrowerDeviceFrame();a.showRecord();4.添加设备信息模块用户可以添加设备信息,实现设备资源的管理主要详细代码:(1)IDeviceService接口public interface IDeviceService public void setDevicedao(deviceDaoImpl devicedao);public boolean insert(Device device);(2)DeviceServiceImpl接口public class DeviceServiceImpl implements IDeviceService/定义一个具体方法的类的一个private deviceDaoImpl devicedao; Overridepublic void setDevicedao(deviceDaoImpl devicedao) this.devicedao = devicedao;/返回设备插入的结果Overridepublic boolean insert(Device device)return devicedao.insert(device);(3)deviceDaoImpl类/* * 第一个方法insert()方法来实现设备插入或者添加操作,使用boolean类型的方法, 当然也要返回blooean类型的值 ,这里是result */public class deviceDaoImpl implements deviceUserDao Overridepublic boolean insert(Device device) boolean result = false;/ 连接数据库Connection con = JDBCConnectionFactory.getConnection();/ 使用try catch语句捕捉异常try PreparedStatement pstmt = con.prepareStatement(insert into euipinfo(D_no,D_name,D_producer,D_price,D_count,D_sum)+ VALUES(?,?,?,?,?,?);/PreparedStatement pstmt = con.prepareStatement(/insert into user1(nickname, name, password,email) values(?,?,?,?);/ 注意你要插入那个字段,这里要和Device表里的字段位置保持一致,从一开始pstmt.setString(1, device.getDno();pstmt.setString(2, device.getDname();pstmt.setString(3, device.getDproducer();pstmt.setString(4, device.getDprice();pstmt.setString(5, device.getDcount();pstmt.setString(6, device.getDsum();/ 下面就要开始向里表格里里插入啦!int x = pstmt.executeUpdate();if (x = 1) result = true; catch (SQLException e) e.printStackTrace(); finally if (con != null) try con.close(); catch (SQLException e) e.printStackTrace();return result;4.修改设备信息模块用户在查询页面时,可以直接选中一行即可将设备的信息进行修改,并跳出修改页面;当用户一行都不选中时,会跳出请选择要修改的一行的提示对话框。主要详细代码:(1)IDeviceService接口public interface IDeviceService public void setDevicedao(deviceDaoImpl devicedao);public boolean update(Device device);(2)DeviceServiceImpl接口public class DeviceServiceImpl implements IDeviceService/定义一个具体方法的类的一个private deviceDaoImpl devicedao; Overridepublic void setDevicedao(deviceDaoImpl devicedao) this.devicedao = devicedao;/返回设备修改的结果Overridepublic boolean iuodate(Device device)ret
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
评论
0/150
提交评论