企業(yè)用電管理系統(tǒng)設(shè)計(jì)_第1頁(yè)
企業(yè)用電管理系統(tǒng)設(shè)計(jì)_第2頁(yè)
企業(yè)用電管理系統(tǒng)設(shè)計(jì)_第3頁(yè)
企業(yè)用電管理系統(tǒng)設(shè)計(jì)_第4頁(yè)
企業(yè)用電管理系統(tǒng)設(shè)計(jì)_第5頁(yè)
已閱讀5頁(yè),還剩118頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

年4月19日企業(yè)用電管理系統(tǒng)設(shè)計(jì)文檔僅供參考,不當(dāng)之處,請(qǐng)聯(lián)系改正。數(shù)據(jù)庫(kù)課程實(shí)訓(xùn)報(bào)告(--第2學(xué)期)題目:企業(yè)用電管理系統(tǒng)專業(yè)軟件工程學(xué)生姓名成曉偉班級(jí)軟件141學(xué)號(hào)指導(dǎo)教師徐靜完成日期.7.1目錄TOC\o"1-5"\h\z\u目錄 21課題內(nèi)容和要求 11.1課題描述 11.2課題要求 12需求分析 12.1對(duì)功能的規(guī)定 12.2數(shù)據(jù)需求分析 23系統(tǒng)設(shè)計(jì) 33.1功能模塊設(shè)計(jì) 33.2數(shù)據(jù)庫(kù)概念設(shè)計(jì) 43.2.2E-R圖 43.3數(shù)據(jù)庫(kù)邏輯設(shè)計(jì) 53.4數(shù)據(jù)庫(kù)物理設(shè)計(jì) 53.5數(shù)據(jù)庫(kù)表間聯(lián)系 64系統(tǒng)實(shí)現(xiàn) 64.1登陸模塊實(shí)現(xiàn) 64.2查詢模塊實(shí)現(xiàn) 74.3添加模塊實(shí)現(xiàn) 84.4刪除模塊實(shí)現(xiàn) 94.5修改模塊實(shí)現(xiàn) 104.6生成電費(fèi)單模塊實(shí)現(xiàn) 105代碼調(diào)試與功能測(cè)試 115.1測(cè)試方案 115.2測(cè)試結(jié)果 126收獲與體會(huì) 16參考文獻(xiàn) 17附錄 18附錄1源程序部分清單 18企業(yè)用電管理系統(tǒng)設(shè)計(jì)1課題內(nèi)容和要求1.1課題描述系統(tǒng)設(shè)計(jì)的的信息有:用電企業(yè)(用電企業(yè)編號(hào)、用電企業(yè)名、地址、電話、聯(lián)系人);電費(fèi)信息(谷價(jià)、峰價(jià));用電情況(用電企業(yè)編號(hào)、谷電量、峰電量、年月、年合計(jì)用電量、年合計(jì)用電費(fèi))。1.2課題要求要求能夠進(jìn)行如下操作:能夠統(tǒng)計(jì)各個(gè)用電企業(yè)的月耗電量以及電費(fèi);能夠統(tǒng)計(jì)查詢各個(gè)用電企業(yè)的總的谷電量和峰電量;能夠統(tǒng)計(jì)該地區(qū)的峰谷電量比例以及電費(fèi)情況;能維護(hù)基本數(shù)據(jù);用戶分級(jí)管理,人機(jī)界面良好。2需求分析2.1對(duì)功能的規(guī)定1、理解需求理解需求是在問(wèn)題及其最終解決方案之間架設(shè)橋梁的第一步。開發(fā)者只有和用戶充分理解了需求之后才能開始設(shè)計(jì)系統(tǒng),否則,對(duì)需求定義的任何改進(jìn),設(shè)計(jì)上都必須大量的返工。下面是對(duì)系統(tǒng)的終端用戶和客戶調(diào)研后得到的需求規(guī)格說(shuō)明書。(1)由于使用者為相關(guān)電力部門及學(xué)習(xí)使用,系統(tǒng)開始時(shí),便能夠進(jìn)入到歡迎界面。

(2)進(jìn)入到系統(tǒng)之后,友好的界面能夠很清晰的分為企業(yè)信息管理跟企業(yè)用電信息管理兩大選擇。(3)點(diǎn)擊企業(yè)信息管理,下拉菜單中選項(xiàng)能夠?qū)崿F(xiàn)對(duì)企業(yè)信息的查詢、添加、修改、刪除操作。

(4)點(diǎn)擊企業(yè)用電管理信息,下拉菜單中選項(xiàng)能夠?qū)崿F(xiàn)對(duì)企業(yè)用電管理信息的查詢、添加、修改和刪除操作。

(5)系統(tǒng)客戶端運(yùn)行在Windows平臺(tái)下,服務(wù)器能夠運(yùn)行在Windows或Unix平臺(tái)下。系統(tǒng)還應(yīng)該有一個(gè)較好的圖形用戶界面。

(6)系統(tǒng)應(yīng)該有很好的可擴(kuò)展性。2、需求分析需求分析是從客戶的需求中提取出軟件系統(tǒng)能夠幫助用戶解決的業(yè)務(wù)問(wèn)題,經(jīng)過(guò)對(duì)用戶業(yè)務(wù)問(wèn)題的分析,確定系統(tǒng)的功能需求。這個(gè)步驟是對(duì)理解需求的升華,直接關(guān)系到該系統(tǒng)的質(zhì)量。分析的根本目的是在開發(fā)者和提出需求的人之間建立一種理解和溝通機(jī)制,因此,系統(tǒng)的需求分析也應(yīng)該是開發(fā)人員和用戶或客戶一起完成的。2.2對(duì)性能的規(guī)定1、精度在精度需求上,根據(jù)使用需要,在各項(xiàng)數(shù)據(jù)的輸入,輸出及傳輸過(guò)程中,能夠滿足各種精度的需求。如:根據(jù)關(guān)鍵字精度的不同,查找可分為精確查找和泛型查找,精確查找可精確匹配系統(tǒng)使用者所知道的企業(yè)名稱及編號(hào)快速便捷的查詢所要知道的信息。2、時(shí)間特性要求在軟件方面,響應(yīng)時(shí)間,更新處理時(shí)間都比較快且迅速,完全滿足用戶要求。3、靈活性當(dāng)用戶需求,如操作方式,運(yùn)行環(huán)境,結(jié)果精度,數(shù)據(jù)結(jié)構(gòu)于其它軟件接口等發(fā)生變化時(shí),設(shè)計(jì)的軟件要做適當(dāng)調(diào)整,靈活性非常大。2.2數(shù)據(jù)需求分析數(shù)據(jù)字典(1)factory名稱:factory名稱:factory別名:無(wú)描述:企業(yè)的基本信息組成:factory=(num+facname+repname+tel+usefnum+usegnum+usemoney)(2)worker名稱:worker名稱:worker別名:無(wú)描述:?jiǎn)T工及管理員的基本信息組成:worker=(id+workername+password+level)3系統(tǒng)設(shè)計(jì)3.1功能模塊設(shè)計(jì)3.2數(shù)據(jù)庫(kù)概念設(shè)計(jì)3.2.1實(shí)體屬性圖3.2.2E-R圖3.3數(shù)據(jù)庫(kù)邏輯設(shè)計(jì)企業(yè)(編號(hào),企業(yè)名,法人代表)電價(jià)(峰電量,谷電量,峰電價(jià),谷電價(jià),總電費(fèi))系統(tǒng)用戶(編號(hào),姓名,密碼,權(quán)限)3.4數(shù)據(jù)庫(kù)物理設(shè)計(jì)表一:factory列名數(shù)據(jù)類型允許Null值numvarchar(50)是facnamevarchar(50)是repnamevarchar(50)是telvarchar(50)是usefnumint是usegnumint是usemoneyint是numfacnamerepnametelusefnumusegnumusemoney001新華書店陳國(guó)勇131410222333002蘇果超市陳博文151622532863003微軟公司畢世勇368524674952004樂(lè)天瑪特丁小杰301127943105005三廠中學(xué)陳家勇242219742875表二:worker列名數(shù)據(jù)類型允許Null值idint否workernamevarchar(50)否passwordvarchar(50)否[level]int否idworkernamepassword[level]111張三1234561112李四1234561113熊大1234562114熊二12345623.5數(shù)據(jù)庫(kù)表間聯(lián)系數(shù)據(jù)庫(kù)中所建的兩張表factory與worker之間并沒(méi)有任何直接的聯(lián)系,一個(gè)代表的是企業(yè)信息,一個(gè)代表的是員工信息。4系統(tǒng)實(shí)現(xiàn)4.1登陸模塊實(shí)現(xiàn)privateclassButtonactionPerformedimplementsActionListener//為登陸按鈕ButtonactionPerformed添加事件監(jiān)視器{ publicvoidactionPerformed(ActionEvente)//從worker表中獲得元組信息進(jìn)行登陸,下面為獲得元組登陸代碼 { a=username2.getText(); s=password2.getText();try { conn=DriverManager.getConnection(url,user,password); conn.setAutoCommit(true); System.out.println("和數(shù)據(jù)庫(kù)已經(jīng)建立連接?。?!"); stmt=(Statement)conn.createStatement(); rs=(ResultSet)stmt.executeQuery("select*fromworker");if(c.equals(a)&&b.equals(s)) { message.setText("姓名和密碼不能為空"); } elseif(true) { while(rs.next()) { if(rs.getString(2).equals(a)&&rs.getString(3).equals(s)&&rs.getInt(4)==level) { message.setText("數(shù)據(jù)庫(kù)連接成功!"); if(level==1) { operate2app2=newoperate2(); app2.setLocationRelativeTo(null); } else { operateapp3=newoperate(); app3.setLocationRelativeTo(null); } } else { message.setText("用戶名和密碼或者身份不正確"); } } } rs.close(); stmt.close(); conn.close(); }4.2查詢模塊實(shí)現(xiàn)privateclassButtonactionPerformedimplementsActionListener//為查詢按鈕ButtonactionPerformed添加事件監(jiān)視器 { publicvoidactionPerformed(ActionEvente)//從worker表中獲取元組,而且顯示在系統(tǒng)上 { facname=search.getText(); try { conn=DriverManager.getConnection(url,user,password); conn.setAutoCommit(true); System.out.println("和數(shù)據(jù)庫(kù)已經(jīng)建立連接?。。?); stmt=(Statement)conn.createStatement(); rs=(ResultSet)stmt.executeQuery("select*fromfactory"); 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添加模塊實(shí)現(xiàn)privateclassButtonactionPerformedimplementsActionListener//為添加按鈕ButtonactionPerformed添加事件監(jiān)視器 { publicvoidactionPerformed(ActionEvente)//在系統(tǒng)內(nèi)輸入要添加的元組信息,經(jīng)過(guò)添加按鈕添加到數(shù)據(jù)庫(kù)中的factory表內(nèi) { 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("和數(shù)據(jù)庫(kù)已經(jīng)建立連接!??!"); prepstmt1=(PreparedStatement)conn.prepareStatement("INSERTINTOfactory(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刪除模塊實(shí)現(xiàn)privateclassButtonactionPerformedimplementsActionListener { publicvoidactionPerformed(ActionEvente) { x1=text1.getText(); try { conn=DriverManager.getConnection(url,user,password); conn.setAutoCommit(true); System.out.println("和數(shù)據(jù)庫(kù)已經(jīng)建立連接!??!"); stmt=(Statement)conn.createStatement(); stmt.executeUpdate("deletefromfactorywherenum="+x1); conn.close(); }4.5修改模塊實(shí)現(xiàn)privateclassButtonactionPerformedimplementsActionListener { publicvoidactionPerformed(ActionEvente) { 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("和數(shù)據(jù)庫(kù)已經(jīng)建立連接?。?!"); prepstmt2=(PreparedStatement)conn.prepareStatement("updatefactorysetnum=?,usegnum=?,usefnum=?,usemoney=?wherenum=?"); 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生成電費(fèi)單模塊實(shí)現(xiàn)privateclassButtonactionPerformedimplementsActionListener { publicvoidactionPerformed(ActionEvente) { facname=search.getText();try { conn=DriverManager.getConnection(url,user,password); conn.setAutoCommit(true); System.out.println("和數(shù)據(jù)庫(kù)已經(jīng)建立連接!!!"); stmt=(Statement)conn.createStatement(); rs=(ResultSet)stmt.executeQuery("select*fromfactory"); 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代碼調(diào)試與功能測(cè)試5.1測(cè)試方案(1)分別輸入用戶、管理員查看登陸進(jìn)去后的界面(2)分別用用戶和管理員查詢企業(yè)用電信息(3)添加企業(yè)用電信息(4)修改企業(yè)用電信息(5)刪除企業(yè)用電信息(6)生成電費(fèi)單5.2測(cè)試結(jié)果管理員登陸管理員登陸后的界面管理員登陸后查詢的界面用戶登陸后查詢的界面點(diǎn)擊添加后的界面輸入數(shù)據(jù)添加成功點(diǎn)擊修改進(jìn)行修改信息修改成功點(diǎn)擊刪除后出現(xiàn)的界面刪除成功點(diǎn)擊生成電費(fèi)單出現(xiàn)的界面在桌面生成的電費(fèi)單6收獲與體會(huì)一、這次課程設(shè)計(jì)的心得體會(huì)經(jīng)過(guò)實(shí)踐我的收獲如下:一開始接觸數(shù)據(jù)結(jié)構(gòu)課程設(shè)計(jì)真的挺難的,好多都不會(huì),不是邏輯方面的問(wèn)題,而不具備動(dòng)手能力,腦子里總有一團(tuán)火,比如對(duì)于這個(gè)題目,一開始有很多的想法,想到了從邏輯上怎么實(shí)現(xiàn)她,要編寫哪些程序,可是一到需要編寫了就開始為難了,能夠說(shuō)是幾乎不知道從哪里入手,參考了書本里的程序,仿照她的結(jié)構(gòu)一步一步做下來(lái),現(xiàn)在對(duì)于單鏈表的各種操作已經(jīng)算是比較熟練了,但我知道光有理論知識(shí)還遠(yuǎn)遠(yuǎn)不夠,需要多動(dòng)手,寫的多了自然就能手到擒來(lái)。二、根據(jù)我在實(shí)習(xí)中遇到得問(wèn)題,我將在以后的學(xué)習(xí)過(guò)程中注意以下幾點(diǎn):1、認(rèn)真上好專業(yè)實(shí)驗(yàn)課,多在實(shí)踐中鍛煉自己。2、寫程序的過(guò)程中要考慮周到,嚴(yán)密。3、在做設(shè)計(jì)的時(shí)候要有信心,有耐心,切勿浮躁。4、認(rèn)真的學(xué)習(xí)課本知識(shí),掌握課本中的知識(shí)點(diǎn),并在此基礎(chǔ)上學(xué)會(huì)靈活運(yùn)用。5、在課余時(shí)間里多寫程序,熟練掌握在調(diào)試程序的過(guò)程中所遇到的常見(jiàn)錯(cuò)誤,以便能節(jié)省調(diào)試程序的時(shí)間。參考文獻(xiàn)[1]錢雪忠,王燕玲,林挺.數(shù)據(jù)庫(kù)原理及技術(shù)[M].北京:清華大學(xué)出版社,.[2]錢雪忠,羅海馳,陳國(guó)俊.數(shù)據(jù)庫(kù)原理及技術(shù)課程設(shè)計(jì)[M].北京:清華大學(xué)出版社,.

附錄附錄1源程序部分清單附錄1.1record代碼importjava.awt.*;importjava.awt.event.*;importjava.sql.Connection;importjava.sql.DriverManager;importjava.sql.SQLException;importjava.sql.ResultSet;importjava.sql.Statement;importjavax.swing.*;publicclassRecordextendsJFrame{ privatestaticfinallongserialVersionUID=1L; privateJLabelusername,password; privateJTextFieldusername2; privateJTextFieldpassword2,message; privateJButtonbutton; privateJRadioButtonbox1,box2; privateButtonGroupbuttongroup; privateStringa,s; privateStringc=""; privateStringb=""; privateintlevel=2; //privateStringjuzi; publicRecord() { super("Record"); setSize(300,300); try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); }catch(Exceptione){} Containercontainer=getContentPane(); container.setBackground(Color.lightGray); container.setLayout(null); username=newJLabel("用戶名:",JLabel.RIGHT); password=newJLabel("密碼:",JLabel.RIGHT); buttongroup=newButtonGroup(); box1=newJRadioButton("員工",true); box2=newJRadioButton("管理員"); username2=newJTextField(20); password2=newJTextField(20); message=newJTextField("歡迎使用企業(yè)用電管理系統(tǒng)"); message.setHorizontalAlignment(JTextField.CENTER); button=newJButton("登錄"); 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); ButtonactionPerformedbuttoner=newButtonactionPerformed(); button.addActionListener(buttoner); RadioButtonHandlerhandler=newRadioButtonHandler(); 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); } publicstaticvoidmain(String[]args) { Record app=newRecord(); app.setLocationRelativeTo(null); } privateclassRadioButtonHandlerimplementsItemListener { publicvoiditemStateChanged(ItemEventevent) { if(box1.isSelected()) { message.setText("員工登錄"); level=2; } elseif(box2.isSelected()) { message.setText("管理員登錄"); level=1; } } } privateclassButtonactionPerformedimplementsActionListener { publicvoidactionPerformed(ActionEvente)//登錄 { a=username2.getText(); s=password2.getText(); try { Class.forName("driver"); } catch(ClassNotFoundExceptionarg0) { System.out.print("classnotfindexceptionoccur.messageis:"); } try{ Class.forName("driver");//加載驅(qū)動(dòng) } catch(ClassNotFoundExceptionevent){System.out.print("classnotfindexceptionoccur.messageis:");} Statementstmt; ResultSetrs; Stringurl="jdbc:sqlserver://localhost:1433;DatabaseName=企業(yè)用電"; Stringdriver="com.microsoft.sqlserver.jdbc.SQLServerDriver"; Stringuser="sa"; Stringpassword="123456"; Connectionconn=null; try { conn=DriverManager.getConnection(url,user,password); conn.setAutoCommit(true); System.out.println("和數(shù)據(jù)庫(kù)已經(jīng)建立連接?。?!"); stmt=(Statement)conn.createStatement(); rs=(ResultSet)stmt.executeQuery("select*fromworker"); if(c.equals(a)&&b.equals(s)) { message.setText("姓名和密碼不能為空"); } elseif(true) { while(rs.next()) { if(rs.getString(2).equals(a)&&rs.getString(3).equals(s)&&rs.getInt(4)==level) { message.setText("數(shù)據(jù)庫(kù)連接成功!"); if(level==1) { operate2app2=newoperate2(); app2.setLocationRelativeTo(null); } else { operateapp3=newoperate(); app3.setLocationRelativeTo(null); } } else { message.setText("用戶名和密碼或者身份不正確"); } } } rs.close(); stmt.close(); conn.close(); } catch(SQLExceptioneb) { System.out.print("SQLexceptionoccur.messageis:"); System.out.print(eb.getMessage()); } } }}附錄1.2operate代碼importjava.awt.Color;importjava.awt.Container;importjava.awt.event.ActionEvent;importjava.awt.event.ActionListener;importjava.sql.Connection;importjava.sql.DriverManager;importjava.sql.SQLException;importjavax.swing.JButton;importjavax.swing.JFrame;importjavax.swing.JLabel;importjavax.swing.JTextField;importjavax.swing.UIManager;importjava.sql.ResultSet;importjava.sql.Statement;publicclassoperateextendsJFrame{ privatestaticfinallongserialVersionUID=1L; privateJButtonb1,b2,b3,b4,b5,b6; privateJLabelc1,c2,c3,c4,c5,c6,c7; privateJTextFieldtext1,text2,text3,text4,text5,text6,text7; privateJTextFieldsearch; privateJLabelname; privateStringfacname; publicoperate() { super("operate"); setSize(700,400); try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); }catch(Exceptione){} Containercontainer=getContentPane(); name=newJLabel("輸入企業(yè)名:",JLabel.RIGHT); c1=newJLabel("企業(yè)編號(hào):",JLabel.RIGHT); c2=newJLabel("企業(yè)名稱:",JLabel.RIGHT); c3=newJLabel("企業(yè)代表人:",JLabel.RIGHT); c4=newJLabel("企業(yè)聯(lián)系電話:",JLabel.RIGHT); c5=newJLabel("企業(yè)谷電量:",JLabel.RIGHT); c6=newJLabel("企業(yè)峰電量:",JLabel.RIGHT); c7=newJLabel("企業(yè)用電費(fèi):",JLabel.RIGHT); b1=newJButton("查詢"); b2=newJButton("取消"); b3=newJButton("添加"); b4=newJButton("刪除"); b5=newJButton("修改"); b6=newJButton("生成電費(fèi)單"); text1=newJTextField(200); text2=newJTextField(200); text3=newJTextField(200); text4=newJTextField(200); text5=newJTextField(200); text6=newJTextField(200); text7=newJTextField(200); search=newJTextField(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); ButtonactionPerformedbuttoner=newButtonactionPerformed(); ButtonactionPerformed2buttoner2=newButtonactionPerformed2(); ButtonactionPerformed3buttoner3=newButtonactionPerformed3(); ButtonactionPerformed4buttoner4=newButtonactionPerformed4(); ButtonactionPerformed5buttoner5=newButtonactionPerformed5(); ButtonactionPerformed6buttoner6=newButtonactionPerformed6(); 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); } privateclassButtonactionPerformedimplementsActionListener { publicvoidactionPerformed(ActionEvente) { facname=search.getText(); try { Class.forName("driver"); } catch(ClassNotFoundExceptionarg0) { System.out.print("classnotfindexceptionoccur.messageis:"); } try{ Class.forName("driver");//加載驅(qū)動(dòng) } catch(ClassNotFoundExceptionevent){System.out.print("classnotfindexceptionoccur.messageis:");} Statementstmt; ResultSetrs; Stringurl="jdbc:sqlserver://localhost:1433;DatabaseName=企業(yè)用電"; Stringdriver="com.microsoft.sqlserver.jdbc.SQLServerDriver"; Stringuser="sa"; Stringpassword="123456"; Connectionconn=null; try { conn=DriverManager.getConnection(url,user,password); conn.setAutoCommit(true); System.out.println("和數(shù)據(jù)庫(kù)已經(jīng)建立連接!??!"); stmt=(Statement)conn.createStatement(); rs=(ResultSet)stmt.executeQuery("select*fromfactory"); 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(SQLExceptioneb) { System.out.print("SQLexceptionoccur.messageis:"); System.out.print(eb.getMessage()); } } } privateclassButtonactionPerformed2implementsActionListener { publicvoidactionPerformed(ActionEventevent) { System.exit(0); } } privateclassButtonactionPerformed3implementsActionListener { publicvoidactionPerformed(ActionEventevent) { insertapp3=newinsert(); app3.setLocationRelativeTo(null); } } privateclassButtonactionPerformed4implementsActionListener { publicvoidactionPerformed(ActionEventevent) { delectapp4=newdelect(); app4.setLocationRelativeTo(null); } } privateclassButtonactionPerformed5implementsActionListener { publicvoidactionPerformed(ActionEventevent) { updateapp5=newupdate(); app5.setLocationRelativeTo(null); } } privateclassButtonactionPerformed6implementsActionListener { publicvoidactionPerformed(ActionEventevent) { createapp6=newcreate(); app6.setLocationRelativeTo(null); } } publicstaticvoidmain(String[]args) { operateapp=newoperate(); app.setLocationRelativeTo(null); }}附錄1.3operate2代碼importjava.awt.Color;importjava.awt.Container;importjava.awt.event.ActionEvent;importjava.awt.event.ActionListener;importjava.sql.Connection;importjava.sql.DriverManager;importjava.sql.SQLException;importjavax.swing.JButton;importjavax.swing.JFrame;importjavax.swing.JLabel;importjavax.swing.JTextField;importjavax.swing.UIManager;importjava.sql.ResultSet;importjava.sql.Statement;publicclassoperate2extendsJFrame{ privatestaticfinallongserialVersionUID=1L; privateJButtonb1,b2,b3,b4; privateJLabelc1,c2,c3,c4,c5,c6,c7,d1,d2,d3,d4;privateJTextFieldtext1,text2,text3,text4,text5,text6,text7,ce1,ce2,ce3,ce4; privateJTextFieldsearch1,search2; privateJLabelname,name2,action1,action2; privateStringfacname1,facname2; publicoperate2() { super("operate2"); setSize(700,600); try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); }catch(Exceptione){} Containercontainer=getContentPane(); action1=newJLabel("查看客戶的資料",JLabel.RIGHT); action2=newJLabel("查看用戶的資料",JLabel.RIGHT); name=newJLabel("輸入企業(yè)名:",JLabel.RIGHT); c1=newJLabel("企業(yè)編號(hào):",JLabel.RIGHT); c2=newJLabel("企業(yè)名稱:",JLabel.RIGHT); c3=newJLabel("企業(yè)代表人:",JLabel.RIGHT); c4=newJLabel("企業(yè)聯(lián)系電話:",JLabel.RIGHT); c5=newJLabel("企業(yè)谷電量:",JLabel.RIGHT); c6=newJLabel("企業(yè)峰電費(fèi):",JLabel.RIGHT); c7=newJLabel("企業(yè)用電費(fèi):",JLabel.RIGHT); name2=newJLabel("輸入職工名:",JLabel.RIGHT); d1=newJLabel("職工編號(hào):",JLabel.RIGHT); d2=newJLabel("職工名稱:",JLabel.RIGHT); d3=newJLabel("職工密碼:",JLabel.RIGHT); d4=newJLabel("職工等級(jí):",JLabel.RIGHT); b1=newJButton("查詢"); b2=newJButton("取消"); b3=newJButton("查詢"); b4=newJButton("取消"); text1=newJTextField(200); text2=newJTextField(200); text3=newJTextField(200); text4=newJTextField(200); text5=newJTextField(200); text6=newJTextField(200); text7=newJTextField(200); ce1=newJTextField(200); ce2=newJTextField(200); ce3=newJTextField(200); ce4=newJTextField(200); search1=newJTextField(60); search2=newJTextField(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); ButtonactionPerformedbuttoner=newButtonactionPerformed(); ButtonactionPerformed2buttoner2=newButtonactionPerformed2(); ButtonactionPerformed3buttoner3=newButtonactionPerformed3(); 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); } privateclassButtonactionPerformedimplementsActionListener { publicvoidactionPerformed(ActionEvente) { facname1=search1.getText(); try { Class.forName("driver"); } catch(ClassNotFoundExceptionarg0) { System.out.print("classnotfindexceptionoccur.messageis:"); } try{ Class.forName("driver");//加載驅(qū)動(dòng) } catch(ClassNotFoundExceptionevent){System.out.print("classnotfindexceptionoccur.messageis:");} Statementstmt; ResultSetrs; Stringurl="jdbc:sqlserver://localhost:1433;DatabaseName=企業(yè)用電"; Stringdriver="com.microsoft.sqlserver.jdbc.SQLServerDriver"; Stringuser="sa"; Stringpassword="123456"; Connectionconn=null; try { conn=DriverManager.getConnection(url,user,password); conn.setAutoCommit(true); System.out.println("和數(shù)據(jù)庫(kù)已經(jīng)建立連接?。。?); stmt=(Statement)conn.createStatement(); rs=(ResultSet)stmt.executeQuery("select*fromfactory"); 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(SQLExceptioneb) { System.out.print("SQLexceptionoccur.messageis:"); System.out.print(eb.getMessage()); } } } privateclassButtonactionPerformed2implementsActionListener { publicvoidactionPerformed(ActionEventevent) { System.exit(0); } } privateclassButtonactionPerformed3implementsActionListener { publicvoidactionPerformed(ActionEvente) { facname2=search2.getText(); try { Class.forName("driver"); } catch(ClassNotFoundExceptionarg0) { System.out.print("classnotfindexceptionoccur.messageis:"); } try{ Class.forName("driver");//加載驅(qū)動(dòng) } catch(ClassNotFoundExceptionevent){System.out.print("classnotfindexceptionoccur.messageis:");} Statementstmt; ResultSetrs; Stringurl="jdbc:sqlserver://localhost:1433;DatabaseName=企業(yè)用電"; Stringdriver="com.microsoft.sqlserver.jdbc.SQLServerDriver"; Stringuser="sa"; Stringpassword="123456"; Connectionconn=null; try { conn=DriverManager.getConnection(url,user,password); conn.setAutoCommit(true); System.out.println("和數(shù)據(jù)庫(kù)已經(jīng)建立連接?。?!"); stmt=(Statement)conn.createStatement(); rs=(ResultSet)stmt.executeQuery("select*fromworker"); 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(SQLExceptioneb) { System.out.print("SQLexceptionoccur.messageis:"); System.out.print(eb.getMessage()); } } } publicstaticvoidmain(String[]args) { operate2add=newoperate2(); add.setLocationRelativeTo(null); }}附錄1.4insert代碼importjava.awt.Color;importjava.awt.Container;importjava.awt.event.ActionEvent;importjava.awt.event.ActionListener;importjava.sql.Connection;importjava.sql.DriverManager;importjava.sql.SQLException;importjavax.swing.JButton;importjavax.swing.JFrame;importjavax.swing.JLabel;importjavax.swing.JTextField;importjavax.swing.UIManager;importjava.sql.PreparedStatement;publicclassinsertextendsJFrame{ privatestaticfinallongserialVersionUID=1L; privateJButtonb1,b2; privateJLabelc1,c2,c3,c4,c5,c6,c7,name; privateJTextFieldtext1,text2,text3,text4,text5,text6,text7; privateString

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

評(píng)論

0/150

提交評(píng)論