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

📄 d_deluser.java

📁 图书管理系统
💻 JAVA
字号:
/*
 * D_deluser.java
 *
 * Created on 2007年6月24日, 下午10:08
 */

package 图书管理系统;
import javax.swing.*;
import java.sql.*;

public class D_deluser extends javax.swing.JFrame {
    
    /** Creates new form D_deluser */
    public D_deluser() {
        initComponents();
        con=connect.getcon();
        stmt=connect.getstmt();
        this.setTitle("删除用户");
        this.setBounds(300,250,350,250);
        this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
    }
    
    /** 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();
        T_user = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        PW_adminpw = new javax.swing.JPasswordField();
        B_deluser = new javax.swing.JButton();
        B_cancel = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        jLabel1.setText("\u8bf7\u8f93\u5165\u4f60\u6240\u8981\u5220\u9664\u7684\u7528\u6237\u540d:");

        T_user.setText(" ");

        jLabel2.setText("\u8bf7\u8f93\u5165\u8d85\u7ea7\u7ba1\u7406\u5458\u5bc6\u7801:");

        B_deluser.setText("\u5220\u9664");
        B_deluser.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                B_deluserActionPerformed(evt);
            }
        });

        B_cancel.setText("\u53d6\u6d88");
        B_cancel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                B_cancelActionPerformed(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()
                .addContainerGap()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jLabel1)
                    .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                        .add(B_deluser)
                        .add(jLabel2)))
                .add(31, 31, 31)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(layout.createSequentialGroup()
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(PW_adminpw, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 100, Short.MAX_VALUE)
                            .add(T_user, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 100, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                        .addContainerGap(38, Short.MAX_VALUE))
                    .add(layout.createSequentialGroup()
                        .add(B_cancel)
                        .addContainerGap())))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .add(35, 35, 35)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel1)
                    .add(T_user, 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(jLabel2)
                    .add(PW_adminpw, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 19, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .add(55, 55, 55)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(B_deluser)
                    .add(B_cancel))
                .addContainerGap(60, Short.MAX_VALUE))
        );
        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void B_cancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_B_cancelActionPerformed
// TODO 将在此处添加您的处理代码:
        this.setVisible(false);
    }//GEN-LAST:event_B_cancelActionPerformed

    private void B_deluserActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_B_deluserActionPerformed
// TODO 将在此处添加您的处理代码:
         try{
            boolean sign=false;
            ResultSet rs=stmt.executeQuery("select 用户名,密码,权限  from 用户表");
            String name1,name2,name3,pwold,pwnew,pwcon,level,pw1,pw2;
            name3=T_user.getText().trim();
            while(rs.next()) {
                char ch[];
                name1=loginuser.getusername().trim();
                name2=(String)rs.getString(1).trim();
                if(name2.equals(name3))
                    sign=true;
              if(name1.equals(name2))
              {
                    ch=PW_adminpw.getPassword();
                    pw1=new String(ch).trim();
                    pw2=rs.getString(2).trim();
                    if(!pw1.equals(pw2))
                    {
                        JOptionPane.showMessageDialog(null,"超级管理员密码错误");
                        return;
                    }
                }
            }
            if(sign)
            {
                PreparedStatement sql=con.prepareStatement("delete  from 用户表 where 用户名=?");
                sql.setString(1,name3);
                sql.executeUpdate();
                JOptionPane.showMessageDialog(null,"用户删除成功");
                this.setVisible(false);
                rs.close();
            }
        } 
        catch(Exception ee)
         {
 ee.printStackTrace();
     }
    }//GEN-LAST:event_B_deluserActionPerformed
    
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new D_deluser().setVisible(true);
            }
        });
    }
    
    // 变量声明 - 不进行修改//GEN-BEGIN:variables
    private javax.swing.JButton B_cancel;
    private javax.swing.JButton B_deluser;
    private javax.swing.JPasswordField PW_adminpw;
    private javax.swing.JTextField T_user;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    // 变量声明结束//GEN-END:variables
    private Connection con;
    private Statement stmt;
}

⌨️ 快捷键说明

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