📄 huanshubiao.java
字号:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.sql.*;
import javax.swing.table.*;
import java.util.Vector;
public class HuanshuBiao extends JFrame implements ActionListener{
ShuJuKu db=new ShuJuKu();
ShuJuKu db1=new ShuJuKu();
ShuJuKu db2=new ShuJuKu();
ShuJuKu db3=new ShuJuKu();
ShuJuKu db4=new ShuJuKu();
ShuJuKu db5=new ShuJuKu();
ResultSet rs,rs1,rs2;
JPanel p1,p2,p3,p4,p5;
public JTextField fields[];
JLabel labels[];
String bnames[]={"查看列表","还书按钮"},dzh,dqrq;
JTable table=null;
DefaultTableModel hsdefaultModel=null;
JButton buttons[];
String labelsName[]={"读者证号","当前日期"};
public HuanshuBiao(){
super("待还书目列表");
p1=new JPanel();
String[] name={"书名","书号","借书日期"};
String[][] data=new String[0][0];
hsdefaultModel=new DefaultTableModel(data,name);
table=new JTable(hsdefaultModel);
table.setPreferredScrollableViewportSize(new Dimension(300,80));
JScrollPane s=new JScrollPane(table);
p1.add(s);
p5=new JPanel();
p2=new JPanel();
buttons=new JButton[2];
for(int r=0;r<2;r++){
buttons[r]=new JButton(bnames[r]);
buttons[r].addActionListener(this);
p2.add(buttons[r]);
}
p3=new JPanel();
p4=new JPanel();
labels=new JLabel[2];
fields=new JTextField[2];
for(int t=0;t<2;t++){
labels[t]=new JLabel(labelsName[t]+":");
fields[t]=new JTextField(15);
p3.add(labels[t]);
p4.add(fields[t]);
}
p3.setLayout(new GridLayout(2,1,0,15));
p4.setLayout(new GridLayout(2,1,0,10));
p5.add(p3);
p5.add(p4);
Container c=getContentPane();
c.add(p1,BorderLayout.CENTER);
c.add(p2,BorderLayout.SOUTH);
c.add(p5,BorderLayout.NORTH);
}
public void actionPerformed(ActionEvent e){
//------查询=====
if(e.getSource()==buttons[0]){
if(fields[0].getText().trim().equals("")) {
JOptionPane.showMessageDialog(null,"借书证号不能为空!");
}
else if(fields[1].getText().trim().equals(""))
{
JOptionPane.showMessageDialog(null,"请输入当前日期");
}
dzh=fields[0].getText();
dqrq=fields[1].getText();
// strSQL="select tushubiao.tushuhao,tushubiao.duzhehao,tushubiao.jiehuanriqi,tushubiao.xingwei, tushuxinxi.tushuhao, tushuxinxi.tushuming From tushubiao,tushuxinxi where tushubiao.tushuhao=tushuxinxi.tushuhao and tushubiao.duzhehao ='"+dzh+"'";
String strSQL1;
strSQL1="select tushubiao.tushuhao,tushubiao.duzhehao,tushubiao.jiehuanriqi,tushubiao.xingwei, tushuxinxi.tushuhao, tushuxinxi.tushuming From tushubiao,tushuxinxi where tushubiao.tushuhao=tushuxinxi.tushuhao and tushubiao.duzhehao ='"+dzh+"' and tushubiao.daihuan = '待还'";
try{
int rowCount=hsdefaultModel.getRowCount()-1;//取得table中的数据行;
int j=rowCount;
for(int i=0;i<=rowCount;i++){
hsdefaultModel.removeRow(j); //删除rowCount行的数据;
hsdefaultModel.setRowCount(j); //重新设置行数;
j=j-1;
}
rs2=db5.getResult(strSQL1);
while(rs2.next()){
Vector data=new Vector();
data.addElement(rs2.getString(6));
data.addElement(rs2.getString(1));
data.addElement(rs2.getString(3));
hsdefaultModel.addRow(data);
}
table.revalidate();
db5.closeConnection();
} catch(SQLException sqle){
System.out.println(sqle.toString());
}
catch(Exception ex){
System.out.println(ex.toString());
}
}
//---------------查询结束-----------
//---------还书
else if(e.getSource()==buttons[1]){
if(table.getSelectedRow()==-1){
JOptionPane.showMessageDialog(null,"请选择要还的书!");
return;
}
String leibie="",shumu="",kucun="";
String strSQL;
String str[]=new String[3];
int row=table.getSelectedRow();
for(int i=0;i<3;i++){
str[i]=(String)table.getValueAt(row,i);
}
JOptionPane.showMessageDialog(null,str[2]);
//--------查借阅数目 和 库存量
strSQL="Select duzheleibie,jieyueshumu From duzhexinxi where duzhehao like '"+fields[0].getText()+"%'";
rs=db.getResult(strSQL);
try{
if(rs.next())
{
shumu = rs.getString("jieyueshumu");
}
db.closeConnection();
}
catch(SQLException sqle){
System.out.println(sqle.toString());
}
catch(Exception ex){
System.out.println(ex.toString());
}
JOptionPane.showMessageDialog(null,shumu);
strSQL="Select kucunliang From tushuxinxi where tushuhao like '"+str[1]+"%'";
rs1=db1.getResult(strSQL);
try{
if(rs1.next())
{
kucun = rs1.getString("kucunliang");
}
db1.closeConnection();
}
catch(SQLException sqle){
System.out.println(sqle.toString());
}
catch(Exception ex){
System.out.println(ex.toString());
}
int a,b=1;
a=Integer.parseInt( shumu );
a= a-1;
shumu=String.valueOf(a);
// JOptionPane.showMessageDialog(null,shumu);
a=Integer.parseInt(kucun);
a=a+1;
kucun= String.valueOf(a);
dqrq=fields[1].getText();
//----------上传库存量信息
try{
strSQL="update tushuxinxi set kucunliang='"+kucun+"' "+"where tushuhao='"+fields[0].getText().trim()+"'";
if(db2.updateSql(strSQL))
{
JOptionPane.showMessageDialog(null,"上传库存量信息 成功!");
this.dispose();
b=b+1;
}
else
{
JOptionPane.showMessageDialog(null,"上传库存量 失败!");
this.dispose();
}
db2.closeConnection();
}
catch(Exception ex){
System.out.println(ex.toString());
}
//------------上传库存量信息
//=============上传借阅数目
try{
strSQL="update duzhexinxi set jieyueshumu='"+shumu+"' "+"where duzhehao='"+fields[0].getText().trim()+"'";
if(db3.updateSql(strSQL))
{
JOptionPane.showMessageDialog(null,"上传借阅数目 成功!");
this.dispose();
b=b+1;
}
else
{
JOptionPane.showMessageDialog(null,"上传借阅数目信息 失败!");
this.dispose();
}
db3.closeConnection();
}
catch(Exception ex){
System.out.println(ex.toString());
}
//-----上传借阅数目
//=====修改历史信息
try{
strSQL="insert into tushubiao(tushuhao,duzhehao,jiehuanriqi,xingwei,daihuan) values('"+
str[0]+"','"+
fields[0].getText().trim()+"','"+
fields[1].getText().trim()+"','"+
"还"+"','"+""+"')";
if(db4.updateSql(strSQL))
{
JOptionPane.showMessageDialog(null,"修改历史信息 成功!");
this.dispose();
b=b+1;
}
else
{
JOptionPane.showMessageDialog(null,"修改历史信息 失败!");
this.dispose();
}
db4.closeConnection();
}
catch(Exception ex){
System.out.println(ex.toString());
}
//---------修改历史信息
if(b==4){
JOptionPane.showMessageDialog(null,"还书成功");
}
}
}//定义响应
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -