CustomerWindow.java~24~
上传用户:liming9091
上传日期:2014-10-27
资源大小:3376k
文件大小:9k
源码类别:

Java编程

开发平台:

Java

  1. package uml_gaokai;
  2. import java.awt.*;
  3. import javax.swing.*;
  4. import com.borland.dx.sql.dataset.*;
  5. import com.borland.dbswing.*;
  6. import com.borland.jbcl.layout.*;
  7. import com.borland.dx.dataset.*;
  8. import java.awt.event.*;
  9. import java.sql.*;
  10. /**
  11.  * <p>Title: </p>
  12.  * <p>Description: </p>
  13.  * <p>Copyright: Copyright (c) 2003</p>
  14.  * <p>Company: </p>
  15.  * @author unascribed
  16.  * @version 1.0
  17.  */
  18. public class CustomerWindow extends JDialog {
  19.   private JPanel panel1 = new JPanel();
  20.   private Database database1 = new Database();
  21.   private JdbTable jdbTable1 = new JdbTable();
  22.   private XYLayout xYLayout1 = new XYLayout();
  23.   private TableScrollPane tableScrollPane1 = new TableScrollPane();
  24.   private JButton jButton1 = new JButton();
  25.   private JButton jButton2 = new JButton();
  26.   private JButton jButton3 = new JButton();
  27.   private JButton jButton5 = new JButton();
  28.   private JButton jButton6 = new JButton();
  29.   private Column column1 = new Column();
  30.   private Column column2 = new Column();
  31.   private Column column3 = new Column();
  32.   private QueryDataSet queryDataSet1 = new QueryDataSet();
  33.   private QueryDataSet queryDataSet2 = new QueryDataSet();
  34.   private QueryDataSet queryDataSet3 = new QueryDataSet();
  35.   private QueryDataSet queryDataSet4 = new QueryDataSet();
  36.   private JLabel jLabel1 = new JLabel();
  37.   private JTextField jTextField1 = new JTextField();
  38.   private JLabel jLabel2 = new JLabel();
  39.   private JTextField jTextField2 = new JTextField();
  40.   private JLabel jLabel3 = new JLabel();
  41.   private JTextField jTextField3 = new JTextField();
  42.   private JLabel jLabel4 = new JLabel();
  43.   private JTextField jTextField4 = new JTextField();
  44.   private JLabel jLabel5 = new JLabel();
  45.   private JTextField jTextField5 = new JTextField();
  46.   private JLabel jLabel6 = new JLabel();
  47.   private JTextField jTextField6 = new JTextField();
  48.   private JLabel jLabel7 = new JLabel();
  49.   private JTextField jTextField7 = new JTextField();
  50.   private JLabel jLabel8 = new JLabel();
  51.   private JPasswordField jPasswordField1 = new JPasswordField();
  52.   public CustomerWindow(Frame frame, String title, boolean modal) {
  53.     super(frame, title, modal);
  54.     try {
  55.       jbInit();
  56.       pack();
  57.     }
  58.     catch(Exception ex) {
  59.       ex.printStackTrace();
  60.     }
  61.   }
  62.   public CustomerWindow() {
  63.     this(null, "", false);
  64.   }
  65.   private void jbInit() throws Exception {
  66.     panel1.setLayout(xYLayout1);
  67.     database1.setConnection(new com.borland.dx.sql.dataset.ConnectionDescriptor("jdbc:odbc:gaokaiSQL", "sa", "", false, "sun.jdbc.odbc.JdbcOdbcDriver"));
  68.     jButton1.setText("浏览全部商品信息");
  69.     jButton1.addActionListener(new java.awt.event.ActionListener() {
  70.       public void actionPerformed(ActionEvent e) {
  71.         jButton1_actionPerformed(e);
  72.       }
  73.     });
  74.     jButton2.setText("浏览某种商品");
  75.     jButton2.addActionListener(new java.awt.event.ActionListener() {
  76.       public void actionPerformed(ActionEvent e) {
  77.         jButton2_actionPerformed(e);
  78.       }
  79.     });
  80.     jButton3.setText("购买商品");
  81.     jButton3.addActionListener(new java.awt.event.ActionListener() {
  82.       public void actionPerformed(ActionEvent e) {
  83.         jButton3_actionPerformed(e);
  84.       }
  85.     });
  86.     jButton6.setText("退出");
  87.     jButton6.addActionListener(new java.awt.event.ActionListener() {
  88.       public void actionPerformed(ActionEvent e) {
  89.         jButton6_actionPerformed(e);
  90.       }
  91.     });
  92.     jdbTable1.setToolTipText("");
  93.     column1.setColumnName("GoodsPrice");
  94.     column1.setDataType(com.borland.dx.dataset.Variant.DOUBLE);
  95.     column1.setSchemaName("dbo");
  96.     column1.setTableName("goodsInfo");
  97.     column1.setVisible(com.borland.jb.util.TriStateProperty.DEFAULT);
  98.     column1.setServerColumnName("GoodsPrice");
  99.     column1.setSqlType(6);
  100.     column3.setColumnName("NewColumn1");
  101.     column3.setDataType(com.borland.dx.dataset.Variant.STRING);
  102.     column3.setDefault("");
  103.     column3.setPreferredOrdinal(1);
  104.     column3.setServerColumnName("NewColumn1");
  105.     column3.setSqlType(0);
  106.     jLabel1.setText("商品名");
  107.     jLabel2.setText("商品ID");
  108.     jLabel3.setText("商品数量");
  109.     jLabel4.setText("商品名");
  110.     jLabel5.setText("商品尺码");
  111.     jLabel6.setText("日期");
  112.     jLabel7.setText("客户姓名");
  113.     jLabel8.setText("密码");
  114.     jTextField1.setText("0");
  115.     getContentPane().add(panel1);
  116.     panel1.add(tableScrollPane1,  new XYConstraints(219, 140, -1, -1));
  117.     panel1.add(jButton1, new XYConstraints(-2, 229, 133, 22));
  118.     panel1.add(jdbTable1,            new XYConstraints(2, 0, 542, 222));
  119.     panel1.add(jButton2, new XYConstraints(0, 267, 131, 23));
  120.     panel1.add(jButton5, new XYConstraints(-2, 384, 132, 21));
  121.     panel1.add(jLabel1,  new XYConstraints(136, 268, 39, 21));
  122.     panel1.add(jTextField2, new XYConstraints(178, 268, 65, 21));
  123.     panel1.add(jLabel2,  new XYConstraints(249, 268, 52, 21));
  124.     panel1.add(jTextField1,  new XYConstraints(297, 268, 66, 23));
  125.     panel1.add(jTextField3,  new XYConstraints(431, 309, 65, 21));
  126.     panel1.add(jLabel3,  new XYConstraints(375, 309, -1, 23));
  127.     panel1.add(jLabel4,  new XYConstraints(137, 309, 39, 21));
  128.     panel1.add(jLabel5,      new XYConstraints(249, 309, 50, 22));
  129.     panel1.add(jTextField5,   new XYConstraints(299, 309, 69, 20));
  130.     panel1.add(jButton3,   new XYConstraints(-1, 307, 127, 22));
  131.     panel1.add(jLabel6,     new XYConstraints(136, 339, 46, 21));
  132.     panel1.add(jTextField6,        new XYConstraints(180, 339, 66, -1));
  133.     panel1.add(jLabel7,    new XYConstraints(249, 339, 50, 21));
  134.     panel1.add(jTextField7,     new XYConstraints(298, 339, 71, 21));
  135.     panel1.add(jLabel8,   new XYConstraints(378, 339, 50, 20));
  136.     panel1.add(jButton6, new XYConstraints(413, 384, 130, 22));
  137.     panel1.add(jPasswordField1,  new XYConstraints(432, 338, 66, 19));
  138.     panel1.add(jTextField4,   new XYConstraints(178, 310, 71, 21));
  139.   }
  140.   //浏览全部商品
  141.   void jButton1_actionPerformed(ActionEvent e) {
  142.     queryDataSet1.setQuery(new com.borland.dx.sql.dataset.QueryDescriptor(database1, "SELECT [goodsInfo].GoodsID,[goodsInfo].GoodsName,[goodsInfo].GoodsNumber,[goodsInfo].GoodsProduct,[go" +
  143.         "odsInfo].GoodsPrice FROM [UML_CS].[dbo].[goodsInfo]", null, true, Load.ALL));
  144.     jdbTable1.setDataSet(queryDataSet1);
  145.     queryDataSet1.refresh();
  146.   }
  147.   //浏览某种商品
  148.   void jButton2_actionPerformed(ActionEvent e) {
  149.     String GoodsName = String.valueOf(jTextField2.getText()) ;
  150.     int GoodsID = Integer.parseInt(jTextField1.getText()) ;
  151.     if( GoodsName.equals("") && GoodsID == 0){
  152.       JOptionPane.showMessageDialog(null,"请输入商品名或商品ID号,查询商品","",JOptionPane.DEFAULT_OPTION);
  153.     }
  154.     else if( GoodsName.equals("") == false  && GoodsID == 0 ){
  155.       queryDataSet2.setQuery(new com.borland.dx.sql.dataset.QueryDescriptor(database1, "SELECT [goodsInfo].GoodsID,[goodsInfo].GoodsName,[goodsInfo].GoodsNumber,[goodsInfo].GoodsProduct,[go" +
  156.           "odsInfo].GoodsPrice FROM [UML_CS].[dbo].[goodsInfo] WHERE GoodsName = '"+GoodsName+"'", null, true, Load.ALL));
  157.       jdbTable1.setDataSet(queryDataSet2);
  158.       queryDataSet2.refresh();
  159.     }
  160.     else if( GoodsName.equals("") && GoodsID != 0 ){
  161.       queryDataSet3.setQuery(new com.borland.dx.sql.dataset.QueryDescriptor(database1, "SELECT [goodsInfo].GoodsID,[goodsInfo].GoodsName,[goodsInfo].GoodsNumber,[goodsInfo].GoodsProduct,[go" +
  162.           "odsInfo].GoodsPrice FROM [UML_CS].[dbo].[goodsInfo] WHERE GoodsID = '"+GoodsID+"'", null, true, Load.ALL));
  163.       jdbTable1.setDataSet(queryDataSet3);
  164.       queryDataSet3.refresh();
  165.     }
  166.   }
  167.   //购买商品
  168.   void jButton3_actionPerformed(ActionEvent e) {
  169.     String goodsName = jTextField4.getText() ; //get the GoodsName
  170.     String goodsSize = jTextField5.getText() ; //get the goodsSize
  171.     String goodsCustomNumber = jTextField3.getText() ; //get the goodsCustomNumber
  172.     String venditionDate = jTextField6.getText() ; //get the venditionDate
  173.     String customerName = jTextField7.getText() ; // get the userName
  174.     String testPassword = String.valueOf(jPasswordField1.getPassword()) ; // get the passward
  175.     String userPassword = null ;
  176.     Statement sql = database1.createStatement() ;
  177.     try{
  178.       ResultSet rs = sql.executeQuery("SELECT userPassword FROM [UML_CS].[dbo].[user] WHERE userName = '"+customerName+"'") ;
  179.       while(rs.next()){
  180.         userPassword = rs.getString("userPassword") ;
  181.       }
  182.       //检验用户正确性
  183.       if(userPassword.equals(testPassword) == false){
  184.         JOptionPane.showMessageDialog(null,"您输入的密码不正确,请重试","verify password" , JOptionPane.DEFAULT_OPTION);
  185.       }
  186.       else{
  187.         JOptionPane.showMessageDialog(null,"success","",JOptionPane.DEFAULT_OPTION);
  188.         sql.executeUpdate("INSERT INTO [UML_CS].[dbo].[vendition_TABLE](GoodsName,GoodsSize,GoodsCustomNumber,VenditionDate,CustomerName) VALUES('"+goodsName+"','"+goodsSize+"','"+goodsCustomNumber+"','"+venditionDate+"','"+customerName+"')") ;
  189.         queryDataSet4.setQuery(new com.borland.dx.sql.dataset.QueryDescriptor(database1, "SELECT * FROM [UML_CS].[dbo].[vendition_TABLE] WHERE CustomerName = '"+customerName+"'", null, true, Load.ALL));
  190.         jdbTable1.setDataSet(queryDataSet4);
  191.         queryDataSet4.refresh();
  192.       }
  193.     }
  194.     catch(SQLException www){
  195.       www.printStackTrace();
  196.     }
  197.   }
  198.   void jButton6_actionPerformed(ActionEvent e) {
  199.     dispose() ;
  200.   }
  201. }