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

📄 dlgloanbook.java~87~

📁 用java实现的一个应用程序,源码非常完整,可以直接运行
💻 JAVA~87~
📖 第 1 页 / 共 2 页
字号:
         return RevertibleTime;
     }

    //*********************************判断日期格式*****************************
     public boolean IsnotDate() {
         boolean IsDate = true;
         String RevertibleTime = txtRevertibleTime.getText();
         try {
             int Ryear = Integer.parseInt(RevertibleTime.substring(0, 4));
             int Rmonth = Integer.parseInt(RevertibleTime.substring(5,
                     RevertibleTime.lastIndexOf("-")));
             int Rday = Integer.parseInt(RevertibleTime.substring(
                     RevertibleTime.
                     lastIndexOf("-") + 1, RevertibleTime.length()));
             if (!((RevertibleTime.lastIndexOf("-") ==
                    RevertibleTime.indexOf("-") + 2) ||
                   (RevertibleTime.lastIndexOf("-") ==
                    RevertibleTime.indexOf("-") + 3))) {
                 IsDate = false;
             } else if (Rmonth < 1 || Rmonth > 12) {
                 IsDate = false;
             } else if (Rday < 1 || Rday > 31) {
                 IsDate = false;
             }
         } catch (Exception ce) {
             IsDate = false;
         }
         return IsDate;
     }

    //**************************判断借书证是否过期****************************
     public boolean IsnotLoanBook() {
         boolean Isnot = false;
         Vector vt = new Vector();
         ReaderConDB readerDB = new ReaderConDB();
         vt = readerDB.SearchLRReader(txtReaId.getText());
         readerDB.CloseReaderDB();
         Calendar c = Calendar.getInstance();
         java.sql.Date dd = new java.sql.Date(c.getTimeInMillis());
         String NowTime, EndTime;
         int year, month, day;
         NowTime = dd.toString();
         year = Integer.parseInt(NowTime.substring(0, 4));
         month = Integer.parseInt(NowTime.substring(5, NowTime.lastIndexOf("-")));
         day = Integer.parseInt(NowTime.substring(NowTime.lastIndexOf("-") + 1,
                                                  NowTime.length()));

         int Ryear, Rmonth, Rday;
         EndTime = ((Reader) (vt.get(0))).getEndTime();
         Ryear = Integer.parseInt(EndTime.substring(0, 4));
         Rmonth = Integer.parseInt(EndTime.substring(5, EndTime.lastIndexOf("-")));
         Rday = Integer.parseInt(EndTime.substring(NowTime.lastIndexOf("-") + 1,
                 EndTime.length()));
         if ((year > Ryear) || (year == Ryear && month > Rmonth) ||
             (year == Ryear && month == Rmonth && day > Rday)) {
             Isnot = true;
         }
         return Isnot;
     }

    //*****************************显示窗口*********************************
     public void ShowLoanBook() {
         Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
         Dimension dlgSize = this.getSize();
         if (dlgSize.height > screenSize.height) {
             dlgSize.height = screenSize.height;
         }
         if (dlgSize.width > screenSize.width) {
             dlgSize.width = screenSize.width;
         }
         this.setLocation((screenSize.width - dlgSize.width) / 2,
                          (screenSize.height - dlgSize.height) / 2);
         this.setVisible(true);
     }

    //****************************选择图书编号或条形码****************************
     public void rbnLibId_stateChanged(ChangeEvent e) {
         if (rbnLibId.isSelected()) {
             Isnot = true;
             txtLibId.setEditable(true);
             txtLibId.setBackground(new java.awt.Color(255, 236, 125));
             txtBarCode.setText("");
             rbnLibId.setForeground(Color.magenta);
             txtBarCode.setBackground(Color.lightGray);
             txtBarCode.setEditable(false);
             rbnBarCode.setForeground(Color.BLACK);
         } else {
             Isnot = false;
             txtLibId.setText("");
             txtLibId.setBackground(Color.LIGHT_GRAY);
             txtLibId.setEditable(false);
             txtBarCode.setEditable(true);
             txtBarCode.setBackground(new java.awt.Color(255, 236, 125));
             rbnLibId.setForeground(Color.BLACK);
             rbnBarCode.setForeground(Color.magenta);
         }
     }

    //****************************读者确定按钮事件**********************************
     public void btnReaOK_actionPerformed(ActionEvent e) {
         ReaderConDB readerDB = new ReaderConDB();
         Vector vt = new Vector();
         Vector Readervt = new Vector();
         if (txtReaId.getText().equals("")) {
             txtReaName.setText("");
             txtLoanableNum.setText("");
             txtAlreadyNum.setText("");
             txtEndTime.setText("");
             txtRemark.setText("");
             JOptionPane.showMessageDialog(this, "请输入读者编号!");
         } else {
             Readervt = readerDB.SearchLRReader(txtReaId.getText());
             readerDB.CloseReaderDB();
             if (Readervt.size() < 1) {
                 txtReaName.setText("");
                 txtLoanableNum.setText("");
                 txtAlreadyNum.setText("");
                 txtEndTime.setText("");
                 txtRemark.setText("");
                 JOptionPane.showMessageDialog(this, "找不到相关记录!");
             } else {
                 RecordConDB recordDB = new RecordConDB();
                 vt = recordDB.SearchAlreadyRecord(txtReaId.getText());
                 recordDB.CloseRecordDB();
                 dt = new DefaultTableModel(vt, vtColName);
                 tblDisplay.setModel(dt);
                 tblDisplay.setAutoResizeMode(tblDisplay.AUTO_RESIZE_OFF);
                 tblDisplay.getTableHeader().setReorderingAllowed(false);
                 txtReaName.setText(((Reader) (Readervt.get(0))).getName());
                 txtLoanableNum.setText(String.valueOf(((Reader) (Readervt.get(
                         0))).getLoanableNum()));
                 txtAlreadyNum.setText(String.valueOf(((Reader) (Readervt.get(0))).
                         getAlreadyNum()));
                 txtEndTime.setText(((Reader) (Readervt.get(0))).getEndTime());
                 txtRemark.setText(((Reader) (Readervt.get(0))).getRemark());
             }
         }
     }

    //****************************图书确定按钮事件**********************************
     public void btnLibOK_actionPerformed(ActionEvent e) {
         Vector vt = new Vector();
         if (txtLibId.getText().equals("") && txtBarCode.getText().equals("")) {
             txtLibName.setText("");
             txtAuthor.setText("");
             txtPublish.setText("");
             txtPage.setText("");
             txtPrice.setText("");
             txtSynopsis.setText("");
             JOptionPane.showMessageDialog(this, "请输入图书编号或条形码!");
         } else {
             BookConDB bookDB = new BookConDB();
             vt = bookDB.SearchLRBook(txtLibId.getText(), txtBarCode.getText(),
                                      Isnot);
             bookDB.CloseBookDB();
             if (vt.size() < 1) {
                 txtLibName.setText("");
                 txtAuthor.setText("");
                 txtPublish.setText("");
                 txtPage.setText("");
                 txtPrice.setText("");
                 txtSynopsis.setText("");
                 JOptionPane.showMessageDialog(this, "找不到相关记录!");
             } else {
                 txtLibName.setText(((Book) (vt.get(0))).getName());
                 txtAuthor.setText(((Book) (vt.get(0))).getAuthor());
                 txtPublish.setText(((Book) (vt.get(0))).getPublish());
                 txtPage.setText(((Book) (vt.get(0))).getPage());
                 txtPrice.setText(((Book) (vt.get(0))).getPrice());
                 txtSynopsis.setText(((Book) (vt.get(0))).getSynopsis());
             }
         }
     }

    //*******************************清空按钮事件*******************************
     public void btnCancel_actionPerformed(ActionEvent e) {
         Vector nullvt = new Vector();
         dt = new DefaultTableModel(nullvt, vtColName);
         tblDisplay.setModel(dt);
         tblDisplay.setAutoResizeMode(tblDisplay.AUTO_RESIZE_OFF);
         tblDisplay.getTableHeader().setReorderingAllowed(false);
         txtLibName.setText("");
         txtAuthor.setText("");
         txtPublish.setText("");
         txtPage.setText("");
         txtPrice.setText("");
         txtSynopsis.setText("");
         txtReaName.setText("");
         txtLoanableNum.setText("");
         txtAlreadyNum.setText("");
         txtEndTime.setText("");
         txtRemark.setText("");
         txtBarCode.setText("");
         txtLibId.setText("");
         txtReaId.setText("");
     }

    //******************************退出按钮事件********************************
     public void btnExit_actionPerformed(ActionEvent e) {
         this.dispose();
     }

    //***************************借书按钮事件***********************************
     public void btnLoan_actionPerformed(ActionEvent e) {
         ReaderConDB readerDB = new ReaderConDB();
         BookConDB bookDB = new BookConDB();
         UserConDB userDB = new UserConDB();
         Vector vt = new Vector();
         String Isin;
         String ReaId = txtReaId.getText();
         String LibId = txtLibId.getText();
         String BarCode = txtBarCode.getText();
         String LoanTime = txtNowTime.getText();
         String RevertibleTime = txtRevertibleTime.getText();
         String Operator = ((User) (userDB.SearchUsing())).getName();
         int LoanableNum = 0;
         boolean IsEndTime;
         IsEndTime = IsnotLoanBook();
         if (IsEndTime) {
             JOptionPane.showMessageDialog(this, "请确认借书证是否过期!");
             return;
         }
         boolean IsDate = IsnotDate();
         if (!IsDate) {
             JOptionPane.showMessageDialog(this, "请确认应还日期是否正确!");
             return;
         }
         try {
             LoanableNum = ((Reader) (readerDB.SearchLRReader(ReaId)).get(0)).
                           getLoanableNum();
         } catch (Exception ce) {
             JOptionPane.showMessageDialog(this, "请确认读者编号!");
             return;
         }
         try {
             Isin = ((Book) (bookDB.SearchLRBook(LibId, BarCode, Isnot)).
                     get(0)).getIsin();
         } catch (Exception ce) {
             JOptionPane.showMessageDialog(this, "请确认图书编号或条形码!");
             return;
         }
         if (LoanableNum < 1) {
             JOptionPane.showMessageDialog(this, "读者不能再借!");
         } else if (Isin.equals("不在库")) {
             JOptionPane.showMessageDialog(this, "图书不在库!");
         } else {
             String Lib = ((Book) (bookDB.SearchLRBook(LibId, BarCode, Isnot).
                                   get(0))).getId();
             String Bar = ((Book) (bookDB.SearchLRBook(LibId, BarCode, Isnot).
                                   get(0))).getBarCode();
             boolean Success;
             RecordConDB recordDB = new RecordConDB();
             Success = recordDB.AddRecord(ReaId, Lib, Bar, LoanTime,
                                          RevertibleTime, Operator);
             recordDB.CloseRecordDB();
             if (!Success) {
                 readerDB.CloseReaderDB();
                 bookDB.CloseBookDB();
                 recordDB.CloseRecordDB();
                 JOptionPane.showMessageDialog(this, "借出失败,请确认填写内容是否正确!");
                 return;
             }
             readerDB.UpdateBorrowBook(ReaId);
             bookDB.UpdateBorrowBook(LibId, BarCode);
             JOptionPane.showMessageDialog(this, "借出成功!");
         }
         readerDB.CloseReaderDB();
         bookDB.CloseBookDB();
     }
}

class dlgLoanBook_btnLoan_actionAdapter implements ActionListener {
    private dlgLoanBook adaptee;
    dlgLoanBook_btnLoan_actionAdapter(dlgLoanBook adaptee) {
        this.adaptee = adaptee;
    }

    public void actionPerformed(ActionEvent e) {
        adaptee.btnLoan_actionPerformed(e);
    }
}


class dlgLoanBook_btnExit_actionAdapter implements ActionListener {
    private dlgLoanBook adaptee;
    dlgLoanBook_btnExit_actionAdapter(dlgLoanBook adaptee) {
        this.adaptee = adaptee;
    }

    public void actionPerformed(ActionEvent e) {
        adaptee.btnExit_actionPerformed(e);
    }
}


class dlgLoanBook_btnCancel_actionAdapter implements ActionListener {
    private dlgLoanBook adaptee;
    dlgLoanBook_btnCancel_actionAdapter(dlgLoanBook adaptee) {
        this.adaptee = adaptee;
    }

    public void actionPerformed(ActionEvent e) {
        adaptee.btnCancel_actionPerformed(e);
    }
}


class dlgLoanBook_btnLibOK_actionAdapter implements ActionListener {
    private dlgLoanBook adaptee;
    dlgLoanBook_btnLibOK_actionAdapter(dlgLoanBook adaptee) {
        this.adaptee = adaptee;
    }

    public void actionPerformed(ActionEvent e) {
        adaptee.btnLibOK_actionPerformed(e);
    }
}


class dlgLoanBook_btnReaOK_actionAdapter implements ActionListener {
    private dlgLoanBook adaptee;
    dlgLoanBook_btnReaOK_actionAdapter(dlgLoanBook adaptee) {
        this.adaptee = adaptee;
    }

    public void actionPerformed(ActionEvent e) {
        adaptee.btnReaOK_actionPerformed(e);
    }
}


class dlgLoanBook_rbnLibId_changeAdapter implements ChangeListener {
    private dlgLoanBook adaptee;
    dlgLoanBook_rbnLibId_changeAdapter(dlgLoanBook adaptee) {
        this.adaptee = adaptee;
    }

    public void stateChanged(ChangeEvent e) {
        adaptee.rbnLibId_stateChanged(e);
    }
}

⌨️ 快捷键说明

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