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

📄 staffmanage.java

📁 一个简单的银行管理系统
💻 JAVA
字号:
/*
 * StaffManage.java
 *
 * Created on 2007年1月19日, 上午5:30
 */

package javaapplication1;
import java.awt.Toolkit;
import java.sql.*;
import javax.swing.table.DefaultTableModel;
import javax.swing.*;
/**
 *
 * @author  lab
 */
public class StaffManage extends javax.swing.JFrame {
    
    /** Creates new form StaffManage */
    public StaffManage() {
        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();
        IDField = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        loginIDField = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        passwordField = new javax.swing.JPasswordField();
        confirmButton = new javax.swing.JButton();
        resetButton = new javax.swing.JButton();
        cancelButton = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        jLabel1.setText("\u5458\u5de5\u64cd\u4f5c\u5e10\u53f7\u5206\u914d");

        jLabel2.setText("\u5458\u5de5\u53f7");

        jLabel3.setText("\u64cd\u4f5c\u5e10\u53f7");

        jLabel4.setText("\u5bc6\u7801\u8bbe\u7f6e");

        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(61, 61, 61)
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(layout.createSequentialGroup()
                                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                    .add(jLabel2)
                                    .add(jLabel3)
                                    .add(jLabel4))
                                .add(13, 13, 13)
                                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
                                    .add(passwordField)
                                    .add(loginIDField)
                                    .add(IDField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 128, Short.MAX_VALUE)))
                            .add(layout.createSequentialGroup()
                                .add(confirmButton)
                                .add(29, 29, 29)
                                .add(resetButton)
                                .add(28, 28, 28)
                                .add(cancelButton))))
                    .add(layout.createSequentialGroup()
                        .add(131, 131, 131)
                        .add(jLabel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 119, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(36, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(jLabel1)
                .add(16, 16, 16)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel2)
                    .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(jLabel3)
                    .add(loginIDField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .add(24, 24, 24)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(passwordField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jLabel4))
                .add(32, 32, 32)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(confirmButton)
                    .add(resetButton)
                    .add(cancelButton))
                .addContainerGap(25, 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
        {
            staffManage.close();
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
    }//GEN-LAST:event_cancelButtonActionPerformed


    //重置按钮响应事件
    private void resetButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_resetButtonActionPerformed
// TODO 将在此处添加您的处理代码:
        IDField.setText("");
        loginIDField.setText("");
        passwordField.setText("");
    }//GEN-LAST:event_resetButtonActionPerformed

    //确认提交响应代码
    private void confirmButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_confirmButtonActionPerformed
// TODO 将在此处添加您的处理代码:
        String staffID = " "+IDField.getText();
        String loginID = loginIDField.getText();
        String password = passwordField.getText();
        if(staffID == null || loginID == null)
        {
            JOptionPane.showMessageDialog(this,"信息请填写完整!","出错",JOptionPane.ERROR_MESSAGE);
            IDField.setText("");
            loginIDField.setText("");
            passwordField.setText("");            
        }
        else
        {
            try
            {
                String sql = "Select * from staff where staffID='"+staffID+"'";
                Statement stat = staffManage.createStatement();
                ResultSet result = stat.executeQuery(sql);
                if(!result.next())
                {
                    JOptionPane.showMessageDialog(this,"该员工不存在!","出错",JOptionPane.ERROR_MESSAGE);
                    IDField.setText("");
                }
                else
                {
                    CallableStatement proc = null;
                    proc = staffManage.prepareCall("{ call InsertStaffOperate(?,?,?) }");
                    proc.setString(1, staffID);
                    proc.setString(2, loginID); 
                    proc.setString(3,password);
                    proc.execute();
                    
                    proc.close();
                    staffManage.close();
                    this.dispose();
                } 
            }
            catch(Exception staffManageException)
            {
                staffManageException.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 StaffManage().setVisible(true);
            }
        });
    }
     //连接数据库操作------------------------------
    public void connectDB()
    {
        String dbUrl = "jdbc:odbc:afei";
        String user = "scott";
        String password = "tiger";
        try
        {
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
            staffManage = DriverManager.getConnection(dbUrl,user,password);
        }
        catch(Exception connectException)
        {
            connectException.printStackTrace();
        }
    }
    
    // 变量声明 - 不进行修改//GEN-BEGIN:variables
    private javax.swing.JTextField IDField;
    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.JTextField loginIDField;
    private javax.swing.JPasswordField passwordField;
    private javax.swing.JButton resetButton;
    // 变量声明结束//GEN-END:variables
     private Connection staffManage;
}

⌨️ 快捷键说明

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