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

📄 d_return.java

📁 图书管理系统
💻 JAVA
字号:
/*
 * D_return.java
 *
 * Created on 2007年6月22日, 上午9:48
 */

package 图书管理系统;
import javax.swing.*;
import java.sql.*;

public class D_return extends javax.swing.JFrame {
    
    /** Creates new form D_return */
    public D_return() {
        initComponents();
        con=connect.getcon();
        stmt=connect.getstmt();
        this.setTitle("还书");
        this.setBounds(300,250,250,180);
        this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
    }
    
    /** 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=" 生成的代码 ">//GEN-BEGIN:initComponents
    private void initComponents() {
        jLabel1 = new javax.swing.JLabel();
        T_BID = new javax.swing.JTextField();
        B_add = new javax.swing.JButton();
        B_cancel = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        jLabel1.setText("\u56fe\u4e66ID:");

        B_add.setText("\u8fd8\u4e66");
        B_add.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                B_addActionPerformed(evt);
            }
        });

        B_cancel.setText("\u53d6\u6d88");
        B_cancel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                B_cancelActionPerformed(evt);
            }
        });

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                    .add(layout.createSequentialGroup()
                        .add(32, 32, 32)
                        .add(jLabel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 47, Short.MAX_VALUE))
                    .add(layout.createSequentialGroup()
                        .addContainerGap()
                        .add(B_add)))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                    .add(T_BID, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 85, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(B_cancel))
                .add(40, 40, 40))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .add(27, 27, 27)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel1)
                    .add(T_BID, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .add(34, 34, 34)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(B_add)
                    .add(B_cancel))
                .addContainerGap(33, Short.MAX_VALUE))
        );
        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void B_cancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_B_cancelActionPerformed
// TODO 将在此处添加您的处理代码:
      this.setVisible(false);
    }//GEN-LAST:event_B_cancelActionPerformed

    private void B_addActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_B_addActionPerformed
// TODO 将在此处添加您的处理代码:
        try{
            if(T_BID.getText().trim().equals(""))
            {
            JOptionPane.showMessageDialog(null,"输入不能为空");
            return;
            }
            PreparedStatement sql1=con.prepareStatement("select datediff(dd,借阅日期,getdate()) from 借阅 where 书号=? and 归还日期 is null");
            sql1.setString(1,T_BID.getText().trim());
            ResultSet rs=sql1.executeQuery();
           if(!rs.next())
             {
                 JOptionPane.showMessageDialog(null,"不存在此借阅记录");
                 return;
             }
            int n=rs.getInt(1);
            if(n>60)
            {
                float f=(n-60)*0.1f+0.5f;
                if(JOptionPane.showConfirmDialog(null,"对不起,您所借阅的图书已经超期"+(n-60)+"天,请交罚款"+f+"元")!=0)
                    return;
            }
           PreparedStatement sql=con.prepareStatement("update 读者 set 已借=已借-1 where 编号 in(select 读者编号 from 借阅 where 书号=?)");
            sql.setString(1,T_BID.getText().trim());
            sql.executeUpdate();
        sql=con.prepareStatement("delete from 借阅  where 书号=?");
        sql.setString(1,T_BID.getText().trim());
        sql.executeUpdate();
        JOptionPane.showMessageDialog(null,"还书操作成功");
        this.setVisible(false);
    }                                     
     catch(Exception ee)
         {
       JOptionPane.showMessageDialog(null,"数据库访问失败,请确认字符是否有效");
 ee.printStackTrace();
    }
        
    }//GEN-LAST:event_B_addActionPerformed
    
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new D_return().setVisible(true);
            }
        });
    }
    
    // 变量声明 - 不进行修改//GEN-BEGIN:variables
    private javax.swing.JButton B_add;
    private javax.swing.JButton B_cancel;
    private javax.swing.JTextField T_BID;
    private javax.swing.JLabel jLabel1;
    // 变量声明结束//GEN-END:variables
    private Connection con;
    private Statement stmt;
}

⌨️ 快捷键说明

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