main
aaa 9 months ago
parent df26c03e1d
commit 7c2d137721

@ -0,0 +1,189 @@
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(); // 关闭当前对话框
}
}
}

@ -0,0 +1,186 @@
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.util.Vector; // 导入向量类,用于存储对象集合
import javax.swing.JButton; // 导入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.productionImpl; // 导入产品服务实现类
import com.lingnan.supermarket.dto.Buffer; // 导入缓冲区数据传输对象
import com.lingnan.supermarket.dto.Production; // 导入产品数据传输对象
import com.lingnan.supermarket.dto.User; // 导入用户数据传输对象
import com.lingnan.supermarket.table.OutTableModel; // 导入出库表格模型类
import com.lingnan.supermarket.view.OutView; // 导入出库视图类
public class ChangeSumDialog extends JDialog implements ActionListener{ // 定义一个对话框类ChangeSumDialog继承自JDialog并实现ActionListener接口
private JPanel prodIdPanel,sumPanel,phonePanel,opePanel,titlePanel; // 声明多个面板变量,用于布局不同的组件
private JLabel prodIdLabel,sumLabel,titleLabel; // 声明标签变量,用于显示文本
private JTextField prodIdTF,sumTF; // 声明文本框变量,用于输入数据
private JButton UpdateBtn,cancelBtn; // 声明按钮变量,用于执行更新和取消操作
private OutTableModel outTableModel = new OutTableModel(); // 创建出库表格模型实例
private Buffer buffer; // 声明缓冲区对象变量
private String prodId,mark; /*mark用来标记是进货还是出货系统*/ // 声明字符串变量用于存储产品ID和标记
private Vector<Production> v; // 声明向量变量,用于存储产品集合
public ChangeSumDialog(JFrame parent,String prodId,String mark,Vector<Production> v) { // 构造方法接收父窗口、产品ID、标记和产品集合作为参数
super(parent,"更改商品数量"); // 调用父类构造方法,设置对话框标题
setSize(350,200); // 设置对话框大小
setLocationRelativeTo(null); // 设置对话框相对于父窗口居中显示
setModal(true); // 设置对话框为模态
setResizable(false); // 设置对话框不可调整大小
this.setLayout(new FlowLayout()); // 设置对话框布局为流式布局
this.prodId=prodId; // 将参数prodId赋值给成员变量prodId
this.mark=mark; // 将参数mark赋值给成员变量mark
this.v = v; // 将参数v赋值给成员变量v
initView(); // 初始化视图
}
public ChangeSumDialog(JFrame parent,String prodId,String mark) { // 另一个构造方法接收父窗口、产品ID和标记作为参数
super(parent,"更改商品数量"); // 调用父类构造方法,设置对话框标题为"更改商品数量"
setSize(350,200); // 设置对话框大小为350x200像素
setLocationRelativeTo(null); // 设置对话框位置相对于父窗口居中显示
setModal(true); // 设置对话框为模态,即用户必须处理完此对话框才能操作其他窗口
setResizable(false); // 设置对话框大小不可变
this.setLayout(new FlowLayout()); // 设置对话框布局为流式布局
this.prodId=prodId; // 将传入的产品ID赋值给成员变量prodId
this.mark=mark; // 将传入的标记赋值给成员变量mark
initView(); // 调用方法初始化视图
}
private void initView() {
titlePanel = new JPanel();
titleLabel = new JLabel("修改商品id为"+prodId+"的数量");
titlePanel.add(titleLabel);
sumPanel = new JPanel();
sumLabel = new JLabel("数量");
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);
}
public Vector<Production> getVector(){
return v;
}
@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;
}
if(sum<0) {/*判断输入大于0*/
JOptionPane.showMessageDialog(this,"请输入大于0的数量","提示",JOptionPane.ERROR_MESSAGE);
return;
}
BufferImpl bufferImpl = new BufferImpl();
productionImpl productionImpl = new productionImpl();
Production production = new Production();
production = productionImpl.findByIdProduction(prodId);
Buffer buffer = new Buffer();
boolean flag = false;
if(mark=="In") {/*进货界面*/
for(Production p:v) {
if(p.getId().equals(prodId))
p.setSum(sum);
}
}
else if(mark=="Out") {/*出货界面*/
buffer = bufferImpl.findInBufferbyId(prodId);
if(buffer!=null) {/*记录有这条数据*/
if(sum>production.getSum())/*修改数量超过库存*/
JOptionPane.showMessageDialog(this,"库存数量为:"+production.getSum()+",修改数量请勿超过库存","提示",JOptionPane.ERROR_MESSAGE);
else
flag = bufferImpl.UpdateInBufferById(prodId, sum);
}
}
if(flag = true) {/*如果修改成功*/
JOptionPane.showMessageDialog(this,"修改成功","提示",JOptionPane.INFORMATION_MESSAGE);
dispose();
}else {
JOptionPane.showMessageDialog(this,"修改失败","提示",JOptionPane.ERROR_MESSAGE);
dispose();
}
}
else if(source == cancelBtn) {
this.dispose();
}
}
}

@ -0,0 +1,230 @@
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; // 导入按钮组件类
import javax.swing.JComboBox; // 导入下拉框组件类
import javax.swing.JDialog; // 导入对话框组件类
import javax.swing.JFrame; // 导入顶层窗口类
import javax.swing.JLabel; // 导入标签组件类
import javax.swing.JOptionPane; // 导入对话框工具类
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; // 导入缓冲区服务实现类
import com.lingnan.supermarket.dao.impl.UserServiceImpl; // 导入用户服务实现类
import com.lingnan.supermarket.dao.impl.productionImpl; // 导入产品服务实现类
import com.lingnan.supermarket.dto.Buffer; // 导入缓冲区数据传输对象
import com.lingnan.supermarket.dto.Production; // 导入产品数据传输对象
import com.lingnan.supermarket.dto.User; // 导入用户数据传输对象
import com.lingnan.supermarket.table.OutTableModel; // 导入出库表格模型类
import com.lingnan.supermarket.view.InView; // 导入进货视图类
import com.lingnan.supermarket.view.OutView; // 导出出库视图类
import com.lingnan.supermarket.view.ProdCatalogView.MyItemListener; // 导入产品目录视图的内部类MyItemListener
public class InDialog extends JDialog implements ActionListener{ // 定义一个对话框类InDialog继承自JDialog并实现ActionListener接口
private JPanel prodIdPanel,sumPanel,phonePanel,opePanel; // 声明面板变量,用于不同功能的面板
private JLabel prodIdLabel,sumLabel; // 声明标签变量,用于显示文本
private JTextField prodIdTF,sumTF; // 声明文本框变量,用于输入数据
private JButton addBtn,cancelBtn; // 声明按钮变量,用于添加和取消操作
private OutTableModel outTableModel = new OutTableModel(); // 创建出库表格模型实例
private Production production; // 声明产品数据传输对象
private productionImpl productionImpl; // 声明产品服务实现类
private Vector<Production> v; // 声明产品集合变量
private User user; // 声明用户数据传输对象
private JFrame JFramparent; // 声明顶层窗口变量,用于存储父窗口
private JComboBox<String> combo; // 声明下拉框组件变量
private String allProdId[] = null; // 声明字符串数组用于存储所有产品ID
private Vector<Production> vAll; // 声明产品集合变量,用于存储所有产品
private static String catalog; // 声明静态字符串变量,用于存储分类信息
public InDialog(JFrame parent,Vector<Production> v,User user) { // 构造方法,接收父窗口、产品集合和用户对象
super(parent,"添加商品"); // 调用父类构造方法,设置对话框标题
setSize(250,200); // 设置对话框大小
setLocationRelativeTo(null); // 设置对话框居中显示
setModal(true); // 设置对话框为模态
setResizable(false); // 设置对话框不可调整大小
this.setLayout(new FlowLayout()); // 设置对话框布局为流式布局
JFramparent=parent; // 初始化父窗口变量
this.v=v; // 初始化产品集合变量
this.user = user; // 初始化用户对象
initView(); // 初始化视图
}
private void initView() {
prodIdPanel = new JPanel(); // 创建一个面板用于显示产品编号
prodIdLabel = new JLabel("编号"); // 创建一个标签显示"编号"
productionImpl= new productionImpl(); // 实例化产品服务实现类
vAll=productionImpl.findAllproduction(); // 调用方法获取所有产品信息
allProdId = new String[vAll.size()]; // 初始化字符串数组用于存储所有产品ID
for(int i=0;i<vAll.size();i++) { // 遍历产品集合将ID存入数组
allProdId[i]=vAll.elementAt(i).getId();
}
catalog = allProdId[0]; // 设置默认分类为第一个产品ID
System.out.println(allProdId[0]); // 打印第一个产品ID
combo = new JComboBox<String>(allProdId); // 创建下拉框并使用产品ID数组初始化
combo.addItemListener(new MyItemListener()); // 为下拉框添加项目监听器
prodIdPanel.add(prodIdLabel); // 将标签添加到编号面板
prodIdPanel.add(combo); // 将下拉框添加到编号面板
sumPanel = new JPanel(); // 创建一个面板用于显示数量
sumLabel = new JLabel("数量"); // 创建一个标签显示"数量"
sumTF = new JTextField(10); // 创建一个文本框用于输入数量宽度为10
sumPanel.add(sumLabel); // 将标签添加到数量面板
sumPanel.add(sumTF); // 将文本框添加到数量面板
opePanel = new JPanel(); // 创建一个面板用于显示操作按钮
addBtn = new JButton("添加"); // 创建一个按钮显示"添加"
cancelBtn = new JButton("取消"); // 创建一个按钮显示"取消"
addBtn.addActionListener(this); // 为添加按钮添加动作监听器
cancelBtn.addActionListener(this); // 为取消按钮添加动作监听器
opePanel.add(addBtn); // 将添加按钮添加到操作面板
opePanel.add(cancelBtn); // 将取消按钮添加到操作面板
Container container = getContentPane(); // 获取内容面板
container.add(prodIdPanel); // 将编号面板添加到内容面板
container.add(sumPanel); // 将数量面板添加到内容面板
container.add(opePanel); // 将操作面板添加到内容面板
}
/*将数组传到inview的刷新方法里面再刷新*/
public Vector<Production> getVector(){ // 提供一个方法获取产品集合
return v;
}
//下拉框监听
static class MyItemListener implements ItemListener{ // 定义一个内部类实现ItemListener接口
@Override
public void itemStateChanged(ItemEvent e) { // 实现项目状态改变时的处理方法
JComboBox cb=(JComboBox)e.getSource(); // 获取事件源下拉框
String select=(String) cb.getSelectedItem(); // 获取选中项的值
catalog=select; // 更新分类信息为选中项的值
}
}
@Override
public void actionPerformed(ActionEvent e) {
Object source = e.getSource(); // 获取事件源
if(source==addBtn){ // 如果事件源是添加按钮
//1.判断是否存在这个商品
//2.如果存在就获取这条商品记录为一个对象
//3.判断购物缓冲区是否有这个记录
//3.1如果有update数量和price
//3.2如果没有就insert这条记录把sum更新
//保存到数据库
//关闭对话框
//刷新table
String prodId =catalog; // 获取选中的商品ID
System.out.println("proId="+prodId); // 打印商品ID
System.out.println("vatalog="+catalog); // 打印分类信息
if(sumTF.getText().equals("")) { // 判断数量文本框是否为空
JOptionPane.showMessageDialog(this,"请输入完整","提示",JOptionPane.ERROR_MESSAGE);
return;
}
int sum = Integer.parseInt(sumTF.getText()) ; // 将文本框中的数量转换为整数
if(sum<0) {/*判断输入大于0*/
JOptionPane.showMessageDialog(this,"请输入大于0的数量","提示",JOptionPane.ERROR_MESSAGE);
return;
}
//TODO 参数校验
/*/判断是已添加,未添加还是不存在*/
productionImpl productionImpl = new productionImpl(); // 实例化产品服务实现类
production = new Production(); // 创建产品对象
production = productionImpl.findByIdProduction(prodId); // 根据ID查找产品
if(production!=null) {/*商品库有这个商品存在*/
int mark = 0; // 标记变量,用于判断商品是否已存在于购物缓冲区
for(Production p:v) { // 遍历购物缓冲区
if(p.getId().equals(prodId)){/*如果数组中存在相同商品就更新数量和价格*/
sum=p.getSum()+sum;/*数量*/
p.setSum(sum);
p.setPrice(sum*p.getInPrice());/*进货价格*/
mark = 1; // 更新标记
break;
}
}
if(mark==0) {/*插入新的*/
System.out.println("缓存区不存在,插入新的数据");
production.setSum(sum);/*更新价格和数量后插入新的*/
production.setPrice(sum*production.getInPrice());
v.add(production); // 将新产品添加到购物缓冲区
}
System.out.println("插入后v的大小"+v.size()); // 打印购物缓冲区大小
this.dispose(); // 关闭对话框
JOptionPane.showMessageDialog(this,"添加成功","提示",JOptionPane.ERROR_MESSAGE); // 显示添加成功消息
}
else {/*商品库没有这个商品*/
JOptionPane.showMessageDialog(this,"商品不存在","提示",JOptionPane.ERROR_MESSAGE); // 显示商品不存在消息
}
}
else if(source == cancelBtn) { // 如果事件源是取消按钮
this.dispose(); // 关闭对话框
}
}
}

@ -0,0 +1,62 @@
package com.lingnan.supermarket.dto; // 声明当前类所在的包
import java.util.Date; // 导入Date类尽管在此类中没有直接使用
// 定义进货订单类InOrder
public class InOrder {
private String iNumber; // 进货订单编号
private Float allInPrice; // 总进货价格
private String inDate; // 进货日期
private String principal; // 负责人
private int status; // 订单状态
private int delmark; // 删除标记
// getiNumber方法用于获取进货订单编号
public String getiNumber() {
return iNumber; // 返回进货订单编号
}
// setiNumber方法用于设置进货订单编号
public void setiNumber(String iNumber) {
this.iNumber = iNumber; // 将参数iNumber赋值给成员变量iNumber
}
// getAllInPrice方法用于获取总进货价格
public Float getAllInPrice() {
return allInPrice; // 返回总进货价格
}
// setAllInPrice方法用于设置总进货价格
public void setAllInPrice(Float allInPrice) {
this.allInPrice = allInPrice; // 将参数allInPrice赋值给成员变量allInPrice
}
// getInDate方法用于获取进货日期
public String getInDate() {
return inDate; // 返回进货日期
}
// setInDate方法用于设置进货日期
public void setInDate(String inDate) {
this.inDate = inDate; // 将参数inDate赋值给成员变量inDate
}
// getPrincipal方法用于获取负责人
public String getPrincipal() {
return principal; // 返回负责人
}
// setPrincipal方法用于设置负责人
public void setPrincipal(String principal) {
this.principal = principal; // 将参数principal赋值给成员变量principal
}
// getStatus方法用于获取订单状态
public int getStatus() {
return status; // 返回订单状态
}
// setStatus方法用于设置订单状态
public void setStatus(int status) {
this.status = status; // 将参数status赋值给成员变量status
}
// getDelmark方法用于获取删除标记
public int getDelmark() {
return delmark; // 返回删除标记
}
// setDelmark方法用于设置删除标记
public void setDelmark(int delmark) {
this.delmark = delmark; // 将参数delmark赋值给成员变量delmark
}
}

@ -0,0 +1,124 @@
package com.lingnan.supermarket.table; // 声明当前类所在的包
import java.util.List; // 导入List接口用于表示列表
import java.util.Vector; // 导入Vector类用于实现可增长的对象数组
import javax.swing.JFrame; // 导入JFrame类用于创建窗口
import javax.swing.table.AbstractTableModel; // 导入AbstractTableModel类用于创建表格模型
import com.lingnan.supermarket.dto.Buffer; // 导入Buffer数据传输对象
import com.lingnan.supermarket.dto.InOrder; // 导入InOrder数据传输对象
import com.lingnan.supermarket.dto.Buffer; // 重复导入Buffer数据传输对象可能是错误
import com.lingnan.supermarket.dto.Production; // 导入Production数据传输对象
import com.lingnan.supermarket.dto.User; // 导入User数据传输对象
import com.lingnan.supermarket.dao.UserService; // 导入UserService接口用于用户数据访问
import com.lingnan.supermarket.dao.impl.*; // 导入所有实现类,可能用于数据访问层的具体实现
import com.lingnan.supermarket.dialog.InDialog; // 导入InDialog类可能用于进货对话框
public class InOrderTM extends AbstractTableModel{ // 定义一个类InOrderTM继承自AbstractTableModel类用于表格模型
private String [] columnName = {"订单号","总价","时间","负责人","状态"}; // 定义列名数组,用于表格的列标题
private productionImpl prodDao = new productionImpl(); // 创建productionImpl对象用于操作产品数据
private Vector<InOrder> InOrders; // 声明一个Vector数组用于存储InOrder对象
private inOrderServiceImpl inOrderImpl= new inOrderServiceImpl(); // 创建inOrderServiceImpl对象用于操作订单数据
private InOrder inOrder ; // 声明InOrder对象用于单个订单操作
String iNumber ; // 声明一个String变量用于存储订单号
public void allInOrderRecord() { // 定义一个方法,用于获取所有订单记录
//将添加的商品加入到静态变量Vector数组中
/*prod = InDialog.getProduction();*/
InOrders = inOrderImpl.findAllInOrder(); // 调用inOrderImpl的方法获取所有订单并赋值给InOrders
}
//查找分类结果
public void resultOfFind(int catalog) { // 定义一个方法,根据分类查找订单
if(catalog==0) // 如果分类为0查找所有订单
InOrders = inOrderImpl.findAllInOrder(); // 获取所有订单
else
InOrders = inOrderImpl.FindStatus(catalog); // 否则根据状态查找订单
}
//根据订单号查找
public void resultOfNumber(String Number) { // 定义一个方法,根据订单号查找订单
InOrders=new Vector<InOrder>(); // 初始化InOrders为新的Vector对象
inOrder = inOrderImpl.findByIdinOrder(Number); // 根据订单号查找订单
InOrders.add(inOrder); // 将找到的订单添加到InOrders中
}
@Override
// 重写getRowCount方法返回表格的行数即订单列表的大小
public int getRowCount() {
return InOrders.size(); // 返回InOrders Vector的大小
}
/*
// 获取所有订单的总价格,此方法已被注释掉
public Float getAllPrice() {
return BufferImpl.InBufferAllPrice();
}
*/
@Override
// 重写getColumnCount方法返回表格的列数即列名数组的长度
public int getColumnCount() {
return columnName.length; // 返回columnName数组的长度
}
@Override
// 重写getValueAt方法根据行索引和列索引获取表格单元格的值
public Object getValueAt(int rowIndex, int columnIndex) {
inOrder = InOrders.get(rowIndex); // 获取指定行的订单对象
// 以下代码已被注释,可能是用于调试的打印语句
/*System.out.println( "id="+users.get(rowIndex).getId());
System.out.println("rowIndex"+rowIndex);
System.out.println("columnIndex"+columnIndex);*/
iNumber=inOrder.getiNumber(); // 获取订单号并赋值给iNumber
if(columnIndex==0) { // 如果是第一列,返回订单号
return inOrder.getiNumber();
}else if(columnIndex==1) { // 如果是第二列,返回订单总价
return inOrder.getAllInPrice();
}else if(columnIndex==2) { // 如果是第三列,返回订单日期
return inOrder.getInDate();
}else if(columnIndex==3) { // 如果是第四列,返回负责人
return inOrder.getPrincipal();
}else if(columnIndex==4) { // 如果是第五列,返回订单状态
String status = null;
if(inOrder.getStatus()==1)
status= "已入库";
else if(inOrder.getStatus()==2)
status= "待入库";
else if(inOrder.getStatus()==3)
status= "已取消";
return status;
}else { // 如果列索引不匹配返回null
return null;
}
}
// 返回要修改或删除的记录的订单号
public String getINumber() {
return iNumber; // 返回类的成员变量iNumber
}
@Override
// 重写getColumnName方法根据列索引获取列名
public String getColumnName(int column) {
return columnName[column]; // 返回columnName数组中指定索引的值
}
}

@ -0,0 +1,35 @@
package com.lingnan.supermarket.dto; // 声明当前类所在的包
import com.lingnan.supermarket.dto.base.BsDomain; // 导入基础域类BsDomain
// 定义进货记录类InRecord继承自BsDomain
public class InRecord extends BsDomain{
private String iNumber; // 进货编号
private int sum; // 进货数量
private Float inPrice; // 进货单价
// getiNumber方法用于获取进货编号
public String getiNumber() {
return iNumber; // 返回进货编号
}
// setiNumber方法用于设置进货编号
public void setiNumber(String iNumber) {
this.iNumber = iNumber; // 将参数iNumber赋值给成员变量iNumber
}
// getSum方法用于获取进货数量
public int getSum() {
return sum; // 返回进货数量
}
// setSum方法用于设置进货数量
public void setSum(int sum) {
this.sum = sum; // 将参数sum赋值给成员变量sum
}
// getInPrice方法用于获取进货单价
public Float getInPrice() {
return inPrice; // 返回进货单价
}
// setInPrice方法用于设置进货单价
public void setInPrice(Float inPrice) {
this.inPrice = inPrice; // 将参数inPrice赋值给成员变量inPrice
}
}

@ -0,0 +1,93 @@
package com.lingnan.supermarket.table; // 声明当前类所在的包
import java.util.List; // 导入List接口用于表示列表
import java.util.Vector; // 导入Vector类用于实现可增长的对象数组
import javax.swing.JFrame; // 导入JFrame类用于创建窗口框架
import javax.swing.table.AbstractTableModel; // 导入AbstractTableModel类用于创建表格模型
import com.lingnan.supermarket.dto.Buffer; // 导入Buffer类可能用于临时数据存储
import com.lingnan.supermarket.dto.InOrder; // 导入InOrder类表示进货订单
import com.lingnan.supermarket.dto.InRecord; // 导入InRecord类表示进货记录
import com.lingnan.supermarket.dto.Buffer; // 重复导入Buffer类可能是错误应该删除
import com.lingnan.supermarket.dto.Production; // 导入Production类表示产品
import com.lingnan.supermarket.dto.User; // 导入User类表示用户
import com.lingnan.supermarket.dao.UserService; // 导入UserService接口用于用户数据访问
import com.lingnan.supermarket.dao.impl.*; // 导入所有实现类,可能用于数据访问层的具体实现
import com.lingnan.supermarket.dialog.InDialog; // 导入InDialog类可能用于显示进货对话框
public class InRecordTM extends AbstractTableModel{ // 定义一个类继承自AbstractTableModel用于创建进货记录表格数据模型
private String [] columnName = {"订单号","id","数量","金额"}; // 定义列名数组,用于表格的列标题
private productionImpl prodDao = new productionImpl(); // 创建productionImpl实例用于操作产品数据
private Vector<InRecord> InRecords; // 声明一个Vector<InRecord>类型的变量,用于存储进货记录
private inRecordServiceImpl inRecordImpl = new inRecordServiceImpl(); // 创建inRecordServiceImpl实例用于操作进货记录数据
private InRecord inRecord= new InRecord(); // 创建InRecord实例用于存储单条进货记录
private String iNumber ;/*订单号*/ // 声明一个String变量用于存储订单号
public InRecordTM(String iNumber) { // 构造函数,接收订单号参数
this.iNumber=iNumber; // 将传入的订单号赋值给类的成员变量
}
public void findInRecordByINumber() { // 根据订单号查找进货记录的方法
//将添加的商品加入到静态变量Vector数组中
/*prod = InDialog.getProduction();*/
InRecords = inRecordImpl.findByIdinRecord(iNumber); // 根据订单号查询进货记录并赋值给InRecords
}
@Override
public int getRowCount() { // 重写方法,获取表格的行数
return InRecords.size(); // 返回InRecords的大小
}
/* public Float getAllPrice() {
return BufferImpl.InBufferAllPrice();
}
*/
@Override
public int getColumnCount() { // 重写方法,获取表格的列数
return columnName.length; // 返回columnName数组的长度
}
@Override
public Object getValueAt(int rowIndex, int columnIndex) { // 重写方法,获取指定单元格的值
inRecord = InRecords.get(rowIndex); // 获取指定行的进货记录
/* System.out.println( "id="+users.get(rowIndex).getId());
System.out.println("rowIndex"+rowIndex);
System.out.println("columnIndex"+columnIndex);*/
iNumber=inRecord.getiNumber(); // 获取订单号
if(columnIndex==0) {
return inRecord.getiNumber(); // 返回订单号
}else if(columnIndex==1) {
return inRecord.getId(); // 返回id
}else if(columnIndex==2) {
return inRecord.getSum(); // 返回数量
}else if(columnIndex==3) {
return inRecord.getInPrice(); // 返回金额
}else {
return null; // 如果列索引不匹配返回null
}
}
public String getINumber() { // 返回要修改或删除的记录的订单号
return iNumber; // 返回类的成员变量iNumber
}
@Override
public String getColumnName(int column) { // 重写方法,获取指定列的列名
return columnName[column]; // 返回columnName数组中指定索引的值
}
}

@ -0,0 +1,106 @@
package com.lingnan.supermarket.table; // 声明当前类所在的包
import java.util.List; // 导入List接口用于表示列表
import java.util.Vector; // 导入Vector类用于实现可增长的对象数组
import javax.swing.JFrame; // 导入JFrame类用于创建窗口框架
import javax.swing.table.AbstractTableModel; // 导入AbstractTableModel类用于创建表格模型
import com.lingnan.supermarket.dto.InOrder; // 导入InOrder类表示进货订单的数据传输对象
import com.lingnan.supermarket.dto.Production; // 导入Production类表示产品数据传输对象
import com.lingnan.supermarket.dto.User; // 导入User类表示用户数据传输对象
import com.lingnan.supermarket.dao.UserService; // 导入UserService接口用于用户数据访问
import com.lingnan.supermarket.dao.impl.*; // 导入所有实现类,可能用于数据访问层的具体实现
import com.lingnan.supermarket.dialog.InDialog; // 导入InDialog类可能用于显示进货对话框
public class InTableModel extends AbstractTableModel{ // 定义一个类继承自AbstractTableModel用于创建进货表格数据模型
// 定义列名数组,用于表格的列标题
private String [] columnName = {"id","名称","数量","单价","价格","保质期","类别","供应商id"};
// 创建productionImpl实例用于操作产品数据
private productionImpl prodDao = new productionImpl();
// 声明一个Vector用于存储Production对象集合
private Vector<Production> v;
// 声明一个String变量用于存储id
String id ;
// 构造函数接收一个Vector<Production>类型的参数
public InTableModel(Vector<Production> v) {
System.out.println("调用InTableModel里面的构造函数"); // 打印日志信息
this.v=v; // 将传入的Vector<Production>赋值给类的成员变量v
}
// 获取表格的行数,即数据集合的大小
public int getRowCount() {
return v.size(); // 返回Vector v的大小
}
// 计算所有商品的总价格
public Float getAllPrice() {
Float allPrice=(float) 0; // 初始化总价格为0
for(Production p:v) { // 遍历Vector v中的所有Production对象
allPrice+=p.getPrice(); // 累加每个商品的价格
}
return allPrice; // 返回计算出的总价格
}
// 重写方法,获取表格的列数,即列名数组的长度
@Override
public int getColumnCount() {
return columnName.length; // 返回columnName数组的长度
}
// 重写方法,获取指定行和列的单元格值
@Override
public Object getValueAt(int rowIndex, int columnIndex) {
Production p = v.get(rowIndex); // 从Vector v中获取指定行的Production对象
id=p.getId(); // 将Production对象的id赋值给类的成员变量id
if(columnIndex==0) { // 判断列索引,并返回相应的值
return p.getId();
}else if(columnIndex==1) {
return p.getName(); // 返回商品名称
}else if(columnIndex==2) {
return p.getSum(); // 返回商品数量
}else if(columnIndex==3) {
return p.getInPrice(); // 返回商品进货单价
}else if(columnIndex==4) {
return p.getPrice(); // 返回商品价格
}else if(columnIndex==5) {
return p.getLife(); // 返回商品保质期
}else if(columnIndex==6) {
return p.getName2()+p.getId2(); // 返回商品类别和类别id的组合
}else if(columnIndex==7) {
return p.getSupplyId(); // 返回供应商id
}else {
return null; // 如果列索引不匹配返回null
}
}
// 获取要修改或删除的记录的id
public String getId() {
return id; // 返回类的成员变量id
}
// 重写方法,获取指定列的列名
@Override
public String getColumnName(int column) {
return columnName[column]; // 返回columnName数组中指定索引的值
}
}

@ -0,0 +1,716 @@
// 定义包名表明该类属于com.lingnan.supermarket.view包
package com.lingnan.supermarket.view;
// 导入必要的Java Swing和AWT类库以及自定义的类库
import java.awt.BorderLayout;
import java.awt.Color;
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.mail.MessagingException;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.text.html.HTMLDocument.Iterator;
import com.lingnan.supermarket.componet.BGPanel;
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.prodCatalogImpl;
import com.lingnan.supermarket.dialog.ChangeStatusDialog;
import com.lingnan.supermarket.dialog.ChangeSumDialog;
import com.lingnan.supermarket.dialog.InDialog;
import com.lingnan.supermarket.dialog.UserDialog;
import com.lingnan.supermarket.dto.Buffer;
import com.lingnan.supermarket.dto.InRecord;
import com.lingnan.supermarket.dto.Production;
import com.lingnan.supermarket.dto.User;
import com.lingnan.supermarket.table.*;
import com.lingnan.supermarket.utils.CreateOrder;
import com.lingnan.supermarket.utils.FontUtil;
import com.lingnan.supermarket.utils.SendQQMailUtil;
import com.lingnan.supermarket.utils.TimeAndOrder;
import com.lingnan.supermarket.view.ProdCatalogView.MyItemListener;
// 声明InView类继承JPanel并实现ActionListener接口
public class InView extends JPanel implements ActionListener{
// 定义类的成员变量,用于构建界面元素
// 上面的工具栏面板
private JPanel toolBarPanel;
// 搜索面板
private JPanel searchPanel;
private JLabel nameLabel,locationLabel; // 标签用于显示文本
private JTextField nameSearchTF; // 文本框用于输入搜索内容
private JButton searchBtn,StockBtn,exitBtn; // 按钮用于执行操作
// 操作面板
private JPanel opePanel;
private JButton addBtn,updateBtn,deleteBtn,historyBtn,backBtn,detailBtn; // 操作按钮
// 中间的表格滚动面板
private JScrollPane tableScrollPane;
private JTable inTable; // 表格用于显示数据
// 下面的面板
private JPanel bottomPanel,bottomPanelLeft,bottomPanelRight; // 底部面板
private JLabel countInfoLabel,countInfoLabel2; // 标签用于显示统计信息
// 缓冲区相关变量
private Buffer Buffer;
private BufferImpl BufferImpl;
// 定义一个静态的Vector集合用于存储Production对象
private static Vector<Production> v = new Vector<Production>();
// 定义一个下拉框组件,用于选择不同的状态
private JComboBox<String> combo;
// 定义一个字符串数组,包含所有可能的状态选项
private String[] status ={"全部","已入库","待入库","已取消"};
// 定义一个变量,用于存储当前选中的目录
private int catalog;
// 定义一个JFrame对象用于表示主窗口
private JFrame jFrame;
// 定义一个User对象用于存储当前用户信息
private User user;
// 定义一个InTableModel对象用于管理表格数据模型
private InTableModel inTableModel ;
// 实例化BufferImpl对象用于操作缓冲区数据
private BufferImpl bufferImpl = new BufferImpl();
// 定义一个标记变量,用于区分是从进货表还是提醒过来的表
private int mark;/*标记从提醒那里来1是进货表0是提醒过来的表*/
// 定义一个inOrderServiceImpl对象用于处理进货订单服务
private inOrderServiceImpl inOrderImpl;
// 定义一个浮点数变量,用于存储总价
private Float allPrice;
// 定义一个整数变量,用于存储选中的行号
private int row;
// 定义一个字符串变量,用于存储用户名
private String uname;
// InView类的构造方法接收主窗口、用户、货物集合和标记作为参数
public InView(JFrame jFrame,User user,Vector<Production> v,int mark) {
// 设置布局管理器为边界布局
this.setLayout(new BorderLayout());
// 初始化成员变量
this.jFrame = jFrame;
this.user = user;
// 获取进货缓冲区的保存的货物并删除缓冲区
this.v =bufferImpl.allInBuffer();
bufferImpl.DelAllInBuffer();
// 初始化标记变量
this.mark=mark;
// 打印标记值,用于调试
System.out.println("mark="+mark);
// 获取并存储用户名
uname = user.getUsername();
// 初始化视图
initView();
}
// 初始化视图的方法
private void initView() {
// 创建工具栏面板,并设置布局管理器为边界布局
toolBarPanel = new JPanel(new BorderLayout());
// 创建搜索面板,并设置布局管理器为流式布局,靠右对齐
searchPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
// 创建并初始化标签,用于显示“订单号”
nameLabel = new JLabel("订单号");
// 创建并初始化文本框用于输入搜索内容宽度为20
nameSearchTF = new JTextField(20);
// 创建并初始化搜索按钮,并设置图标
searchBtn = new JButton(new ImageIcon("static\\icon\\search.png"));
// 为搜索按钮添加动作监听器
searchBtn.addActionListener(this);
// 创建并初始化位置标签,并设置字体和前景色
locationLabel=new JLabel("当前位置>进货系统");
locationLabel.setFont(new FontUtil().userFont);
locationLabel.setForeground(new Color(18, 150, 219));
// 创建并初始化下拉框,使用状态数组作为选项
combo = new JComboBox<String>(status);
// 为下拉框添加项目监听器
combo.addItemListener(new MyItemListener());
// 创建操作面板,并设置布局管理器为流式布局,靠左对齐
opePanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
// 创建并初始化添加按钮,并设置图标
addBtn =new JButton(new ImageIcon("static\\icon\\add.png"));
// 创建并初始化更新按钮,并设置图标
updateBtn =new JButton(new ImageIcon("static\\icon\\change.png"));
// 创建并初始化删除按钮,并设置图标
deleteBtn =new JButton(new ImageIcon("static\\icon\\delete.png"));
// 创建并初始化历史按钮,并设置图标
historyBtn =new JButton(new ImageIcon("static\\icon\\history.png"));
// 创建并初始化返回按钮,并设置图标
backBtn =new JButton(new ImageIcon("static\\icon\\back.png"));
// 创建并初始化详情按钮,并设置图标
detailBtn = new JButton(new ImageIcon("static\\icon\\detail.png"));
// 为添加按钮添加动作监听器
addBtn.addActionListener(this);
// 为更新按钮添加动作监听器
updateBtn.addActionListener(this);
// 为删除按钮添加动作监听器
deleteBtn.addActionListener(this);
// 为历史按钮添加动作监听器
historyBtn.addActionListener(this);
// 为返回按钮添加动作监听器
backBtn.addActionListener(this);
// 为详情按钮添加动作监听器
detailBtn.addActionListener(this);
// 设置返回按钮初始不可见,它在记录页面时才会显示
backBtn.setVisible(false);/*在记录页面显示出来*/
// 设置详情按钮初始不可见,它在订单详情页时才会显示
detailBtn.setVisible(false);/*在订单详情页显示出来*/
// 将添加按钮添加到操作面板
opePanel.add(addBtn);
// 将返回按钮添加到操作面板
opePanel.add(backBtn);
// 将详情按钮添加到操作面板
opePanel.add(detailBtn);
// 将更新按钮添加到操作面板
opePanel.add(updateBtn);
// 将删除按钮添加到操作面板
opePanel.add(deleteBtn);
// 将历史按钮添加到操作面板
opePanel.add(historyBtn);
// 将位置标签添加到搜索面板
searchPanel.add(locationLabel);
// 将订单号标签添加到搜索面板
searchPanel.add(nameLabel);
// 将搜索文本框添加到搜索面板
searchPanel.add(nameSearchTF);
// 将搜索按钮添加到搜索面板
searchPanel.add(searchBtn);
// 将状态下拉框添加到搜索面板
searchPanel.add(combo);
// 将搜索面板添加到工具栏面板的西边West
toolBarPanel.add(searchPanel,"West");
// 将操作面板添加到工具栏面板的东边East
toolBarPanel.add(opePanel,"East");
//中间表
// 创建一个表格模型并传入数据向量v
inTableModel = new InTableModel(v);
// 创建一个新的表格,使用上面创建的表格模型
inTable = new JTable(inTableModel);
// 设置表格的字体
inTable.setFont(FontUtil.tableFont);
// 设置表格的行高
inTable.setRowHeight(50);
// 创建一个滚动面板,并将表格添加到滚动面板中
tableScrollPane = new JScrollPane(inTable);
// 获取表格模型中的所有商品总价
allPrice = inTableModel.getAllPrice();
// 获取表格模型中的行数,即商品种类数量
row = inTableModel.getRowCount();
// 创建底部左侧面板,并设置布局为右对齐流式布局
bottomPanelLeft = new JPanel(new FlowLayout(FlowLayout.RIGHT));
// 创建一个标签用于显示商品种类和总价信息
countInfoLabel = new JLabel("商品种类:"+row+",总价:"+allPrice);
// 将商品信息标签添加到底部左侧面板
bottomPanelLeft.add(countInfoLabel,"Left");
// 创建底部右侧面板,并设置布局为左对齐流式布局
bottomPanelRight = new JPanel(new FlowLayout(FlowLayout.LEFT));
// 创建并初始化结账按钮,并设置图标
StockBtn =new JButton(new ImageIcon("static\\icon\\stock.png"));/*结账按钮*/
// 创建并初始化退出按钮,并设置图标
exitBtn =new JButton(new ImageIcon("static\\icon\\exit.png"));/*退出按钮*/
// 为结账按钮添加动作监听器
StockBtn.addActionListener(this);
// 为退出按钮添加动作监听器
exitBtn.addActionListener(this);
// 将结账按钮添加到底部右侧面板
bottomPanelRight.add(StockBtn);
// 将退出按钮添加到底部右侧面板
bottomPanelRight.add(exitBtn);
// 创建底部面板,并设置布局为边界布局
bottomPanel = new JPanel(new BorderLayout());
// 将底部右侧面板添加到底部面板的东边
bottomPanel.add(bottomPanelRight,"East");
// 将底部左侧面板添加到底部面板的西边
bottomPanel.add(bottomPanelLeft,"West");
// 将工具栏面板添加到窗口的北边
this.add(toolBarPanel,"North");
// 将表格滚动面板添加到窗口的中间
this.add(tableScrollPane,"Center");/*将表格放到中间*/
// 将底部面板添加到窗口的南边
this.add(bottomPanel,"South");
// 如果标记为1表示是从提醒模块过来的则刷新缓冲区
if(mark==1) /*判断是不是从提醒那里过来的*/{
refreshBuffer(v);
}
// 如果标记为0则执行进货订单记录操作
else if(mark==0) {
InOrderRecord();
}
// 设置窗口为可见状态,这样用户就可以看到并与之交互
setVisible(true);
}
// 提供一个静态方法用于获取存储Production对象的Vector集合
public static Vector<Production> getVector(){
return v;
}
// 定义一个内部类MyItemListener实现ItemListener接口来监听下拉框项目的状态改变
public class MyItemListener implements ItemListener {
// 重写itemStateChanged方法当下拉框中的项目状态改变时被调用
@Override
public void itemStateChanged(ItemEvent e) {
// 将事件源转换为JComboBox类型
JComboBox cb = (JComboBox) e.getSource();
// 获取当前选中的项目,并转换为字符串
String catalog1 = (String) cb.getSelectedItem();
// 根据选中的项目设置相应的分类代码
if(catalog1.equals("全部"))
catalog=0;
else if(catalog1.equals("已入库"))
catalog=1;
else if(catalog1.equals("待入库"))
catalog=2;
else if(catalog1.equals("已取消"))
catalog=3;
// 根据分类代码执行查找操作
resultOfFindStatus(catalog);
}
}
// 设置按钮组件的可见性
public void OrderView() {
// 设置返回按钮为可见
backBtn.setVisible(true);
// 设置详情按钮为可见
detailBtn.setVisible(true);
// 设置更新按钮为可见
updateBtn.setVisible(true);
// 设置删除按钮为可见
deleteBtn.setVisible(true);
// 设置添加按钮为不可见
addBtn.setVisible(false);
// 设置历史按钮为不可见
historyBtn.setVisible(false);
}
// 根据订单编号查询结果,并更新界面
public void resultOfNumber(String iNumber) {
// 重置标记
this.mark=0;
// 创建InOrderTM对象用于处理订单数据
InOrderTM inOrderTM = new InOrderTM();
// 根据订单编号查询结果
inOrderTM.resultOfNumber(iNumber);
// 设置表格模型为查询结果
inTable.setModel(inOrderTM);
// 清除底部左侧面板的内容
bottomPanelLeft.removeAll();
// 创建一个标签,显示记录总数
countInfoLabel = new JLabel("共"+inOrderTM.getRowCount()+"条记录");
// 将标签添加到底部左侧面板
bottomPanelLeft.add(countInfoLabel);
// 更新按钮组件的可见性
OrderView();
}
// 根据状态分类代码查询订单,并更新界面
public void resultOfFindStatus(int catalog) {
// 重置标记
this.mark=0;
// 创建InOrderTM对象用于处理订单数据
InOrderTM inOrderTM = new InOrderTM();
// 根据分类代码查询订单
inOrderTM.resultOfFind(catalog);
// 设置表格模型为查询结果
inTable.setModel(inOrderTM);
// 清除底部左侧面板的内容
bottomPanelLeft.removeAll();
// 创建一个标签,显示记录总数
countInfoLabel = new JLabel("共"+inOrderTM.getRowCount()+"条记录");
// 将标签添加到底部左侧面板
bottomPanelLeft.add(countInfoLabel);
// 更新按钮组件的可见性
OrderView();
}
// 刷新缓冲区数据,并更新界面
public void refreshBuffer(Vector<Production> v) {
// 设置标记为1表示刷新操作
this.mark=1;
// 创建InTableModel对象使用传入的Vector作为数据源
InTableModel inTableModel = new InTableModel(v);
// 设置表格模型为新的数据模型
inTable.setModel(inTableModel);
// 清除底部左侧面板的内容
bottomPanelLeft.removeAll();
// 创建一个标签,显示商品种类和总价信息
countInfoLabel = new JLabel("商品种类:"+inTableModel.getRowCount()+",总价:"+inTableModel.getAllPrice());
// 将标签添加到底部左侧面板
bottomPanelLeft.add(countInfoLabel);
// 设置按钮的可见性
backBtn.setVisible(false);
detailBtn.setVisible(false);
historyBtn.setVisible(true);
updateBtn.setVisible(true);
addBtn.setVisible(true);
deleteBtn.setVisible(true);
// 更新总价和记录数
allPrice = inTableModel.getAllPrice();
row = inTableModel.getRowCount();
}
// 调出所有进货订单记录,并更新界面
public void InOrderRecord() {
// 重置标记
this.mark=0;
// 创建InOrderTM对象用于处理订单数据
InOrderTM inOrderTM = new InOrderTM();
// 获取所有进货订单记录
inOrderTM.allInOrderRecord();
// 设置表格模型为所有订单记录
inTable.setModel(inOrderTM);
// 清除底部左侧面板的内容
bottomPanelLeft.removeAll();
// 创建一个标签,显示记录总数
countInfoLabel = new JLabel("共"+inOrderTM.getRowCount()+"条记录");
// 将标签添加到底部左侧面板
bottomPanelLeft.add(countInfoLabel);
// 更新按钮组件的可见性
OrderView();
}
// 根据订单编号查询进货记录,并更新界面
public void InRecord(String iNumber) {
// 设置标记为2表示按订单编号查询
this.mark=2;
// 创建InRecordTM对象使用订单编号作为查询条件
InRecordTM inRecordTM = new InRecordTM(iNumber);
// 查询进货记录
inRecordTM.findInRecordByINumber();
// 设置表格模型为查询结果
inTable.setModel(inRecordTM);
// 清除底部左侧面板的内容
bottomPanelLeft.removeAll();
// 创建一个标签,显示订单号和记录总数
countInfoLabel = new JLabel("订单号@"+iNumber+"共有"+inRecordTM.getRowCount()+"条记录");
// 将标签添加到底部左侧面板
bottomPanelLeft.add(countInfoLabel);
// 更新按钮的可见性
backBtn.setVisible(true);
detailBtn.setVisible(false);
updateBtn.setVisible(false);
addBtn.setVisible(false);
historyBtn.setVisible(false);
deleteBtn.setVisible(false);
}
/*按钮监听时间*/
@Override
public void actionPerformed(ActionEvent e) {
// 创建购物车实例
BufferImpl = new BufferImpl();/*获得购物车*/
// 获取事件源对象
Object source = e.getSource();
// 如果事件源是搜索按钮
if(searchBtn==source) {
// 从搜索文本框中获取订单号
String number = nameSearchTF.getText();
// 打印搜索后的订单号
System.out.println("搜索后的订单:"+number);
// 根据订单号进行搜索并处理结果
resultOfNumber(number);
}
// 如果事件源是添加按钮
else if(addBtn==source) {
// 创建添加对话框实例,并传入窗口框架、向量数据、用户信息
InDialog outDialog = new InDialog(jFrame,v,user);
// 设置对话框为可见
outDialog.setVisible(true);
// 获取对话框返回的向量数据
v=outDialog.getVector();
// 刷新购物车数据
refreshBuffer(v);
}
else if(updateBtn==source) { /*更新*/
// 打印当前操作标记值
System.out.println("mark="+mark);
// 获取表格中被选中的行索引
int rowIndex = inTable.getSelectedRow();
// 如果没有行被选中,弹出提示对话框并返回
if(rowIndex==-1) {
JOptionPane.showMessageDialog(this,"请选中一条进行更改数量");
return;
}
// 如果标记值为1表示当前操作是进货表修改
if(mark==1) {
// 从选中的行中获取ID
String id =(String) inTable.getValueAt(rowIndex,0);
// 创建修改数量的对话框实例,并传入相关参数
ChangeSumDialog changesumDialog = new ChangeSumDialog(jFrame,id,"In",v);
// 设置对话框为可见
changesumDialog.setVisible(true);
// 获取对话框返回的向量数据
v = changesumDialog.getVector();
// 打印更改状态后向量的大小
System.out.println("更改状态后v.size="+v.size());
// 刷新缓冲区数据
refreshBuffer(v);
}
//inOrder修改,修改状态
else if(mark==0) {
// 从选中的行中获取订单编号
String iNumber =(String) inTable.getValueAt(rowIndex,0);
// 从选中的行中获取订单状态
String status =(String) inTable.getValueAt(rowIndex,4);
// 如果订单状态为"已入库",则弹出提示信息并返回
if(status.equals("已入库")) {
JOptionPane.showMessageDialog(this,"订单上的货物已入库无法修改状态","提示",JOptionPane.INFORMATION_MESSAGE);
return;
}
// 创建修改状态对话框实例,并传入相关参数
ChangeStatusDialog changeStatusDialog = new ChangeStatusDialog(jFrame,iNumber,status);
// 设置对话框为可见
changeStatusDialog.setVisible(true);
// 刷新主界面提醒
MainView.refreshRemind();
// 刷新首页
HomeView.refreshHome();
// 重新加载订单记录
InOrderRecord();
}
}
else if(deleteBtn==source) {
// 获取表格中被选中的行索引
int rowIndex = inTable.getSelectedRow();
// 如果没有行被选中,弹出提示对话框并返回
if(rowIndex==-1) {
JOptionPane.showMessageDialog(this,"请选中一条");
return;
}
/*删除进货表的*/
if(mark==1) {
// 打印日志信息,表示将删除进货表中的记录
System.out.println("删除进货表");
// 从选中的行中获取记录的ID
String id =(String) inTable.getValueAt(rowIndex,0);
// 弹出确认对话框询问用户是否删除指定ID的记录
int select = JOptionPane.showConfirmDialog(this,"是否删除id为"+id+"的记录","提示",JOptionPane.YES_NO_OPTION);
// 如果用户选择"是",则执行删除操作
if(select==JOptionPane.YES_OPTION) {/*选择是*/
// 遍历向量v寻找匹配的ID进行删除
for(int i =0;i<v.size();i++) {
// 打印日志信息,表示开始删除操作
System.out.println("开始删除");
// 如果找到匹配的ID则从向量中移除该元素
if(v.elementAt(i).getId().equals(id))
{
v.remove(i);
// 弹出提示对话框,表示删除成功
JOptionPane.showMessageDialog(this,"删除成功","提示",JOptionPane.INFORMATION_MESSAGE);
break;
}
}
// 刷新缓冲区数据
refreshBuffer(v);
}
}
// 删除进货订单
else if(mark==0) {
// 打印日志信息,表示将删除订单表中的记录
System.out.println("删除订单表");
// 从选中的行中获取订单编号
String iNumber =(String) inTable.getValueAt(rowIndex,0);
// 弹出确认对话框,询问用户是否删除指定订单编号的记录
int select = JOptionPane.showConfirmDialog(this,"是否删除订单为"+iNumber+"的记录","提示",JOptionPane.YES_NO_OPTION);
// 如果用户选择"是",则执行删除操作
if(select==JOptionPane.YES_OPTION) {/*选择是*/
// 打印订单编号
System.out.println("iNumber="+iNumber);
// 创建订单服务实现类实例
inOrderImpl=new inOrderServiceImpl();
// 调用删除订单的方法
inOrderImpl.deleteInOrder(iNumber);
// 弹出提示对话框,表示删除成功
JOptionPane.showMessageDialog(this,"删除成功","提示",JOptionPane.INFORMATION_MESSAGE);
// 重新加载订单记录
InOrderRecord();
}
}
}else if(historyBtn==source) {/*查看历史全部记录*/
// 调用方法加载所有订单记录
InOrderRecord();
}else if(backBtn==source) {/*历史记录中的返回按钮*/
// 如果标记为0则刷新缓冲区数据
if(mark==0)
refreshBuffer(v);
// 如果标记为2则重新加载订单记录
else if(mark==2)
InOrderRecord();
}else if(detailBtn==source) {/*查看订单详细*/
// 获取表格中被选中的行索引
int rowIndex = inTable.getSelectedRow();
// 如果没有行被选中,弹出提示对话框并返回
if(rowIndex==-1) {
JOptionPane.showMessageDialog(this,"请选中一条查看订单详细信息");
return;
}
// 从选中的行中获取订单编号
String iNumber =(String) inTable.getValueAt(rowIndex,0);
// 打印订单编号,用于调试
System.out.println("详情订单号为="+iNumber);
// 调用方法查看指定订单编号的详细信息
InRecord(iNumber);
}
else if(StockBtn==source) {/*结账*/
// 刷新缓冲区数据
refreshBuffer(v);
// 如果购物车为空,则弹出提示对话框
if(v.size()==0)/*购物车为空*/{
JOptionPane.showMessageDialog(null,"您的进货页面为空", "提示", JOptionPane.YES_OPTION);
}
else {/*购物车不为空*/
// 弹出确认对话框,显示总金额和负责人信息,并询问是否提交订单
int res = JOptionPane.showConfirmDialog(null,"进价总金额:"+allPrice+"元\r\n负责人:"+uname+"\r\n发送邮件至 re@qq.com", "提交订单", JOptionPane.YES_NO_OPTION);
if(res==JOptionPane.YES_OPTION)/*如果已经结账*/{
// 获取当前时间和订单号s[0]为订单号s[1]为时间
String[] s =TimeAndOrder.TimeAndOrder(uname);
// 往订单表插入一条记录
inOrderServiceImpl inOrderImpl = new inOrderServiceImpl();
inOrderImpl.InsertInOrder(s[0], allPrice, s[1],uname ,2);
// 往inRecord表添加数据
inRecordServiceImpl inRecordImpl = new inRecordServiceImpl();
for(Production p:v) {/*往inRecord表添加数据*/
inRecordImpl.insertInRecord(s[0], p);
}
// 生成订单文本
CreateOrder createOrder = new CreateOrder();
String OrderText = createOrder.CreateOrder(v, s[0], s[1], allPrice,uname);
try {/*发送邮件*/
SendQQMailUtil QQEmail = new SendQQMailUtil("sender@qq.com","自行获取 SMTP 授权码","receiver@qq.com","@新民超市进货需求申请",OrderText);
} catch (MessagingException e1) {
// 异常处理,打印堆栈跟踪
e1.printStackTrace();
}
// 清空购物车并刷新缓冲区
v=new Vector<Production>();
refreshBuffer(v);
// 刷新主界面提醒
MainView.refreshRemind();
// 弹出提示对话框,显示邮件发送成功和订单信息
JOptionPane.showConfirmDialog(null,"发送邮件成功\r\n订单号:"+s[0]+"\r\n负责人:"+uname, "提示", JOptionPane.YES_OPTION);
}
}
}else if(exitBtn==source) {
// 弹出确认对话框,询问是否退出并清空购物车
int res = JOptionPane.showConfirmDialog(null,"确定退出并清空购物车吗", "结账", JOptionPane.YES_NO_OPTION);
if(res==JOptionPane.YES_OPTION)/*如果退出*/{
// 将购物车数组置空并刷新缓冲区
v=new Vector<Production>();/*将数组置空*/
refreshBuffer(v);
// 弹出提示对话框,显示退出成功
JOptionPane.showConfirmDialog(null,"退出成功", "提示", JOptionPane.PLAIN_MESSAGE);
}
}
}
}

@ -0,0 +1,702 @@
package com.lingnan.supermarket.view; // 定义包名,所有视图相关的类都在这个包下
import java.awt.event.ActionEvent; // 导入ActionEvent类用于监听动作事件
import java.awt.event.ActionListener; // 导入ActionListener接口用于实现动作事件监听
import java.awt.event.MouseEvent; // 导入MouseEvent类用于监听鼠标事件
import java.awt.event.MouseListener; // 导入MouseListener接口用于实现鼠标事件监听
import java.awt.event.WindowEvent; // 导入WindowEvent类用于监听窗口事件
import java.awt.event.WindowListener; // 导入WindowListener接口用于实现窗口事件监听
import java.io.File; // 导入File类用于文件操作
import java.io.IOException; // 导入IOException类用于处理输入输出异常
import java.util.Date; // 导入Date类用于处理日期
import java.util.Random; // 导入Random类用于生成随机数
import java.util.Vector; // 导入Vector类用于实现动态数组
import javax.imageio.ImageIO; // 导入ImageIO类用于图像输入输出
import javax.swing.ImageIcon; // 导入ImageIcon类用于显示图片
import javax.swing.JButton; // 导入JButton类用于创建按钮
import javax.swing.JLabel; // 导入JLabel类用于创建标签
import javax.swing.JMenu; // 导入JMenu类用于创建菜单
import javax.swing.JMenuBar; // 导入JMenuBar类用于创建菜单栏
import javax.swing.JMenuItem; // 导入JMenuItem类用于创建菜单项
import javax.swing.JOptionPane; // 导入JOptionPane类用于显示对话框
import javax.swing.JPanel; // 导入JPanel类用于创建面板
import javax.swing.JSplitPane; // 导入JSplitPane类用于创建分隔面板
import javax.swing.Timer; // 导入Timer类用于实现定时器
import com.lingnan.supermarket.componet.BGPanel; // 导入自定义的BGPanel类
import com.lingnan.supermarket.dao.impl.BufferImpl; // 导入BufferImpl类可能是数据访问层的实现
import com.lingnan.supermarket.dao.impl.inOrderServiceImpl; // 导入inOrderServiceImpl类可能是订单服务的实现
import com.lingnan.supermarket.dialog.CloseDialog; // 导入CloseDialog类可能是关闭对话框
import com.lingnan.supermarket.dialog.InDialog; // 导入InDialog类可能是入库对话框
import com.lingnan.supermarket.dialog.UserDialog; // 导入UserDialog类可能是用户对话框
import com.lingnan.supermarket.dialog.UserInfDialog; // 导入UserInfDialog类可能是用户信息对话框
import com.lingnan.supermarket.dto.InOrder; // 导入InOrder类可能是订单数据传输对象
import com.lingnan.supermarket.dto.Production; // 导入Production类可能是产品数据传输对象
import com.lingnan.supermarket.dto.User; // 导入User类可能是用户数据传输对象
import com.lingnan.supermarket.utils.DateUtil; // 导入DateUtil类可能是日期工具类
import com.lingnan.supermarket.utils.FontUtil; // 导入FontUtil类可能是字体工具类
import com.lingnan.supermarket.view.base.BaseView; // 导入BaseView类可能是视图基类
import java.awt.*; // 导入awt包中的所有类
// 主视图类继承自BaseView并实现多个事件监听接口
public class MainView extends BaseView implements ActionListener, MouseListener,WindowListener{
JMenuBar menuBar; // 声明菜单栏变量
JMenu settingMenu,helpMenu; // 声明设置菜单和帮助菜单变量
JMenuItem skinMenuItem,configMenuItem; // 声明皮肤菜单项和配置菜单项变量
JSplitPane containerPanel; // 声明分隔面板变量,用于左右布局
CardLayout rightPanelLayout; // 声明卡片布局管理器变量,用于右侧面板
JPanel leftPanel,rightPanel; // 声明左侧和右侧面板变量
/*菜单栏组件*/
JLabel logoLabel,userMenuLabel1,homeMenuLabel,userMenuLabel,inMenuLabel,
outMenuLabel,storageMenuLabel,supplierMenuLabel,catalogMenuLabel;
// 声明菜单栏中各个标签的变量
static JLabel remindMenuLabel;/*声明静态标签变量,用于全局调用刷新*/
JPanel bottomPanel; // 声明底部面板变量
JLabel timeLabel; // 声明时间标签变量
JPanel purposePanel,timePanel; // 声明目的面板和时间面板变量
JLabel purposeLabel; // 声明目的标签变量
JButton saveBtn,unSaveBtn,cancleBtn;/*退出时按钮*/
//
Timer timer; // 声明定时器变量,用于执行周期性任务
private User user ;/*从登录界面传过来的用户信息,用于当前视图的用户上下文*/
private BufferImpl bufferImpl; // 声明BufferImpl对象可能是用于缓存处理的实现
private Image bgImage ; // 声明背景图片变量
private String iconSkin; // 声明图标皮肤路径变量
private int skin; // 声明皮肤编号变量
private Vector<Production> vP=new Vector<Production>() ;/*用于进货缓存,存储产品信息*/
private int location; // 声明位置变量,可能用于记录当前视图的状态或位置
private int sSuper=-1;//界面权限,用于标识用户权限级别
private static inOrderServiceImpl inOrderImpl = new inOrderServiceImpl(); // 声明并实例化订单服务实现类
private static int unConfirmmark;/*未确认订单的数量*/
// 构造方法,接收用户信息、皮肤编号和图标皮肤路径
public MainView(User user,int skin,String iconSkin) {
super(1300,850,"新民超市管理系统欢迎您",user,skin); // 调用父类构造方法,设置窗口大小、标题、用户信息和皮肤
timer = new Timer(1000,this); // 创建定时器每1000毫秒执行一次
timer.start(); // 启动定时器
this.user = user; // 保存用户信息到当前视图
this.sSuper=user.getUsuper();//界面权限,从用户信息中获取权限级别
System.out.println("userid="+user.getId()); // 打印用户ID
this.addWindowListener(this); // 为当前窗口添加窗口事件监听器
this.skin = skin; // 保存皮肤编号
this.iconSkin = iconSkin; // 保存图标皮肤路径
ImageIcon icon=new ImageIcon(iconSkin); // 创建ImageIcon对象加载图标皮肤
this.setIconImage(icon.getImage()); // 设置窗口图标
// 获得未进货的信息
Vector<InOrder> vInOrder;
vInOrder = inOrderImpl.findUnconfirmInOrder(); // 查找未确认的订单
unConfirmmark=vInOrder.size(); // 设置未确认订单的数量
initView(user,skin); // 初始化视图
}
// 另一个构造方法,只接收用户信息
public MainView(User user) {
super(1300,850,"新民超市管理系统欢迎您"); // 调用父类构造方法,设置窗口大小和标题
timer = new Timer(1000,this); // 创建定时器每1000毫秒执行一次
timer.start(); // 启动定时器
this.user = user; // 保存用户信息到当前视图
this.sSuper=user.getUsuper();//界面权限,从用户信息中获取权限级别
System.out.println("userid="+user.getId()); // 打印用户ID
this.addWindowListener(this); // 为当前窗口添加窗口事件监听器
// 获得未进货的信息
Vector<InOrder> vInOrder;
vInOrder = inOrderImpl.findUnconfirmInOrder(); // 查找未确认的订单
unConfirmmark=vInOrder.size(); // 设置未确认订单的数量
initView(user,skin); // 初始化视图这里没有为skin赋值可能会出错
}
public static void refreshRemind() {
Vector<InOrder> vInOrder; // 声明未确认订单的向量
vInOrder = inOrderImpl.findUnconfirmInOrder(); // 查找所有未确认的订单
unConfirmmark = vInOrder.size(); // 获取未确认订单的数量
remindMenuLabel.setText("待确认进货:" + unConfirmmark); // 更新菜单标签,显示未确认订单的数量
}
// 以下是注释掉的代码,没有实现功能
/* public static User getUserInf() {
return user; // 返回用户信息
}*/
@Override
protected void initView(User user, int skin) {
// 初始化视图的方法,接收用户信息和皮肤编号
/*菜单栏*/
menuBar = new JMenuBar(); // 创建菜单栏
settingMenu = new JMenu("设置"); // 创建设置菜单
helpMenu = new JMenu("帮助"); // 创建帮助菜单
skinMenuItem = new JMenuItem("随机切换皮肤", new ImageIcon("static\\icon\\skin.png")); // 创建切换皮肤的菜单项
/*for
for(int i = 3;i<9;i++) {
}*/
configMenuItem = new JMenuItem("参数设置", new ImageIcon("static\\icon\\setting.png")); // 创建参数设置的菜单项
skinMenuItem.addActionListener(this); // 为切换皮肤菜单项添加动作监听器
settingMenu.add(configMenuItem); // 将参数设置菜单项添加到设置菜单
settingMenu.add(skinMenuItem); // 将切换皮肤菜单项添加到设置菜单
menuBar.add(settingMenu); // 将设置菜单添加到菜单栏
menuBar.add(helpMenu); // 将帮助菜单添加到菜单栏
setJMenuBar(menuBar); // 将菜单栏设置到当前窗口
/*左边菜单栏设置*/
try {
bgImage = ImageIO.read(new File("static\\bg\\bg" + skin + ".jpg")); // 读取背景图片
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace(); // 打印异常堆栈信息
}
leftPanel = new BGPanel(bgImage); /*皮肤*/ // 创建带有背景的左边面板
leftPanel.setLayout(null); // 设置左边面板布局为空,即绝对布局
/*菜单栏:用户登录信息*/
System.out.println("用户头像地址==" + user.getImg()); // 打印用户头像地址
JLabel logoLabel = new JLabel(new ImageIcon(user.getImg()), JLabel.LEFT); // 创建用户头像标签
System.out.println(user.getImg()); // 再次打印用户头像地址
leftPanel.add(logoLabel); // 将用户头像标签添加到左边面板
logoLabel.setBounds(25, 30, 150, 150); // 设置用户头像标签的位置和大小
/*账号名字*/
String x = UsuperIcon(user.getUsuper()); /*判断权限返回icon地址*/ // 根据用户权限返回相应的图标地址
System.out.println("身份地址:" + x); // 打印身份图标地址
userMenuLabel1 = new JLabel("|" + user.getUsername() + "|" + user.getRname(), new ImageIcon(x), JLabel.LEFT); // 创建用户信息标签
userMenuLabel1.setFont(FontUtil.userFont); // 设置用户信息标签的字体
userMenuLabel1.addMouseListener(this); // 为用户信息标签添加鼠标监听器
userMenuLabel1.setBounds(20, 170, 180, 32); // 设置用户信息标签的位置和大小
userMenuLabel1.setForeground(Color.white); // 设置用户信息标签的前景色为白色
leftPanel.add(userMenuLabel1); /*添加用户选项到菜单栏*/ // 将用户信息标签添加到左边面板
/*菜单栏:首页*/
homeMenuLabel = new JLabel("新民首页", new ImageIcon("static\\icon\\home1.png"), JLabel.LEFT); // 创建一个带有图标的JLabel用于表示首页菜单
homeMenuLabel.setFont(FontUtil.menuFont); // 设置菜单标签的字体样式
homeMenuLabel.addMouseListener(this); // 为菜单标签添加鼠标事件监听器
homeMenuLabel.setBounds(20, 250, 150, 32); // 设置菜单标签的位置和大小
homeMenuLabel.setForeground(Color.white); // 设置菜单标签的前景色为白色
leftPanel.add(homeMenuLabel); // 将首页菜单标签添加到左侧面板
/*菜单栏:人员管理*/
userMenuLabel = new JLabel("人员管理", new ImageIcon("static\\icon\\user1.png"), JLabel.LEFT); // 创建一个带有图标的JLabel用于表示人员管理菜单
userMenuLabel.setFont(FontUtil.menuFont); // 设置菜单标签的字体样式
userMenuLabel.addMouseListener(this); // 为菜单标签添加鼠标事件监听器
userMenuLabel.setBounds(20, 300, 150, 32); // 设置菜单标签的位置和大小
userMenuLabel.setForeground(Color.white); // 设置菜单标签的前景色为白色
leftPanel.add(userMenuLabel); // 将人员管理菜单标签添加到左侧面板
/*菜单栏:进货系统*/
inMenuLabel = new JLabel("进货系统", new ImageIcon("static\\icon\\in1.png"), JLabel.LEFT); // 创建一个带有图标的JLabel用于表示进货系统菜单
inMenuLabel.setFont(FontUtil.menuFont); // 设置菜单标签的字体样式
inMenuLabel.addMouseListener(this); // 为菜单标签添加鼠标事件监听器
inMenuLabel.setBounds(20, 350, 150, 32); // 设置菜单标签的位置和大小
inMenuLabel.setForeground(Color.white); // 设置菜单标签的前景色为白色
leftPanel.add(inMenuLabel); // 将进货系统菜单标签添加到左侧面板
/*菜单栏:收银系统*/
outMenuLabel = new JLabel("收银系统", new ImageIcon("static\\icon\\out1.png"), JLabel.LEFT); // 创建一个带有图标的JLabel用于表示收银系统菜单
outMenuLabel.setFont(FontUtil.menuFont); // 设置菜单标签的字体样式
outMenuLabel.addMouseListener(this); // 为菜单标签添加鼠标事件监听器
outMenuLabel.setBounds(20, 400, 150, 32); // 设置菜单标签的位置和大小
outMenuLabel.setForeground(Color.white); // 设置菜单标签的前景色为白色
leftPanel.add(outMenuLabel); // 将收银系统菜单标签添加到左侧面板
/*菜单栏:库存*/
storageMenuLabel = new JLabel("商品库存", new ImageIcon("static\\icon\\storage1.png"), JLabel.LEFT); // 创建一个带有图标的JLabel用于表示商品库存菜单
storageMenuLabel.setFont(FontUtil.menuFont); // 设置菜单标签的字体样式
storageMenuLabel.addMouseListener(this); // 为菜单标签添加鼠标事件监听器
storageMenuLabel.setBounds(20, 450, 150, 32); // 设置菜单标签的位置和大小
storageMenuLabel.setForeground(Color.white); // 设置菜单标签的前景色为白色
leftPanel.add(storageMenuLabel); // 将商品库存菜单标签添加到左侧面板
/*菜单栏:供应商*/
supplierMenuLabel = new JLabel("供应商", new ImageIcon("static\\icon\\supplier1.png"), JLabel.LEFT); // 创建一个带有图标的JLabel用于表示供应商菜单
supplierMenuLabel.setFont(FontUtil.menuFont); // 设置菜单标签的字体样式
supplierMenuLabel.addMouseListener(this); // 为菜单标签添加鼠标事件监听器
supplierMenuLabel.setBounds(20, 500, 150, 32); // 设置菜单标签的位置和大小
supplierMenuLabel.setForeground(Color.white); // 设置菜单标签的前景色为白色
leftPanel.add(supplierMenuLabel); // 将供应商菜单标签添加到左侧面板
/*菜单栏:商品目录*/
catalogMenuLabel = new JLabel("商品目录", new ImageIcon("static\\icon\\catalog1.png"), JLabel.LEFT); // 创建一个带有图标的JLabel用于表示商品目录菜单
catalogMenuLabel.setFont(FontUtil.menuFont); // 设置菜单标签的字体样式
catalogMenuLabel.addMouseListener(this); // 为菜单标签添加鼠标事件监听器
catalogMenuLabel.setBounds(20, 550, 150, 32); // 设置菜单标签的位置和大小
catalogMenuLabel.setForeground(Color.white); // 设置菜单标签的前景色为白色
leftPanel.add(catalogMenuLabel); // 将商品目录菜单标签添加到左侧面板
/*提醒进货确认模块*/
remindMenuLabel = new JLabel("待确认进货:"+unConfirmmark, new ImageIcon("static\\icon\\remind1.png"), JLabel.LEFT); // 创建一个带有图标的JLabel用于显示待确认进货的数量
remindMenuLabel.setFont(FontUtil.remindFont); // 设置提醒菜单标签的字体样式
remindMenuLabel.addMouseListener(this); // 为提醒菜单标签添加鼠标事件监听器
remindMenuLabel.setBounds(0, 650, 200, 32); // 设置提醒菜单标签的位置和大小
remindMenuLabel.setForeground(Color.white); // 设置提醒菜单标签的前景色为白色
leftPanel.add(remindMenuLabel); // 将提醒菜单标签添加到左侧面板
// 设置右侧面板的布局管理器为卡片布局
rightPanelLayout = new CardLayout();
// 0.超市首页展示,创建并实例化首页视图面板
JPanel homePanel = new HomeView(this);
// 1.用户管理界面:用户的列表,创建并实例化用户管理视图面板
JPanel userPanel = new UserView(this);
// 2.进货系统界面,创建并实例化进货系统视图面板
JPanel inPanel = new InView(this, user, vP, 1);
// 3.收银系统界面,创建并实例化收银系统视图面板
JPanel outPanel = new OutView(this, user);
// 4.库存系统界面,创建并实例化库存系统视图面板
JPanel storagePanel = new StorageView(this);
// 5.供应商界面,创建并实例化供应商视图面板
JPanel supplierPanel = new SupplierView(this);
// 6.商品目录界面,创建并实例化商品目录视图面板
JPanel ProdCatalogPanel = new ProdCatalogView(this);
// 7.超市总览界面,创建并实例化超市总览视图面板
JPanel superPanel = new SuperView(this);
// 8.进货信息提示界面,创建并实例化进货信息提示视图面板
JPanel inPanel2 = new InView(this, user, vP, 0);
// 创建右侧面板并设置布局管理器为之前定义的卡片布局
rightPanel = new JPanel(rightPanelLayout);
rightPanel.add(homePanel, "0"); // 添加首页视图面板并设置其索引为"0"
rightPanel.add(userPanel, "1"); // 添加用户管理视图面板并设置其索引为"1"
rightPanel.add(inPanel, "2"); // 添加进货系统视图面板并设置其索引为"2"
rightPanel.add(outPanel, "3"); // 添加收银系统视图面板并设置其索引为"3"
rightPanel.add(storagePanel, "4"); // 添加库存系统视图面板并设置其索引为"4"
rightPanel.add(supplierPanel, "5"); // 添加供应商视图面板并设置其索引为"5"
rightPanel.add(ProdCatalogPanel, "6"); // 添加商品目录视图面板并设置其索引为"6"
rightPanel.add(superPanel, "7"); // 添加超市总览视图面板并设置其索引为"7"
rightPanel.add(inPanel2, "8"); // 添加进货信息提示视图面板并设置其索引为"8"
// 创建一个分割面板,将左侧面板和右侧面板水平分割
containerPanel = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, leftPanel, rightPanel);
containerPanel.setDividerLocation(180); // 设置分割线的位置
containerPanel.setDividerSize(0); // 设置分割线的尺寸为0即隐藏分割线
// 创建底部面板,默认使用流式布局
bottomPanel = new JPanel();
bottomPanel.setBackground(Color.WHITE); // 设置底部面板的背景色为白色
bottomPanel.setLayout(new BorderLayout()); // 设置底部面板的布局管理器为边界布局
// 创建目的地区面板,用于显示当前位置信息
purposePanel = new JPanel();
purposePanel.setLayout(new FlowLayout(FlowLayout.LEFT)); // 设置目的地区面板的布局管理器为左对齐的流式布局
purposePanel.setBackground(Color.WHITE); // 设置目的地区面板的背景色为白色
purposeLabel = new JLabel("当前位置是:超市首页"); // 创建标签显示当前位置信息
purposePanel.add(purposeLabel); // 将位置信息标签添加到目的地区面板
// 创建一个新的 JPanel 实例用于显示时间
timePanel=new JPanel();
// 设置 timePanel 的布局为 FlowLayout并指定元素靠右对齐
timePanel.setLayout(new FlowLayout(FlowLayout.TRAILING));
// 设置 timePanel 的背景颜色为白色
timePanel.setBackground(Color.WHITE);
// 创建一个新的 JLabel 实例,显示当前日期和时间,使用 DateUtil 工具类进行格式化
timeLabel = new JLabel(DateUtil.dateToString(new Date(),null));
// 将 timeLabel 添加到 timePanel 中
timePanel.add(timeLabel);
// 将 purposePanel 添加到 bottomPanel 的西边West
bottomPanel.add(purposePanel,"West");
// 将 timePanel 添加到 bottomPanel 的东边East
bottomPanel.add(timePanel,"East");
// 获取当前窗口的内容窗格
Container container = getContentPane();
// 将 containerPanel 添加到内容窗格的中心Center
container.add(containerPanel,"Center");
// 将 bottomPanel 添加到内容窗格的南边South
container.add(bottomPanel,"South");
}
@Override
// 定义当触发动作事件时的处理方法
public void actionPerformed(ActionEvent e) {
// 获取触发事件的源对象
Object source = e.getSource();
// 更新时间标签以显示当前时间
timeLabel.setText(DateUtil.dateToString(new Date(),null));
// 检查事件源是否为皮肤菜单项,如果是则进行换肤操作
if(source==skinMenuItem)/*换肤*/{
// 打印换肤操作信息到控制台
System.out.println("切换皮肤");
// 创建一个新的随机数生成器实例
Random random=new Random();
// 生成一个0到9之间的随机数作为皮肤编号
skin=random.nextInt(10);
// 销毁当前窗口
this.dispose();
// 创建并显示一个新的主视图窗口,传入用户信息、皮肤编号和图标皮肤
new MainView(user,skin,iconSkin);
}
}
@Override/*左侧菜单栏点击事件*/
// 定义当鼠标点击事件发生时的处理方法
public void mouseClicked(MouseEvent e) {
// 获取触发事件的源对象
Object source = e.getSource();
// 检查事件源是否为首页菜单标签,如果是则显示对应的面板
if(source==homeMenuLabel) {
rightPanelLayout.show(rightPanel,"0"); // 显示首页面板
location=0; // 更新当前位置索引为0
}
// 检查事件源是否为用户菜单标签,根据权限显示不同面板
else if(source==userMenuLabel) {
if(sSuper==0) // 如果权限为0
rightPanelLayout.show(rightPanel,"1"); // 显示用户面板1
else{ // 如果权限不为0
rightPanelLayout.show(rightPanel,"7"); // 显示用户面板7
}
location=1; // 更新当前位置索引为1
}
// 检查事件源是否为入库菜单标签,根据权限显示不同面板
else if(source==inMenuLabel) {
if(sSuper==2) // 如果权限为2
rightPanelLayout.show(rightPanel,"7"); // 显示面板7
else{ // 如果权限不为2
rightPanelLayout.show(rightPanel,"2"); // 显示入库面板
}
location=2; // 更新当前位置索引为2
}
// 检查事件源是否为出库菜单标签,如果是则显示对应的面板
else if(source==outMenuLabel) {
rightPanelLayout.show(rightPanel,"3"); // 显示出库面板
location=3; // 更新当前位置索引为3
}
// 检查事件源是否为库存菜单标签,如果是则显示对应的面板
else if(source==storageMenuLabel) {
rightPanelLayout.show(rightPanel,"4"); // 显示库存面板
location=4; // 更新当前位置索引为4
}
// 检查事件源是否为供应商菜单标签,如果是则显示对应的面板
else if(source==supplierMenuLabel) {
rightPanelLayout.show(rightPanel,"5"); // 显示供应商面板
location=5; // 更新当前位置索引为5
}
// 检查事件源是否为目录菜单标签,如果是则显示对应的面板
else if(source==catalogMenuLabel) {
rightPanelLayout.show(rightPanel,"6"); // 显示目录面板
location=6; // 更新当前位置索引为6
}
// 检查事件源是否为提醒菜单标签,根据权限显示不同面板
else if(source==remindMenuLabel) {
if(sSuper==2) // 如果权限为2
rightPanelLayout.show(rightPanel,"7"); // 显示面板7
else{ // 如果权限不为2
rightPanelLayout.show(rightPanel,"8"); // 显示提醒面板
}
location=7; // 更新当前位置索引为7
}
// 检查事件源是否为用户信息菜单标签1如果是则显示用户信息对话框
else if(source==userMenuLabel1){
UserInfDialog userInfDialog = new UserInfDialog(this,user); // 创建用户信息对话框
userInfDialog.setVisible(true); // 显示用户信息对话框
location=8; // 更新当前位置索引为8
}
// 调用refreshRemove方法可能用于刷新界面或执行其他操作
refreshRemove();
}
//获取当前位置
// 定义一个方法用于刷新和移除面板内容
public void refreshRemove(){
// 从目的面板中移除所有组件
purposePanel.removeAll();
// 根据当前的位置索引设置不同的目的标签文本
if(location==0){
purposeLabel = new JLabel("当前位置是:"+homeMenuLabel.getText()); // 设置当前位置为首页
}
else if(location==1){
purposeLabel = new JLabel("当前位置是:"+userMenuLabel.getText()); // 设置当前位置为用户菜单
}
else if(location==2){
purposeLabel = new JLabel("当前位置是:"+inMenuLabel.getText()); // 设置当前位置为入库菜单
}
else if(location==3){
purposeLabel = new JLabel("当前位置是:"+outMenuLabel.getText()); // 设置当前位置为出库菜单
}
else if(location==4){
purposeLabel = new JLabel("当前位置是:"+storageMenuLabel.getText()); // 设置当前位置为库存菜单
}
else if(location==5){
purposeLabel = new JLabel("当前位置是:"+supplierMenuLabel.getText()); // 设置当前位置为供应商菜单
}
else{
purposeLabel = new JLabel("当前位置是:"+catalogMenuLabel.getText()); // 设置当前位置为目录菜单
}
// 将新的目的标签添加到目的面板
purposePanel.add(purposeLabel);
// 可能需要调用重新绘制界面或更新界面显示的方法,但这里没有显示出来
}
@Override
public void mousePressed(MouseEvent e) {
// TODO Auto-generated method stub
}
@Override
public void mouseReleased(MouseEvent e) {
// TODO Auto-generated method stub
}
@Override/*鼠标焦点时*/
// 重写鼠标进入组件事件的处理方法
public void mouseEntered(MouseEvent e) {
// 获取触发事件的源对象
Object source = e.getSource();
// 如果事件源是首页菜单标签,则改变前景色和图标
if(source==homeMenuLabel) {
homeMenuLabel.setForeground(new Color(18, 150, 219)); // 设置前景色为蓝色
homeMenuLabel.setIcon(new ImageIcon("static\\icon\\home2.png")); // 设置鼠标进入时的图标
}
// 如果事件源是用户菜单标签,则改变前景色和图标
if(source==userMenuLabel) {
userMenuLabel.setForeground(new Color(18, 150, 219)); // 设置前景色为蓝色
userMenuLabel.setIcon(new ImageIcon("static\\icon\\user2.png")); // 设置鼠标进入时的图标
}
// 如果事件源是入库菜单标签,则改变前景色和图标
else if(source==inMenuLabel) {
inMenuLabel.setForeground(new Color(18, 150, 219)); // 设置前景色为蓝色
inMenuLabel.setIcon(new ImageIcon("static\\icon\\in2.png")); // 设置鼠标进入时的图标
}
// 如果事件源是出库菜单标签,则改变前景色和图标
else if(source==outMenuLabel) {
outMenuLabel.setForeground(new Color(18, 150, 219)); // 设置前景色为蓝色
outMenuLabel.setIcon(new ImageIcon("static\\icon\\out2.png")); // 设置鼠标进入时的图标
}
// 如果事件源是库存菜单标签,则改变前景色和图标
else if(source==storageMenuLabel) {
storageMenuLabel.setForeground(new Color(18, 150, 219)); // 设置前景色为蓝色
storageMenuLabel.setIcon(new ImageIcon("static\\icon\\storage2.png")); // 设置鼠标进入时的图标
}
// 如果事件源是供应商菜单标签,则改变前景色和图标
else if(source==supplierMenuLabel) {
supplierMenuLabel.setForeground(new Color(18, 150, 219)); // 设置前景色为蓝色
supplierMenuLabel.setIcon(new ImageIcon("static\\icon\\supplier2.png")); // 设置鼠标进入时的图标
}
// 如果事件源是目录菜单标签,则改变前景色和图标
else if(source==catalogMenuLabel) {
catalogMenuLabel.setForeground(new Color(18, 150, 219)); // 设置前景色为蓝色
catalogMenuLabel.setIcon(new ImageIcon("static\\icon\\catalog2.png")); // 设置鼠标进入时的图标
}
// 如果事件源是用户菜单标签1则改变前景色
else if(source==userMenuLabel1) {
userMenuLabel1.setForeground(new Color(18, 150, 219)); // 设置前景色为蓝色
// 注意:这里没有设置图标,可能是因为该标签没有对应的鼠标进入图标
}
// 方法结束,没有设置图标的变化,只是改变了前景色
}
@Override
// 重写鼠标离开组件事件的处理方法
public void mouseExited(MouseEvent e) {
// 获取触发事件的源对象
Object source = e.getSource();
// 如果事件源是首页菜单标签,则恢复前景色和图标
if(source==homeMenuLabel) {
homeMenuLabel.setForeground(Color.white); // 恢复前景色为白色
homeMenuLabel.setIcon(new ImageIcon("static\\icon\\home1.png")); // 设置鼠标离开时的默认图标
}
// 如果事件源是用户菜单标签,则恢复前景色和图标
else if(source==userMenuLabel) {
userMenuLabel.setForeground(Color.white); // 恢复前景色为白色
userMenuLabel.setIcon(new ImageIcon("static\\icon\\user1.png")); // 设置鼠标离开时的默认图标
}
// 如果事件源是入库菜单标签,则恢复前景色和图标
else if(source==inMenuLabel) {
inMenuLabel.setForeground(Color.white); // 恢复前景色为白色
inMenuLabel.setIcon(new ImageIcon("static\\icon\\in1.png")); // 设置鼠标离开时的默认图标
}
// 如果事件源是出库菜单标签,则恢复前景色和图标
else if(source==outMenuLabel) {
outMenuLabel.setForeground(Color.white); // 恢复前景色为白色
outMenuLabel.setIcon(new ImageIcon("static\\icon\\out1.png")); // 设置鼠标离开时的默认图标
}
// 如果事件源是库存菜单标签,则恢复前景色和图标
else if(source==storageMenuLabel) {
storageMenuLabel.setForeground(Color.white); // 恢复前景色为白色
storageMenuLabel.setIcon(new ImageIcon("static\\icon\\storage1.png")); // 设置鼠标离开时的默认图标
}
// 如果事件源是供应商菜单标签,则恢复前景色和图标
else if(source==supplierMenuLabel) {
supplierMenuLabel.setForeground(Color.white); // 恢复前景色为白色
supplierMenuLabel.setIcon(new ImageIcon("static\\icon\\supplier1.png")); // 设置鼠标离开时的默认图标
}
// 如果事件源是目录菜单标签,则恢复前景色和图标
else if(source==catalogMenuLabel) {
catalogMenuLabel.setForeground(Color.white); // 恢复前景色为白色
catalogMenuLabel.setIcon(new ImageIcon("static\\icon\\catalog1.png")); // 设置鼠标离开时的默认图标
}
// 如果事件源不是上述任何一个标签则默认处理用户菜单标签1
else {
userMenuLabel1.setForeground(Color.white); // 恢复前景色为白色
// 注意:这里没有设置图标,可能是因为该标签没有对应的鼠标离开图标
}
// 方法结束,所有菜单标签的前景色和图标已根据鼠标离开事件进行了相应的恢复
}
@Override
protected void initView() {
// TODO Auto-generated method stub
}
@Override
public void windowOpened(WindowEvent e) {
// TODO Auto-generated method stub
}
@Override
// 重写窗口关闭事件的处理方法
public void windowClosing(WindowEvent e) {
// TODO Auto-generated method stub
// 获取触发事件的源对象
Object source = e.getSource();
// 如果事件源是当前窗口对象,执行以下操作
if(source==this) {
// 关闭窗口时检查进货系统和出货系统是否还有记录
this.vP =InView.getVector(); // 获取进货系统的记录向量
System.out.println("v的size="+vP.size()); // 打印进货系统记录的数量
bufferImpl = new BufferImpl(); // 创建缓冲区实现对象
// 如果进货系统的购物车还有记录或者出货系统的缓冲区还有记录
if(vP.size()!=0||bufferImpl.allOutBuffer().size()!=0) {
// 如果购物车还有记录,则显示关闭确认对话框
CloseDialog closeDialog = new CloseDialog(this,vP); // 创建关闭对话框
closeDialog.setVisible(true); // 显示关闭对话框
} else {
// 如果没有记录,则直接退出程序
System.exit(0); // 安全退出程序
}
}
// 方法结束,窗口关闭事件已处理
}
@Override
public void windowClosed(WindowEvent e) {
// TODO Auto-generated method stub
}
@Override
public void windowIconified(WindowEvent e) {
// TODO Auto-generated method stub
}
@Override
public void windowDeiconified(WindowEvent e) {
// TODO Auto-generated method stub
}
@Override
public void windowActivated(WindowEvent e) {
// TODO Auto-generated method stub
}
@Override
public void windowDeactivated(WindowEvent e) {
// TODO Auto-generated method stub
}
}

@ -0,0 +1,25 @@
package com.lingnan.supermarket.dto; // 声明当前类所在的包
// 定义产品目录类ProdCatalog
public class ProdCatalog {
private String id; // 产品目录ID
private String name; // 产品目录名称
// getId方法用于获取产品目录ID
public String getId() {
return id; // 返回产品目录ID
}
// setId方法用于设置产品目录ID
public void setId(String id) {
this.id = id; // 将参数id赋值给成员变量id
}
// getName方法用于获取产品目录名称
public String getName() {
return name; // 返回产品目录名称
}
// setName方法用于设置产品目录名称
public void setName(String name) {
this.name = name; // 将参数name赋值给成员变量name
}
}

@ -0,0 +1,69 @@
package com.lingnan.supermarket.table; // 声明当前类所在的包
import java.util.List; // 导入List接口用于表示列表
import java.util.Vector; // 导入Vector类用于实现可增长的对象数组
import javax.swing.table.AbstractTableModel; // 导入AbstractTableModel类用于创建表格模型
import com.lingnan.supermarket.dto.Production; // 导入Production类表示产品数据传输对象
import com.lingnan.supermarket.dto.User; // 导入User类表示用户数据传输对象
import com.lingnan.supermarket.dao.UserService; // 导入UserService接口用于用户数据访问
import com.lingnan.supermarket.dao.impl.*; // 导入所有实现类,可能用于数据访问层的具体实现
public class ProdCatalogTM extends AbstractTableModel{ // 定义一个类继承自AbstractTableModel用于产品目录的表格数据模型
private String [] columnName = {"类别id","类别名称","商品id","商品名称"}; // 定义列名数组,用于表格的列标题
private productionImpl prodDao = new productionImpl(); // 创建productionImpl实例用于操作产品数据
private Vector<Production> prods; // 声明一个Vector用于存储产品列表
public void all() {
// 查找全部数据
prods = prodDao.findAllproduction(); // 调用findAllproduction方法获取所有产品数据
}
public void ById2(Production p) {
// 根据类别id查找数据
prods = prodDao.findProductionById2(p.getId2()); // 调用findProductionById2方法根据类别id获取产品数据
}
@Override
public int getRowCount() {
return prods.size(); // 返回产品列表的大小,即表格的行数
}
@Override
public int getColumnCount() {
return columnName.length; // 返回列名数组的长度,即表格的列数
}
@Override
public Object getValueAt(int rowIndex, int columnIndex) {
Production prod = prods.get(rowIndex); // 获取指定行的产品对象
// 以下注释掉的是打印语句,用于调试
/*System.out.println( "id="+users.get(rowIndex).getId());
System.out.println("rowIndex"+rowIndex);
System.out.println("columnIndex"+columnIndex);*/
if(columnIndex==0) {
return prod.getId2(); // 返回类别id
}else if(columnIndex==1) {
return prod.getName2(); // 返回类别名称
}else if(columnIndex==2) {
return prod.getId(); // 返回商品id
}else if(columnIndex==3) {
return prod.getName(); // 返回商品名称
}else {
return null; // 如果列索引不匹配返回null
}
}
@Override
public String getColumnName(int column) {
return columnName[column]; // 返回指定列的列名
}
}

@ -0,0 +1,200 @@
package com.lingnan.supermarket.view; // 定义包名表示这个类属于com.lingnan.supermarket.view包
import java.awt.BorderLayout; // 导入BorderLayout布局管理器类
import java.awt.Color; // 导入Color类用于定义颜色
import java.awt.FlowLayout; // 导入FlowLayout布局管理器类
import java.awt.event.ActionEvent; // 导入ActionEvent类用于处理按钮点击等事件
import java.awt.event.ActionListener; // 导入ActionListener接口用于实现事件监听
import java.awt.event.ItemEvent; // 导入ItemEvent类用于处理下拉框选择事件
import java.awt.event.ItemListener; // 导入ItemListener接口用于实现下拉框事件监听
import java.util.ArrayList; // 导入ArrayList类用于存储动态数组
import javax.swing.ImageIcon; // 导入ImageIcon类用于显示图片
import javax.swing.JButton; // 导入JButton类用于创建按钮
import javax.swing.JComboBox; // 导入JComboBox类用于创建下拉框
import javax.swing.JFrame; // 导入JFrame类用于创建窗口框架
import javax.swing.JLabel; // 导入JLabel类用于创建标签
import javax.swing.JPanel; // 导入JPanel类用于创建面板
import javax.swing.JScrollPane; // 导入JScrollPane类用于创建滚动面板
import javax.swing.JTable; // 导入JTable类用于创建表格
import javax.swing.JTextField; // 导入JTextField类用于创建文本框
import com.lingnan.supermarket.dao.impl.prodCatalogImpl; // 导入prodCatalogImpl类用于操作商品目录数据
import com.lingnan.supermarket.dialog.UserDialog; // 导入UserDialog类用于显示用户对话框
import com.lingnan.supermarket.dto.ProdCatalog; // 导入ProdCatalog类用于表示商品目录数据传输对象
import com.lingnan.supermarket.dto.Production; // 导入Production类用于表示产品数据传输对象
import com.lingnan.supermarket.dto.User; // 导入User类用于表示用户数据传输对象
import com.lingnan.supermarket.table.ProdCatalogTM; // 导入ProdCatalogTM类用于表示商品目录表格模型
import com.lingnan.supermarket.table.StorageTableModel; // 导入StorageTableModel类用于表示库存表格模型
import com.lingnan.supermarket.table.UserTableModel; // 导入UserTableModel类用于表示用户表格模型
import com.lingnan.supermarket.utils.FontUtil; // 导入FontUtil类用于字体工具类
public class ProdCatalogView extends JPanel { // 定义ProdCatalogView类继承自JPanel
// 上面
private JPanel toolBarPanel; // 工具栏面板
private JPanel searchPanel; // 搜索面板
private JLabel logLabel, locationLabel; // 标签,用于显示文本
private JTextField nameSearchTF; // 文本框,用于输入搜索内容
private JButton searchBtn; // 搜索按钮
private JPanel opePanel; // 操作面板
private JButton addBtn, updateBtn, deleteBtn; // 添加、更新、删除按钮
private String catalog = "0"; // 商品目录ID
private JComboBox<String> combo; // 下拉框,用于选择商品目录
private String log[]=null; // 商品目录名称数组
private ArrayList<String>alog=null; // 商品目录名称列表
private ProdCatalogTM prodCatalogTM; // 商品目录表格模型
private ProdCatalog pc; // 商品目录数据传输对象
private prodCatalogImpl pci; // 商品目录数据操作实现类
// 中间
private JScrollPane tableScrollPane; // 表格滚动面板
private JTable prodCatalogTable; // 商品目录表格
// 下面
private JPanel bottomPanel; // 底部面板
private JLabel countInfoLabel; // 标签,用于显示记录总数
private JFrame jFrame; // 窗口框架
// 构造方法接收一个JFrame参数
public ProdCatalogView(JFrame jFrame) {
this.setLayout(new BorderLayout()); // 设置面板布局为BorderLayout
initView(); // 初始化视图
this.jFrame = jFrame; // 保存传入的JFrame实例
}
private void initView() {
// 初始化视图方法
toolBarPanel = new JPanel(new BorderLayout()); // 创建工具栏面板并设置布局为BorderLayout
searchPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); // 创建搜索面板并设置布局为左对齐的FlowLayout
locationLabel = new JLabel("商品目录"); // 创建商品目录标签并设置文本
locationLabel.setFont(new FontUtil().userFont); // 设置标签字体
locationLabel.setForeground(new Color(18, 150, 219)); // 设置标签前景色
logLabel = new JLabel("分类"); // 创建分类标签并设置文本
nameSearchTF = new JTextField(10); // 创建文本框并设置大小
searchBtn = new JButton("搜索", new ImageIcon("static\\icon\\search.png")); // 创建搜索按钮并设置图标和文本
// 创建操作面板和按钮,并设置图标(注释部分,未使用)
// opePanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
// addBtn = new JButton(new ImageIcon("static\\icon\\add.png"));
// updateBtn = new JButton(new ImageIcon("static\\icon\\update.png"));
// deleteBtn = new JButton(new ImageIcon("static\\icon\\delete.png"));
// 为按钮添加事件监听(注释部分,未使用)
// addBtn.addActionListener(this);
// updateBtn.addActionListener(this);
// deleteBtn.addActionListener(this);
// 将按钮添加到操作面板(注释部分,未使用)
// opePanel.add(addBtn);
// opePanel.add(updateBtn);
// opePanel.add(deleteBtn);
pci=new prodCatalogImpl(); // 创建商品目录数据操作实现类实例
this.alog=pci.findNameProdCatalog(); // 查找所有商品目录名称
this.log=new String[alog.size()]; // 创建字符串数组以存储商品目录名称
for(int i=0;i<alog.size();i++)
log[i]=alog.get(i); // 将商品目录名称填充到数组
for(int i=0;i<log.length;i++)
{
System.out.println(log[i]); // 打印所有商品目录名称
}
combo = new JComboBox<String>(log); // 创建下拉框并设置选项
combo.addItemListener(new MyItemListener()); // 为下拉框添加事件监听器
searchPanel.add(locationLabel); // 将商品目录标签添加到搜索面板
searchPanel.add(logLabel); // 将分类标签添加到搜索面板
searchPanel.add(combo); // 将下拉框添加到搜索面板
/*
* searchPanel.add(nameSearchTF); // 将文本框添加到搜索面板(注释部分,未使用)
* searchPanel.add(searchBtn); // 将搜索按钮添加到搜索面板(注释部分,未使用)
*/
toolBarPanel.add(searchPanel, "West"); // 将搜索面板添加到工具栏面板的西边
// toolBarPanel.add(opePanel, "East"); // 将操作面板添加到工具栏面板的东边(注释部分,未使用)
// 中间表格
prodCatalogTM = new ProdCatalogTM(); // 创建商品目录表格模型
prodCatalogTM.all(); // 加载所有商品目录数据
prodCatalogTable = new JTable(prodCatalogTM); // 创建表格并设置模型
prodCatalogTable.setFont(FontUtil.tableFont); // 设置表格字体
prodCatalogTable.setRowHeight(50); // 设置表格行高
tableScrollPane = new JScrollPane(prodCatalogTable); // 创建滚动面板并添加表格
// 下面
bottomPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); // 创建底部面板并设置布局为左对齐的FlowLayout
countInfoLabel = new JLabel("总共" + prodCatalogTable.getRowCount() + "条"); // 创建记录数标签并设置文本
bottomPanel.add(countInfoLabel); // 将记录数标签添加到底部面板
this.add(toolBarPanel, "North"); // 将工具栏面板添加到面板的北边
this.add(tableScrollPane, "Center"); /* 将表格放到中间 */ // 将表格滚动面板添加到面板的中间
this.add(bottomPanel, "South"); // 将底部面板添加到面板的南边
setVisible(true); // 设置面板为可见
}
// @Override
// public void actionPerformed(ActionEvent e) {
// Object source = e.getSource();
// if (addBtn == source) { // 如果事件源是添加按钮
// UserDialog userDialog = new UserDialog(jFrame); // 创建用户对话框
// userDialog.setVisible(true); // 设置用户对话框为可见
// } else if (updateBtn == source) { // 如果事件源是更新按钮
// // 更新按钮的事件处理代码(未实现)
// } else if (deleteBtn == source) { // 如果事件源是删除按钮
// // 删除按钮的事件处理代码(未实现)
// }
// }
public class MyItemListener implements ItemListener { // 创建一个内部类实现ItemListener接口
@Override
public void itemStateChanged(ItemEvent e) { // 重写itemStateChanged方法
JComboBox cb = (JComboBox) e.getSource(); // 获取事件源下拉框
String catalog1 = (String) cb.getSelectedItem(); // 获取选中的商品目录名称
pci =new prodCatalogImpl(); // 创建商品目录数据操作实现类实例
for(int i=0;i<log.length;i++){ // 遍历商品目录数组
if(catalog1.equals(log[i])) // 如果选中的商品目录名称与数组中的名称匹配
catalog=pci.findProdCatalogByname(catalog1); // 查找对应的商品目录
System.out.println(catalog); // 打印商品目录信息
}
refreshFindId2(); // 刷新界面
}
}
// 刷新当前界面
public void refreshFindId2() {
Production p = new Production(); // 创建Production对象
p.setId2(catalog); // 设置Production对象的ID2
prodCatalogTM = new ProdCatalogTM(); // 创建商品目录表格模型
prodCatalogTM.ById2(p); // 根据ID2查询商品目录数据
prodCatalogTable.setModel(prodCatalogTM); // 更新表格模型
// 同时更新下面的记录数
refreshCount(); // 刷新记录数
}
public void refreshCount() {
bottomPanel.removeAll(); // 清空底部面板
countInfoLabel = new JLabel("总共" + prodCatalogTM.getRowCount() + "条"); // 创建新的记录数标签
bottomPanel.add(countInfoLabel); // 将记录数标签添加到底部面板
}
}

@ -0,0 +1,320 @@
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.ArrayList; // 导入ArrayList类
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.JTextField; // 导入Swing的文本框组件
import com.lingnan.supermarket.*; // 导入supermarket包下的所有类
import com.lingnan.supermarket.dao.SupplierInfService; // 导入供应商信息服务接口
import com.lingnan.supermarket.dao.productionService; // 导入产品服务接口
import com.lingnan.supermarket.dao.impl.SupplierInfImpl; // 导入供应商信息服务的实现类
import com.lingnan.supermarket.dao.impl.prodCatalogImpl; // 导入产品目录服务的实现类
import com.lingnan.supermarket.dao.impl.productionImpl; // 导入产品服务的实现类
import com.lingnan.supermarket.dto.ProdCatalog; // 导入产品目录数据传输对象
import com.lingnan.supermarket.dto.Production; // 导入产品数据传输对象
import com.lingnan.supermarket.dto.SupplierInf; // 导入供应商信息数据传输对象
import com.lingnan.supermarket.table.ProdCatalogTM; // 导入产品目录表格模型
import com.lingnan.supermarket.view.StorageView; // 导入库存视图
import com.lingnan.supermarket.view.SupplierView; // 导入供应商视图
import com.lingnan.supermarket.view.ProdCatalogView.MyItemListener; // 导入产品目录视图的内部类MyItemListener
public class ProductionDialog extends JDialog implements ActionListener { // 定义一个对话框类ProductionDialog继承自JDialog并实现ActionListener接口
private JPanel namePanel, addressPanel, contactPanel, // 声明多个面板变量
opePanel,idPanel,inpricePanel,outpricePanel,lifePanel, // 用于不同信息的布局
sumPanel,supplyidPanel,id2Panel,name2Panel; //
private JLabel nameLabel, addressLabel, contactLabel, // 声明多个标签变量
idLabel,inpriceLabel,outpriceLabel,lifeLabel,sumLabel, // 用于显示不同信息的标签
supplyidLabel,id2Label,name2Label; //
private JTextField nameTF, addressTF, contactTF, // 声明多个文本框变量
idTF,inpriceTF,outpriceTF,lifeTF,sumTF, // 用于输入不同信息
supplyidTF,id2TF,name2TF; //
private JButton saveBtn, cancelBtn; // 声明保存和取消按钮变量
private productionService productionService = new productionImpl(); // 实例化产品服务
// 下拉类别相关变量
private String log[]=null; // 用于存储类别信息的数组
private ArrayList<String>alog=null; // 用于存储类别信息的列表
private ProdCatalogTM prodCatalogTM; // 产品目录表格模型
private ProdCatalog pc; // 产品目录数据传输对象
private prodCatalogImpl pci; // 产品目录服务实现类
private JComboBox<String> combo; // 下拉框组件
private String id2; // 产品目录ID
private String name2; // 产品目录名称
// 下拉供应商类别相关变量
private String superlier[]=null; // 用于存储供应商信息的数组
private ArrayList<String>asuperlier=null; // 用于存储供应商信息的列表
private SupplierInf si; // 供应商信息数据传输对象
private SupplierInfImpl sii; // 供应商信息服务实现类
private JComboBox<String> combo1; // 供应商下拉框组件
private int supplyid; // 供应商ID
private StorageView storageView; // 库存视图引用
private Production production; // 产品数据传输对象
public ProductionDialog(JFrame parent) { // 构造函数,接收一个父窗口作为参数
super(parent, "添加"); // 调用父类构造函数,设置对话框标题为"添加"
setSize(350, 500); // 设置对话框大小
setLocationRelativeTo(null); // 设置对话框相对于屏幕居中
setModal(true); // 设置对话框为模态
setResizable(false); // 设置对话框不可调整大小
this.setLayout(new FlowLayout()); // 设置对话框布局为流式布局
initView(); // 初始化视图
}
private void initView() { // 初始化视图的方法
idPanel = new JPanel(); // 创建一个面板用于显示商品编号
idLabel = new JLabel("商品编号"); // 创建一个标签显示"商品编号"
idTF = new JTextField(15); // 创建一个文本框用于输入商品编号宽度为15
idPanel.add(idLabel); // 将标签添加到面板
idPanel.add(idTF); // 将文本框添加到面板
namePanel = new JPanel(); // 创建一个面板用于显示名称
nameLabel = new JLabel("名称"); // 创建一个标签显示"名称"
nameTF = new JTextField(15); // 创建一个文本框用于输入名称宽度为15
namePanel.add(nameLabel); // 将标签添加到面板
namePanel.add(nameTF); // 将文本框添加到面板
inpricePanel = new JPanel(); // 创建一个面板用于显示进货单价
inpriceLabel = new JLabel("进货单价"); // 创建一个标签显示"进货单价"
inpriceTF = new JTextField(15); // 创建一个文本框用于输入进货单价宽度为15
inpricePanel.add(inpriceLabel); // 将标签添加到面板
inpricePanel.add(inpriceTF); // 将文本框添加到面板
outpricePanel = new JPanel(); // 创建一个面板用于显示购买单价
outpriceLabel = new JLabel("购买单价"); // 创建一个标签显示"购买单价"
outpriceTF = new JTextField(15); // 创建一个文本框用于输入购买单价宽度为15
outpricePanel.add(outpriceLabel); // 将标签添加到面板
outpricePanel.add(outpriceTF); // 将文本框添加到面板
lifePanel = new JPanel(); // 创建一个面板用于显示保质期
lifeLabel = new JLabel("保质期(月份数)"); // 创建一个标签显示"保质期(月份数)"
lifeTF = new JTextField(15); // 创建一个文本框用于输入保质期宽度为15
lifePanel.add(lifeLabel); // 将标签添加到面板
lifePanel.add(lifeTF); // 将文本框添加到面板
sumPanel = new JPanel(); // 创建一个面板用于显示库存
sumLabel = new JLabel("库存"); // 创建一个标签显示"库存"
sumTF = new JTextField(15); // 创建一个文本框用于输入库存数量宽度为15
sumPanel.add(sumLabel); // 将标签添加到面板
sumPanel.add(sumTF); // 将文本框添加到面板
//供应商名下拉框 传递supplyid
supplyidPanel = new JPanel(); // 创建一个面板用于显示供应商信息
supplyidLabel = new JLabel("供应商"); // 创建一个标签显示"供应商"
//supplyidTF = new JTextField(15); // 注释掉的代码原本可能是用于输入供应商ID的文本框
sii=new SupplierInfImpl(); // 创建供应商信息服务的实例
this.asuperlier=sii.findNameSupplier(); // 获取所有供应商名称的列表
this.superlier=new String[asuperlier.size()]; // 创建一个字符串数组用于存储供应商名称
for(int i=0;i<asuperlier.size();i++)
superlier[i]=asuperlier.get(i); // 将供应商名称填充到字符串数组中
for(int i=0;i<superlier.length;i++)
{
System.out.println(superlier[i]); // 打印供应商名称,用于调试
}
combo1 = new JComboBox<String>(superlier); // 创建一个下拉框组件,用于选择供应商
combo1.addItemListener(new MyItemListener1()); // 为下拉框添加项目监听器
supplyidPanel.add(supplyidLabel); // 将标签添加到面板
supplyidPanel.add(combo1); // 将下拉框添加到面板
/* id2Panel = new JPanel();
id2Label = new JLabel("分类id");
id2TF = new JTextField(id2,15);
id2Panel.add(id2Label);
id2Panel.add(id2TF);*/
//类名下拉框
name2Panel = new JPanel(); // 创建一个面板用于显示类名
name2Label = new JLabel("类名"); // 创建一个标签显示"类名"
pci=new prodCatalogImpl(); // 创建产品目录服务的实例
this.alog=pci.findNameProdCatalog(); // 获取所有产品目录名称的列表
this.log=new String[alog.size()]; // 创建一个字符串数组用于存储产品目录名称
for(int i=0;i<alog.size();i++)
log[i]=alog.get(i); // 将产品目录名称填充到字符串数组中
combo = new JComboBox<String>(log); // 创建一个下拉框组件,用于选择产品目录
combo.addItemListener(new MyItemListener()); // 为下拉框添加项目监听器
name2Panel.add(name2Label); // 将标签添加到面板
name2Panel.add(combo); // 将下拉框添加到面板
addressPanel = new JPanel(); // 创建一个面板用于显示地址
addressLabel = new JLabel("地址"); // 创建一个标签显示"地址"
addressTF = new JTextField(15); // 创建一个文本框用于输入地址宽度为15
addressPanel.add(addressLabel); // 将标签添加到面板
addressPanel.add(addressTF); // 将文本框添加到面板
contactPanel = new JPanel(); // 创建一个面板用于显示联系方式
contactLabel = new JLabel("电话"); // 创建一个标签显示"电话"
contactTF = new JTextField(15); // 创建一个文本框用于输入电话宽度为15
contactPanel.add(contactLabel); // 将标签添加到面板
contactPanel.add(contactTF); // 将文本框添加到面板
opePanel = new JPanel(); // 创建一个面板用于显示操作按钮
saveBtn = new JButton("保存"); // 创建一个保存按钮
cancelBtn = new JButton("取消"); // 创建一个取消按钮
saveBtn.addActionListener(this); // 为保存按钮添加动作监听器
cancelBtn.addActionListener(this); // 为取消按钮添加动作监听器
opePanel.add(saveBtn); // 将保存按钮添加到面板
opePanel.add(cancelBtn); // 将取消按钮添加到面板
Container container = getContentPane(); // 获取对话框的内容面板
container.add(idPanel); // 将商品编号面板添加到内容面板
container.add(namePanel); // 将名称面板添加到内容面板
container.add(inpricePanel); // 将进货单价面板添加到内容面板
container.add(outpricePanel); // 将购买单价面板添加到内容面板
container.add(lifePanel); // 将保质期面板添加到内容面板
container.add(sumPanel); // 将库存面板添加到内容面板
container.add(supplyidPanel); // 将供应商面板添加到内容面板
//container.add(id2Panel); // 注释掉的代码原本可能是用于添加分类ID面板
container.add(name2Panel); // 将类名面板添加到内容面板
container.add(opePanel); // 将操作按钮面板添加到内容面板
}
@Override
public void actionPerformed(ActionEvent e) { // 实现ActionListener接口的actionPerformed方法
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) { // 如果production对象为空表示是添加新商品
if(supplyid==-1){ // 如果供应商ID为-1表示商品检索出错
JOptionPane.showMessageDialog(this, "商品检索出错", "提示",
JOptionPane.ERROR_MESSAGE); // 显示错误消息
return; // 退出方法
}
if(supplyid==0){ // 如果供应商ID为0表示未选择商品名
JOptionPane.showMessageDialog(this, "请选择商品名", "提示",
JOptionPane.ERROR_MESSAGE); // 显示错误消息
return; // 退出方法
}
if(id2.equals("0")){ // 如果分类ID为"0",表示未选择商品类
JOptionPane.showMessageDialog(this, "请选择商品类", "提示",
JOptionPane.ERROR_MESSAGE); // 显示错误消息
return; // 退出方法
}
Production production = new Production(); // 创建新的Production对象
production.setId(id); // 设置商品编号
production.setName(name); // 设置商品名称
production.setInPrice(inprice); // 设置进货单价
production.setOutPrice(outprice); // 设置销售单价
production.setLife(life); // 设置保质期
production.setSum(sum); // 设置库存
production.setSupplyId(supplyid); // 设置供应商ID
production.setId2(id2); // 设置分类ID
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){ // 如果返回值为2表示已存在该商品
JOptionPane.showMessageDialog(this, "已存在该商品", "提示",
JOptionPane.ERROR_MESSAGE); // 显示错误消息
}
else { // 如果添加失败
JOptionPane.showMessageDialog(this, "出错!添加失败", "提示",
JOptionPane.ERROR_MESSAGE); // 显示错误消息
}
}/*else{
//更新
SupplierInf supplierInf= new SupplierInf();
supplierInf.setName(name);
supplierInf.setAddress(address);
supplierInf.setContact(contact);
supplierInf.setId(this.supplierInf.getId());
int result = supplierInfService.updateSupplierInf(supplierInf);
if(result==1){
JOptionPane.showMessageDialog(this, "更新成功", "提示",
JOptionPane.INFORMATION_MESSAGE);
}
}*/
} else if (source == cancelBtn) { // 如果事件源是取消按钮
this.dispose(); // 关闭对话框
}
}
// 定义一个内部类MyItemListener实现ItemListener接口
public class MyItemListener implements ItemListener {
@Override
public void itemStateChanged(ItemEvent e) { // 实现itemStateChanged方法
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); // 通过名称查找商品分类ID
}
}
}
// 定义另一个内部类MyItemListener1实现ItemListener接口
public class MyItemListener1 implements ItemListener {
@Override
public void itemStateChanged(ItemEvent e) { // 实现itemStateChanged方法
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); // 通过名称查找供应商ID
}
}
}
}

@ -0,0 +1,46 @@
package com.lingnan.supermarket.dto; // 声明当前类所在的包
import java.util.Date; // 导入Date类用于处理日期和时间
import com.lingnan.supermarket.dto.base.BsDomain; // 导入基础域类BsDomain
// 定义存储记录类StorageRecord继承自BsDomain
public class StorageRecord extends BsDomain{
private String theNumber; // 存储记录编号
private String cDate; // 记录创建日期
private int num; // 存储数量
private String execute; // 执行操作(可能是执行人或者操作类型)
// getTheNumber方法用于获取存储记录编号
public String getTheNumber() {
return theNumber; // 返回存储记录编号
}
// setTheNumber方法用于设置存储记录编号
public void setTheNumber(String theNumber) {
this.theNumber = theNumber; // 将参数theNumber赋值给成员变量theNumber
}
// getcDate方法用于获取记录创建日期
public String getcDate() {
return cDate; // 返回记录创建日期
}
// setcDate方法用于设置记录创建日期
public void setcDate(String cDate) {
this.cDate = cDate; // 将参数cDate赋值给成员变量cDate
}
// getNum方法用于获取存储数量
public int getNum() {
return num; // 返回存储数量
}
// setNum方法用于设置存储数量
public void setNum(int num) {
this.num = num; // 将参数num赋值给成员变量num
}
// getExecute方法用于获取执行操作
public String getExecute() {
return execute; // 返回执行操作
}
// setExecute方法用于设置执行操作
public void setExecute(String execute) {
this.execute = execute; // 将参数execute赋值给成员变量execute
}
}

@ -0,0 +1,75 @@
package com.lingnan.supermarket.table; // 声明当前类所在的包
import java.util.Vector; // 导入Vector类用于实现可增长的对象数组
import javax.swing.table.AbstractTableModel; // 导入AbstractTableModel类用于创建表格模型
import com.lingnan.supermarket.dao.impl.storageRecordImpl; // 导入storageRecordImpl类可能是用于操作存储记录的数据访问实现
import com.lingnan.supermarket.dto.StorageRecord; // 导入StorageRecord类表示存储记录的数据传输对象
public class StorageRecordTM extends AbstractTableModel{ // 定义一个类继承自AbstractTableModel用于存储存储记录的表格数据模型
private String [] columnName = {"订单号","操作时间","商品编号","进货+/出货-","数量"}; // 定义列名数组,用于表格的列标题
private storageRecordImpl srDao = new storageRecordImpl(); // 创建storageRecordImpl实例用于操作存储记录的数据访问
private Vector<StorageRecord> storageRecords; // 声明一个Vector用于存储存储记录列表
private StorageRecord storageRecord ; // 声明一个StorageRecord对象用于存储单条记录
String oNumber ;/*订单号*/ // 声明一个字符串变量,用于存储订单号
public void allStoragrRecord() { // 定义一个方法,用于获取所有存储记录
//将添加的商品加入到静态变量Vector数组中
/*prod = InDialog.getProduction();*/
storageRecords = srDao.findAllStorageRecord(); // 调用srDao的方法获取所有存储记录并赋值给storageRecords
}
@Override
public int getRowCount() { // 重写getRowCount方法返回表格的行数
return storageRecords.size(); // 返回storageRecords的大小即记录的数量
}
/* public Float getAllPrice() {
return BufferImpl.InBufferAllPrice();
}*/
@Override
public int getColumnCount() { // 重写getColumnCount方法返回表格的列数
return columnName.length; // 返回columnName数组的长度即列的数量
}
@Override
public Object getValueAt(int rowIndex, int columnIndex) { // 重写getValueAt方法返回指定单元格的值
storageRecord = storageRecords.get(rowIndex); // 获取指定行的存储记录
/* System.out.println( "id="+users.get(rowIndex).getId());
System.out.println("rowIndex"+rowIndex);
System.out.println("columnIndex"+columnIndex);*/
oNumber=storageRecord.getTheNumber(); // 获取订单号并赋值给oNumber
if(columnIndex==0) {
return storageRecord.getTheNumber(); // 返回订单号
}else if(columnIndex==1) {
return storageRecord.getcDate(); // 返回操作时间
}else if(columnIndex==2) {
return storageRecord.getId(); // 返回商品编号
}else if(columnIndex==3) {
return storageRecord.getExecute(); // 返回进货/出货操作
}else if(columnIndex==4) {
return storageRecord.getNum(); // 返回数量
}else {
return null; // 如果列索引不匹配返回null
}
}
@Override
public String getColumnName(int column) { // 重写getColumnName方法返回指定列的列名
return columnName[column]; // 返回columnName数组中指定索引的值
}
}

@ -0,0 +1,74 @@
package com.lingnan.supermarket.table; // 包声明,指定当前类所在的包
import java.util.List; // 导入List接口用于表示列表
import java.util.Vector; // 导入Vector类用于实现可增长的对象数组
import javax.swing.table.AbstractTableModel; // 导入AbstractTableModel类用于创建表格模型
import com.lingnan.supermarket.dto.Production; // 导入Production类表示产品数据传输对象
import com.lingnan.supermarket.dto.User; // 导入User类表示用户数据传输对象
import com.lingnan.supermarket.dao.UserService; // 导入UserService接口用于用户数据访问
import com.lingnan.supermarket.dao.impl.*; // 导入所有实现类,可能用于数据访问层的具体实现
public class StorageTableModel extends AbstractTableModel{ // 定义一个类继承自AbstractTableModel用于存储表格数据模型
private String [] columnName = {"id","名称","保质期","数量","类别","供应商编号"}; // 定义列名数组,用于表格的列标题
private productionImpl prodDao = new productionImpl(); // 创建productionImpl对象用于操作产品数据
private Vector<Production> prods; // 声明一个Vector用于存储Production对象列表
public void all() {
// 查找全部数据并更新prods向量
prods = prodDao.findAllproduction();
}
public void Byname(Production p) {
// 根据产品名称查找数据并更新prods向量
prods = prodDao.findproduction(p.getName());
}
@Override
public int getRowCount() {
// 获取表格的行数即prods向量的元素数量
return prods.size();
}
@Override
public int getColumnCount() {
// 获取表格的列数即columnName数组的长度
return columnName.length;
}
@Override
public Object getValueAt(int rowIndex, int columnIndex) {
// 获取指定行和列的单元格值
Production prod = prods.get(rowIndex); // 获取指定行的Production对象
if(columnIndex==0) {
return prod.getId(); // 返回产品ID
}else if(columnIndex==1) {
return prod.getName(); // 返回产品名称
}else if(columnIndex==2) {
return prod.getLife(); // 返回产品保质期
}else if(columnIndex==3) {
return prod.getSum(); // 返回产品数量
}else if(columnIndex==4) {
return prod.getName2()+prod.getId2(); // 返回产品类别和ID的组合
}else if(columnIndex==5) {
return prod.getSupplyId(); // 返回产品供应商编号
}else {
return null; // 如果列索引不匹配返回null
}
}
@Override
public String getColumnName(int column) {
// 获取指定列的列名
return columnName[column]; // 返回columnName数组中指定索引的值
}
}

@ -0,0 +1,228 @@
package com.lingnan.supermarket.view; // 定义包名表示这个类属于com.lingnan.supermarket.view包
import java.awt.BorderLayout; // 导入BorderLayout布局管理器类
import java.awt.Color; // 导入Color类用于定义颜色
import java.awt.FlowLayout; // 导入FlowLayout布局管理器类
import java.awt.event.ActionEvent; // 导入事件监听接口
import java.awt.event.ActionListener; // 导入事件监听器接口
import javax.swing.ImageIcon; // 导入ImageIcon类用于显示图片
import javax.swing.JButton; // 导入JButton类用于创建按钮
import javax.swing.JFrame; // 导入JFrame类用于创建窗口
import javax.swing.JLabel; // 导入JLabel类用于创建标签
import javax.swing.JOptionPane; // 导入JOptionPane类用于显示对话框
import javax.swing.JPanel; // 导入JPanel类用于创建面板
import javax.swing.JScrollPane; // 导入JScrollPane类用于创建滚动面板
import javax.swing.JTable; // 导入JTable类用于创建表格
import javax.swing.JTextField; // 导入JTextField类用于创建文本框
import com.lingnan.supermarket.dao.productionService; // 导入productionService接口
import com.lingnan.supermarket.dao.impl.productionImpl; // 导入productionImpl实现类
import com.lingnan.supermarket.dialog.ProductionDialog; // 导入ProductionDialog类
import com.lingnan.supermarket.dialog.UserDialog; // 导入UserDialog类
import com.lingnan.supermarket.dto.Production; // 导入Production类
import com.lingnan.supermarket.table.StorageRecordTM; // 导入StorageRecordTM类
import com.lingnan.supermarket.table.StorageTableModel; // 导入StorageTableModel类
import com.lingnan.supermarket.utils.FontUtil; // 导入FontUtil类用于字体设置
public class StorageView extends JPanel implements ActionListener{ // 创建StorageView类继承JPanel并实现ActionListener接口
//上面
private JPanel toolBarPanel; // 工具栏面板变量声明
private JPanel searchPanel; // 搜索面板变量声明
private JLabel nameLabel,locationLabel; // 标签变量声明
private JTextField nameSearchTF; // 文本框变量声明
private JButton searchBtn; // 搜索按钮变量声明
private JPanel opePanel; // 操作面板变量声明
private JButton addBtn,updateBtn,deleteBtn,historyBtn,backBtn; // 按钮变量声明
//中间
private JScrollPane tableScrollPane; // 表格滚动面板变量声明
private JTable storageTable; // 表格变量声明
//下面
private JPanel bottomPanel; // 底部面板变量声明
private JLabel countInfoLabel; // 记录总数标签变量声明
private StorageTableModel storageTableModel ; // 表格模型变量声明
private JFrame jFrame; // 窗口变量声明
private productionService productionService=new productionImpl(); // 创建productionService实例
public StorageView(JFrame jFrame) { // StorageView构造方法
this.setLayout(new BorderLayout()); // 设置布局管理器为BorderLayout
initView(); // 初始化视图
this.jFrame = jFrame; // 将传入的JFrame实例赋值给成员变量
}
private void initView() { // 初始化视图的方法
toolBarPanel = new JPanel(new BorderLayout()); // 创建工具栏面板并设置布局为BorderLayout
searchPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); // 创建搜索面板并设置布局为左对齐的FlowLayout
locationLabel=new JLabel("当前位置>商品库存"); // 创建位置标签并设置文本
locationLabel.setFont(new FontUtil().userFont); // 设置标签字体
locationLabel.setForeground(new Color(18, 150, 219)); // 设置标签前景色
nameLabel = new JLabel("商品名"); // 创建商品名标签并设置文本
nameSearchTF = new JTextField(10); // 创建文本框并设置大小
searchBtn = new JButton(new ImageIcon("static\\icon\\search.png")); // 创建搜索按钮并设置图标
opePanel = new JPanel(new FlowLayout(FlowLayout.RIGHT)); // 创建操作面板并设置布局为右对齐的FlowLayout
addBtn =new JButton(new ImageIcon("static\\icon\\add.png")); // 创建添加按钮并设置图标
updateBtn =new JButton(new ImageIcon("static\\icon\\update.png")); // 创建更新按钮并设置图标
deleteBtn =new JButton(new ImageIcon("static\\icon\\delete.png")); // 创建删除按钮并设置图标
backBtn =new JButton(new ImageIcon("static\\icon\\back.png")); // 创建返回按钮并设置图标
historyBtn =new JButton(new ImageIcon("static\\icon\\history.png")); // 创建历史按钮并设置图标
backBtn.setVisible(false); // 设置返回按钮为不可见
addBtn.addActionListener(this); // 为添加按钮添加事件监听器
updateBtn.addActionListener(this); // 为更新按钮添加事件监听器
deleteBtn.addActionListener(this); // 为删除按钮添加事件监听器
searchBtn.addActionListener(this); // 为搜索按钮添加事件监听器
backBtn.addActionListener(this); // 为返回按钮添加事件监听器
historyBtn.addActionListener(this); // 为历史按钮添加事件监听器
opePanel.add(addBtn); // 将添加按钮添加到操作面板
opePanel.add(updateBtn); // 将更新按钮添加到操作面板
opePanel.add(deleteBtn); // 将删除按钮添加到操作面板
opePanel.add(backBtn); // 将返回按钮添加到操作面板
opePanel.add(historyBtn); // 将历史按钮添加到操作面板
searchPanel.add(locationLabel); // 将位置标签添加到搜索面板
searchPanel.add(nameLabel); // 将商品名标签添加到搜索面板
searchPanel.add(nameSearchTF); // 将商品名文本框添加到搜索面板
searchPanel.add(searchBtn); // 将搜索按钮添加到搜索面板
toolBarPanel.add(searchPanel,"West"); // 将搜索面板添加到工具栏面板的西边
toolBarPanel.add(opePanel,"East"); // 将操作面板添加到工具栏面板的东边
//中间表格
storageTableModel = new StorageTableModel(); // 创建表格模型实例
storageTableModel.all(); // 调用表格模型的方法以加载所有数据
storageTable = new JTable(storageTableModel); // 创建表格并设置模型
storageTable.setFont(FontUtil.tableFont); // 设置表格字体
storageTable.setRowHeight(50); // 设置表格行高
tableScrollPane = new JScrollPane(storageTable); // 创建滚动面板并添加表格
//下面
bottomPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); // 创建底部面板并设置布局为左对齐的FlowLayout
countInfoLabel = new JLabel("总共"+storageTableModel.getRowCount()+"条"); // 创建记录总数标签并设置文本
bottomPanel.add(countInfoLabel); // 将记录总数标签添加到底部面板
this.add(toolBarPanel,"North"); // 将工具栏面板添加到面板的北边
this.add(tableScrollPane,"Center"); /*将表格放到中间*/ // 将表格滚动面板添加到面板的中间
this.add(bottomPanel,"South"); // 将底部面板添加到面板的南边
setVisible(true); // 设置面板为可见
}
@Override
public void actionPerformed(ActionEvent e) {
Object source = e.getSource(); // 获取事件源
if(addBtn==source) { // 如果事件源是添加按钮
//添加数据的对话框
ProductionDialog productionDialog = new ProductionDialog(jFrame); // 创建添加数据的对话框
productionDialog.setVisible(true); // 设置对话框为可见
refreshProduction(); // 刷新生产数据
}else if(updateBtn==source) { // 如果事件源是更新按钮
refreshProduction(); // 刷新生产数据
}else if(historyBtn==source) { // 如果事件源是历史按钮
storageRecord(); // 处理库存记录
}else if(backBtn==source) { // 如果事件源是返回按钮
refreshProduction(); // 刷新生产数据
}
else if(deleteBtn==source) { // 如果事件源是删除按钮
//获取选中记录,删除
int[] rowIndexs = storageTable.getSelectedRows(); // 获取表格中所有选中行的索引
if(rowIndexs.length==0) { // 如果没有选中任何行
JOptionPane.showMessageDialog(this,"请至少选中一条"); // 显示提示信息
return; // 结束方法执行
}
int select=JOptionPane.showConfirmDialog(this,"是否删除选中的"+rowIndexs.length+"条记录","提示",JOptionPane.YES_NO_OPTION); // 显示确认删除的对话框
if(select==JOptionPane.YES_OPTION){ // 如果用户选择是
for(int i=0;i<rowIndexs.length;i++){ // 遍历所有选中的行
String id = (String)storageTable.getValueAt(rowIndexs[i],0); // 获取选中行的ID
if(productionService.deleteProduction(id)==1) { // 尝试删除记录
// 删除成功,不需要额外操作
}else {
JOptionPane.showMessageDialog(this,"删除失败,id="+id,"提示",JOptionPane.ERROR_MESSAGE); // 显示删除失败的提示信息
}
}
JOptionPane.showMessageDialog(this,"删除操作结束","提示",JOptionPane.INFORMATION_MESSAGE); // 显示删除操作结束的提示信息
}
refreshProduction(); // 刷新生产数据
}else if(source==searchBtn){ // 如果事件源是搜索按钮
refreshFindRname(); // 刷新搜索结果
}
}
public void refreshFindRname() {
String name = nameSearchTF.getText(); // 获取搜索框中的文本
Production p=new Production(); // 创建Production对象
p.setName(name); // 设置Production对象的名称
storageTableModel = new StorageTableModel(); // 创建新的StorageTableModel对象
storageTableModel.Byname(p); // 根据名称过滤数据
storageTable.setModel(storageTableModel); // 设置表格模型
//同时更新下面的记录数
refreshCount(); // 刷新记录数
hiddinBtn(); // 隐藏或显示按钮
}
public void refreshProduction() {
storageTableModel = new StorageTableModel(); // 创建新的StorageTableModel对象
storageTableModel.all(); // 获取所有数据
storageTable.setModel(storageTableModel); // 设置表格模型
//同时更新下面的记录数
refreshCount(); // 刷新记录数
hiddinBtn(); // 隐藏或显示按钮
}
public void refreshCount(){
bottomPanel.removeAll(); // 清除底部面板上的所有组件
countInfoLabel = new JLabel("总共"+storageTableModel.getRowCount()+"条"); // 创建新的标签显示记录总数
bottomPanel.add(countInfoLabel); // 将记录总数标签添加到底部面板
hiddinBtn(); // 隐藏或显示按钮
}
public void storageRecord() {
StorageRecordTM storageRecordTM= new StorageRecordTM(); // 创建StorageRecordTM对象
storageRecordTM.allStoragrRecord(); // 获取所有库存记录
storageTable.setModel(storageRecordTM); // 设置表格模型为库存记录
//同时更新下面的记录数
bottomPanel.removeAll(); // 清除底部面板上的所有组件
countInfoLabel = new JLabel("总共"+storageRecordTM.getRowCount()+"条"); // 创建新的标签显示记录总数
bottomPanel.add(countInfoLabel); // 将记录总数标签添加到底部面板
backBtn.setVisible(true); // 设置返回按钮为可见
updateBtn.setVisible(false); // 设置更新按钮为不可见
addBtn.setVisible(false); // 设置添加按钮为不可见
historyBtn.setVisible(false); // 设置历史按钮为不可见
deleteBtn.setVisible(false); // 设置删除按钮为不可见
}
public void hiddinBtn() {
backBtn.setVisible(false); // 设置返回按钮为不可见
updateBtn.setVisible(true); // 设置更新按钮为可见
addBtn.setVisible(true); // 设置添加按钮为可见
historyBtn.setVisible(true); // 设置历史按钮为可见
deleteBtn.setVisible(true); // 设置删除按钮为可见
}
}

@ -0,0 +1,37 @@
package com.lingnan.supermarket.view; // 定义包名表示这段代码属于com.lingnan.supermarket.view这个包
import java.awt.BorderLayout; // 导入BorderLayout类用于设置布局管理器
import javax.swing.ImageIcon; // 导入ImageIcon类用于处理图片
import javax.swing.JFrame; // 导入JFrame类用于创建窗口
import javax.swing.JLabel; // 导入JLabel类用于显示文本或图片
import javax.swing.JPanel; // 导入JPanel类用于创建面板
import javax.swing.SwingUtilities; // 导入SwingUtilities类用于在事件调度线程中执行代码
public class SuperView extends JPanel{ // 定义一个名为SuperView的公共类继承自JPanel类
private JLabel label; // 声明一个私有的JLabel类型的变量用于显示图片
private JFrame jFrame; // 声明一个私有的JFrame类型的变量用于引用窗口
public SuperView(JFrame jFrame) { // SuperView类的构造方法接收一个JFrame类型的参数
this.setLayout(new BorderLayout()); // 设置面板的布局管理器为BorderLayout
initView(); // 调用初始化视图的方法
this.jFrame = jFrame; // 将传入的JFrame参数赋值给成员变量jFrame
}
private void initView() { // 定义一个私有的初始化视图的方法
//中间
label = new JLabel(); // 创建一个JLabel对象
label.setIcon(new ImageIcon("static\\img\\3.png")); // 设置JLabel的图标为指定的图片路径
label.setHorizontalAlignment(SwingUtilities.CENTER); // 设置标签的水平对齐方式为居中
label.setVerticalAlignment(SwingUtilities.CENTER); // 设置标签的垂直对齐方式为居中
this.add(label,"Center"); // 将标签添加到面板的中间位置
setVisible(true); // 设置面板可见
}
}

@ -0,0 +1,53 @@
package com.lingnan.supermarket.dto; // 声明当前类所在的包
import com.lingnan.supermarket.dto.base.BaseDomain; // 导入基础域类BaseDomain
// 定义供应商信息类SupplierInf继承自BaseDomain
public class SupplierInf extends BaseDomain{
private String name; // 供应商名称
private String address; // 供应商地址
private String contact; // 供应商联系方式
private String email; // 供应商邮箱
// getEmail方法用于获取供应商邮箱
public String getEmail() {
return email; // 返回邮箱
}
// setEmail方法用于设置供应商邮箱
public void setEmail(String email) {
this.email = email; // 将参数email赋值给成员变量email
}
private int delmark; // 删除标记
// getDelmark方法用于获取删除标记
public int getDelmark() {
return delmark; // 返回删除标记
}
// setDelmark方法用于设置删除标记
public void setDelmark(int delmark) {
this.delmark = delmark; // 将参数delmark赋值给成员变量delmark
}
// getName方法用于获取供应商名称
public String getName() {
return name; // 返回供应商名称
}
// setName方法用于设置供应商名称
public void setName(String name) {
this.name = name; // 将参数name赋值给成员变量name
}
// getAddress方法用于获取供应商地址
public String getAddress() {
return address; // 返回供应商地址
}
// setAddress方法用于设置供应商地址
public void setAddress(String address) {
this.address = address; // 将参数address赋值给成员变量address
}
// getContact方法用于获取供应商联系方式
public String getContact() {
return contact; // 返回供应商联系方式
}
// setContact方法用于设置供应商联系方式
public void setContact(String contact) {
this.contact = contact; // 将参数contact赋值给成员变量contact
}
}

@ -0,0 +1,151 @@
package com.lingnan.supermarket.dialog; // 声明当前类所在的包
import java.awt.Container; // 导入Container类用于包含和布局组件
import java.awt.FlowLayout; // 导入FlowLayout类用于流式布局管理
import java.awt.event.ActionEvent; // 导入ActionEvent类用于处理按钮点击等动作事件
import java.awt.event.ActionListener; // 导入ActionListener接口用于监听和处理动作事件
import javax.swing.JButton; // 导入JButton类用于创建按钮
import javax.swing.JDialog; // 导入JDialog类用于创建对话框
import javax.swing.JFrame; // 导入JFrame类用于创建主窗口框架
import javax.swing.JLabel; // 导入JLabel类用于创建标签
import javax.swing.JOptionPane; // 导入JOptionPane类用于显示对话框
import javax.swing.JPanel; // 导入JPanel类用于创建面板容器
import javax.swing.JTextField; // 导入JTextField类用于创建文本输入框
import com.lingnan.supermarket.*; // 导入lingnan.supermarket包下的所有类
import com.lingnan.supermarket.dao.SupplierInfService; // 导入SupplierInfService接口用于供应商信息数据访问
import com.lingnan.supermarket.dao.impl.SupplierInfImpl; // 导入SupplierInfImpl类实现SupplierInfService接口
import com.lingnan.supermarket.dto.SupplierInf; // 导入SupplierInf类用于表示供应商信息数据传输对象
import com.lingnan.supermarket.view.SupplierView; // 导入SupplierView类用于显示供应商信息视图
public class SupplierInfDialog extends JDialog implements ActionListener { // 定义一个对话框类SupplierInfDialog继承自JDialog并实现ActionListener接口
private JPanel namePanel, addressPanel, contactPanel, emailPanel, opePanel; // 声明面板变量,用于不同信息的布局
private JLabel nameLabel, addressLabel, contactLabel, emailLabel; // 声明标签变量,用于显示文本信息
private JTextField nameTF, addressTF, contactTF, emailTF; // 声明文本框变量,用于输入信息
private JButton saveBtn, cancelBtn; // 声明按钮变量,用于保存和取消操作
private SupplierInfService supplierInfService = new SupplierInfImpl(); // 创建供应商信息服务实例
private SupplierView supplierView; // 声明供应商视图变量
private SupplierInf supplierInf; // 声明供应商信息变量
// 构造方法,接收父窗口和供应商视图作为参数
public SupplierInfDialog(JFrame parent, SupplierView supplierView) {
super(parent, "添加"); // 调用父类构造方法,设置对话框标题为"添加"
this.supplierView = supplierView; // 初始化供应商视图
setSize(350, 300); // 设置对话框大小
setLocationRelativeTo(null); // 设置对话框相对于屏幕居中
setModal(true); // 设置对话框为模态
setResizable(false); // 设置对话框不可调整大小
this.setLayout(new FlowLayout()); // 设置对话框布局为流式布局
initView(); // 初始化视图
}
private void initView() { // 初始化视图的私有方法
namePanel = new JPanel(); // 创建名称的面板
nameLabel = new JLabel("名称"); // 创建名称的标签
nameTF = new JTextField(15); // 创建名称的文本框宽度为15
namePanel.add(nameLabel); // 将名称标签添加到名称面板
namePanel.add(nameTF); // 将名称文本框添加到名称面板
addressPanel = new JPanel(); // 创建地址的面板
addressLabel = new JLabel("地址"); // 创建地址的标签
addressTF = new JTextField(15); // 创建地址的文本框宽度为15
addressPanel.add(addressLabel); // 将地址标签添加到地址面板
addressPanel.add(addressTF); // 将地址文本框添加到地址面板
contactPanel = new JPanel(); // 创建联系方式的面板
contactLabel = new JLabel("电话"); // 创建联系方式的标签
contactTF = new JTextField(15); // 创建联系方式的文本框宽度为15
contactPanel.add(contactLabel); // 将联系方式标签添加到联系方式面板
contactPanel.add(contactTF); // 将联系方式文本框添加到联系方式面板
emailPanel = new JPanel(); // 创建邮箱的面板
emailLabel = new JLabel("邮箱"); // 创建邮箱的标签
emailTF = new JTextField(15); // 创建邮箱的文本框宽度为15
emailPanel.add(emailLabel); // 将邮箱标签添加到邮箱面板
emailPanel.add(emailTF); // 将邮箱文本框添加到邮箱面板
opePanel = new JPanel(); // 创建操作按钮的面板
saveBtn = new JButton("保存"); // 创建保存按钮
cancelBtn = new JButton("取消"); // 创建取消按钮
saveBtn.addActionListener(this); // 为保存按钮添加动作监听器
cancelBtn.addActionListener(this); // 为取消按钮添加动作监听器
opePanel.add(saveBtn); // 将保存按钮添加到操作面板
opePanel.add(cancelBtn); // 将取消按钮添加到操作面板
Container container = getContentPane(); // 获取对话框的内容面板
container.add(namePanel); // 将名称面板添加到内容面板
container.add(addressPanel); // 将地址面板添加到内容面板
container.add(contactPanel); // 将联系方式面板添加到内容面板
container.add(emailPanel); // 将邮箱面板添加到内容面板
container.add(opePanel); // 将操作按钮面板添加到内容面板
}
@Override
public void actionPerformed(ActionEvent e) { // 实现ActionListener接口的actionPerformed方法
Object source = e.getSource(); // 获取事件源
if (source == saveBtn) { // 如果事件源是保存按钮
// 思路获取数据
// 保存到数据库
// 关闭对话框
// 刷新table
String name = nameTF.getText(); // 获取名称文本框的内容
String address = addressTF.getText(); // 获取地址文本框的内容
String contact = contactTF.getText(); // 获取联系方式文本框的内容
String email = emailTF.getText(); // 获取邮箱文本框的内容
// TODO 参数校验
if (this.supplierInf == null) { // 如果supplierInf为null表示是添加新供应商
SupplierInf supplierInf = new SupplierInf(); // 创建新的供应商信息对象
supplierInf.setName(name); // 设置供应商名称
supplierInf.setAddress(address); // 设置供应商地址
supplierInf.setContact(contact); // 设置供应商联系方式
supplierInf.setEmail(email); // 设置供应商邮箱
int result = supplierInfService.addSupplierInf(supplierInf); // 调用服务层添加供应商信息
// int result = 1; // 假设添加成功
if (result == 1) { // 如果添加成功
JOptionPane.showMessageDialog(this, "添加成功", "提示", // 显示添加成功的消息对话框
JOptionPane.INFORMATION_MESSAGE);
this.dispose(); // 关闭对话框
} else { // 如果添加失败
JOptionPane.showMessageDialog(this, "添加失败", "提示", // 显示添加失败的消息对话框
JOptionPane.ERROR_MESSAGE);
}
}/*else{ // 如果supplierInf不为null表示是更新供应商信息
//更新
SupplierInf supplierInf= new SupplierInf(); // 创建新的供应商信息对象
supplierInf.setName(name); // 设置供应商名称
supplierInf.setAddress(address); // 设置供应商地址
supplierInf.setContact(contact); // 设置供应商联系方式
supplierInf.setId(this.supplierInf.getId()); // 设置供应商ID
int result = supplierInfService.updateSupplierInf(supplierInf); // 调用服务层更新供应商信息
if(result==1){ // 如果更新成功
JOptionPane.showMessageDialog(this, "更新成功", "提示", // 显示更新成功的消息对话框
JOptionPane.INFORMATION_MESSAGE);
}
}*/
} else if (source == cancelBtn) { // 如果事件源是取消按钮
this.dispose(); // 关闭对话框
}
}
}

@ -0,0 +1,105 @@
package com.lingnan.supermarket.table;
import java.util.List;
import java.util.Vector;
import javax.swing.table.AbstractTableModel;
import com.lingnan.supermarket.dto.SupplierInf;
import com.lingnan.supermarket.dao.SupplierInfService;
import com.lingnan.supermarket.dao.impl.*;
public class SupplierTableModel extends AbstractTableModel{
// 定义表格列名数组
private String [] columnName = {"id","名称","地址","联系方式","邮箱"};
// 声明供应商信息服务接口实例
//private SupplierInfImpl supplierDao = new SupplierInfImpl();
private SupplierInfService supplierInfService = new SupplierInfImpl();
// 创建供应商信息对象
private SupplierInf supplierInf = new SupplierInf();
// 创建供应商信息列表
private Vector<SupplierInf> suppliers;
// 定义供应商ID变量
private int id=0;
// 查找全部供应商信息的方法
public void all() {
// 查找全部数据
suppliers = supplierInfService.findAllSupplierInf();
}
// 根据名称查找供应商信息的方法
public void Byname(SupplierInf supplierInf) {
// 根据名称查找供应商信息
suppliers = supplierInfService.findByNameSupplierInf(supplierInf);
}
// 重写获取行数的方法
@Override
public int getRowCount() {
// 返回供应商列表的大小
return suppliers.size();
}
// 重写获取列数的方法
@Override
public int getColumnCount() {
// 返回列名数组的长度
return columnName.length;
}
// 重写获取单元格值的方法
@Override
public Object getValueAt(int rowIndex, int columnIndex) {
// 获取指定行的供应商信息
SupplierInf prod = suppliers.get(rowIndex);
// 根据列索引返回相应的供应商信息属性
if(columnIndex==0) {
return prod.getId();
}else if(columnIndex==1) {
return prod.getName();
}else if(columnIndex==2) {
return prod.getAddress();
}else if(columnIndex==3) {
return prod.getContact();
}else if(columnIndex==4){
return prod.getEmail();
}
else {
return null;
}
}
// 重写获取列名的方法
@Override
public String getColumnName(int column) {
// 返回指定列索引的列名
return columnName[column];
}
/*
public int getId() {
return id;
}
public int getValueAt(int rowIndex){
SupplierInf supplierInf = suppliers.get(rowIndex);
id=suppliers.get(rowIndex).getId();
//System.out.println("rowIndex"+rowIndex);
//System.out.println("columnIndex"+columnIndex);
return supplierInf.getId();
}
*/
}

@ -0,0 +1,179 @@
package com.lingnan.supermarket.view; // 定义包名表示这个类属于com.lingnan.supermarket.view包
import java.awt.BorderLayout; // 导入BorderLayout布局管理器类
import java.awt.Color; // 导入Color类用于定义颜色
import java.awt.FlowLayout; // 导入FlowLayout布局管理器类用于流式布局
import java.awt.event.ActionEvent; // 导入ActionEvent类用于处理动作事件
import java.awt.event.ActionListener; // 导入ActionListener接口用于实现事件监听
import javax.swing.ImageIcon; // 导入ImageIcon类用于处理图片
import javax.swing.JButton; // 导入JButton类用于创建按钮
import javax.swing.JFrame; // 导入JFrame类用于创建窗口
import javax.swing.JLabel; // 导入JLabel类用于创建标签
import javax.swing.JOptionPane; // 导入JOptionPane类用于显示对话框
import javax.swing.JPanel; // 导入JPanel类用于创建面板
import javax.swing.JScrollPane; // 导入JScrollPane类用于创建带滚动条的容器
import javax.swing.JTable; // 导入JTable类用于创建表格
import javax.swing.JTextField; // 导入JTextField类用于创建文本框
import com.lingnan.supermarket.dao.SupplierInfService; // 导入供应商信息服务的接口
import com.lingnan.supermarket.dao.impl.SupplierInfImpl; // 导入供应商信息服务的实现类
import com.lingnan.supermarket.dialog.SupplierInfDialog; // 导入供应商信息对话框类
import com.lingnan.supermarket.dto.SupplierInf; // 导入供应商信息数据传输对象
import com.lingnan.supermarket.table.SupplierTableModel; // 导入供应商信息表格模型类
import com.lingnan.supermarket.utils.FontUtil; // 导入字体工具类
public class SupplierView extends JPanel implements ActionListener{ // 定义一个公共类SupplierView继承JPanel并实现ActionListener接口
//上面
private JPanel toolBarPanel; // 工具栏面板的私有成员变量
private JPanel searchPanel; // 搜索面板的私有成员变量
private JLabel nameLabel,locationLabel; // 标签的私有成员变量,用于显示文本
private JTextField nameSearchTF; // 文本框的私有成员变量,用于输入搜索内容
private JButton searchBtn; // 搜索按钮的私有成员变量
private JPanel opePanel; // 操作面板的私有成员变量
private JButton addBtn,updateBtn,deleteBtn; // 按钮的私有成员变量,用于添加、更新、删除操作
//中间
private JScrollPane tableScrollPane; // 带滚动条的表格面板的私有成员变量
private JTable supplierTable; // 表格的私有成员变量,用于显示供应商信息
//下面
private JPanel bottomPanel; // 底部面板的私有成员变量
private JLabel countInfoLabel; // 标签的私有成员变量,用于显示记录总数信息
private SupplierTableModel supplierTableModel; // 供应商信息表格模型的私有成员变量
private JFrame jFrame; // 窗口的私有成员变量
private SupplierInfService supplierInfService = new SupplierInfImpl(); // 供应商信息服务的实例化对象
public SupplierView(JFrame jFrame) { // SupplierView类的构造方法接收一个JFrame参数
this.setLayout(new BorderLayout()); // 设置面板的布局为BorderLayout
initView(); // 调用初始化视图的方法
this.jFrame = jFrame; // 将传入的JFrame窗口对象赋值给类的成员变量
}
private void initView() { // 初始化视图的私有方法
toolBarPanel = new JPanel(new BorderLayout()); // 创建工具栏面板并设置布局为BorderLayout
searchPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); // 创建搜索面板并设置布局为左对齐的FlowLayout
locationLabel=new JLabel("当前位置>供应商"); // 创建标签并设置文本为当前位置信息
locationLabel.setFont(new FontUtil().userFont); // 设置标签的字体
locationLabel.setForeground(new Color(18, 150, 219)); // 设置标签的前景色(文字颜色)
nameLabel = new JLabel("公司名称"); // 创建标签并设置文本为公司名称
nameSearchTF = new JTextField(10); // 创建文本框并设置大小为10个字符宽度
searchBtn = new JButton(new ImageIcon("static\\icon\\search.png")); // 创建搜索按钮并设置图标
opePanel = new JPanel(new FlowLayout(FlowLayout.RIGHT)); // 创建操作面板并设置布局为右对齐的FlowLayout
addBtn =new JButton(new ImageIcon("static\\icon\\add.png")); // 创建添加按钮并设置图标
updateBtn =new JButton(new ImageIcon("static\\icon\\update.png")); // 创建更新按钮
searchBtn = new JButton(new ImageIcon("static\\icon\\search.png")); // 创建搜索按钮并设置图标
opePanel = new JPanel(new FlowLayout(FlowLayout.RIGHT)); // 创建操作面板并设置布局为右对齐的FlowLayout
addBtn =new JButton(new ImageIcon("static\\icon\\add.png")); // 创建添加按钮并设置图标
updateBtn =new JButton(new ImageIcon("static\\icon\\update.png")); // 创建更新按钮并设置图标
deleteBtn =new JButton(new ImageIcon("static\\icon\\delete.png")); // 创建删除按钮并设置图标
addBtn.addActionListener(this); // 为添加按钮添加事件监听器
updateBtn.addActionListener(this); // 为更新按钮添加事件监听器
deleteBtn.addActionListener(this); // 为删除按钮添加事件监听器
searchBtn.addActionListener(this); // 为搜索按钮添加事件监听器
opePanel.add(addBtn); // 将添加按钮添加到操作面板
opePanel.add(updateBtn); // 将更新按钮添加到操作面板
opePanel.add(deleteBtn); // 将删除按钮添加到操作面板
searchPanel.add(locationLabel); // 将位置标签添加到搜索面板
searchPanel.add(nameLabel); // 将公司名称标签添加到搜索面板
searchPanel.add(nameSearchTF); // 将公司名称文本框添加到搜索面板
searchPanel.add(searchBtn); // 将搜索按钮添加到搜索面板
toolBarPanel.add(searchPanel,"West"); // 将搜索面板添加到工具栏面板的西边
toolBarPanel.add(opePanel,"East"); // 将操作面板添加到工具栏面板的东边
//中间表格
supplierTableModel = new SupplierTableModel(); // 创建供应商表格模型对象
supplierTableModel.all(); // 调用表格模型的方法以加载所有数据
supplierTable = new JTable(supplierTableModel); // 创建表格并设置模型
supplierTable.setFont(FontUtil.tableFont); // 设置表格字体
supplierTable.setRowHeight(50); // 设置表格行高
tableScrollPane = new JScrollPane(supplierTable); // 创建带滚动条的容器并添加表格
//下面
bottomPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); // 创建底部面板并设置布局为左对齐的FlowLayout
countInfoLabel = new JLabel("总共"+supplierTableModel.getRowCount()+"条"); // 创建标签并设置显示记录总数的文本
bottomPanel.add(countInfoLabel); // 将记录总数标签添加到底部面板
this.add(toolBarPanel,"North"); // 将工具栏面板添加到主面板的北边
this.add(tableScrollPane,"Center"); // 将带滚动条的表格容器添加到主面板的中间
this.add(bottomPanel,"South"); // 将底部面板添加到主面板的南边
setVisible(true); // 设置主面板可见(通常不需要,因为主面板会在添加到窗口时自动设置为可见)
}
@Override
public void actionPerformed(ActionEvent e) { // 实现ActionListener接口的actionPerformed方法
Object source = e.getSource(); // 获取事件源
if(addBtn==source) { // 如果事件源是添加按钮
SupplierInfDialog supplierInfDialog = new SupplierInfDialog(jFrame, null); // 创建供应商信息对话框
supplierInfDialog.setVisible(true); // 设置对话框可见
refreshSupplier(); // 刷新供应商信息
}else if(updateBtn==source) { // 如果事件源是更新按钮
refreshSupplier(); // 刷新供应商信息
}else if(deleteBtn==source) { // 如果事件源是删除按钮
//获取选中记录
int rowIndex = supplierTable.getSelectedRow(); // 获取表格中选中的行索引
if(rowIndex==-1) { // 如果没有行被选中
JOptionPane.showMessageDialog(this,"请选中一条"); // 显示提示信息
return; // 结束方法执行
}
int id = (Integer)supplierTable.getValueAt(rowIndex,0); // 获取选中行的ID
int select=JOptionPane.showConfirmDialog(this,"是否删除id="+id,"提示",JOptionPane.YES_NO_OPTION); // 显示确认删除的对话框并获取用户的选择
if(select==JOptionPane.YES_OPTION){ // 如果用户在确认对话框中选择“是”
if(supplierInfService.deleteSupplierInf(id)==1) { // 尝试删除供应商信息如果成功返回1
JOptionPane.showMessageDialog(this,"删除成功","提示",JOptionPane.INFORMATION_MESSAGE); // 显示删除成功的消息
refreshSupplier(); // 刷新供应商信息
}else {
JOptionPane.showMessageDialog(this,"删除失败","提示",JOptionPane.ERROR_MESSAGE); // 显示删除失败的消息
}
}
}else if(searchBtn==source){ // 如果事件源是搜索按钮
System.out.println("搜索"); // 打印搜索操作信息到控制台
refreshFindRname(); // 调用方法刷新搜索结果
}
}
// 根据名称刷新供应商信息的方法
public void refreshFindRname() {
String name = nameSearchTF.getText(); // 获取搜索文本框中的文本
SupplierInf supplierInf = new SupplierInf(); // 创建供应商信息对象
supplierInf.setName(name); // 设置供应商名称为搜索文本
supplierTableModel = new SupplierTableModel(); // 创建新的供应商表格模型
supplierTableModel.Byname(supplierInf); // 调用表格模型的方法按名称查询供应商信息
supplierTable.setModel(supplierTableModel); // 更新表格模型以显示查询结果
refreshCount(); // 刷新记录总数
}
// 刷新供应商信息的方法
public void refreshSupplier() {
supplierTableModel = new SupplierTableModel(); // 创建新的供应商表格模型
supplierTableModel.all(); // 加载所有供应商信息
supplierTable.setModel(supplierTableModel); // 更新表格模型以显示所有供应商信息
refreshCount(); // 刷新记录总数
}
// 刷新记录总数的方法
public void refreshCount(){
bottomPanel.removeAll(); // 清除底部面板上的所有组件
countInfoLabel = new JLabel("总共"+supplierTableModel.getRowCount()+"条"); // 创建新的标签显示记录总数
bottomPanel.add(countInfoLabel); // 将记录总数标签添加到底部面板
}
}
Loading…
Cancel
Save