📄 delcustomerpanel.java
字号:
package bank;
import javax.swing.JPanel;
import javax.swing.JButton;
import com.borland.jbcl.layout.XYLayout;
import com.borland.jbcl.layout.*;
import javax.swing.UIManager;
import javax.swing.JLabel;
import java.awt.Font;
import javax.swing.JTextField;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.sql.Statement;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.swing.JOptionPane;
import java.awt.Color;
public class DelCustomerPanel extends JPanel{
public DelCustomerPanel() {
try {
jbInit();
}
catch (Exception ex) {
ex.printStackTrace();
}
}
private void jbInit() throws Exception {
this.setLayout(xYLayout1);
this.setBackground(UIManager.getColor("ToolTip.background"));
jButton1.setFont(new java.awt.Font("Dialog", Font.PLAIN, 12));
jButton1.setText("确定");
this.setBackground(new Color(176, 227, 249));
jButton1.addActionListener(new DelCustomerPanel_jButton1_actionAdapter(this));
jLabel1.setFont(new java.awt.Font("宋体", Font.PLAIN, 16));
jLabel1.setText("卡号:");
jLabel2.setFont(new java.awt.Font("宋体", Font.PLAIN, 16));
jLabel2.setText("客户名:");
jLabel3.setFont(new java.awt.Font("宋体", Font.PLAIN, 16));
jLabel3.setText("城市:");
jTextField3.setEditable(false);
jTextField2.setEditable(false);
jButton2.setFont(new java.awt.Font("Dialog", Font.PLAIN, 12));
jButton2.setText("显示信息");
jButton2.addActionListener(new DelCustomerPanel_jButton2_actionAdapter(this));
jLabel4.setFont(new java.awt.Font("Dialog", Font.PLAIN, 16));
jLabel4.setText("客户ID:");
jTextField4.setEditable(false);
jButton3.setFont(new java.awt.Font("Dialog", Font.PLAIN, 12));
jButton3.setText("重置");
jButton3.addActionListener(new DelCustomerPanel_jButton3_actionAdapter(this));
this.add(jLabel3, new XYConstraints(37, 209, 71, 26));
this.add(jLabel2, new XYConstraints(35, 146, 70, 38));
this.add(jLabel4, new XYConstraints(36, 86, 71, 38));
this.add(jTextField2, new XYConstraints(113, 154, 167, 34));
this.add(jTextField3, new XYConstraints(114, 204, 167, 32));
this.add(jTextField4, new XYConstraints(112, 94, 168, 34));
this.add(jTextField1, new XYConstraints(113, 44, 164, 31));
this.add(jLabel1, new XYConstraints(37, 39, 58, 35));
this.add(jButton1, new XYConstraints(300, 201, 88, 33));
this.add(jButton2, new XYConstraints(301, 158, 86, 32));
this.add(jButton3, new XYConstraints(303, 112, 87, 30));
}
XYLayout xYLayout1 = new XYLayout();
JButton jButton1 = new JButton();
JLabel jLabel1 = new JLabel();
JLabel jLabel2 = new JLabel();
JLabel jLabel3 = new JLabel();
JTextField jTextField1 = new JTextField();
JTextField jTextField2 = new JTextField();
JTextField jTextField3 = new JTextField();
JButton jButton2 = new JButton();
private static int count=0;
private Connection con;
JLabel jLabel4 = new JLabel();
JTextField jTextField4 = new JTextField();
JButton jButton3 = new JButton();
public void jButton2_actionPerformed(ActionEvent e) {
if(e.getSource()==jButton2) //显示信息
{
jTextField2.setText("");
jTextField3.setText("");
jTextField4.setText("");
try {
con = bankconnect.getconn();
Statement stmt = con.createStatement();
int i=0;
ResultSet rs = stmt.executeQuery("select * from customer,account,depositor where account.account_num="+Integer.parseInt(jTextField1.getText().trim())+" and account.account_num=depositor.account_num and depositor.customer_id=customer.customer_id");
while(rs.next())
{
jTextField2.setText(rs.getString("customer_name"));
jTextField3.setText(rs.getString("customer_city"));
jTextField4.setText(rs.getString("customer_id"));
rs.close();
con.close();
i=1;
return ;
}
if(i==0) JOptionPane.showMessageDialog( null,"不存在这个客户!");
else JOptionPane.showMessageDialog( null,"确定删除吗?");
}
catch (SQLException ex) {
System.out.println("数据库连接出错!"+ex.toString());
}
}
}
public void jButton1_actionPerformed(ActionEvent e) {
if(e.getSource()==jButton1)//delete
{
try{
con=bankconnect.getconn();
Statement stmt=con.createStatement();
try{
//这里还需要好好处理一下
con.setAutoCommit(false);
String sql = "delete from depositor where account_num=" +
Long.parseLong(jTextField1.getText().trim());
stmt.executeUpdate(sql);
stmt.executeUpdate("delete from customer where customer_id like '%" +
jTextField4.getText().trim()+"%'");
sql = "delete from account where account_num=" +
Long.parseLong(jTextField1.getText().trim());
stmt.executeUpdate(sql);
con.commit();
con.setAutoCommit(true);
JOptionPane.showMessageDialog(null, "客户已经成功被删除!!!");
con.close();
}catch(Exception exp){
con.rollback();
con.close();
con.setAutoCommit(true);
exp.printStackTrace();
}
}
catch(SQLException ex)
{
System.out.println("数据库连接出错!"+ex.toString());
}
}
}
public void jButton3_actionPerformed(ActionEvent e) {
jTextField1.setText("");
jTextField2.setText("");
jTextField3.setText("");
jTextField4.setText("");
}
}
class DelCustomerPanel_jButton3_actionAdapter
implements ActionListener {
private DelCustomerPanel adaptee;
DelCustomerPanel_jButton3_actionAdapter(DelCustomerPanel adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton3_actionPerformed(e);
}
}
class DelCustomerPanel_jButton1_actionAdapter
implements ActionListener {
private DelCustomerPanel adaptee;
DelCustomerPanel_jButton1_actionAdapter(DelCustomerPanel adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton1_actionPerformed(e);
}
}
class DelCustomerPanel_jButton2_actionAdapter
implements ActionListener {
private DelCustomerPanel adaptee;
DelCustomerPanel_jButton2_actionAdapter(DelCustomerPanel adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton2_actionPerformed(e);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -