注册
当前位置: 首页> 研讨体会> 观后感>

企业用电管理系统设计课程实训报告

发布时间:2021-05-03 20:38:21 浏览数:

数据库课程实训报告 ( 2015-- 2016年度第2学期) 题目:
企业用电管理系统 专业 软件工程 学生姓名 班级 软件 学号 指导教师 完成日期 2016 目 录 目 录 2 1 课题内容和要求 1 1.1课题描述 1 1.2 课题要求 1 2 需求分析 1 2.1 对功能的规定 1 2.2 数据需求分析 2 3 系统设计 3 3.1 功能模块设计 3 3.2 数据库概念设计 4 3.2.2 E-R图 4 3.3 数据库逻辑设计 5 3.4 数据库物理设计 5 3.5 数据库表间联系 6 4系统实现 6 4.1登陆模块实现 6 4.2查询模块实现 7 4.3 添加模块实现 8 4.4 删除模块实现 9 4.5 修改模块实现 10 4.6 生成电费单模块实现 10 5 代码调试与功能测试 11 5.1 测试方案 11 5.2 测试结果 12 6 收获与体会 16 参考文献 17 附  录 18 附录1源程序部分清单 18 企业用电管理系统设计 1 课题内容和要求 1.1课题描述 系统设计的的信息有:
(1) 用电企业(用电企业编号、用电企业名、地址、电话、联系人);

(2) 电费信息(谷价、峰价);

(3) 用电情况(用电企业编号、谷电量、峰电量、年月、年合计用电量、年合计用电费)。

1.2 课题要求 要求能够进行如下操作:
(1) 能够统计各个用电企业的月耗电量以及电费;

(2) 能够统计查询各个用电企业的总的谷电量和峰电量;

(3) 能够统计该地区的峰谷电量比例以及电费情况;

(4) 能维护基本数据;

(5) 用户分级管理,人机界面良好。

2 需求分析 2.1 对功能的规定 1、理解需求 理解需求是在问题及其最终解决方案之间架设桥梁的第一步。开发者只有和用户充分理解了需求之后才能开始设计系统,否则,对需求定义的任何改进,设计上都必须大量的返工。

下面是对系统的终端用户和客户调研后得到的需求规格说明书。

(1)由于使用者为相关电力部门及学习使用,系统开始时,便可以进入到欢迎界面。  (2)进入到系统之后,友好的界面可以很清晰的分为企业信息管理跟企业用电信息管理两大选择。

(3)点击企业信息管理,下拉菜单中选项可以实现对企业信息的查询、添加、修改、删除操作。  (4)点击企业用电管理信息,下拉菜单中选项可以实现对企业用电管理信息的查询、添加、修改和删除操作。  (5)系统客户端运行在Windows平台下,服务器可以运行在Windows或Unix平台下。系统还应该有一个较好的图形用户界面。  (6)系统应该有很好的可扩展性。

2、需求分析 需求分析是从客户的需求中提取出软件系统能够帮助用户解决的业务问题,通过对用户业务问题的分析,确定系统的功能需求。这个步骤是对理解需求的升华,直接关系到该系统的质量。分析的根本目的是在开发者和提出需求的人之间建立一种理解和沟通机制,因此,系统的需求分析也应该是开发人员和用户或客户一起完成的。

2.2 对性能的规定 1、精度 在精度需求上,根据使用需要,在各项数据的输入,输出及传输过程中,可以满足各种精度的需求。如:根据关键字精度的不同,查找可分为精确查找和泛型查找,精确查找可精确匹配系统使用者所知道的企业名称及编号快速便捷的查询所要知道的信息。

2、时间特性要求 在软件方面,响应时间,更新处理时间都比较快且迅速,完全满足用户要求。

3、灵活性 当用户需求,如操作方式,运行环境,结果精度,数据结构于其他软件接口等发生变化时,设计的软件要做适当调整,灵活性非常大。

2.2 数据需求分析 数据字典 (1)factory 名称:factory 别名:无 描述:企业的基本信息 组成:factory=(num+facname+repname+tel+usefnum+usegnum+usemoney) (2) worker 名称:worker 别名:无 描述:员工及管理员的基本信息 组成:worker=(id+workername+password+level) 3 系统设计 3.1 功能模块设计 3.2 数据库概念设计 3.2.1实体属性图 3.2.2 E-R图 3.3 数据库逻辑设计 企业(编号,企业名,法人代表) 电价(峰电量,谷电量,峰电价,谷电价,总电费) 系统用户(编号,姓名,密码,权限) 3.4 数据库物理设计 表一:
factory 列名 数据类型 允许Null值 num varchar(50) 是 facname varchar(50) 是 repname varchar(50) 是 tel varchar(50) 是 usefnum int 是 usegnum int 是 usemoney int 是 num facname repname tel usefnum usegnum usemoney 001 新华书店 陈国勇 17802590001 1314 1022 2333 002 苏果超市 陈博文 17802590002 1516 2253 2863 003 微软公司 毕世勇 17802590003 3685 2467 4952 004 乐天玛特 丁小杰 17802590004 3011 2794 3105 005 三厂中学 陈家勇 17802590005 2422 1974 2875 表二:
worker 列名 数据类型 允许Null值 id int 否 workername varchar(50) 否 password varchar(50) 否 [level] int 否 id workername password [level] 111 张三 123456 1 112 李四 123456 1 113 熊大 123456 2 114 熊二 123456 2 3.5 数据库表间联系 数据库中所建的两张表factory与worker之间并没有任何直接的联系,一个代表的是企业信息,一个代表的是员工信息。

4系统实现 4.1登陆模块实现 private class ButtonactionPerformed implements ActionListener //为登陆按钮ButtonactionPerformed添加事件监视器 { public void actionPerformed(ActionEvent e)//从worker表中获得元组信息进行登陆,下面为获得元组登陆代码 { a=username2.getText(); s=password2.getText(); try { conn=DriverManager.getConnection(url, user, password); conn.setAutoCommit(true); System.out.println(“和数据库已经建立连接!!!“); stmt=(Statement) conn.createStatement(); rs=(ResultSet)stmt.executeQuery(“select * from worker “); if(c.equals(a)&&b.equals(s)) { message.setText(“姓名和密码不能为空“); } else if(true) { while(rs.next()) { if(rs.getString(2).equals(a)&& rs.getString(3).equals(s)&&rs.getInt(4)==level) { message.setText(“数据库连接成功!“); if(level==1) { operate2 app2=new operate2(); app2.setLocationRelativeTo(null); } else { operate app3=new operate(); app3.setLocationRelativeTo(null); } } else { message.setText(“用户名和密码或者身份不正确“); } } } rs.close(); stmt.close(); conn.close(); } 4.2查询模块实现 private class ButtonactionPerformed implements ActionListener //为查询按钮ButtonactionPerformed添加事件监视器 { public void actionPerformed(ActionEvent e) //从worker表中获取元组,并且显示在系统上 { facname=search.getText(); try { conn=DriverManager.getConnection(url, user, password); conn.setAutoCommit(true); System.out.println(“和数据库已经建立连接!!!“); stmt=(Statement) conn.createStatement(); rs=(ResultSet)stmt.executeQuery(“select * from factory “); while(rs.next()) { if(rs.getString(2).equals(facname)) { text1.setText(rs.getString(1)); text2.setText(rs.getString(2)); text3.setText(rs.getString(3)); text4.setText(rs.getString(4)); text5.setText(““+(rs.getInt(5))); text6.setText(““+rs.getInt(6)); text7.setText(““+rs.getInt(7)); } } rs.close(); stmt.close(); conn.close(); } 4.3 添加模块实现 private class ButtonactionPerformed implements ActionListener //为添加按钮ButtonactionPerformed添加事件监视器 { public void actionPerformed(ActionEvent e) //在系统内输入要添加的元组信息,通过添加按钮添加到数据库中的factory表内 { x1=text1.getText(); x2=text2.getText(); x3=text3.getText(); x4=text4.getText(); x5=text5.getText(); x6=text6.getText(); x7=text7.getText(); try { conn=DriverManager.getConnection(url, user, password); conn.setAutoCommit(true); System.out.println(“和数据库已经建立连接!!!“); prepstmt1=(PreparedStatement) conn.prepareStatement(“INSERT INTO factory(num,facname,repname,tel,usefnum,usegnum,usemoney)“ +“VALUES(?,?,?,?,?,?,?)“); prepstmt1.setString(1, x1); prepstmt1.setString(2, x2); prepstmt1.setString(3, x3); prepstmt1.setString(4, x4); prepstmt1.setString(5, x5); prepstmt1.setString(6, x6); prepstmt1.setString(7, x7); prepstmt1.executeUpdate(); conn.close(); } 4.4 删除模块实现 private class ButtonactionPerformed implements ActionListener { public void actionPerformed(ActionEvent e) { x1=text1.getText(); try { conn=DriverManager.getConnection(url, user, password); conn.setAutoCommit(true); System.out.println(“和数据库已经建立连接!!!“); stmt=(Statement) conn.createStatement(); stmt.executeUpdate(“delete from factory where num=“+x1); conn.close(); } 4.5 修改模块实现 private class ButtonactionPerformed implements ActionListener { public void actionPerformed(ActionEvent e) { x1=text1.getText(); x2=text2.getText(); x3=text3.getText(); x4=text4.getText();try { conn=DriverManager.getConnection(url, user, password); conn.setAutoCommit(true); System.out.println(“和数据库已经建立连接!!!“); prepstmt2=(PreparedStatement) conn.prepareStatement(“update factory set num=?,usegnum=?,usefnum=?,usemoney=? where num=?“); prepstmt2.setString(1, x1); prepstmt2.setString(2, x2); prepstmt2.setString(3, x3); prepstmt2.setString(4, x4); prepstmt2.setString(5, x1); prepstmt2.executeUpdate(); prepstmt2.close(); conn.close(); } 4.6 生成电费单模块实现 private class ButtonactionPerformed implements ActionListener { public void actionPerformed(ActionEvent e) { facname=search.getText(); try { conn=DriverManager.getConnection(url, user, password); conn.setAutoCommit(true); System.out.println(“和数据库已经建立连接!!!“); stmt=(Statement) conn.createStatement(); rs=(ResultSet)stmt.executeQuery(“select * from factory “); while(rs.next()) { if(rs.getString(2).equals(facname)) { x1=rs.getString(5); x2=rs.getString(6); x3=rs.getString(7); text1.setText(rs.getString(5)); text2.setText(rs.getString(6)); text3.setText(rs.getString(7)); } } rs.close(); stmt.close(); conn.close(); } 5 代码调试与功能测试 5.1 测试方案 (1)分别输入用户、管理员查看登陆进去后的界面 (2)分别用用户和管理员查询企业用电信息 (3)添加企业用电信息 (4)修改企业用电信息 (5)删除企业用电信息 (6)生成电费单 5.2 测试结果 管理员登陆 管理员登陆后的界面 管理员登陆后查询的界面 用户登陆后查询的界面 点击添加后的界面 输入数据 添加成功 点击修改进行修改信息 修改成功 点击删除后出现的界面 删除成功 点击生成电费单出现的界面 在桌面生成的电费单 6 收获与体会 一、这次课程设计的心得体会通过实践我的收获如下:
一开始接触数据结构课程设计真的挺难的,好多都不会,不是逻辑方面的问题,而不具备动手能力,脑子里总有一团火,比如对于这个题目,一开始有很多的想法,想到了从逻辑上怎么实现他,要编写哪些程序,但是一到需要编写了就开始为难了,可以说是几乎不知道从哪里入手,参考了书本里的程序,仿照他的结构一步一步做下来,现在对于单链表的各种操作已经算是比较熟练了,但我知道光有理论知识还远远不够,需要多动手,写的多了自然就能手到擒来。

