diff --git a/Supermarket/src/com/lingnan/supermarket/dialog/ChangeStatusDialog.java b/Supermarket/src/com/lingnan/supermarket/dialog/ChangeStatusDialog.java index 637df04..cf943a4 100644 --- a/Supermarket/src/com/lingnan/supermarket/dialog/ChangeStatusDialog.java +++ b/Supermarket/src/com/lingnan/supermarket/dialog/ChangeStatusDialog.java @@ -1,5 +1,7 @@ +// 定义包名,表明该类属于com.lingnan.supermarket.dialog包 package com.lingnan.supermarket.dialog; +// 导入必要的Java和Swing类库 import java.awt.Container; import java.awt.FlowLayout; import java.awt.event.ActionEvent; @@ -18,6 +20,7 @@ import javax.swing.JPanel; import javax.swing.JTable; import javax.swing.JTextField; +// 导入项目相关的类和接口 import com.lingnan.supermarket.*; import com.lingnan.supermarket.dao.UserService; import com.lingnan.supermarket.dao.impl.BufferImpl; @@ -37,91 +40,128 @@ import com.lingnan.supermarket.view.HomeView; import com.lingnan.supermarket.view.OutView; import com.lingnan.supermarket.view.ProdCatalogView.MyItemListener; - +// 定义ChangeStatusDialog类,继承JDialog并实现ActionListener接口 public class ChangeStatusDialog extends JDialog implements ActionListener{ - - + + // 声明面板、标签、按钮等组件 private JPanel statusPanel,opePanel,titlePanel,comboPanel; private JLabel titleLabel,statusLabel; private JButton UpdateBtn,cancelBtn; + // 声明字符串变量,用于存储订单编号和状态 private String iNumber; private String status; - + + // 声明一个Vector集合,用于存储InRecord对象 private Vector InRecords; - + + // 声明一个JComboBox组件,用于显示订单状态选项 private JComboBox combo; + // 声明一个字符串数组,用于存储订单状态选项 private String[] log = { "待入库", "已入库", "取消订单" }; - + + // 声明inRecordServiceImpl对象,用于操作入库记录 private inRecordServiceImpl inRecordImpl; - + + // 声明一个整数变量,用于存储分类信息 private int catalog; - + // 声明productionImpl对象,用于操作商品信息 private productionImpl productionImpl; - - - - + + + + + + // 构造方法,接收父窗口、订单编号和状态作为参数 public ChangeStatusDialog(JFrame parent,String iNumber,String status) { + // 调用父类构造方法,设置对话框标题 super(parent,"修改进货订单状态"); - - setSize(400,200); - setLocationRelativeTo(null); + + // 设置对话框大小 + setSize(400,200); + // 设置对话框在屏幕中央显示 + setLocationRelativeTo(null); + // 设置对话框为模态 setModal(true); - setResizable(false); + // 设置对话框不可调整大小 + setResizable(false); + // 设置对话框布局为FlowLayout this.setLayout(new FlowLayout()); - + + // 初始化成员变量 this.iNumber=iNumber; this.status=status; + // 初始化视图 initView(); } - - - + // 初始化视图的私有方法 private void initView() { + // 创建标题面板 titlePanel = new JPanel(); + // 创建标题标签,显示订单编号 titleLabel = new JLabel("修改订单为"+iNumber+"的状态"); + // 将标题标签添加到标题面板 titlePanel.add(titleLabel); - + // 创建状态面板 statusPanel = new JPanel(); + // 创建状态标签,显示当前状态 statusLabel = new JLabel("当前状态:"+status); + // 将状态标签添加到状态面板 statusPanel.add(statusLabel); - + + // 创建组合框面板 comboPanel = new JPanel(); + // 创建组合框,用于选择订单状态 combo = new JComboBox(log);/*下拉表*/ + // 为组合框添加项目监听器 combo.addItemListener(new MyItemListener()); + // 将组合框添加到组合框面板 comboPanel.add(combo); - - + + + // 创建操作面板 opePanel = new JPanel(); + // 创建更新按钮 UpdateBtn = new JButton("更改"); + // 创建取消按钮 cancelBtn = new JButton("取消"); + // 为更新按钮添加动作监听器 UpdateBtn.addActionListener(this); + // 为取消按钮添加动作监听器 cancelBtn.addActionListener(this); + // 将按钮添加到操作面板 opePanel.add(UpdateBtn); opePanel.add(cancelBtn); - + + // 获取内容面板 Container container = getContentPane(); + // 将标题面板添加到内容面板的北部 container.add(titlePanel,"North"); + // 将状态面板添加到内容面板的中央 container.add(statusPanel,"Center"); + // 将组合框面板添加到内容面板的南部 container.add(comboPanel,"South"); + // 将操作面板添加到内容面板 container.add(opePanel); - - - } + } + // 内部类,实现ItemListener接口,用于监听组合框项目变化 public class MyItemListener implements ItemListener { + // 重写itemStateChanged方法,当组合框项目变化时调用 @Override public void itemStateChanged(ItemEvent e) { + // 获取触发事件的组合框 JComboBox cb = (JComboBox) e.getSource(); + // 获取选中的项目 String catalog1 = (String) cb.getSelectedItem(); + // 根据选中的项目设置分类变量 if (catalog1.equals("已入库")) { catalog = 1; } @@ -129,56 +169,143 @@ public class ChangeStatusDialog extends JDialog implements ActionListener{ catalog = 2; } else if (catalog1.equals("取消订单")) { catalog = 3; + } } } - + + // 公共方法,返回InRecords向量 public Vector getVector(){ + // 返回InRecords向量 return InRecords; } - + // 重写ActionListener接口的actionPerformed方法,用于处理按钮点击事件 @Override public void actionPerformed(ActionEvent e) { + // 获取事件源对象 Object source = e.getSource(); + // 如果事件源是更新按钮 if(source==UpdateBtn){ + // 打印当前分类变量的值 System.out.println("此时此刻的catalog为"+catalog); - //这里修改进货订单表的状态*/ + // 这里修改进货订单表的状态 inOrderServiceImpl inOrderImpl = new inOrderServiceImpl(); inRecordServiceImpl inRecordImpl = new inRecordServiceImpl(); storageRecordImpl storageRecordImpl = new storageRecordImpl(); productionImpl = new productionImpl(); Production p ; - //获得订单信息 - - //修改状态 + // 获得订单信息 + + // 修改订单状态 inOrderImpl.updateInOrderStatus(iNumber,catalog); - //确认进货,修改状态并对库存和库存日志修改 + // 确认进货,修改状态并对库存和库存日志进行修改 if(catalog==1) { - //获得订单详细信息 + // 获得订单详细信息 this.InRecords = inRecordImpl.findByIdinRecord(iNumber); - //遍历添加库存 + // 遍历订单详细信息,添加库存 String s[]=TimeAndOrder.TimeAndOrder("");/*生成时间*/ for(InRecord i:InRecords) { - //查找到原来的价格 - //更新库存表 - productionImpl.updateProductionSum(i.getId(),i.getSum()); - //增加库存日志表 + // 查找到原来的价格 + // 更新库存表 + productionImpl.updateProductionSum(i.getId(),i.getSum()); + // 增加库存日志表记录 storageRecordImpl.insertStorageRecord(iNumber,s[1], i.getId(),"+", i.getSum()); } - + + // 弹出订单确认和库存更新成功的提示对话框 JOptionPane.showMessageDialog(this,"订单已确认,库存更新成功","提示",JOptionPane.INFORMATION_MESSAGE); - } - /*刷新首页*/ + } + // 刷新首页 this.dispose(); } + // 如果事件源是取消按钮 else if(source == cancelBtn) { - + // 关闭对话框 this.dispose(); + } } } + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Supermarket/src/com/lingnan/supermarket/dialog/ChangeSumDialog.java b/Supermarket/src/com/lingnan/supermarket/dialog/ChangeSumDialog.java index 5c95dc2..3dc3480 100644 --- a/Supermarket/src/com/lingnan/supermarket/dialog/ChangeSumDialog.java +++ b/Supermarket/src/com/lingnan/supermarket/dialog/ChangeSumDialog.java @@ -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; @@ -15,6 +17,7 @@ import javax.swing.JPanel; import javax.swing.JTable; import javax.swing.JTextField; +// 导入项目中的其他包和类 import com.lingnan.supermarket.*; import com.lingnan.supermarket.dao.UserService; import com.lingnan.supermarket.dao.impl.BufferImpl; @@ -26,160 +29,228 @@ import com.lingnan.supermarket.dto.User; import com.lingnan.supermarket.table.OutTableModel; import com.lingnan.supermarket.view.OutView; - +// 定义ChangeSumDialog类,继承JDialog并实现ActionListener接口 public class ChangeSumDialog extends JDialog implements ActionListener{ - - + + // 声明各种面板 private JPanel prodIdPanel,sumPanel,phonePanel,opePanel,titlePanel; - + + // 声明标签和文本框 private JLabel prodIdLabel,sumLabel,titleLabel; private JTextField prodIdTF,sumTF; - + + // 声明按钮 private JButton UpdateBtn,cancelBtn; - - + + + // 实例化OutTableModel对象 private OutTableModel outTableModel = new OutTableModel(); - + + // 声明Buffer对象 private Buffer buffer; - + + // 声明字符串变量,用于存储商品ID和标记 private String prodId,mark;/*mark用来标记是进货还是出货系统*/ - + + // 声明一个Vector集合,用于存储Production对象 private Vector v; - + + // 带参数的构造方法,初始化对话框并设置属性 public ChangeSumDialog(JFrame parent,String prodId,String mark,Vector v) { super(parent,"更改商品数量"); - - setSize(350,200); - setLocationRelativeTo(null); + + // 设置对话框大小 + setSize(350,200); + // 设置对话框相对于父窗口居中 + setLocationRelativeTo(null); + // 设置对话框为模态 setModal(true); - setResizable(false); + // 设置对话框不可调整大小 + setResizable(false); + // 设置对话框布局为FlowLayout this.setLayout(new FlowLayout()); - + + // 初始化成员变量 this.prodId=prodId; this.mark=mark; this.v = v; + // 初始化视图 initView(); } - + + // 另一个带参数的构造方法,初始化对话框并设置属性 public ChangeSumDialog(JFrame parent,String prodId,String mark) { super(parent,"更改商品数量"); - - setSize(350,200); - setLocationRelativeTo(null); + + // 设置对话框大小 + setSize(350,200); + // 设置对话框相对于父窗口居中 + setLocationRelativeTo(null); + // 设置对话框为模态 setModal(true); - setResizable(false); + // 设置对话框不可调整大小 + setResizable(false); + // 设置对话框布局为FlowLayout this.setLayout(new FlowLayout()); - + + // 初始化成员变量 this.prodId=prodId; this.mark=mark; + // 初始化视图 initView(); } - - - - - + + + + + + + // 私有方法,用于初始化视图 private void initView() { + // 创建标题面板 titlePanel = new JPanel(); + // 创建标题标签,显示要修改的商品ID titleLabel = new JLabel("修改商品id为"+prodId+"的数量"); + // 将标题标签添加到标题面板 titlePanel.add(titleLabel); - - + + + // 创建数量输入面板 sumPanel = new JPanel(); + // 创建数量标签 sumLabel = new JLabel("数量"); + // 创建文本框,用于输入数量,宽度为15个字符 sumTF = new JTextField(15); + // 将数量标签和文本框添加到数量输入面板 sumPanel.add(sumLabel); sumPanel.add(sumTF); - - + + + // 创建操作按钮面板 opePanel = new JPanel(); + // 创建更新按钮 UpdateBtn = new JButton("更改"); + // 创建取消按钮 cancelBtn = new JButton("取消"); + // 为更新按钮添加事件监听器 UpdateBtn.addActionListener(this); + // 为取消按钮添加事件监听器 cancelBtn.addActionListener(this); + // 将更新和取消按钮添加到操作按钮面板 opePanel.add(UpdateBtn); opePanel.add(cancelBtn); - + + // 获取内容面板 Container container = getContentPane(); + // 将标题面板、数量输入面板和操作按钮面板添加到内容面板 container.add(titlePanel); container.add(sumPanel); container.add(opePanel); - } - + } + + // 公共方法,用于获取Vector public Vector getVector(){ return v; } + // 实现ActionListener接口的actionPerformed方法 @Override public void actionPerformed(ActionEvent e) { + // 获取事件源 Object source = e.getSource(); + // 判断事件源是否为更新按钮 if(source==UpdateBtn){ - + //TODO 参数校验 /*/返回这个记录的信息*/ - + + // 从文本框中获取数量并转换为整数 int sum = Integer.parseInt(sumTF.getText());/*获得数量*/ + // 打印要修改的数量 System.out.println("所要修改的数量sum="+sum); - + + // 判断文本框是否为空 if(sumTF.getText().equals("")) { + // 弹出错误提示对话框 JOptionPane.showMessageDialog(this,"请输入完整","提示",JOptionPane.ERROR_MESSAGE); return; } + // 判断输入的数量是否小于0 if(sum<0) {/*判断输入大于0*/ + // 弹出错误提示对话框 JOptionPane.showMessageDialog(this,"请输入大于0的数量","提示",JOptionPane.ERROR_MESSAGE); return; } - - - - + + + + + + // 实例化BufferImpl对象,用于操作缓冲区数据 BufferImpl bufferImpl = new BufferImpl(); - + +// 实例化productionImpl对象,用于操作商品数据 productionImpl productionImpl = new productionImpl(); +// 创建一个新的Production对象 Production production = new Production(); +// 根据商品ID查找商品信息并赋值给production对象 production = productionImpl.findByIdProduction(prodId); - + +// 创建一个新的Buffer对象 Buffer buffer = new Buffer(); +// 标志变量,用于表示操作是否成功 boolean flag = false; - - if(mark=="In") {/*进货界面*/ + +// 如果标记为"进货" + if(mark=="In") { + // 遍历购物缓冲区中的商品 for(Production p:v) { + // 如果找到对应ID的商品,则更新其数量 if(p.getId().equals(prodId)) p.setSum(sum); } - + } - - else if(mark=="Out") {/*出货界面*/ + +// 如果标记为"出货" + else if(mark=="Out") { + // 根据商品ID查找缓冲区中的进货记录 buffer = bufferImpl.findInBufferbyId(prodId); - if(buffer!=null) {/*记录有这条数据*/ - if(sum>production.getSum())/*修改数量超过库存*/ + // 如果找到了对应的记录 + if(buffer!=null) { + // 如果修改的数量超过库存 + if(sum>production.getSum()) + // 弹出错误提示对话框 JOptionPane.showMessageDialog(this,"库存数量为:"+production.getSum()+",修改数量请勿超过库存","提示",JOptionPane.ERROR_MESSAGE); else + // 更新缓冲区中的进货记录,并设置标志变量 flag = bufferImpl.UpdateInBufferById(prodId, sum); - + } - + } - - if(flag = true) {/*如果修改成功*/ - +// 如果操作成功 + if(flag = true) { + // 弹出修改成功的提示对话框 JOptionPane.showMessageDialog(this,"修改成功","提示",JOptionPane.INFORMATION_MESSAGE); + // 关闭对话框 dispose(); - + }else { + // 弹出修改失败的提示对话框 JOptionPane.showMessageDialog(this,"修改失败","提示",JOptionPane.ERROR_MESSAGE); + // 关闭对话框 dispose(); } - } - - else if(source == cancelBtn) { - +// 如果事件源是取消按钮 + }else if(source == cancelBtn) { + // 关闭对话框 this.dispose(); + } } }