Java程序設(shè)計——商品銷售客戶管理_第1頁
Java程序設(shè)計——商品銷售客戶管理_第2頁
Java程序設(shè)計——商品銷售客戶管理_第3頁
Java程序設(shè)計——商品銷售客戶管理_第4頁
Java程序設(shè)計——商品銷售客戶管理_第5頁
已閱讀5頁,還剩17頁未讀 繼續(xù)免費閱讀

下載本文檔

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

文檔簡介

1、java程序設(shè)計報告年級專業(yè) 信息管理與信息系統(tǒng) 學(xué) 號 學(xué)生姓名 指導(dǎo)教師 二一四年六月 一、所用到的表的結(jié)構(gòu)及數(shù)據(jù)類型 customer顧客表表名customer顧客說明此表記錄顧客基本信息列名說明數(shù)據(jù)類型約束cno顧客編號char(10)主碼cname顧客姓名char(10)cage年齡intcsex性別char(2)取值為男或女,默認(rèn)女ctelephone顧客聯(lián)系方式char(15)非空操作人員表表名操作人員說明此表記錄操作人員信息列名說明數(shù)據(jù)類型約束用戶名用戶登錄名nchar(10)主碼密碼登錄密碼nchar(3)非空職位擔(dān)任職務(wù)nchar(10)二、程序的功能及實現(xiàn)結(jié)果截圖1、 登

2、錄功能打開java文件login.java運行后輸入錯誤的用戶名后出現(xiàn):輸入用戶名lucy 密碼:123點擊登錄進入操作界面:2、 添加功能下拉顧客信息系統(tǒng)菜單,選擇添加客戶信息添加信息前數(shù)據(jù)庫客戶表的內(nèi)容:沒有編號0000013添加客戶0000013:張薔,29,女,0000013據(jù)庫內(nèi)表變?yōu)椋鹤ⅲ?000015號是截圖之前添加進去的3、 查詢功能下拉客戶信息系統(tǒng)菜單,選擇查詢客戶信息,輸入客戶編碼0000013后點擊確定查詢此顧客:4、 修改功能下拉菜單客戶信息系統(tǒng),選擇修改客戶信息,重新輸入相應(yīng)的正確信息,將錯誤的覆蓋掉,此處將0000013張薔年齡改為32:數(shù)

3、據(jù)庫表內(nèi)內(nèi)容:5、 刪除功能下拉菜單客戶信息系統(tǒng),選擇刪除客戶信息,輸入客戶編碼0000013點擊確認(rèn):數(shù)據(jù)庫信息變?yōu)椋?000013號信息已經(jīng)刪除6、 退出系統(tǒng)功能下拉菜單客戶信息管理選擇退出:然后就退出了界面。三、 程序源代碼package loginsystem;import java.sql.*;import java.io.*;import javax.swing.*;import java.awt.*;import java.awt.event.*;import javax.swing.event.*; /登錄界面public class login extends jframep

4、rivate textfield namefield = new textfield(10);private jpasswordfield passwordfield = new jpasswordfield(15);private jbutton loginbutton = new jbutton(登 錄);private jbutton exitbutton = new jbutton(退 出);private jlabel titlelabel = new jlabel(夢之路時尚天堂商品管理系統(tǒng));private jlabel userlabel = new jlabel(用戶名);p

5、rivate jlabel pwdlabel = new jlabel(密 碼);private string user = null;private char pwd = null;public static void main(string args)login frame = new login();frame.settitle(系統(tǒng)登錄);frame.setdefaultcloseoperation(jframe.do_nothing_on_close);frame.setresizable(false);frame.setlocation(600,300);frame.pack();

6、frame.setvisible(true);public login()jpanel titlepanels = new jpanel();titlepanels.add(titlelabel);titlelabel.setfont(new java.awt.font(dialog,1,28);titlelabel.setforeground(color.red);jpanel labelpanels = new jpanel();labelpanels.setlayout(new gridlayout(2,1,10,40);labelpanels.add(userlabel);labelp

7、anels.add(pwdlabel);jpanel textfieldpanels = new jpanel();textfieldpanels.setlayout(new gridlayout(2,1,10,40);textfieldpanels.add(namefield);textfieldpanels.add(passwordfield);jpanel buttonpanels = new jpanel();buttonpanels.add(loginbutton);buttonpanels.add(exitbutton);jpanel picturepanels = new jpa

8、nel();jlabel lb = new jlabel(new imageicon(a.png); picturepanels.add(lb);jpanel dialogpanels = new jpanel();dialogpanels.setlayout(new borderlayout();dialogpanels.add(titlepanels,borderlayout.north);dialogpanels.add(labelpanels,borderlayout.west);dialogpanels.add(textfieldpanels,borderlayout.center)

9、;dialogpanels.add(buttonpanels,borderlayout.south);dialogpanels.add(picturepanels,borderlayout.east);add(dialogpanels);exitbutton.addactionlistener(new actionlistener()public void actionperformed(actionevent event)system.exit(0););loginbutton.addactionlistener(new actionlistener()public void actionp

10、erformed(actionevent event)connection con=login.getconnection();trystatement state=con.createstatement();user = namefield.gettext();pwd = passwordfield.getpassword();string pwds = new string(pwd);string sql = select 密碼 from 操作人員 where 用戶名 =+user+;resultset rs = state.executequery(sql);rs.next();if(p

11、wds.equals()|user.equals()joptionpane.showmessagedialog(null,用戶名或密碼不能為空!,錯誤,joptionpane.error_message);else if(!(rs.getstring(密碼).equals(pwds)joptionpane.showmessagedialog(null,用戶名或密碼錯誤!,錯誤,joptionpane.error_message);elsenew goods();dispose();login.closeconn(con);login.closestate(state);login.closer

12、s(rs);catch(sqlexception e)joptionpane.showmessagedialog(null,用戶名或密碼錯誤!,錯誤,joptionpane.error_message););public static void closeconn(connection conn)try if(conn != null)conn.close(); catch (sqlexception e) e.printstacktrace();public static void closestate(statement state) try if(state != null)state.

13、close(); catch (sqlexception e) e.printstacktrace();public static void closers(resultset rs) try if(rs != null)rs.close(); catch (sqlexception e) e.printstacktrace();/連接數(shù)據(jù)庫public static connection getconnection()string drivername = com.microsoft.sqlserver.jdbc.sqlserverdriver;string dburl = jdbc:sql

14、server:/localhost:1433;databasename=夢之路時尚天堂商品管理系統(tǒng); string username = sa; string userpwd = 123; connection conn=null; try class.forname(drivername); conn = drivermanager.getconnection(dburl, username, userpwd); catch (exception e) e.printstacktrace(); return conn;/菜單界面class goodsprivate static final

15、long serialversionuid=1l;static final int width=760;static final int height=510;jpopupmenu pop;jmenuitem item2;jframe f;jmenuitem item1;jpanel p;jtabbedpane tp;public goods()f=new jframe(夢之路時尚天堂商品管理系統(tǒng));jmenubar menubar1=new jmenubar();tp=new jtabbedpane();p=new jpanel();f.setjmenubar(menubar1);f.add

16、(p);p.add(tp);jmenu menu1=new jmenu(顧客信息系統(tǒng));menu1.setmnemonic(z);menubar1.add(menu1); jmenuitem item1=new jmenuitem(添加客戶信息); jmenuitem item2=new jmenuitem(修改客戶信息); jmenuitem item3=new jmenuitem(查詢客戶信息); jmenuitem item4=new jmenuitem(刪除客戶信息); jmenuitem item5=new jmenuitem(退出); item1.setaccelerator(ke

17、ystroke.getkeystroke(a,java.awt.event.ctrl_mask,false); item2.setaccelerator(keystroke.getkeystroke(u,java.awt.event.ctrl_mask,false); item3.setaccelerator(keystroke.getkeystroke(s,java.awt.event.ctrl_mask,false); item4.setaccelerator(keystroke.getkeystroke(d,java.awt.event.ctrl_mask,false); item5.s

18、etaccelerator(keystroke.getkeystroke(e,java.awt.event.ctrl_mask,false); menu1.add(item1); menu1.add(item2); menu1.add(item3); menu1.add(item4); menu1.add(item5); f.add(p); jlabel lb = new jlabel(new imageicon(sc.jpg); p.add(lb); f.setvisible(true); f.setsize(width,height); toolkit kit=toolkit.getdef

19、aulttoolkit(); dimension screensize=kit.getscreensize(); int width=screensize.width; int height=screensize.height; int x=(width-width)/2; int y=(height-height)/2; f.setlocation(x,y); item1.addactionlistener(new actionlistener() public void actionperformed(actionevent event) add con1=new add(); tp.ad

20、dtab(添加客戶信息,con1); tp.setenabledat(0,true); tp.settitleat(0,添加客戶信息); tp.setpreferredsize(new dimension(500,200); tp.settabplacement(jtabbedpane.top); tp.settablayoutpolicy(jtabbedpane.scroll_tab_layout); ); item2.addactionlistener(new actionlistener() public void actionperformed(actionevent event) u

21、pdate con2=new update(); tp.addtab(修改客戶信息,con2); tp.setenabledat(0,true); tp.settitleat(0,修改客戶信息); tp.setpreferredsize(new dimension(500,200); tp.settabplacement(jtabbedpane.top); tp.settablayoutpolicy(jtabbedpane.scroll_tab_layout); ); item3.addactionlistener(new actionlistener() public void action

22、performed(actionevent event) select con3=new select(); tp.addtab(查詢客戶信息,con3); tp.setenabledat(0,true); tp.settitleat(0,查詢客戶信息); tp.setpreferredsize(new dimension(500,200); tp.settabplacement(jtabbedpane.top); tp.settablayoutpolicy(jtabbedpane.scroll_tab_layout); ); item4.addactionlistener(new actio

23、nlistener() public void actionperformed(actionevent event) delect con4=new delect(); tp.addtab(刪除客戶信息,con4); tp.setenabledat(0,true); tp.settitleat(0,刪除客戶信息); tp.setpreferredsize(new dimension(500,200); tp.settabplacement(jtabbedpane.top); tp.settablayoutpolicy(jtabbedpane.scroll_tab_layout); ); ite

24、m5.addactionlistener(new actionlistener() public void actionperformed(actionevent e) system.exit(0); ); menu1.addmenulistener(new menulistener() public void menuselected(menuevent event) item2.setenabled(!item1.isselected(); public void menudeselected(menuevent event) public void menucanceled(menuev

25、ent event) ); /信息添加 class add extends jpanel public void add(component c,gridbagconstraints constraints,int x,int y,int w,int h) constraints.gridx=x; constraints.gridy=y; constraints.gridwidth=w; constraints.gridheight=h; add(c,constraints); add() gridbaglayout lay=new gridbaglayout(); setlayout(lay

26、); jbutton ok=new jbutton(確 定); jbutton clear=new jbutton(清 空); jbutton c=new jbutton(關(guān)閉); jlabel name=new jlabel(姓名); jlabel phone=new jlabel(電話號碼); jlabel sex=new jlabel(性別); jlabel num=new jlabel(客戶編碼); jlabel years=new jlabel(年齡); font font=new font(serief, font.bold, 22); final jtextfield namei

27、nput=new jtextfield(10); final jtextfield phoneinput=new jtextfield(10); final jtextfield sexinput=new jtextfield(10); final jtextfield numinput=new jtextfield(10); final jtextfield yearsinput=new jtextfield(10); jlabel title=new jlabel(顧客基本信息); title.setfont(font); title.setforeground(color.blue);

28、jbutton additionbutton=new jbutton(添加); gridbagconstraints constraints=new gridbagconstraints(); constraints.fill=gridbagconstraints.none; constraints.weightx=4; constraints.weighty=7; add(title,constraints,0,0,4,1); add(num,constraints,0,4,1,1); add(name,constraints,0,1,1,1); add(phone,constraints,

29、0,5,1,1); add(sex,constraints,0,3,1,1); add(years,constraints,0,2,1,1); add(nameinput,constraints,1,1,1,1); add(phoneinput,constraints,1,5,1,1); add(sexinput,constraints,1,3,1,1); add(numinput,constraints,1,4,1,1); add(yearsinput,constraints,1,2,1,1); add(ok,constraints,3,1,1,1); add(clear,constrain

30、ts,3,3,1,1); add(c,constraints,3,5,1,1); c.addactionlistener(new actionlistener() public void actionperformed(actionevent event) removeall(); ); ok.addactionlistener(new actionlistener() public void actionperformed(actionevent event) try class.forname(com.microsoft.sqlserver.jdbc.sqlserverdriver); c

31、atch(classnotfoundexception ex) string url=jdbc:sqlserver:/localhost:1433; databasename=夢之路時尚天堂商品管理系統(tǒng);string user=sa;string password=123; statement stmt; resultset rs; preparedstatement prestmt;string nametext=nameinput.gettext(); string phonetext=phoneinput.gettext(); string sextext=sexinput.gettex

32、t(); string numtext=numinput.gettext(); string yearstext=yearsinput.gettext(); tryconnection con= drivermanager.getconnection(url,user,password);prestmt=con.preparestatement(insert into customer顧客 values(?,?,?,?,?) );prestmt.setstring(5,phonetext);prestmt.setstring(2,nametext);prestmt.setstring(4,se

33、xtext);prestmt.setstring(1,numtext);prestmt.setstring(3,yearstext);prestmt.executeupdate();con.close();joptionpane.showmessagedialog(null,信息添加成功,ok,joptionpane.information_message); catch(sqlexception ex) ); clear.addactionlistener(new actionlistener() public void actionperformed(actionevent event)

34、nameinput.settext(); phoneinput.settext(); sexinput.settext(); numinput.settext(); yearsinput.settext(); ); /信息修改 class update extends jpanel public void add(component c,gridbagconstraints constraints,int x,int y,int w,int h) constraints.gridx=x; constraints.gridy=y; constraints.gridwidth=w; constra

35、ints.gridheight=h; add(c,constraints); update() gridbaglayout lay=new gridbaglayout(); setlayout(lay); jbutton ok=new jbutton(確 定); jbutton clear=new jbutton(清 空); jbutton c=new jbutton(關(guān)閉); jlabel name=new jlabel(姓名); jlabel phone=new jlabel(電話號碼); jlabel sex=new jlabel(性別); jlabel num=new jlabel(客

36、戶編碼); jlabel years=new jlabel(年齡); final jtextfield nameinput=new jtextfield(10); final jtextfield phoneinput=new jtextfield(10); final jtextfield sexinput=new jtextfield(10); final jtextfield numinput=new jtextfield(10); final jtextfield yearsinput=new jtextfield(10); jlabel title=new jlabel(修改基本信息

37、); font font=new font(serief, font.bold, 22); title.setfont(font); title.setforeground(color.blue);/設(shè)置標(biāo)簽前景色 jbutton additionbutton=new jbutton(添加); gridbagconstraints constraints=new gridbagconstraints(); constraints.fill=gridbagconstraints.none; constraints.weightx=4; constraints.weighty=7; add(tit

38、le,constraints,0,0,4,1); add(name,constraints,0,1,1,1); add(phone,constraints,0,5,1,1); add(sex,constraints,0,3,1,1); add(num,constraints,0,4,1,1); add(nameinput,constraints,1,1,1,1); add(phoneinput,constraints,1,5,1,1); add(sexinput,constraints,1,3,1,1);add(numinput,constraints,1,4,1,1); add(years,

39、constraints,0,2,1,1); add(yearsinput,constraints,1,2,1,1); add(ok,constraints,3,1,1,1); add(clear,constraints,3,3,1,1); add(c,constraints,3,5,1,1); c.addactionlistener(new actionlistener() public void actionperformed(actionevent e) removeall(); ); ok.addactionlistener(new actionlistener() public voi

40、d actionperformed(actionevent event) try class.forname(com.microsoft.sqlserver.jdbc.sqlserverdriver); catch(classnotfoundexception ex) string url=jdbc:sqlserver:/localhost:1433; databasename=夢之路時尚天堂商品管理系統(tǒng);string user=sa;string password=123; statement stmt; resultset rs; preparedstatement prestmt;str

41、ing nametext=nameinput.gettext(); string phonetext=phoneinput.gettext(); string sextext=sexinput.gettext(); string numtext=numinput.gettext(); string yearstext=yearsinput.gettext(); tryconnection conn= drivermanager.getconnection(url,user,password);prestmt=conn.preparestatement(update customer顧客 set

42、 cname=?,csex=?,ctelephone=?,cage=? where cno=?);prestmt.setstring(1,nametext);prestmt.setstring(2,sextext);prestmt.setstring(5,numtext);prestmt.setstring(4,yearstext);prestmt.setstring(3,phonetext);prestmt.executeupdate();prestmt.close();conn.close();joptionpane.showmessagedialog(null,信息修改成功,ok,jop

43、tionpane.information_message);catch(sqlexception ex) ex.printstacktrace(); ); clear.addactionlistener(new actionlistener() public void actionperformed(actionevent event) nameinput.settext(); phoneinput.settext(); sexinput.settext(); numinput.settext(); yearsinput.settext(); ); /信息刪除 class delect extends jpanel public void add(component c,gridbagconstraints constraints,int x,int y,int w,int h) constraints.gridx=x; constraints.gridy=y; constraints.gridwidth=w; constraints.gr

溫馨提示

  • 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)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論