二、根据我在实习中遇到得问题,我将在以后的学习过程中注意以下几点:
1、认真上好专业实验课,多在实践中锻炼自己。

2、写程序的过程中要考虑周到,严密。

3、在做设计的时候要有信心,有耐心,切勿浮躁。

4、认真的学习课本知识,掌握课本中的知识点,并在此基础上学会灵活运用。

5、在课余时间里多写程序,熟练掌握在调试程序的过程中所遇到的常见错误,以便能节省调试程序的时间。

参考文献 [1] 钱雪忠,王燕玲,林挺.数据库原理及技术[M].北京:清华大学出版社,2011. [2] 钱雪忠,罗海驰,陈国俊.数据库原理及技术课程设计[M].北京:清华大学出版社,2014. 附  录 附录1源程序部分清单 附录1.1record代码 import java.awt.*; import java.awt.event.*; import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; import java.sql.ResultSet; import java.sql.Statement; import javax.swing.*; public class Record extends JFrame { private static final long serialVersionUID = 1L; private JLabel username,password; private JTextField username2; private JTextField password2,message; private JButton button; private JRadioButton box1,box2; private ButtonGroup buttongroup; private String a,s; private String c=““; private String b=““; private int level=2; //private String juzi; public Record() { super(“Record“); setSize(300,300); try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); }catch(Exception e){} Container container=getContentPane(); container.setBackground(Color.lightGray); container.setLayout(null); username=new JLabel(“用户名:“,JLabel.RIGHT); password=new JLabel(“ 密码: “,JLabel.RIGHT); buttongroup=new ButtonGroup(); box1=new JRadioButton(“员工“,true); box2=new JRadioButton(“管理员“); username2=new JTextField(20); password2=new JTextField(20); message=new JTextField(“欢迎使用企业用电管理系统“); message.setHorizontalAlignment(JTextField.CENTER); button=new JButton(“登录“); username.setBounds(50, 50, 50, 25); username2.setBounds(100, 50, 120, 25); password.setBounds(50, 85, 50, 25); password2.setBounds(100,85, 120, 25); message.setBounds(55,160, 190, 25); box1.setBounds(50,120,50,25); box2.setBounds(110,120,70,25); button.setBounds(190, 120, 60, 25); buttongroup.add(box1); buttongroup.add(box2); ButtonactionPerformed buttoner=new ButtonactionPerformed(); button.addActionListener(buttoner); RadioButtonHandler handler = new RadioButtonHandler(); box1.addItemListener(handler); box2.addItemListener(handler); container.add(username); container.add(username2); container.add(password); container.add(password2); container.add(box1); container.add(box2); container.add(button); container.add(message); setVisible(true); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } public static void main(String[] args) { Record app=new Record(); app.setLocationRelativeTo(null); } private class RadioButtonHandler implements ItemListener { public void itemStateChanged(ItemEvent event) { if(box1.isSelected()) { message.setText(“员工登录“); level=2; } else if(box2.isSelected()) { message.setText(“管理员登录“); level=1; } } } private class ButtonactionPerformed implements ActionListener { public void actionPerformed(ActionEvent e)//登录 { a=username2.getText(); s=password2.getText(); try { Class.forName(“driver“); } catch(ClassNotFoundException arg0) { System.out.print(“class not find exception occur. message is:“); } try{ Class.forName(“driver“);//加载驱动 } catch(ClassNotFoundException event){System.out.print(“class not find exception occur. message is:“);} Statement stmt; ResultSet rs; String url=“jdbc:sqlserver://localhost:1433; DatabaseName=企业用电“; String driver=“com.microsoft.sqlserver.jdbc.SQLServerDriver“; String user=“sa“; String password=“123456“; Connection conn=null; try { conn=DriverManager.getConnection(url, user, password); conn.setAutoCommit(true); System.out.println(“和数据库已经建立连接!!!“); stmt=(Statement) conn.createStatement(); rs=(ResultSet)stmt.executeQuery(“select * from worker “); if(c.equals(a)&&b.equals(s)) { message.setText(“姓名和密码不能为空“); } else if(true) { while(rs.next()) { if(rs.getString(2).equals(a)&& rs.getString(3).equals(s)&&rs.getInt(4)==level) { message.setText(“数据库连接成功!“); if(level==1) { operate2 app2=new operate2(); app2.setLocationRelativeTo(null); } else { operate app3=new operate(); app3.setLocationRelativeTo(null); } } else { message.setText(“用户名和密码或者身份不正确“); } } } rs.close(); stmt.close(); conn.close(); } catch(SQLException eb) { System.out.print(“SQL exception occur. message is:“); System.out.print(eb.getMessage()); } } } } 附录1.2 operate代码 import java.awt.Color; import java.awt.Container; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JTextField; import javax.swing.UIManager; import java.sql.ResultSet; import java.sql.Statement; public class operate extends JFrame { private static final long serialVersionUID = 1L; private JButton b1,b2,b3,b4,b5,b6; private JLabel c1,c2,c3,c4,c5,c6,c7; private JTextField text1,text2,text3,text4,text5,text6,text7; private JTextField search; private JLabel name; private String facname; public operate() { super(“operate“); setSize(700,400); try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); }catch(Exception e){} Container container=getContentPane(); name=new JLabel(“输入企业名:“,JLabel.RIGHT); c1=new JLabel(“企业编号:“,JLabel.RIGHT); c2=new JLabel(“企业名称:“,JLabel.RIGHT); c3=new JLabel(“企业代表人:“,JLabel.RIGHT); c4=new JLabel(“企业联系电话:“,JLabel.RIGHT); c5=new JLabel(“企业谷电量:“,JLabel.RIGHT); c6=new JLabel(“企业峰电量:“,JLabel.RIGHT); c7=new JLabel(“企业用电费:“,JLabel.RIGHT); b1=new JButton(“查询“); b2=new JButton(“取消“); b3=new JButton(“添加“); b4=new JButton(“删除“); b5=new JButton(“修改“); b6=new JButton(“生成电费单“); text1=new JTextField(200); text2=new JTextField(200); text3=new JTextField(200); text4=new JTextField(200); text5=new JTextField(200); text6=new JTextField(200); text7=new JTextField(200); search=new JTextField(60); name.setBounds(80, 50, 100, 30); c1.setBounds(80, 100, 100, 30); c2.setBounds(80, 130, 100, 30); c3.setBounds(80, 160, 100, 30); c4.setBounds(80, 190, 100, 30); c5.setBounds(80, 220, 100, 30); c6.setBounds(80, 250, 100, 30); c7.setBounds(80, 280, 100, 30); search.setBounds(200, 50, 100, 25); b1.setBounds(370, 52,60,25); b2.setBounds(500,52,60,25); b3.setBounds(150, 330,60,25); b4.setBounds(250, 330,60,25); b5.setBounds(350, 330,60,25); b6.setBounds(450, 330,100,25); text1.setBounds(200,100,350,30); text2.setBounds(200,130,350,30); text3.setBounds(200,160,350,30); text4.setBounds(200,190,350,30); text5.setBounds(200,220,350,30); text6.setBounds(200,250,350,30); text7.setBounds(200,280,350,30); ButtonactionPerformed buttoner=new ButtonactionPerformed(); ButtonactionPerformed2 buttoner2=new ButtonactionPerformed2(); ButtonactionPerformed3 buttoner3=new ButtonactionPerformed3(); ButtonactionPerformed4 buttoner4=new ButtonactionPerformed4(); ButtonactionPerformed5 buttoner5=new ButtonactionPerformed5(); ButtonactionPerformed6 buttoner6=new ButtonactionPerformed6(); b1.addActionListener(buttoner); b2.addActionListener(buttoner2); b3.addActionListener(buttoner3); b4.addActionListener(buttoner4); b5.addActionListener(buttoner5); b6.addActionListener(buttoner6); container.add(b1); container.add(b2); container.add(b3); container.add(b4); container.add(b5); container.add(b6); container.add(search); container.add(text1); container.add(text2); container.add(text3); container.add(text4); container.add(text5); container.add(text6); container.add(text7); container.add(name); container.add(c1); container.add(c2); container.add(c3); container.add(c4); container.add(c5); container.add(c6); container.add(c7); container.setBackground(Color.lightGray); container.setLayout(null); setVisible(true); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } private class ButtonactionPerformed implements ActionListener { public void actionPerformed(ActionEvent e) { facname=search.getText(); try { Class.forName(“driver“); } catch(ClassNotFoundException arg0) { System.out.print(“class not find exception occur. message is:“); } try{ Class.forName(“driver“);//加载驱动 } catch(ClassNotFoundException event){System.out.print(“class not find exception occur. message is:“);} Statement stmt; ResultSet rs; String url=“jdbc:sqlserver://localhost:1433; DatabaseName=企业用电“; String driver=“com.microsoft.sqlserver.jdbc.SQLServerDriver“; String user=“sa“; String password=“123456“; Connection conn=null; try { conn=DriverManager.getConnection(url, user, password); conn.setAutoCommit(true); System.out.println(“和数据库已经建立连接!!!“); stmt=(Statement) conn.createStatement(); rs=(ResultSet)stmt.executeQuery(“select * from factory “); while(rs.next()) { if(rs.getString(2).equals(facname)) { text1.setText(rs.getString(1)); text2.setText(rs.getString(2)); text3.setText(rs.getString(3)); text4.setText(rs.getString(4)); text5.setText(““+(rs.getInt(5))); text6.setText(““+rs.getInt(6)); text7.setText(““+rs.getInt(7)); } } rs.close(); stmt.close(); conn.close(); } catch(SQLException eb) { System.out.print(“SQL exception occur. message is:“); System.out.print(eb.getMessage()); } } } private class ButtonactionPerformed2 implements ActionListener { public void actionPerformed(ActionEvent event) { System.exit(0); } } private class ButtonactionPerformed3 implements ActionListener { public void actionPerformed(ActionEvent event) { insert app3=new insert(); app3.setLocationRelativeTo(null); } } private class ButtonactionPerformed4 implements ActionListener { public void actionPerformed(ActionEvent event) { delect app4=new delect(); app4.setLocationRelativeTo(null); } } private class ButtonactionPerformed5 implements ActionListener { public void actionPerformed(ActionEvent event) { update app5=new update(); app5.setLocationRelativeTo(null); } } private class ButtonactionPerformed6 implements ActionListener { public void actionPerformed(ActionEvent event) { create app6=new create(); app6.setLocationRelativeTo(null); } } public static void main(String[] args) { operate app=new operate(); app.setLocationRelativeTo(null); } } 附录1.3 operate2代码 import java.awt.Color; import java.awt.Container; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JTextField; import javax.swing.UIManager; import java.sql.ResultSet; import java.sql.Statement; public class operate2 extends JFrame { private static final long serialVersionUID = 1L; private JButton b1,b2,b3,b4; private JLabel c1,c2,c3,c4,c5,c6,c7,d1,d2,d3,d4; private JTextField text1,text2,text3,text4,text5,text6,text7,ce1,ce2,ce3,ce4; private JTextField search1,search2; private JLabel name,name2,action1,action2; private String facname1,facname2; public operate2() { super(“operate2“); setSize(700,600); try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); }catch(Exception e){} Container container=getContentPane(); action1=new JLabel(“ 查看客户的资料“,JLabel.RIGHT); action2=new JLabel(“ 查看用户的资料“,JLabel.RIGHT); name=new JLabel(“输入企业名:“,JLabel.RIGHT); c1=new JLabel(“企业编号:“,JLabel.RIGHT); c2=new JLabel(“企业名称:“,JLabel.RIGHT); c3=new JLabel(“企业代表人:“,JLabel.RIGHT); c4=new JLabel(“企业联系电话:“,JLabel.RIGHT); c5=new JLabel(“企业谷电量:“,JLabel.RIGHT); c6=new JLabel(“企业峰电费:“,JLabel.RIGHT); c7=new JLabel(“企业用电费:“,JLabel.RIGHT); name2=new JLabel(“输入职工名:“,JLabel.RIGHT); d1=new JLabel(“职工编号:“,JLabel.RIGHT); d2=new JLabel(“职工名称:“,JLabel.RIGHT); d3=new JLabel(“职工密码:“,JLabel.RIGHT); d4=new JLabel(“职工等级:“,JLabel.RIGHT); b1=new JButton(“查询“); b2=new JButton(“取消“); b3=new JButton(“查询“); b4=new JButton(“取消“); text1=new JTextField(200); text2=new JTextField(200); text3=new JTextField(200); text4=new JTextField(200); text5=new JTextField(200); text6=new JTextField(200); text7=new JTextField(200); ce1=new JTextField(200); ce2=new JTextField(200); ce3=new JTextField(200); ce4=new JTextField(200); search1=new JTextField(60); search2=new JTextField(60); action1.setBounds(200,10, 200, 30); action2.setBounds(200,300, 200, 30); name.setBounds(80, 50, 100, 30); name2.setBounds(80, 330, 100, 30); c1.setBounds(80, 100, 100, 30); c2.setBounds(80, 130, 100, 30); c3.setBounds(80, 160, 100, 30); c4.setBounds(80, 190, 100, 30); c5.setBounds(80, 220, 100, 30); c6.setBounds(80, 250, 100, 30); c7.setBounds(80, 280, 100, 30); d1.setBounds(80, 360, 100, 30); d2.setBounds(80, 390, 100, 30); d3.setBounds(80, 420, 100, 30); d4.setBounds(80, 450, 100, 30); search1.setBounds(200, 50, 100, 25); search2.setBounds(200, 330, 100, 25); b1.setBounds(370, 52,60,25); b2.setBounds(500,52,60,25); b3.setBounds(370, 332,60,25); b4.setBounds(500,332,60,25); text1.setBounds(200,100,350,30); text2.setBounds(200,130,350,30); text3.setBounds(200,160,350,30); text4.setBounds(200,190,350,30); text5.setBounds(200,220,350,30); text6.setBounds(200,250,350,30); text7.setBounds(200,280,350,30); ce1.setBounds(200,360,350,30); ce2.setBounds(200,390,350,30); ce3.setBounds(200,420,350,30); ce4.setBounds(200,450,350,30); ButtonactionPerformed buttoner=new ButtonactionPerformed(); ButtonactionPerformed2 buttoner2=new ButtonactionPerformed2(); ButtonactionPerformed3 buttoner3=new ButtonactionPerformed3(); b1.addActionListener(buttoner); b2.addActionListener(buttoner2); b3.addActionListener(buttoner3); b4.addActionListener(buttoner2); container.add(b1); container.add(b2); container.add(b3); container.add(b4); container.add(search1); container.add(search2); container.add(text1); container.add(text2); container.add(text3); container.add(text4); container.add(text5); container.add(text6); container.add(text7); container.add(ce1); container.add(ce2); container.add(ce3); container.add(ce4); container.add(name); container.add(name2); container.add(action1); container.add(action2); container.add(c1); container.add(c2); container.add(c3); container.add(c4); container.add(c5); container.add(c6); container.add(c7); container.add(d1); container.add(d2); container.add(d3); container.add(d4); container.setBackground(Color.lightGray); container.setLayout(null); setVisible(true); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } private class ButtonactionPerformed implements ActionListener { public void actionPerformed(ActionEvent e) { facname1=search1.getText(); try { Class.forName(“driver“); } catch(ClassNotFoundException arg0) { System.out.print(“class not find exception occur. message is:“); } try{ Class.forName(“driver“);//加载驱动 } catch(ClassNotFoundException event){System.out.print(“class not find exception occur. message is:“);} Statement stmt; ResultSet rs; String url=“jdbc:sqlserver://localhost:1433; DatabaseName=企业用电“; String driver=“com.microsoft.sqlserver.jdbc.SQLServerDriver“; String user=“sa“; String password=“123456“; Connection conn=null; try { conn=DriverManager.getConnection(url, user, password); conn.setAutoCommit(true); System.out.println(“和数据库已经建立连接!!!“); stmt=(Statement) conn.createStatement(); rs=(ResultSet)stmt.executeQuery(“select * from factory “); while(rs.next()) { if(rs.getString(2).equals(facname1)) { text1.setText(rs.getString(1)); text2.setText(rs.getString(2)); text3.setText(rs.getString(3)); text4.setText(rs.getString(4)); text5.setText(““+(rs.getInt(5))); text6.setText(““+rs.getInt(6)); text7.setText(““+rs.getInt(7)); } } rs.close(); stmt.close(); conn.close(); } catch(SQLException eb) { System.out.print(“SQL exception occur. message is:“); System.out.print(eb.getMessage()); } } } private class ButtonactionPerformed2 implements ActionListener { public void actionPerformed(ActionEvent event) { System.exit(0); } } private class ButtonactionPerformed3 implements ActionListener { public void actionPerformed(ActionEvent e) { facname2=search2.getText(); try { Class.forName(“driver“); } catch(ClassNotFoundException arg0) { System.out.print(“class not find exception occur. message is:“); } try{ Class.forName(“driver“);//加载驱动 } catch(ClassNotFoundException event){System.out.print(“class not find exception occur. message is:“);} Statement stmt; ResultSet rs; String url=“jdbc:sqlserver://localhost:1433; DatabaseName=企业用电“; String driver=“com.microsoft.sqlserver.jdbc.SQLServerDriver“; String user=“sa“; String password=“123456“; Connection conn=null; try { conn=DriverManager.getConnection(url, user, password); conn.setAutoCommit(true); System.out.println(“和数据库已经建立连接!!!“); stmt=(Statement) conn.createStatement(); rs=(ResultSet)stmt.executeQuery(“select * from worker “); while(rs.next()) { if(rs.getString(2).equals(facname2)) { ce1.setText(““+rs.getInt(1)); ce2.setText(rs.getString(2)); ce3.setText(rs.getString(3)); ce4.setText(““+rs.getInt(4)); } } rs.close(); stmt.close(); conn.close(); } catch(SQLException eb) { System.out.print(“SQL exception occur. message is:“); System.out.print(eb.getMessage()); } } } public static void main(String[] args) { operate2 add=new operate2(); add.setLocationRelativeTo(null); } } 附录1.4 insert代码 import java.awt.Color; import java.awt.Container; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JTextField; import javax.swing.UIManager; import java.sql.PreparedStatement; public class insert extends JFrame { private static final long serialVersionUID = 1L; private JButton b1,b2; private JLabel c1,c2,c3,c4,c5,c6,c7,name; private JTextField text1,text2,text3,text4,text5,text6,text7; private String x1,x2,x3,x4,x5,x6,x7; public insert() { super(“insert“); setSize(700,400); try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); }catch(Exception e){} Container container=getContentPane(); name=new JLabel(“ 请输入要添客户的相关资料“,JLabel.RIGHT); c1=new JLabel(“企业编号:“,JLabel.RIGHT); c2=new JLabel(“企业名称:“,JLabel.RIGHT); c3=new JLabel(“企业代表人:“,JLabel.RIGHT); c4=new JLabel(“企业联系电话:“,JLabel.RIGHT); c5=new JLabel(“企业谷电量:“,JLabel.RIGHT); c6=new JLabel(“企业峰电量:“,JLabel.RIGHT); c7=new JLabel(“企业用电费:“,JLabel.RIGHT); b1=new JButton(“确定“); b2=new JButton(“取消“); text1=new JTextField(200); text2=new JTextField(200); text3=new JTextField(200); text4=new JTextField(200); text5=new JTextField(200); text6=new JTextField(200); text7=new JTextField(200); name.setBounds(240, 10, 200, 30); c1.setBounds(80, 60, 100, 30); c2.setBounds(80, 90, 100, 30); c3.setBounds(80, 120, 100, 30); c4.setBounds(80, 150, 100, 30); c5.setBounds(80, 180, 100, 30); c6.setBounds(80, 210, 100, 30); c7.setBounds(80, 240, 100, 30); b1.setBounds(250, 280,60,25); b2.setBounds(450,280,60,25); text1.setBounds(200,60,350,30); text2.setBounds(200,90,350,30); text3.setBounds(200,120,350,30); text4.setBounds(200,150,350,30); text5.setBounds(200,180,350,30); text6.setBounds(200,210,350,30); text7.setBounds(200,240,350,30); ButtonactionPerformed buttoner=new ButtonactionPerformed(); ButtonactionPerformed2 buttoner2=new ButtonactionPerformed2(); b1.addActionListener(buttoner); b2.addActionListener(buttoner2); container.add(name); container.add(b1); container.add(b2); container.add(text1); container.add(text2); container.add(text3); container.add(text4); container.add(text5); container.add(text6); container.add(text7); container.add(c1); container.add(c2); container.add(c3); container.add(c4); container.add(c5); container.add(c6); container.add(c7); container.setBackground(Color.lightGray); container.setLayout(null); setVisible(true); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } private class ButtonactionPerformed implements ActionListener { public void actionPerformed(ActionEvent e) { x1=text1.getText(); x2=text2.getText(); x3=text3.getText(); x4=text4.getText(); x5=text5.getText(); x6=text6.getText(); x7=text7.getText(); try { Class.forName(“driver“); } catch(ClassNotFoundException arg0) { System.out.print(“class not find exception occur. message is:“); } try{ Class.forName(“driver“);//加载驱动 } catch(ClassNotFoundException event){System.out.print(“class not find exception occur. message is:“ PreparedStatement prepstmt1; String url=“jdbc:sqlserver://localhost:1433; DatabaseName=企业用电“; String driver=“com.microsoft.sqlserver.jdbc.SQLServerDriver“; String user=“sa“; String password=“123456“; Connection conn=null; try { conn=DriverManager.getConnection(url, user, password); conn.setAutoCommit(true); System.out.println(“和数据库已经建立连接!!!“); prepstmt1=(PreparedStatement) conn.prepareStatement(“INSERT INTO factory(num,facname,repname,tel,usefnum,usegnum,usemoney)“ +“VALUES(?,?,?,?,?,?,?)“); prepstmt1.setString(1, x1); prepstmt1.setString(2, x2); prepstmt1.setString(3, x3); prepstmt1.setString(4, x4); prepstmt1.setString(5, x5); prepstmt1.setString(6, x6); prepstmt1.setString(7, x7); prepstmt1.executeUpdate(); conn.close(); } catch(SQLException eb) { System.out.print(“SQL exception occur. message is:“); System.out.print(eb.getMessage()); } } } private class ButtonactionPerformed2 implements ActionListener { public void actionPerformed(ActionEvent event) { operate app4=new operate(); app4.setLocationRelativeTo(null); } } public static void main(String[] args) { insert app=new insert(); app.setLocationRelativeTo(null); } } 附录1.5 delect代码 import java.awt.Color; import java.awt.Container; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JTextField; import javax.swing.UIManager; import java.sql.Statement; public class delect extends JFrame { private static final long serialVersionUID = 1L; private JButton b1,b2; private JLabel c1,name; private JTextField text1; private String x1; public delect() { super(“delect“); setSize(700,400); try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); }catch(Exception e){} Container container=getContentPane(); name=new JLabel(“ 请输入要添删除客户的企业编号“,JLabel.RIGHT); c1=new JLabel(“企业编号:“,JLabel.RIGHT); b1=new JButton(“确定“); b2=new JButton(“取消“); text1=new JTextField(200); name.setBounds(240, 10, 200, 30); c1.setBounds(80, 60, 100, 30); b1.setBounds(200, 150,60,25); b2.setBounds(450,150,60,25); text1.setBounds(200,60,350,30); ButtonactionPerformed buttoner=new ButtonactionPerformed(); ButtonactionPerformed2 buttoner2=new ButtonactionPerformed2(); b1.addActionListener(buttoner); b2.addActionListener(buttoner2); container.add(name); container.add(b1); container.add(b2); container.add(text1); container.add(c1); container.setBackground(Color.lightGray); container.setLayout(null); setVisible(true); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } private class ButtonactionPerformed implements ActionListener { public void actionPerformed(ActionEvent e) { x1=text1.getText(); try { Class.forName(“driver“); } catch(ClassNotFoundException arg0) { System.out.print(“class not find exception occur. message is:“); } try{ Class.forName(“driver“);//加载驱动 } catch(ClassNotFoundException event){System.out.print(“class not find exception occur. message is:“);} Statement stmt; String url=“jdbc:sqlserver://localhost:1433; DatabaseName=企业用电“; Stringdriver=“com.microsoft.sqlserver.jdbc.SQLServerDriver“; String user=“sa“; String password=“123456“; Connection conn=null; try { conn=DriverManager.getConnection(url, user, password); conn.setAutoCommit(true); System.out.println(“和数据库已经建立连接!!!“); stmt=(Statement) conn.createStatement(); stmt.executeUpdate(“delete from factory where num=“+x1); conn.close(); } catch(SQLException eb) { System.out.print(“SQL exception occur. message is:“); System.out.print(eb.getMessage()); } } } private class ButtonactionPerformed2 implements ActionListener { public void actionPerformed(ActionEvent event) { operate app4=new operate(); app4.setLocationRelativeTo(null); } } public static void main(String[] args) { delect app=new delect(); app.setLocationRelativeTo(null); } } 附录1.6 update代码 import java.awt.Color; import java.awt.Container; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JTextField; import javax.swing.UIManager; import java.sql.PreparedStatement; public class update extends JFrame { private static final long serialVersionUID = 1L; private JButton b1,b2; private JLabel c1,c3,c2,c4,name; private JTextField text1,text2,text3,text4; private String x1,x2,x3,x4; public update() { super(“update“); setSize(700,400); try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); }catch(Exception e){} Container container=getContentPane(); name=new JLabel(“ 请输入要添修改客户的企业编号和相关信息“,JLabel.RIGHT); c1=new JLabel(“企业编号:“,JLabel.RIGHT); c2=new JLabel(“企业谷电量:“,JLabel.RIGHT); c3=new JLabel(“企业峰电量:“,JLabel.RIGHT); c4=new JLabel(“企业用电费:“,JLabel.RIGHT); b1=new JButton(“确定“); b2=new JButton(“取消“); text1=new JTextField(200); text2=new JTextField(200); text3=new JTextField(200); text4=new JTextField(200); name.setBounds(150, 10, 300, 30); c1.setBounds(200, 60, 100, 30); c2.setBounds(200, 90, 100, 30); c3.setBounds(200, 120, 100, 30); c4.setBounds(200, 150, 100, 30); b1.setBounds(250, 210,60,25); b2.setBounds(350,210,60,25); text1.setBounds(300,60,100,30); text2.setBounds(300,90,100,30); text3.setBounds(300,120,100,30); text4.setBounds(300,150,100,30); ButtonactionPerformed buttoner=new ButtonactionPerformed(); ButtonactionPerformed2 buttoner2=new ButtonactionPerformed2(); b1.addActionListener(buttoner); b2.addActionListener(buttoner2); container.add(name); container.add(b1); container.add(b2); container.add(text1); container.add(text2); container.add(text3); container.add(text4); container.add(c1); container.add(c2); container.add(c3); container.add(c4); container.setBackground(Color.lightGray); container.setLayout(null); setVisible(true); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } private class ButtonactionPerformed implements ActionListener { public void actionPerformed(ActionEvent e) { x1=text1.getText(); x2=text2.getText(); x3=text3.getText(); x4=text4.getText(); try { Class.forName(“driver“); } catch(ClassNotFoundException arg0) { System.out.print(“class not find exception occur. message is:“); } try{ Class.forName(“driver“);//加载驱动 } catch(ClassNotFoundException event){System.out.print(“class not find exception occur. message is:“);} PreparedStatement prepstmt2; String url=“jdbc:sqlserver://localhost:1433; DatabaseName=企业用电“; String driver=“com.microsoft.sqlserver.jdbc.SQLServerDriver“; String user=“sa“; String password=“123456“; Connection conn=null; try { conn=DriverManager.getConnection(url, user, password); conn.setAutoCommit(true); System.out.println(“和数据库已经建立连接!!!“); prepstmt2=(PreparedStatement) conn.prepareStatement(“update factory set num=?,usegnum=?,usefnum=?,usemoney=? where num=?“); prepstmt2.setString(1, x1); prepstmt2.setString(2, x2); prepstmt2.setString(3, x3); prepstmt2.setString(4, x4); prepstmt2.setString(5, x1); prepstmt2.executeUpdate(); prepstmt2.close(); conn.close(); } catch(SQLException eb) { System.out.print(“SQL exception occur. message is:“); System.out.print(eb.getMessage()); } } } private class ButtonactionPerformed2 implements ActionListener { public void actionPerformed(ActionEvent event) { operate app4=new operate(); app4.setLocationRelativeTo(null); } } public static void main(String[] args) { update app=new update(); app.setLocationRelativeTo(null); } } 附录1.7 create代码 import java.awt.Color; import java.awt.Container; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JTextField; import javax.swing.UIManager; import java.sql.ResultSet; import java.sql.Statement; import java.io.PrintWriter; import java.io.FileNotFoundException; public class create extends JFrame { private static final long serialVersionUID = 1L; private JButton b1,b6; private JLabel c1,c2,c3; private JTextField text1,text2,text3; private JTextField search; private JLabel name; private String facname,x1,x2,x3,x4; public create() { super(“create“); setSize(600,400); try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); }catch(Exception e){} Container container=getContentPane(); name=new JLabel(“输入企业名:“,JLabel.RIGHT); c1=new JLabel(“企业谷电量:“,JLabel.RIGHT); c2=new JLabel(“企业峰电量:“,JLabel.RIGHT); c3=new JLabel(“企业用电费:“,JLabel.RIGHT); b1=new JButton(“查询“); b6=new JButton(“生成电费单“); text1=new JTextField(200); text2=new JTextField(200); text3=new JTextField(200); search=new JTextField(60); name.setBounds(80, 50, 100, 30); c1.setBounds(80, 100, 100, 30); c2.setBounds(80, 130, 100, 30); c3.setBounds(80, 160, 100, 30); search.setBounds(200, 50, 100, 25); b1.setBounds(320, 52,60,25); b6.setBounds(230, 200,100,25); text1.setBounds(200,100,180,30); text2.setBounds(200,130,180,30); text3.setBounds(200,160,180,30); ButtonactionPerformed buttoner=new ButtonactionPerformed(); ButtonactionPerformed2 buttoner2=new ButtonactionPerformed2(); b1.addActionListener(buttoner); b6.addActionListener(buttoner2); container.add(b1); container.add(b6); container.add(search); container.add(text1); container.add(text2); container.add(text3); container.add(name); container.add(c1); container.add(c2); container.add(c3); container.setBackground(Color.lightGray); container.setLayout(null); setVisible(true); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } private class ButtonactionPerformed implements ActionListener { public void actionPerformed(ActionEvent e) { facname=search.getText(); try { Class.forName(“driver“); } catch(ClassNotFoundException arg0) { System.out.print(“class not find exception occur. message is:“); } try{ Class.forName(“driver“);//加载驱动 } catch(ClassNotFoundException event){System.out.print(“class not find exception occur. message is:“);} Statement stmt; ResultSet rs; String url=“jdbc:sqlserver://localhost:1433; DatabaseName=企业用电“; String driver=“com.microsoft.sqlserver.jdbc.SQLServerDriver“; String user=“sa“; String password=“123456“; Connection conn=null; try { conn=DriverManager.getConnection(url, user, password); conn.setAutoCommit(true); System.out.println(“和数据库已经建立连接!!!“); stmt=(Statement) conn.createStatement(); rs=(ResultSet)stmt.executeQuery(“select * from factory “); while(rs.next()) { if(rs.getString(2).equals(facname)) { x1=rs.getString(5); x2=rs.getString(6); x3=rs.getString(7); text1.setText(rs.getString(5)); text2.setText(rs.getString(6)); text3.setText(rs.getString(7)); } } rs.close(); stmt.close(); conn.close(); } catch(SQLException eb) { System.out.print(“SQL exception occur. message is:“); System.out.print(eb.getMessage()); } } } private class ButtonactionPerformed2 implements ActionListener { public void actionPerformed(ActionEvent event) { try { x4=search.getText(); PrintWriter f=new PrintWriter (“C:/用户/Administrator/桌面/电费单.txt“); f.println(“ “+x4+“企业电费单 “); f.println(“ “); f.println(“ “); f.println(“ 谷用电量: “+x1); f.println(“ “); f.println(“ 峰用电量: “+x2); f.println(“ “); f.println(“ 企业用电费: “+x3); f.close(); } catch(FileNotFoundException e) { System.out.println(“发生异常“); } } } public static void main(String[] args) { create app=new create(); app.setLocationRelativeTo(null); } } 附录1.8 test代码 import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; import java.sql.ResultSet; import java.sql.Statement; public class test { public test(){ try { Class.forName(“driver“); } catch(ClassNotFoundException arg0) { System.out.print(“class not find exception occur. message is:“); } try{ Class.forName(“driver“);//加载驱动 } catch(ClassNotFoundException event){System.out.print(“class not find exception occur. message is:“);} Statement stmt; ResultSet rs; String url=“jdbc:sqlserver://localhost:1433; DatabaseName=企业用电“; String driver=“com.microsoft.sqlserver.jdbc.SQLServerDriver“; String user=“sa“; String password=“123456“; Connection conn=null; try { conn=DriverManager.getConnection(url, user, password); conn.setAutoCommit(true); System.out.println(“和数据库已经建立连接!!!“); stmt=(Statement) conn.createStatement(); int a=1000; rs=(ResultSet)stmt.executeQuery(“select * from worker “); while(rs.next()) { if(rs.getInt(1)==a) System.out.println(“数据库连接成功!“); } rs.close(); stmt.close(); conn.close(); } catch(SQLException eb) { System.out.print(“SQL exception occur. message is:“); System.out.print(eb.getMessage()); } } }

上一篇:在干部调整集体谈话会上的讲话提纲

上一篇:中心组学习档案管理制度

相关范文