📄 userinpanel.java~1~
字号:
package bar;import java.awt.*;import javax.swing.*;import java.awt.event.*;import java.sql.*;import java.text.*;import java.util.*;import com.borland.dx.sql.dataset.*;/** * <p>Title: </p> * <p>Description: </p> * <p>Copyright: Copyright (c) 2004</p> * <p>Company: </p> * @author not attributable * @version 1.0 */public class userInPanel extends JPanel { JLabel jLabel1 = new JLabel(); JLabel jLabel2 = new JLabel(); JLabel jLabel3 = new JLabel(); JLabel jLabel4 = new JLabel(); JComboBox jComboBox1 = new JComboBox(); JTextField jTextField2 = new JTextField(); JTextField jTextField3 = new JTextField(); JButton jButton1 = new JButton(); JButton jButton2 = new JButton(); JPasswordField jPasswordField1 = new JPasswordField(); barConnect barConnect1=new barConnect(); private Connection con; private Statement queryStmt; private Statement insertStmt; private String loginQuery; private String insertString; public userInPanel(mainFrame mFrame) { try { Frame1 = mFrame; jbInit(); } catch(Exception ex) { ex.printStackTrace(); } } void jbInit() throws Exception { jLabel1.setFont(new java.awt.Font("Serif", 0, 16)); jLabel1.setForeground(new Color(187, 173, 201)); jLabel1.setHorizontalAlignment(SwingConstants.CENTER); jLabel1.setText("机器号码:"); jLabel1.setBounds(new Rectangle(76, 47, 90, 24)); this.setLayout(null); jLabel2.setBounds(new Rectangle(75, 96, 90, 24)); jLabel2.setText("卡 号:"); jLabel2.setHorizontalAlignment(SwingConstants.CENTER); jLabel2.setFont(new java.awt.Font("Serif", 0, 16)); jLabel2.setForeground(new Color(152, 97, 131)); jLabel3.setBounds(new Rectangle(78, 150, 90, 24)); jLabel3.setText("密 码:"); jLabel3.setHorizontalAlignment(SwingConstants.CENTER); jLabel3.setFont(new java.awt.Font("Serif", 0, 16)); jLabel3.setForeground(Color.red); jLabel4.setBounds(new Rectangle(76, 197, 90, 24)); jLabel4.setText("开始时间:"); jLabel4.setHorizontalAlignment(SwingConstants.CENTER); jLabel4.setFont(new java.awt.Font("Serif", 0, 16)); jLabel4.setForeground(Color.magenta); jComboBox1.setBounds(new Rectangle(167, 47, 129, 26)); jTextField2.setText(""); jTextField2.setBounds(new Rectangle(167, 96, 137, 27)); java.util.Date today = new java.util.Date(); SimpleDateFormat HMFromat = new SimpleDateFormat("HH:mm"); String nowTime = HMFromat.format(today); jTextField3.setText(nowTime); jTextField3.setCaretColor(new Color(180, 166, 0)); jTextField3.setBounds(new Rectangle(170, 196, 136, 27)); jButton1.setBounds(new Rectangle(98, 259, 73, 25)); jButton1.setFont(new java.awt.Font("Serif", 0, 12)); jButton1.setForeground(Color.red); jButton1.setContentAreaFilled(true); jButton1.setText("确定"); jButton1.addActionListener(new userInPanel_jButton1_actionAdapter(this)); jButton2.setBounds(new Rectangle(264, 258, 73, 25)); jButton2.setFont(new java.awt.Font("Serif", 0, 12)); jButton2.setForeground(Color.green); jButton2.setText("重设"); jPasswordField1.setCaretColor(new Color(7, 0, 0)); jPasswordField1.setText(""); jPasswordField1.setBounds(new Rectangle(168, 147, 135, 28)); database1.setConnection(new com.borland.dx.sql.dataset.ConnectionDescriptor("jdbc:microsoft:sqlserver://102-38:1433;DatabaseName=webbra", "sa", "709394", false, "com.microsoft.jdbc.sqlserver.SQLServerDriver")); queryDataSet1.setQuery(new com.borland.dx.sql.dataset.QueryDescriptor(database1, "", null, true, Load.ALL)); this.add(jLabel4, null); this.add(jLabel2, null); this.add(jLabel1, null); this.add(jLabel3, null); this.add(jComboBox1, null); this.add(jTextField2, null); this.add(jButton1, null); this.add(jButton2, null); this.add(jPasswordField1, null); this.add(jTextField3, null); con = barConnect.getconn(); Statement stmt = con.createStatement(); ResultSet boxRs = stmt.executeQuery("select * from ComputerIDView"); jComboBox1.addItem(""); while(boxRs.next()){ jComboBox1.addItem(boxRs.getString("ComputerID"));//连接并查询需要的数据 } con.close(); } void jButton1_actionPerformed(ActionEvent e) { try{ String passwordtemp = ""; for(int i=0;i<jPasswordField1.getPassword().length;i++){ passwordtemp += jPasswordField1.getPassword()[i]; } if(jTextField2.getText().trim() != ""){//测试用户是否输入卡号 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')"; int rs2 = insertStmt.executeUpdate(insertString); } else { jTextField2.setText("卡号或者密码不对"); } rs1.close(); } con.close(); } catch(SQLException ex){ System.out.print("系统错误,请检测数据库"); } welcomePanel welcomePanel2 = new welcomePanel(); Frame1.remove(Frame1.getContentPane()); Frame1.getContentPane().add(welcomePanel2); Frame1.setContentPane(welcomePanel2); Frame1.show(); } private mainFrame Frame1; Database database1 = new Database(); QueryDataSet queryDataSet1 = new QueryDataSet();}class userInPanel_jButton1_actionAdapter implements java.awt.event.ActionListener { userInPanel adaptee; userInPanel_jButton1_actionAdapter(userInPanel adaptee) { this.adaptee = adaptee; } public void actionPerformed(ActionEvent e) { adaptee.jButton1_actionPerformed(e); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -