仓库系统部分注释完成

pull/47/head
郑亦歆 9 months ago
parent 5639047a02
commit 31474a5234

@ -1,5 +1,7 @@
// 定义包名表明该类属于com.lingnan.supermarket.dialog包
package com.lingnan.supermarket.dialog; package com.lingnan.supermarket.dialog;
// 导入必要的Java和Swing类库
import java.awt.Container; import java.awt.Container;
import java.awt.FlowLayout; import java.awt.FlowLayout;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
@ -18,6 +20,7 @@ import javax.swing.JPanel;
import javax.swing.JTable; import javax.swing.JTable;
import javax.swing.JTextField; import javax.swing.JTextField;
// 导入项目相关的类和接口
import com.lingnan.supermarket.*; import com.lingnan.supermarket.*;
import com.lingnan.supermarket.dao.UserService; import com.lingnan.supermarket.dao.UserService;
import com.lingnan.supermarket.dao.impl.BufferImpl; 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.OutView;
import com.lingnan.supermarket.view.ProdCatalogView.MyItemListener; import com.lingnan.supermarket.view.ProdCatalogView.MyItemListener;
// 定义ChangeStatusDialog类继承JDialog并实现ActionListener接口
public class ChangeStatusDialog extends JDialog implements ActionListener{ public class ChangeStatusDialog extends JDialog implements ActionListener{
// 声明面板、标签、按钮等组件
private JPanel statusPanel,opePanel,titlePanel,comboPanel; private JPanel statusPanel,opePanel,titlePanel,comboPanel;
private JLabel titleLabel,statusLabel; private JLabel titleLabel,statusLabel;
private JButton UpdateBtn,cancelBtn; private JButton UpdateBtn,cancelBtn;
// 声明字符串变量,用于存储订单编号和状态
private String iNumber; private String iNumber;
private String status; private String status;
// 声明一个Vector集合用于存储InRecord对象
private Vector<InRecord> InRecords; private Vector<InRecord> InRecords;
// 声明一个JComboBox组件用于显示订单状态选项
private JComboBox<String> combo; private JComboBox<String> combo;
// 声明一个字符串数组,用于存储订单状态选项
private String[] log = { "待入库", "已入库", "取消订单" }; private String[] log = { "待入库", "已入库", "取消订单" };
// 声明inRecordServiceImpl对象用于操作入库记录
private inRecordServiceImpl inRecordImpl; private inRecordServiceImpl inRecordImpl;
// 声明一个整数变量,用于存储分类信息
private int catalog; private int catalog;
// 声明productionImpl对象用于操作商品信息
private productionImpl productionImpl; private productionImpl productionImpl;
// 构造方法,接收父窗口、订单编号和状态作为参数
public ChangeStatusDialog(JFrame parent,String iNumber,String status) { public ChangeStatusDialog(JFrame parent,String iNumber,String status) {
// 调用父类构造方法,设置对话框标题
super(parent,"修改进货订单状态"); super(parent,"修改进货订单状态");
// 设置对话框大小
setSize(400,200); setSize(400,200);
// 设置对话框在屏幕中央显示
setLocationRelativeTo(null); setLocationRelativeTo(null);
// 设置对话框为模态
setModal(true); setModal(true);
// 设置对话框不可调整大小
setResizable(false); setResizable(false);
// 设置对话框布局为FlowLayout
this.setLayout(new FlowLayout()); this.setLayout(new FlowLayout());
// 初始化成员变量
this.iNumber=iNumber; this.iNumber=iNumber;
this.status=status; this.status=status;
// 初始化视图
initView(); initView();
} }
// 初始化视图的私有方法
private void initView() { private void initView() {
// 创建标题面板
titlePanel = new JPanel(); titlePanel = new JPanel();
// 创建标题标签,显示订单编号
titleLabel = new JLabel("修改订单为"+iNumber+"的状态"); titleLabel = new JLabel("修改订单为"+iNumber+"的状态");
// 将标题标签添加到标题面板
titlePanel.add(titleLabel); titlePanel.add(titleLabel);
// 创建状态面板
statusPanel = new JPanel(); statusPanel = new JPanel();
// 创建状态标签,显示当前状态
statusLabel = new JLabel("当前状态:"+status); statusLabel = new JLabel("当前状态:"+status);
// 将状态标签添加到状态面板
statusPanel.add(statusLabel); statusPanel.add(statusLabel);
// 创建组合框面板
comboPanel = new JPanel(); comboPanel = new JPanel();
// 创建组合框,用于选择订单状态
combo = new JComboBox<String>(log);/*下拉表*/ combo = new JComboBox<String>(log);/*下拉表*/
// 为组合框添加项目监听器
combo.addItemListener(new MyItemListener()); combo.addItemListener(new MyItemListener());
// 将组合框添加到组合框面板
comboPanel.add(combo); comboPanel.add(combo);
// 创建操作面板
opePanel = new JPanel(); opePanel = new JPanel();
// 创建更新按钮
UpdateBtn = new JButton("更改"); UpdateBtn = new JButton("更改");
// 创建取消按钮
cancelBtn = new JButton("取消"); cancelBtn = new JButton("取消");
// 为更新按钮添加动作监听器
UpdateBtn.addActionListener(this); UpdateBtn.addActionListener(this);
// 为取消按钮添加动作监听器
cancelBtn.addActionListener(this); cancelBtn.addActionListener(this);
// 将按钮添加到操作面板
opePanel.add(UpdateBtn); opePanel.add(UpdateBtn);
opePanel.add(cancelBtn); opePanel.add(cancelBtn);
// 获取内容面板
Container container = getContentPane(); Container container = getContentPane();
// 将标题面板添加到内容面板的北部
container.add(titlePanel,"North"); container.add(titlePanel,"North");
// 将状态面板添加到内容面板的中央
container.add(statusPanel,"Center"); container.add(statusPanel,"Center");
// 将组合框面板添加到内容面板的南部
container.add(comboPanel,"South"); container.add(comboPanel,"South");
// 将操作面板添加到内容面板
container.add(opePanel); container.add(opePanel);
} }
// 内部类实现ItemListener接口用于监听组合框项目变化
public class MyItemListener implements ItemListener { public class MyItemListener implements ItemListener {
// 重写itemStateChanged方法当组合框项目变化时调用
@Override @Override
public void itemStateChanged(ItemEvent e) { public void itemStateChanged(ItemEvent e) {
// 获取触发事件的组合框
JComboBox cb = (JComboBox) e.getSource(); JComboBox cb = (JComboBox) e.getSource();
// 获取选中的项目
String catalog1 = (String) cb.getSelectedItem(); String catalog1 = (String) cb.getSelectedItem();
// 根据选中的项目设置分类变量
if (catalog1.equals("已入库")) { if (catalog1.equals("已入库")) {
catalog = 1; catalog = 1;
} }
@ -129,6 +169,7 @@ public class ChangeStatusDialog extends JDialog implements ActionListener{
catalog = 2; catalog = 2;
} else if (catalog1.equals("取消订单")) { } else if (catalog1.equals("取消订单")) {
catalog = 3; catalog = 3;
} }
} }
@ -136,17 +177,22 @@ public class ChangeStatusDialog extends JDialog implements ActionListener{
} }
// 公共方法返回InRecords向量
public Vector<InRecord> getVector(){ public Vector<InRecord> getVector(){
// 返回InRecords向量
return InRecords; return InRecords;
} }
// 重写ActionListener接口的actionPerformed方法用于处理按钮点击事件
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
// 获取事件源对象
Object source = e.getSource(); Object source = e.getSource();
// 如果事件源是更新按钮
if(source==UpdateBtn){ if(source==UpdateBtn){
// 打印当前分类变量的值
System.out.println("此时此刻的catalog为"+catalog); System.out.println("此时此刻的catalog为"+catalog);
//这里修改进货订单表的状态*/ // 这里修改进货订单表的状态
inOrderServiceImpl inOrderImpl = new inOrderServiceImpl(); inOrderServiceImpl inOrderImpl = new inOrderServiceImpl();
inRecordServiceImpl inRecordImpl = new inRecordServiceImpl(); inRecordServiceImpl inRecordImpl = new inRecordServiceImpl();
storageRecordImpl storageRecordImpl = new storageRecordImpl(); storageRecordImpl storageRecordImpl = new storageRecordImpl();
@ -154,31 +200,112 @@ public class ChangeStatusDialog extends JDialog implements ActionListener{
Production p ; Production p ;
// 获得订单信息 // 获得订单信息
//修改状态 // 修改订单状态
inOrderImpl.updateInOrderStatus(iNumber,catalog); inOrderImpl.updateInOrderStatus(iNumber,catalog);
//确认进货,修改状态并对库存和库存日志修改 // 确认进货,修改状态并对库存和库存日志进行修改
if(catalog==1) { if(catalog==1) {
// 获得订单详细信息 // 获得订单详细信息
this.InRecords = inRecordImpl.findByIdinRecord(iNumber); this.InRecords = inRecordImpl.findByIdinRecord(iNumber);
//遍历添加库存 // 遍历订单详细信息,添加库存
String s[]=TimeAndOrder.TimeAndOrder("");/*生成时间*/ String s[]=TimeAndOrder.TimeAndOrder("");/*生成时间*/
for(InRecord i:InRecords) { 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()); storageRecordImpl.insertStorageRecord(iNumber,s[1], i.getId(),"+", i.getSum());
} }
// 弹出订单确认和库存更新成功的提示对话框
JOptionPane.showMessageDialog(this,"订单已确认,库存更新成功","提示",JOptionPane.INFORMATION_MESSAGE); JOptionPane.showMessageDialog(this,"订单已确认,库存更新成功","提示",JOptionPane.INFORMATION_MESSAGE);
} }
/*刷新首页*/ // 刷新首页
this.dispose(); this.dispose();
} }
// 如果事件源是取消按钮
else if(source == cancelBtn) { else if(source == cancelBtn) {
// 关闭对话框
this.dispose(); this.dispose();
} }
} }
} }

@ -1,5 +1,7 @@
// 定义包名表示该类属于com.lingnan.supermarket.dialog包
package com.lingnan.supermarket.dialog; package com.lingnan.supermarket.dialog;
// 导入所需的java.awt和javax.swing包中的类
import java.awt.Container; import java.awt.Container;
import java.awt.FlowLayout; import java.awt.FlowLayout;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
@ -15,6 +17,7 @@ import javax.swing.JPanel;
import javax.swing.JTable; import javax.swing.JTable;
import javax.swing.JTextField; import javax.swing.JTextField;
// 导入项目中的其他包和类
import com.lingnan.supermarket.*; import com.lingnan.supermarket.*;
import com.lingnan.supermarket.dao.UserService; import com.lingnan.supermarket.dao.UserService;
import com.lingnan.supermarket.dao.impl.BufferImpl; import com.lingnan.supermarket.dao.impl.BufferImpl;
@ -26,52 +29,74 @@ import com.lingnan.supermarket.dto.User;
import com.lingnan.supermarket.table.OutTableModel; import com.lingnan.supermarket.table.OutTableModel;
import com.lingnan.supermarket.view.OutView; import com.lingnan.supermarket.view.OutView;
// 定义ChangeSumDialog类继承JDialog并实现ActionListener接口
public class ChangeSumDialog extends JDialog implements ActionListener{ public class ChangeSumDialog extends JDialog implements ActionListener{
// 声明各种面板
private JPanel prodIdPanel,sumPanel,phonePanel,opePanel,titlePanel; private JPanel prodIdPanel,sumPanel,phonePanel,opePanel,titlePanel;
// 声明标签和文本框
private JLabel prodIdLabel,sumLabel,titleLabel; private JLabel prodIdLabel,sumLabel,titleLabel;
private JTextField prodIdTF,sumTF; private JTextField prodIdTF,sumTF;
// 声明按钮
private JButton UpdateBtn,cancelBtn; private JButton UpdateBtn,cancelBtn;
// 实例化OutTableModel对象
private OutTableModel outTableModel = new OutTableModel(); private OutTableModel outTableModel = new OutTableModel();
// 声明Buffer对象
private Buffer buffer; private Buffer buffer;
// 声明字符串变量用于存储商品ID和标记
private String prodId,mark;/*mark用来标记是进货还是出货系统*/ private String prodId,mark;/*mark用来标记是进货还是出货系统*/
// 声明一个Vector集合用于存储Production对象
private Vector<Production> v; private Vector<Production> v;
// 带参数的构造方法,初始化对话框并设置属性
public ChangeSumDialog(JFrame parent,String prodId,String mark,Vector<Production> v) { public ChangeSumDialog(JFrame parent,String prodId,String mark,Vector<Production> v) {
super(parent,"更改商品数量"); super(parent,"更改商品数量");
// 设置对话框大小
setSize(350,200); setSize(350,200);
// 设置对话框相对于父窗口居中
setLocationRelativeTo(null); setLocationRelativeTo(null);
// 设置对话框为模态
setModal(true); setModal(true);
// 设置对话框不可调整大小
setResizable(false); setResizable(false);
// 设置对话框布局为FlowLayout
this.setLayout(new FlowLayout()); this.setLayout(new FlowLayout());
// 初始化成员变量
this.prodId=prodId; this.prodId=prodId;
this.mark=mark; this.mark=mark;
this.v = v; this.v = v;
// 初始化视图
initView(); initView();
} }
// 另一个带参数的构造方法,初始化对话框并设置属性
public ChangeSumDialog(JFrame parent,String prodId,String mark) { public ChangeSumDialog(JFrame parent,String prodId,String mark) {
super(parent,"更改商品数量"); super(parent,"更改商品数量");
// 设置对话框大小
setSize(350,200); setSize(350,200);
// 设置对话框相对于父窗口居中
setLocationRelativeTo(null); setLocationRelativeTo(null);
// 设置对话框为模态
setModal(true); setModal(true);
// 设置对话框不可调整大小
setResizable(false); setResizable(false);
// 设置对话框布局为FlowLayout
this.setLayout(new FlowLayout()); this.setLayout(new FlowLayout());
// 初始化成员变量
this.prodId=prodId; this.prodId=prodId;
this.mark=mark; this.mark=mark;
// 初始化视图
initView(); initView();
} }
@ -79,56 +104,83 @@ public class ChangeSumDialog extends JDialog implements ActionListener{
// 私有方法,用于初始化视图
private void initView() { private void initView() {
// 创建标题面板
titlePanel = new JPanel(); titlePanel = new JPanel();
// 创建标题标签显示要修改的商品ID
titleLabel = new JLabel("修改商品id为"+prodId+"的数量"); titleLabel = new JLabel("修改商品id为"+prodId+"的数量");
// 将标题标签添加到标题面板
titlePanel.add(titleLabel); titlePanel.add(titleLabel);
// 创建数量输入面板
sumPanel = new JPanel(); sumPanel = new JPanel();
// 创建数量标签
sumLabel = new JLabel("数量"); sumLabel = new JLabel("数量");
// 创建文本框用于输入数量宽度为15个字符
sumTF = new JTextField(15); sumTF = new JTextField(15);
// 将数量标签和文本框添加到数量输入面板
sumPanel.add(sumLabel); sumPanel.add(sumLabel);
sumPanel.add(sumTF); sumPanel.add(sumTF);
// 创建操作按钮面板
opePanel = new JPanel(); opePanel = new JPanel();
// 创建更新按钮
UpdateBtn = new JButton("更改"); UpdateBtn = new JButton("更改");
// 创建取消按钮
cancelBtn = new JButton("取消"); cancelBtn = new JButton("取消");
// 为更新按钮添加事件监听器
UpdateBtn.addActionListener(this); UpdateBtn.addActionListener(this);
// 为取消按钮添加事件监听器
cancelBtn.addActionListener(this); cancelBtn.addActionListener(this);
// 将更新和取消按钮添加到操作按钮面板
opePanel.add(UpdateBtn); opePanel.add(UpdateBtn);
opePanel.add(cancelBtn); opePanel.add(cancelBtn);
// 获取内容面板
Container container = getContentPane(); Container container = getContentPane();
// 将标题面板、数量输入面板和操作按钮面板添加到内容面板
container.add(titlePanel); container.add(titlePanel);
container.add(sumPanel); container.add(sumPanel);
container.add(opePanel); container.add(opePanel);
} }
// 公共方法用于获取Vector<Production>
public Vector<Production> getVector(){ public Vector<Production> getVector(){
return v; return v;
} }
// 实现ActionListener接口的actionPerformed方法
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
// 获取事件源
Object source = e.getSource(); Object source = e.getSource();
// 判断事件源是否为更新按钮
if(source==UpdateBtn){ if(source==UpdateBtn){
//TODO 参数校验 //TODO 参数校验
/*/返回这个记录的信息*/ /*/返回这个记录的信息*/
// 从文本框中获取数量并转换为整数
int sum = Integer.parseInt(sumTF.getText());/*获得数量*/ int sum = Integer.parseInt(sumTF.getText());/*获得数量*/
// 打印要修改的数量
System.out.println("所要修改的数量sum="+sum); System.out.println("所要修改的数量sum="+sum);
// 判断文本框是否为空
if(sumTF.getText().equals("")) { if(sumTF.getText().equals("")) {
// 弹出错误提示对话框
JOptionPane.showMessageDialog(this,"请输入完整","提示",JOptionPane.ERROR_MESSAGE); JOptionPane.showMessageDialog(this,"请输入完整","提示",JOptionPane.ERROR_MESSAGE);
return; return;
} }
// 判断输入的数量是否小于0
if(sum<0) {/*判断输入大于0*/ if(sum<0) {/*判断输入大于0*/
// 弹出错误提示对话框
JOptionPane.showMessageDialog(this,"请输入大于0的数量","提示",JOptionPane.ERROR_MESSAGE); JOptionPane.showMessageDialog(this,"请输入大于0的数量","提示",JOptionPane.ERROR_MESSAGE);
return; return;
} }
@ -136,50 +188,69 @@ public class ChangeSumDialog extends JDialog implements ActionListener{
// 实例化BufferImpl对象用于操作缓冲区数据
BufferImpl bufferImpl = new BufferImpl(); BufferImpl bufferImpl = new BufferImpl();
// 实例化productionImpl对象用于操作商品数据
productionImpl productionImpl = new productionImpl(); productionImpl productionImpl = new productionImpl();
// 创建一个新的Production对象
Production production = new Production(); Production production = new Production();
// 根据商品ID查找商品信息并赋值给production对象
production = productionImpl.findByIdProduction(prodId); production = productionImpl.findByIdProduction(prodId);
// 创建一个新的Buffer对象
Buffer buffer = new Buffer(); Buffer buffer = new Buffer();
// 标志变量,用于表示操作是否成功
boolean flag = false; boolean flag = false;
if(mark=="In") {/*进货界面*/ // 如果标记为"进货"
if(mark=="In") {
// 遍历购物缓冲区中的商品
for(Production p:v) { for(Production p:v) {
// 如果找到对应ID的商品则更新其数量
if(p.getId().equals(prodId)) if(p.getId().equals(prodId))
p.setSum(sum); p.setSum(sum);
} }
} }
else if(mark=="Out") {/*出货界面*/ // 如果标记为"出货"
else if(mark=="Out") {
// 根据商品ID查找缓冲区中的进货记录
buffer = bufferImpl.findInBufferbyId(prodId); 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); JOptionPane.showMessageDialog(this,"库存数量为:"+production.getSum()+",修改数量请勿超过库存","提示",JOptionPane.ERROR_MESSAGE);
else else
// 更新缓冲区中的进货记录,并设置标志变量
flag = bufferImpl.UpdateInBufferById(prodId, sum); flag = bufferImpl.UpdateInBufferById(prodId, sum);
} }
} }
// 如果操作成功
if(flag = true) {/*如果修改成功*/ if(flag = true) {
// 弹出修改成功的提示对话框
JOptionPane.showMessageDialog(this,"修改成功","提示",JOptionPane.INFORMATION_MESSAGE); JOptionPane.showMessageDialog(this,"修改成功","提示",JOptionPane.INFORMATION_MESSAGE);
// 关闭对话框
dispose(); dispose();
}else { }else {
// 弹出修改失败的提示对话框
JOptionPane.showMessageDialog(this,"修改失败","提示",JOptionPane.ERROR_MESSAGE); JOptionPane.showMessageDialog(this,"修改失败","提示",JOptionPane.ERROR_MESSAGE);
// 关闭对话框
dispose(); dispose();
} }
} // 如果事件源是取消按钮
}else if(source == cancelBtn) {
else if(source == cancelBtn) { // 关闭对话框
this.dispose(); this.dispose();
} }
} }
} }

Loading…
Cancel
Save