📄 5.还书界面.txt
字号:
package library;
import java.awt.BorderLayout;
import java.awt.Dimension;
import javax.swing.JFrame;
import javax.swing.JPanel;
import com.borland.jbcl.layout.XYLayout;
import com.borland.jbcl.layout.*;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JButton;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.*;
import javax.swing.JTextArea;
import javax.swing.JOptionPane;
import javax.swing.JPasswordField;
public class Frame5 extends JFrame {
JPanel contentPane;
XYLayout xYLayout1 = new XYLayout();
JLabel jLabel1 = new JLabel();
JTextField jTextField1 = new JTextField();
JButton jButton1 = new JButton();
JLabel jLabel2 = new JLabel();
JTextField jTextField2 = new JTextField();
JTextArea jTextArea1 = new JTextArea();
Connection conn;
JLabel jLabel3 = new JLabel();
JPasswordField jPasswordField1 = new JPasswordField();
JLabel jLabel4 = new JLabel();
JButton jButton2 = new JButton();
JButton jButton3 = new JButton();
JButton jButton4 = new JButton();
JButton jButton5 = new JButton();
JButton jButton6 = new JButton();
JLabel jLabel5 = new JLabel();
JLabel jLabel6 = new JLabel();
JLabel jLabel7 = new JLabel();
JLabel jLabel8 = new JLabel();
JTextField jTextField3 = new JTextField();
JTextField jTextField4 = new JTextField();
JTextField jTextField5 = new JTextField();
JTextField jTextField6 = new JTextField();
public Frame5() {
try {
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
jbInit();
} catch (Exception exception)
{
exception.printStackTrace();
}
}
private void jbInit() throws Exception {
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String connURL ="jdbc:odbc:library";
String user = "sa";
String pw = "123";
conn=DriverManager.getConnection(connURL,user,pw);
}
catch(Exception e)
{
System.out.println("class no found can not connect to sql server"+e);
}
contentPane = (JPanel) getContentPane();
contentPane.setLayout(xYLayout1);
setSize(new Dimension(600, 380));
setTitle("还书");
jLabel1.setText("ID");
jButton1.setText("确定");
jButton1.addActionListener(new Frame5_jButton1_actionAdapter(this));
jLabel2.setText("还书(1)");
jLabel3.setText("密码");
jLabel4.setText("请输入所要归还的书籍编号在和当时借书的相同位置");
jButton2.setText("确定");
jButton2.addActionListener(new Frame5_jButton2_actionAdapter(this));
jButton3.setText("确定");
jButton3.addActionListener(new Frame5_jButton3_actionAdapter(this));
jButton4.setText("确定");
jButton4.addActionListener(new Frame5_jButton4_actionAdapter(this));
jButton5.setText("确定");
jButton5.addActionListener(new Frame5_jButton5_actionAdapter(this));
jButton6.setText("清除显示");
jButton6.addActionListener(new Frame5_jButton6_actionAdapter(this));
jLabel5.setText("还书(2)");
jLabel6.setText("还书(3)");
jLabel7.setText("还书(4)");
jLabel8.setText("还书(5)");
contentPane.add(jLabel1, new XYConstraints(12, 16, 33, 23));
contentPane.add(jLabel3, new XYConstraints(7, 61, -1, -1));
contentPane.add(jTextField1, new XYConstraints(63, 15, 218, 28));
contentPane.add(jPasswordField1, new XYConstraints(63, 51, 218, 31));
contentPane.add(jLabel6, new XYConstraints(4, 200, -1, -1));
contentPane.add(jLabel2, new XYConstraints(4, 115, 63, 27));
contentPane.add(jLabel5, new XYConstraints(4, 160, -1, -1));
contentPane.add(jTextField2, new XYConstraints(63, 117, 142, 28));
contentPane.add(jLabel8, new XYConstraints(2, 273, -1, -1));
contentPane.add(jTextField3, new XYConstraints(63, 153, 142, 26));
contentPane.add(jTextField4, new XYConstraints(63, 189, 141, 26));
contentPane.add(jTextField5, new XYConstraints(63, 227, 141, 28));
contentPane.add(jLabel7, new XYConstraints(5, 235, -1, -1));
contentPane.add(jTextField6, new XYConstraints(62, 266, 143, 27));
contentPane.add(jLabel4, new XYConstraints(2, 83, 278, 31));
contentPane.add(jButton4, new XYConstraints(214, 229, 64, 26));
contentPane.add(jButton5, new XYConstraints(215, 267, 64, 26));
contentPane.add(jButton3, new XYConstraints(212, 188, 66, 28));
contentPane.add(jButton1, new XYConstraints(211, 119, 67, 26));
contentPane.add(jButton2, new XYConstraints(211, 153, 68, 26));
contentPane.add(jTextArea1, new XYConstraints(312, 16, 251, 242));
contentPane.add(jButton6, new XYConstraints(369, 268, 125, 27));
}
public void jButton1_actionPerformed(ActionEvent e) {
F5_1();
}
void F5_1(){
try
{
String str5_1_1,str5_1_2;
str5_1_1=jTextField1.getText();
str5_1_2=new String(jPasswordField1.getPassword());
Statement stmt5_1_1 = conn.createStatement(ResultSet.
TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_UPDATABLE);
String sq5_1_l= "select * from reader where ID='"+str5_1_1+"' AND 密码 = '"+str5_1_2+"' ";
ResultSet rs5_1_1 = stmt5_1_1.executeQuery(sq5_1_l);
if(!rs5_1_1.next())
{
JOptionPane.showMessageDialog(this,"帐号或者密码错误","错误",JOptionPane.ERROR_MESSAGE);
}
else
{
stmt5_1_1.close();
try
{
String str5_1_3;
str5_1_3=jTextField2.getText();
Statement stmt5_1_2 = conn.createStatement(ResultSet.
TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_UPDATABLE);
String sq5_1_2 = "select * from book where 编号 = '"+str5_1_3+"'";
ResultSet rs5_1_2 = stmt5_1_2.executeQuery(sq5_1_2);
if(!rs5_1_2.next())
{
JOptionPane.showMessageDialog(this,"编号错误","错误",JOptionPane.ERROR_MESSAGE);
}
else{
Statement stmt5_1_3 = conn.createStatement(ResultSet.
TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_UPDATABLE);
String sq5_1_3 = "select 借阅情况 from book where 编号 ='"+str5_1_3+"' and 借书ID ='"+str5_1_1+"' ";
ResultSet rs5_1_3 = stmt5_1_3.executeQuery(sq5_1_3);
String a=new String("送书");
if(!(rs5_1_3.next()&&rs5_1_3.getString("借阅情况").equals(a)))
{
JOptionPane.showMessageDialog(this,"此书没有被你所借","错误",JOptionPane.ERROR_MESSAGE);
stmt5_1_3.close();
}
else
{
Statement stmt4_1_51 = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_UPDATABLE);
String sq4_1_51 = "select * from book where 编号 = '"+str5_1_3+"'";
ResultSet rs4_1_51 = stmt4_1_51.executeQuery(sq4_1_51);
if(rs4_1_51.next())
{ String rs1item1 = rs4_1_51.getString("编号");
String rs1item2 = rs4_1_51.getString("书名");
String rs1item3 = rs4_1_51.getString( "作者");
String rs1item4 = rs4_1_51.getString("出版社");
jTextArea1.setText("编号: " +
rs1item1 +
'\n' +
"书名: " + rs1item2 + '\n' +
"作者: " + rs1item3 + '\n' +
"出版社: " + rs1item4 +
'\n');}
JOptionPane.showMessageDialog(this, "请核对所要归还的书籍信息", "成功还书",JOptionPane.OK_CANCEL_OPTION);
try {
Statement stmt5_1_4 = conn.createStatement(
ResultSet.
TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_UPDATABLE);
String sq5_1_4 ="update reader set 已借书籍 = '未借' where ID ='"+str5_1_1+"' ";
stmt5_1_4.executeUpdate(sq5_1_4);
Statement stmt5_1_5 = conn.createStatement(ResultSet.
TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_UPDATABLE);
String sq5_1_5 = "update book set 借阅情况 = '收书' where 编号 ='"+str5_1_3+"'";
stmt5_1_5.executeUpdate(sq5_1_5);
Statement stmt5_1_6 = conn.createStatement(ResultSet.
TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_UPDATABLE);
String sq5_1_6 = "update book set 借书ID = '未借' where 编号 ='"+str5_1_3+"'";
stmt5_1_6.executeUpdate(sq5_1_6);
} catch (Exception e) {
System.err.println(e);
}
}
}
}
catch(Exception e)
{
System.err.println(e);
}
}
}
catch(Exception e)
{
System.err.println(e);
}
}//F5_1()
public void jButton2_actionPerformed(ActionEvent e) {
F5_2();
}
void F5_2(){
try
{
String str5_2_1,str5_2_2;
str5_2_1=jTextField1.getText();
str5_2_2=new String(jPasswordField1.getPassword());
Statement stmt5_2_1 = conn.createStatement(ResultSet.
TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_UPDATABLE);
String sq5_2_l= "select * from reader where ID='"+str5_2_1+"' AND 密码 = '"+str5_2_2+"' ";
ResultSet rs5_2_1 = stmt5_2_1.executeQuery(sq5_2_l);
if(!rs5_2_1.next())
{
JOptionPane.showMessageDialog(this,"帐号或者密码错误","错误",JOptionPane.ERROR_MESSAGE);
}
else
{
stmt5_2_1.close();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -