📄 delete_jieyue.java
字号:
/* * Delete_Jieyue.java * * Created on 2008年5月19日, 上午11:31 */import java.sql.*;import javax.swing.JOptionPane;import java.util.GregorianCalendar;/** * * @author Administrator */public class Delete_Jieyue extends javax.swing.JDialog { /** Creates new form Delete_Jieyue */ public Delete_Jieyue(java.awt.Frame parent, boolean modal) { super(parent, modal); initComponents(); this.setTitle("删除借阅记录"); this.setResizable(false); } /** 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="Generated Code">//GEN-BEGIN:initComponents private void initComponents() { jPanel1 = new javax.swing.JPanel(); jLabel1 = new javax.swing.JLabel(); jtxtLibCard = new javax.swing.JTextField(); jLabel2 = new javax.swing.JLabel(); jtxtISBN = new javax.swing.JTextField(); jLabel3 = new javax.swing.JLabel(); jtxtBorrowTime = new javax.swing.JTextField(); jLabel4 = new javax.swing.JLabel(); jLabel5 = new javax.swing.JLabel(); jbtnDelete = new javax.swing.JButton(); jlabelMsg = new javax.swing.JLabel(); jcmbIndex = new javax.swing.JComboBox(); setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); jLabel1.setText("借书证号:"); jLabel2.setText("ISBN:"); jLabel3.setText("借出时间:"); jLabel4.setText("(格式:2000-11-11)"); jLabel5.setText("索书号:"); jbtnDelete.setText("删除"); jbtnDelete.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jbtnDeleteActionPerformed(evt); } }); jlabelMsg.setFont(new java.awt.Font("宋体", 0, 14)); javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1); jPanel1.setLayout(jPanel1Layout); jPanel1Layout.setHorizontalGroup( jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup() .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false) .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup() .addGap(20, 20, 20) .addComponent(jlabelMsg, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup() .addGap(36, 36, 36) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addGroup(jPanel1Layout.createSequentialGroup() .addComponent(jLabel2) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(jtxtISBN, javax.swing.GroupLayout.PREFERRED_SIZE, 139, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(jPanel1Layout.createSequentialGroup() .addComponent(jLabel1) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jtxtLibCard))) .addGroup(jPanel1Layout.createSequentialGroup() .addComponent(jLabel5) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jcmbIndex, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jbtnDelete)) .addGroup(jPanel1Layout.createSequentialGroup() .addComponent(jLabel3) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jtxtBorrowTime, javax.swing.GroupLayout.PREFERRED_SIZE, 68, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jLabel4))) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED))) .addContainerGap(14, Short.MAX_VALUE)) ); jPanel1Layout.setVerticalGroup( jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup() .addGap(35, 35, 35) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel1) .addComponent(jtxtLibCard, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(18, 18, 18) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel2) .addComponent(jtxtISBN, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel3) .addComponent(jtxtBorrowTime, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel4)) .addGap(18, 18, 18) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel5) .addComponent(jbtnDelete) .addComponent(jcmbIndex, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jlabelMsg, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE) .addContainerGap(12, Short.MAX_VALUE)) ); getContentPane().add(jPanel1, java.awt.BorderLayout.CENTER); pack(); }// </editor-fold>//GEN-END:initComponents public void Empty(){ try{ Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); }catch(ClassNotFoundException ex) { jlabelMsg.setText("SQL错:"+ex.getMessage()); } try { String url="jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ=sources\\data.mdb;pwd=shujuyuan"; Connection con=DriverManager.getConnection(url); Statement st=con.createStatement(); ResultSet res=st.executeQuery("select suoshuNo from jy"); jcmbIndex.removeAllItems(); while(res.next()) jcmbIndex.addItem(res.getString("suoshuNo")); try { if (st != null) { st.close(); } } catch (SQLException sQLException) { } }catch(Exception e){ JOptionPane.showConfirmDialog(null,"找不到数据库驱动程序!","Warning",JOptionPane.CLOSED_OPTION,JOptionPane.WARNING_MESSAGE); this.setVisible(false); } jtxtLibCard.setText(""); jtxtISBN.setText(""); jtxtBorrowTime.setText(""); jcmbIndex.setSelectedIndex(0); jlabelMsg.setText("选择索书号,然后点击删除。"); jtxtLibCard.setEnabled(false); jtxtISBN.setEnabled(false); jtxtBorrowTime.setEnabled(false); } private void jbtnDeleteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnDeleteActionPerformed // TODO add your handling code here: jtxtLibCard.setText(""); jtxtISBN.setText(""); jtxtBorrowTime.setText(""); String lc="",is="",bt="",ss=""; try{ try{ Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); } catch(ClassNotFoundException ex) { throw new ClassNotFoundException(); } try{ ss=new String((String)jcmbIndex.getSelectedItem()); }catch(NullPointerException e){ throw new NullPointerException(); } if(ss.length()!=10) throw new ArithmeticException(); String url="jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ=sources\\data.mdb;pwd=shujuyuan"; Connection con=DriverManager.getConnection(url); Statement st=con.createStatement(); ResultSet rs=st.executeQuery("select * from jy"); jcmbIndex.removeItem(ss); jcmbIndex.setSelectedItem(null); while(rs.next()) if(ss.equals(rs.getString("suoshuNo"))){ lc=new String(rs.getString("libCard")); jtxtLibCard.setText(lc); is=new String(rs.getString("ISBN")); jtxtISBN.setText(is); bt=new String(rs.getString("borrowTime").substring(0,10)); jtxtBorrowTime.setText(bt); } if(lc.length()<1) throw new ArrayIndexOutOfBoundsException(); PreparedStatement ps=con.prepareStatement("delete from jy where suoshuNo=?"); ps.setString(1,ss); ps.executeUpdate(); GregorianCalendar d=new GregorianCalendar(); int year=d.get(d.YEAR); int month=d.get(d.MONTH)+1; int day=d.get(d.DAY_OF_MONTH); String rt=year+"-"+month+"-"+day; PreparedStatement ps2=con.prepareStatement("insert into jyls values(?,?,?,?,?)"); ps2.setString(1, lc); ps2.setString(2, is); ps2.setString(3, ss); ps2.setString(4, bt); ps2.setString(5, rt); ps2.executeUpdate(); //删除借阅记录时,对应的读者借书数减1,书的库存量加1 PreparedStatement ps3=con.prepareStatement("update xs set borrowNum=borrowNum-1 where libCard=?"); ps3.setString(1, lc); ps3.executeUpdate(); PreparedStatement ps4=con.prepareStatement("update book set kucunNum=KucunNum+1 where ISBN=?"); ps4.setString(1, is); ps4.executeUpdate(); jlabelMsg.setText("成功删除 "+ss+" 的信息!"); try{ if(con!=null) con.close(); }catch(Exception e){ } }catch(ClassNotFoundException ex) { jlabelMsg.setText("SQL错:"+ex.getMessage()); }catch(NullPointerException e) { jlabelMsg.setText("请选择索书号!"); }catch(ArithmeticException e){ jlabelMsg.setText("索书号格式不正确!"); } catch(ArrayIndexOutOfBoundsException ex) { jlabelMsg.setText("此索书号记录不存在!"); } catch(Exception e){ jlabelMsg.setText("删除失败!(可能连接数据库失败)"); }}//GEN-LAST:event_jbtnDeleteActionPerformed /** * @param args the command line arguments */ public static void main(String args[]) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { Delete_Jieyue dialog = new Delete_Jieyue(new javax.swing.JFrame(), true); dialog.addWindowListener(new java.awt.event.WindowAdapter() { public void windowClosing(java.awt.event.WindowEvent e) { System.exit(0); } }); dialog.setVisible(true); } }); } // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel3; private javax.swing.JLabel jLabel4; private javax.swing.JLabel jLabel5; private javax.swing.JPanel jPanel1; private javax.swing.JButton jbtnDelete; private javax.swing.JComboBox jcmbIndex; private javax.swing.JLabel jlabelMsg; private javax.swing.JTextField jtxtBorrowTime; private javax.swing.JTextField jtxtISBN; private javax.swing.JTextField jtxtLibCard; // End of variables declaration//GEN-END:variables }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -