⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 deleteaccount.java

📁 一个简单的银行管理系统
💻 JAVA
字号:
/*
 * DeleteAccount.java
 *
 * Created on 2007年1月19日, 下午3:44
 */

package javaapplication1;
import java.awt.Toolkit;
import java.sql.*;
import javax.swing.JOptionPane;
/**
 *
 * @author  zzz
 */
public class DeleteAccount extends javax.swing.JFrame {
    String staffID = "";
    /** Creates new form DeleteAccount */
    public DeleteAccount(String ID) {
        this.staffID = ID;
        connectDB();
        initComponents();
        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        //-------设置窗口位置居中---------------------------------------------------------------        
        int locationX=(int)(Toolkit.getDefaultToolkit().getScreenSize().getWidth()-getSize().getWidth())/2; 
        int locationY=(int)(Toolkit.getDefaultToolkit().getScreenSize().getHeight()-getSize().getHeight())/2;
        setLocation(locationX,locationY);
        //--------------------------------------------------------------------------------------
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc=" 生成的代码 ">//GEN-BEGIN:initComponents
    private void initComponents() {
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        accountField = new javax.swing.JTextField();
        IDField = new javax.swing.JTextField();
        confirmButton = new javax.swing.JButton();
        resetButton = new javax.swing.JButton();
        cancelButton = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        jLabel1.setText("\u53d6\u6d88\u5e10\u6237");

        jLabel2.setText("\u5e10\u53f7");

        jLabel3.setText("\u8bc1\u4ef6\u53f7");

        confirmButton.setText("\u786e\u5b9a");
        confirmButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                confirmButtonActionPerformed(evt);
            }
        });

        resetButton.setText("\u91cd\u7f6e");
        resetButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                resetButtonActionPerformed(evt);
            }
        });

        cancelButton.setText("\u53d6\u6d88");
        cancelButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cancelButtonActionPerformed(evt);
            }
        });

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(layout.createSequentialGroup()
                        .add(88, 88, 88)
                        .add(jLabel1))
                    .add(layout.createSequentialGroup()
                        .add(29, 29, 29)
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                            .add(layout.createSequentialGroup()
                                .add(jLabel2)
                                .add(15, 15, 15))
                            .add(layout.createSequentialGroup()
                                .add(jLabel3)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)))
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
                            .add(accountField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 106, Short.MAX_VALUE)
                            .add(IDField)))
                    .add(layout.createSequentialGroup()
                        .add(21, 21, 21)
                        .add(confirmButton)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(resetButton)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(cancelButton)))
                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(jLabel1)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel2)
                    .add(accountField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel3)
                    .add(IDField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .add(18, 18, 18)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(confirmButton)
                    .add(resetButton)
                    .add(cancelButton))
                .addContainerGap(23, Short.MAX_VALUE))
        );
        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelButtonActionPerformed
// TODO 将在此处添加您的处理代码:
        this.dispose();
        try
        {
            deleteAccount.close();
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
    }//GEN-LAST:event_cancelButtonActionPerformed

    private void resetButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_resetButtonActionPerformed
// TODO 将在此处添加您的处理代码:
        accountField.setText("");
        IDField.setText("");
    }//GEN-LAST:event_resetButtonActionPerformed

    private void confirmButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_confirmButtonActionPerformed
// TODO 将在此处添加您的处理代码:
        String accountID = " "+accountField.getText();
        String ID = IDField.getText();
        
        CallableStatement proc = null;
        try
        {
            String sql = "select * from deAccount where accountID = '"+accountID+"'";
     //       String sql = "select * from deAccount where state='EF' and accountID = '"+accountID+"' and IDcard = '"+ID+"'";
            Statement stat = deleteAccount.createStatement();
            ResultSet result = stat.executeQuery(sql);
            if(!result.next())
            {
                JOptionPane.showMessageDialog(null,"您输入的帐号不存在,请确认后重新输入!","出错",JOptionPane.ERROR_MESSAGE);
                accountField.setText("");
                IDField.setText("");  
            }
            else
            {
                 String sql1 = "select * from deAccount where accountID = '"+accountID+"' and IDcard = '"+ID+"'";
     //       String sql = "select * from deAccount where state='EF' and accountID = '"+accountID+"' and IDcard = '"+ID+"'";
                ResultSet result1 = stat.executeQuery(sql1);
                if(!result1.next())
                {
                    JOptionPane.showMessageDialog(null,"您输入的证件号错误,请确认后重新输入!","出错",JOptionPane.ERROR_MESSAGE);
                    accountField.setText("");
                    IDField.setText("");  
                }
                else
                {
                    proc = deleteAccount.prepareCall("{ call DeleteAccount(?,?) }");
                    proc.setString(1, accountID);
                    proc.setString(2, staffID);
                    proc.execute(); 
                    this.dispose();
                    proc.close();
                    deleteAccount.close();
                }
            }
         }
         catch(Exception insertAccountException)
         {
            insertAccountException.printStackTrace();
         }
    }//GEN-LAST:event_confirmButtonActionPerformed
    
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
      //          new DeleteAccount().setVisible(true);
            }
        });
    }
    
    //连接数据库操作------------------------------
    private void connectDB()
    {
        String dbUrl = "jdbc:odbc:afei";
        String user = "scott";
        String password = "tiger";
        try
        {
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
            deleteAccount = DriverManager.getConnection(dbUrl,user,password);
        }
        catch(Exception connectException)
        {
            connectException.printStackTrace();
        }
    }
    // 变量声明 - 不进行修改//GEN-BEGIN:variables
    private javax.swing.JTextField IDField;
    private javax.swing.JTextField accountField;
    private javax.swing.JButton cancelButton;
    private javax.swing.JButton confirmButton;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JButton resetButton;
    // 变量声明结束//GEN-END:variables
    private Connection deleteAccount;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -