package card; import java.awt.*; import javax.swing.*; import java.awt.event.*; import java.sql.*; import java.lang.Number.*; import java.util.*; import java.text.*; /** * Title: * Description: * Copyright: Copyright (c) 2003 * Company: * @author not attributable * @version 1.0 */ public class storePanel extends JPanel { JLabel jLabel1 = new JLabel(); JLabel jLabel2 = new JLabel(); JLabel jLabel3 = new JLabel(); JTextField jTextField1 = new JTextField(); JButton jButton1 = new JButton(); JButton jButton2 = new JButton(); public storePanel(String Name,String ID,Connection connection1,eventFrame Frame1){ try { UserName = Name; CardID = ID; con = connection1; eventFrame = Frame1; jbInit(); } catch(Exception ex) { ex.printStackTrace(); } } void jbInit() throws Exception { this.setPreferredSize(new Dimension(300, 300)); this.setLayout(null); jLabel1.setFont(new java.awt.Font("Serif", 1, 18)); jLabel1.setForeground(Color.blue); jLabel1.setText("用 户 名:"); jLabel1.setBounds(new Rectangle(65, 30, 100, 30)); jLabel2.setFont(new java.awt.Font("Serif", 1, 18)); jLabel2.setText(UserName); jLabel2.setBounds(new Rectangle(165, 30, 100, 30)); jLabel3.setFont(new java.awt.Font("Serif", 1, 18)); jLabel3.setForeground(Color.blue); jLabel3.setText("存入数额:"); jLabel3.setBounds(new Rectangle(65, 100, 100, 30)); jTextField1.setText("0"); jTextField1.setBounds(new Rectangle(165, 100, 100, 25)); jButton1.setBounds(new Rectangle(70, 210, 70, 25)); jButton1.setText("确定"); jButton1.addActionListener(new storePanel_jButton1_actionAdapter(this)); jButton2.setBounds(new Rectangle(160, 210, 70, 25)); jButton2.setText("重置"); jButton2.addActionListener(new storePanel_jButton2_actionAdapter(this)); this.add(jLabel1, null); this.add(jLabel2, null); this.add(jLabel3, null); this.add(jTextField1, null); this.add(jButton1, null); this.add(jButton2, null); } void jButton2_actionPerformed(ActionEvent e) { jTextField1.setText(""); } void jButton1_actionPerformed(ActionEvent e) { try{ today = new java.text.SimpleDateFormat("yyyy-MM-dd", java.util.Locale.US); System.out.print(today.format(new java.util.Date())); storeInsert =con.createStatement(); storeUpdate =con.createStatement(); insertString = "insert event (CardID,EventMoney,EventDate) values ("+CardID+","+Integer.parseInt(jTextField1.getText())+",2003-09-15)"; updateString = "update card set LeaveMoney = LeaveMoney + "+Integer.parseInt(jTextField1.getText().trim())+" where CardID = "+CardID; System.out.print(insertString); storeInsert.executeUpdate(insertString); storeUpdate.executeUpdate(updateString); eventFrame.toquery(); } catch(SQLException ex){ System.out.print("系统错误,请检测数据库"); } } private String CardID; private Connection con; private Statement storeUpdate; private Statement storeInsert; private java.text.SimpleDateFormat today; private String UserName; private eventFrame eventFrame; private String updateString; private String insertString; } class storePanel_jButton2_actionAdapter implements java.awt.event.ActionListener { storePanel adaptee; storePanel_jButton2_actionAdapter(storePanel adaptee) { this.adaptee = adaptee; } public void actionPerformed(ActionEvent e) { adaptee.jButton2_actionPerformed(e); } } class storePanel_jButton1_actionAdapter implements java.awt.event.ActionListener { storePanel adaptee; storePanel_jButton1_actionAdapter(storePanel adaptee) { this.adaptee = adaptee; } public void actionPerformed(ActionEvent e) { adaptee.jButton1_actionPerformed(e); } }