?? 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 + -