|
|
|
@ -1,5 +1,7 @@
|
|
|
|
|
// 定义包名,表明该类属于com.lingnan.supermarket.dialog包
|
|
|
|
|
package com.lingnan.supermarket.dialog;
|
|
|
|
|
|
|
|
|
|
// 导入所需的java.awt和javax.swing包中的类
|
|
|
|
|
import java.awt.Container;
|
|
|
|
|
import java.awt.FlowLayout;
|
|
|
|
|
import java.awt.event.ActionEvent;
|
|
|
|
@ -17,6 +19,7 @@ import javax.swing.JOptionPane;
|
|
|
|
|
import javax.swing.JPanel;
|
|
|
|
|
import javax.swing.JTextField;
|
|
|
|
|
|
|
|
|
|
// 导入com.lingnan.supermarket包中的相关类
|
|
|
|
|
import com.lingnan.supermarket.*;
|
|
|
|
|
import com.lingnan.supermarket.dao.SupplierInfService;
|
|
|
|
|
import com.lingnan.supermarket.dao.productionService;
|
|
|
|
@ -31,24 +34,31 @@ import com.lingnan.supermarket.view.StorageView;
|
|
|
|
|
import com.lingnan.supermarket.view.SupplierView;
|
|
|
|
|
import com.lingnan.supermarket.view.ProdCatalogView.MyItemListener;
|
|
|
|
|
|
|
|
|
|
// 定义ProductionDialog类,继承JDialog并实现ActionListener接口
|
|
|
|
|
public class ProductionDialog extends JDialog implements ActionListener {
|
|
|
|
|
|
|
|
|
|
// 声明多个JPanel对象,用于布局
|
|
|
|
|
private JPanel namePanel, addressPanel, contactPanel,
|
|
|
|
|
opePanel,idPanel,inpricePanel,outpricePanel,lifePanel,
|
|
|
|
|
sumPanel,supplyidPanel,id2Panel,name2Panel;
|
|
|
|
|
opePanel,idPanel,inpricePanel,outpricePanel,lifePanel,
|
|
|
|
|
sumPanel,supplyidPanel,id2Panel,name2Panel;
|
|
|
|
|
|
|
|
|
|
// 声明多个JLabel对象,用于显示文本
|
|
|
|
|
private JLabel nameLabel, addressLabel, contactLabel,
|
|
|
|
|
idLabel,inpriceLabel,outpriceLabel,lifeLabel,sumLabel,
|
|
|
|
|
supplyidLabel,id2Label,name2Label;
|
|
|
|
|
idLabel,inpriceLabel,outpriceLabel,lifeLabel,sumLabel,
|
|
|
|
|
supplyidLabel,id2Label,name2Label;
|
|
|
|
|
|
|
|
|
|
// 声明多个JTextField对象,用于文本输入
|
|
|
|
|
private JTextField nameTF, addressTF, contactTF,
|
|
|
|
|
idTF,inpriceTF,outpriceTF,lifeTF,sumTF,
|
|
|
|
|
supplyidTF,id2TF,name2TF;
|
|
|
|
|
idTF,inpriceTF,outpriceTF,lifeTF,sumTF,
|
|
|
|
|
supplyidTF,id2TF,name2TF;
|
|
|
|
|
|
|
|
|
|
// 声明按钮对象,用于保存和取消操作
|
|
|
|
|
private JButton saveBtn, cancelBtn;
|
|
|
|
|
|
|
|
|
|
// 实例化productionService对象,用于操作产品数据
|
|
|
|
|
private productionService productionService = new productionImpl();
|
|
|
|
|
|
|
|
|
|
//下拉类别
|
|
|
|
|
// 下拉类别相关变量
|
|
|
|
|
private String log[]=null;
|
|
|
|
|
private ArrayList<String>alog=null;
|
|
|
|
|
private ProdCatalogTM prodCatalogTM;
|
|
|
|
@ -58,7 +68,7 @@ public class ProductionDialog extends JDialog implements ActionListener {
|
|
|
|
|
private String id2;
|
|
|
|
|
private String name2;
|
|
|
|
|
|
|
|
|
|
//下拉供应商类别
|
|
|
|
|
// 下拉供应商类别相关变量
|
|
|
|
|
private String superlier[]=null;
|
|
|
|
|
private ArrayList<String>asuperlier=null;
|
|
|
|
|
private SupplierInf si;
|
|
|
|
@ -66,135 +76,199 @@ public class ProductionDialog extends JDialog implements ActionListener {
|
|
|
|
|
private JComboBox<String> combo1;
|
|
|
|
|
private int supplyid;
|
|
|
|
|
|
|
|
|
|
// StorageView对象,用于界面更新
|
|
|
|
|
private StorageView storageView;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 声明Production对象,用于存储产品信息
|
|
|
|
|
private Production production;
|
|
|
|
|
|
|
|
|
|
// 构造方法,接收一个JFrame对象作为父窗口,并设置对话框标题为"添加"
|
|
|
|
|
public ProductionDialog(JFrame parent) {
|
|
|
|
|
super(parent, "添加");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 设置对话框的大小为350x500像素
|
|
|
|
|
setSize(350, 500);
|
|
|
|
|
|
|
|
|
|
// 设置对话框相对于屏幕居中
|
|
|
|
|
setLocationRelativeTo(null);
|
|
|
|
|
|
|
|
|
|
// 设置对话框为模态,即不关闭此对话框无法操作其他窗口
|
|
|
|
|
setModal(true);
|
|
|
|
|
// 设置对话框不可调整大小
|
|
|
|
|
setResizable(false);
|
|
|
|
|
|
|
|
|
|
// 设置对话框的布局管理器为FlowLayout
|
|
|
|
|
this.setLayout(new FlowLayout());
|
|
|
|
|
|
|
|
|
|
// 初始化视图
|
|
|
|
|
initView();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 初始化视图的方法
|
|
|
|
|
private void initView() {
|
|
|
|
|
// 创建商品编号输入面板
|
|
|
|
|
idPanel = new JPanel();
|
|
|
|
|
// 创建商品编号标签
|
|
|
|
|
idLabel = new JLabel("商品编号");
|
|
|
|
|
// 创建商品编号文本框
|
|
|
|
|
idTF = new JTextField(15);
|
|
|
|
|
// 将标签和文本框添加到商品编号输入面板
|
|
|
|
|
idPanel.add(idLabel);
|
|
|
|
|
idPanel.add(idTF);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 创建名称输入面板
|
|
|
|
|
namePanel = new JPanel();
|
|
|
|
|
// 创建名称标签
|
|
|
|
|
nameLabel = new JLabel("名称");
|
|
|
|
|
// 创建名称文本框
|
|
|
|
|
nameTF = new JTextField(15);
|
|
|
|
|
// 将标签和文本框添加到名称输入面板
|
|
|
|
|
namePanel.add(nameLabel);
|
|
|
|
|
namePanel.add(nameTF);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 创建进货单价输入面板
|
|
|
|
|
inpricePanel = new JPanel();
|
|
|
|
|
// 创建进货单价标签
|
|
|
|
|
inpriceLabel = new JLabel("进货单价");
|
|
|
|
|
// 创建进货单价文本框
|
|
|
|
|
inpriceTF = new JTextField(15);
|
|
|
|
|
// 将标签和文本框添加到进货单价输入面板
|
|
|
|
|
inpricePanel.add(inpriceLabel);
|
|
|
|
|
inpricePanel.add(inpriceTF);
|
|
|
|
|
|
|
|
|
|
// 创建购买单价输入面板
|
|
|
|
|
outpricePanel = new JPanel();
|
|
|
|
|
// 创建购买单价标签
|
|
|
|
|
outpriceLabel = new JLabel("购买单价");
|
|
|
|
|
// 创建购买单价文本框
|
|
|
|
|
outpriceTF = new JTextField(15);
|
|
|
|
|
// 将标签和文本框添加到购买单价输入面板
|
|
|
|
|
outpricePanel.add(outpriceLabel);
|
|
|
|
|
outpricePanel.add(outpriceTF);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 创建保质期输入面板
|
|
|
|
|
lifePanel = new JPanel();
|
|
|
|
|
// 创建保质期标签
|
|
|
|
|
lifeLabel = new JLabel("保质期(月份数)");
|
|
|
|
|
// 创建保质期文本框
|
|
|
|
|
lifeTF = new JTextField(15);
|
|
|
|
|
// 将标签和文本框添加到保质期输入面板
|
|
|
|
|
lifePanel.add(lifeLabel);
|
|
|
|
|
lifePanel.add(lifeTF);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 创建库存输入面板
|
|
|
|
|
sumPanel = new JPanel();
|
|
|
|
|
// 创建库存标签
|
|
|
|
|
sumLabel = new JLabel("库存");
|
|
|
|
|
// 创建库存文本框
|
|
|
|
|
sumTF = new JTextField(15);
|
|
|
|
|
// 将标签和文本框添加到库存输入面板
|
|
|
|
|
sumPanel.add(sumLabel);
|
|
|
|
|
sumPanel.add(sumTF);
|
|
|
|
|
|
|
|
|
|
//供应商名下拉框 传递supplyid
|
|
|
|
|
// 创建供应商选择面板
|
|
|
|
|
supplyidPanel = new JPanel();
|
|
|
|
|
// 创建供应商标签
|
|
|
|
|
supplyidLabel = new JLabel("供应商");
|
|
|
|
|
// supplyidTF = new JTextField(15);
|
|
|
|
|
// 注释掉的代码,原本可能用于创建供应商文本框,但现在使用下拉框
|
|
|
|
|
// supplyidTF = new JTextField(15);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 实例化SupplierInfImpl对象,用于操作供应商信息
|
|
|
|
|
sii=new SupplierInfImpl();
|
|
|
|
|
// 调用findNameSupplier方法获取所有供应商的名称,并存储到asuperlier列表中
|
|
|
|
|
this.asuperlier=sii.findNameSupplier();
|
|
|
|
|
// 根据asuperlier列表的大小创建superlier字符串数组
|
|
|
|
|
this.superlier=new String[asuperlier.size()];
|
|
|
|
|
// 将asuperlier列表中的元素复制到superlier数组中
|
|
|
|
|
for(int i=0;i<asuperlier.size();i++)
|
|
|
|
|
superlier[i]=asuperlier.get(i);
|
|
|
|
|
|
|
|
|
|
// 遍历superlier数组,并打印每个供应商的名称
|
|
|
|
|
for(int i=0;i<superlier.length;i++)
|
|
|
|
|
{
|
|
|
|
|
System.out.println(superlier[i]);
|
|
|
|
|
System.out.println(superlier[i]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 创建一个新的JComboBox,使用superlier数组作为下拉列表的数据源
|
|
|
|
|
combo1 = new JComboBox<String>(superlier);
|
|
|
|
|
// 为combo1添加一个ItemListener,用于监听下拉列表选项的变化
|
|
|
|
|
combo1.addItemListener(new MyItemListener1());
|
|
|
|
|
|
|
|
|
|
// 将供应商标签和下拉列表添加到supplyidPanel面板中
|
|
|
|
|
supplyidPanel.add(supplyidLabel);
|
|
|
|
|
supplyidPanel.add(combo1);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* id2Panel = new JPanel();
|
|
|
|
|
id2Label = new JLabel("分类id");
|
|
|
|
|
id2TF = new JTextField(id2,15);
|
|
|
|
|
id2Panel.add(id2Label);
|
|
|
|
|
id2Panel.add(id2TF);*/
|
|
|
|
|
//类名下拉框
|
|
|
|
|
// 注释掉的代码,原本可能用于创建分类id的输入面板
|
|
|
|
|
/* id2Panel = new JPanel();
|
|
|
|
|
id2Label = new JLabel("分类id");
|
|
|
|
|
id2TF = new JTextField(id2,15);
|
|
|
|
|
id2Panel.add(id2Label);
|
|
|
|
|
id2Panel.add(id2TF);*/
|
|
|
|
|
// 创建类名输入面板
|
|
|
|
|
name2Panel = new JPanel();
|
|
|
|
|
// 创建类名标签
|
|
|
|
|
name2Label = new JLabel("类名");
|
|
|
|
|
// 实例化prodCatalogImpl对象,用于操作产品目录信息
|
|
|
|
|
pci=new prodCatalogImpl();
|
|
|
|
|
// 调用findNameProdCatalog方法获取所有产品目录的名称,并存储到alog列表中
|
|
|
|
|
this.alog=pci.findNameProdCatalog();
|
|
|
|
|
// 根据alog列表的大小创建log字符串数组
|
|
|
|
|
this.log=new String[alog.size()];
|
|
|
|
|
// 将alog列表中的元素复制到log数组中
|
|
|
|
|
for(int i=0;i<alog.size();i++)
|
|
|
|
|
log[i]=alog.get(i);
|
|
|
|
|
log[i]=alog.get(i);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 创建一个新的JComboBox,使用log数组作为下拉列表的数据源
|
|
|
|
|
combo = new JComboBox<String>(log);
|
|
|
|
|
// 为combo添加一个ItemListener,用于监听下拉列表选项的变化
|
|
|
|
|
combo.addItemListener(new MyItemListener());
|
|
|
|
|
// 将类名标签和下拉列表添加到name2Panel面板中
|
|
|
|
|
name2Panel.add(name2Label);
|
|
|
|
|
name2Panel.add(combo);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 创建地址输入面板
|
|
|
|
|
addressPanel = new JPanel();
|
|
|
|
|
// 创建地址标签
|
|
|
|
|
addressLabel = new JLabel("地址");
|
|
|
|
|
// 创建地址文本框
|
|
|
|
|
addressTF = new JTextField(15);
|
|
|
|
|
// 将标签和文本框添加到地址输入面板
|
|
|
|
|
addressPanel.add(addressLabel);
|
|
|
|
|
addressPanel.add(addressTF);
|
|
|
|
|
|
|
|
|
|
// 创建电话输入面板
|
|
|
|
|
contactPanel = new JPanel();
|
|
|
|
|
// 创建电话标签
|
|
|
|
|
contactLabel = new JLabel("电话");
|
|
|
|
|
// 创建电话文本框
|
|
|
|
|
contactTF = new JTextField(15);
|
|
|
|
|
// 将标签和文本框添加到电话输入面板
|
|
|
|
|
contactPanel.add(contactLabel);
|
|
|
|
|
contactPanel.add(contactTF);
|
|
|
|
|
|
|
|
|
|
// 创建操作按钮面板
|
|
|
|
|
opePanel = new JPanel();
|
|
|
|
|
// 创建保存按钮
|
|
|
|
|
saveBtn = new JButton("保存");
|
|
|
|
|
// 创建取消按钮
|
|
|
|
|
cancelBtn = new JButton("取消");
|
|
|
|
|
// 为保存按钮添加ActionListener,监听按钮点击事件
|
|
|
|
|
saveBtn.addActionListener(this);
|
|
|
|
|
// 为取消按钮添加ActionListener,监听按钮点击事件
|
|
|
|
|
cancelBtn.addActionListener(this);
|
|
|
|
|
// 将保存和取消按钮添加到操作按钮面板
|
|
|
|
|
opePanel.add(saveBtn);
|
|
|
|
|
opePanel.add(cancelBtn);
|
|
|
|
|
|
|
|
|
|
// 获取内容面板
|
|
|
|
|
Container container = getContentPane();
|
|
|
|
|
// 将所有面板添加到内容面板中
|
|
|
|
|
container.add(idPanel);
|
|
|
|
|
container.add(namePanel);
|
|
|
|
|
container.add(inpricePanel);
|
|
|
|
@ -202,72 +276,97 @@ public class ProductionDialog extends JDialog implements ActionListener {
|
|
|
|
|
container.add(lifePanel);
|
|
|
|
|
container.add(sumPanel);
|
|
|
|
|
container.add(supplyidPanel);
|
|
|
|
|
// container.add(id2Panel);
|
|
|
|
|
// 注释掉的代码,可能原本用于添加另一个面板
|
|
|
|
|
//container.add(id2Panel);
|
|
|
|
|
container.add(name2Panel);
|
|
|
|
|
container.add(opePanel);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void actionPerformed(ActionEvent e) {
|
|
|
|
|
Object source = e.getSource();
|
|
|
|
|
if (source == saveBtn) {
|
|
|
|
|
// 思路获取数据
|
|
|
|
|
// 保存到数据库
|
|
|
|
|
// 关闭对话框
|
|
|
|
|
// 刷新table
|
|
|
|
|
|
|
|
|
|
String name = nameTF.getText();
|
|
|
|
|
String id = idTF.getText();
|
|
|
|
|
float inprice = Float.parseFloat((inpriceTF.getText()));
|
|
|
|
|
float outprice = Float.parseFloat(outpriceTF.getText());
|
|
|
|
|
int life = Integer.parseInt(lifeTF.getText());
|
|
|
|
|
int sum = Integer.parseInt(sumTF.getText());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// TODO 参数校验
|
|
|
|
|
if (this.production == null) {
|
|
|
|
|
if(supplyid==-1){
|
|
|
|
|
JOptionPane.showMessageDialog(this, "商品检索出错", "提示",
|
|
|
|
|
JOptionPane.ERROR_MESSAGE);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if(supplyid==0){
|
|
|
|
|
JOptionPane.showMessageDialog(this, "请选择商品名", "提示",
|
|
|
|
|
JOptionPane.ERROR_MESSAGE);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if(id2.equals("0")){
|
|
|
|
|
JOptionPane.showMessageDialog(this, "请选择商品类", "提示",
|
|
|
|
|
JOptionPane.ERROR_MESSAGE);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Production production = new Production();
|
|
|
|
|
production.setId(id);
|
|
|
|
|
production.setName(name);
|
|
|
|
|
production.setInPrice(inprice);
|
|
|
|
|
production.setOutPrice(outprice);
|
|
|
|
|
production.setLife(life);
|
|
|
|
|
production.setSum(sum);
|
|
|
|
|
production.setSupplyId(supplyid);
|
|
|
|
|
production.setId2(id2);
|
|
|
|
|
production.setName2(name2);
|
|
|
|
|
int result = productionService.addProduction(production);
|
|
|
|
|
// int result = 1;
|
|
|
|
|
if (result == 1) {
|
|
|
|
|
|
|
|
|
|
JOptionPane.showMessageDialog(this, "添加成功", "提示",
|
|
|
|
|
JOptionPane.INFORMATION_MESSAGE);
|
|
|
|
|
this.dispose();
|
|
|
|
|
} else if(result == 2){
|
|
|
|
|
JOptionPane.showMessageDialog(this, "已存在该商品", "提示",
|
|
|
|
|
JOptionPane.ERROR_MESSAGE);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
JOptionPane.showMessageDialog(this, "出错!添加失败", "提示",
|
|
|
|
|
JOptionPane.ERROR_MESSAGE);
|
|
|
|
|
}
|
|
|
|
|
// 重写actionPerformed方法,以处理按钮点击事件
|
|
|
|
|
@Override
|
|
|
|
|
public void actionPerformed(ActionEvent e) {
|
|
|
|
|
// 获取事件源
|
|
|
|
|
Object source = e.getSource();
|
|
|
|
|
// 如果事件源是保存按钮
|
|
|
|
|
if (source == saveBtn) {
|
|
|
|
|
// 获取文本框中的数据
|
|
|
|
|
String name = nameTF.getText();
|
|
|
|
|
String id = idTF.getText();
|
|
|
|
|
// 将文本框中的字符串转换为浮点数
|
|
|
|
|
float inprice = Float.parseFloat((inpriceTF.getText()));
|
|
|
|
|
// 将文本框中的字符串转换为浮点数
|
|
|
|
|
float outprice = Float.parseFloat(outpriceTF.getText());
|
|
|
|
|
// 将文本框中的字符串转换为整数
|
|
|
|
|
int life = Integer.parseInt(lifeTF.getText());
|
|
|
|
|
// 将文本框中的字符串转换为整数
|
|
|
|
|
int sum = Integer.parseInt(sumTF.getText());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// TODO 参数校验
|
|
|
|
|
// 如果production对象为null,表示是添加新商品
|
|
|
|
|
if (this.production == null) {
|
|
|
|
|
// 如果supplyid为-1,表示商品检索出错
|
|
|
|
|
if(supplyid==-1){
|
|
|
|
|
JOptionPane.showMessageDialog(this, "商品检索出错", "提示",
|
|
|
|
|
JOptionPane.ERROR_MESSAGE);
|
|
|
|
|
return; // 退出方法
|
|
|
|
|
}
|
|
|
|
|
// 如果supplyid为0,表示用户没有选择商品名
|
|
|
|
|
if(supplyid==0){
|
|
|
|
|
JOptionPane.showMessageDialog(this, "请选择商品名", "提示",
|
|
|
|
|
JOptionPane.ERROR_MESSAGE);
|
|
|
|
|
return; // 退出方法
|
|
|
|
|
}
|
|
|
|
|
// 如果id2为"0",表示用户没有选择商品类
|
|
|
|
|
if(id2.equals("0")){
|
|
|
|
|
JOptionPane.showMessageDialog(this, "请选择商品类", "提示",
|
|
|
|
|
JOptionPane.ERROR_MESSAGE);
|
|
|
|
|
return; // 退出方法
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 创建一个新的Production对象
|
|
|
|
|
Production production = new Production();
|
|
|
|
|
// 设置商品ID
|
|
|
|
|
production.setId(id);
|
|
|
|
|
// 设置商品名称
|
|
|
|
|
production.setName(name);
|
|
|
|
|
// 设置商品进价
|
|
|
|
|
production.setInPrice(inprice);
|
|
|
|
|
// 设置商品售价
|
|
|
|
|
production.setOutPrice(outprice);
|
|
|
|
|
// 设置商品保质期
|
|
|
|
|
production.setLife(life);
|
|
|
|
|
// 设置商品库存
|
|
|
|
|
production.setSum(sum);
|
|
|
|
|
// 设置供应商ID
|
|
|
|
|
production.setSupplyId(supplyid);
|
|
|
|
|
// 设置商品类别ID
|
|
|
|
|
production.setId2(id2);
|
|
|
|
|
// 设置商品类别名称
|
|
|
|
|
production.setName2(name2);
|
|
|
|
|
// 调用productionService的addProduction方法添加商品,并获取返回结果
|
|
|
|
|
int result = productionService.addProduction(production);
|
|
|
|
|
// int result = 1; // 注释掉的代码,可能是用于测试的硬编码结果
|
|
|
|
|
// 如果添加成功
|
|
|
|
|
if (result == 1) {
|
|
|
|
|
// 显示添加成功的消息框
|
|
|
|
|
JOptionPane.showMessageDialog(this, "添加成功", "提示",
|
|
|
|
|
JOptionPane.INFORMATION_MESSAGE);
|
|
|
|
|
// 关闭当前对话框
|
|
|
|
|
this.dispose();
|
|
|
|
|
}
|
|
|
|
|
// 如果返回结果为2,表示已存在该商品
|
|
|
|
|
else if(result == 2){
|
|
|
|
|
JOptionPane.showMessageDialog(this, "已存在该商品", "提示",
|
|
|
|
|
JOptionPane.ERROR_MESSAGE);
|
|
|
|
|
}
|
|
|
|
|
// 如果添加失败
|
|
|
|
|
else {
|
|
|
|
|
// 显示添加失败的消息框
|
|
|
|
|
JOptionPane.showMessageDialog(this, "出错!添加失败", "提示",
|
|
|
|
|
JOptionPane.ERROR_MESSAGE);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}/*else{
|
|
|
|
|
//更新
|
|
|
|
|
SupplierInf supplierInf= new SupplierInf();
|
|
|
|
@ -283,39 +382,99 @@ public class ProductionDialog extends JDialog implements ActionListener {
|
|
|
|
|
}
|
|
|
|
|
}*/
|
|
|
|
|
|
|
|
|
|
} else if (source == cancelBtn) {
|
|
|
|
|
// 如果事件源是取消按钮
|
|
|
|
|
else if (source == cancelBtn) {
|
|
|
|
|
// 关闭当前对话框
|
|
|
|
|
this.dispose();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.dispose();
|
|
|
|
|
// 定义一个内部类MyItemListener实现ItemListener接口,用于监听下拉列表选项的变化
|
|
|
|
|
public class MyItemListener implements ItemListener {
|
|
|
|
|
|
|
|
|
|
// 实现接口的itemStateChanged方法
|
|
|
|
|
@Override
|
|
|
|
|
public void itemStateChanged(ItemEvent e) {
|
|
|
|
|
// 将事件源转换为JComboBox
|
|
|
|
|
JComboBox cb = (JComboBox) e.getSource();
|
|
|
|
|
// 获取选中的下拉列表项,并转换为字符串
|
|
|
|
|
name2 = (String) cb.getSelectedItem();
|
|
|
|
|
// 创建prodCatalogImpl对象,用于查询商品类别信息
|
|
|
|
|
pci =new prodCatalogImpl();
|
|
|
|
|
// 遍历log数组,寻找与选中项匹配的商品类别名称
|
|
|
|
|
for(int i=0;i<log.length;i++){
|
|
|
|
|
// 如果找到匹配的商品类别名称
|
|
|
|
|
if(name2.equals(log[i]))
|
|
|
|
|
// 调用findProdCatalogByname方法获取商品类别ID
|
|
|
|
|
id2=pci.findProdCatalogByname(name2);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 定义另一个内部类MyItemListener1实现ItemListener接口,用于监听供应商下拉列表选项的变化
|
|
|
|
|
public class MyItemListener1 implements ItemListener {
|
|
|
|
|
|
|
|
|
|
// 实现接口的itemStateChanged方法
|
|
|
|
|
@Override
|
|
|
|
|
public void itemStateChanged(ItemEvent e) {
|
|
|
|
|
// 将事件源转换为JComboBox
|
|
|
|
|
JComboBox cb = (JComboBox) e.getSource();
|
|
|
|
|
// 获取选中的下拉列表项,并转换为字符串
|
|
|
|
|
String suppliername = (String) cb.getSelectedItem();
|
|
|
|
|
// 创建SupplierInfImpl对象,用于查询供应商信息
|
|
|
|
|
sii =new SupplierInfImpl();
|
|
|
|
|
// 遍历superlier数组,寻找与选中项匹配的供应商名称
|
|
|
|
|
for(int i=0;i<superlier.length;i++){
|
|
|
|
|
// 如果找到匹配的供应商名称
|
|
|
|
|
if(suppliername.equals(superlier[i]))
|
|
|
|
|
// 调用findIdSupplierByName方法获取供应商ID
|
|
|
|
|
supplyid=sii.findIdSupplierByName(suppliername);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
public class MyItemListener implements ItemListener {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void itemStateChanged(ItemEvent e) {
|
|
|
|
|
JComboBox cb = (JComboBox) e.getSource();
|
|
|
|
|
name2 = (String) cb.getSelectedItem();
|
|
|
|
|
pci =new prodCatalogImpl();
|
|
|
|
|
for(int i=0;i<log.length;i++){
|
|
|
|
|
if(name2.equals(log[i]))
|
|
|
|
|
id2=pci.findProdCatalogByname(name2);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class MyItemListener1 implements ItemListener {
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void itemStateChanged(ItemEvent e) {
|
|
|
|
|
JComboBox cb = (JComboBox) e.getSource();
|
|
|
|
|
String suppliername = (String) cb.getSelectedItem();
|
|
|
|
|
sii =new SupplierInfImpl();
|
|
|
|
|
for(int i=0;i<superlier.length;i++){
|
|
|
|
|
if(suppliername.equals(superlier[i]))
|
|
|
|
|
supplyid=sii.findIdSupplierByName(suppliername);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|