




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認(rèn)領(lǐng)
文檔簡介
1、超市商品管理系統(tǒng)源代碼 import java.awt.*;import java.awt.event.*;import javax.swing.*;import java.sql.*;public class sale2 extends JFrame implements ActionListener /銷售界面private JPanel sM=new JPanel();/supermarket面板JLabel label1,label2;JTextField field1,field2;JButton button1,button2;String num=null,name=null,t
2、ime=null,add=null,t1=null,t2=null,t3=null;int price=0,countBG,n1;/ 價格/商品的賣出數(shù)量private JTextArea goodsShow=new JTextArea();/文本區(qū)private JScrollPane jsp=new JScrollPane(goodsShow); /滾動區(qū)域 設(shè)定內(nèi)容為 商品顯示的文本區(qū)private JButton pS=new JButton("銷售界面"),new JButton("銷售管理"),new JBut
3、ton("商品管理"),new JButton("用戶管理");/personty 按鈕private JLabel CD=new JLabel("清單號",JLabel.CENTER),new JLabel("編號",JLabel.CENTER),new JLabel("名稱",JLabel.CENTER),new JLabel("價格",JLabel.CENTER),new J
4、Label("生產(chǎn)日期",JLabel.CENTER),new JLabel("產(chǎn)地",JLabel.CENTER),new JLabel("數(shù)量",JLabel.CENTER);/帳單查詢時的商品顯示標(biāo)簽public sale2()label1=new JLabel("按編號查詢",JLabel.CENTER);label2=new JLabel("按帳單查詢",JLabel.CENTER);field1=new
5、JTextField(30);field2=new JTextField(30);button1=new JButton("查詢1");button2=new JButton("查詢2");sM.setLayout(null);field1.setBounds(100,120,150,22);field2.setBounds(600,120,150,22);label1.setBounds(100,90,150,30);label2.setBounds(600,90,150,30);button1.setBounds(26
6、0,120,80,22);button2.setBounds(760,120,80,22);button1.addActionListener(this);button2.addActionListener(this);sM.add(label1);sM.add(label2);sM.add(field1);sM.add(field2);sM.add(button1);sM.add(button2);for(int i=0;i<4;i+)pSi.setBounds(550+i*110,50,100,22);sM.add(pSi);pSi.addActionListener(thi
7、s);for(int i=0;i<7;i+)/6個標(biāo)簽的繪制CDi.setBounds(100+i*115,160,115,20);sM.add(CDi);jsp.setBounds(100,180,800,500);goodsShow.setLineWrap(true);addWindowListener(new WindowAdapter() public void windowClosing(WindowEvent e) System.exit(0););sM.add(jsp);this.add(sM);this.setTitle("銷售窗口&qu
8、ot;);this.setResizable(false);this.setBounds(0,0,1024,768);this.setVisible(true);public void actionPerformed(ActionEvent p)Connection con,con1;Statement sql,sql1;String url = "jdbc:odbc:driver=Microsoft Access Driver (*.mdb);DBQ=D:supermarket.mdb"ResultSet rs,rs1;if (p.getSource()=
9、button1)String num=field1.getText();try Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");catch (ClassNotFoundException f)System.out.println(""+f);try con=DriverManager.getConnection(url);sql=con.createStatement();rs=sql.executeQuery("SELECT count(goodsnum) F
10、ROM information where goodsnum='"+num+"'");while(rs.next()countBG=rs.getInt(1);System.out.println(countBG);rs=sql.executeQuery("SELECT * FROM goods where num='"+num+"'");while(rs.next()name=rs.getString(2)
11、;price=rs.getInt(3);time=rs.getString(4);add=rs.getString(5);n1=1;con.close();catch (SQLException g)System.out.println(g);if (n1=1) goodsShow.append(" (物品銷售量查詢) "+num+" "+name+" "+price+" "+time+" "+add+&qu
12、ot; "+countBG+"n");n1=0;else /goodsShow.setText(" ");num=null;name=null;price=0;time=null;add=null;JOptionPane.showMessageDialog(this," 輸入錯誤n 請重新輸入","提示",JOptionPane.WARNING_MESSAGE);if(p.getSource()=pS0)View2 frame=new
13、 View2();dispose();if(p.getSource()=pS2)Frm_Main frame=new Frm_Main();dispose();if(p.getSource()=pS3)View3 frame=new View3();dispose();if (p.getSource()=button2)String numb=field2.getText();int num=Integer.parseInt(numb);try Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");catch (Clas
14、sNotFoundException f)System.out.println(""+f);trycon=DriverManager.getConnection(url);sql=con.createStatement();rs=sql.executeQuery("SELECT goodsnum,count(goodsnum) FROM information where listnum="+num+" group by goodsnum");while(rs.next() con1=D
15、riverManager.getConnection(url);sql1=con1.createStatement();String number=rs.getString(1); countBG=rs.getInt(2);System.out.println(countBG+number+name+time+price+add);rs1=sql1.executeQuery("SELECT * FROM goods where num='"+number+"'");while (rs1.ne
16、xt()name=rs1.getString(2);price=rs1.getint(3);time=rs1.getString(4);add=rs1.getString(5);goodsShow.append(" "+num+" "+number+" "+name+" "+price+" "+time+" "+add+" "+countBG+&
17、amp;quot;n"); con1.close();con.close();catch (SQLException g)System.out.println(g);/ goodsShow.setText(" ");/ num=null;name=null;price=0;time=null;add=null;/ JOptionPane.showMessageDialog(this," 輸入錯誤n 請重新輸入","提示",JOptionPane.WARNING_MESS
18、AGE);/ public class View2 extends JFrame implements ActionListener /銷售界面String num=null,name=null,time=null,add=null,t1=null,t2=null,t3=null;int price=0;int n1,n2,ap,n3;private JPanel sM=new JPanel(); /supermarket面板private JButton pS=new JButton("銷售界面"),new JButton("銷售管理&a
19、mp;quot;),new JButton("商品管理"),new JButton("權(quán)限管理");/personty 按鈕private JTextArea goodsShow=new JTextArea(), searchShow=new JTextArea(); /文本區(qū)private JScrollPane jsp=new JScrollPane(goodsShow); /滾動區(qū)域 設(shè)定內(nèi)容為 商品顯示的文本區(qū)private JTextField numSearch=new JTextField(),showGoo
20、ds=new JTextField(); /商品查詢/顯示商品private JButton searchGoods=new JButton("搜索"),buyGoods=new JButton("購買"), clean=new JButton("清空"), ok=new JButton("提交"),print=new JButton("打印并提交"); /查詢按鈕private JLabel goodsInform
21、ation=new JLabel("商品編碼",JLabel.CENTER),new JLabel("商品名稱",JLabel.CENTER),new JLabel("商品價格",JLabel.CENTER),new JLabel("生產(chǎn)日期",JLabel.CENTER),new JLabel("生產(chǎn)地",JLabel.CENTER) ;private JLabel goodsI=new JLabel(&q
22、uot;商品編碼",JLabel.CENTER),new JLabel("商品名稱",JLabel.CENTER),new JLabel("商品價格",JLabel.CENTER),new JLabel("生產(chǎn)日期",JLabel.CENTER),new JLabel("生產(chǎn)地",JLabel.CENTER) ; private JLabel allPrice=new JLabel("商品總價:n "
23、;,JLabel.LEFT),label1=new JLabel("商品信息 ",JLabel.RIGHT),label2=new JLabel("購物信息 ",JLabel.RIGHT);public View2()sM.setLayout(null);for(int i=0;i<4;i+)pSi.setBounds(550+i*110,50,100,22);sM.add(pSi);pSi.addActionListener(this);jsp.setBounds(100,180,800,500);good
24、sShow.setLineWrap(true);numSearch.setBounds(100,50,150,22);searchGoods.setBounds(260,50,60,22);searchGoods.addActionListener(this);buyGoods.setBounds(330,50,60,22);buyGoods.addActionListener(this);showGoods.setBounds(100,120,800,22);for (int b=0;b<5 ;b+ )goodsInformationb.setBounds(100+160*b,
25、87,160,30);sM.add(goodsInformationb);for (int b=0;b<5 ;b+ )goodsIb.setBounds(100+160*b,150,160,30);sM.add(goodsIb);clean.setBounds(100,690,100,22);clean.addActionListener(this);ok.setBounds(690,690,100,22);ok.addActionListener(this);print.setBounds(800,690,100,22);print.addActionListener(this
26、);allPrice.setBounds(900,480,100,50);label1.setBounds(20,120,80,22);label2.setBounds(20,180,80,22);sM.add(label1);sM.add(label2);sM.add(allPrice);sM.add(print);sM.add(ok);sM.add(showGoods);sM.add(clean);sM.add(numSearch );sM.add(searchGoods);sM.add(buyGoods);sM.add(jsp);addWindowListener(new WindowA
27、dapter() public void windowClosing(WindowEvent e) Connection con;Statement sql;ResultSet rs;tryif (n3!=0)int a1=0;con=DriverManager.getConnection("jdbc:odbc:q","","");sql=con.createStatement();rs=sql.executeQuery("SELECT MAX(編號) from inf
28、ormation");while(rs.next()a1=rs.getInt(1);for (int i=0;i<n3 ;i+ )sql.executeUpdate("delete from information where 編號="+(a1-i);con.close();ap=0;num=null;name=null;price=0;time=null;add=null;n3=0;goodsShow.setText(null);catch (SQLException g)System.out.println(g);Syst
29、em.exit(0););this.add(sM);this.setTitle("銷售窗口");this.setResizable(false);this.setBounds(0,0,1024,768);this.setVisible(true);validate();if(p.getSource()=buyGoods) /購買按鍵 tryif (num!=null)con=DriverManager.getConnection("jdbc:odbc:q","","&a
30、mp;quot;);sql=con.createStatement();sql.executeUpdate("insert into information(listnum,goodsnum) values('"+n2+"','"+num+"')");rs=sql.executeQuery("SELECT * FROM information where listnum="+n2);n3+
31、;/記錄購買商品個數(shù)con.close();goodsShow.append(" "+num+" "+name+" "+price+" "+time+" "+add+"n"); elseJOptionPane.showMessageDialog(this,"請選擇商品","提示",JOptionPane.WAR
32、NING_MESSAGE);ap=ap+price;/總價allPrice.setText("商品總價:n"+ap);catch (SQLException g)System.out.println(g);if(p.getSource()=ok)tryif (n3!=0)con=DriverManager.getConnection("jdbc:odbc:q","","");sql=con.createStatement();sql.executeUp
33、date("insert into information(listnum,allprice) values('"+n2+"','"+ap+"')");rs=sql.executeQuery("SELECT * FROM information where listnum="+n2);con.close();ap=0;num=null;name=null;price=0;time=null
34、;add=null;n3=0;goodsShow.setText(null);n2+;/帳單號elseJOptionPane.showMessageDialog(this,"請購買商品","提示",JOptionPane.WARNING_MESSAGE);catch (SQLException g)System.out.println(g);if(p.getSource()=print)tryif (n3!=0)con=DriverManager.getConnection("jdbc:odbc:q&am
35、p;quot;,"","");sql=con.createStatement();sql.executeUpdate("insert into information(listnum,allprice) values('"+n2+"','"+ap+"')");rs=sql.executeQuery("SELECT * FROM info
36、rmation where listnum="+n2);con.close();ap=0;num=null;name=null;price=0;time=null;add=null;n3=0;goodsShow.setText(null);n2+;/帳單號elseJOptionPane.showMessageDialog(this,"請購買商品","提示",JOptionPane.WARNING_MESSAGE);catch (SQLException g)System.out.println(g);if
37、(p.getSource()=clean) try if (n3!=0) int a1=0;con=DriverManager.getConnection("jdbc:odbc:q","","");sql=con.createStatement();rs=sql.executeQuery("SELECT MAX(編號) from information");while(rs.next() a1=rs.getInt(1);for (int i=0;i&a
38、mp;lt;n3 ;i+ ) sql.executeUpdate("delete from information where 編號="+(a1-i); con.close();ap=0;num=null;name=null;price=0;time=null;add=null;n3=0;goodsShow.setText(null);catch (SQLException g)System.out.println(g); public class Login extends Frame implements ActionListener,WindowLis
39、tener /登陸界面public int screanWidth,screanHeight;String idin=null;String keyin=null;String passwordD=null;public static String persontyD=null;MenuBar menubar;Menu menu;MenuItem quet,help;Label id,key;TextField idtf,keytf;Box boxV1,boxV2,boxV3,baseBox,boxx;Button enterB;Login() setTitle("超市管理系
40、統(tǒng)登陸界面");Toolkit tool=getToolkit();Dimension dim=tool.getScreenSize();screanWidth=dim.width;screanHeight=dim.height;setBounds(dim.width/3,dim.height/3,320,215);menubar=new MenuBar();menu=new Menu("功能");help=new MenuItem("幫助");quet=new MenuItem("退出
41、");quet.setShortcut(new MenuShortcut(KeyEvent.VK_E);quet.addActionListener(new ActionListener() /匿名類實例控制public void actionPerformed(ActionEvent p)System.exit(0); );menu.add(help);menu.add(quet);menubar.add(menu);setMenuBar(menubar);id=new Label("請輸入帳號:",Label.RIGHT);key=ne
42、w Label("請輸入密碼:",Label.RIGHT);idtf=new TextField(10);keytf=new TextField(10);keytf.setEchoChar('*');enterB=new Button("登陸");boxV1=Box.createVerticalBox();boxV1.add(Box.createVerticalStrut(35);boxV1.add(id);boxV1.add(Box.createVerticalStrut(15);boxV
43、1.add(key);boxV1.add(Box.createVerticalStrut(15);boxV2=Box.createVerticalBox();boxV2.add(Box.createVerticalStrut(35);boxV2.add(idtf);boxV2.add(Box.createVerticalStrut(15);boxV2.add(keytf);boxV2.add(Box.createVerticalStrut(15);baseBox=Box.createHorizontalBox();baseBox.add(Box.createHorizontalStrut(25
44、);baseBox.add(boxV1);baseBox.add(Box.createHorizontalStrut(5);baseBox.add(boxV2);baseBox.add(Box.createHorizontalStrut(70);boxV3=Box.createHorizontalBox();boxV3.add(Box.createHorizontalStrut(125);boxV3.add(enterB);boxV3.add(Box.createHorizontalStrut(125);boxx=Box.createVerticalBox();boxx.add(baseBox);boxx.add(Box .createVerticalStrut(15);box
溫馨提示
- 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)容負責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 網(wǎng)絡(luò)教學(xué)論文
- 中班音樂游戲開鎖
- 教師在校安全培訓(xùn)
- 縱膈腫瘤新進展
- 2025職業(yè)病防治法培訓(xùn)
- 衣柜維修技巧培訓(xùn)課件
- 少兒口才培訓(xùn)教案 課件
- 剪映考試題及答案
- 耳鼻喉科培訓(xùn)課件
- 家務(wù)保姆 考試題及答案
- 低空經(jīng)濟八大應(yīng)用場景與實踐案例解析方案
- 廣東省深圳市福田區(qū)2023-2024學(xué)年一年級下學(xué)期語文期末試卷(含答案)
- 2025年物業(yè)管理員(中級)職業(yè)技能鑒定試卷(含物業(yè)設(shè)施設(shè)備維護案例)
- 下肢功能鍛煉的護理方法
- 核電站清潔維護派遣及環(huán)境監(jiān)測服務(wù)合同
- 口腔合伙股東協(xié)議書
- 行政管理學(xué)科試題及答案分享
- 江蘇南通2025年公開招聘農(nóng)村(村務(wù))工作者筆試題帶答案分析
- 《公司法教學(xué)課件》課件
- 房屋停租合同協(xié)議
- 銀行客戶分類管理
評論
0/150
提交評論