📄 delete.java
字号:
/* * To change this template, choose Tools | Templates * and open the template in the editor. */package book_booking;import java.awt.*;import java.awt.event.*;import javax.swing.*;import java.sql.*;public class Delete extends JPanel implements ActionListener{ JTextField 书籍号,书名,作者,价格,出版社,库存量; JTextField 书籍号2,书名2,作者2,价格2,出版社2,库存量2; JButton 删除; JButton 删除2; JButton 删除采购单; public Delete() { 书籍号=new JTextField(10); 删除=new JButton("删除书籍",new ImageIcon("D:/book_booking/image/35.jpg")); 书籍号.addActionListener(this); 删除.addActionListener(this); 书名=new JTextField(10); 书名.setEditable(false); 作者=new JTextField(10); 作者.setEditable(false); 价格=new JTextField(10); 价格.setEditable(false); 出版社=new JTextField(10); 出版社.setEditable(false); 库存量=new JTextField(10); 库存量.setEditable(false); 书籍号2=new JTextField(10); 删除2=new JButton("删除采购单中书籍",new ImageIcon("D:/book_booking/image/35.jpg")); 删除采购单=new JButton("删除全部采购单",new ImageIcon("D:/book_booking/image/35.jpg")); 书籍号2.addActionListener(this); 删除2.addActionListener(this); 删除采购单.addActionListener(this); 书名2=new JTextField(10); 书名2.setEditable(false); 作者2=new JTextField(10); 作者2.setEditable(false); 价格2=new JTextField(10); 价格2.setEditable(false); 出版社2=new JTextField(10); 出版社2.setEditable(false); 库存量2=new JTextField(10); 库存量2.setEditable(false); Box box1=Box.createHorizontalBox(); box1.add(new JLabel("输入要删除书籍的书籍号:",new ImageIcon("D:/book_booking/image/48.jpg"),JLabel.CENTER)); box1.add(书籍号); box1.add(删除); Box box2=Box.createHorizontalBox(); box2.add(new JLabel("书名:",JLabel.CENTER)); box2.add(书名); Box box3=Box.createHorizontalBox(); box3.add(new JLabel("作者:",JLabel.CENTER)); box3.add(作者); Box box4=Box.createHorizontalBox(); box4.add(new JLabel("价格:",JLabel.CENTER)); box4.add(价格); Box box5=Box.createHorizontalBox(); box5.add(new JLabel("出版社:",JLabel.CENTER)); box5.add(出版社); Box box6=Box.createHorizontalBox(); box6.add(new JLabel("库存量:",JLabel.CENTER)); box6.add(库存量); Box box7=Box.createHorizontalBox(); box7.add(new JLabel("输入要删除采购单的书籍号:",new ImageIcon("D:/book_booking/image/48.jpg"),JLabel.CENTER)); box7.add(书籍号2); box7.add(删除2); Box box8=Box.createHorizontalBox(); box8.add(new JLabel("书名:",JLabel.CENTER)); box8.add(书名2); Box box9=Box.createHorizontalBox(); box9.add(new JLabel("作者:",JLabel.CENTER)); box9.add(作者2); Box box10=Box.createHorizontalBox(); box10.add(new JLabel("价格:",JLabel.CENTER)); box10.add(价格2); Box box11=Box.createHorizontalBox(); box11.add(new JLabel("出版社:",JLabel.CENTER)); box11.add(出版社2); Box box12=Box.createHorizontalBox(); box12.add(new JLabel("库存量:",JLabel.CENTER)); box12.add(库存量2); Box box13=Box.createHorizontalBox(); box13.add(删除采购单); Box boxH=Box.createVerticalBox(); boxH.add(box1); boxH.add(box2); boxH.add(box3); boxH.add(box4); boxH.add(box5); boxH.add(box6); boxH.add(box7); boxH.add(box8); boxH.add(box9); boxH.add(box10); boxH.add(box11); boxH.add(box12); boxH.add(box13); boxH.add(Box.createVerticalGlue()); JPanel pCenter=new JPanel(); pCenter.add(boxH); setLayout(new BorderLayout()); add(pCenter,BorderLayout.CENTER); validate(); } public void actionPerformed(ActionEvent e) { if(e.getSource()==删除||e.getSource()==书籍号) { String number=""; number=书籍号.getText(); if(number.length()>0) { Boolean boo=false; try { SqlBean sqlBean1=new SqlBean(); String sqlStr="select * from books"; ResultSet result=sqlBean1.executeQuery(sqlStr); while(result.next()) { String snumber=result.getString("bookID"); if(snumber.equals(number)) { 书名.setText(result.getString("bookName")); 作者.setText(result.getString("author")); 价格.setText(result.getString("price")); 出版社.setText(result.getString("press")); 库存量.setText(result.getString("bookCount")); boo=true; } } sqlBean1.CloseDataBase(); } catch(Exception ee) { } if(boo==true) { String m="确定要删除该书籍吗?"; int ok=JOptionPane.showConfirmDialog(this,m,"确认",JOptionPane.YES_NO_OPTION,JOptionPane.QUESTION_MESSAGE); if(ok==JOptionPane.YES_OPTION) { try { SqlBean sqlBean2=new SqlBean(); String sqlStr="delete from books where bookID="+"'"+number+"'"; int result=sqlBean2.executeDelete(sqlStr); sqlBean2.CloseDataBase(); } catch(Exception ee) { } 书籍号.setText(null); 书名.setText(null); 作者.setText(null); 价格.setText(null); 出版社.setText(null); 库存量.setText(null); } else if(ok==JOptionPane.NO_OPTION) { 书籍号.setText(null); 书名.setText(null); 作者.setText(null); 价格.setText(null); 出版社.setText(null); 库存量.setText(null); } } else if(boo==false) { String warning="该书籍号不存在!"; JOptionPane.showMessageDialog(this,warning,"警告",JOptionPane.WARNING_MESSAGE); } } else { String warning="必须输入书籍号!"; JOptionPane.showMessageDialog(this,warning,"警告",JOptionPane.WARNING_MESSAGE); } } if(e.getSource()==删除2||e.getSource()==书籍号2) { String number=""; number=书籍号2.getText(); if(number.length()>0) { Boolean boo=false; try { SqlBean sqlBean3=new SqlBean(); String sqlStr="select * from bookingList"; ResultSet result=sqlBean3.executeQuery(sqlStr); while(result.next()) { String snumber=result.getString("bookID"); if(snumber.equals(number)) { boo=true; 书名2.setText(result.getString("bookName")); 作者2.setText(result.getString("author")); 价格2.setText(result.getString("price")); 出版社2.setText(result.getString("press")); 库存量2.setText(result.getString("needCount"));// boo=true; } } sqlBean3.CloseDataBase(); } catch(Exception ee) { } if(boo==true) { String m="确定要删除该采购吗?"; int ok=JOptionPane.showConfirmDialog(this,m,"确认",JOptionPane.YES_NO_OPTION,JOptionPane.QUESTION_MESSAGE); if(ok==JOptionPane.YES_OPTION) { try { SqlBean sqlBean4=new SqlBean(); String sqlStr="delete from bookingList where bookID="+"'"+number+"'"; int result=sqlBean4.executeDelete(sqlStr); sqlBean4.CloseDataBase(); } catch(Exception ee) { } 书籍号2.setText(null); 书名2.setText(null); 作者2.setText(null); 价格2.setText(null); 出版社2.setText(null); 库存量2.setText(null); } else if(ok==JOptionPane.NO_OPTION) { 书籍号2.setText(null); 书名2.setText(null); 作者2.setText(null); 价格2.setText(null); 出版社2.setText(null); 库存量2.setText(null); } } else if(boo==false) { String warning="该书籍号不存在!"; JOptionPane.showMessageDialog(this,warning,"警告",JOptionPane.WARNING_MESSAGE); } } else { String warning="必须输入书籍号!"; JOptionPane.showMessageDialog(this,warning,"警告",JOptionPane.WARNING_MESSAGE); } } if(e.getSource()==删除采购单) { Boolean boo=false; try { SqlBean sqlBean5=new SqlBean(); String sqlStr="select * from bookingList"; ResultSet result=sqlBean5.executeQuery(sqlStr); if(result.next()) { boo=true; } sqlBean5.CloseDataBase(); } catch(Exception ee) { } if(boo==false) { String warning="采购单为空,不能删除!"; JOptionPane.showMessageDialog(this,warning,"警告",JOptionPane.WARNING_MESSAGE); } if(boo==true) { String m="确定要删除全部采购单吗?"; int ok=JOptionPane.showConfirmDialog(this,m,"确认",JOptionPane.YES_NO_OPTION,JOptionPane.QUESTION_MESSAGE); if(ok==JOptionPane.YES_OPTION) { try { SqlBean sqlBean6=new SqlBean(); String sqlStr="delete from bookingList"; int result=sqlBean6.executeDelete(sqlStr); sqlBean6.CloseDataBase(); } catch(Exception ee) { } } } } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -