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

📄 deletereader.java

📁 这是一个用jbuilder2005编写的图书管理系统
💻 JAVA
字号:
package bookmanage;

import javax.swing.*;
import java.awt.Rectangle;
import java.awt.SystemColor;
import javax.swing.border.Border;
import javax.swing.border.TitledBorder;
import java.awt.Color;
import java.awt.Frame;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.sql.ResultSet;
import java.sql.*;

public class DeleteReader
    extends JDialog {
  ButtonGroup buttonGroup1 = new ButtonGroup();
  JPanel jPanel1 = new JPanel();
  Border border1 = BorderFactory.createLineBorder(SystemColor.controlText, 2);
  Border border2 = new TitledBorder(border1, "请在下面选择删除学生");
  JRadioButton jRadioButtonXueHao = new JRadioButton();
  JRadioButton jRadioButtonGrade = new JRadioButton();
  JLabel jLabel1 = new JLabel();
  JLabel jLabel2 = new JLabel();
  JLabel jLabel3 = new JLabel();
  JTextField jTextFieldDRXueHao = new JTextField();
  JTextField jTextFieldDRGrade = new JTextField();
  String xsType[]={"本科生","研究生","硕士生","博士生"};
  JComboBox jComboBoxDRType = new JComboBox(xsType);
  JButton jButtonDRAlert = new JButton();
  JButton jButton2 = new JButton();
  String DRType="";
  String DRLeiXing="";
  String xHao="";
  String nJi="";
  ResultSet rs;
  //定义数据库操作对象
  private DBManager db = new DBManager();
  String strSQL="";


  public DeleteReader(Frame owner, String title, boolean modal) {
    super(owner, title, modal);
    try {
      jbInit();
    }
    catch (Exception ex) {
      ex.printStackTrace();
    }
  }

  private void jbInit() throws Exception {
    border2 = new TitledBorder(BorderFactory.createLineBorder(Color.lightGray,
        2), "请在下面选择删除学生");
    this.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
    this.setResizable(false);
    this.getContentPane().setLayout(null);
    jPanel1.setBorder(border2);
    jPanel1.setBounds(new Rectangle(50, 34, 299, 143));
    jPanel1.setLayout(null);
    jRadioButtonXueHao.setText("按学号:");
    jRadioButtonXueHao.setBounds(new Rectangle(10, 26, 84, 23));
    jRadioButtonXueHao.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        jRadioButtonXueHao_actionPerformed(e);
      }
    });
    jRadioButtonGrade.setText("按年级:");
    jRadioButtonGrade.setBounds(new Rectangle(10, 58, 85, 23));
    jRadioButtonGrade.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        jRadioButtonGrade_actionPerformed(e);
      }
    });
    jLabel1.setText("请输入学号:");
    jLabel1.setBounds(new Rectangle(96, 26, 79, 23));
    jLabel2.setText("请输入年级:");
    jLabel2.setBounds(new Rectangle(96, 91, 79, 23));
    jLabel3.setText("请输入类型:");
    jLabel3.setBounds(new Rectangle(98, 58, 79, 23));
    jTextFieldDRXueHao.setBounds(new Rectangle(184, 26, 97, 23));
    jTextFieldDRGrade.setBounds(new Rectangle(184, 91, 97, 23));
    jComboBoxDRType.setBounds(new Rectangle(183, 58, 97, 23));
    jComboBoxDRType.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        jComboBoxDRType_actionPerformed(e);
      }
    });
    jButtonDRAlert.setBounds(new Rectangle(82, 196, 81, 23));
    jButtonDRAlert.setText("确定删除");
    jButtonDRAlert.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        jButtonDRAlert_actionPerformed(e);
      }
    });
    jButton2.setBounds(new Rectangle(224, 195, 81, 23));
    jButton2.setText("取消");
    jButton2.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        jButton2_actionPerformed(e);
      }
    });
    this.getContentPane().add(jPanel1);
    jPanel1.add(jLabel1);
    jPanel1.add(jTextFieldDRXueHao);
    jPanel1.add(jComboBoxDRType);
    jPanel1.add(jLabel3);
    jPanel1.add(jLabel2);
    jPanel1.add(jTextFieldDRGrade);
    jPanel1.add(jRadioButtonXueHao);
    jPanel1.add(jRadioButtonGrade);
    this.getContentPane().add(jButtonDRAlert);
    this.getContentPane().add(jButton2);
    buttonGroup1.add(jRadioButtonXueHao);
    buttonGroup1.add(jRadioButtonGrade);
  }

  public void jButton2_actionPerformed(ActionEvent e) {
    this.dispose();
  }

  public void jComboBoxDRType_actionPerformed(ActionEvent e) {
    DRType=(String)jComboBoxDRType.getSelectedItem();
    if(DRType!=null)
      DRType=DRType.trim();
    else
      DRType="";
  }

  public void jRadioButtonXueHao_actionPerformed(ActionEvent e) {
    DRLeiXing="xueHao";
  }

  public void jRadioButtonGrade_actionPerformed(ActionEvent e) {
    DRLeiXing="grade";
  }


  /**
   *
   * @param e ActionEvent
   *
   */
  public void jButtonDRAlert_actionPerformed(ActionEvent e) {
    xHao=jTextFieldDRXueHao.getText();
    if(xHao!=null)
      xHao=xHao.trim();
    else
      xHao="";
    nJi=jTextFieldDRGrade.getText();
    if(nJi!=null)
      nJi=nJi.trim();
    else
      nJi="";
    if(DRLeiXing.equals("xueHao")){
      if (xHao.equals("")) {
        JOptionPane.showMessageDialog(this, "学号不许为空!");
        return;
      }
      //生成sql操作语句,查询要删除的用户名是否存在,若存在执行删除,若不存在提示并返回
      strSQL = "select * from buser where xuehao='" +
          xHao + "'";
      rs = db.getResult(strSQL);

      boolean isexist = false;
      try {
        isexist = rs.first();
      }
      catch (SQLException ex1) {
      }
      //若用户名不存在,提示警告信息
      if (!isexist)
      {
        JOptionPane.showMessageDialog(this, "此学生不存在!");

      }
      else {
        try{
          float fakuan=rs.getFloat("penalty");
          System.out.println(""+fakuan);
          if(fakuan>0){
            JOptionPane.showMessageDialog(this, "此学生还有欠款,不能被删除!");
            return;
          }
        }catch(Exception el){
          el.printStackTrace();
        }

        strSQL = "delete from buser where xuehao='" + xHao + "'";
        //由数据库操作对象执行数据库操作,并返回操作成功失败的提示信息
        if (db.executeSql(strSQL)) {
          JOptionPane.showMessageDialog(this, "成功删除!");
          jTextFieldDRXueHao.setText("");
        }
        else {
          JOptionPane.showMessageDialog(this, " 删除失败,可能该读者还没有还完书,请重新操作!");
          jTextFieldDRXueHao.setText("");
        }
        db.close();
      }
    }
    else if(DRLeiXing.equals("grade")){
      nJi=jRadioButtonGrade.getText().trim();
      if(DRType.equals("")){
        JOptionPane.showMessageDialog(this, "学生类型不能为空!!");
        return;
      }
      if(nJi.equals("")){
        JOptionPane.showMessageDialog(this, "年级不能为空!!");
        return;
      }
      strSQL = "select * from buser where grade='"+nJi+ "' and bookNumOfBorrow=0"+
          "and penalty=0";
      rs = db.getResult(strSQL);
      boolean isexist = false;
      try {
        isexist = rs.first();
      }
      catch (SQLException ex1) {
      }
      //若用户名不存在,提示警告信息
      if (!isexist)
      {
        JOptionPane.showMessageDialog(this, "满足条件的学生不存在!");
      }
      else{
        strSQL = "delete from buser where grade='"+nJi+"' and bookNumOfBorrow=0 and penalty=0";
        if (db.executeSql(strSQL)) {
         JOptionPane.showMessageDialog(this, "成功删除!");
         jTextFieldDRGrade.setText("");
       }
       else {
         JOptionPane.showMessageDialog(this, " 删除失败,请重新操作!");
         jTextFieldDRGrade.setText("");
       }
       db.close();
      }
    }
  }

}

⌨️ 快捷键说明

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