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