【Java开源代码栏目提醒】:网学会员为需要Java开源代码的朋友们搜集整理了CommodityQuery.java相关资料,希望对各位网友有所帮助!
package internal;
import internalFrame.guanli.Item;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Vector;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JComponent;
import javax.swing.JInternalFrame;
import javax.swing.JLabel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.table.DefaultTableModel;
import dataBaseConnection.Dao;
import model.*;
public class CommodityQuery extends JInternalFrame {
private JTable table;
private JTextField conditionContent;
private JComboBox conditionOperation;
private JComboBox conditionName;
private Dao dao = new Dao();
public CommodityQuery() {
super();
setIconifiable(true);
setClosable(true);
setTitle("服饰信息查询");
getContentPane().setLayout(new GridBagLayout());
setBounds(100, 100, 600, 375);
table = new JTable();
table.setEnabled(false);
table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
final DefaultTableModel dftm = (DefaultTableModel) table.getModel();
String[] tableHeads = new String[] { "服饰名称", "商品编号", "供应商", "生产日期",
"进货价格", "销售价格", "保质期", "数量", "数量下限", "单位" };
dftm.setColumnIdentifiers(tableHeads);
final JScrollPane scrollPane = new JScrollPane(table);
final GridBagConstraints gridBagConstraints_6 = new GridBagConstraints();
gridBagConstraints_6.weighty = 1.0;
gridBagConstraints_6.anchor = GridBagConstraints.NORTH;
gridBagConstraints_6.insets = new Insets(0, 10, 0, 10);
gridBagConstraints_6.fill = GridBagConstraints.BOTH;
gridBagConstraints_6.gridwidth = 6;
gridBagConstraints_6.gridy = 1;
gridBagConstraints_6.gridx = 0;
getContentPane().add(scrollPane, gridBagConstraints_6);
setupComponet(new JLabel(" 选择
查询条件:"), 0, 0, 1, 1, false);
conditionName = new JComboBox();
conditionName.setModel(new DefaultComboBoxModel(new String[] { "服饰名称",
"服饰编号" }));
setupComponet(conditionName, 1, 0, 1, 30, true);
conditionOperation = new JComboBox();
conditionOperation.setModel(new DefaultComboBoxModel(new String[] {
"等于", "包含" }));
setupComponet(conditionOperation, 2, 0, 1, 30, true);
conditionContent = new JTextField();
setupComponet(conditionContent, 3, 0, 1, 110, true);
final JButton queryButton = new JButton();
queryButton.addActionListener(new QueryAction(dftm));
setupComponet(queryButton, 4, 0, 1, 1, false);
queryButton.setText("查询");
final JButton showAllButton = new JButton();
showAllButton.addActionListener(new ActionListener() {
public void actionPerformed(final ActionEvent e) {
conditionContent.setText("");
List list = dao.getAllCommodities();
try {
updateTable(list, dftm);
} catch (SQLException e1) {
e1.printStackTrace();
}
}
});
setupComponet(showAllButton, 5, 0, 1, 1, false);
showAllButton.setText("显示全部数据");
}
private void updateTable(List list, final DefaultTableModel dftm)
throws SQLException {
int num = dftm.getRowCount(); // 获取表格中的当前行数
for (int i = 0; i < num; i++)
dftm.removeRow(0); // 循环删除表格中的所有行
Iterator iterator = list.iterator();
Commodity commodity;
ResultSet rs, set;
int total = 0;
Provider p = new Provider();
while (iterator.hasNext()) {
List info = (List) iterator.next(); // 获取总集合中的每个子集合元素
rs = (ResultSet) dao
.findForResultSet("select * from Provider where ProviderNumber='"
+ Integer.parseInt(info.get(1).toString()) + "'"); // 根据商品信息中的供应商编号获取供应商信息
set = (ResultSet) dao
.findForResultSet("select * from storage where commodityid ='"
+ Integer.parseInt(info.get(0).toString()) + "'"); // 根据商品信息中的商品编号获取商品库存信息
if (rs.next()) {
p.setProviderName(rs.getString(4)); // 获得供应商名称
}
if (set.next()) {
total = Integer.parseInt(set.getString(3)); // 获得商品库存总量
}
int commodityId = Integer.parseInt(info.ge