?? frame_card_guashi.java
字號:
package student_computer;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2006</p>
* <p>Company: </p>
* @author not attributable
* @version 1.0
*/
public class Frame_card_guashi extends JFrame {
JLabel jLabel1 = new JLabel();
JLabel jLabel2 = new JLabel();
JLabel jLabel3 = new JLabel();
JTextField jTextField1 = new JTextField();
JLabel jLabel4 = new JLabel();
JTextField jTextField2 = new JTextField();
JButton jButton1 = new JButton();
JButton jButton2 = new JButton();
public Frame_card_guashi() {
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
private void jbInit() throws Exception {
jLabel1.setFont(new java.awt.Font("Dialog", 0, 32));
jLabel1.setText("卡號掛失");
jLabel1.setBounds(new Rectangle(115, 16, 148, 48));
this.getContentPane().setLayout(null);
jLabel2.setFont(new java.awt.Font("Dialog", 0, 16));
jLabel2.setText("請輸入學(xué)號或者卡號:");
jLabel2.setBounds(new Rectangle(79, 75, 212, 29));
jLabel3.setFont(new java.awt.Font("Dialog", 0, 16));
jLabel3.setText("學(xué)號:");
jLabel3.setBounds(new Rectangle(79, 116, 68, 27));
jTextField1.setText("");
jTextField1.setBounds(new Rectangle(170, 116, 106, 27));
jLabel4.setFont(new java.awt.Font("Dialog", 0, 16));
jLabel4.setText("卡號:");
jLabel4.setBounds(new Rectangle(79, 159, 59, 33));
jTextField2.setText("");
jTextField2.setBounds(new Rectangle(170, 162, 108, 27));
jButton1.setBounds(new Rectangle(79, 211, 87, 29));
jButton1.setFont(new java.awt.Font("Dialog", 0, 16));
jButton1.setText("掛失");
jButton1.addActionListener(new Frame_card_guashi_jButton1_actionAdapter(this));
jButton2.setBounds(new Rectangle(211, 213, 87, 29));
jButton2.setFont(new java.awt.Font("Dialog", 0, 16));
jButton2.setText("恢復(fù)");
jButton2.addActionListener(new Frame_card_guashi_jButton2_actionAdapter(this));
this.getContentPane().add(jLabel1, null);
this.getContentPane().add(jTextField1, null);
this.getContentPane().add(jLabel3, null);
this.getContentPane().add(jLabel2, null);
this.getContentPane().add(jLabel4, null);
this.getContentPane().add(jTextField2, null);
this.getContentPane().add(jButton1, null);
this.getContentPane().add(jButton2, null);
this.setSize(400,300);
this.setLocation(250,190);
}
void jButton1_actionPerformed(ActionEvent e) {
String student_num=jTextField1.getText().trim();
String card=jTextField2.getText().trim();
if(student_num.equals("")&&card.equals(""))
{
JOptionPane.showMessageDialog(this,"學(xué)號和卡號不能同時為空!!!","提示",JOptionPane.PLAIN_MESSAGE);
return;
}
try{
String driverName = "com.microsoft.jdbc.sqlserver.SQLServerDriver";
String dbURL = "jdbc:microsoft:sqlserver://210.30.104.11:1433; DatabaseName=student_computer";
String userName = "xueli";
String userPwd = "gejingguo";
Class.forName(driverName);
Connection con = DriverManager.getConnection(dbURL, userName, userPwd);
PreparedStatement stmt=null;
//System.out.println(apartid+dom_id+date);
if(student_num.equals(""))
{
stmt=con.prepareStatement("update card set card_state='掛失' where card_number=?");
stmt.setString(1,card);
}
else
{
stmt = con.prepareStatement(
"update card set card_state='掛失' where student_number=?");
stmt.setString(1,student_num);
}
int a=stmt.executeUpdate();
if(a!=0)
{
JOptionPane.showMessageDialog(this,"掛失成功!!!","提示",JOptionPane.PLAIN_MESSAGE);
return;
}
else
{
JOptionPane.showMessageDialog(this,"掛失失敗,請確認(rèn)有該記錄!!!","提示",JOptionPane.PLAIN_MESSAGE);
return;
}
}catch(Exception e4)
{
JOptionPane.showMessageDialog(this,"掛失失敗,請確認(rèn)有該記錄!!!","提示",JOptionPane.PLAIN_MESSAGE);
return;
//e4.printStackTrace();
}
}
/////////////掛失恢復(fù)
void jButton2_actionPerformed(ActionEvent e) {
String student_num=jTextField1.getText().trim();
String card=jTextField2.getText().trim();
if(student_num.equals("")&&card.equals(""))
{
JOptionPane.showMessageDialog(this,"學(xué)號和卡號不能同時為空!!!","提示",JOptionPane.PLAIN_MESSAGE);
return;
}
try{
String driverName = "com.microsoft.jdbc.sqlserver.SQLServerDriver";
String dbURL = "jdbc:microsoft:sqlserver://210.30.104.11:1433; DatabaseName=student_computer";
String userName = "xueli";
String userPwd = "gejingguo";
Class.forName(driverName);
Connection con = DriverManager.getConnection(dbURL, userName, userPwd);
PreparedStatement stmt=null;
//System.out.println(apartid+dom_id+date);
if(student_num.equals(""))
{
stmt=con.prepareStatement("update card set card_state='正常' where card_number=?");
stmt.setString(1,card);
}
else
{
stmt = con.prepareStatement(
"update card set card_state='正常' where student_number=?");
stmt.setString(1,student_num);
}
int a=stmt.executeUpdate();
if(a!=0)
{
JOptionPane.showMessageDialog(this,"掛失恢復(fù)成功!!!","提示",JOptionPane.PLAIN_MESSAGE);
return;
}
else
{
JOptionPane.showMessageDialog(this,"掛失恢復(fù)失敗,請確認(rèn)有該記錄!!!","提示",JOptionPane.PLAIN_MESSAGE);
return;
}
}catch(Exception e4)
{
JOptionPane.showMessageDialog(this,"掛失恢復(fù)失敗,請確認(rèn)有該記錄!!!","提示",JOptionPane.PLAIN_MESSAGE);
return;
//e4.printStackTrace();
}
}
}
class Frame_card_guashi_jButton1_actionAdapter implements java.awt.event.ActionListener {
Frame_card_guashi adaptee;
Frame_card_guashi_jButton1_actionAdapter(Frame_card_guashi adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton1_actionPerformed(e);
}
}
class Frame_card_guashi_jButton2_actionAdapter implements java.awt.event.ActionListener {
Frame_card_guashi adaptee;
Frame_card_guashi_jButton2_actionAdapter(Frame_card_guashi adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton2_actionPerformed(e);
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -