我现在在弄这个书里的系统 希望这样能帮的上大家

源代码在线查看: useinpanel.java~36~

软件大小: 8132 K
上传用户: andyandnancy
关键词:
下载地址: 免注册下载 普通下载 VIP

相关代码

				package bar;
				
				import java.awt.*;
				import javax.swing.*;
				import java.awt.event.*;
				import java.sql.*;
				import java.text.*;
				import java.util.*;
				
				/**
				 * Title: 
				 * Description: 
				 * Copyright: Copyright (c) 2003
				 * Company: 
				 * @author not attributable
				 * @version 1.0
				 */
				
				public class useInPanel extends JPanel {
				  JLabel jLabel1 = new JLabel();
				  JLabel jLabel2 = new JLabel();
				  JTextField jTextField2 = new JTextField();
				  JLabel jLabel3 = new JLabel();
				  JLabel jLabel4 = new JLabel();
				  JTextField jTextField3 = new JTextField();
				  JButton jButton1 = new JButton();
				  JButton jButton2 = new JButton();
				  JPasswordField jPasswordField1 = new JPasswordField();
				
				  public useInPanel() {
				    try {
				      jbInit();
				    }
				    catch(Exception ex) {
				      ex.printStackTrace();
				    }
				  }
				  void jbInit() throws Exception {
				    this.setLayout(null);
				
				    jLabel1.setFont(new java.awt.Font("Serif", 0, 13));
				    jLabel1.setHorizontalAlignment(SwingConstants.CENTER);
				    jLabel1.setText("机器号码:");
				    jLabel1.setBounds(new Rectangle(95, 30, 70, 25));
				
				    jComboBox1.setBounds(new Rectangle(175, 30, 110, 25));
				
				    jLabel2.setFont(new java.awt.Font("Serif", 0, 13));
				    jLabel2.setHorizontalAlignment(SwingConstants.CENTER);
				    jLabel2.setText("卡        号:");
				    jLabel2.setBounds(new Rectangle(95, 75, 70, 25));
				
				    jTextField2.setText("");
				    jTextField2.setBounds(new Rectangle(175, 75, 110, 25));
				
				    jLabel3.setFont(new java.awt.Font("Serif", 0, 13));
				    jLabel3.setHorizontalAlignment(SwingConstants.CENTER);
				    jLabel3.setText("密        码:");
				    jLabel3.setBounds(new Rectangle(95, 120, 70, 25));
				
				    jPasswordField1.setText("");
				    jPasswordField1.setBounds(new Rectangle(175, 120, 110, 25));
				
				    jLabel4.setFont(new java.awt.Font("Serif", 0, 13));
				    jLabel4.setHorizontalAlignment(SwingConstants.CENTER);
				    jLabel4.setText("开始时间:");
				    jLabel4.setBounds(new Rectangle(95, 165, 70, 25));
				
				    java.util.Date today = new java.util.Date();
				    SimpleDateFormat HMFromat = new SimpleDateFormat("HH:mm");
				    String nowTime = HMFromat.format(today);
				    jTextField3.setText(nowTime);
				    jTextField3.setBounds(new Rectangle(175, 165, 110, 25));
				
				    jButton1.setBounds(new Rectangle(115, 215, 65, 25));
				    jButton1.setText("确认");
				    jButton1.addActionListener(new useInPanel_jButton1_actionAdapter(this));
				
				    jButton2.setBounds(new Rectangle(200, 215, 65, 25));
				    jButton2.setText("重置");
				    jButton2.addActionListener(new useInPanel_jButton2_actionAdapter(this));
				
				
				    this.add(jTextField2, null);
				    this.add(jLabel2, null);
				    this.add(jLabel3, null);
				    this.add(jLabel4, null);
				    this.add(jTextField3, null);
				    this.add(jPasswordField1, null);
				    this.add(jLabel1, null);
				    this.add(jButton1, null);
				    this.add(jButton2, null);
				    this.add(jComboBox1, null);
				    Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
				    String url = "jdbc:microsoft:sqlserver://keweixing:1433;DatabaseName=dbbar";
				    String username = "sa";
				    String password = "";
				    con = DriverManager.getConnection(url, username, password);
				    Statement stmt = con.createStatement();
				    ResultSet boxRs = stmt.executeQuery("select * from CompuetIDView");
				
				    jComboBox1.addItem("");
				    while(boxRs.next()){
				      jComboBox1.addItem(boxRs.getString("ComputerID"));
				    }
				  }
				
				  void jButton2_actionPerformed(ActionEvent e) {
				    jComboBox1.setSelectedIndex(0);
				    jTextField2.setText("");
				    jPasswordField1.setText("");
				    jTextField3.setText("");
				  }
				
				  void jButton1_actionPerformed(ActionEvent e) {
				   try{
				     String passwordtemp = "";
				     for(int i=0;i				       passwordtemp += jPasswordField1.getPassword()[i];
				     }
				     queryStmt = con.createStatement();
				     loginQuery = "select * from Card where CardID = " +
				                            Integer.parseInt(jTextField2.getText().trim()) +
				                            " and password = "+passwordtemp;
				     ResultSet rs1 = queryStmt.executeQuery(loginQuery);
				     if(rs1.next()){
				       insertStmt = con.createStatement();
				       insertString = "INSERT INTO Event (CardID, ComputerID, BeginTime) VALUES ("+Integer.parseInt(jTextField2.getText().trim())+", "+Integer.parseInt(jComboBox1.getSelectedItem().toString())+", '"+jTextField3.getText()+":00')";
				       System.out.print(insertString);
				       int rs2 = insertStmt.executeUpdate(insertString);
				       System.out.print(rs2);
				     }
				     else{
				       jTextField2.setText("卡号或者密码不对。");
				     }
				     rs1.close();
				     con.close();
				     this.hide();
				   }
				   catch(SQLException ex){
				     System.out.print("系统错误,请检测数据库。");
				   }
				  }
				
				  private Statement queryStmt;
				  private Statement insertStmt;
				  private String loginQuery;
				  private String insertString;
				  private Connection con;
				  JComboBox jComboBox1 = new JComboBox();
				
				}
				
				class useInPanel_jButton2_actionAdapter implements java.awt.event.ActionListener {
				  useInPanel adaptee;
				
				  useInPanel_jButton2_actionAdapter(useInPanel adaptee) {
				    this.adaptee = adaptee;
				  }
				  public void actionPerformed(ActionEvent e) {
				    adaptee.jButton2_actionPerformed(e);
				  }
				}
				
				class useInPanel_jButton1_actionAdapter implements java.awt.event.ActionListener {
				  useInPanel adaptee;
				
				  useInPanel_jButton1_actionAdapter(useInPanel adaptee) {
				    this.adaptee = adaptee;
				  }
				  public void actionPerformed(ActionEvent e) {
				    adaptee.jButton1_actionPerformed(e);
				  }
				}			

相关资源