📄 editbook.java
字号:
/*
* register.java
*
* Created on 2007年12月18日, 下午11:12
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
/**
*
* @author Owner
*/
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.ButtonGroup;
import java.sql.*;
import java.util.*;
import java.util.Date;
public class editbook extends JPanel implements ActionListener
{
Box basebox,box1,box2,box3,box4;
JButton submit,reset;
JTextField isbn,bookname,author,price,barcode;
JTextArea content;
Choice publisherlist,bookclasslist;
Connection con;
Statement sql;
ResultSet rs;
String s;
String barcodein;
int publisherindex,bookclassindex;
userflag userflag;
/** Creates a new instance of register */
public editbook(String barcodein) {
this.barcodein=barcodein;
isbn=new JTextField(15);
isbn.setEditable(false);
barcode=new JTextField(15);
barcode.setEditable(false);
bookname=new JTextField(15);
author=new JTextField(15);
price=new JTextField(15);
content=new JTextArea(6,15);
publisherlist=new Choice();
bookclasslist=new Choice();
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(ClassNotFoundException e2){}
try
{
con=DriverManager.getConnection("jdbc:odbc:sample","std","123");
sql=con.createStatement();
s="select * from publisher";
rs=sql.executeQuery("select * from publisher");
while(rs.next())
{
publisherlist.add(rs.getString("publishername"));
}
s="select * from bookclass";
rs=sql.executeQuery(s);
while(rs.next())
{
bookclasslist.addItem(rs.getString("bookclassname"));
}
s="select * from bookinfo where barcode='"+barcodein+"'";
rs=sql.executeQuery(s);
rs.next();
barcode.setText(barcodein);
isbn.setText(rs.getString("isbn"));
bookname.setText(rs.getString("bookname"));
author.setText(rs.getString("author"));
price.setText(rs.getString("price"));
content.setText(rs.getString("content"));
publisherindex=rs.getInt("publisherid");
bookclassindex=rs.getInt("bookclassid");
publisherlist.select(publisherindex-1);
bookclasslist.select(bookclassindex-1);
}
catch(SQLException e3)
{
System.out.println(e3);
}
submit=new JButton("更新图书信息");
reset=new JButton("重设");
submit.addActionListener(this);
reset.addActionListener(this);
box1=Box.createVerticalBox();
box1.add(new Label("图书标识"));
box1.add(Box.createVerticalStrut(8));
box1.add(new Label("图书ISBN"));
box1.add(Box.createVerticalStrut(8));
box1.add(new Label("图书名称"));
box1.add(Box.createVerticalStrut(8));
box1.add(new Label("出版商"));
box1.add(Box.createVerticalStrut(8));
box1.add(new Label("图书类型"));
box1.add(Box.createVerticalStrut(8));
box1.add(new Label("作者"));
box1.add(Box.createVerticalStrut(8));
box1.add(new Label("价格"));
box1.add(Box.createVerticalStrut(8));
box1.add(new Label("内容简介"));
box1.add(Box.createVerticalStrut(90));
box2=Box.createVerticalBox();
box2.add(barcode);
box2.add(Box.createVerticalStrut(8));
box2.add(isbn);
box2.add(Box.createVerticalStrut(8));
box2.add(bookname);
box2.add(Box.createVerticalStrut(8));
box2.add(publisherlist);
box2.add(Box.createVerticalStrut(8));
box2.add(bookclasslist);
box2.add(Box.createVerticalStrut(8));
box2.add(author);
box2.add(Box.createVerticalStrut(8));
box2.add(price);
box2.add(Box.createVerticalStrut(15));
box2.add(content);
box3=Box.createHorizontalBox();
box3.add(box1);
box3.add(Box.createHorizontalStrut(10));
box3.add(box2);
box4=Box.createHorizontalBox();
box4.add(submit);
box4.add(Box.createHorizontalStrut(45));
box4.add(reset);
basebox=Box.createVerticalBox();
basebox.add(new Label("请填写修改信息:"));
basebox.add(Box.createVerticalStrut(15));
basebox.add(box3);
basebox.add(Box.createVerticalStrut(15));
basebox.add(box4);
add(basebox);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==submit)
{
if(isbn.getText().equals(""))
{
JOptionPane.showMessageDialog(this,"图书ISBN不能为空");
}
else if(bookname.getText().equals(""))
{
JOptionPane.showMessageDialog(this,"图书名字不能为空");
}
else if(author.getText().equals(""))
{
JOptionPane.showMessageDialog(this,"作者不能为空");
}
else if(price.getText().equals(""))
{
JOptionPane.showMessageDialog(this,"价格不能为空");
}
else
{
try{
String ss;
int publisherid,bookclassid;
publisherid=publisherlist.getSelectedIndex()+1;
bookclassid=bookclasslist.getSelectedIndex()+1;
ss="'"+isbn.getText()+"','"+bookname.getText()+"','"+publisherid+"','"+bookclassid+"','"+author.getText()+"','"+price.getText()+"','"+content.getText()+"'";
s="update bookinfo set isbn='"+isbn.getText()+"',bookname='"+bookname.getText()+"',publisherid='"+publisherid+"',bookclassid='"+bookclassid+"',author='"+author.getText()+"',price='"+price.getText()+"',content='"+content.getText()+"' where barcode='"+barcodein+"'";
System.out.println(s);
sql.executeUpdate(s);
s="update storage set bookname='"+bookname.getText()+"' where isbn='"+isbn.getText()+"'";
sql.executeUpdate(s);
JOptionPane.showMessageDialog(this,"成功修改图书");
}
catch(SQLException ee)
{
System.out.println(ee);
}
}
}
else if(e.getSource()==reset)
{
isbn.setText(null);
price.setText(null);
bookname.setText(null);
author.setText(null);
content.setText(null);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -