




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)
文檔簡介
.-..--可修編...word...---可修編.數(shù)據(jù)庫課程實訓(xùn)報告(2021--2021年度第2學(xué)期)題目:企業(yè)用電管理系統(tǒng)專業(yè)軟件工程學(xué)生XX成曉偉班級軟件141學(xué)號1410075094指導(dǎo)教師X靜完成日期2021.7.1.-....word...-目錄TOC\o"1-5"\h\z\u目錄21課題內(nèi)容和要求11.1課題描述11.2課題要求12需求分析12.1對功能的規(guī)定12.2數(shù)據(jù)需求分析23系統(tǒng)設(shè)計33.1功能模塊設(shè)計33.2數(shù)據(jù)庫概念設(shè)計43.2.2E-R圖43.3數(shù)據(jù)庫邏輯設(shè)計53.4數(shù)據(jù)庫物理設(shè)計53.5數(shù)據(jù)庫表間聯(lián)系64系統(tǒng)實現(xiàn)64.1登陸模塊實現(xiàn)64.2查詢模塊實現(xiàn)74.3添加模塊實現(xiàn)84.4刪除模塊實現(xiàn)94.5修改模塊實現(xiàn)104.6生成電費單模塊實現(xiàn)105代碼調(diào)試與功能測試115.1測試方案115.2測試結(jié)果126收獲與體會16參考文獻(xiàn)17附錄18附錄1源程序局部清單18....word..企業(yè)用電管理系統(tǒng)設(shè)計1課題內(nèi)容和要求1.1課題描述系統(tǒng)設(shè)計的的信息有:用電企業(yè)〔用電企業(yè)編號、用電企業(yè)名、地址、、聯(lián)系人〕;電費信息〔谷價、峰價〕;用電情況〔用電企業(yè)編號、谷電量、峰電量、年月、年合計用電量、年合計用電費〕。1.2課題要求要求能夠進(jìn)展如下操作:能夠統(tǒng)計各個用電企業(yè)的月耗電量以及電費;能夠統(tǒng)計查詢各個用電企業(yè)的總的谷電量和峰電量;能夠統(tǒng)計該地區(qū)的峰谷電量比例以及電費情況;能維護(hù)根本數(shù)據(jù);用戶分級管理,人機界面良好。2需求分析2.1對功能的規(guī)定1、理解需求理解需求是在問題及其最終解決方案之間架設(shè)橋梁的第一步。開發(fā)者只有和用戶充分理解了需求之后才能開場設(shè)計系統(tǒng),否那么,對需求定義的任何改良,設(shè)計上都必須大量的返工。下面是對系統(tǒng)的終端用戶和客戶調(diào)研后得到的需求規(guī)格說明書。(1)由于使用者為相關(guān)電力部門及學(xué)習(xí)使用,系統(tǒng)開場時,便可以進(jìn)入到歡送界面。
(2)進(jìn)入到系統(tǒng)之后,友好的界面可以很清晰的分為企業(yè)信息管理跟企業(yè)用電信息管理兩大選擇。(3)點擊企業(yè)信息管理,下拉菜單中選項可以實現(xiàn)對企業(yè)信息的查詢、添加、修改、刪除操作。
(4)點擊企業(yè)用電管理信息,下拉菜單中選項可以實現(xiàn)對企業(yè)用電管理信息的查詢、添加、修改和刪除操作。
(5)系統(tǒng)客戶端運行在Windows平臺下,效勞器可以運行在Windows或Unix平臺下。系統(tǒng)還應(yīng)該有一個較好的圖形用戶界面。
(6)系統(tǒng)應(yīng)該有很好的可擴展性。2、需求分析需求分析是從客戶的需求中提取出軟件系統(tǒng)能夠幫助用戶解決的業(yè)務(wù)問題,通過對用戶業(yè)務(wù)問題的分析,確定系統(tǒng)的功能需求。這個步驟是對理解需求的升華,直接關(guān)系到該系統(tǒng)的質(zhì)量。分析的根本目的是在開發(fā)者和提出需求的人之間建立一種理解和溝通機制,因此,系統(tǒng)的需求分析也應(yīng)該是開發(fā)人員和用戶或客戶一起完成的。2.2對性能的規(guī)定1、精度在精度需求上,根據(jù)使用需要,在各項數(shù)據(jù)的輸入,輸出及傳輸過程中,可以滿足各種精度的需求。如:根據(jù)關(guān)鍵字精度的不同,查找可分為準(zhǔn)確查找和泛型查找,準(zhǔn)確查找可準(zhǔn)確匹配系統(tǒng)使用者所知道的企業(yè)名稱及編號快速便捷的查詢所要知道的信息。2、時間特性要求在軟件方面,響應(yīng)時間,更新處理時間都比擬快且迅速,完全滿足用戶要求。3、靈活性當(dāng)用戶需求,如操作方式,運行環(huán)境,結(jié)果精度,數(shù)據(jù)構(gòu)造于其他軟件接口等發(fā)生變化時,設(shè)計的軟件要做適當(dāng)調(diào)整,靈活性非常大。2.2數(shù)據(jù)需求分析數(shù)據(jù)字典〔1〕factory名稱:factory名稱:factory別名:無描述:企業(yè)的根本信息組成:factory=〔num+faame+repname+tel+usefnum+usegnum+usemoney〕(2)worker名稱:worker名稱:worker別名:無描述:員工及管理員的根本信息組成:worker=〔id+workername+password+level〕3系統(tǒng)設(shè)計3.1功能模塊設(shè)計3.2數(shù)據(jù)庫概念設(shè)計3.2.1實體屬性圖3.2.2E-R圖3.3數(shù)據(jù)庫邏輯設(shè)計企業(yè)〔編號,企業(yè)名,法人代表〕電價〔峰電量,谷電量,峰電價,谷電價,總電費〕系統(tǒng)用戶〔編號,XX,密碼,權(quán)限〕3.4數(shù)據(jù)庫物理設(shè)計表一:factory列名數(shù)據(jù)類型允許Null值numvarchar(50)是faamevarchar(50)是repnamevarchar(50)是telvarchar(50)是usefnumint是usegnumint是usemoneyint是numfaamerepnametelusefnumusegnumusemoney001新華書店陳國勇131410222333002蘇果超市陳博文151622532863003微軟公司畢世勇368524674952004樂天瑪特丁小杰301127943105005三廠中學(xué)陳家勇242219742875表二:worker列名數(shù)據(jù)類型允許Null值idint否workernamevarchar(50)否passwordvarchar(50)否[level]int否idworkernamepassword[level]111X三1234561112李四1234561113熊大1234562114熊二12345623.5數(shù)據(jù)庫表間聯(lián)系數(shù)據(jù)庫中所建的兩X表factory與worker之間并沒有任何直接的聯(lián)系,一個代表的是企業(yè)信息,一個代表的是員工信息。4系統(tǒng)實現(xiàn)4.1登陸模塊實現(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.setAutomit(true); System.out.println("和數(shù)據(jù)庫已經(jīng)建立連接?。?!");stmt=(Statement)conn.createStatement(); rs=(ResultSet)stmt.executeQuery("select*fromworker");if(c.equals(a)&&b.equals(s)) { message.setText("XX和密碼不能為空"); }elseif(true) {while(rs.next()) {if(rs.getString(2).equals(a)&&rs.getString(3).equals(s)&&rs.getInt(4)==level) { message.setText("數(shù)據(jù)庫連接成功!");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查詢模塊實現(xiàn)privateclassButtonactionPerformedimplementsActionListener//為查詢按鈕ButtonactionPerformed添加事件監(jiān)視器 {publicvoidactionPerformed(ActionEvente)//從worker表中獲取元組,并且顯示在系統(tǒng)上 { faame=search.getText();try { conn=DriverManager.getConnection(url,user,password); conn.setAutomit(true); System.out.println("和數(shù)據(jù)庫已經(jīng)建立連接?。?!"); stmt=(Statement)conn.createStatement(); rs=(ResultSet)stmt.executeQuery("select*fromfactory");while(rs.next()) {if(rs.getString(2).equals(faame)) { 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添加模塊實現(xiàn)privateclassButtonactionPerformedimplementsActionListener//為添加按鈕ButtonactionPerformed添加事件監(jiān)視器 {publicvoidactionPerformed(ActionEvente)//在系統(tǒng)內(nèi)輸入要添加的元組信息,通過添加按鈕添加到數(shù)據(jù)庫中的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.setAutomit(true); System.out.println("和數(shù)據(jù)庫已經(jīng)建立連接?。?!"); prepstmt1=(PreparedStatement)conn.prepareStatement("INSERTINTOfactory(num,faame,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刪除模塊實現(xiàn)privateclassButtonactionPerformedimplementsActionListener {publicvoidactionPerformed(ActionEvente) { x1=text1.getText();try { conn=DriverManager.getConnection(url,user,password); conn.setAutomit(true);System.out.println("和數(shù)據(jù)庫已經(jīng)建立連接!?。?); stmt=(Statement)conn.createStatement(); stmt.executeUpdate("deletefromfactorywherenum="+x1); conn.close(); }4.5修改模塊實現(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.setAutomit(true); System.out.println("和數(shù)據(jù)庫已經(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生成電費單模塊實現(xiàn)privateclassButtonactionPerformedimplementsActionListener {publicvoidactionPerformed(ActionEvente) { faame=search.getText();try { conn=DriverManager.getConnection(url,user,password); conn.setAutomit(true); System.out.println("和數(shù)據(jù)庫已經(jīng)建立連接?。?!"); stmt=(Statement)conn.createStatement(); rs=(ResultSet)stmt.executeQuery("select*fromfactory");while(rs.next()) {if(rs.getString(2).equals(faame)) { 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)試與功能測試5.1測試方案〔1〕分別輸入用戶、管理員查看登陸進(jìn)去后的界面〔2〕分別用用戶和管理員查詢企業(yè)用電信息〔3〕添加企業(yè)用電信息〔4〕修改企業(yè)用電信息〔5〕刪除企業(yè)用電信息〔6〕生成電費單5.2測試結(jié)果管理員登陸管理員登陸后的界面管理員登陸后查詢的界面用戶登陸后查詢的界面點擊添加后的界面輸入數(shù)據(jù)添加成功點擊修改良行修改信息修改成功點擊刪除后出現(xiàn)的界面刪除成功點擊生成電費單出現(xiàn)的界面在桌面生成的電費單6收獲與體會一、這次課程設(shè)計的心得體會通過實踐我的收獲如下:一開場接觸數(shù)據(jù)構(gòu)造課程設(shè)計真的挺難的,好多都不會,不是邏輯方面的問題,而不具備動手能力,腦子里總有一團(tuán)火,比方對于這個題目,一開場有很多的想法,想到了從邏輯上怎么實現(xiàn)他,要編寫哪些程序,但是一到需要編寫了就開場為難了,可以說是幾乎不知道從哪里入手,參考了書本里的程序,仿照他的構(gòu)造一步一步做下來,現(xiàn)在對于單鏈表的各種操作已經(jīng)算是比擬熟練了,但我知道光有理論知識還遠(yuǎn)遠(yuǎn)不夠,需要多動手,寫的多了自然就能手到擒來。二、根據(jù)我在實習(xí)中遇到得問題,我將在以后的學(xué)習(xí)過程中注意以下幾點:1、認(rèn)真上好專業(yè)實驗課,多在實踐中鍛煉自己。2、寫程序的過程中要考慮周到,嚴(yán)密。3、在做設(shè)計的時候要有信心,有耐心,切勿急躁。4、認(rèn)真的學(xué)習(xí)課本知識,掌握課本中的知識點,并在此根底上學(xué)會靈活運用。5、在課余時間里多寫程序,熟練掌握在調(diào)試程序的過程中所遇到的常見錯誤,以便能節(jié)省調(diào)試程序的時間。....word..參考文獻(xiàn)[1]錢雪忠,王燕玲,林挺.數(shù)據(jù)庫原理及技術(shù)[M].:清華大學(xué),2021.[2]錢雪忠,羅海馳,陳國俊.數(shù)據(jù)庫原理及技術(shù)課程設(shè)計[M].:清華大學(xué),2021.附錄附錄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;privateuttonbutton;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=newutton("登錄"); 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ū)動 }catch(ClassNotFoundExceptionevent){System.out.print("classnotfindexceptionoccur.messageis:");} Statementstmt; ResultSetrs; Stringurl="jdbc:sqlserver://localhost:1433;DatabaseName=企業(yè)用電"; Stringdriver=".microsoft.sqlserver.jdbc.SQLServerDriver"; Stringuser="sa"; Stringpassword="123456"; Connectionconn=null;try { conn=DriverManager.getConnection(url,user,password); conn.setAutomit(true); System.out.println("和數(shù)據(jù)庫已經(jīng)建立連接?。?!"); stmt=(Statement)conn.createStatement(); rs=(ResultSet)stmt.executeQuery("select*fromworker");if(c.equals(a)&&b.equals(s)) { message.setText("XX和密碼不能為空"); }elseif(true) {while(rs.next()) {if(rs.getString(2).equals(a)&&rs.getString(3).equals(s)&&rs.getInt(4)==level) { message.setText("數(shù)據(jù)庫連接成功!");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.utton;importjavax.swing.JFrame;importjavax.swing.JLabel;importjavax.swing.JTextField;importjavax.swing.UIManager;importjava.sql.ResultSet;importjava.sql.Statement;publicclassoperateextendsJFrame{privatestaticfinallongserialVersionUID=1L;privateuttonb1,b2,b3,b4,b5,b6;privateJLabelc1,c2,c3,c4,c5,c6,c7;privateJTextFieldtext1,text2,text3,text4,text5,text6,text7;privateJTextFieldsearch;privateJLabelname;privateStringfaame;publicoperate() {super("operate"); setSize(700,400);try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); }catch(Exceptione){} Containercontainer=getContentPane(); name=newJLabel("輸入企業(yè)名:",JLabel.RIGHT); c1=newJLabel("企業(yè)編號:",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è)用電費:",JLabel.RIGHT); b1=newutton("查詢"); b2=newutton("取消"); b3=newutton("添加"); b4=newutton("刪除"); b5=newutton("修改"); b6=newutton("生成電費單"); 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) { faame=search.getText();try { Class.forName("driver"); }catch(ClassNotFoundExceptionarg0) { System.out.print("classnotfindexceptionoccur.messageis:"); }try{ Class.forName("driver");//加載驅(qū)動 }catch(ClassNotFoundExceptionevent){System.out.print("classnotfindexceptionoccur.messageis:");} Statementstmt; ResultSetrs; Stringurl="jdbc:sqlserver://localhost:1433;DatabaseName=企業(yè)用電"; Stringdriver=".microsoft.sqlserver.jdbc.SQLServerDriver"; Stringuser="sa"; Stringpassword="123456"; Connectionconn=null;try { conn=DriverManager.getConnection(url,user,password); conn.setAutomit(true); System.out.println("和數(shù)據(jù)庫已經(jīng)建立連接?。?!"); stmt=(Statement)conn.createStatement(); rs=(ResultSet)stmt.executeQuery("select*fromfactory");while(rs.next()) {if(rs.getString(2).equals(faame)) { 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.utton;importjavax.swing.JFrame;importjavax.swing.JLabel;importjavax.swing.JTextField;importjavax.swing.UIManager;importjava.sql.ResultSet;importjava.sql.Statement;publicclassoperate2extendsJFrame{privatestaticfinallongserialVersionUID=1L;privateuttonb1,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;privateStringfaame1,faame2;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è)編號:",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è)用電費:",JLabel.RIGHT); name2=newJLabel("輸入職工名:",JLabel.RIGHT); d1=newJLabel("職工編號:",JLabel.RIGHT); d2=newJLabel("職工名稱:",JLabel.RIGHT); d3=newJLabel("職工密碼:",JLabel.RIGHT); d4=newJLabel("職工等級:",JLabel.RIGHT); b1=newutton("查詢"); b2=newutton("取消"); b3=newutton("查詢"); b4=newutton("取消"); 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) { faame1=search1.getText();try { Class.forName("driver"); }catch(ClassNotFoundExceptionarg0) { System.out.print("classnotfindexceptionoccur.messageis:"); }try{ Class.forName("driver");//加載驅(qū)動 }catch(ClassNotFoundExceptionevent){System.out.print("classnotfindexceptionoccur.messageis:");} Statementstmt; ResultSetrs; Stringurl="jdbc:sqlserver://localhost:1433;DatabaseName=企業(yè)用電"; Stringdriver=".microsoft.sqlserver.jdbc.SQLServerDriver"; Stringuser="sa"; Stringpassword="123456"; Connectionconn=null;try { conn=DriverManager.getConnection(url,user,password); conn.setAutomit(true); System.out.println("和數(shù)據(jù)庫已經(jīng)建立連接?。?!"); stmt=(Statement)conn.createStatement(); rs=(ResultSet)stmt.executeQuery("select*fromfactory");while(rs.next()) {if(rs.getString(2).equals(faame1)) { 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) { faame2=search2.getText();try { Class.forName("driver"); }catch(ClassNotFoundExceptionarg0) { System.out.print("classnotfindexceptionoccur.messageis:"); }try{ Class.forName("driver");//加載驅(qū)動 }catch(ClassNotFoundExceptionevent){System.out.print("classnotfindexceptionoccur.messageis:");} Statementstmt; ResultSetrs; Stringurl="jdbc:sqlserver://localhost:1433;DatabaseName=企業(yè)用電"; Stringdriver=".microsoft.sqlserver.jdbc.SQLServerDriver"; Stringuser="sa"; Stringpassword="123456"; Connectionconn=null;try { conn=DriverManager.getConnection(url,user,password); conn.setAutomit(true); System.out.println("和數(shù)據(jù)庫已經(jīng)建立連接?。?!"); stmt=(Statement)conn.
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 二零二五年度分公司股權(quán)轉(zhuǎn)讓及利益再分配執(zhí)行合同
- 2025版房產(chǎn)交易合同規(guī)范范本
- 二零二五年度美容院美容護(hù)膚產(chǎn)品研發(fā)與推廣合作協(xié)議書
- 二零二五年度大型活動贊助廣告合同協(xié)議
- 二零二五年度屋頂花園草皮供應(yīng)合同樣本
- 二零二五年度電子產(chǎn)品銷售與供應(yīng)鏈管理合同
- 二零二五年度環(huán)??萍紡S房及場地租賃服務(wù)協(xié)議
- 二零二五年度特色餐廳承包與員工福利保障合同
- 早讀神器課件WPS
- 二零二五年度車輛抵押貸款擔(dān)保與金融創(chuàng)新合同
- GB/T 45000-2024表面活性劑蔗糖脂肪酸酯的組成分析液相色譜法
- 《高速公路邊坡光伏光環(huán)境影響評價方法》
- 氯化亞砜MSDS安全技術(shù)說明書
- 腸梗阻護(hù)理新進(jìn)展
- 紅星美凱龍展廳租賃合同
- 單純皰疹患者的護(hù)理
- 養(yǎng)老護(hù)理員職責(zé)培訓(xùn)課件
- 酒店員工接待禮儀培訓(xùn)
- 車位租賃協(xié)議
- 醫(yī)療器械生產(chǎn)質(zhì)量管理手冊
- 2024年新滬教牛津版三年級上冊英語全冊教學(xué)課件
評論
0/150
提交評論