package netbarfeemanagement;
import java.awt.*;
import javax.swing.*;
import java.util.*;
import java.text.SimpleDateFormat;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class LoginPanel
extends JPanel {
public LoginPanel() {
try {
jbInit();
}
catch (Exception exception) {
exception.printStackTrace();
}
}
private void jbInit() throws Exception {
this.setLayout(null);
jLabel1.setFont(new java.awt.Font("Dialog", Font.BOLD, 16));
jLabel1.setText("机器号码:");
jLabel1.setBounds(new Rectangle(60, 29, 89, 27));
jLabel2.setFont(new java.awt.Font("Dialog", Font.BOLD, 16));
jLabel2.setText("卡 号:");
jLabel2.setBounds(new Rectangle(60, 71, 89, 27));
jLabel3.setFont(new java.awt.Font("Dialog ", Font.BOLD, 16));
jLabel3.setText("密 码:");
jLabel3.setBounds(new Rectangle(60, 113, 89, 27));
jLabel4.setFont(new java.awt.Font("Dialog", Font.BOLD, 16));
jLabel4.setText("开始时间:");
jLabel4.setBounds(new Rectangle(60, 155, 89, 27));
comComputerNo.setFont(new java.awt.Font("Dialog", Font.BOLD, 16));
comComputerNo.setBounds(new Rectangle(192, 29, 140, 27));
txtCardNo.setFont(new java.awt.Font("Dialog", Font.BOLD, 16));
txtCardNo.setText("");
txtCardNo.setBounds(new Rectangle(192, 71, 140, 27));
txtPassword.setFont(new java.awt.Font("Dialog", Font.BOLD, 16));
txtPassword.setText("");
txtPassword.setBounds(new Rectangle(191, 113, 140, 27));
txtBeginTime.setFont(new java.awt.Font("Dialog", Font.BOLD, 16));
txtBeginTime.setText("");
txtBeginTime.setBounds(new Rectangle(192, 155, 140, 27));
btnOk.setBounds(new Rectangle(90, 212, 85, 24));
btnOk.setFont(new java.awt.Font("Dialog", Font.BOLD, 16));
btnOk.setText("确 定");
btnOk.addActionListener(new LoginPanel_btnOk_actionAdapter(this));
btnReset.setBounds(new Rectangle(229, 212, 85, 24));
btnReset.setFont(new java.awt.Font("Dialog", Font.BOLD, 16));
btnReset.setText("重 置");
btnReset.addActionListener(new LoginPanel_btnReset_actionAdapter(this));
this.add(txtPassword);
this.add(comComputerNo);
this.add(txtCardNo);
this.add(txtBeginTime);
this.add(jLabel4);
this.add(jLabel1);
this.add(jLabel2);
this.add(jLabel3);
this.add(btnOk);
this.add(btnReset);
txtBeginTime.setEnabled(false);
setComboBoxValues();
}
public void setComboBoxValues(){
DBConnection con = new DBConnection();
Vector v = con.selectComputerNo(0);
for(int i=0; i<v.size(); i++){
comComputerNo.addItem(v.get(i));
}
}
JLabel jLabel1 = new JLabel();
JLabel jLabel2 = new JLabel();
JLabel jLabel3 = new JLabel();
JLabel jLabel4 = new JLabel();
JComboBox comComputerNo = new JComboBox();
JTextField txtCardNo = new JTextField();
JPasswordField txtPassword = new JPasswordField();
JTextField txtBeginTime = new JTextField();
JButton btnOk = new JButton();
JButton btnReset = new JButton();
public void btnOk_actionPerformed(ActionEvent e) {
String cardNo = txtCardNo.getText().trim();
if(cardNo.equals("")){
JOptionPane.showConfirmDialog(this, "卡号不能为空,请输入卡号!", "信息",
JOptionPane.YES_OPTION, JOptionPane.INFORMATION_MESSAGE);
txtCardNo.requestFocus(true);
return;
}
String passwordNo = new String(txtPassword.getPassword());
if(passwordNo.equals("")){
JOptionPane.showConfirmDialog(this, "密码不能为空,请输入密码!", "信息",
JOptionPane.YES_OPTION, JOptionPane.INFORMATION_MESSAGE);
txtPassword.requestFocus(true);
return;
}
DBConnection con = new DBConnection();
String vpassword = con.selectCardNo(cardNo);
if(vpassword == null){
JOptionPane.showConfirmDialog(this, "你输入的卡号有误,请重新输入卡号!", "信息",
JOptionPane.YES_OPTION, JOptionPane.INFORMATION_MESSAGE);
txtCardNo.requestFocus(true);
txtCardNo.setSelectionStart(0);
txtCardNo.setSelectionEnd(cardNo.length());
return;
}
if(!vpassword.equals(passwordNo)){
JOptionPane.showConfirmDialog(this, "输入的密码有误,请重新输入密码!", "信息",
JOptionPane.YES_OPTION, JOptionPane.INFORMATION_MESSAGE);
txtPassword.requestFocus(true);
txtPassword.setSelectionStart(0);
txtPassword.setSelectionEnd(passwordNo.length());
return;
}
if(con.isCardExists(cardNo)){
JOptionPane.showConfirmDialog(this, "卡号不能重复使用!", "警告",
JOptionPane.YES_OPTION, JOptionPane.WARNING_MESSAGE);
txtCardNo.requestFocus(true);
txtCardNo.requestFocus(true);
txtCardNo.setSelectionStart(0);
txtCardNo.setSelectionEnd(cardNo.length());
return;
}
DataBean bean = new DataBean();
String machineNo = comComputerNo.getSelectedItem().toString();
Date now = new Date();
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd kk:mm:ss");
String begintime = df.format(now);
txtBeginTime.setText(begintime);
/////////////////////////////////////////
bean.setCardNo(cardNo);
bean.setMachineNo(machineNo);
bean.setBeginTime(begintime);
con.loginOperation(bean);
comComputerNo.setEnabled(false);
System.out.println("登录成功!");
}
public void btnReset_actionPerformed(ActionEvent e) {
comComputerNo.removeAllItems();
setComboBoxValues();
comComputerNo.setEnabled(true);
comComputerNo.setSelectedIndex(0);
txtCardNo.setText("");
txtPassword.setText("");
txtBeginTime.setText("");
txtCardNo.requestFocus(true);
}
}
class LoginPanel_btnReset_actionAdapter
implements ActionListener {
private LoginPanel adaptee;
LoginPanel_btnReset_actionAdapter(LoginPanel adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.btnReset_actionPerformed(e);
}
}
class LoginPanel_btnOk_actionAdapter
implements ActionListener {
private LoginPanel adaptee;
LoginPanel_btnOk_actionAdapter(LoginPanel adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.btnOk_actionPerformed(e);
}
}
评论0