|
|
package com.lingnan.supermarket.dialog; // 声明当前类所在的包
|
|
|
|
|
|
import java.awt.Container; // 导入AWT容器类
|
|
|
import java.awt.FlowLayout; // 导入流式布局类
|
|
|
import java.awt.event.ActionEvent; // 导入动作事件类
|
|
|
import java.awt.event.ActionListener; // 导入动作监听器接口
|
|
|
import java.awt.event.ItemEvent; // 导入项目事件类
|
|
|
import java.awt.event.ItemListener; // 导入项目监听器接口
|
|
|
import java.util.Vector; // 导入向量类,用于存储对象集合
|
|
|
|
|
|
import javax.swing.JButton; // 导入Swing按钮组件
|
|
|
import javax.swing.JComboBox; // 导入Swing下拉框组件
|
|
|
import javax.swing.JDialog; // 导入Swing对话框组件
|
|
|
import javax.swing.JFrame; // 导入Swing顶层窗口组件
|
|
|
import javax.swing.JLabel; // 导入Swing标签组件
|
|
|
import javax.swing.JOptionPane; // 导入Swing对话框工具类
|
|
|
import javax.swing.JPanel; // 导入Swing面板组件
|
|
|
import javax.swing.JTable; // 导入Swing表格组件
|
|
|
import javax.swing.JTextField; // 导入Swing文本框组件
|
|
|
|
|
|
import com.lingnan.supermarket.*; // 导入超市项目相关包
|
|
|
import com.lingnan.supermarket.dao.UserService; // 导入用户服务接口
|
|
|
import com.lingnan.supermarket.dao.impl.BufferImpl; // 导入缓冲区实现类
|
|
|
import com.lingnan.supermarket.dao.impl.UserServiceImpl; // 导入用户服务实现类
|
|
|
import com.lingnan.supermarket.dao.impl.inOrderServiceImpl; // 导入入库订单服务实现类
|
|
|
import com.lingnan.supermarket.dao.impl.inRecordServiceImpl; // 导入入库记录服务实现类
|
|
|
import com.lingnan.supermarket.dao.impl.productionImpl; // 导入产品服务实现类
|
|
|
import com.lingnan.supermarket.dao.impl.storageRecordImpl; // 导入库存记录服务实现类
|
|
|
import com.lingnan.supermarket.dto.Buffer; // 导入缓冲区数据传输对象
|
|
|
import com.lingnan.supermarket.dto.InOrder; // 导入入库订单数据传输对象
|
|
|
import com.lingnan.supermarket.dto.InRecord; // 导入入库记录数据传输对象
|
|
|
import com.lingnan.supermarket.dto.Production; // 导入产品数据传输对象
|
|
|
import com.lingnan.supermarket.dto.User; // 导入用户数据传输对象
|
|
|
import com.lingnan.supermarket.table.OutTableModel; // 导入出库表格模型类
|
|
|
import com.lingnan.supermarket.utils.TimeAndOrder; // 导入时间和订单工具类
|
|
|
import com.lingnan.supermarket.view.HomeView; // 导入主页视图类
|
|
|
import com.lingnan.supermarket.view.OutView; // 导入出库视图类
|
|
|
import com.lingnan.supermarket.view.ProdCatalogView.MyItemListener; // 导入产品目录视图的内部类MyItemListener
|
|
|
|
|
|
|
|
|
|
|
|
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; // 订单状态
|
|
|
|
|
|
private Vector<InRecord> InRecords; // 存储入库记录的向量
|
|
|
|
|
|
private JComboBox<String> combo; // 下拉框组件,用于选择订单状态
|
|
|
|
|
|
private String[] log = { "待入库", "已入库", "取消订单" }; // 订单状态数组
|
|
|
|
|
|
private inRecordServiceImpl inRecordImpl; // 入库记录服务实现类
|
|
|
|
|
|
private int catalog; // 分类标识
|
|
|
|
|
|
private productionImpl productionImpl; // 产品服务实现类
|
|
|
|
|
|
// 构造方法,接收父窗口、订单编号和订单状态作为参数
|
|
|
public ChangeStatusDialog(JFrame parent,String iNumber,String status) {
|
|
|
super(parent,"修改进货订单状态"); // 调用父类构造方法,设置对话框标题
|
|
|
|
|
|
setSize(400,200); // 设置对话框大小
|
|
|
setLocationRelativeTo(null); // 设置对话框相对于父窗口居中
|
|
|
setModal(true); // 设置对话框为模态
|
|
|
setResizable(false); // 设置对话框大小不可变
|
|
|
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<String>(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); // 将操作按钮面板添加到内容面板
|
|
|
|
|
|
}
|
|
|
|
|
|
public class MyItemListener implements ItemListener { // 定义一个内部类,实现项目监听器接口
|
|
|
|
|
|
@Override
|
|
|
public void itemStateChanged(ItemEvent e) { // 实现项目状态改变时的处理方法
|
|
|
JComboBox cb = (JComboBox) e.getSource(); // 获取事件源,即下拉框
|
|
|
String catalog1 = (String) cb.getSelectedItem(); // 获取下拉框选中的项
|
|
|
if (catalog1.equals("已入库")) { // 如果选中项为"已入库"
|
|
|
catalog = 1; // 将分类标识设置为1
|
|
|
}
|
|
|
else if (catalog1.equals("待入库")) { // 如果选中项为"待入库"
|
|
|
catalog = 2; // 将分类标识设置为2
|
|
|
} else if (catalog1.equals("取消订单")) { // 如果选中项为"取消订单"
|
|
|
catalog = 3; // 将分类标识设置为3
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public Vector<InRecord> getVector(){ // 定义一个公共方法,返回一个InRecord类型的Vector
|
|
|
return InRecords; // 返回成员变量InRecords,它是一个包含InRecord对象的Vector
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
public void actionPerformed(ActionEvent e) { // 重写actionPerformed方法以响应按钮点击事件
|
|
|
Object source = e.getSource(); // 获取事件源
|
|
|
if(source==UpdateBtn){ // 如果事件源是更新按钮
|
|
|
System.out.println("此时此刻的catalog为"+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) { // 如果catalog等于1
|
|
|
//获得订单详细信息
|
|
|
this.InRecords = inRecordImpl.findByIdinRecord(iNumber); // 根据订单编号查找进货记录
|
|
|
//遍历添加库存
|
|
|
String s[]=TimeAndOrder.TimeAndOrder("");/*生成时间*/
|
|
|
for(InRecord i:InRecords) { // 遍历进货记录
|
|
|
//查找到原来的价格
|
|
|
//更新库存表
|
|
|
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(); // 关闭当前对话框
|
|
|
|
|
|
}
|
|
|
}
|
|
|
}
|