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

📄 changeaccountpassword.java

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

package javaapplication1;
import java.awt.Toolkit;
import java.sql.*;
import javax.swing.JOptionPane;
/**
 *
 * @author  zzz
 */
public class ChangeAccountPassword extends javax.swing.JFrame {
    String staffID = "";
    /** Creates new form ChangeAccountPassword */
    public ChangeAccountPassword(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();
        commitButton = new javax.swing.JButton();
        jLabel2 = new javax.swing.JLabel();
        accountField = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        newPasswordField = new javax.swing.JPasswordField();
        reNewPasswordField = new javax.swing.JPasswordField();
        restButton = new javax.swing.JButton();
        cancelButton = new javax.swing.JButton();
        jLabel5 = new javax.swing.JLabel();
        oldPasswordField = new javax.swing.JPasswordField();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        jLabel1.setText("\u8bf7\u8ba4\u771f\u586b\u5199\u4ee5\u4e0b\u4fe1\u606f");

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

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

        jLabel3.setText("\u65b0\u5bc6\u7801");

        jLabel4.setText("\u91cd\u590d\u65b0\u5bc6\u7801");

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

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

        jLabel5.setText("\u65e7\u5bc6\u7801");

        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(34, 34, 34)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(layout.createSequentialGroup()
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(jLabel4)
                            .add(jLabel3)
                            .add(jLabel5)
                            .add(jLabel2))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(accountField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 199, Short.MAX_VALUE)
                            .add(oldPasswordField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 199, Short.MAX_VALUE)
                            .add(newPasswordField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 199, Short.MAX_VALUE)
                            .add(reNewPasswordField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 199, Short.MAX_VALUE)))
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                        .add(commitButton)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(restButton)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(cancelButton)
                        .add(32, 32, 32)))
                .addContainerGap(33, Short.MAX_VALUE))
            .add(layout.createSequentialGroup()
                .add(119, 119, 119)
                .add(jLabel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 137, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(74, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(jLabel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 25, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .add(17, 17, 17)
                .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(jLabel5)
                    .add(oldPasswordField, 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(newPasswordField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .add(15, 15, 15)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel4)
                    .add(reNewPasswordField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .add(30, 30, 30)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(cancelButton)
                    .add(restButton)
                    .add(commitButton))
                .addContainerGap(31, Short.MAX_VALUE))
        );
        pack();
    }// </editor-fold>//GEN-END:initComponents

    //提交修改资料响应事件
    private void commitButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_commitButtonActionPerformed
// TODO 将在此处添加您的处理代码:
        String accountID = " "+accountField.getText();
        String oldPassword = oldPasswordField.getText();
        String newPassword = newPasswordField.getText();
        String reNewPassword = reNewPasswordField.getText();
        
        if(!newPassword.equals(reNewPassword))
        {
            JOptionPane.showMessageDialog(null,"您输入的两次新密码不一致,请确认后重新输入!","出错",JOptionPane.ERROR_MESSAGE);
            oldPasswordField.setText("");
            newPasswordField.setText("");
            reNewPasswordField.setText("");
        }

        else
        {
            CallableStatement proc = null;
            try
            {
                String sql = "select * from deAccount where accountID = '"+accountID+"'";
 //               String sql = "select * from deAccount where accountID = '"+accountID+"' and accountPassword = '"+oldPassword+"'";
                Statement stat = changeAccountPassword.createStatement();
                ResultSet result = stat.executeQuery(sql);
                if(!result.next())
                {
                    JOptionPane.showMessageDialog(null,"您输入的帐号不存在,请确认后重新输入!","出错",JOptionPane.ERROR_MESSAGE);
                    accountField.setText("");
                    oldPasswordField.setText("");
                    newPasswordField.setText("");
                    reNewPasswordField.setText("");
                }
                else
                {
                    String sql1 = "select * from deAccount where accountID = '"+accountID+"' and accountPassword = '"+oldPassword+"'";
                    ResultSet result1 = stat.executeQuery(sql1);
                    if(!result1.next())
                    {
                        JOptionPane.showMessageDialog(null,"您输入的旧密码不正确,请确认后重新输入!","出错",JOptionPane.ERROR_MESSAGE);
                        accountField.setText("");
                        oldPasswordField.setText("");
                        newPasswordField.setText("");
                        reNewPasswordField.setText("");
                    }
                    else
                    {
                        String sql2 = "select * from deAccount where state='EF' and accountID = '"+accountID+"' and accountPassword = '"+oldPassword+"'";
                        ResultSet result2 = stat.executeQuery(sql2);
                        if(!result2.next())
                        {
                            JOptionPane.showMessageDialog(null,"您输入的帐号已经被挂失,请确认后重新输入!","出错",JOptionPane.ERROR_MESSAGE);
                            oldPasswordField.setText("");
                            newPasswordField.setText("");
                            reNewPasswordField.setText("");
                        }
                        else
                        {
                            proc = changeAccountPassword.prepareCall("{ call ChangeAccountPassword(?,?,?) }");                      
                            proc.setString(1, accountID);
                            proc.setString(2, newPassword); 
                            proc.setString(3, staffID);
                            proc.execute(); 
                            this.dispose();
                            proc.close();
                            changeAccountPassword.close();
                        }
                    }
                }
            }
            catch(Exception insertAccountException)
            {
                insertAccountException.printStackTrace();
            }
        }
    }//GEN-LAST:event_commitButtonActionPerformed

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

    //重置事件代码
    private void restButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_restButtonActionPerformed
// TODO 将在此处添加您的处理代码:
        accountField.setText("");
        oldPasswordField.setText("");
        newPasswordField.setText("");
        reNewPasswordField.setText("");
    }//GEN-LAST:event_restButtonActionPerformed
    
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
    //            new ChangeAccountPassword().setVisible(true);
            }
        });
    }
   
    //连接数据库操作------------------------------
    public void connectDB()
    {
        String dbUrl = "jdbc:odbc:afei";
        String user = "scott";
        String password = "tiger";
        try
        {
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
            changeAccountPassword = DriverManager.getConnection(dbUrl,user,password);
        }
        catch(Exception connectException)
        {
            connectException.printStackTrace();
        }
    }
    // 变量声明 - 不进行修改//GEN-BEGIN:variables
    private javax.swing.JTextField accountField;
    private javax.swing.JButton cancelButton;
    private javax.swing.JButton commitButton;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JPasswordField newPasswordField;
    private javax.swing.JPasswordField oldPasswordField;
    private javax.swing.JPasswordField reNewPasswordField;
    private javax.swing.JButton restButton;
    // 变量声明结束//GEN-END:variables
    private Connection changeAccountPassword;
}

⌨️ 快捷键说明

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