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

📄 transfer.java

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

package javaapplication1;
import java.awt.Toolkit;
import java.sql.*;
import javax.swing.JOptionPane;
/**
 *
 * @author  zzz
 */
public class Transfer extends javax.swing.JFrame {
    String staffID = "";
    /** Creates new form Transfer */
    public Transfer(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();
        aimField = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        sumField = new javax.swing.JTextField();
        confirmButton = new javax.swing.JButton();
        resetButton = new javax.swing.JButton();
        cancelButton = new javax.swing.JButton();
        jLabel5 = new javax.swing.JLabel();
        passwordField = new javax.swing.JPasswordField();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        jLabel1.setText("\u8f6c\u5e10");

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

        jLabel3.setText("\u63a5\u6536\u5e10\u53f7");

        jLabel4.setText("\u8f6c\u5e10\u91d1\u989d");

        confirmButton.setText("\u786e\u8ba4");
        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);
            }
        });

        jLabel5.setText("\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(133, 133, 133)
                .add(jLabel1)
                .addContainerGap(117, Short.MAX_VALUE))
            .add(layout.createSequentialGroup()
                .add(50, 50, 50)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(layout.createSequentialGroup()
                        .add(jLabel5)
                        .addContainerGap())
                    .add(layout.createSequentialGroup()
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(layout.createSequentialGroup()
                                .add(confirmButton)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(resetButton)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(cancelButton))
                            .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                                .add(jLabel2)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(accountField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 132, Short.MAX_VALUE))
                            .add(layout.createSequentialGroup()
                                .add(jLabel4)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(sumField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 132, Short.MAX_VALUE))
                            .add(layout.createSequentialGroup()
                                .add(jLabel3)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                    .add(passwordField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 132, Short.MAX_VALUE)
                                    .add(aimField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 132, Short.MAX_VALUE))))
                        .add(39, 39, 39))))
        );
        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(jLabel5)
                    .add(passwordField, 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(aimField, 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(jLabel4)
                    .add(sumField, 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(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        pack();
    }// </editor-fold>//GEN-END:initComponents

    //提交响应事件代码
    private void confirmButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_confirmButtonActionPerformed
// TODO 将在此处添加您的处理代码:
        String accountID = " "+accountField.getText();
        String aimID = " "+aimField.getText();
        String password = passwordField.getText();
        int sum = Integer.parseInt(sumField.getText());
        
        CallableStatement proc = null;
        try
        {
            String sql = "select * from deAccount where accountID = '"+accountID+"'";
            Statement stat = transferMoney.createStatement();
            ResultSet result = stat.executeQuery(sql);
            if(!result.next())
            {
                JOptionPane.showMessageDialog(null,"您输入的转帐帐户不存在,请确认后重新输入!","出错",JOptionPane.ERROR_MESSAGE);
                accountField.setText("");
            }
            else
            {
                String sql4 = "select * from deAccount where accountID = '"+accountID+"' and accountType='CU'";
                ResultSet result4 = stat.executeQuery(sql4);
                if(!result4.next())
                {
                    JOptionPane.showMessageDialog(null,"您输入的转帐帐户不是活期帐户,请确认后重新输入!","出错",JOptionPane.ERROR_MESSAGE);
                    accountField.setText("");
                }
                else
                {
                    String sql5 = "select * from deAccount where accountID = '"+aimID+"' and accountType='CU'";
                    ResultSet result5 = stat.executeQuery(sql5);
                    if(!result5.next())
                    {
                        JOptionPane.showMessageDialog(null,"您输入的目的帐户不是活期帐户,请确认后重新输入!","出错",JOptionPane.ERROR_MESSAGE);
                        aimField.setText("");
                    }
                    else
                    {
                        String sql1 = "select * from deAccount where accountID = '"+accountID+"' and accountPassword = '"+password+"'";
                        ResultSet result1 = stat.executeQuery(sql1);
                        if(!result1.next())
                        {
                            JOptionPane.showMessageDialog(null,"您输入的密码错误,请确认后重新输入!","出错",JOptionPane.ERROR_MESSAGE);
                            passwordField.setText("");
                        }
                        else
                        {
                            String sql2 = "select * from deAccount where accountID = '"+aimID+"'";
                            ResultSet result2 = stat.executeQuery(sql2);
                            if(!result2.next())
                            {
                                JOptionPane.showMessageDialog(null,"您输入的目的帐户不存在,请确认后重新输入!","出错",JOptionPane.ERROR_MESSAGE);
                                aimField.setText("");
                            }
                            else
                            {
                                String sql3 = "select * from deAccount where accountID = '"+accountID+"' and accountSum >"+sum;
                                ResultSet result3 = stat.executeQuery(sql3);
                                if(!result3.next())
                                {
                                    JOptionPane.showMessageDialog(null,"您输入的帐户余额,请确认后重新输入!","出错",JOptionPane.ERROR_MESSAGE);
                                    sumField.setText("");
                                }
                                else
                                {
                                    proc = transferMoney.prepareCall("{ call TransMoney(?,?,?,?) }");
                                    proc.setString(1, staffID);
                                    proc.setString(2, accountID);  
                                    proc.setString(3, aimID);
                                    proc.setInt(4, sum);
                                    proc.execute(); 
                                    this.dispose();
                                    proc.close();
                                    transferMoney.close();
                                }
                            }
                        }
                    }
                }
            }
         }
         catch(Exception insertAccountException)
         {
            insertAccountException.printStackTrace();
         }
    }//GEN-LAST:event_confirmButtonActionPerformed

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


    //取消事件按钮
    private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelButtonActionPerformed
// TODO 将在此处添加您的处理代码:
        this.dispose();
        try
        {
            transferMoney.close();
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
    }//GEN-LAST:event_cancelButtonActionPerformed
    
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Transfer(" 00007").setVisible(true);
            }
        });
    }
    
    //连接数据库操作------------------------------
    private void connectDB()
    {
        String dbUrl = "jdbc:odbc:afei";
        String user = "scott";
        String password = "tiger";
        try
        {
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
            transferMoney = DriverManager.getConnection(dbUrl,user,password);
        }
        catch(Exception connectException)
        {
            connectException.printStackTrace();
        }
    }
    
    // 变量声明 - 不进行修改//GEN-BEGIN:variables
    private javax.swing.JTextField accountField;
    private javax.swing.JTextField aimField;
    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.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JPasswordField passwordField;
    private javax.swing.JButton resetButton;
    private javax.swing.JTextField sumField;
    // 变量声明结束//GEN-END:variables
    private Connection transferMoney;
}

⌨️ 快捷键说明

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