📄 insertbook.java~8~
字号:
package bookmanage;
import java.awt.*;
import javax.swing.*;
import java.awt.Rectangle;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.sql.ResultSet;
import java.sql.SQLException;
/**
* <p>Title: 图书管理系统</p>
*
* <p>Description:InsertBook类是继承JDialog类,主要是用来插入图书 </p>
*
* <p>Copyright: Copyright (c) 2006</p>
*
* <p>Company: 浙江工业大学信息学院计算机系</p>
*
* @author 曾文秋
* @version 1.0
*/
public class InsertBook
extends JDialog {
public InsertBook(Frame owner, String title, boolean modal) {
super(owner, title, modal);
try {
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
jbInit();
pack();
}
catch (Exception exception) {
exception.printStackTrace();
}
}
public InsertBook() {
this(new Frame(), "InsertBook", false);
}
private void jbInit() throws Exception {
this.setResizable(false);
this.setTitle("插入图书");
this.getContentPane().setLayout(null);
jLabel1.setText("书名:");
jLabel1.setBounds(new Rectangle(32, 47, 49, 21));
jLabel2.setText("ISBN:");
jLabel2.setBounds(new Rectangle(226, 47, 42, 21));
jTextFieldISBN.setBounds(new Rectangle(291, 47, 109, 20));
jTextFieldPrice.setBounds(new Rectangle(290, 82, 109, 20));
jTextFieldAuthor.setBounds(new Rectangle(91, 82, 109, 20));
jLabel3.setText("价格:");
jLabel3.setBounds(new Rectangle(225, 82, 42, 21));
jLabel4.setText("作者:");
jLabel4.setBounds(new Rectangle(31, 82, 49, 21));
jTextFieldPubDate.setBounds(new Rectangle(290, 116, 109, 20));
jLabel5.setText("出版时间:");
jLabel5.setBounds(new Rectangle(225, 116, 64, 21));
jTextFieldPublisher.setBounds(new Rectangle(91, 116, 109, 20));
jLabel6.setDisplayedMnemonic('0');
jLabel6.setText("出版社:");
jLabel6.setBounds(new Rectangle(31, 116, 49, 21));
jTextFieldBookNum.setBounds(new Rectangle(289, 151, 109, 20));
jLabel7.setText("书数量:");
jLabel7.setBounds(new Rectangle(224, 151, 64, 21));
jLabel8.setText("关键字:");
jLabel8.setBounds(new Rectangle(30, 151, 49, 21));
jTextFieldKeyWords.setBounds(new Rectangle(90, 151, 109, 20));
jButtonInsert.setBounds(new Rectangle(69, 223, 81, 23));
jButtonInsert.setText("插入");
jButtonInsert.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
jButtonInsert_actionPerformed(e);
}
});
jButton2.setBounds(new Rectangle(182, 223, 81, 23));
jButton2.setText("取消");
jButton2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
jButton2_actionPerformed(e);
}
});
jButtonClear.setBounds(new Rectangle(295, 223, 81, 23));
jButtonClear.setText("清空");
jButtonClear.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
jButtonClear_actionPerformed(e);
}
});
jTextFieldAdress.setBounds(new Rectangle(90, 185, 109, 20));
jLabel9.setText("索书号:");
jLabel9.setBounds(new Rectangle(30, 185, 53, 21));
this.getContentPane().add(jLabel4);
this.getContentPane().add(jLabel1);
this.getContentPane().add(jLabel7);
this.getContentPane().add(jLabel5);
this.getContentPane().add(jLabel3);
this.getContentPane().add(jLabel2);
this.getContentPane().add(jTextFieldISBN);
this.getContentPane().add(jTextFieldPrice);
this.getContentPane().add(jTextFieldPubDate);
this.getContentPane().add(jTextFieldBookNum);
this.getContentPane().add(jLabel8);
this.getContentPane().add(jLabel6);
this.getContentPane().add(jButton2);
this.getContentPane().add(jButtonClear);
this.getContentPane().add(jButtonInsert);
this.getContentPane().add(jLabel9);
this.getContentPane().add(jTextFieldBookName);
this.getContentPane().add(jTextFieldAuthor);
this.getContentPane().add(jTextFieldPublisher);
this.getContentPane().add(jTextFieldKeyWords);
this.getContentPane().add(jTextFieldAdress);
jTextFieldBookName.setBounds(new Rectangle(92, 47, 109, 20));
}
JLabel jLabel1 = new JLabel();
JTextField jTextFieldBookName = new JTextField();
JLabel jLabel2 = new JLabel();
JTextField jTextFieldISBN = new JTextField();
JTextField jTextFieldPrice = new JTextField();
JTextField jTextFieldAuthor = new JTextField();
JLabel jLabel3 = new JLabel();
JLabel jLabel4 = new JLabel();
JTextField jTextFieldPubDate = new JTextField();
JLabel jLabel5 = new JLabel();
JTextField jTextFieldPublisher = new JTextField();
JLabel jLabel6 = new JLabel();
JTextField jTextFieldBookNum = new JTextField();
JLabel jLabel7 = new JLabel();
JLabel jLabel8 = new JLabel();
JTextField jTextFieldKeyWords = new JTextField();
JButton jButtonInsert = new JButton();
JButton jButton2 = new JButton();
ResultSet rs;
//定义数据库操作对象
private DBManager db = new DBManager();
JButton jButtonClear = new JButton();
JTextField jTextFieldAdress = new JTextField();
JLabel jLabel9 = new JLabel();
public void jButton2_actionPerformed(ActionEvent e) {
this.dispose();
}
public void jButtonInsert_actionPerformed(ActionEvent e) {
String insertBookName="";
String insertISBN="";
String insertAuthor="";
String insertPrice="";
String insertPublisher="";
String InsertPubDate="";
String InsertKeyWords="";
String InsertBookNum="";
String InsertAdress="";
insertBookName=jTextFieldBookName.getText().trim();
insertISBN=jTextFieldISBN.getText().trim();
insertAuthor=jTextFieldAuthor.getText().trim();
insertPrice=jTextFieldPrice.getText().trim();
insertPublisher=jTextFieldPublisher.getText().trim();
InsertPubDate=jTextFieldPubDate.getText().trim();
InsertKeyWords=jTextFieldKeyWords.getText().trim();
InsertBookNum=jTextFieldBookNum.getText().trim();
InsertAdress=jTextFieldAdress.getText().trim();
if(insertBookName.equals("")){
JOptionPane.showMessageDialog(this, "书名不许为空!");
return;
}
if(insertISBN.equals("")){
JOptionPane.showMessageDialog(this, "ISBN不许为空!");
return;
}
if(insertAuthor.equals("")){
JOptionPane.showMessageDialog(this, "作者不许为空!");
return;
}
if(insertPrice.equals("")){
JOptionPane.showMessageDialog(this, "书的价格不许为空!");
return;
}
float iprice=Float.parseFloat(insertPrice);
if(insertPublisher.equals("")){
JOptionPane.showMessageDialog(this, "出版社不许为空!");
return;
}
if(InsertPubDate.equals("")){
JOptionPane.showMessageDialog(this, "出版日期不许为空!");
return;
}
if(InsertKeyWords.equals("")){
JOptionPane.showMessageDialog(this, "关键字不许为空!");
return;
}
if(InsertBookNum.equals("")){
JOptionPane.showMessageDialog(this, "书数量不许为空!");
return;
}
int bookNum=Integer.parseInt(InsertBookNum);
//float bookNum=Float.parseFloat(InsertBookNum);
if(InsertAdress.equals("")){
JOptionPane.showMessageDialog(this, "馆藏地址不许为空!");
return;
}
String strSQL="";
strSQL="select * from bookInfo where ISBN='"+insertISBN+"'";
rs = db.getResult(strSQL);
boolean isexist = false;
try {
isexist = rs.first();
}
catch (SQLException ex1) {
}
//若书名存在,提示警告信息
if (isexist){
JOptionPane.showMessageDialog(this, "这本书已经存在");
return;
}
//strSQL="insert into bookInfo(name,ISBN,bookAuthor,price,publisher,pubDate,keywords)"+
// "values('"+insertBookName+"','"+insertISBN+"','"+insertAuthor+"',"+
// "'"+insertPrice+"','"+insertPublisher+"','"+InsertPubDate+"','"+InsertKeyWords+"')";
strSQL="exec Pro_InsertBook '"+insertBookName+"','"+insertISBN+"','"+insertAuthor+"',"+
""+iprice+",'"+insertPublisher+"','"+InsertPubDate+"','"+InsertKeyWords+"','"+InsertAdress+"',"+bookNum+"";
if (db.executeSql(strSQL)) {
JOptionPane.showMessageDialog(this, "成功添加!");
}
else {
JOptionPane.showMessageDialog(this, " 添加失败,请重新操作!");
}
}
public void jButtonClear_actionPerformed(ActionEvent e) {
jTextFieldBookName.setText("");
jTextFieldISBN.setText("");
jTextFieldAuthor.setText("");
jTextFieldPrice.setText("");
jTextFieldPublisher.setText("");
jTextFieldPubDate.setText("");
jTextFieldKeyWords.setText("");
jTextFieldBookNum.setText("");
jTextFieldAdress.setText("");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -