package com.sjsq.view;
import java.math.BigDecimal;
import java.sql.Connection;
import java.sql.ResultSet;
import java.util.Vector;
import javax.swing.BorderFactory;
import javax.swing.GroupLayout;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JInternalFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.LayoutStyle;
import javax.swing.table.DefaultTableModel;
import com.sjsq.dao.BookDao;
import com.sjsq.dao.BookTypeDao;
import com.sjsq.model.Book;
import com.sjsq.model.BookType;
import com.sjsq.util.DbUtil;
import com.sjsq.util.StringUtil;
public class BookManagerFrm extends JInternalFrame {
private JTextField authorText;
private JTextField bookId;
private JTextField bookName;
private JTextField bookNameText;
private JTable bookTable;
private JButton jButton1;
private JButton jButton2;
private JComboBox jCB_status;
private JComboBox jCB_type2;
private JLabel jLabel1;
private JLabel jLabel10;
private JLabel jLabel11;
private JLabel jLabel3;
private JLabel jLabel4;
private JLabel jLabel5;
private JLabel jLabel6;
private JLabel jLabel7;
private JLabel jLabel8;
private JLabel jLabel9;
private JPanel jPanel1;
private JPanel jPanel2;
private JScrollPane jScrollPane1;
private JTextField numberText;
private JTextField priceText;
private JTextField publishText;
private JTextField remarkText;
DbUtil dbUtil = new DbUtil();
BookTypeDao bookTypeDao = new BookTypeDao();
BookDao bookDao = new BookDao();
public BookManagerFrm() {
initComponents();
this.jCB_status.addItem("上架");
this.jCB_status.addItem("下架");
fillBookTable(new Book());
fillBookType();
setTitle("书籍修改");
this.setLocation(125, 10);
}
private void fillBookType() {
Connection con = null;
try {
con = dbUtil.getCon();
ResultSet list = bookTypeDao.list(con, new BookType());
while (list.next()) {
BookType bookType = new BookType();
bookType.setTypeId(list.getInt("id"));
bookType.setTypeName(list.getString("type_name"));
this.jCB_type2.addItem(bookType);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
dbUtil.closeCon(con);
} catch (Exception e) {
e.printStackTrace();
}
}
}
private void fillBookTable(Book book) {
DefaultTableModel model = (DefaultTableModel) bookTable.getModel();
model.setRowCount(0);
Connection con = null;
try {
con = dbUtil.getCon();
ResultSet resultSet = bookDao.list(con, book);
while (resultSet.next()) {
Vector rowData = new Vector();
rowData.add(resultSet.getInt("id"));
rowData.add(resultSet.getString("book_name"));
rowData.add(resultSet.getString("type_name"));
rowData.add(resultSet.getString("author"));
rowData.add(resultSet.getDouble("price"));
rowData.add(resultSet.getInt("number"));
if (resultSet.getInt("status") == 1) {
rowData.add("上架");
} else {
rowData.add("下架");
}
model.addRow(rowData);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
dbUtil.closeCon(con);
} catch (Exception e) {
e.printStackTrace();
}
}
}
private void initComponents() {
jPanel1 = new JPanel();
jLabel1 = new JLabel();
bookNameText = new JTextField();
jButton1 = new JButton();
jScrollPane1 = new JScrollPane();
bookTable = new JTable();
jPanel2 = new JPanel();
jLabel3 = new JLabel();
bookId = new JTextField();
jLabel4 = new JLabel();
bookName = new JTextField();
jLabel5 = new JLabel();
authorText = new JTextField();
jLabel6 = new JLabel();
publishText = new JTextField();
jLabel7 = new JLabel();
priceText = new JTextField();
jLabel8 = new JLabel();
numberText = new JTextField();
jLabel9 = new JLabel();
jLabel10 = new JLabel();
jCB_type2 = new JComboBox();
jLabel11 = new JLabel();
remarkText = new JTextField();
jButton2 = new JButton();
jCB_status = new JComboBox();
setClosable(true);
jPanel1.setBorder(BorderFactory.createTitledBorder("查询操作"));
jLabel1.setText("书名:");
jButton1.setText("查询");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
GroupLayout jPanel1Layout = new GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(jPanel1Layout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup().addGap(25, 25, 25).addComponent(jLabel1)
.addGap(18, 18, 18)
.addComponent(bookNameText, GroupLayout.PREFERRED_SIZE, 171,
GroupLayout.PREFERRED_SIZE)
.addGap(62, 62, 62).addComponent(jButton1).addContainerGap(299, Short.MAX_VALUE)));
jPanel1Layout
.setVerticalGroup(jPanel1Layout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup().addGroup(jPanel1Layout
.createParallelGroup(GroupLayout.Alignment.BASELINE).addComponent(jLabel1)
.addComponent(bookNameText, GroupLayout.PREFERRED_SIZE,
GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
.addComponent(jButton1)).addContainerGap(22, Short.MAX_VALUE)));
bookTable.setModel(new DefaultTableModel(new Object[][] {
}, new String[] { "编号", "书名", "类别", "作者", "价格", "库存", "状态" }) {
boolean[] canEdit = new boolean[] { false, false, false, false, false, false, false };
public boolean isCellEditable(int rowIndex, int columnIndex) {
return canEdit[columnIndex];
}
});
bookTable.addMouseListener(new java.awt.event.MouseAdapter() {
public void mousePressed(java.awt.event.MouseEvent evt) {
bookTableMousePressed(evt);
}
});
jScrollPane1.setViewportView(bookTable);
jPanel2.setBorder(BorderFactory.createTitledBorder("书籍操作"));
jLabel3.setText("编号:");
bookId.setEditable(false);
jLabel4.setText("书名:");
jLabel5.setText("作者:");
jLabel6.setText("出版:");
jLabel7.setText("价格:");
jLabel8.setText("库存:");
jLabel9.setText("状态:");
jLabel10.setText("类别:");
jLabel11.setText("描述:");
jButton2.setText("修改");
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});
GroupLayout jPanel2Layout = new GroupLayout(jPanel2);
jPanel2.setLayout(jPanel2Layout);
jPanel2Layout.setHorizontalGroup(jPanel2Layout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addGroup(jPanel2Layout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(
jPanel2Layout.createSequentialGroup().addGap(26, 26, 26).addGroup(jPanel2Layout
.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(
jPanel2Layout.createSequentialGroup().addComponent(jLabel9)
.addPreferredGap(
LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jCB_status, 0, 117, Short.MAX_VALUE))
.addGroup(GroupLayout.Alignment.TRAILING,
jPanel2Layout
.createSequentialGroup().addGroup(jPanel2Layout
.createParallelGroup(
GroupLayout.Alignment.LEADING)
.addComponent(jLabel3).addComponent(jLabel6))
.addPreferredGap(
LayoutStyle.ComponentPlacement.RELATED,
GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(jPanel2Layout
.createParallel
- 1
- 2
- 3
- 4
- 5
- 6
前往页