JAVA日记

  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理 ::
  10 随笔 :: 0 文章 :: 0 评论 :: 0 Trackbacks
 注册
  
2  * To change this template, choose Tools | Templates
  
3  * and open the template in the editor.
  
4  */
  
5 
  
6 /*
  7  * regist.java
  8  *
  9  * Created on 2010-6-17, 22:52:43
 10  
*/

 
11 package sp_ma.ui;
 
12 
 
13 /**
 14  *
 15  * 
@author zncuxt
 16  
*/

 
17 import org.hibernate.*;
 
18 import sp_ma.util.HibernateUtil;
 
19 import sp_ma.entity.SpUser;
 
20 
 
21 public class regist extends javax.swing.JFrame {
 
22 
 
23     /** Creates new form regist */
 
24     public regist() {
 
25         initComponents();
 
26     }

 
27 
 
28     /** This method is called from within the constructor to
 29      * initialize the form.
 30      * WARNING: Do NOT modify this code. The content of this method is
 31      * always regenerated by the Form Editor.
 32      
*/

 
33     @SuppressWarnings("unchecked")
 
34     // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
 35     private void initComponents() {
 
36 
 
37         jLabel1 = new javax.swing.JLabel();
 
38         jTextField1 = new javax.swing.JTextField();
 
39         jLabel2 = new javax.swing.JLabel();
 
40         jButton1 = new javax.swing.JButton();
 
41         jTextField2 = new javax.swing.JTextField();
 
42 
 
43         setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
 
44 
 
45         jLabel1.setText("用户名");
 
46 
 
47         jTextField1.addActionListener(new java.awt.event.ActionListener() {
 
48             public void actionPerformed(java.awt.event.ActionEvent evt) {
 
49                 jTextField1ActionPerformed(evt);
 
50             }

 
51         }
);
 
52 
 
53         jLabel2.setText("密码");
 
54 
 
55         jButton1.setText("注册");
 
56         jButton1.addActionListener(new java.awt.event.ActionListener() {
 
57             public void actionPerformed(java.awt.event.ActionEvent evt) {
 
58                 jButton1ActionPerformed(evt);
 
59             }

 
60         }
);
 
61 
 
62         javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
 
63         getContentPane().setLayout(layout);
 
64         layout.setHorizontalGroup(
 
65             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 
66             .addGroup(layout.createSequentialGroup()
 
67                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 
68                     .addGroup(layout.createSequentialGroup()
 
69                         .addGap(545454)
 
70                         .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 
71                             .addComponent(jLabel2)
 
72                             .addComponent(jLabel1)))
 
73                     .addGroup(layout.createSequentialGroup()
 
74                         .addGap(153153153)
 
75                         .addComponent(jButton1))
 
76                     .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
 
77                         .addContainerGap(77, Short.MAX_VALUE)
 
78                         .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 202, javax.swing.GroupLayout.PREFERRED_SIZE))
 
79                     .addGroup(layout.createSequentialGroup()
 
80                         .addGap(777777)
 
81                         .addComponent(jTextField2, javax.swing.GroupLayout.DEFAULT_SIZE, 202, Short.MAX_VALUE)))
 
82                 .addGap(121121121))
 
83         );
 
84         layout.setVerticalGroup(
 
85             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 
86             .addGroup(layout.createSequentialGroup()
 
87                 .addGap(333333)
 
88                 .addComponent(jLabel1)
 
89                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
 
90                 .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
 
91                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
 
92                 .addComponent(jLabel2)
 
93                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
 
94                 .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
 
95                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 110, Short.MAX_VALUE)
 
96                 .addComponent(jButton1)
 
97                 .addGap(444444))
 
98         );
 
99 
100         pack();
101     }
// </editor-fold>                        
102 
103     private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) {                                            
104         // TODO add your handling code here:
105     }
                                           
106 
107     private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
108         // TODO add your handling code here:
109         SessionFactory sessionFactory = HibernateUtil.getSessionFactory();
110         Session session = sessionFactory.openSession();
111         Transaction tx = session.beginTransaction();
112         SpUser user = new SpUser();
113         user.setUsername(jTextField1.getText());
114         user.setPassword(jTextField2.getText());
115         session.save(user);
116         tx.commit();
117         session.close();
118         this.dispose();
119     }
                                        
120 
121     /**
122      * 
@param args the command line arguments
123      
*/

124     public static void main(String args[]) {
125         java.awt.EventQueue.invokeLater(new Runnable() {
126 
127             public void run() {
128                 new regist().setVisible(true);
129             }

130         }
);
131     }

132     // Variables declaration - do not modify                     
133     private javax.swing.JButton jButton1;
134     private javax.swing.JLabel jLabel1;
135     private javax.swing.JLabel jLabel2;
136     private javax.swing.JTextField jTextField1;
137     private javax.swing.JTextField jTextField2;
138     // End of variables declaration                   
登陆
/*
  2  * To change this template, choose Tools | Templates
  3  * and open the template in the editor.
  4  
*/

  
5 
  
6 /*
  7  * login.java
  8  *
  9  * Created on 2010-6-14, 15:12:38
 10  
*/

 
11 
 
12 package sp_ma.ui;
 
13 
 
14 /**
 15  *
 16  * 
@author Administrator
 17  
*/

 
18 import org.hibernate.*;
 
19 import sp_ma.util.HibernateUtil;
 
20 import java.util.List;
 
21 
 
22 public class login extends javax.swing.JFrame {
 
23 
 
24     /** Creates new form login */
 
25     public login() {
 
26         initComponents();
 
27     }

 
28 
 
29     /** This method is called from within the constructor to
 30      * initialize the form.
 31      * WARNING: Do NOT modify this code. The content of this method is
 32      * always regenerated by the Form Editor.
 33      
*/

 
34     @SuppressWarnings("unchecked")
 
35     // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
 36     private void initComponents() {
 
37 
 
38         TextField = new javax.swing.JTextField();
 
39         yse = new javax.swing.JButton();
 
40         PasswordField = new javax.swing.JPasswordField();
 
41         jLabel1 = new javax.swing.JLabel();
 
42         jLabel2 = new javax.swing.JLabel();
 
43 
 
44         setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
 
45         setTitle("登陆界面");
 
46 
 
47         TextField.addActionListener(new java.awt.event.ActionListener() {
 
48             public void actionPerformed(java.awt.event.ActionEvent evt) {
 
49                 TextFieldActionPerformed(evt);
 
50             }

 
51         }
);
 
52 
 
53         yse.setText("登陆");
 
54         yse.addActionListener(new java.awt.event.ActionListener() {
 
55             public void actionPerformed(java.awt.event.ActionEvent evt) {
 
56                 yseActionPerformed(evt);
 
57             }

 
58         }
);
 
59 
 
60         jLabel1.setText("用户名");
 
61 
 
62         jLabel2.setText("密码");
 
63 
 
64         javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
 
65         getContentPane().setLayout(layout);
 
66         layout.setHorizontalGroup(
 
67             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 
68             .addGroup(layout.createSequentialGroup()
 
69                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 
70                     .addGroup(layout.createSequentialGroup()
 
71                         .addGap(515151)
 
72                         .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
 
73                             .addComponent(jLabel1)
 
74                             .addComponent(jLabel2))
 
75                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
 
76                         .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
 
77                             .addComponent(TextField)
 
78                             .addComponent(PasswordField, javax.swing.GroupLayout.DEFAULT_SIZE, 187, Short.MAX_VALUE)))
 
79                     .addGroup(layout.createSequentialGroup()
 
80                         .addGap(132132132)
 
81                         .addComponent(yse, javax.swing.GroupLayout.PREFERRED_SIZE, 86, javax.swing.GroupLayout.PREFERRED_SIZE)))
 
82                 .addContainerGap(82, Short.MAX_VALUE))
 
83         );
 
84         layout.setVerticalGroup(
 
85             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 
86             .addGroup(layout.createSequentialGroup()
 
87                 .addGap(434343)
 
88                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 
89                     .addComponent(TextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
 
90                     .addComponent(jLabel1))
 
91                 .addGap(595959)
 
92                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 
93                     .addComponent(jLabel2)
 
94                     .addComponent(PasswordField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
 
95                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 90, Short.MAX_VALUE)
 
96                 .addComponent(yse, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
 
97                 .addGap(313131))
 
98         );
 
99 
100         pack();
101     }
// </editor-fold>                        
102 
103     private void TextFieldActionPerformed(java.awt.event.ActionEvent evt) {                                          
104         // TODO add your handling code here:
105     }
                                         
106 
107 
108     private void yseActionPerformed(java.awt.event.ActionEvent evt) {                                    
109         // TODO add your handling code here:
110         String  username=TextField.getText();
111         char[] password= PasswordField.getPassword();
112         String passwordstr= new String(password);
113         SessionFactory sessionFactory=HibernateUtil.getSessionFactory();  //取得SESSIONFACTORY
114         Session session=sessionFactory.openSession();           //打开SESSION
115         Transaction tx=session.beginTransaction();              //建立通信
116         String hql="from SpUser where username='"+username+"'and password ='"+passwordstr+"'";   //查询语句
117         Query userlist=session.createQuery(hql);         //建立查询
118         List list=userlist.list();                        //结果放入链表
119         boolean isExist=false;
120         if (list.size()>0)
121         {
122             
123             if(username.equals("admin"))
124             {
125                admin a=new admin();
126                a.show();
127             }

128             else{ employees e=new employees();
129                  e.show();
130                  }

131 
132         }

133         else {
134             Eorro ro=new Eorro();
135             ro.show();
136         }

137         tx.commit();
138         session.close();
139         this.dispose();
140     }
                                   
141 
142     /**
143     * 
@param args the command line arguments
144     
*/

145     public static void main(String args[]) {
146         java.awt.EventQueue.invokeLater(new Runnable() {
147             public void run() {
148                 new login().setVisible(true);
149             }

150         }
);
151     }

152 
153     // Variables declaration - do not modify                     
154     private javax.swing.JPasswordField PasswordField;
155     private javax.swing.JTextField TextField;
156     private javax.swing.JLabel jLabel1;
157     private javax.swing.JLabel jLabel2;
158     private javax.swing.JButton yse;
159     // End of variables declaration                   
160 
161 }

162 
163 


收银
1 /*
  2  * To change this template, choose Tools | Templates
  3  * and open the template in the editor.
  4  
*/

  
5 
  
6 /*
  7  * casher.java
  8  *
  9  * Created on 2010-6-15, 16:53:57
 10  
*/

 
11 
 
12 package sp_ma.ui;
 
13 
 
14 /**
 15  *
 16  * 
@author Administrator
 17  
*/

 
18 import java.util.List;
 
19 import org.hibernate.*;
 
20 import sp_ma.entity.Commodity;
 
21 import sp_ma.entity.Sales;
 
22 import sp_ma.util.HibernateUtil;
 
23 public class casher extends javax.swing.JFrame {
 
24 
 
25     /** Creates new form casher */
 
26     public casher() {
 
27         initComponents();
 
28     }

 
29 
 
30     /** This method is called from within the constructor to
 31      * initialize the form.
 32      * WARNING: Do NOT modify this code. The content of this method is
 33      * always regenerated by the Form Editor.
 34      
*/

 
35     @SuppressWarnings("unchecked")
 
36     // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
 37     private void initComponents() {
 
38 
 
39         jButton1 = new javax.swing.JButton();
 
40         jTextField2 = new javax.swing.JTextField();
 
41         jButton3 = new javax.swing.JButton();
 
42         jButton4 = new javax.swing.JButton();
 
43         jScrollPane1 = new javax.swing.JScrollPane();
 
44         jTextPane1 = new javax.swing.JTextPane();
 
45         jLabel1 = new javax.swing.JLabel();
 
46 
 
47         setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
 
48         setTitle("收银界面");
 
49 
 
50         jButton1.setText("添加");
 
51         jButton1.addActionListener(new java.awt.event.ActionListener() {
 
52             public void actionPerformed(java.awt.event.ActionEvent evt) {
 
53                 jButton1ActionPerformed(evt);
 
54             }

 
55         }
);
 
56 
 
57         jButton3.setText("结算");
 
58         jButton3.addActionListener(new java.awt.event.ActionListener() {
 
59             public void actionPerformed(java.awt.event.ActionEvent evt) {
 
60                 jButton3ActionPerformed(evt);
 
61             }

 
62         }
);
 
63 
 
64         jButton4.setText("打印");
 
65 
 
66         jScrollPane1.setViewportView(jTextPane1);
 
67 
 
68         jLabel1.setText("所购商品");
 
69 
 
70         javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
 
71         getContentPane().setLayout(layout);
 
72         layout.setHorizontalGroup(
 
73             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 
74             .addGroup(layout.createSequentialGroup()
 
75                 .addContainerGap(14, javax.swing.GroupLayout.PREFERRED_SIZE)
 
76                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 
77                     .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 76, javax.swing.GroupLayout.PREFERRED_SIZE)
 
78                     .addGroup(layout.createSequentialGroup()
 
79                         .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 
80                             .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
 
81                                 .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, 101, javax.swing.GroupLayout.PREFERRED_SIZE)
 
82                                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
 
83                                 .addComponent(jButton3))
 
84                             .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 285, Short.MAX_VALUE))
 
85                         .addGap(222)
 
86                         .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
 
87                             .addComponent(jButton4)
 
88                             .addComponent(jButton1))))
 
89                 .addContainerGap())
 
90         );
 
91         layout.setVerticalGroup(
 
92             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 
93             .addGroup(layout.createSequentialGroup()
 
94                 .addContainerGap()
 
95                 .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 19, javax.swing.GroupLayout.PREFERRED_SIZE)
 
96                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
 
97                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
 
98                     .addComponent(jButton1, javax.swing.GroupLayout.Alignment.LEADING)
 
99                     .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 292, javax.swing.GroupLayout.PREFERRED_SIZE))
100                 .addGap(181818)
101                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
102                     .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
103                     .addComponent(jButton3)
104                     .addComponent(jButton4))
105                 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
106         );
107 
108         pack();
109     }
// </editor-fold>                        
110     private int[] fun(String s){
111           String str=s;
112         String instr[]=str.split(",");
113         int inint[]={0,0,0,0,0,0,0,0,0};
114            String ostr="";
115            for(int i=0;i<=str.length();i++){
116            inint[i]=Integer.parseInt(instr[i]);
117         }

118            return inint;
119     }

120     private double coint[]={0.00,0.00,0.00,0.00};//初始化DOUBLE数组
121     private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
122         // TODO add your handling code here:
123         SessionFactory sessionFactory=HibernateUtil.getSessionFactory();    //Hibernate初始化
124         Session session=sessionFactory.openSession();
125         Transaction tx=session.beginTransaction();
126 
127            String str=jTextPane1.getText(); //获取输入
128               String instr[]=str.split(",");//截取输入,存入数组
129                  int inint[]={0,0,0,0};//初始化INT数组
130 
131                      String ostr="商品编号                            零售价格  \n"//输出格式
132            
133 
134 
135           for(int i=0;i<instr.length;i++)//当I小于输入字符个数,I++
136            inint[i]=Integer.parseInt(instr[i]);//TOSTRING
137               int a=inint[i];//中间变量
138                  coint[i]=getrp(a); //使用函数 获得零售价 存入数组
139                     ostr+=instr[i]+"                                     " +coint[i]+"\n";  //输出格式
140                     jTextPane1.setText(ostr);//输出
141            }

142 
143           Sales sale=new Sales();                               //向数据库添加一个新的Sales对象,主键自动生成
144             sale.setAItem(inint[0]);
145             sale.setBItem(inint[1]);
146             sale.setCItem(inint[2]);
147             sale.setDItem(inint[3]);
148             session.save(sale);
149 
150           tx.commit();                                         //通信关闭,关闭SESSION
151           session.close();
152 
153 
154    
155     }
                                        
156 
157     private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {                                         
158         // TODO add your handling code here:
159         double sum=0.00;  //中间变量
160            for(int i=0;i<coint.length;i++){
161                 sum+=coint[i];
162                 }

163                      String s=""+sum;
164         jTextField2.setText(s);
165 
166     }
                                        
167  private double getrp(int i)//功能:批量查询
168             {
169        int a=0;
170         SessionFactory sessionFactory=HibernateUtil.getSessionFactory();    //Hibernate初始化
171           Session session=sessionFactory.openSession();
172            Transaction tx=session.beginTransaction();
173             String hql="from Commodity co where co.comNumbers="+i;
174                Query colist=session.createQuery(hql);
175                  List list=colist.list();
176                    Commodity co=(Commodity)list.get(a);
177                        a++;
178        return co.getRetailPrice();
179    }

180 
181     /**
182     * 
@param args the command line arguments
183     
*/

184     public static void main(String args[]) {
185         java.awt.EventQueue.invokeLater(new Runnable() {
186             public void run() {
187                 new casher().setVisible(true);
188             }

189         }
);
190     }

191 
192     // Variables declaration - do not modify                     
193     private javax.swing.JButton jButton1;
194     private javax.swing.JButton jButton3;
195     private javax.swing.JButton jButton4;
196     private javax.swing.JLabel jLabel1;
197     private javax.swing.JScrollPane jScrollPane1;
198     private javax.swing.JTextField jTextField2;
199     private javax.swing.JTextPane jTextPane1;
200     // End of variables declaration                   
201 
202 }

203 
204 
库管
  
1 /*
  2  * To change this template, choose Tools | Templates
  3  * and open the template in the editor.
  4  
*/

  
5 
  
6 /*
  7  * sto_admin.java
  8  *
  9  * Created on 2010-6-15, 13:17:57
 10  
*/

 
11 
 
12 package sp_ma.ui;
 
13 
 
14 /**
 15  *
 16  * 
@author Administrator
 17  
*/

 
18 import org.hibernate.*;
 
19 import sp_ma.util.HibernateUtil;
 
20 import java.util.List;
 
21 import java.util.Vector;
 
22 import javax.swing.table.DefaultTableModel;
 
23 import sp_ma.entity.StandCom;
 
24 import sp_ma.entity.StoreCom;
 
25 
 
26 public class sto_admin extends javax.swing.JFrame {
 
27 
 
28     /** Creates new form sto_admin */
 
29     public sto_admin() {
 
30         initComponents();
 
31     }

 
32 
 
33     /** This method is called from within the constructor to
 34      * initialize the form.
 35      * WARNING: Do NOT modify this code. The content of this method is
 36      * always regenerated by the Form Editor.
 37      
*/

 
38     @SuppressWarnings("unchecked")
 
39     // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
 40     private void initComponents() {
 
41         bindingGroup = new org.jdesktop.beansbinding.BindingGroup();
 
42 
 
43         jButton1 = new javax.swing.JButton();
 
44         jButton2 = new javax.swing.JButton();
 
45         jLabel1 = new javax.swing.JLabel();
 
46         jTextField1 = new javax.swing.JTextField();
 
47         jTextField2 = new javax.swing.JTextField();
 
48         jLabel2 = new javax.swing.JLabel();
 
49         jLabel3 = new javax.swing.JLabel();
 
50         jTextField3 = new javax.swing.JTextField();
 
51         jScrollPane1 = new javax.swing.JScrollPane();
 
52         jTable1 = new javax.swing.JTable();
 
53         jLabel4 = new javax.swing.JLabel();
 
54         jTextField4 = new javax.swing.JTextField();
 
55 
 
56         setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
 
57         setTitle("库管界面");
 
58 
 
59         jButton1.setText("检索");
 
60         jButton1.addActionListener(new java.awt.event.ActionListener() {
 
61             public void actionPerformed(java.awt.event.ActionEvent evt) {
 
62                 jButton1ActionPerformed(evt);
 
63             }

 
64         }
);
 
65 
 
66         jButton2.setText("更新");
 
67         jButton2.addActionListener(new java.awt.event.ActionListener() {
 
68             public void actionPerformed(java.awt.event.ActionEvent evt) {
 
69                 jButton2ActionPerformed(evt);
 
70             }

 
71         }
);
 
72 
 
73         jLabel1.setText("商品编号");
 
74 
 
75         org.jdesktop.beansbinding.Binding binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, jTable1, org.jdesktop.beansbinding.ELProperty.create("${selectedElement.staComNum}"), jTextField2, org.jdesktop.beansbinding.BeanProperty.create("text"));
 
76         bindingGroup.addBinding(binding);
 
77 
 
78         jLabel2.setText("货架数量");
 
79 
 
80         jLabel3.setText("库存数量");
 
81 
 
82         jTable1.setModel(new javax.swing.table.DefaultTableModel(
 
83             new Object [][] {
 
84                 {nullnullnullnull},
 
85                 {nullnullnullnull},
 
86                 {nullnullnullnull},
 
87                 {nullnullnullnull}
 
88             }
,
 
89             new String [] {
 
90                 "商品编号""货架数量""所在货架""库存数量"
 
91             }

 
92         ) {
 
93             Class[] types = new Class [] {
 
94                 java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class
 
95             }
;
 
96 
 
97             public Class getColumnClass(int columnIndex) {
 
98                 return types [columnIndex];
 
99             }

100         }
);
101         jScrollPane1.setViewportView(jTable1);
102 
103         jLabel4.setText("所在货架");
104 
105         javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
106         getContentPane().setLayout(layout);
107         layout.setHorizontalGroup(
108             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
109             .addGroup(layout.createSequentialGroup()
110                 .addContainerGap()
111                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
112                     .addGroup(layout.createSequentialGroup()
113                         .addComponent(jLabel2)
114                         .addGap(131131131)
115                         .addComponent(jLabel4))
116                     .addComponent(jLabel3)
117                     .addGroup(layout.createSequentialGroup()
118                         .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
119                             .addComponent(jTextField3)
120                             .addComponent(jTextField2)
121                             .addComponent(jLabel1, javax.swing.GroupLayout.Alignment.LEADING)
122                             .addComponent(jTextField1, javax.swing.GroupLayout.DEFAULT_SIZE, 172, Short.MAX_VALUE))
123                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
124                         .addComponent(jTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, 153, javax.swing.GroupLayout.PREFERRED_SIZE)
125                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 103, Short.MAX_VALUE)
126                         .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
127                             .addComponent(jButton1, javax.swing.GroupLayout.Alignment.TRAILING)
128                             .addComponent(jButton2, javax.swing.GroupLayout.Alignment.TRAILING)))
129                     .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 491, Short.MAX_VALUE))
130                 .addContainerGap())
131         );
132         layout.setVerticalGroup(
133             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
134             .addGroup(layout.createSequentialGroup()
135                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
136                     .addGroup(layout.createSequentialGroup()
137                         .addGap(212121)
138                         .addComponent(jButton1))
139                     .addGroup(layout.createSequentialGroup()
140                         .addContainerGap()
141                         .addComponent(jLabel1)
142                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
143                         .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
144                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
145                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
146                     .addComponent(jLabel2)
147                     .addComponent(jLabel4))
148                 .addGap(333)
149                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
150                     .addComponent(jButton2)
151                     .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
152                     .addComponent(jTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
153                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
154                 .addComponent(jLabel3)
155                 .addGap(777)
156                 .addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
157                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
158                 .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 221, javax.swing.GroupLayout.PREFERRED_SIZE)
159                 .addContainerGap(60, Short.MAX_VALUE))
160         );
161 
162         bindingGroup.bind();
163 
164         pack();
165     }
// </editor-fold>                        
166 
167     private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
168         // TODO add your handling code here:
169         String hql1="from StandCom sta  where sta.comNumbers="+jTextField1.getText();      //HQL1预定义语句 查询商品编号为..STANDCOM
170         String hql2="from StoreCom sto  where sto.comNumbers="+jTextField1.getText();      //HQL2预定于语句  查询商品编号为..的STorecom
171         SessionFactory sessionFactory=HibernateUtil.getSessionFactory();                   //取得工厂
172         Session session=sessionFactory.openSession();                                     //打开SESSION
173         Transaction tx=session.beginTransaction();                                        //建立通信
174         Query stalist=session.createQuery(hql1);                                          //查询HQL1 将结果存入 STALIST
175         List list1=stalist.list();                                                        //建立LIST1链表
176         Query stolist=session.createQuery(hql2);
177         List list2=stolist.list();
178         displayResult(list1,list2);                                                      //执行displayResult函数
179         tx.commit();                                                                     //结束通信
180         session.close();                                                                 //关闭SESSION
181 
182     }
                                        
183 
184     private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {                                         
185         // TODO add your handling code here:
186         String hql1="update StandCom sta set sta.staComNum="+jTextField2.getText()+"where sta.comNumbers="+jTextField1.getText();
187         String hql2="update StandCom sta set sta.standComLoc='"+jTextField4.getText()+"'where sta.comNumbers="+jTextField1.getText();
188         String hql3="update StoreCom sto set sto.stoComNum="+jTextField3.getText()+"where sto.comNumbers="+jTextField1.getText();
189         SessionFactory sessionFactory=HibernateUtil.getSessionFactory();
190         Session session=sessionFactory.openSession();
191         Transaction tx=session.beginTransaction();
192         Query update1=session.createQuery(hql1);
193         int ret1=update1.executeUpdate();
194         Query update2=session.createQuery(hql2);
195         int ret2=update2.executeUpdate();
196         Query update3=session.createQuery(hql3);
197         int ret3=update3.executeUpdate();
198         tx.commit();
199         session.close();
200 
201     }
                                        
202 
203     /**
204     * 
@param args the command line arguments
205     
*/

206     public static void main(String args[]) {
207         java.awt.EventQueue.invokeLater(new Runnable() {
208             public void run() {
209                 new sto_admin().setVisible(true);
210             }

211         }
);
212     }

213    private void displayResult(List resultList1,List resultList2) {
214        Vector<String> tableHeaders = new Vector<String>();
215        Vector tableData = new Vector();
216        tableHeaders.add("商品编号");
217        tableHeaders.add("货架数量");
218        tableHeaders.add("所在货架");
219        tableHeaders.add("仓存数量");
220        for(int a=0;a<resultList1.size();a++{
221            StandCom sta = (StandCom)resultList1.get(a);
222            StoreCom sto = (StoreCom)resultList2.get(a);
223            Vector<Object> oneRow = new Vector<Object>();
224            oneRow.add(sta.getComNumbers());
225            oneRow.add(sta.getStaComNum());
226            oneRow.add(sta.getStandComLoc());
227           oneRow.add(sto.getStoComNum());
228            tableData.add(oneRow);    }

229        jTable1.setModel(new DefaultTableModel(tableData, tableHeaders));
230    }

231     // Variables declaration - do not modify                     
232     private javax.swing.JButton jButton1;
233     private javax.swing.JButton jButton2;
234     private javax.swing.JLabel jLabel1;
235     private javax.swing.JLabel jLabel2;
236     private javax.swing.JLabel jLabel3;
237     private javax.swing.JLabel jLabel4;
238     private javax.swing.JScrollPane jScrollPane1;
239     private javax.swing.JTable jTable1;
240     private javax.swing.JTextField jTextField1;
241     private javax.swing.JTextField jTextField2;
242     private javax.swing.JTextField jTextField3;
243     private javax.swing.JTextField jTextField4;
244     private org.jdesktop.beansbinding.BindingGroup bindingGroup;
245     // End of variables declaration                   
246 
247 }

248 
249 


管理员
/*
  2  * To change this template, choose Tools | Templates
  3  * and open the template in the editor.
  4  
*/

  
5 
  
6 /*
  7  * admin.java
  8  *
  9  * Created on 2010-6-14, 16:16:07
 10  
*/

 
11 
 
12 package sp_ma.ui;
 
13 
 
14 import org.hibernate.*;
 
15 import sp_ma.util.HibernateUtil;
 
16 import java.util.List;
 
17 import java.util.Vector;
 
18 import javax.swing.table.DefaultTableModel;
 
19 import sp_ma.entity.StandCom;
 
20 import sp_ma.entity.StoreCom;
 
21 import sp_ma.entity.Commodity;
 
22 /**
 23  *
 24  * 
@author Administrator
 25  
*/

 
26 public class admin extends javax.swing.JFrame {
 
27 
 
28     /** Creates new form admin */
 
29     public admin() {
 
30         initComponents();
 
31     }

 
32 
 
33     /** This method is called from within the constructor to
 34      * initialize the form.
 35      * WARNING: Do NOT modify this code. The content of this method is
 36      * always regenerated by the Form Editor.
 37      
*/

 
38     @SuppressWarnings("unchecked")
 
39     // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
 40     private void initComponents() {
 
41 
 
42         jLabel1 = new javax.swing.JLabel();
 
43         jScrollPane1 = new javax.swing.JScrollPane();
 
44         jTable1 = new javax.swing.JTable();
 
45         jTextField1 = new javax.swing.JTextField();
 
46         jButton1 = new javax.swing.JButton();
 
47         jButton2 = new javax.swing.JButton();
 
48         jButton3 = new javax.swing.JButton();
 
49         jTextField2 = new javax.swing.JTextField();
 
50         jTextField3 = new javax.swing.JTextField();
 
51         jTextField4 = new javax.swing.JTextField();
 
52         jTextField5 = new javax.swing.JTextField();
 
53         jTextField6 = new javax.swing.JTextField();
 
54         jLabel3 = new javax.swing.JLabel();
 
55         jLabel4 = new javax.swing.JLabel();
 
56         jLabel5 = new javax.swing.JLabel();
 
57         jLabel6 = new javax.swing.JLabel();
 
58         jLabel7 = new javax.swing.JLabel();
 
59         jTextField7 = new javax.swing.JTextField();
 
60         jLabel8 = new javax.swing.JLabel();
 
61         jButton4 = new javax.swing.JButton();
 
62         jButton5 = new javax.swing.JButton();
 
63 
 
64         setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
 
65 
 
66         jLabel1.setText("商品编号");
 
67 
 
68         jTable1.setModel(new javax.swing.table.DefaultTableModel(
 
69             new Object [][] {
 
70                 {nullnullnullnull},
 
71                 {nullnullnullnull},
 
72                 {nullnullnullnull},
 
73                 {nullnullnullnull}
 
74             }
,
 
75             new String [] {
 
76                 "Title 1""Title 2""Title 3""Title 4"
 
77             }

 
78         ));
 
79         jScrollPane1.setViewportView(jTable1);
 
80 
 
81         jButton1.setText("查询");
 
82         jButton1.addActionListener(new java.awt.event.ActionListener() {
 
83             public void actionPerformed(java.awt.event.ActionEvent evt) {
 
84                 jButton1ActionPerformed(evt);
 
85             }

 
86         }
);
 
87 
 
88         jButton2.setText("修改");
 
89         jButton2.addActionListener(new java.awt.event.ActionListener() {
 
90             public void actionPerformed(java.awt.event.ActionEvent evt) {
 
91                 jButton2ActionPerformed(evt);
 
92             }

 
93         }
);
 
94 
 
95         jButton3.setText("删除");
 
96         jButton3.addActionListener(new java.awt.event.ActionListener() {
 
97             public void actionPerformed(java.awt.event.ActionEvent evt) {
 
98                 jButton3ActionPerformed(evt);
 
99             }

100         }
);
101 
102         jLabel3.setText("商品名称");
103 
104         jLabel4.setText("商品进价");
105 
106         jLabel5.setText("商品零售价");
107 
108         jLabel6.setText("库存量");
109 
110         jLabel7.setText("上架数量");
111 
112         jLabel8.setText("所在货架");
113 
114         jButton4.setText("注册新员工");
115         jButton4.addActionListener(new java.awt.event.ActionListener() {
116             public void actionPerformed(java.awt.event.ActionEvent evt) {
117                 jButton4ActionPerformed(evt);
118             }

119         }
);
120 
121         jButton5.setText("添加新产品");
122         jButton5.addActionListener(new java.awt.event.ActionListener() {
123             public void actionPerformed(java.awt.event.ActionEvent evt) {
124                 jButton5ActionPerformed(evt);
125             }

126         }
);
127 
128         javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
129         getContentPane().setLayout(layout);
130         layout.setHorizontalGroup(
131             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
132             .addGroup(layout.createSequentialGroup()
133                 .addContainerGap()
134                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
135                     .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 679, Short.MAX_VALUE)
136                     .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
137                         .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
138                             .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
139                                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
140                                     .addComponent(jLabel3)
141                                     .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, 76, javax.swing.GroupLayout.PREFERRED_SIZE))
142                                 .addGap(181818)
143                                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
144                                     .addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, 74, javax.swing.GroupLayout.PREFERRED_SIZE)
145                                     .addComponent(jLabel4))
146                                 .addGap(181818)
147                                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
148                                     .addComponent(jTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, 69, javax.swing.GroupLayout.PREFERRED_SIZE)
149                                     .addComponent(jLabel5))
150                                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
151                                     .addGroup(layout.createSequentialGroup()
152                                         .addGap(181818)
153                                         .addComponent(jLabel6)
154                                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 43, Short.MAX_VALUE))
155                                     .addGroup(layout.createSequentialGroup()
156                                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
157                                         .addComponent(jTextField5, javax.swing.GroupLayout.PREFERRED_SIZE, 73, javax.swing.GroupLayout.PREFERRED_SIZE)
158                                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)))
159                                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
160                                     .addGroup(layout.createSequentialGroup()
161                                         .addComponent(jLabel7)
162                                         .addGap(474747))
163                                     .addGroup(layout.createSequentialGroup()
164                                         .addComponent(jTextField6, javax.swing.GroupLayout.PREFERRED_SIZE, 69, javax.swing.GroupLayout.PREFERRED_SIZE)
165                                         .addGap(181818)))
166                                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
167                                     .addComponent(jLabel8)
168                                     .addComponent(jTextField7, javax.swing.GroupLayout.PREFERRED_SIZE, 74, javax.swing.GroupLayout.PREFERRED_SIZE))
169                                 .addGap(797979))
170                             .addGroup(layout.createSequentialGroup()
171                                 .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 263, javax.swing.GroupLayout.PREFERRED_SIZE)
172                                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
173                                 .addComponent(jButton5)
174                                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)))
175                         .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
176                             .addComponent(jButton2)
177                             .addComponent(jButton1)))
178                     .addComponent(jButton3, javax.swing.GroupLayout.Alignment.TRAILING)
179                     .addComponent(jLabel1)
180                     .addComponent(jButton4))
181                 .addContainerGap())
182         );
183         layout.setVerticalGroup(
184             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
185             .addGroup(layout.createSequentialGroup()
186                 .addContainerGap()
187                 .addComponent(jLabel1)
188                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
189                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
190                     .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
191                     .addComponent(jButton1)
192                     .addComponent(jButton5))
193                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
194                     .addGroup(layout.createSequentialGroup()
195                         .addGap(666)
196                         .addComponent(jButton2)
197                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
198                         .addComponent(jButton3))
199                     .addGroup(layout.createSequentialGroup()
200                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
201                         .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
202                             .addComponent(jLabel3)
203                             .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
204                                 .addComponent(jLabel8)
205                                 .addComponent(jLabel7))
206                             .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
207                                 .addComponent(jLabel6)
208                                 .addComponent(jLabel4)
209                                 .addComponent(jLabel5)))
210                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
211                         .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
212                             .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
213                                 .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
214                                 .addComponent(jTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
215                                 .addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
216                             .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
217                                 .addComponent(jTextField7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
218                                 .addComponent(jTextField5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
219                                 .addComponent(jTextField6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))))
220                 .addGap(121212)
221                 .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 241, javax.swing.GroupLayout.PREFERRED_SIZE)
222                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
223                 .addComponent(jButton4)
224                 .addContainerGap(46, Short.MAX_VALUE))
225         );
226 
227         pack();
228     }
// </editor-fold>                        
229 
230     private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
231         // TODO add your handling code here:
232         String hql1="from StandCom sta  where sta.comNumbers="+jTextField1.getText();      //HQL1预定义语句 查询商品编号为..STANDCOM
233         String hql2="from StoreCom sto  where sto.comNumbers="+jTextField1.getText();//HQL2预定于语句  查询商品编号为..的STorecom
234         String hql3="from Commodity co where co.comNumbers="+jTextField1.getText();
235         SessionFactory sessionFactory=HibernateUtil.getSessionFactory();                   //取得工厂
236         Session session=sessionFactory.openSession();                                     //打开SESSION
237         Transaction tx=session.beginTransaction();                                        //建立通信
238         Query stalist=session.createQuery(hql1);                                          //查询HQL1 将结果存入 STALIST
239         List list1=stalist.list();                                                        //建立LIST1链表
240         Query stolist=session.createQuery(hql2);
241         List list2=stolist.list();
242         Query colist=session.createQuery(hql3);
243         List list3=colist.list();
244         displayResult(list1,list2,list3);                                                      //执行displayResult函数
245         tx.commit();                                                                     //结束通信
246         session.close();                                                                 //关闭SESSION
247 
248 
249 
250 
251     }
                                        
252 
253     private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {                                         
254         // TODO add your handling code here:
255         String hql1="update Commodity co set co.comName='"+jTextField2.getText() +"' where co.comNumbers="+jTextField1.getText();
256         String hql2="update Commodity co set co.retailPrice='"+jTextField3.getText()+"'where co.comNumbers="+jTextField1.getText();
257         String hql3="update Commodity co set co.purchasePrice='"+jTextField4.getText()+"'where co.comNumbers="+jTextField1.getText();
258         String hql4="update StoreCom sto set sto.stoComNum='"+jTextField5.getText()+"'where sto.comNumbers="+jTextField1.getText();
259         String hql5="update StandCom sta set sta.staComNum='"+jTextField6.getText()+"'where sta.comNumbers="+jTextField1.getText();
260          String hql6="update StandCom sta set sta.standComLoc='"+jTextField7.getText()+"'where sta.comNumbers="+jTextField1.getText();
261         SessionFactory sessionFactory=HibernateUtil.getSessionFactory();
262         Session session=sessionFactory.openSession();
263         Transaction tx=session.beginTransaction();
264         Query update1=session.createQuery(hql1);
265         int ret1=update1.executeUpdate();
266         Query update2=session.createQuery(hql2);
267         int ret2=update2.executeUpdate();
268         Query update3=session.createQuery(hql3);
269         int ret3=update3.executeUpdate();
270         Query update4=session.createQuery(hql4);
271         int ret4=update4.executeUpdate();
272          Query update5=session.createQuery(hql5);
273         int ret5=update5.executeUpdate();
274          Query update6=session.createQuery(hql6);
275         int ret6=update6.executeUpdate();
276         tx.commit();
277         session.close();
278 
279 
280     }
                                        
281 
282     private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {                                         
283         // TODO add your handling code here:
284         String hql1="delete Commodity co where co.comNumbers="+jTextField1.getText();
285         SessionFactory sessionFactory=HibernateUtil.getSessionFactory();
286         Session session=sessionFactory.openSession();
287         Transaction tx=session.beginTransaction();
288         Query query=session.createQuery(hql1);
289         int re1=query.executeUpdate();
290         tx.commit();
291         session.close();
292       
293     }
                                        
294 
295     private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {                                         
296         // TODO add your handling code here:
297         regist re=new regist();
298         re.show();
299 
300     }
                                        
301 
302     private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {                                         
303         // TODO add your handling code here:
304          int comNumbers=Integer.parseInt(jTextField1.getText());            //强制转化类型
305          double PurchasePrice=Double.parseDouble(jTextField4.getText());
306          double RetailPrice=Double.parseDouble(jTextField3.getText());
307          int StaComNum=Integer.parseInt(jTextField6.getText());
308          int StoComNum=Integer.parseInt(jTextField5.getText());
309 
310         SessionFactory sessionFactory=HibernateUtil.getSessionFactory();    //Hibernate初始化
311         Session session=sessionFactory.openSession();
312         Transaction tx=session.beginTransaction();
313 
314         Commodity co =new Commodity();                                      //对象初始化
315         StandCom sta=new StandCom();
316         StoreCom sto=new StoreCom();
317 
318         co.setComNumbers(comNumbers);                                       //添加功能
319         co.setComName(jTextField2.getText());
320         co.setPurchasePrice(PurchasePrice);
321         co.setRetailPrice(RetailPrice);
322         sta.setComNumbers(comNumbers);
323         sta.setStaComNum(StaComNum);
324         sta.setStandComLoc(jTextField7.getText());
325         sto.setComNumbers(comNumbers);
326         sto.setStoComNum(StoComNum);
327 
328         session.save(co);                                                   //保存对象
329         session.save(sta);
330         session.save(sto);
331 
332         tx.commit();                                                       //关闭
333         session.close();
334 
335     }
                                        
336 
337     /**
338     * 
@param args the command line arguments
339     
*/

340     public static void main(String args[]) {
341         java.awt.EventQueue.invokeLater(new Runnable() {
342             public void run() {
343                 new admin().setVisible(true);
344             }

345         }
);
346     }

347 private void displayResult(List resultList1,List resultList2,List resultList3) {
348        Vector<String> tableHeaders = new Vector<String>();
349        Vector tableData = new Vector();
350        tableHeaders.add("商品编号");
351         tableHeaders.add("商品名称");
352        tableHeaders.add("商品进价");
353        tableHeaders.add("商品零售价");
354        tableHeaders.add("仓存数量");
355         tableHeaders.add("上架量");
356          tableHeaders.add("所在货架");
357        for(int a=0;a<resultList1.size();a++{
358            StandCom sta = (StandCom)resultList1.get(a);
359            StoreCom sto = (StoreCom)resultList2.get(a);
360            Commodity co= (Commodity)resultList3.get(a);
361            Vector<Object> oneRow = new Vector<Object>();
362            oneRow.add(co.getComNumbers());
363            oneRow.add(co.getComName());
364            oneRow.add(co.getRetailPrice());
365            oneRow.add(co.getPurchasePrice());
366           oneRow.add(sto.getStoComNum());
367           oneRow.add(sta.getStaComNum());
368           oneRow.add(sta.getStandComLoc());
369            tableData.add(oneRow);    }

370        jTable1.setModel(new DefaultTableModel(tableData, tableHeaders));
371    }

372     // Variables declaration - do not modify                     
373     private javax.swing.JButton jButton1;
374     private javax.swing.JButton jButton2;
375     private javax.swing.JButton jButton3;
376     private javax.swing.JButton jButton4;
377     private javax.swing.JButton jButton5;
378     private javax.swing.JLabel jLabel1;
379     private javax.swing.JLabel jLabel3;
380     private javax.swing.JLabel jLabel4;
381     private javax.swing.JLabel jLabel5;
382     private javax.swing.JLabel jLabel6;
383     private javax.swing.JLabel jLabel7;
384     private javax.swing.JLabel jLabel8;
385     private javax.swing.JScrollPane jScrollPane1;
386     private javax.swing.JTable jTable1;
387     private javax.swing.JTextField jTextField1;
388     private javax.swing.JTextField jTextField2;
389     private javax.swing.JTextField jTextField3;
390     private javax.swing.JTextField jTextField4;
391     private javax.swing.JTextField jTextField5;
392     private javax.swing.JTextField jTextField6;
393     private javax.swing.JTextField jTextField7;
394     // End of variables declaration                   
395 
396 }

397 
398 
Hibernate配置主文件
1 <?xml version="1.0" encoding="UTF-8"?>
 
2 <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
 
3 <hibernate-configuration>
 
4   <session-factory>
 
5     <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
 
6     <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
 
7     <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/sp_db</property>
 8     <property name="hibernate.connection.username">root</property>
 
9     <property name="hibernate.connection.password">4873617</property>
10     <mapping resource="sp_ma/entity/Commodity.hbm.xml"/>
11     <mapping resource="sp_ma/entity/StoreCom.hbm.xml"/>
12     <mapping resource="sp_ma/entity/StandCom.hbm.xml"/>
13     <mapping resource="sp_ma/entity/SpUser.hbm.xml"/>
14     <mapping resource="sp_ma/entity/Sales.hbm.xml"/>
15   </session-factory>
16 </hibernate-configuration>
posted on 2010-08-03 22:29 辛彤 阅读(1651) 评论(0)  编辑  收藏

只有注册用户登录后才能发表评论。


网站导航: