《2022年水电管理系统数据库课程设计说明书 .pdf》由会员分享,可在线阅读,更多相关《2022年水电管理系统数据库课程设计说明书 .pdf(37页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。
1、中北大学数据库课程设计说 明 书学院、 系:软件学院专业:网络工程学 生 姓 名:马骏学 号:0921020124 设 计 题 目:水电管理系统起迄日期 : 2011 年 5 月 30 日 2011 年 6 月 17 日指导教师 :李玉荣2010 年 6 月 17 日名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 1 页,共 37 页 - - - - - - - - - 一 背景资料:随着科学科技的不断发展,人们的生活方式正在发生着日新月异的变化,生活更趋于智能化,便捷化,手机,电脑
2、,互联网这些科技发展的成果,则完全改变了我们的生活方式。人造卫星, 航天器,航天飞机, 更是把人类的文明提升到了更高的深度和广度,而这些成就,却离不开计算机科学时代的基础软件!社会发展越来越快,水电力需求量旺盛,加强有序用水和电管理,确保电力和水力的有效供应。随着各个公寓居住条件的不断改善,越来越多的电器,如空调、电脑、电热设备、饮水机等正逐步走进公寓,公寓用电量越来越大。传统所采用的定时、限量的用电管理模式受到挑战,供电是否适应时代要求已经关系到生活环境的质量问题。为了给住户提供一个符合时代发展的生活环境,使公寓服务向社会化发展,急需开发一套安全、合理的用电用水管理系统。由于各种原因, 设计
3、这个系统。 通过这个系统中,方便供水和电的公司及时掌握跟踪客户的用电和用水情况,实现实时管理,在充分利用现有电力和水力资源的基础上,做好计划用电、优化用电、加强有序用电、提高电能和水能效益等提供技术支持。对没有及时缴纳电费和水费的住户给予警告和通知其快点缴纳费用。为此,我将用JAVA实现水电管理系统的设计!二 设计的目的:本课程设计采用面向对象语言及关系型数据库完成题目的设计。本课程设计将面向对象程序设计、 数据库原理及应用课程相结合,论联系实际, 分析解决实际问题的能力。从而提高我们的实践编程的能力。具体如下: 1. 进一步学习面向对象程序设计语言,关系型数据库基础知识2. 培养面向对象程序
4、设计、模块化程序设计的方法和能力3. 了解软件的编制过程及各环节的具体内容4. 提高程序调试技巧、软件设计能力和代码规范化等素质5. 分析问题、解决问题以及实际运用能力三需求分析:本系统实现如下功能:1、查询功能: 访问数据库, 查询用户有关信息。如用户的姓名、 楼号、 单元、 房间号、手机、帐号、电表型号、水表型号、电费、水费等。2、添加功能:访问数据库,添加用户的以上信息。名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 2 页,共 37 页 - - - - - - - - - 3
5、、删除功能: 访问数据库,删除用户信息,账户信息。4、关闭功能: 退出水电管理系统。5、系统总体框架图:登录界面输入用户名和密码四、总体设计: 1.经以上分析可以把此系统分为五个模块:第一个模块: 登录模块,此模块用来实现系统管理员的登录,也就是进入此系统的权限。第二个模块: 查询模块, 此模块可分为两部分用户信息部分,账号信息部分又因为账号信息部分又依赖于用户信息部分,所以此两部分又是一个统一的整。体。第三个模块:添加模块,此模块分为两部分,用户信息的添加,账户信息的添加,因为账户信息有依赖于用户信息的部分,所以在添加信息时,应该先添加用户信息,后添加账户信息。否则添加信息不能成功。这一点特
6、别重要!第四个模块:删除模块,此模块也包括两部分,用户信息的删除,账户信息的删除, 因为账户信息部分有依赖用户信息的部分,所以根据数据库的相关知识,删除有关信息时,应该先删除账户信息部分,后删除用户信息部分。第五个模块:退出系统模块,此模块用来实现退出系统功能。主对话框实现查询功能实现添加功能实现删除功能实现关闭功能名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 3 页,共 37 页 - - - - - - - - - 2. 数据库的设计: (1) 系统管理员用真确的用户名和密码登录
7、 (2) 查询用户信息: 1查询用户信息:输入真确的用户号码 2查询帐户信息:输入真确的帐号号码 (3)添加用户信息: 1首先输入真确的用户信息:包括用户号码、姓名、楼号、单元号、门牌号、用户手机。 2接着输入真确的帐户信息:包括用户的账单号、电表型号、水表型号、电费、水费、付费日期。 (4) 删除用户信息: 1删除用户信息:输入正确的用户号码 2删除账户信息:输入正确的账号密码(5) 数据分析:经过调查分析知, 数据处理过程中涉及到两个实体:用户和账单, 各实体应该具有以下属性:用户(用户编号,姓名,楼号,单元号,门牌号,手机号)系统管理员(用户名,密码)账单(账单号,电表型号,水表型号,电
8、费,水费,交费日期)由于一个用户对应一张账单,所以用户和账单是一对一的关系。因此完整的数据库E-R 图为 client用户信息表:表中列名数据类型可否为空说明用户号char not null( 主键 ) 用户编号姓名char null 用户姓名楼号char null 用户所在楼单元char null 用户所在单元门牌号Char null 用户的门牌号手机Char null 用户的手机accounting账单信息:名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 4 页,共 37 页 -
9、 - - - - - - - - 表中列名数据类型可否为空说明账单号char not null( 主键 ) 账单编号电表型号char null 电表的类型水表型号char null 水表的类型电费char null 用电的费用水费Char null 用水的费用交费日期Char null 交费的时间系统管理员登录表:表中列名数据类型可否为空说明用户名char not null( 主键 ) 登录系统的管理员密码char not null 验证是否符合授权3. 数据表的实现:管理员信息表:用户信息表:名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - -
10、 - - - 名师精心整理 - - - - - - - 第 5 页,共 37 页 - - - - - - - - - 账单信息表:用户信息与账单信息表的E-R 图:1.用户在 SQL Sever2000 实现的关系表联系:账单对应名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 6 页,共 37 页 - - - - - - - - - 五、详细设计: 1.登录模块:登录界面:名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - -
11、 名师精心整理 - - - - - - - 第 7 页,共 37 页 - - - - - - - - - 核心代码:import java.sql.*; import java.io.IOException; import java.io.PrintWriter; import java.sql.DriverManager; import java.awt.BorderLayout; import java.awt.Color; import java.awt.Container; import java.awt.FlowLayout; import java.awt.GridLayout;
12、import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.*; import javax.swing.JPasswordField; class MainFrame extends JFrame implements ActionListener JPasswordField jp = new JPasswordField(); Connection con ; ResultSet rs ; / 定义一个结果集对象 Statement st ; / 语句对象(可以接收和
13、执行一条SQL语句)JPanel panel_d3=new JPanel(); JButton button=new JButton(OK ); JLabel label1=new JLabel( 用户名 ); JLabel label3=new JLabel( 密码 ); JTextField text3=new JTextField(10); JTextField text1=new JTextField(10); JButton ok =new JButton( 确定 ); 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - -
14、名师精心整理 - - - - - - - 第 8 页,共 37 页 - - - - - - - - - MainFrame() super( 水电管理系统登录 ); this.setBounds(400,70,500,450); this .setResizable(false );/ 参数为 boolean 类型, resizeable值为 true时,表示在生成的窗体可以自由改变大小;resizeable值为 false时,表示生成的窗体大小是由程序员决定的,用户不可以自由改变该窗体的大小。BorderLayout border=new BorderLayout(); this.setLa
15、yout(border); this.add(BorderLayout.SOUTH, panel_d3); this.add(panel_d3); panel_d3.setLayout(null); label1.setBounds(40,300,40,20); text1.setBounds(90,300,150,20); label3.setBounds(255,300,40,20); jp .setBounds(300,300,150,20); button.setBounds(235,330,70,30); panel_d3.add(label1); panel_d3.add(text
16、1); panel_d3.add(label3); panel_d3.add(jp ); 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 9 页,共 37 页 - - - - - - - - - panel_d3.add(button); button.addActionListener(this); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE ); this.setVisible(true); publicvoid acti
17、onPerformed(ActionEvent e) if(e.getSource()=button) try Class.forName( sun.jdbc.odbc.JdbcOdbcDriver); JOptionPane.showMessageDialog( null, 数据库加载成功 ); catch(ClassNotFoundException ed) JOptionPane.showMessageDialog( null, 数据库加载失败 ); try con = DriverManager.getConnection( jdbc:odbc:zsl, system, jsj); s
18、t =con .createStatement(); JOptionPane.showMessageDialog( null, 数据库连接成功 ); catch(SQLException ew) 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 10 页,共 37 页 - - - - - - - - - JOptionPane.showMessageDialog( null, 数据库连接失败 ); String s1=text1.getText().trim(); String s2=
19、jp .getText().trim(); String s = ; String sql= select key from people where name=+s1+ ; try rs =st .executeQuery(sql); if( rs .next() System.out .print(s2); System.out .println(s2); s= rs .getString(1); s.trim(); System.out .print(s); System.out .println(s); if(s.equals(s2)=true) JOptionPane.showMes
20、sageDialog( null, 登录成功! ); MainFrame1 p=new MainFrame1(); else JOptionPane.showMessageDialog( null, 你输入的密码或用户名错误! ); 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 11 页,共 37 页 - - - - - - - - - else JOptionPane.showMessageDialog( null, 你输入的密码或用户名错误! ); catch(Exceptio
21、n ex) JOptionPane.showMessageDialog( null, 抱歉,程序出现异常! ); System.out .println(ex.getMessage(); try st .close(); con .close(); catch(SQLException e1 ) JOptionPane.showMessageDialog( null, 数据库关闭失败了! ); 2. 系统主界面:名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 12 页,共 37 页
22、- - - - - - - - - 3. 查询模块:名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 13 页,共 37 页 - - - - - - - - - 核心代码:class MainFrame1 extends JFrame implements ActionListener Connection con ; Statement st ; JButton a=new JButton( 查询 ); JButton b=new JButton( 添加 ); JButton c=n
23、ew JButton( 删除 ); JMenuBar bar =new JMenuBar(); JMenu menu =new JMenu( 选项 ); JMenuItem item4=new JMenuItem( 退出 ); GridLayout grid=new GridLayout(1,1,40,40);/GridLayout(int rows,int cols,int hgap,int vgap),rows - 行数 ,cols - 列数 ,hgap - 水平间距 ,vgap - 垂直间距MainFrame1() 名师资料总结 - - -精品资料欢迎下载 - - - - - - - -
24、 - - - - - - - - - - 名师精心整理 - - - - - - - 第 14 页,共 37 页 - - - - - - - - - super( 欢迎进入水电管理系统 ); this.setBounds(400,70,500,500);/this.setBounds(x, y, width, height),移动组件并调整其大小,由x ,y指定左上角的位置,由width和height指定大小this.setLayout(null); Container con=this.getContentPane(); con.setLayout(null); a.setBounds(65,
25、250,80,50); b.setBounds(215,250,80,50); c .setBounds(365,250,80,50); con.add(a); con.add(b); con.add(c ); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE ); a.addActionListener(this); b.addActionListener(this); c .addActionListener(this); item4.addActionListener(this); menu .add(item4); bar .add(
26、menu ); this.setJMenuBar(bar ); this.setVisible(true); publicvoid actionPerformed(ActionEvent e) if(e.getSource()=a) select a1=new select(); a1.setVisible(true); 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 15 页,共 37 页 - - - - - - - - - elseif(e.getSource()=b) inse
27、rt a2=new insert(); a2.setVisible(true); elseif(e.getSource()=c ) delete a3=new delete(); a3.setVisible(true); elseif(e.getSource()=item4) dispose(); System.exit(0);/this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); class select extends JFrame implements ActionListener Connection con ; ResultSet
28、rs ; ResultSet rs2 ; Statement st ; Statement st2 ; String cno , cname , building, unit, room , cellphone; String accountno, powerno, waterno, poweraccount, wateraccount, paymentdate; String s1 , s2 ; 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 16 页,共 37 页 - - - -
29、 - - - - - JButton button = new JButton( 查询 ); JLabel label1=new JLabel( 请输入客户号码 ); JLabel label2=new JLabel( 姓名 ); JLabel label3=new JLabel( 楼号 ); JLabel label4=new JLabel( 单元 ); JLabel label5=new JLabel( 门牌号码 ); JLabel label6=new JLabel( 手机 ); JLabel label7=new JLabel( 账单号 ); JLabel label8=new JLa
30、bel( 电表型号 ); JLabel label9=new JLabel( 水表型号 ); JLabel label10=new JLabel( 电费 ); JLabel label11=new JLabel( 水费 ); JLabel label12=new JLabel( 交费日期 ); JLabel label13=new JLabel( ); JLabel label14=new JLabel( ); JLabel label15=new JLabel( ); JLabel label16=new JLabel( ); JTextField text3=new JTextField(
31、10); JTextField text4=new JTextField(10); JTextField text5=new JTextField(10); JTextField text6=new JTextField(10); JTextField text7=new JTextField(10); JTextField text8=new JTextField(10); JTextField text9=new JTextField(10); JTextField text10=new JTextField(10); JTextField text11=new JTextField(10
32、); JTextField text12=new JTextField(10); JTextField text13=new JTextField(10); JTextField text14=new JTextField(10); JTextField text15=new JTextField(10); 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 17 页,共 37 页 - - - - - - - - - JTextField text16=new JTextField(10
33、); GridLayout grid=new GridLayout(5,5,0,0); select() super( 水电管理系统查询 ); this.setBounds(200,70,800,600); this.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE ); button.addActionListener(this); Container con=this.getContentPane(); con.setLayout(grid); con.add(label2); con.add(text3); con.add(label3); co
34、n.add(text4); con.add(label4); con.add(text5); con.add(label5); con.add(text6); con.add(label6); con.add(text7); con.add(label7); con.add(text8); con.add(label8); con.add(text9); con.add(label9); con.add(text10); con.add(label10); con.add(text11); con.add(label11); con.add(text12); 名师资料总结 - - -精品资料欢
35、迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 18 页,共 37 页 - - - - - - - - - con.add(label12); con.add(text13); con.add(label15); con.add(label16); con.add(label1); con.add(text16); con.add(button); publicvoid actionPerformed(ActionEvent e) if(e.getSource()=button) try Class.forName(
36、 sun.jdbc.odbc.JdbcOdbcDriver); JOptionPane.showMessageDialog( null, 数据库加载成功 ); catch(ClassNotFoundException ed) JOptionPane.showMessageDialog( null, 数据库加载失败 ); try con = DriverManager.getConnection( jdbc:odbc:zsl, system, jsj); st = con .createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CON
37、CUR_READ_ONLY); st2 = con .createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 19 页,共 37 页 - - - - - - - - - READ_ONLY); JOptionPane.showMessageDialog( null, 数据库连接成功 ); catch(SQLException ew) JOptionPane.sho
38、wMessageDialog( null, 数据库连接失败 ); s1 =text16.getText(); System.out .println(ok1); String sql=select o,cname,building,unit,room,cellphone, + accountno,powerno,waterno,poweraccount,wateraccount,paymentdate + from client,accounting where o=o and o=+s1 +; System.out .println(sql); try rs =st .executeQuer
39、y(sql); int count=0; if( rs .next() System.out .println(ok4); cno = rs .getString(cno); System.out .println(cno ); cname = rs .getString(cname); building=rs .getString(building); 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 20 页,共 37 页 - - - - - - - - - unit = rs .
40、getString(unit)+ unit; System.out .println(unit); room =rs .getString(room)+ room; cellphone=rs .getString(cellphone); System.out .println(cellphone); accountno=rs .getString(accountno); System.out .println(accountno); powerno=rs .getString(powerno); System.out .println(powerno); waterno=rs .getStri
41、ng(waterno); System.out .println(waterno); poweraccount=rs .getString(poweraccount); System.out .println(poweraccount); wateraccount=rs .getString(wateraccount); System.out .println(wateraccount); paymentdate=rs .getString(paymentdate); System.out .println(paymentdate); +count; if(count=0) JOptionPa
42、ne.showMessageDialog( null, 对不起,没有您要查找的用户信息! ); else System.out .println( 显示了 ); text16.setText(cno ); text3.setText(cname ); text4.setText(building); 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 21 页,共 37 页 - - - - - - - - - text5.setText(unit); text6.setText(room
43、 ); text7.setText(cellphone); text8.setText(accountno); text9.setText(powerno); text10.setText(waterno); text11.setText(poweraccount); text12.setText(wateraccount); text13.setText(paymentdate); System.out .println( 找到了 ); catch(Exception ex) JOptionPane.showMessageDialog( null, 抱歉,程序出现异常! ); System.
44、out .println(ex.getMessage(); try st .close(); con .close(); catch(SQLException e1 ) JOptionPane.showMessageDialog( null, 数据库关闭失败了! ); 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 22 页,共 37 页 - - - - - - - - - 4. 添加模块:核心代码:class insert extends JFrame implements Act
45、ionListener JLabel label1=new JLabel( 请输入客户号码 ); JLabel label2=new JLabel( 姓名 ); JLabel label3=new JLabel( 楼号 ); JLabel label4=new JLabel( 单元 ); JLabel label5=new JLabel( 门牌号码 ); JLabel label6=new JLabel( 手机 ); 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 23 页,共 37
46、 页 - - - - - - - - - JLabel label7=new JLabel( 请输入账户号 ); JLabel label8=new JLabel( 客户号码 ); JLabel label9=new JLabel( 电表型号 ); JLabel label10=new JLabel( 水表型号 ); JLabel label11=new JLabel( 电费 ); JLabel label12=new JLabel( 水费 ); JLabel label13=new JLabel( 交费日期 ); JLabel a=new JLabel( ); JLabel b=new JL
47、abel( ); JLabel c =new JLabel( ); JLabel d=new JLabel( ); JLabel e=new JLabel( ); JLabel f =new JLabel( ); JLabel g=new JLabel( ); JLabel a1 =new JLabel( ); JLabel a2 =new JLabel( ); JLabel a3 =new JLabel( ); JLabel a4 =new JLabel( ); JTextField text3=new JTextField(10); JTextField text4=new JTextFi
48、eld(10); JTextField text5=new JTextField(10); JTextField text6=new JTextField(10); JTextField text7=new JTextField(10); JTextField text8=new JTextField(10); JTextField text9=new JTextField(10); JTextField text10=new JTextField(10); JTextField text11=new JTextField(10); 名师资料总结 - - -精品资料欢迎下载 - - - - -
49、 - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 24 页,共 37 页 - - - - - - - - - JTextField text12=new JTextField(10); JTextField text13=new JTextField(10); JTextField text14=new JTextField(10); JTextField text15=new JTextField(10); JTextField text16=new JTextField(10); JTextField text17=new JTextFie
50、ld(10); JTextField text18=new JTextField(10); JTextField text19=new JTextField(10); JTextField text20=new JTextField(10); JTextField text21=new JTextField(10); JTextField text22=new JTextField(10); JTextField text23=new JTextField(10); JTextField text24=new JTextField(10); JTextField text25=new JTex