Merge remote-tracking branch 'remotes/origin/main' into developer

# Conflicts:
#	Supermarket/bin/com/lingnan/supermarket/componet/BGPanel.class
#	Supermarket/bin/com/lingnan/supermarket/dao/impl/storageRecordImpl.class
#	Supermarket/bin/com/lingnan/supermarket/utils/CreateOrder.class
#	Supermarket/bin/com/lingnan/supermarket/utils/JDBCUtil.class
#	Supermarket/bin/com/lingnan/supermarket/utils/TimeAndOrder.class
#	Supermarket/bin/com/lingnan/supermarket/view/InView.class
#	Supermarket/bin/com/lingnan/supermarket/view/MainView.class
#	Supermarket/src/com/lingnan/supermarket/dao/impl/storageRecordImpl.java
#	Supermarket/src/com/lingnan/supermarket/utils/CreateOrder.java
#	Supermarket/src/com/lingnan/supermarket/utils/JDBCUtil.java
#	Supermarket/src/com/lingnan/supermarket/utils/TimeAndOrder.java
#	Supermarket/src/com/lingnan/supermarket/view/InView.java
pull/48/head
HouXinyu 9 months ago
commit 56521ce0d3

@ -4,11 +4,12 @@ import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Iterator;
import java.util.Vector;
<<<<<<< HEAD
// 导入相关的业务逻辑接口、数据传输对象以及工具类,用于数据库操作和日期处理等功能
=======
>>>>>>> remotes/origin/main
import com.lingnan.supermarket.dao.storageRecordService;
import com.lingnan.supermarket.dto.StorageRecord;
import com.lingnan.supermarket.utils.DateUtil;
@ -17,6 +18,7 @@ import com.lingnan.supermarket.utils.JDBCUtil;
// 实现storageRecordService接口--用于处理库存记录相关的数据持久化操作
public class storageRecordImpl implements storageRecordService {
<<<<<<< HEAD
// 查询所有库存记录信息并以Vector容器存储返回
@Override
public Vector<StorageRecord> findAllStorageRecord() {
@ -47,9 +49,53 @@ public class storageRecordImpl implements storageRecordService {
// 设置StorageRecord对象的执行情况属性
sr.setExecute(resultSet.getString("execute"));
// 通过DateUtil工具类的dateToString方法将数据库中获取的时间戳类型的日期数据转换为字符串类型方便后续使用第二个参数为null可能表示使用默认的日期格式转换具体看DateUtil实现
=======
/**
*
*
* @return Vector<StorageRecord>
*/
@Override
public Vector<StorageRecord> findAllStorageRecord() {
// 创建一个空的Vector对象用于存储所有查询到的StorageRecord
Vector<StorageRecord> v = new Vector<StorageRecord>();
// 通过JDBC获取数据库连接
Connection conn = JDBCUtil.getConn();
// 声明PreparedStatement和ResultSet对象
PreparedStatement pstmt = null;
ResultSet resultSet = null;
try {
// 编写SQL查询语句按存储日期降序排列
String sql = "select * from storageRecord order by cDate desc";
// 准备SQL语句
pstmt = conn.prepareStatement(sql);
// 执行查询,获取结果集
resultSet = pstmt.executeQuery();
// 迭代结果集将每条记录封装成StorageRecord对象
while (resultSet.next()) {
StorageRecord sr = new StorageRecord();
// 设置StorageRecord对象的各个属性
sr.setId(resultSet.getString("id")); // 设置id字段
sr.setTheNumber(resultSet.getString("theNumber")); // 设置存储记录编号
sr.setNum(resultSet.getInt("num")); // 设置数量字段
sr.setExecute(resultSet.getString("execute")); // 设置执行状态字段
// 设置创建日期字段并通过DateUtil工具类格式化日期
>>>>>>> remotes/origin/main
sr.setcDate(DateUtil.dateToString(resultSet.getTimestamp("cDate"), null));
// 将StorageRecord对象添加到Vector中
v.add(sr);
}
<<<<<<< HEAD
} catch (SQLException e) {
// 若出现SQL异常打印异常栈信息
@ -70,10 +116,41 @@ public class storageRecordImpl implements storageRecordService {
StorageRecord sr = null;
// 获取数据库连接
Connection conn = JDBCUtil.getConn();
=======
} catch (SQLException e) {
// 如果出现SQL异常打印错误信息
e.printStackTrace();
} finally {
// 确保资源被关闭,避免内存泄漏
JDBCUtil.close(resultSet, pstmt, conn);
}
// 返回所有存储记录的Vector
return v;
}
/**
*
*
* @param theNumber
* @return StorageRecord null
*/
@Override
public StorageRecord findByIdStorageRecord(String theNumber) {
// 创建一个空的StorageRecord对象用于存储查询结果
StorageRecord sr = null;
// 获取数据库连接
Connection conn = JDBCUtil.getConn();
// 声明PreparedStatement和ResultSet对象
>>>>>>> remotes/origin/main
PreparedStatement pstmt = null;
ResultSet resultSet = null;
try {
<<<<<<< HEAD
// 创建一个新的StorageRecord对象用于后续封装查询到的数据
sr = new StorageRecord();
// 预编译SQL语句用于根据给定的库存编号theNumber查询storageRecord表中的记录
@ -86,10 +163,30 @@ public class storageRecordImpl implements storageRecordService {
if (resultSet.next()) {
sr.setTheNumber((resultSet.getString("theNumber")));
sr.setId((resultSet.getString("id")));
=======
// 初始化StorageRecord对象
sr = new StorageRecord();
// 编写SQL查询语句通过存储记录编号查询特定记录
pstmt = conn.prepareStatement("select * from storageRecord where theNumber=?");
// 设置查询条件,即存储记录编号
pstmt.setString(1, theNumber);
// 执行查询操作并将结果存放在resultSet中
resultSet = pstmt.executeQuery();
// 如果查询到数据填充StorageRecord对象
if (resultSet.next()) {
sr.setTheNumber(resultSet.getString("theNumber"));
sr.setId(resultSet.getString("id"));
>>>>>>> remotes/origin/main
sr.setNum(resultSet.getInt("num"));
sr.setExecute(resultSet.getString("execute"));
// 设置存储记录的创建日期,并进行格式化
sr.setcDate(DateUtil.dateToString(resultSet.getTimestamp("cDate"), null));
}
<<<<<<< HEAD
} catch (SQLException e) {
// 若出现SQL异常打印异常栈信息
@ -108,10 +205,44 @@ public class storageRecordImpl implements storageRecordService {
boolean flag = false;
// 获取数据库连接
Connection conn = JDBCUtil.getConn();
=======
} catch (SQLException e) {
// 如果发生SQLException打印堆栈信息
e.printStackTrace();
} finally {
// 确保资源关闭,防止资源泄露
JDBCUtil.close(resultSet, pstmt, conn);
}
// 返回找到的存储记录对象如果没有找到则返回null
return sr;
}
/**
*
*
* @param iNumber
* @param time
* @param prodId
* @param execute
* @param sum
* @return boolean truefalse
*/
public boolean insertStorageRecord(String iNumber, String time, String prodId, String execute, int sum) {
// 默认插入操作失败
boolean flag = false;
// 获取数据库连接
Connection conn = JDBCUtil.getConn();
// 声明PreparedStatement和ResultSet对象
>>>>>>> remotes/origin/main
PreparedStatement pstmt = null;
ResultSet resultSet = null;
try {
<<<<<<< HEAD
// 预编译插入数据的SQL语句向storageRecord表中插入五条数据
pstmt = conn.prepareStatement("insert into storageRecord values(?,?,?,?,?) ");
// 设置SQL语句中的第一个参数
@ -138,6 +269,42 @@ public class storageRecordImpl implements storageRecordService {
JDBCUtil.close(resultSet, pstmt, conn);
}
=======
// 编写SQL插入语句将数据插入到storageRecord表中
pstmt = conn.prepareStatement("insert into storageRecord values(?,?,?,?,?)");
// 设置插入的字段值
pstmt.setString(1, iNumber); // 存储记录编号
pstmt.setString(2, time); // 存储记录时间
pstmt.setString(3, prodId); // 商品编号
pstmt.setString(4, execute); // 执行状态
pstmt.setInt(5, sum); // 数量
// 执行插入操作如果插入成功则返回1
if (pstmt.executeUpdate() == 1) {
// 如果插入成功设置标志位为true
flag = true;
}
} catch (SQLException e) {
// 如果发生SQLException打印堆栈信息
e.printStackTrace();
} finally {
// 确保数据库连接和资源被关闭
JDBCUtil.close(resultSet, pstmt, conn);
}
// 返回插入操作的结果成功返回true失败返回false
>>>>>>> remotes/origin/main
return flag;
}
}

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

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

@ -29,91 +29,157 @@ import com.lingnan.supermarket.table.OutTableModel;
import com.lingnan.supermarket.view.MainView;
import com.lingnan.supermarket.view.OutView;
public class CloseDialog extends JDialog implements ActionListener {
public class CloseDialog extends JDialog implements ActionListener{
/**
*
*/
private JPanel prodIdPanel,sumPanel,phonePanel,opePanel;
private JLabel prodIdLabel,sumLabel;
private JTextField prodIdTF,sumTF;
private JButton saveBtn,unSaveBtn,cancleBtn;
// Panel用于显示不同的用户信息
private JPanel prodIdPanel, sumPanel, phonePanel, opePanel;
// JLabel组件显示提示文本
private JLabel prodIdLabel, sumLabel;
// JTextField组件允许用户输入或显示文本
private JTextField prodIdTF, sumTF;
// JButton组件用户点击后触发保存、取消等操作
private JButton saveBtn, unSaveBtn, cancleBtn;
// 用于展示商品的表格模型
private OutTableModel outTableModel = new OutTableModel();
// 缓冲区操作的实现类,用于处理商品的存储与删除
private BufferImpl bufferImpl;
// 当前用户信息
private User user;
// 购物车中的商品列表
private Vector<Production> v;
public CloseDialog(JFrame parent,Vector<Production> v) {
super(parent,"提示");
setSize(350,130);
setLocationRelativeTo(null);
setModal(true);
setResizable(false);
this.setLayout(new FlowLayout());
this.v = v;
initView();
/**
*
* @param parent
* @param v
*/
public CloseDialog(JFrame parent, Vector<Production> v) {
super(parent, "提示"); // 设置对话框标题
setSize(350, 130); // 设置对话框窗口的大小
setLocationRelativeTo(null); // 将窗口放置在屏幕中央
setModal(true); // 设置对话框为模态,强制用户先处理此窗口才能继续操作其他窗口
setResizable(false); // 不允许调整窗口大小
this.setLayout(new FlowLayout()); // 设置窗口的布局方式为流式布局
this.v = v; // 将购物车中的商品列表传入此窗口
initView(); // 初始化界面组件
}
/**
*
*/
private void initView() {
// 创建并初始化显示产品ID的面板
prodIdPanel = new JPanel();
prodIdLabel = new JLabel("您还未结账,是否保存购物车");
prodIdPanel.add(prodIdLabel);
// 创建操作按钮的面板,并初始化按钮
opePanel = new JPanel();
saveBtn = new JButton("保存");
unSaveBtn = new JButton("不保存");
cancleBtn = new JButton("取消");
// 为按钮添加监听器,当按钮被点击时执行相应的操作
saveBtn.addActionListener(this);
unSaveBtn.addActionListener(this);
cancleBtn.addActionListener(this);
// 将按钮添加到面板中
opePanel.add(saveBtn);
opePanel.add(unSaveBtn);
opePanel.add(cancleBtn);
// 获取内容容器,并将各个面板添加到容器中
Container container = getContentPane();
container.add(prodIdPanel);
container.add(opePanel);
container.add(prodIdPanel); // 添加显示提示文本的面板
container.add(opePanel); // 添加操作按钮面板
debugLog("Initialized CloseDialog view."); // 输出调试日志,表示界面已经初始化
}
/**
*
*
*/
@Override
public void actionPerformed(ActionEvent e) {
Object source = e.getSource();
bufferImpl = new BufferImpl();
if(source==saveBtn){/*吧vector数组加入到缓冲区中*/
for(Production p:v) {
System.out.println("保存数据");
bufferImpl.insertInBuffer(p);
Object source = e.getSource(); // 获取事件源,判断点击的是哪个按钮
bufferImpl = new BufferImpl(); // 创建缓冲区操作实例
// 处理点击“保存”按钮的逻辑
if (source == saveBtn) {
debugLog("Save button clicked.");
// 遍历购物车中的所有商品,保存到缓冲区
for (Production p : v) {
debugLog("Saving product: " + p.getName()); // 打印调试信息,显示正在保存的商品
bufferImpl.insertInBuffer(p); // 将商品保存到缓冲区
}
// 结束程序
System.exit(0);
}else if(source==unSaveBtn) {
bufferImpl = new BufferImpl();
}
// 处理点击“不保存”按钮的逻辑
else if (source == unSaveBtn) {
debugLog("Don't save button clicked.");
// 删除所有缓冲区中的商品数据
bufferImpl.DelAllOutBuffer();
// 结束程序
System.exit(0);
}else if(source==cancleBtn) {
}
// 处理点击“取消”按钮的逻辑
else if (source == cancleBtn) {
debugLog("Cancel button clicked.");
// 关闭对话框,不做任何操作
setVisible(false);
}
}
}/*else if(source==WindowEvent)*/
/**
* 便
* @param message
*/
private void debugLog(String message) {
System.out.println("DEBUG: " + message); // 将调试信息输出到控制台
}
/**
*
*
* @param we
*/
public void windowClosing(WindowEvent we) {
debugLog("Window is closing.");
}
public void windowClosed(WindowEvent we) {
debugLog("Window closed.");
}
public void windowOpened(WindowEvent we) {
debugLog("Window opened.");
}
public void windowIconified(WindowEvent we) {
debugLog("Window minimized.");
}
public void windowDeiconified(WindowEvent we) {
debugLog("Window restored.");
}
public void windowActivated(WindowEvent we) {
debugLog("Window activated.");
}
public void windowDeactivated(WindowEvent we) {
debugLog("Window deactivated.");
}
}

@ -29,60 +29,59 @@ 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;
public class InDialog extends JDialog implements 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;
private Vector<Production> vAll;
private static String catalog;
public InDialog(JFrame parent,Vector<Production> v,User user) {
super(parent,"添加商品");
setSize(250,200);
setLocationRelativeTo(null);
setSize(250,200);
setLocationRelativeTo(null);
setModal(true);
setResizable(false);
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();
@ -94,19 +93,19 @@ public class InDialog extends JDialog implements ActionListener{
System.out.println(allProdId[0]);
combo = new JComboBox<String>(allProdId);
combo.addItemListener(new MyItemListener());
prodIdPanel.add(prodIdLabel);
prodIdPanel.add(combo);
sumPanel = new JPanel();
sumLabel = new JLabel("数量");
sumTF = new JTextField(10);
sumPanel.add(sumLabel);
sumPanel.add(sumTF);
opePanel = new JPanel();
addBtn = new JButton("添加");
cancelBtn = new JButton("取消");
@ -114,19 +113,19 @@ public class InDialog extends JDialog implements ActionListener{
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{
@ -136,15 +135,15 @@ public class InDialog extends JDialog implements ActionListener{
String select=(String) cb.getSelectedItem();
catalog=select;
}
}
@Override
public void actionPerformed(ActionEvent e) {
@ -153,17 +152,17 @@ public class InDialog extends JDialog implements ActionListener{
//1.判断是否存在这个商品
//2.如果存在就获取这条商品记录为一个对象
//3.判断购物缓冲区是否有这个记录
//3.1如果有update数量和price
//3.2如果没有就insert这条记录把sum更新
//3.1如果有update数量和price
//3.2如果没有就insert这条记录把sum更新
//保存到数据库
//关闭对话框
//刷新table
String prodId =catalog;
System.out.println("proId="+prodId);
System.out.println("vatalog="+catalog);
if(sumTF.getText().equals("")) {
JOptionPane.showMessageDialog(this,"请输入完整","提示",JOptionPane.ERROR_MESSAGE);
return;
@ -174,7 +173,7 @@ public class InDialog extends JDialog implements ActionListener{
JOptionPane.showMessageDialog(this,"请输入大于0的数量","提示",JOptionPane.ERROR_MESSAGE);
return;
}
//TODO 参数校验
/*/判断是已添加,未添加还是不存在*/
productionImpl productionImpl = new productionImpl();
@ -185,7 +184,7 @@ public class InDialog extends JDialog implements ActionListener{
if(production!=null) {/*商品库有这个商品存在*/
int mark = 0;
for(Production p:v) {
if(p.getId().equals(prodId)){/*如果数组中存在相同商品就更新数量和价格*/
sum=p.getSum()+sum;/*数量*/
p.setSum(sum);
@ -193,7 +192,7 @@ public class InDialog extends JDialog implements ActionListener{
mark = 1;
break;
}
}
if(mark==0) {/*插入新的*/
System.out.println("缓存区不存在,插入新的数据");
@ -201,22 +200,22 @@ public class InDialog extends JDialog implements ActionListener{
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 {/*商品库没有这个商品*/
JOptionPane.showMessageDialog(this,"商品不存在","提示",JOptionPane.ERROR_MESSAGE);
}
}
else if(source == cancelBtn) {
this.dispose();
}
}

@ -11,7 +11,6 @@ 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.*;
@ -26,140 +25,134 @@ import com.lingnan.supermarket.table.OutTableModel;
import com.lingnan.supermarket.view.OutView;
public class OutDialog extends JDialog implements ActionListener{
private JPanel prodIdPanel,sumPanel,phonePanel,opePanel;
private JLabel prodIdLabel,sumLabel;
private JTextField prodIdTF,sumTF;
private JButton addBtn,cancelBtn;
public class OutDialog extends JDialog implements ActionListener {
// 定义JPanel组件用于组织界面元素
private JPanel prodIdPanel, sumPanel, phonePanel, opePanel;
// 定义JLabel用于显示文本
private JLabel prodIdLabel, sumLabel;
// 定义JTextField用于输入商品ID和数量
private JTextField prodIdTF, sumTF;
// 定义JButton按钮用于添加商品和取消操作
private JButton addBtn, cancelBtn;
// 创建OutTableModel对象用于管理表格数据
private OutTableModel outTableModel = new OutTableModel();
// 创建Buffer对象用于暂存添加的商品信息
private Buffer buffer;
// 构造函数,初始化对话框,设置窗口属性
public OutDialog(JFrame parent) {
super(parent,"添加商品");
setSize(350,300);
setLocationRelativeTo(null);
setModal(true);
setResizable(false);
this.setLayout(new FlowLayout());
initView();
super(parent, "添加商品");
setSize(350, 300); // 设置窗口大小
setLocationRelativeTo(null); // 设置窗口居中
setModal(true); // 设置为模态对话框,阻止父窗口操作
setResizable(false); // 设置不可调整窗口大小
this.setLayout(new FlowLayout()); // 设置布局方式为流式布局
initView(); // 调用初始化界面方法
}
// 初始化界面方法
private void initView() {
// 创建商品ID输入面板
prodIdPanel = new JPanel();
prodIdLabel = new JLabel("编号");
prodIdTF = new JTextField(15);
prodIdPanel.add(prodIdLabel);
prodIdPanel.add(prodIdTF);
prodIdTF = new JTextField(15); // 设置商品ID的文本框长度为15
prodIdPanel.add(prodIdLabel); // 将标签添加到面板
prodIdPanel.add(prodIdTF); // 将文本框添加到面板
// 创建数量输入面板
sumPanel = new JPanel();
sumLabel = new JLabel("数量");
sumTF = new JTextField(15);
sumPanel.add(sumLabel);
sumPanel.add(sumTF);
sumTF = new JTextField(15); // 设置数量的文本框长度为15
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);
addBtn.addActionListener(this); // 添加按钮的事件监听
cancelBtn.addActionListener(this); // 取消按钮的事件监听
opePanel.add(addBtn); // 将添加按钮添加到面板
opePanel.add(cancelBtn); // 将取消按钮添加到面板
// 将所有面板添加到容器中
Container container = getContentPane();
container.add(prodIdPanel);
container.add(sumPanel);
container.add(opePanel);
container.add(prodIdPanel); // 添加商品ID面板
container.add(sumPanel); // 添加数量面板
container.add(opePanel); // 添加操作按钮面板
}
// 实现ActionListener接口的actionPerformed方法处理按钮点击事件
@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 =prodIdTF.getText();
System.out.println("proId="+prodId);
if(prodIdTF.getText().equals("")||sumTF.getText().equals("")) {
JOptionPane.showMessageDialog(this,"请输入完整","提示",JOptionPane.ERROR_MESSAGE);
return;
Object source = e.getSource(); // 获取触发事件的源对象
if (source == addBtn) { // 如果点击了"添加"按钮
// 获取商品ID和数量输入框的值
String prodId = prodIdTF.getText();
System.out.println("proId=" + prodId);
// 判断输入框是否为空
if (prodIdTF.getText().equals("") || 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;
// 获取数量并进行格式化转换
int sum = Integer.parseInt(sumTF.getText());
// 判断数量是否为负数
if (sum < 0) {
JOptionPane.showMessageDialog(this, "请输入大于0的数量", "提示", JOptionPane.ERROR_MESSAGE);
return; // 如果为负数,弹出提示框并返回
}
//TODO 参数校验
/*/判断是已添加,未添加还是不存在*/
// 创建生产商品的实现对象,查询商品库
productionImpl productionImpl = new productionImpl();
Production production = new Production();
production = productionImpl.findByIdProduction(prodId);
if(production!=null) {/*商品库有这个商品存在*/
buffer = new Buffer();
BufferImpl BufferImpl = new BufferImpl();
buffer = BufferImpl.findOutBufferbyId(prodId);/*判断购物车是否有这个商品了,获得已添加的sum和价格*/
int allSum = production.getSum();
if(sum<0) {
JOptionPane.showMessageDialog(this,"请输入大于0的数量","提示",JOptionPane.ERROR_MESSAGE);
production = productionImpl.findByIdProduction(prodId); // 根据商品ID查询商品
if (production != null) { // 如果商品存在
buffer = new Buffer(); // 创建缓冲区对象
BufferImpl bufferImpl = new BufferImpl();
buffer = bufferImpl.findOutBufferbyId(prodId); // 查找购物车是否已存在该商品
int allSum = production.getSum(); // 获取商品的库存数量
// 如果商品库存不足,弹出提示框并返回
if (sum > allSum) {
JOptionPane.showMessageDialog(this, "库存数量不够,库存数:" + allSum, "提示", JOptionPane.ERROR_MESSAGE);
return;
}
if(buffer!=null)/*购物缓冲区已经有添加的商品*/{
int exeistSum = buffer.getSum();
if(sum+exeistSum>allSum)/*库存不够*/{
JOptionPane.showMessageDialog(this,"库存数量不够,库存数:"+allSum,"提示",JOptionPane.ERROR_MESSAGE);
return;
}else
BufferImpl.addOutBufferExeistProd(prodId, sum, buffer);
}
else if(buffer==null){/*添加新的商品*/
if(sum>allSum)/*库存不够*/{
JOptionPane.showMessageDialog(this,"库存数量不够,库存数:"+allSum,"提示",JOptionPane.ERROR_MESSAGE);
return;
}else
BufferImpl.addOutBufferNewProd(prodId, sum);
}
this.dispose();
JOptionPane.showMessageDialog(this,"添加成功","提示",JOptionPane.ERROR_MESSAGE);
// 如果购物车中已经有该商品,更新数量和价格
if (buffer != null) {
int exeistSum = buffer.getSum(); // 获取购物车中该商品已有的数量
if (sum + exeistSum > allSum) { // 判断购物车中商品数量加起来是否超过库存
JOptionPane.showMessageDialog(this, "库存数量不够,库存数:" + allSum, "提示", JOptionPane.ERROR_MESSAGE);
return; // 如果超过库存,弹出提示框并返回
} else {
bufferImpl.addOutBufferExeistProd(prodId, sum, buffer); // 更新购物车中的商品数量
}
} else { // 如果购物车中没有该商品
bufferImpl.addOutBufferNewProd(prodId, sum); // 将商品添加到购物车
}
this.dispose(); // 关闭当前对话框
JOptionPane.showMessageDialog(this, "添加成功", "提示", JOptionPane.INFORMATION_MESSAGE); // 弹出添加成功提示
} else { // 如果商品不存在
JOptionPane.showMessageDialog(this, "商品不存在", "提示", JOptionPane.ERROR_MESSAGE); // 弹出商品不存在提示
}
else {
JOptionPane.showMessageDialog(this,"商品不存在","提示",JOptionPane.ERROR_MESSAGE);
}
}
else if(source == cancelBtn) {
this.dispose();
} else if (source == cancelBtn) { // 如果点击了"取消"按钮
this.dispose(); // 关闭当前对话框
}
}
}

@ -34,20 +34,20 @@ import com.lingnan.supermarket.view.ProdCatalogView.MyItemListener;
public class ProductionDialog extends JDialog implements ActionListener {
private JPanel namePanel, addressPanel, contactPanel,
opePanel,idPanel,inpricePanel,outpricePanel,lifePanel,
sumPanel,supplyidPanel,id2Panel,name2Panel;
opePanel,idPanel,inpricePanel,outpricePanel,lifePanel,
sumPanel,supplyidPanel,id2Panel,name2Panel;
private JLabel nameLabel, addressLabel, contactLabel,
idLabel,inpriceLabel,outpriceLabel,lifeLabel,sumLabel,
supplyidLabel,id2Label,name2Label;
idLabel,inpriceLabel,outpriceLabel,lifeLabel,sumLabel,
supplyidLabel,id2Label,name2Label;
private JTextField nameTF, addressTF, contactTF,
idTF,inpriceTF,outpriceTF,lifeTF,sumTF,
supplyidTF,id2TF,name2TF;
idTF,inpriceTF,outpriceTF,lifeTF,sumTF,
supplyidTF,id2TF,name2TF;
private JButton saveBtn, cancelBtn;
private productionService productionService = new productionImpl();
//下拉类别
private String log[]=null;
private ArrayList<String>alog=null;
@ -57,7 +57,7 @@ public class ProductionDialog extends JDialog implements ActionListener {
private JComboBox<String> combo;
private String id2;
private String name2;
//下拉供应商类别
private String superlier[]=null;
private ArrayList<String>asuperlier=null;
@ -72,7 +72,7 @@ public class ProductionDialog extends JDialog implements ActionListener {
public ProductionDialog(JFrame parent) {
super(parent, "添加");
setSize(350, 500);
@ -93,66 +93,66 @@ public class ProductionDialog extends JDialog implements ActionListener {
idPanel.add(idLabel);
idPanel.add(idTF);
namePanel = new JPanel();
nameLabel = new JLabel("名称");
nameTF = new JTextField(15);
namePanel.add(nameLabel);
namePanel.add(nameTF);
inpricePanel = new JPanel();
inpriceLabel = new JLabel("进货单价");
inpriceTF = new JTextField(15);
inpricePanel.add(inpriceLabel);
inpricePanel.add(inpriceTF);
outpricePanel = new JPanel();
outpriceLabel = new JLabel("购买单价");
outpriceTF = new JTextField(15);
outpricePanel.add(outpriceLabel);
outpricePanel.add(outpriceTF);
lifePanel = new JPanel();
lifeLabel = new JLabel("保质期(月份数)");
lifeTF = new JTextField(15);
lifePanel.add(lifeLabel);
lifePanel.add(lifeTF);
sumPanel = new JPanel();
sumLabel = new JLabel("库存");
sumTF = new JTextField(15);
sumPanel.add(sumLabel);
sumPanel.add(sumTF);
//供应商名下拉框 传递supplyid
supplyidPanel = new JPanel();
supplyidLabel = new JLabel("供应商");
// supplyidTF = new JTextField(15);
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]);
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);
@ -165,15 +165,15 @@ public class ProductionDialog extends JDialog implements ActionListener {
this.alog=pci.findNameProdCatalog();
this.log=new String[alog.size()];
for(int i=0;i<alog.size();i++)
log[i]=alog.get(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);
@ -222,8 +222,8 @@ public class ProductionDialog extends JDialog implements ActionListener {
float outprice = Float.parseFloat(outpriceTF.getText());
int life = Integer.parseInt(lifeTF.getText());
int sum = Integer.parseInt(sumTF.getText());
// TODO 参数校验
if (this.production == null) {
@ -242,7 +242,7 @@ public class ProductionDialog extends JDialog implements ActionListener {
JOptionPane.ERROR_MESSAGE);
return;
}
Production production = new Production();
production.setId(id);
production.setName(name);
@ -252,7 +252,7 @@ public class ProductionDialog extends JDialog implements ActionListener {
production.setSum(sum);
production.setSupplyId(supplyid);
production.setId2(id2);
production.setName2(name2);
production.setName2(name2);
int result = productionService.addProduction(production);
// int result = 1;
if (result == 1) {
@ -275,7 +275,7 @@ public class ProductionDialog extends JDialog implements ActionListener {
supplierInf.setAddress(address);
supplierInf.setContact(contact);
supplierInf.setId(this.supplierInf.getId());
int result = supplierInfService.updateSupplierInf(supplierInf);
if(result==1){
JOptionPane.showMessageDialog(this, "更新成功", "提示",
@ -297,15 +297,15 @@ public class ProductionDialog extends JDialog implements ActionListener {
pci =new prodCatalogImpl();
for(int i=0;i<log.length;i++){
if(name2.equals(log[i]))
id2=pci.findProdCatalogByname(name2);
id2=pci.findProdCatalogByname(name2);
}
}
}
public class MyItemListener1 implements ItemListener {
@Override
public void itemStateChanged(ItemEvent e) {
JComboBox cb = (JComboBox) e.getSource();
@ -316,6 +316,6 @@ public class ProductionDialog extends JDialog implements ActionListener {
supplyid=sii.findIdSupplierByName(suppliername);
}
}
}
}

@ -68,7 +68,7 @@ public class SupplierInfDialog extends JDialog implements ActionListener {
contactTF = new JTextField(15);
contactPanel.add(contactLabel);
contactPanel.add(contactTF);
emailPanel = new JPanel();
emailLabel = new JLabel("邮箱");
emailTF = new JTextField(15);
@ -130,7 +130,7 @@ public class SupplierInfDialog extends JDialog implements ActionListener {
supplierInf.setAddress(address);
supplierInf.setContact(contact);
supplierInf.setId(this.supplierInf.getId());
int result = supplierInfService.updateSupplierInf(supplierInf);
if(result==1){
JOptionPane.showMessageDialog(this, "更新成功", "提示",

@ -1,48 +1,189 @@
// 定义包名表明该类属于com.lingnan.supermarket.dto包
package com.lingnan.supermarket.dto;
// 导入java.util.Date类尽管在此类中没有直接使用但可能用于其他相关类或方法
import java.util.Date;
// 定义一个公共类InOrder用于表示入库订单的信息
public class InOrder {
private String iNumber;
private Float allInPrice;
private String inDate;
private String principal;
private int status;
private int delmark;
// 定义私有成员变量iNumber用于存储订单编号
private String iNumber;
// 定义私有成员变量allInPrice用于存储订单的总价
private Float allInPrice;
// 定义私有成员变量inDate用于存储订单的日期
private String inDate;
// 定义私有成员变量principal用于存储订单的负责人
private String principal;
// 定义私有成员变量status用于存储订单的状态
private int status;
// 定义私有成员变量delmark用于存储删除标记
private int delmark;
// 定义公共方法getiNumber用于获取订单编号
public String getiNumber() {
return iNumber;
return iNumber; // 返回订单编号
}
// 定义公共方法setiNumber用于设置订单编号
public void setiNumber(String iNumber) {
this.iNumber = iNumber;
this.iNumber = iNumber; // 将传入的参数赋值给成员变量iNumber
}
// 定义公共方法getAllInPrice用于获取订单的总价
public Float getAllInPrice() {
return allInPrice;
return allInPrice; // 返回订单的总价
}
// 定义公共方法setAllInPrice用于设置订单的总价
public void setAllInPrice(Float allInPrice) {
this.allInPrice = allInPrice;
this.allInPrice = allInPrice; // 将传入的参数赋值给成员变量allInPrice
}
// 定义公共方法getInDate用于获取订单的日期
public String getInDate() {
return inDate;
return inDate; // 返回订单的日期
}
// 定义公共方法setInDate用于设置订单的日期
public void setInDate(String inDate) {
this.inDate = inDate;
this.inDate = inDate; // 将传入的参数赋值给成员变量inDate
}
// 定义公共方法getPrincipal用于获取订单的负责人
public String getPrincipal() {
return principal;
return principal; // 返回订单的负责人
}
// 定义公共方法setPrincipal用于设置订单的负责人
public void setPrincipal(String principal) {
this.principal = principal;
}
public int getDelmark() {
return delmark;
}
public void setDelmark(int delmark) {
this.delmark = delmark;
this.principal = principal; // 将传入的参数赋值给成员变量principal
}
// 定义公共方法getStatus用于获取订单的状态
public int getStatus() {
return status;
return status; // 返回订单的状态
}
// 定义公共方法setStatus用于设置订单的状态
public void setStatus(int status) {
this.status = status;
this.status = status; // 将传入的参数赋值给成员变量status
}
// 定义公共方法getDelmark用于获取删除标记
public int getDelmark() {
return delmark; // 返回删除标记
}
// 定义公共方法setDelmark用于设置删除标记
public void setDelmark(int delmark) {
this.delmark = delmark; // 将传入的参数赋值给成员变量delmark
}
}

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

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

@ -1,36 +1,139 @@
// 定义包名表明该类属于com.lingnan.supermarket.dto包
package com.lingnan.supermarket.dto;
// 导入java.util.Date类用于处理日期
import java.util.Date;
// 导入com.lingnan.supermarket.dto.base.BsDomain类表示StorageRecord类继承自BsDomain
import com.lingnan.supermarket.dto.base.BsDomain;
// 定义一个公共类StorageRecord继承自BsDomain类
public class StorageRecord extends BsDomain{
private String theNumber;
private String cDate;
private int num;
private String execute;
public String getTheNumber() {
return theNumber;
}
public void setTheNumber(String theNumber) {
this.theNumber = theNumber;
}
public String getcDate() {
return cDate;
}
public void setcDate(String cDate) {
this.cDate = cDate;
}
public int getNum() {
return num;
}
public void setNum(int num) {
this.num = num;
}
public String getExecute() {
return execute;
}
public void setExecute(String execute) {
this.execute = execute;
}
// 定义私有成员变量theNumber用于存储记录编号
private String theNumber;
// 定义私有成员变量cDate用于存储记录日期
private String cDate;
// 定义私有成员变量num用于存储数量
private int num;
// 定义私有成员变量execute用于存储执行操作
private String execute;
// 定义公共方法getTheNumber用于获取记录编号
public String getTheNumber() {
return theNumber; // 返回记录编号
}
// 定义公共方法setTheNumber用于设置记录编号
public void setTheNumber(String theNumber) {
this.theNumber = theNumber; // 将传入的参数赋值给成员变量theNumber
}
// 定义公共方法getcDate用于获取记录日期
public String getcDate() {
return cDate; // 返回记录日期
}
// 定义公共方法setcDate用于设置记录日期
public void setcDate(String cDate) {
this.cDate = cDate; // 将传入的参数赋值给成员变量cDate
}
// 定义公共方法getNum用于获取数量
public int getNum() {
return num; // 返回数量
}
// 定义公共方法setNum用于设置数量
public void setNum(int num) {
this.num = num; // 将传入的参数赋值给成员变量num
}
// 定义公共方法getExecute用于获取执行操作
public String getExecute() {
return execute; // 返回执行操作
}
// 定义公共方法setExecute用于设置执行操作
public void setExecute(String execute) {
this.execute = execute; // 将传入的参数赋值给成员变量execute
}
}

@ -1,45 +1,171 @@
package com.lingnan.supermarket.dto;
import com.lingnan.supermarket.dto.base.BaseDomain;
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;
private String name; // 供应商名称
private String address; // 供应商地址
private String contact; // 供应商联系方式
private String email; // 供应商邮箱
// getEmail方法用于获取供应商邮箱
public String getEmail() {
return email;
return email; // 返回邮箱
}
// setEmail方法用于设置供应商邮箱
public void setEmail(String email) {
this.email = email;
this.email = email; // 将参数email赋值给成员变量email
}
private int delmark;
private int delmark; // 删除标记
// getDelmark方法用于获取删除标记
public int getDelmark() {
return delmark;
return delmark; // 返回删除标记
}
// setDelmark方法用于设置删除标记
public void setDelmark(int delmark) {
this.delmark = delmark;
this.delmark = delmark; // 将参数delmark赋值给成员变量delmark
}
// getName方法用于获取供应商名称
public String getName() {
return name;
return name; // 返回供应商名称
}
// setName方法用于设置供应商名称
public void setName(String name) {
this.name = name;
this.name = name; // 将参数name赋值给成员变量name
}
// getAddress方法用于获取供应商地址
public String getAddress() {
return address;
return address; // 返回供应商地址
}
// setAddress方法用于设置供应商地址
public void setAddress(String address) {
this.address = address;
this.address = address; // 将参数address赋值给成员变量address
}
// getContact方法用于获取供应商联系方式
public String getContact() {
return contact;
return contact; // 返回供应商联系方式
}
// setContact方法用于设置供应商联系方式
public void setContact(String contact) {
this.contact = contact;
}
this.contact = contact; // 将参数contact赋值给成员变量contact
}
}

@ -17,24 +17,24 @@ import com.lingnan.supermarket.dialog.InDialog;
public class InOrderTM extends AbstractTableModel{
private String [] columnName = {"订单号","总价","时间","负责人","状态"};
private productionImpl prodDao = new productionImpl();
private Vector<InOrder> InOrders;
private inOrderServiceImpl inOrderImpl= new inOrderServiceImpl();
private InOrder inOrder ;
String iNumber ;/*订单号*/
public void allInOrderRecord() {
//将添加的商品加入到静态变量Vector数组中
/*prod = InDialog.getProduction();*/
InOrders = inOrderImpl.findAllInOrder();
}
//查找分类结果
public void resultOfFind(int catalog) {
if(catalog==0)
@ -42,7 +42,7 @@ public class InOrderTM extends AbstractTableModel{
else
InOrders = inOrderImpl.FindStatus(catalog);
}
//根据订单查找
public void resultOfNumber(String Number) {
InOrders=new Vector<InOrder>();
@ -54,13 +54,13 @@ public class InOrderTM extends AbstractTableModel{
public int getRowCount() {
return InOrders.size();
}
/* public Float getAllPrice() {
return BufferImpl.InBufferAllPrice();
}
*/
/* public Float getAllPrice() {
return BufferImpl.InBufferAllPrice();
}
*/
@Override
public int getColumnCount() {
public int getColumnCount() {
return columnName.length;
}
@ -76,7 +76,7 @@ public class InOrderTM extends AbstractTableModel{
}else if(columnIndex==1) {
return inOrder.getAllInPrice();
}else if(columnIndex==2) {
return inOrder.getInDate();
return inOrder.getInDate();
}else if(columnIndex==3) {
return inOrder.getPrincipal();
}else if(columnIndex==4) {
@ -92,16 +92,16 @@ public class InOrderTM extends AbstractTableModel{
return null;
}
}
public String getINumber() { /*返回要修改或删除的记录*/
return iNumber;
}
@Override
public String getColumnName(int column) {
return columnName[column];
}
}

@ -18,42 +18,42 @@ import com.lingnan.supermarket.dialog.InDialog;
public class InRecordTM extends AbstractTableModel{
private String [] columnName = {"订单号","id","数量","金额"};
private productionImpl prodDao = new productionImpl();
private Vector<InRecord> InRecords;
private inRecordServiceImpl inRecordImpl = new inRecordServiceImpl();
private InRecord inRecord= new InRecord();
private String iNumber ;/*订单号*/
public InRecordTM(String iNumber) {
this.iNumber=iNumber;
}
public void findInRecordByINumber() {
//将添加的商品加入到静态变量Vector数组中
/*prod = InDialog.getProduction();*/
InRecords = inRecordImpl.findByIdinRecord(iNumber);
}
@Override
public int getRowCount() {
return InRecords.size();
}
/* public Float getAllPrice() {
return BufferImpl.InBufferAllPrice();
}
*/
/* public Float getAllPrice() {
return BufferImpl.InBufferAllPrice();
}
*/
@Override
public int getColumnCount() {
public int getColumnCount() {
return columnName.length;
}
@ -69,23 +69,23 @@ public class InRecordTM extends AbstractTableModel{
}else if(columnIndex==1) {
return inRecord.getId();
}else if(columnIndex==2) {
return inRecord.getSum();
return inRecord.getSum();
}else if(columnIndex==3) {
return inRecord.getInPrice();
}else {
return null;
}
}
public String getINumber() { /*返回要修改或删除的记录*/
return iNumber;
}
@Override
public String getColumnName(int column) {
return columnName[column];
}
}

@ -1,99 +1,121 @@
package com.lingnan.supermarket.table;
package com.lingnan.supermarket.table; // 定义包名表示这个类属于com.lingnan.supermarket.table包
import java.util.List;
import java.util.Vector;
import java.util.List; // 导入Java的List接口用于存储集合数据
import java.util.Vector; // 导入Java的Vector类用于存储表格数据
import javax.swing.JFrame;
import javax.swing.table.AbstractTableModel;
import javax.swing.JFrame; // 导入Swing库中的JFrame类用于创建窗口框架
import javax.swing.table.AbstractTableModel; // 导入Swing库中的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.*; // 导入impl包下的所有类可能包含数据访问层的实现类
import com.lingnan.supermarket.dialog.InDialog; // 导入自定义的InDialog类但在此代码中未使用
import com.lingnan.supermarket.dto.InOrder;
public class InTableModel extends AbstractTableModel{ // 定义一个名为InTableModel的类该类继承自AbstractTableModel类用于创建表格模型
import com.lingnan.supermarket.dto.Production;
import com.lingnan.supermarket.dto.User;
import com.lingnan.supermarket.dao.UserService;
import com.lingnan.supermarket.dao.impl.*;
import com.lingnan.supermarket.dialog.InDialog;
private String [] columnName = {"id","名称","数量","单价","价格","保质期","类别","供应商id"}; // 定义一个字符串数组,用于存储表格的列名
private productionImpl prodDao = new productionImpl(); // 创建productionImpl类的实例用于访问商品数据
private Vector<Production> v; // 声明一个Vector类型的变量用于存储商品列表
public class InTableModel extends AbstractTableModel{
private String [] columnName = {"id","名称","数量","单价","价格","保质期","类别","供应商id"};
String id ; // 声明一个String类型的变量用于存储id但未初始化和使用
private productionImpl prodDao = new productionImpl();
private Vector<Production> v;
String id ;
public InTableModel(Vector<Production> v) {
System.out.println("调用imtablemodel里面的构造函数");
this.v=v;
public InTableModel(Vector<Production> v) { // 定义一个名为InTableModel的构造函数接收Vector<Production>类型的参数
System.out.println("调用imtablemodel里面的构造函数"); // 打印信息,表示构造函数被调用
this.v=v; // 将传入的参数v赋值给成员变量v
}
// 定义一个方法getRowCount用来获取集合v中的元素数量
public int getRowCount() {
return v.size();
return v.size(); // 返回集合v的大小即元素的数量
}
// 定义一个方法getAllPrice用来计算集合v中所有Production对象的价格总和
public Float getAllPrice() {
Float allPrice=(float) 0;
for(Production p:v) {
allPrice+=p.getPrice();
Float allPrice=(float) 0; // 初始化总价格为0.0
for(Production p:v) { // 遍历集合v中的每一个Production对象
allPrice+=p.getPrice(); // 将当前Production对象的价格加到总价格上
}
return allPrice;
return allPrice; // 返回计算出的总价格
}
// 重写getColumnCount方法返回表格模型中的列数
@Override
public int getColumnCount() {
return columnName.length;
public int getColumnCount() {
return columnName.length; // 返回列名数组的长度,即列的数量
}
// 重写getValueAt方法根据行索引和列索引获取表格模型中的值
@Override
public Object getValueAt(int rowIndex, int columnIndex) {
Production p = v.get(rowIndex);
/* System.out.println( "id="+users.get(rowIndex).getId());
System.out.println("rowIndex"+rowIndex);
System.out.println("columnIndex"+columnIndex);*/
id=p.getId();
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();
}else if(columnIndex==7) {
return p.getSupplyId();
}else {
return null;
Production p = v.get(rowIndex); // 根据行索引从集合v中获取对应的Production对象
/* ID
System.out.println( "id="+users.get(rowIndex).getId());
System.out.println("rowIndex"+rowIndex);
System.out.println("columnIndex"+columnIndex); */
id=p.getId(); // 将Production对象的ID赋值给id变量
if(columnIndex==0) { // 如果列索引为0
return p.getId(); // 返回Production对象的ID
}else if(columnIndex==1) { // 如果列索引为1
return p.getName(); // 返回Production对象的名称
}else if(columnIndex==2) { // 如果列索引为2
return p.getSum(); // 返回Production对象的Sum属性
}else if(columnIndex==3) { // 如果列索引为3
return p.getInPrice(); // 返回Production对象的InPrice属性
}else if(columnIndex==4) { // 如果列索引为4
return p.getPrice(); // 返回Production对象的Price属性
}else if(columnIndex==5) { // 如果列索引为5
return p.getLife(); // 返回Production对象的Life属性
}else if(columnIndex==6) { // 如果列索引为6
return p.getName2()+p.getId2(); // 返回Production对象的Name2和Id2拼接的字符串
}else if(columnIndex==7) { // 如果列索引为7
return p.getSupplyId(); // 返回Production对象的SupplyId属性
}else { // 如果列索引不匹配上述任何情况
return null; // 返回null
}
}
// 定义一个方法getId用来获取当前对象的ID属性值
public String getId() { /*返回要修改或删除的记录*/
return id;
return id; // 返回当前对象的id字段值
}
// 重写getColumnName方法根据列索引返回对应的列名
@Override
public String getColumnName(int column) {
return columnName[column];
return columnName[column]; // 返回存储列名的数组中对应索引的列名
}
}

@ -18,76 +18,128 @@ import com.lingnan.supermarket.dao.impl.*;
import com.lingnan.supermarket.dialog.InDialog;
public class OutOrderTM extends AbstractTableModel{
private String [] columnName = {"订单号","总价","时间","负责人"};
public class OutOrderTM extends AbstractTableModel {
// 定义表格列名
private String[] columnName = {"订单号", "总价", "时间", "负责人"};
// 实现类对象,用于与数据库进行交互
private productionImpl prodDao = new productionImpl();
private Vector<OutOrder> outOrders;
private outOrderServiceImpl outOrderImpl= new outOrderServiceImpl();
private OutOrder outOrder ;
String oNumber ;/*订单号*/
// 存储所有订单记录的Vector
private Vector<OutOrder> outOrders;
// 用于从数据库获取订单数据的服务实现类
private outOrderServiceImpl outOrderImpl = new outOrderServiceImpl();
// 当前订单对象
private OutOrder outOrder;
// 当前订单号
String oNumber;
/**
*
*/
public void allOutOrderRecord() {
//将添加的商品加入到静态变量Vector数组中
/*prod = InDialog.getProduction();*/
// 调用服务层方法获取所有订单数据
outOrders = outOrderImpl.findAllOutOrder();
logMethodCall("allOutOrderRecord");
debugLog("Fetched " + outOrders.size() + " out orders.");
}
/**
*
* @param oNumber
*/
public void resultOfNumber(String oNumber) {
outOrders = new Vector<OutOrder>();
// 根据订单号查询订单
outOrder = outOrderImpl.findByIdOutOrder(oNumber);
outOrders.add(outOrder);
logMethodCall("resultOfNumber");
debugLog("Fetched order with oNumber: " + oNumber);
}
/**
*
*/
@Override
public int getRowCount() {
return outOrders.size();
}
/* public Float getAllPrice() {
return BufferImpl.InBufferAllPrice();
}
*/
/**
*
*/
@Override
public int getColumnCount() {
public int getColumnCount() {
return columnName.length;
}
/**
*
* @param rowIndex
* @param columnIndex
*/
@Override
public Object getValueAt(int rowIndex, int columnIndex) {
// 获取指定行的订单对象
outOrder = outOrders.get(rowIndex);
/* System.out.println( "id="+users.get(rowIndex).getId());
System.out.println("rowIndex"+rowIndex);
System.out.println("columnIndex"+columnIndex);*/
oNumber=outOrder.getoNumber();
if(columnIndex==0) {
// 根据列索引返回不同的订单属性
if (columnIndex == 0) {
return outOrder.getoNumber();
}else if(columnIndex==1) {
} else if (columnIndex == 1) {
return outOrder.getAllOutPrice();
}else if(columnIndex==2) {
} else if (columnIndex == 2) {
return outOrder.getoDate();
}else if(columnIndex==3) {
return outOrder.getPrincipal();
}else {
} else if (columnIndex == 3) {
return outOrder.getPrincipal();
} else {
return null;
}
}
public String getOutNumber() { /*返回要修改或删除的记录*/
/**
*
* @return
*/
public String getOutNumber() {
// 返回当前操作的订单号,用于修改或删除操作
return oNumber;
}
/**
*
* @param column
* @return
*/
@Override
public String getColumnName(int column) {
return columnName[column];
}
// 打印方法调用的日志信息
private void logMethodCall(String methodName) {
System.out.println("Method " + methodName + " was called.");
}
// 输出调试信息
private void debugLog(String message) {
System.out.println("DEBUG: " + message);
}
// 模拟查询订单的测试方法
public void testGetOutOrder() {
resultOfNumber("ORD12345"); // 使用一个示例订单号
debugLog("OutOrder with oNumber: " + oNumber + " fetched successfully.");
}
// 测试用例,模拟获取所有订单记录
public void testAllOutOrders() {
allOutOrderRecord(); // 获取所有订单
debugLog("Fetched " + outOrders.size() + " out orders.");
}
}

@ -17,82 +17,127 @@ import com.lingnan.supermarket.dao.impl.*;
import com.lingnan.supermarket.dialog.InDialog;
public class OutRecordTM extends AbstractTableModel{
/**
*
*/
public class OutRecordTM extends AbstractTableModel {
private String [] columnName = {"订单号","id","数量","金额"};
// 定义表格的列名
private String[] columnName = {"订单号", "id", "数量", "金额"};
// 用于从数据库获取商品数据的服务层对象
private productionImpl prodDao = new productionImpl();
private Vector<OutRecord> OutRecords;
// 存储所有出货记录的Vector
private Vector<OutRecord> OutRecords;
// 用于操作出货记录数据的服务实现类
private outRecordServiceImpl outRecordImpl = new outRecordServiceImpl();
private OutRecord outRecord= new OutRecord();
private String oNumber ;/*订单号*/
// 当前的出货记录对象
private OutRecord outRecord = new OutRecord();
// 当前订单号
private String oNumber;
/**
*
* @param oNumber
*/
public OutRecordTM(String oNumber) {
this.oNumber=oNumber;
this.oNumber = oNumber;
logMethodCall("OutRecordTM Constructor");
debugLog("OutRecordTM initialized with oNumber: " + oNumber);
}
/**
*
*/
public void findOutRecordByINumber() {
//将添加的商品加入到静态变量Vector数组中
/*prod = InDialog.getProduction();*/
// 调用数据库服务获取出货记录数据
OutRecords = outRecordImpl.findByIdOutRecordr(oNumber);
logMethodCall("findOutRecordByINumber");
debugLog("Fetched " + OutRecords.size() + " out records for oNumber: " + oNumber);
}
/**
*
* @return
*/
@Override
public int getRowCount() {
return OutRecords.size();
}
/* public Float getAllPrice() {
return BufferImpl.InBufferAllPrice();
}
*/
/**
*
* @return
*/
@Override
public int getColumnCount() {
public int getColumnCount() {
return columnName.length;
}
/**
*
* @param rowIndex
* @param columnIndex
* @return
*/
@Override
public Object getValueAt(int rowIndex, int columnIndex) {
outRecord = OutRecords.get(rowIndex);
/* System.out.println( "id="+users.get(rowIndex).getId());
System.out.println("rowIndex"+rowIndex);
System.out.println("columnIndex"+columnIndex);*/
oNumber=outRecord.getoNumber();
if(columnIndex==0) {
// 根据列索引返回对应的出货记录属性
if (columnIndex == 0) {
return outRecord.getoNumber();
}else if(columnIndex==1) {
} else if (columnIndex == 1) {
return outRecord.getId();
}else if(columnIndex==2) {
return outRecord.getSum();
}else if(columnIndex==3) {
return outRecord.getOutPrice();
}else {
} else if (columnIndex == 2) {
return outRecord.getSum();
} else if (columnIndex == 3) {
return outRecord.getOutPrice();
} else {
return null;
}
}
public String getONumber() { /*返回要修改或删除的记录*/
/**
*
* @return
*/
public String getONumber() {
// 返回当前操作的订单号,用于修改或删除操作
return oNumber;
}
/**
*
* @param column
* @return
*/
@Override
public String getColumnName(int column) {
return columnName[column];
}
// 打印方法调用的日志信息
private void logMethodCall(String methodName) {
System.out.println("Method " + methodName + " was called.");
}
// 输出调试信息
private void debugLog(String message) {
System.out.println("DEBUG: " + message);
}
// 模拟查询出货记录的测试方法
public void testFindOutRecord() {
findOutRecordByINumber(); // 查询指定订单号的出货记录
debugLog("OutRecord with oNumber: " + oNumber + " fetched successfully.");
}
// 测试用例,模拟获取所有出货记录
public void testAllOutRecords() {
findOutRecordByINumber(); // 获取指定订单号的出货记录
debugLog("Fetched " + OutRecords.size() + " out records for oNumber: " + oNumber);
}
}

@ -14,68 +14,114 @@ import com.lingnan.supermarket.dao.impl.*;
import com.lingnan.supermarket.dialog.OutDialog;
public class OutTableModel extends AbstractTableModel{
private String [] columnName = {"id","名称","数量","单价","价格","保质期","类别","供应商id"};
public class OutTableModel extends AbstractTableModel {
// 定义列名,表示表格的各个列的名称
private String [] columnName = {"id", "名称", "数量", "单价", "价格", "保质期", "类别", "供应商id"};
// 创建生产商品的实现类对象
private productionImpl prodDao = new productionImpl();
private Vector<Buffer> Buffers;
private BufferImpl BufferImpl = new BufferImpl();
// 定义一个Vector用于存储Buffer对象
private Vector<Buffer> Buffers;
// Buffer实现类对象用于从数据库获取购物车中的商品数据
private BufferImpl BufferImpl = new BufferImpl();
/**
*
*/
public void allOutBuffer() {
//将添加的商品加入到静态变量Vector数组中
/*prod = OutDialog.getProduction();*/
// 从数据库获取购物车中的商品信息并将其存入Buffers
Buffers = BufferImpl.allOutBuffer();
// 打印调试信息查看Buffer数据
System.out.println("Fetched " + Buffers.size() + " items from the buffer.");
}
/**
*
*/
@Override
public int getRowCount() {
// 返回购物车中商品的数量
return Buffers.size();
}
/**
*
* @return
*/
public Float getAllPrice() {
// 获取购物车中所有商品的总价格
return BufferImpl.OutBufferAllPrice();
}
/**
*
*/
@Override
public int getColumnCount() {
public int getColumnCount() {
// 返回表格列的数量
return columnName.length;
}
/**
*
* @param rowIndex
* @param columnIndex
*/
@Override
public Object getValueAt(int rowIndex, int columnIndex) {
// 获取对应的Buffer对象
Buffer Buffer = Buffers.get(rowIndex);
/* System.out.println( "id="+users.get(rowIndex).getId());
System.out.println("rowIndex"+rowIndex);
System.out.println("columnIndex"+columnIndex);*/
if(columnIndex==0) {
// 根据列的索引返回对应的Buffer属性值
if(columnIndex == 0) {
return Buffer.getId();
}else if(columnIndex==1) {
return Buffer.getName();
}else if(columnIndex==2) {
return Buffer.getSum();
}else if(columnIndex==3) {
return Buffer.getOutPrice() ;
}else if(columnIndex==4) {
return Buffer.getPrice() ;
}else if(columnIndex==5) {
} else if(columnIndex == 1) {
return Buffer.getName();
} else if(columnIndex == 2) {
return Buffer.getSum();
} else if(columnIndex == 3) {
return Buffer.getOutPrice();
} else if(columnIndex == 4) {
return Buffer.getPrice();
} else if(columnIndex == 5) {
return Buffer.getLife();
}else if(columnIndex==6) {
return Buffer.getName2()+Buffer.getId2();
}else if(columnIndex==7) {
return Buffer.getSupplyId();
}else {
return null;
} else if(columnIndex == 6) {
return Buffer.getName2() + Buffer.getId2(); // 返回类别和供应商信息的组合
} else if(columnIndex == 7) {
return Buffer.getSupplyId(); // 供应商ID
} else {
return null; // 如果列索引不在有效范围内返回null
}
}
/**
*
* @param column
*/
@Override
public String getColumnName(int column) {
// 返回列名
return columnName[column];
}
// 打印日志,记录方法的调用
private void logMethodCall(String methodName) {
// 打印方法调用的日志信息
System.out.println("Method " + methodName + " was called.");
}
// 增加调试日志
public void debugLog(String message) {
System.out.println("DEBUG: " + message);
}
// 测试用例,模拟从购物车中获取所有商品的情况
public void testGetAllOutBuffer() {
allOutBuffer(); // 调用获取所有商品的方法
debugLog("OutBuffer contains " + Buffers.size() + " items.");
}
}

@ -1,65 +1,76 @@
package com.lingnan.supermarket.table;
package com.lingnan.supermarket.table; // 定义包名表示这个类属于com.lingnan.supermarket.table包
import java.util.List;
import java.util.Vector;
import java.util.List; // 导入Java的List接口用于存储集合数据
import java.util.Vector; // 导入Java的Vector类用于存储表格数据
import javax.swing.table.AbstractTableModel;
import javax.swing.table.AbstractTableModel; // 导入Swing库中的AbstractTableModel类用于创建表格模型
import com.lingnan.supermarket.dto.Production;
import com.lingnan.supermarket.dto.User;
import com.lingnan.supermarket.dao.UserService;
import com.lingnan.supermarket.dao.impl.*;
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.*; // 导入impl包下的所有类可能包含数据访问层的实现类
public class ProdCatalogTM extends AbstractTableModel{ // 定义一个名为ProdCatalogTM的类该类继承自AbstractTableModel类用于创建表格模型
public class ProdCatalogTM extends AbstractTableModel{
private String [] columnName = {"类别id","类别名称","商品id","商品名称"};
private String [] columnName = {"类别id","类别名称","商品id","商品名称"}; // 定义一个字符串数组,用于存储表格的列名
private productionImpl prodDao = new productionImpl();
private Vector<Production> prods;
public void all() {
private productionImpl prodDao = new productionImpl(); // 创建productionImpl类的实例用于访问商品数据
private Vector<Production> prods; // 声明一个Vector类型的变量用于存储商品列表
public void all() { // 定义一个名为all的方法无参数
//查找全部数据
prods = prodDao.findAllproduction();
prods = prodDao.findAllproduction(); // 调用prodDao的findAllproduction方法获取所有商品并赋值给prods变量
}
public void ById2(Production p) {
public void ById2(Production p) { // 定义一个名为ById2的方法接收Production类型的参数
//查找全部数据
prods = prodDao.findProductionById2(p.getId2());
prods = prodDao.findProductionById2(p.getId2()); // 调用prodDao的findProductionById2方法根据id2获取商品并赋值给prods变量
}
@Override
public int getRowCount() {
return prods.size();
@Override // 标记该方法重写了父类的方法
public int getRowCount() { // 重写AbstractTableModel类的getRowCount方法用于获取表格的行数
return prods.size(); // 返回prods的大小即商品的数量
}
@Override
public int getColumnCount() {
return columnName.length;
@Override // 标记该方法重写了父类的方法
public int getColumnCount() { // 重写AbstractTableModel类的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());
@Override // 标记该方法重写了父类的方法
public Object getValueAt(int rowIndex, int columnIndex) { // 重写AbstractTableModel类的getValueAt方法用于获取表格中指定位置的值
Production prod = prods.get(rowIndex); // 从prods中获取指定行的商品
/*
System.out.println( "id="+users.get(rowIndex).getId());
System.out.println("rowIndex"+rowIndex);
System.out.println("columnIndex"+columnIndex);*/
if(columnIndex==0) {
return prod.getId2();
}else if(columnIndex==1) {
return prod.getName2();
}else if(columnIndex==2) {
return prod.getId();
}else if(columnIndex==3) {
return prod.getName();
}else {
return null;
if(columnIndex==0) { // 如果列索引为0即第一列
return prod.getId2(); // 返回类别id
}else if(columnIndex==1) { // 如果列索引为1即第二列
return prod.getName2(); // 返回类别名称
}else if(columnIndex==2) { // 如果列索引为2即第三列
return prod.getId(); // 返回商品id
}else if(columnIndex==3) { // 如果列索引为3即第四列
return prod.getName(); // 返回商品名称
}else { // 如果列索引不匹配以上任何列
return null; // 返回null
}
}
@Override
public String getColumnName(int column) {
return columnName[column];
@Override // 标记该方法重写了父类的方法
public String getColumnName(int column) { // 重写AbstractTableModel类的getColumnName方法用于获取指定列的名称
return columnName[column]; // 返回columnName数组中指定索引的列名
}
}

@ -1,75 +1,85 @@
package com.lingnan.supermarket.table;
package com.lingnan.supermarket.table; // 定义包名表示这个类属于com.lingnan.supermarket.table包
import java.util.Vector;
import java.util.Vector; // 导入Java的Vector类用于存储表格数据
import javax.swing.table.AbstractTableModel; // 导入Swing库中的AbstractTableModel类用于创建表格模型
import javax.swing.table.AbstractTableModel;
import com.lingnan.supermarket.dao.impl.storageRecordImpl; // 导入自定义的storageRecordImpl类可能用于处理存储记录的数据访问对象
import com.lingnan.supermarket.dto.StorageRecord; // 导入自定义的StorageRecord类可能用于表示存储记录的数据传输对象
import com.lingnan.supermarket.dao.impl.storageRecordImpl;
import com.lingnan.supermarket.dto.StorageRecord;
public class StorageRecordTM extends AbstractTableModel{ // 定义一个名为StorageRecordTM的类该类继承自AbstractTableModel类用于创建表格模型
public class StorageRecordTM extends AbstractTableModel{
private String [] columnName = {"订单号","操作时间","商品编号","进货+/出货-","数量"};
private String [] columnName = {"订单号","操作时间","商品编号","进货+/出货-","数量"}; // 定义一个字符串数组,用于存储表格的列名
private storageRecordImpl srDao = new storageRecordImpl();
private Vector<StorageRecord> storageRecords;
private StorageRecord storageRecord ;
String oNumber ;/*订单号*/
public void allStoragrRecord() {
private storageRecordImpl srDao = new storageRecordImpl(); // 创建一个storageRecordImpl类的实例用于操作存储记录的数据
private Vector<StorageRecord> storageRecords; // 声明一个Vector类型的变量用于存储多个StorageRecord对象
private StorageRecord storageRecord ; // 声明一个StorageRecord类型的变量用于表示单个存储记录
String oNumber ;/*订单号*/ // 声明一个String类型的变量用于存储订单号并添加注释说明
public void allStoragrRecord() { // 定义一个公共方法,用于获取所有存储记录
//将添加的商品加入到静态变量Vector数组中
/*prod = InDialog.getProduction();*/
storageRecords = srDao.findAllStorageRecord();
/*prod = InDialog.getProduction();*/ // 这行代码被注释掉了,可能是用于从对话框获取商品信息
storageRecords = srDao.findAllStorageRecord(); // 调用srDao的findAllStorageRecord方法获取所有存储记录并赋值给storageRecords变量
}
@Override
public int getRowCount() {
return storageRecords.size();
@Override // 标记该方法重写了父类的方法
public int getRowCount() { // 重写AbstractTableModel类的getRowCount方法用于获取表格的行数
return storageRecords.size(); // 返回storageRecords的大小即存储记录的数量
}
/* public Float getAllPrice() {
return BufferImpl.InBufferAllPrice();
}
*/
@Override
public int getColumnCount() {
return columnName.length;
@Override // 标记该方法重写了父类的方法
public int getColumnCount() { // 重写AbstractTableModel类的getColumnCount方法用于获取表格的列数
return columnName.length; // 返回列名数组的长度,即表格的列数
}
@Override
public Object getValueAt(int rowIndex, int columnIndex) {
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();
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;
@Override // 标记该方法重写了父类的方法
public Object getValueAt(int rowIndex, int columnIndex) { // 重写AbstractTableModel类的getValueAt方法用于获取表格中指定位置的值
storageRecord = storageRecords.get(rowIndex); // 从storageRecords中获取指定行的存储记录
/*
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) { // 如果列索引为0即第一列
return storageRecord.getTheNumber(); // 返回订单号
}else if(columnIndex==1) { // 如果列索引为1即第二列
return storageRecord.getcDate(); // 返回操作时间
}else if(columnIndex==2) { // 如果列索引为2即第三列
return storageRecord.getId(); // 返回商品编号
}else if(columnIndex==3) { // 如果列索引为3即第四列
return storageRecord.getExecute(); // 返回进货或出货标识
}else if(columnIndex==4) { // 如果列索引为4即第五列
return storageRecord.getNum(); // 返回数量
}else { // 如果列索引不匹配以上任何列
return null; // 返回null
}
}
@Override
public String getColumnName(int column) {
return columnName[column];
@Override // 标记该方法重写了父类的方法
public String getColumnName(int column) { // 重写AbstractTableModel类的getColumnName方法用于获取指定列的名称
return columnName[column]; // 返回columnName数组中指定索引的列名
}
}

@ -10,45 +10,68 @@ import com.lingnan.supermarket.dto.User;
import com.lingnan.supermarket.dao.UserService;
import com.lingnan.supermarket.dao.impl.*;
// 定义一个表格模型类,用于存储和生产相关的数据
public class StorageTableModel extends AbstractTableModel{
// 定义列名数组
private String [] columnName = {"id","名称","保质期","数量","类别","供应商编号"};
// 实例化生产数据访问对象
private productionImpl prodDao = new productionImpl();
// 声明一个向量,用于存储生产数据
private Vector<Production> prods;
// 查找所有生产数据的方法
public void all() {
//查找全部数据
// 查找全部数据并赋值给prods
prods = prodDao.findAllproduction();
}
// 根据名称查找生产数据的方法
public void Byname(Production p) {
//查找全部数据
// 查找指定名称的生产数据并赋值给prods
prods = prodDao.findproduction(p.getName());
}
// 重写获取行数的方法
@Override
public int getRowCount() {
// 返回生产数据的数量
return prods.size();
}
// 重写获取列数的方法
@Override
public int getColumnCount() {
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.getId();
}else if(columnIndex==1) {
return prod.getName();
return prod.getName();
}else if(columnIndex==2) {
return prod.getLife();
return prod.getLife();
}else if(columnIndex==3) {
return prod.getSum();
}else if(columnIndex==4) {
@ -57,13 +80,21 @@ public class StorageTableModel extends AbstractTableModel{
return prod.getSupplyId();
}else {
return null;
}
}
// 重写获取列名的方法
@Override
public String getColumnName(int column) {
// 返回指定列的列名
return columnName[column];
}
}

@ -13,18 +13,18 @@ import com.lingnan.supermarket.dao.impl.*;
public class SupplierTableModel extends AbstractTableModel{
private String [] columnName = {"id","名称","地址","联系方式","邮箱"};
private String [] columnName = {"id","名称","地址","电话","邮箱"};
//private SupplierInfImpl supplierDao = new SupplierInfImpl();
private SupplierInfService supplierInfService = new SupplierInfImpl();
private SupplierInf supplierInf = new SupplierInf();
private Vector<SupplierInf> suppliers;
private int id=0;
public void all() {
//查找全部数据
suppliers = supplierInfService.findAllSupplierInf();
@ -32,17 +32,17 @@ public class SupplierTableModel extends AbstractTableModel{
public void Byname(SupplierInf supplierInf) {
suppliers = supplierInfService.findByNameSupplierInf(supplierInf);
}
@Override
public int getRowCount() {
return suppliers.size();
}
@Override
public int getColumnCount() {
public int getColumnCount() {
return columnName.length;
}
@ -56,7 +56,7 @@ public class SupplierTableModel extends AbstractTableModel{
if(columnIndex==0) {
return prod.getId();
}else if(columnIndex==1) {
return prod.getName();
return prod.getName();
}else if(columnIndex==2) {
return prod.getAddress();
}else if(columnIndex==3) {
@ -68,12 +68,12 @@ public class SupplierTableModel extends AbstractTableModel{
return null;
}
}
@Override
public String getColumnName(int column) {
return columnName[column];
}
/*
public int getId() {
return id;
@ -88,6 +88,6 @@ public class SupplierTableModel extends AbstractTableModel{
*/
}

@ -8,6 +8,7 @@ import com.lingnan.supermarket.dto.Production;
// 用于创建订单相关文本内容
public class CreateOrder {
<<<<<<< HEAD
// 用于生成一个完整的订单文本信息,接收商品信息向量、订单编号、时间、总价以及负责人用户名等参数
public String CreateOrder(Vector<Production> v, String oNumber, String time, Float allPrice, String username) {
// 分割线
@ -18,10 +19,25 @@ public class CreateOrder {
// 添加订单小票中商品信息展示的表头部分
InRequireText += "#名称 #单价 #数量 #金额\r\n";
//循环遍历传入的商品信息向量,将每个商品的具体信息按照设定的格式拼接添加到订单文本中
=======
// 方法:生成订单小票文本
public String CreateOrder(Vector<Production> v, String oNumber, String time, Float allPrice, String username) {
// 初始化分隔符
String xx = "----------------------------------------------------------------------------\r\n";
// 订单生成时间
String InRequireText = time + "\r\n" + xx;
// 添加订单标题
InRequireText += "#名称 #单价 #数量 #金额\r\n";
// 遍历商品列表,生成订单项信息
>>>>>>> remotes/origin/main
for (Production p : v) {
InRequireText += p.getName() + " " + p.getInPrice() + " " + p.getSum() + " " + p.getPrice() + "\r\n";
}
<<<<<<< HEAD
// 添加一条分割线
InRequireText += "\r\n" + xx;
@ -39,4 +55,76 @@ public class CreateOrder {
// 返回最终生成的完整订单文本内容
return InRequireText;
}
}
}
=======
// 订单总金额
InRequireText += "\r\n" + xx;
InRequireText += "#总进货金额:" + allPrice + "元";
// 订单负责人和编号
InRequireText += "\r\n#负责人:" + username;
InRequireText += "\r\n#订单编号:" + oNumber;
// 商店信息
InRequireText += "\r\n#地址:新民超市";
InRequireText += "\r\n#联系电话:xxx";
// 加入订单备注
InRequireText += "\r\n#备注:谢谢光临,欢迎下次购买!";
// 空行分隔
InRequireText += "\r\n";
// 添加当前时间的时间戳
InRequireText += "#生成时间:" + System.currentTimeMillis() + "\r\n";
// 订单结束标记
InRequireText += "----------------------------------------------------------------------------\r\n";
// 返回生成的订单小票文本
return InRequireText;
}
// 日志记录方法(模拟)
private void logOrderCreation(String oNumber) {
// 这里模拟记录订单生成日志
System.out.println("订单创建成功,订单编号:" + oNumber);
}
// 模拟打印订单内容的方法
public void printOrder(String orderContent) {
// 打印订单内容(实际应用中可能是发送到打印机)
System.out.println(orderContent);
}
// 订单处理(模拟)方法
public void processOrder(Vector<Production> v, String oNumber, String time, Float allPrice, String username) {
// 创建订单内容
String orderContent = CreateOrder(v, oNumber, time, allPrice, username);
// 打印订单
printOrder(orderContent);
// 记录订单创建日志
logOrderCreation(oNumber);
}
// 添加订单清单格式方法
private String getOrderListFormat(Vector<Production> v) {
StringBuilder orderList = new StringBuilder();
for (Production p : v) {
orderList.append(p.getName())
.append(" - 单价: ")
.append(p.getInPrice())
.append(",数量: ")
.append(p.getSum())
.append(",金额: ")
.append(p.getPrice())
.append("\r\n");
}
return orderList.toString();
}
}
>>>>>>> remotes/origin/main

@ -9,10 +9,16 @@ import java.sql.SQLException;
import java.sql.Statement;
import java.util.Properties;
<<<<<<< HEAD
// JDBCUtil工具类用于管理数据库连接相关的操作如加载数据库配置、获取数据库连接以及释放相关资源等
public class JDBCUtil {
// 用于存储数据库连接相关的配置信息,通过读取配置文件将配置项加载到该对象中
=======
public class JDBCUtil {
// Properties对象用于加载配置文件
>>>>>>> remotes/origin/main
private static Properties properties;
// 数据库连接的URL地址
private static String url;
@ -21,14 +27,25 @@ public class JDBCUtil {
// 数据库连接的密码
private static String password;
<<<<<<< HEAD
// 静态代码块,在类加载时执行,主要用于加载数据库配置文件并注册数据库驱动,同时获取配置文件中的连接相关信息
static {
// 通过类加载器获取配置文件的输入流,该文件应位于类路径下,以便能够正确读取
InputStream inputStream = JDBCUtil.class.getClassLoader().getResourceAsStream("jdbc.properties");
// 创建一个Properties对象用于存储键值对形式的配置信息
=======
// 静态代码块用于加载配置文件和数据库驱动
static {
// 获取配置文件输入流
InputStream inputStream = JDBCUtil.class.getClassLoader().getResourceAsStream("jdbc.properties");
// 初始化Properties对象
>>>>>>> remotes/origin/main
properties = new Properties();
try {
<<<<<<< HEAD
// 将从输入流中读取配置文件的内容加载到Properties对象中
properties.load(inputStream);
} catch (IOException e) {
@ -37,14 +54,26 @@ public class JDBCUtil {
} finally {
// 在完成配置文件读取后释放资源
if (inputStream!= null) {
=======
// 加载配置文件
properties.load(inputStream);
} catch (IOException e) {
// 如果加载配置文件失败,打印错误信息
e.printStackTrace();
} finally {
// 关闭输入流
if (inputStream != null) {
>>>>>>> remotes/origin/main
try {
inputStream.close();
} catch (IOException e) {
// 关闭流失败,打印错误信息
e.printStackTrace();
}
}
}
<<<<<<< HEAD
// 注册数据库驱动
try {
// 从配置文件中获取驱动类名属性,并加载该驱动类,类加载过程会执行驱动类中相关的静态代码,完成驱动在系统中的注册
@ -58,26 +87,49 @@ public class JDBCUtil {
password = properties.getProperty("password");
} catch (ClassNotFoundException e) {
// 若找不到指定的驱动类,打印异常栈信息
=======
// 注册JDBC驱动
try {
// 加载JDBC驱动类
Class.forName(properties.getProperty("driver"));
// 获取数据库连接信息
url = properties.getProperty("url");
user = properties.getProperty("user");
password = properties.getProperty("password");
} catch (ClassNotFoundException e) {
// 如果驱动类加载失败,打印错误信息
>>>>>>> remotes/origin/main
e.printStackTrace();
}
}
/**
<<<<<<< HEAD
* DriverManagerURL
* SQLnull
*
* @return null
=======
*
*
* @return
>>>>>>> remotes/origin/main
*/
public static Connection getConn() {
try {
// 通过DriverManager获取数据库连接
return DriverManager.getConnection(url, user, password);
} catch (SQLException e) {
// 连接失败时,打印错误信息
e.printStackTrace();
return null;
}
}
/**
<<<<<<< HEAD
* ResultSetStatementConnection
* nullnullcloseSQL
*
@ -99,8 +151,97 @@ public class JDBCUtil {
if (connection!= null) {
connection.close();
}
=======
*
*
* @param resultSet
* @param statement SQL
* @param connection
*/
public static void close(ResultSet resultSet, Statement statement, Connection connection) {
try {
// 释放结果集资源
if (resultSet != null) {
resultSet.close();
}
// 释放Statement资源
if (statement != null) {
statement.close();
}
// 释放Connection资源
if (connection != null) {
connection.close();
}
>>>>>>> remotes/origin/main
} catch (SQLException e) {
// 如果关闭资源时发生错误,打印错误信息
e.printStackTrace();
}
}
}
<<<<<<< HEAD
}
=======
/**
*
*/
private static void printDbConfig() {
System.out.println("数据库连接信息:");
System.out.println("JDBC驱动" + properties.getProperty("driver"));
System.out.println("数据库URL" + properties.getProperty("url"));
System.out.println("数据库用户名:" + properties.getProperty("user"));
System.out.println("数据库密码:" + properties.getProperty("password"));
}
/**
*
*
* @return
*/
private static String getDbConnectionString() {
return "jdbc connection info: " + url + " as user " + user;
}
/**
*
*
* @return true if connection is successful, otherwise false
*/
public static boolean testConnection() {
Connection connection = null;
try {
connection = getConn();
if (connection != null) {
System.out.println("数据库连接成功!");
return true;
} else {
System.out.println("数据库连接失败!");
return false;
}
} catch (Exception e) {
System.out.println("测试数据库连接时发生异常:" + e.getMessage());
return false;
} finally {
// 关闭连接
close(null, null, connection);
}
}
/**
*
*/
private static void logConnectionStatus() {
System.out.println("正在尝试连接数据库...");
}
/**
*
*/
private static void logCloseConnection() {
System.out.println("数据库连接已关闭。");
}
}
>>>>>>> remotes/origin/main

@ -8,6 +8,7 @@ import java.util.Random;
public class TimeAndOrder {
/**
<<<<<<< HEAD
*
*
* "yyyy-MM-dd HH:mm:ss"
@ -48,10 +49,46 @@ public class TimeAndOrder {
System.out.println(s[1]); // 打印时间戳
// 返回包含订单号和时间戳的字符串数组
=======
*
* @param username
* @return
*/
public static String[] TimeAndOrder(String username) {
// 创建一个长度为2的字符串数组用于存储订单号和当前时间
String[] s = new String[2];
// 创建两个SimpleDateFormat对象分别用于不同格式的日期输出
SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); // 当前时间的格式
SimpleDateFormat sdf2 = new SimpleDateFormat("yyyyMMddHHmmss"); // 订单号日期格式(年月日时分秒)
// 获取当前时间
Calendar cal = Calendar.getInstance();
String date1 = sdf1.format(cal.getTime()); // 当前日期时间
String date2 = sdf2.format(cal.getTime()); // 订单号使用的时间
// 生成随机数,以增加订单号的随机性
Random random = new Random();
int result1 = random.nextInt(10); // 随机生成一个0到9之间的数字
int result2 = random.nextInt(10); // 随机生成另一个0到9之间的数字
// 生成订单号,将用户名、时间和随机数拼接在一起
s[0] = username + result1 + date2 + result2;
// 生成当前时间字符串
s[1] = date1;
// 打印生成的订单号和时间(调试用)
System.out.println(s[0]);
System.out.println(s[1]);
// 返回包含订单号和时间的字符串数组
>>>>>>> remotes/origin/main
return s;
}
/**
<<<<<<< HEAD
* "yyyy-MM-dd"
*
* @return
@ -68,5 +105,39 @@ public class TimeAndOrder {
// 返回当前日期的字符串表示
return date;
=======
*
* @return yyyy-MM-dd
*/
public static String yMdTime() {
// 创建一个SimpleDateFormat对象用于格式化当前日期
SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd");
// 获取当前时间
Calendar cal = Calendar.getInstance();
String date = sdf1.format(cal.getTime()); // 获取当前日期的字符串
// 返回当前日期字符串
return date;
}
/**
*
*/
public static void testMethod() {
// 输出当前时间和生成的订单号
System.out.println("Current time: " + yMdTime());
String[] orderDetails = TimeAndOrder("testUser");
System.out.println("Generated order number: " + orderDetails[0]);
System.out.println("Generated time: " + orderDetails[1]);
}
/**
*
*/
private static void logMethodCall(String methodName) {
// 模拟打印方法调用日志
System.out.println("Method " + methodName + " was called.");
>>>>>>> remotes/origin/main
}
}

@ -42,6 +42,7 @@ import com.lingnan.supermarket.utils.SendQQMailUtil;
import com.lingnan.supermarket.utils.TimeAndOrder;
import com.lingnan.supermarket.view.ProdCatalogView.MyItemListener;
<<<<<<< HEAD
/**
*
*
@ -52,9 +53,18 @@ public class InView extends JPanel implements ActionListener {
private JPanel toolBarPanel;
// 搜索面板
=======
public class InView extends JPanel implements ActionListener{
//上面
private JPanel toolBarPanel;
>>>>>>> remotes/origin/main
private JPanel searchPanel;
private JLabel nameLabel, locationLabel;
private JTextField nameSearchTF;
<<<<<<< HEAD
private JButton searchBtn, StockBtn, exitBtn;
// 操作面板
@ -77,10 +87,31 @@ public class InView extends JPanel implements ActionListener {
private static Vector<Production> v = new Vector<Production>();
// 状态下拉框
=======
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;
private static Vector<Production> v = new Vector<Production>();
>>>>>>> remotes/origin/main
private JComboBox<String> combo;
private String[] status = {"全部", "已入库", "待入库", "已取消"};
private int catalog;
<<<<<<< HEAD
// 主窗口和用户信息
private JFrame jFrame;
private User user;
@ -98,10 +129,24 @@ public class InView extends JPanel implements ActionListener {
private inOrderServiceImpl inOrderImpl;
// 总价和行数
=======
private JFrame jFrame;
private User user;
private InTableModel inTableModel ;
private BufferImpl bufferImpl = new BufferImpl();
private int mark;/*标记从提醒那里来1是进货表0是提醒过来的表*/
private inOrderServiceImpl inOrderImpl;
>>>>>>> remotes/origin/main
private Float allPrice;
private int row;
private String uname;
<<<<<<< HEAD
//构造函数
public InView(JFrame jFrame, User user, Vector<Production> v, int mark) {
@ -214,10 +259,148 @@ public class InView extends JPanel implements ActionListener {
}
//处理状态下拉框的选项变化
=======
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("订单号");
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);
toolBarPanel.add(searchPanel,"West");
toolBarPanel.add(opePanel,"East");
//中间表
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");
if(mark==1) /*判断是不是从提醒那里过来的*/{
refreshBuffer(v);
}
else if(mark==0) {
InOrderRecord();
}
setVisible(true);
}
public static Vector<Production> getVector(){
return v;
}
>>>>>>> remotes/origin/main
public class MyItemListener implements ItemListener {
@Override
public void itemStateChanged(ItemEvent e) {
<<<<<<< HEAD
JComboBox cb = (JComboBox) e.getSource(); // 获取事件源
String catalog1 = (String) cb.getSelectedItem(); // 获取选中的状态
if (catalog1.equals("全部"))
@ -228,12 +411,35 @@ public class InView extends JPanel implements ActionListener {
catalog = 2;
else if (catalog1.equals("已取消"))
catalog = 3;
=======
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);
>>>>>>> remotes/origin/main
resultOfFindStatus(catalog); // 根据状态查询结果
}
}
<<<<<<< HEAD
//按钮组件隐藏。
=======
}
//按钮组件隐藏
>>>>>>> remotes/origin/main
public void OrderView() {
backBtn.setVisible(true); // 显示返回按钮
detailBtn.setVisible(true); // 显示详情按钮
@ -243,6 +449,7 @@ public class InView extends JPanel implements ActionListener {
historyBtn.setVisible(false); // 隐藏历史记录按钮
}
<<<<<<< HEAD
//根据订单号查询结果
public void resultOfNumber(String iNumber) {
this.mark = 0; // 设置标记为0
@ -256,6 +463,20 @@ public class InView extends JPanel implements ActionListener {
}
//根据状态查询结果
=======
public void resultOfNumber(String iNumber) {
this.mark=0;
InOrderTM inOrderTM = new InOrderTM();
inOrderTM.resultOfNumber(iNumber);
inTable.setModel(inOrderTM);
bottomPanelLeft.removeAll();
countInfoLabel = new JLabel("共"+inOrderTM.getRowCount()+"条记录");
bottomPanelLeft.add(countInfoLabel);
OrderView();
}
>>>>>>> remotes/origin/main
public void resultOfFindStatus(int catalog) {
this.mark = 0; // 设置标记为0
InOrderTM inOrderTM = new InOrderTM(); // 创建进货订单表格模型
@ -267,6 +488,7 @@ public class InView extends JPanel implements ActionListener {
OrderView(); // 调用OrderView方法
}
<<<<<<< HEAD
//刷新缓冲区
public void refreshBuffer(Vector<Production> v) {
this.mark = 1; // 设置标记为1
@ -298,6 +520,63 @@ public class InView extends JPanel implements ActionListener {
bottomPanelLeft.add(countInfoLabel); // 将标签添加到底部左侧面板
OrderView(); // 调用OrderView方法
}
=======
/*刷新*/
public void refreshBuffer(Vector<Production> v) {
this.mark=1;
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 = new InOrderTM();
inOrderTM.allInOrderRecord();
inTable.setModel(inOrderTM);
bottomPanelLeft.removeAll();
countInfoLabel = new JLabel("共"+inOrderTM.getRowCount()+"条记录");
bottomPanelLeft.add(countInfoLabel);
OrderView();
}
/*调出进货订单表*/
public void InRecord(String iNumber) {
this.mark=2;
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);
}
>>>>>>> remotes/origin/main
// 调出进货订单表
public void InRecord(String iNumber) {
@ -319,6 +598,7 @@ public class InView extends JPanel implements ActionListener {
//按钮监听事件
@Override
public void actionPerformed(ActionEvent e) {
<<<<<<< HEAD
BufferImpl = new BufferImpl(); // 获取购物车
Object source = e.getSource(); // 获取事件源
@ -449,6 +729,175 @@ public class InView extends JPanel implements ActionListener {
MainView.refreshRemind(); // 刷新提醒
JOptionPane.showConfirmDialog(null, "发送邮件成功\r\n订单号:" + s[0] + "\r\n负责人:" + uname, "提示", JOptionPane.YES_OPTION); // 提示用户发送邮件成功
}
=======
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;
}
//进货表修改
if(mark==1) {
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("删除进货表");
String id =(String) inTable.getValueAt(rowIndex,0);
int select = JOptionPane.showConfirmDialog(this,"是否删除id为"+id+"的记录","提示",JOptionPane.YES_NO_OPTION);
if(select==JOptionPane.YES_OPTION) {/*选择是*/
for(int i =0;i<v.size();i++) {
System.out.println("开始删除");
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) {/*历史记录中的返回按钮*/
if(mark==0)
refreshBuffer(v);
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) {
// TODO Auto-generated catch block
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);
>>>>>>> remotes/origin/main
}
} else if (exitBtn == source) { // 如果是退出按钮
int res = JOptionPane.showConfirmDialog(null, "确定退出并清空购物车吗", "结账", JOptionPane.YES_NO_OPTION); // 提示用户确认退出
@ -459,4 +908,8 @@ public class InView extends JPanel implements ActionListener {
}
}
}
}
<<<<<<< HEAD
}
=======
}
>>>>>>> remotes/origin/main

@ -1,3 +1,4 @@
package com.lingnan.supermarket.view;
import java.awt.BorderLayout;
@ -28,195 +29,209 @@ import com.lingnan.supermarket.table.*;
import com.lingnan.supermarket.utils.FontUtil;
import com.lingnan.supermarket.utils.TimeAndOrder;
public class OutView extends JPanel implements ActionListener{
//上面
public class OutView extends JPanel implements ActionListener {
// 声明工具栏相关组件
private JPanel toolBarPanel;
// 声明搜索区域相关组件
private JPanel searchPanel;
private JLabel nameLabel,locationLabel;
private JLabel nameLabel, locationLabel;
private JTextField nameSearchTF;
private JButton searchBtn,AccountBtn,exitBtn;
private JButton searchBtn, AccountBtn, exitBtn;
// 声明操作区域相关组件
private JPanel opePanel;
private JButton addBtn,updateBtn,deleteBtn,historyBtn,backBtn,detailBtn;
//中间
private JButton addBtn, updateBtn, deleteBtn, historyBtn, backBtn, detailBtn;
// 声明中间区域的表格显示相关组件
private JScrollPane tableScrollPane;
private JTable outTable;
//下面
private JPanel bottomPanel,bottomPanelLeft,bottomPanelRight;
private JLabel countInfoLabel,countInfoLabel2;
// 声明底部区域的相关组件
private JPanel bottomPanel, bottomPanelLeft, bottomPanelRight;
private JLabel countInfoLabel, countInfoLabel2;
// 声明业务数据相关变量
private Buffer Buffer;
private BufferImpl BufferImpl;
// 声明用于展示的数据集合
private Vector<Buffer> v;
// 声明当前视图的 JFrame 和用户对象
private JFrame jFrame;
private User user;
// 声明表格数据模型
private OutTableModel outTableModel = new OutTableModel();
private int mark;/*标记订单表和订单详情表*/
public OutView(JFrame jFrame,User user) {
// 标记订单表和订单详情表的区别
private int mark;
// 构造函数,初始化视图并设置 JFrame 和用户
public OutView(JFrame jFrame, User user) {
this.setLayout(new BorderLayout());
initView();
this.jFrame = jFrame;
this.user = user;
}
// 初始化视图组件
private void initView() {
toolBarPanel = new JPanel(new BorderLayout());
searchPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
// 初始化工具栏面板,使用边界布局
toolBarPanel = new JPanel(new BorderLayout());
// 初始化搜索面板,使用流式布局
searchPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
nameLabel = new JLabel("订单号");
nameSearchTF = new JTextField(20);
// 初始化搜索按钮,并为其添加事件监听器
searchBtn = new JButton(new ImageIcon("static\\icon\\search.png"));
searchBtn.addActionListener(this);
locationLabel=new JLabel("当前位置>收银系统");
// 初始化当前位置标签
locationLabel = new JLabel("当前位置>收银系统");
locationLabel.setFont(new FontUtil().userFont);
locationLabel.setForeground(new Color(18, 150, 219));
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"));
// 初始化操作面板,使用流式布局
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"));
backBtn.setVisible(false);/*在记录页面显示出来*/
detailBtn.setVisible(false);/*在订单详情页显示出来*/
// 设置后退和详情按钮默认不可见
backBtn.setVisible(false);
detailBtn.setVisible(false);
// 为按钮添加事件监听器
addBtn.addActionListener(this);
updateBtn.addActionListener(this);
deleteBtn.addActionListener(this);
// 为按钮添加事件监听器
historyBtn.addActionListener(this);
backBtn.addActionListener(this);
detailBtn.addActionListener(this);
opePanel.add(addBtn);
// 将按钮添加到操作面板中
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);
toolBarPanel.add(searchPanel,"West");
toolBarPanel.add(opePanel,"East");
//中间表格
// 将搜索面板和操作面板添加到工具栏面板中
toolBarPanel.add(searchPanel, "West");
toolBarPanel.add(opePanel, "East");
// 中间部分的表格
outTableModel = new OutTableModel();
outTableModel.allOutBuffer();/*查找所有购物车*/
outTableModel.allOutBuffer(); // 查找所有购物车
outTable = new JTable(outTableModel);
outTable.setFont(FontUtil.tableFont);
outTable.setRowHeight(50);
tableScrollPane = new JScrollPane(outTable);
//下面
outTable.setFont(FontUtil.tableFont); // 设置表格字体
outTable.setRowHeight(50); // 设置表格行高
tableScrollPane = new JScrollPane(outTable); // 创建带滚动条的表格面板
// 下部分区域
bottomPanelLeft = new JPanel(new FlowLayout(FlowLayout.LEFT));
countInfoLabel = new JLabel("商品种类:"+outTableModel.getRowCount()+",总价:"+outTableModel.getAllPrice());
countInfoLabel = new JLabel("商品种类:" + outTableModel.getRowCount() + ", 总价:" + outTableModel.getAllPrice()); // 显示商品种类和总价
bottomPanelLeft.add(countInfoLabel);
bottomPanelRight = new JPanel(new FlowLayout(FlowLayout.RIGHT));
AccountBtn =new JButton(new ImageIcon("static\\icon\\Account.png"));/*结账按钮*/
exitBtn =new JButton(new ImageIcon("static\\icon\\exit.png"));/*退出按钮*/
AccountBtn.addActionListener(this);
exitBtn.addActionListener(this);
bottomPanelRight.add(AccountBtn);
bottomPanelRight.add(exitBtn);
AccountBtn = new JButton(new ImageIcon("static\\icon\\Account.png")); // 创建结账按钮
exitBtn = new JButton(new ImageIcon("static\\icon\\exit.png")); // 创建退出按钮
AccountBtn.addActionListener(this); // 为结账按钮添加事件监听器
exitBtn.addActionListener(this); // 为退出按钮添加事件监听器
bottomPanelRight.add(AccountBtn); // 将结账按钮添加到右侧面板
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");*/
this.add(bottomPanel,"South");
bottomPanel.add(bottomPanelRight, "East");
bottomPanel.add(bottomPanelLeft, "West");
// 将工具栏、表格和底部面板添加到主面板
this.add(toolBarPanel, "North");
this.add(tableScrollPane, "Center"); // 将表格添加到中间
this.add(bottomPanel, "South"); // 将底部面板添加到底部
// 设置界面可见
setVisible(true);
}
//按钮组件隐藏
// 按钮组件隐藏,用于切换视图
public void OrderView() {
backBtn.setVisible(true);
detailBtn.setVisible(true);
updateBtn.setVisible(false);
deleteBtn.setVisible(true);
addBtn.setVisible(false);
historyBtn.setVisible(false);
backBtn.setVisible(true); // 显示返回按钮
detailBtn.setVisible(true); // 显示详情按钮
updateBtn.setVisible(false); // 隐藏更新按钮
deleteBtn.setVisible(true); // 显示删除按钮
addBtn.setVisible(false); // 隐藏添加按钮
historyBtn.setVisible(false); // 隐藏历史按钮
}
//通过订单查找
// 通过订单号查找对应订单并更新显示
public void resultOfNumber(String oNumber) {
this.mark=1;
this.mark = 1; // 设置标记为订单详情
OutOrderTM outOrderTM = new OutOrderTM();
outOrderTM.resultOfNumber(oNumber);
outTable.setModel(outOrderTM);
bottomPanelLeft.removeAll();
countInfoLabel = new JLabel("共"+outOrderTM.getRowCount()+"条记录");
outOrderTM.resultOfNumber(oNumber); // 根据订单号查找订单
outTable.setModel(outOrderTM); // 更新表格模型
bottomPanelLeft.removeAll(); // 清空底部左侧面板
countInfoLabel = new JLabel("共" + outOrderTM.getRowCount() + "条记录"); // 显示记录条数
bottomPanelLeft.add(countInfoLabel);
OrderView();
OrderView(); // 切换到订单视图
}
/*刷新*/
// 刷新购物车数据
public void refreshOutBuffer() {
OutTableModel outTableModel = new OutTableModel();
outTableModel.allOutBuffer();
outTable.setModel(outTableModel);
bottomPanelLeft.removeAll();
countInfoLabel = new JLabel("商品种类:"+outTableModel.getRowCount()+",总价:"+outTableModel.getAllPrice());
outTableModel.allOutBuffer(); // 查询所有购物车
outTable.setModel(outTableModel); // 更新表格模型
bottomPanelLeft.removeAll(); // 清空底部左侧面板
countInfoLabel = new JLabel("商品种类:" + outTableModel.getRowCount() + ", 总价:" + outTableModel.getAllPrice()); // 显示商品种类和总价
bottomPanelLeft.add(countInfoLabel);
backBtn.setVisible(false);
detailBtn.setVisible(false);
historyBtn.setVisible(true);
updateBtn.setVisible(true);
addBtn.setVisible(true);
deleteBtn.setVisible(true);
backBtn.setVisible(false); // 隐藏返回按钮
detailBtn.setVisible(false); // 隐藏详情按钮
historyBtn.setVisible(true); // 显示历史按钮
updateBtn.setVisible(true); // 显示更新按钮
addBtn.setVisible(true); // 显示添加按钮
deleteBtn.setVisible(true); // 显示删除按钮
}
/*调出收银出货订单表*/
// 调出收银出货订单表
public void OutOrderRecord() {
this.mark=1;
this.mark = 1; // 设置标记为订单详情
OutOrderTM outOrderTM = new OutOrderTM();
outOrderTM.allOutOrderRecord();
outTable.setModel(outOrderTM);
bottomPanelLeft.removeAll();
countInfoLabel = new JLabel("共"+outOrderTM.getRowCount()+"条记录");
outOrderTM.allOutOrderRecord(); // 获取所有出货订单记录
outTable.setModel(outOrderTM); // 更新表格模型
bottomPanelLeft.removeAll(); // 清空底部左侧面板
countInfoLabel = new JLabel("共" + outOrderTM.getRowCount() + "条记录"); // 显示记录条数
bottomPanelLeft.add(countInfoLabel);
OrderView();
OrderView(); // 切换到订单视图
}
// 处理查看订单记录的逻辑
public void OutRecord(String oNumber) {
this.mark=0;
OutRecordTM outRecordTM = new OutRecordTM(oNumber);
outRecordTM.findOutRecordByINumber();
outTable.setModel(outRecordTM);
bottomPanelLeft.removeAll();
countInfoLabel = new JLabel("订单号@"+oNumber+"共有"+outRecordTM.getRowCount()+"条记录");
bottomPanelLeft.add(countInfoLabel);
this.mark = 0; // 设置标记为0表示查看历史订单
OutRecordTM outRecordTM = new OutRecordTM(oNumber); // 创建OutRecordTM实例
outRecordTM.findOutRecordByINumber(); // 根据订单号查找订单记录
outTable.setModel(outRecordTM); // 更新表格模型为查询结果
bottomPanelLeft.removeAll(); // 清空底部左侧信息面板
countInfoLabel = new JLabel("订单号@" + oNumber + "共有" + outRecordTM.getRowCount() + "条记录"); // 显示订单记录数
bottomPanelLeft.add(countInfoLabel); // 将记录数标签添加到面板
// 设置按钮的可见性
backBtn.setVisible(true);
detailBtn.setVisible(false);
updateBtn.setVisible(false);
@ -224,115 +239,116 @@ public class OutView extends JPanel implements ActionListener{
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();
resultOfNumber(number);
BufferImpl = new BufferImpl(); // 获取购物车数据
Object source = e.getSource(); // 获取触发事件的源对象
// 搜索按钮点击事件
if (searchBtn == source) {
String number = nameSearchTF.getText(); // 获取输入的订单号
resultOfNumber(number); // 根据订单号查找对应订单
}
if(addBtn==source) {
OutDialog outDialog = new OutDialog(jFrame);
outDialog.setVisible(true);
refreshOutBuffer();
// 添加按钮点击事件
if (addBtn == source) {
OutDialog outDialog = new OutDialog(jFrame); // 创建并显示“添加”对话框
outDialog.setVisible(true);
refreshOutBuffer(); // 刷新购物车数据
}
else if(updateBtn==source) {
int rowIndex = outTable.getSelectedRow();
if(rowIndex==-1) {
JOptionPane.showMessageDialog(this,"请选中一条进行更改数量");
return;
}
String id =(String) outTable.getValueAt(rowIndex,0);
ChangeSumDialog changesumDialog = new ChangeSumDialog(jFrame,id,"Out");
changesumDialog.setVisible(true);
refreshOutBuffer();
// 更新按钮点击事件
else if (updateBtn == source) {
int rowIndex = outTable.getSelectedRow(); // 获取选中的行索引
if (rowIndex == -1) {
JOptionPane.showMessageDialog(this, "请选中一条进行更改数量");
return;
}
String id = (String) outTable.getValueAt(rowIndex, 0); // 获取选中行的ID
ChangeSumDialog changesumDialog = new ChangeSumDialog(jFrame, id, "Out"); // 创建并显示“更改数量”对话框
changesumDialog.setVisible(true);
refreshOutBuffer(); // 刷新购物车数据
}
else if(deleteBtn==source) {
int rowIndex = outTable.getSelectedRow();
if(rowIndex==-1) {
JOptionPane.showMessageDialog(this,"请选中一条");
return;
}
String id =(String) outTable.getValueAt(rowIndex,0);
int select = JOptionPane.showConfirmDialog(this,"是否删除id为"+id+"的记录","提示",JOptionPane.YES_NO_OPTION);
if(select==JOptionPane.YES_OPTION) {/*选择是*/
if(BufferImpl.DelOutBufferById(id)==true) {
JOptionPane.showMessageDialog(this,"删除成功","提示",JOptionPane.INFORMATION_MESSAGE);
}else {
JOptionPane.showMessageDialog(this,"删除失败","提示",JOptionPane.ERROR_MESSAGE);
}
refreshOutBuffer();
}
}else if(historyBtn==source) {/*查看历史全部记录*/
OutOrderRecord();
}else if(backBtn==source) {/*历史记录中的返回按钮*/
System.out.println("outView中的mark="+mark);
if(mark==1) {
refreshOutBuffer();
}else if(mark==0) {
OutOrderRecord();
// 删除按钮点击事件
else if (deleteBtn == source) {
int rowIndex = outTable.getSelectedRow(); // 获取选中的行索引
if (rowIndex == -1) {
JOptionPane.showMessageDialog(this, "请选中一条");
return;
}
String id = (String) outTable.getValueAt(rowIndex, 0); // 获取选中行的ID
int select = JOptionPane.showConfirmDialog(this, "是否删除id为" + id + "的记录", "提示", JOptionPane.YES_NO_OPTION);
if (select == JOptionPane.YES_OPTION) { // 如果选择“是”
if (BufferImpl.DelOutBufferById(id) == true) { // 删除购物车中的记录
JOptionPane.showMessageDialog(this, "删除成功", "提示", JOptionPane.INFORMATION_MESSAGE);
} else {
JOptionPane.showMessageDialog(this, "删除失败", "提示", JOptionPane.ERROR_MESSAGE);
}
refreshOutBuffer(); // 刷新购物车数据
}
}
// 查看历史记录按钮点击事件
else if (historyBtn == source) {
OutOrderRecord(); // 查看出货历史订单记录
}
// 返回按钮点击事件
else if (backBtn == source) {
System.out.println("outView中的mark=" + mark);
if (mark == 1) {
refreshOutBuffer(); // 刷新购物车数据
} else if (mark == 0) {
OutOrderRecord(); // 刷新出货历史记录
}
}else if(detailBtn==source) {/*查看订单详细*/
int rowIndex = outTable.getSelectedRow();
if(rowIndex==-1) {
JOptionPane.showMessageDialog(this,"请选中一条查看订单详细信息");
}
// 查看订单详情按钮点击事件
else if (detailBtn == source) {
int rowIndex = outTable.getSelectedRow(); // 获取选中的行索引
if (rowIndex == -1) {
JOptionPane.showMessageDialog(this, "请选中一条查看订单详细信息");
return;
}
String oNumber =(String) outTable.getValueAt(rowIndex,0);
System.out.println("详情订单号为="+oNumber);
OutRecord(oNumber);
String oNumber = (String) outTable.getValueAt(rowIndex, 0); // 获取订单号
System.out.println("详情订单号为=" + oNumber);
OutRecord(oNumber); // 查看订单详情
}
else if(AccountBtn==source) {/*结账*/
refreshOutBuffer();
v = BufferImpl.allOutBuffer();
if(v.size()==0)/*购物车为空*/{
JOptionPane.showMessageDialog(null,"您的购物车为空", "提示", JOptionPane.YES_OPTION);
}
else {/*购物车不为空*/
int res = JOptionPane.showConfirmDialog(null,"总金额:"+outTableModel.getAllPrice()+"元\r\n是否已经结账", "结账", JOptionPane.YES_NO_OPTION);
if(res==JOptionPane.YES_OPTION)/*如果已经结账*/{
String[] s =TimeAndOrder.TimeAndOrder(user.getUsername());/*获得时间和订单号*/
BufferImpl.InsertOutOrder(s[0],outTableModel.getAllPrice(), s[1], user.getUsername());/*往订单表插入一条记录*/
for(int i=0;i<v.size();i++) {
Buffer = v.elementAt(i);
BufferImpl.Account(s[0],s[1],Buffer.getId(),Buffer.getSum(),Buffer.getPrice());/*调用结账存储过程*/
}
refreshOutBuffer();/*刷新所有购物车*/
HomeView.refreshHome();/*刷新首页*/
JOptionPane.showConfirmDialog(null,"支付成功\r\n订单号:"+s[0]+"\r\n负责人:"+user.getUsername(), "提示", JOptionPane.YES_OPTION);
}
// 结账按钮点击事件
else if (AccountBtn == source) {
refreshOutBuffer(); // 刷新购物车数据
v = BufferImpl.allOutBuffer(); // 获取购物车中的所有商品
if (v.size() == 0) { // 如果购物车为空
JOptionPane.showMessageDialog(null, "您的购物车为空", "提示", JOptionPane.YES_OPTION);
} else { // 如果购物车不为空
int res = JOptionPane.showConfirmDialog(null, "总金额:" + outTableModel.getAllPrice() + "元\r\n是否已经结账", "结账", JOptionPane.YES_NO_OPTION);
if (res == JOptionPane.YES_OPTION) { // 如果选择“已结账”
String[] s = TimeAndOrder.TimeAndOrder(user.getUsername()); // 获取时间和订单号
BufferImpl.InsertOutOrder(s[0], outTableModel.getAllPrice(), s[1], user.getUsername()); // 插入订单记录
for (int i = 0; i < v.size(); i++) {
Buffer = v.elementAt(i);
BufferImpl.Account(s[0], s[1], Buffer.getId(), Buffer.getSum(), Buffer.getPrice()); // 调用结账存储过程
}
}else if(exitBtn==source) {
refreshOutBuffer();
int res = JOptionPane.showConfirmDialog(null,"确定退出并清空购物车吗", "结账", JOptionPane.YES_NO_OPTION);
if(res==JOptionPane.YES_OPTION)/*如果已经结账*/{
BufferImpl.DelAllOutBuffer();
refreshOutBuffer();/*刷新所有购物车*/
JOptionPane.showConfirmDialog(null,"退出成功", "提示", JOptionPane.PLAIN_MESSAGE);
refreshOutBuffer(); // 刷新购物车数据
HomeView.refreshHome(); // 刷新首页
JOptionPane.showConfirmDialog(null, "支付成功\r\n订单号:" + s[0] + "\r\n负责人:" + user.getUsername(), "提示", JOptionPane.YES_OPTION);
}
}
}
// 退出按钮点击事件
else if (exitBtn == source) {
refreshOutBuffer(); // 刷新购物车数据
int res = JOptionPane.showConfirmDialog(null, "确定退出并清空购物车吗", "结账", JOptionPane.YES_NO_OPTION);
if (res == JOptionPane.YES_OPTION) { // 如果选择“是”
BufferImpl.DelAllOutBuffer(); // 清空购物车
refreshOutBuffer(); // 刷新购物车数据
JOptionPane.showConfirmDialog(null, "退出成功", "提示", JOptionPane.PLAIN_MESSAGE);
}
}
}
}

@ -65,7 +65,7 @@ public class ProdCatalogView extends JPanel {
initView();
this.jFrame = jFrame;
}
private void initView() {
@ -92,21 +92,21 @@ public class ProdCatalogView extends JPanel {
// 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);
log[i]=alog.get(i);
for(int i=0;i<log.length;i++)
{
System.out.println(log[i]);
System.out.println(log[i]);
}
combo = new JComboBox<String>(log);
combo.addItemListener(new MyItemListener());
@ -163,8 +163,8 @@ public class ProdCatalogView extends JPanel {
pci =new prodCatalogImpl();
for(int i=0;i<log.length;i++){
if(catalog1.equals(log[i]))
catalog=pci.findProdCatalogByname(catalog1);
System.out.println(catalog);
}

@ -1,224 +1,234 @@
package com.lingnan.supermarket.view;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.ImageIcon;
import javax.swing.JButton;
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 com.lingnan.supermarket.dao.productionService;
import com.lingnan.supermarket.dao.impl.productionImpl;
import com.lingnan.supermarket.dialog.ProductionDialog;
import com.lingnan.supermarket.dialog.UserDialog;
import com.lingnan.supermarket.dto.Production;
import com.lingnan.supermarket.table.StorageRecordTM;
import com.lingnan.supermarket.table.StorageTableModel;
import com.lingnan.supermarket.utils.FontUtil;
public class StorageView extends JPanel implements ActionListener{
package 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.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类并实现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 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 JScrollPane tableScrollPane; // 表格滚动面板变量声明
private JTable storageTable; // 表格变量声明
//下面
private JPanel bottomPanel;
private JLabel countInfoLabel;
private StorageTableModel storageTableModel ;
private JFrame jFrame;
private productionService productionService=new productionImpl();
public StorageView(JFrame jFrame) {
this.setLayout(new BorderLayout());
initView();
this.jFrame = jFrame;
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; // 设置窗口引用
}
private void initView() {
toolBarPanel = new JPanel(new BorderLayout());
searchPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
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));
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");
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")); // 创建更新按钮并设置图标
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);
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));
countInfoLabel = new JLabel("总共"+storageTableModel.getRowCount()+"条");
bottomPanel.add(countInfoLabel);
this.add(toolBarPanel,"North");
this.add(tableScrollPane,"Center");/*将表格放到中间*/
this.add(bottomPanel,"South");
setVisible(true);
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) {
public void actionPerformed(ActionEvent e) { // 重写actionPerformed方法以处理按钮点击事件
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();
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) {
else if(deleteBtn==source) { // 如果事件源是删除按钮
//获取选中记录,删除
int[] rowIndexs = storageTable.getSelectedRows();
if(rowIndexs.length==0) {
JOptionPane.showMessageDialog(this,"请至少选中一条");
return;
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);
if(productionService.deleteProduction(id)==1) {
}else {
JOptionPane.showMessageDialog(this,"删除失败,id="+id,"提示",JOptionPane.ERROR_MESSAGE);
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);
JOptionPane.showMessageDialog(this,"删除操作结束","提示",JOptionPane.INFORMATION_MESSAGE); // 显示删除操作结束信息
}
refreshProduction();
refreshProduction(); // 刷新数据
}else if(source==searchBtn){
refreshFindRname();
}else if(source==searchBtn){ // 如果事件源是搜索按钮
refreshFindRname(); // 刷新搜索结果
}
}
public void refreshFindRname() {
String name = nameSearchTF.getText();
Production p=new Production();
p.setName(name);
storageTableModel = new StorageTableModel();
storageTableModel.Byname(p);
storageTable.setModel(storageTableModel);
public void refreshFindRname() { // 刷新搜索结果的方法
String name = nameSearchTF.getText(); // 获取搜索框中的文本
Production p=new Production(); // 创建Production对象
p.setName(name); // 设置Production对象的名称
storageTableModel = new StorageTableModel(); // 创建新的存储表格模型
storageTableModel.Byname(p); // 根据名称过滤数据
storageTable.setModel(storageTableModel); // 更新表格模型
//同时更新下面的记录数
refreshCount();
hiddinBtn();
refreshCount(); // 刷新记录数
hiddinBtn(); // 隐藏按钮
}
public void refreshProduction() {
storageTableModel = new StorageTableModel();
storageTableModel.all();
storageTable.setModel(storageTableModel);
public void refreshProduction() { // 刷新生产数据的方法
storageTableModel = new StorageTableModel(); // 创建新的存储表格模型
storageTableModel.all(); // 加载所有数据
storageTable.setModel(storageTableModel); // 更新表格模型
//同时更新下面的记录数
refreshCount();
hiddinBtn();
refreshCount(); // 刷新记录数
hiddinBtn(); // 隐藏按钮
}
public void refreshCount(){
bottomPanel.removeAll();
countInfoLabel = new JLabel("总共"+storageTableModel.getRowCount()+"条");
bottomPanel.add(countInfoLabel);
hiddinBtn();
public void refreshCount(){ // 刷新记录数的方法
bottomPanel.removeAll(); // 清除底部面板上的所有组件
countInfoLabel = new JLabel("总共"+storageTableModel.getRowCount()+"条"); // 创建新的记录数标签
bottomPanel.add(countInfoLabel); // 将记录数标签添加到底部面板
hiddinBtn(); // 隐藏按钮
}
public void storageRecord() {
StorageRecordTM storageRecordTM= new StorageRecordTM();
storageRecordTM.allStoragrRecord();
storageTable.setModel(storageRecordTM);
StorageRecordTM storageRecordTM= new 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);
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);
backBtn.setVisible(false); // 设置返回按钮不可见
updateBtn.setVisible(true); // 设置更新按钮可见
addBtn.setVisible(true); // 设置添加按钮可见
historyBtn.setVisible(true); // 设置历史按钮可见
deleteBtn.setVisible(true); // 设置删除按钮可见
}

@ -1,37 +1,37 @@
package com.lingnan.supermarket.view;
package com.lingnan.supermarket.view; // 定义包名表示这段代码属于com.lingnan.supermarket.view这个包
import java.awt.BorderLayout;
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类用于在事件调度线程中执行代码
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.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() { // 定义一个私有的初始化视图的方法
public class SuperView extends JPanel{
private JLabel label;
private JFrame jFrame;
public SuperView(JFrame jFrame) {
this.setLayout(new BorderLayout());
initView();
this.jFrame = jFrame;
}
private void initView() {
//中间
label = new JLabel();
label.setIcon(new ImageIcon("static\\img\\3.png"));
label.setHorizontalAlignment(SwingUtilities.CENTER);
label.setVerticalAlignment(SwingUtilities.CENTER);
this.add(label,"Center");
setVisible(true);
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); // 设置面板可见
}
}

@ -1,177 +1,183 @@
package com.lingnan.supermarket.view;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.ImageIcon;
import javax.swing.JButton;
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 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{
package 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 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 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) {
this.setLayout(new BorderLayout());
initView();
this.jFrame = jFrame;
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());
searchPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
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));
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");
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")); // 创建更新按钮并设置图标
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 supplierTableModel = new SupplierTableModel();
supplierTableModel.all();
supplierTable = new JTable(supplierTableModel);
supplierTable.setFont(FontUtil.tableFont);
supplierTable.setRowHeight(50);
tableScrollPane = new JScrollPane(supplierTable);/*滑动条*/
supplierTableModel = new SupplierTableModel(); // 创建供应商表格模型实例
supplierTableModel.all(); // 调用表格模型的方法以加载所有数据
supplierTable = new JTable(supplierTableModel); // 创建表格并使用供应商表格模型
supplierTable.setFont(FontUtil.tableFont); // 设置表格字体
supplierTable.setRowHeight(50); // 设置表格行高为50像素
tableScrollPane = new JScrollPane(supplierTable); // 创建滚动面板并添加表格/*滑动条*/
//下面
bottomPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
countInfoLabel = new JLabel("总共"+supplierTableModel.getRowCount()+"条");
bottomPanel.add(countInfoLabel);
this.add(toolBarPanel,"North");
this.add(tableScrollPane,"Center");/*将表格放到中间*/
this.add(bottomPanel,"South");
setVisible(true);
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) {
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) {
public void actionPerformed(ActionEvent e) { // 重写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);
int select=JOptionPane.showConfirmDialog(this,"是否删除id="+id,"提示",JOptionPane.YES_NO_OPTION);
if(select==JOptionPane.YES_OPTION){
if(supplierInfService.deleteSupplierInf(id)==1) {
JOptionPane.showMessageDialog(this,"删除成功","提示",JOptionPane.INFORMATION_MESSAGE);
refreshSupplier();
}else {
JOptionPane.showMessageDialog(this,"删除失败","提示",JOptionPane.ERROR_MESSAGE);
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) { // 尝试删除供应商信息
JOptionPane.showMessageDialog(this,"删除成功","提示",JOptionPane.INFORMATION_MESSAGE); // 显示删除成功信息
refreshSupplier(); // 刷新供应商列表
}else {
JOptionPane.showMessageDialog(this,"删除失败","提示",JOptionPane.ERROR_MESSAGE); // 显示删除失败信息
}
}
}else{
System.out.println("搜索");
refreshFindRname();
}else{ // 如果事件源不是以上按钮
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 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 refreshSupplier() { // 刷新供应商列表的方法
supplierTableModel = new SupplierTableModel(); // 创建供应商表格模型
supplierTableModel.all(); // 加载所有供应商信息
supplierTable.setModel(supplierTableModel); // 更新表格模型
refreshCount(); // 刷新记录数显示
}
public void refreshCount(){
bottomPanel.removeAll();
countInfoLabel = new JLabel("总共"+supplierTableModel.getRowCount()+"条");
bottomPanel.add(countInfoLabel);
public void refreshCount(){ // 刷新记录数显示的方法
bottomPanel.removeAll(); // 清除底部面板上的所有组件
countInfoLabel = new JLabel("总共"+supplierTableModel.getRowCount()+"条"); // 创建新的记录数标签
bottomPanel.add(countInfoLabel); // 将记录数标签添加到底部面板
}
}
}

@ -1,14 +1,19 @@
<<<<<<< HEAD
123 445666+6
111
2222
=======
123
z1 z2 13131
d11111
d2
d3
>>>>>>> remotes/origin/developer
d4w
d5
d6
d7
顶顶顶
444444
11111
Z4
Loading…
Cancel
Save