展开全部
package com.gxa.Export;
import java.awt.event.*;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import com.gxa.Main.Main;
import com.gxa.Pub.*;
import javax.swing.*;
import javax.swing.table.DefaultTableModel;
public class ExportSelectPanel implements ActionListener{
JPanel pSelect;
JComboBox cb;
JTextField tfd;
JLabel lb;
JButton btn1,btn2;
public void actionPerformed(ActionEvent e) {
Object btn = e.getSource();
PreparedStatement prep = null;
ResultSet rs;
if(btn==cb && cb.getSelectedItem().equals("入库日期")){
pSelect.add(lb);
}
if(btn==btn1){
Object cbName = cb.getSelectedItem();
String[] col = { "iExportId", "cEmployeeId", "dShipmentDate",
"cGoodId", "mPrice", "iAmount", "cStorageCode" };
DefaultTableModel mm = new DefaultTableModel(col, 0); // 定义一个表的模板
String str = tfd.getText();
try{
Connection conn = Conn.getCon().con;
if(tfd.getText().length()==0){
prep = conn.prepareStatement("select * from Export");
}
else if(cbName.equals("入库单号")){
prep = conn.prepareStatement("select * from Export where iExportId= ?");
prep.setString(1,str);
if(str.equals("")){
JOptionPane.showMessageDialog(ExportMainPanel.getExportMainPanel(), "请输入入库单号!");
return;
}else if(!str.matches("^\\d+$")){
JOptionPane.showMessageDialog(ExportMainPanel.getExportMainPanel(), "入库单号只能e68a843231313335323631343130323136353331333239313431为数字!");
return;
}
}
else if(cbName.equals("经手人ID")){
prep = conn.prepareStatement("select * from Export where cEmployeeId= ?");
prep.setString(1,str);
if(str.equals("")){
JOptionPane.showMessageDialog(ExportMainPanel.getExportMainPanel(), "请输入经手人!");
return;
}else if(!str.matches("^\\d+$")){
JOptionPane.showMessageDialog(ExportMainPanel.getExportMainPanel(), "经手人只能为数字!");
return;
}
}
else if(cbName.equals("入库日期")){
prep = conn.prepareStatement("select * from Export where dShipmentDate = '"+str+"'");
}
else if(cbName.equals("货品编号")){
prep = conn.prepareStatement("select * from Export where cCommodityId= ?");
prep.setString(1,str);
if(str.equals("")){
JOptionPane.showMessageDialog(ExportMainPanel.getExportMainPanel(), "请输入货品编号!");
return;
}else if(!str.matches("^\\d+$")){
JOptionPane.showMessageDialog(ExportMainPanel.getExportMainPanel(), "货品编号只能为数字!");
return;
}
}
else if(cbName.equals("仓库编号")){
prep = conn.prepareStatement("select * from Export where cStorageCode= ?");
prep.setString(1,str);
if(str.equals("")){
JOptionPane.showMessageDialog(ExportMainPanel.getExportMainPanel(), "请输入仓库编号!");
return;
}else if(!str.matches("^\\d+$")){
JOptionPane.showMessageDialog(ExportMainPanel.getExportMainPanel(), "仓库编号只能为数字!");
return;
}
}
rs = prep.executeQuery();// 将查询得到的结果集给rs
while (rs.next()) {
String iExportId = rs.getString(1);
String cEmployeeId = rs.getString(2);
String dShipmentDate = rs.getString(3);
String cCommodityId = rs.getString(4);
String mPrice = rs.getString(5);
String iAmount = rs.getString(6);
String cStorageCode = rs.getString(7);
String[] str_row = { iExportId, cEmployeeId, dShipmentDate,
cCommodityId, mPrice, iAmount, cStorageCode }; // 将一行的数据存在str_row
// 字符串数组里
mm.addRow(str_row);// 添加在表模板中
}
rs.close();
prep.close();
ExportMainPanel.getExportMainPanel().jtable.setModel(mm);
ExportMainPanel.getExportMainPanel().scp.add(ExportMainPanel.getExportMainPanel().jscrollpane);
// 将加载了表的滚动条在JFrame中显示
}catch(Exception ee){
ee.printStackTrace();
}
}
if(btn==btn2){
Main.getMain().setVisible(true);
ExportMainPanel.getExportMainPanel().setVisible(false);
}
}
public ExportSelectPanel(){
cb = new JComboBox();
tfd = new JTextField(10);
lb = new JLabel("日期格式2008-01-01 00:00:00");
pSelect = new JPanel();
btn1 = new JButton("确定查询");
btn2 = new JButton("返回主界面");
cb.addItem("入库单号");
cb.addItem("经手人ID");
cb.addItem("入库日期");
cb.addItem("货品编号");
cb.addItem("仓库编号");
cb.addActionListener(this);
btn1.addActionListener(this);
btn2.addActionListener(this);
pSelect.add(cb);
pSelect.add(tfd);
pSelect.add(btn1);
pSelect.add(btn2);
}
}
本回答被提问者采纳
已赞过
已踩过<
你对这个回答的评价是?
评论
收起