diff --git a/Supermarket/bin/com/lingnan/supermarket/componet/BGPanel.class b/Supermarket/bin/com/lingnan/supermarket/componet/BGPanel.class index a42e4a1..6b0e55c 100644 Binary files a/Supermarket/bin/com/lingnan/supermarket/componet/BGPanel.class and b/Supermarket/bin/com/lingnan/supermarket/componet/BGPanel.class differ diff --git a/Supermarket/bin/com/lingnan/supermarket/dao/impl/outOrderServiceImpl.class b/Supermarket/bin/com/lingnan/supermarket/dao/impl/outOrderServiceImpl.class index d1062dc..21ab99d 100644 Binary files a/Supermarket/bin/com/lingnan/supermarket/dao/impl/outOrderServiceImpl.class and b/Supermarket/bin/com/lingnan/supermarket/dao/impl/outOrderServiceImpl.class differ diff --git a/Supermarket/bin/com/lingnan/supermarket/dao/impl/outRecordServiceImpl.class b/Supermarket/bin/com/lingnan/supermarket/dao/impl/outRecordServiceImpl.class index c84096e..7baa27c 100644 Binary files a/Supermarket/bin/com/lingnan/supermarket/dao/impl/outRecordServiceImpl.class and b/Supermarket/bin/com/lingnan/supermarket/dao/impl/outRecordServiceImpl.class differ diff --git a/Supermarket/bin/com/lingnan/supermarket/dao/impl/prodCatalogImpl.class b/Supermarket/bin/com/lingnan/supermarket/dao/impl/prodCatalogImpl.class index dfab04b..cf4cbfd 100644 Binary files a/Supermarket/bin/com/lingnan/supermarket/dao/impl/prodCatalogImpl.class and b/Supermarket/bin/com/lingnan/supermarket/dao/impl/prodCatalogImpl.class differ diff --git a/Supermarket/bin/com/lingnan/supermarket/dao/impl/storageRecordImpl.class b/Supermarket/bin/com/lingnan/supermarket/dao/impl/storageRecordImpl.class index a4ab5e5..696d216 100644 Binary files a/Supermarket/bin/com/lingnan/supermarket/dao/impl/storageRecordImpl.class and b/Supermarket/bin/com/lingnan/supermarket/dao/impl/storageRecordImpl.class differ diff --git a/Supermarket/bin/com/lingnan/supermarket/utils/CreateOrder.class b/Supermarket/bin/com/lingnan/supermarket/utils/CreateOrder.class index b89e86a..57d07cd 100644 Binary files a/Supermarket/bin/com/lingnan/supermarket/utils/CreateOrder.class and b/Supermarket/bin/com/lingnan/supermarket/utils/CreateOrder.class differ diff --git a/Supermarket/bin/com/lingnan/supermarket/utils/DateUtil.class b/Supermarket/bin/com/lingnan/supermarket/utils/DateUtil.class index 1c69283..7129ff2 100644 Binary files a/Supermarket/bin/com/lingnan/supermarket/utils/DateUtil.class and b/Supermarket/bin/com/lingnan/supermarket/utils/DateUtil.class differ diff --git a/Supermarket/bin/com/lingnan/supermarket/utils/EmailTest.class b/Supermarket/bin/com/lingnan/supermarket/utils/EmailTest.class index 41a0d5c..2a92b22 100644 Binary files a/Supermarket/bin/com/lingnan/supermarket/utils/EmailTest.class and b/Supermarket/bin/com/lingnan/supermarket/utils/EmailTest.class differ diff --git a/Supermarket/bin/com/lingnan/supermarket/utils/JDBCUtil.class b/Supermarket/bin/com/lingnan/supermarket/utils/JDBCUtil.class index c16b29d..ffef5cd 100644 Binary files a/Supermarket/bin/com/lingnan/supermarket/utils/JDBCUtil.class and b/Supermarket/bin/com/lingnan/supermarket/utils/JDBCUtil.class differ diff --git a/Supermarket/bin/com/lingnan/supermarket/utils/Test.class b/Supermarket/bin/com/lingnan/supermarket/utils/Test.class index 689a24d..2d1db8c 100644 Binary files a/Supermarket/bin/com/lingnan/supermarket/utils/Test.class and b/Supermarket/bin/com/lingnan/supermarket/utils/Test.class differ diff --git a/Supermarket/bin/com/lingnan/supermarket/utils/TimeAndOrder.class b/Supermarket/bin/com/lingnan/supermarket/utils/TimeAndOrder.class index b65128c..73eb6dd 100644 Binary files a/Supermarket/bin/com/lingnan/supermarket/utils/TimeAndOrder.class and b/Supermarket/bin/com/lingnan/supermarket/utils/TimeAndOrder.class differ diff --git a/Supermarket/bin/com/lingnan/supermarket/utils/tplbTest$1.class b/Supermarket/bin/com/lingnan/supermarket/utils/tplbTest$1.class index 4f46f87..d530c2e 100644 Binary files a/Supermarket/bin/com/lingnan/supermarket/utils/tplbTest$1.class and b/Supermarket/bin/com/lingnan/supermarket/utils/tplbTest$1.class differ diff --git a/Supermarket/bin/com/lingnan/supermarket/utils/tplbTest.class b/Supermarket/bin/com/lingnan/supermarket/utils/tplbTest.class index 8eb35e4..eea6747 100644 Binary files a/Supermarket/bin/com/lingnan/supermarket/utils/tplbTest.class and b/Supermarket/bin/com/lingnan/supermarket/utils/tplbTest.class differ diff --git a/Supermarket/bin/com/lingnan/supermarket/view/InView$MyItemListener.class b/Supermarket/bin/com/lingnan/supermarket/view/InView$MyItemListener.class index 998ea75..8dc13e9 100644 Binary files a/Supermarket/bin/com/lingnan/supermarket/view/InView$MyItemListener.class and b/Supermarket/bin/com/lingnan/supermarket/view/InView$MyItemListener.class differ diff --git a/Supermarket/bin/com/lingnan/supermarket/view/InView.class b/Supermarket/bin/com/lingnan/supermarket/view/InView.class index c6d8d22..ac7d0fc 100644 Binary files a/Supermarket/bin/com/lingnan/supermarket/view/InView.class and b/Supermarket/bin/com/lingnan/supermarket/view/InView.class differ diff --git a/Supermarket/bin/com/lingnan/supermarket/view/MainView.class b/Supermarket/bin/com/lingnan/supermarket/view/MainView.class index 929ad49..3e699f8 100644 Binary files a/Supermarket/bin/com/lingnan/supermarket/view/MainView.class and b/Supermarket/bin/com/lingnan/supermarket/view/MainView.class differ diff --git a/Supermarket/bin/com/lingnan/supermarket/view/Nimbus.class b/Supermarket/bin/com/lingnan/supermarket/view/Nimbus.class index 8416915..1705b38 100644 Binary files a/Supermarket/bin/com/lingnan/supermarket/view/Nimbus.class and b/Supermarket/bin/com/lingnan/supermarket/view/Nimbus.class differ diff --git a/Supermarket/bin/com/lingnan/supermarket/view/base/BaseView.class b/Supermarket/bin/com/lingnan/supermarket/view/base/BaseView.class index 0f912c1..b5217a2 100644 Binary files a/Supermarket/bin/com/lingnan/supermarket/view/base/BaseView.class and b/Supermarket/bin/com/lingnan/supermarket/view/base/BaseView.class differ diff --git a/Supermarket/src/com/lingnan/supermarket/componet/BGPanel.java b/Supermarket/src/com/lingnan/supermarket/componet/BGPanel.java index a953dc7..44f891d 100644 --- a/Supermarket/src/com/lingnan/supermarket/componet/BGPanel.java +++ b/Supermarket/src/com/lingnan/supermarket/componet/BGPanel.java @@ -8,16 +8,16 @@ public class BGPanel extends JPanel{ private Image image; public BGPanel(Image image) { - // 定义一个构造方法,接收一个Image类型的参数image,用于创建BGPanel对象时传入要显示的图像 + // 定义构造方法 this.image = image; // 将传入的参数image赋值给类的成员变量image int width = Toolkit.getDefaultToolkit().getScreenSize().width; - // 通过默认工具包(Toolkit)获取屏幕的宽度,存储在局部变量width中 + // 通过默认工具包(Toolkit)获取屏幕的宽度 int height = Toolkit.getDefaultToolkit().getScreenSize().height; - // 通过默认工具包(Toolkit)获取屏幕的高度,存储在局部变量height中 + // 通过默认工具包(Toolkit)获取屏幕的高度 this.setSize(width, height); - // 设置该面板(BGPanel)的大小为整个屏幕的大小,即宽度和高度分别为获取到的屏幕宽高 + // 设置该面板的大小为整个屏幕的大小 } public BGPanel(Image image, int width, int height) { @@ -37,7 +37,6 @@ public class BGPanel extends JPanel{ // 调用父类(JPanel)的paintComponent方法,以确保完成一些默认的绘制操作,比如背景清除等 g.drawImage(image, 0, 0, getWidth(), getHeight(), this); - // 使用传入的Graphics对象g在面板上绘制图像,参数含义如下: // image:要绘制的图像对象,就是之前保存的成员变量image // 0, 0:表示在面板上绘制图像的起始坐标(x坐标和y坐标),这里从面板的左上角(0, 0)位置开始绘制 // getWidth(), getHeight():获取当前面板的宽度和高度,用于指定绘制图像时按照面板的实际大小进行拉伸或缩放,确保图像填满整个面板 diff --git a/Supermarket/src/com/lingnan/supermarket/dao/impl/outOrderServiceImpl.java b/Supermarket/src/com/lingnan/supermarket/dao/impl/outOrderServiceImpl.java index dd7af64..bcdd022 100644 --- a/Supermarket/src/com/lingnan/supermarket/dao/impl/outOrderServiceImpl.java +++ b/Supermarket/src/com/lingnan/supermarket/dao/impl/outOrderServiceImpl.java @@ -13,21 +13,29 @@ import com.lingnan.supermarket.dto.InOrder; import com.lingnan.supermarket.dto.OutOrder; import com.lingnan.supermarket.utils.JDBCUtil; -public class outOrderServiceImpl implements outOrderService{ +// 实现outOrderService接口--用于处理与出库订单相关的数据访问操作 +public class outOrderServiceImpl implements outOrderService { + // 查询所有出库订单信息,并按照日期降序排列返回 @Override public Vector findAllOutOrder() { + // 存储查询到的所有出库订单信息的向量集合 Vector outOrders = new Vector(); + // 获取数据库连接 Connection conn = JDBCUtil.getConn(); PreparedStatement preparedStatement = null; - ResultSet resultSet=null; - + ResultSet resultSet = null; + + // 从OutOrder表中查询所有记录,并按oDate字段降序排序 String SQL = "select * from OutOrder order by oDate desc"; - + try { + // 根据SQL语句创建预编译的Statement对象 preparedStatement = conn.prepareStatement(SQL); + // 执行查询操作 resultSet = preparedStatement.executeQuery(); - while(resultSet.next()) { + // 遍历结果集,将每条记录封装成OutOrder对象,并添加到outOrders集合中 + while (resultSet.next()) { OutOrder outOrder = new OutOrder(); outOrder.setoNumber(resultSet.getString("oNumber")); outOrder.setAllOutPrice(resultSet.getFloat("allOutPrice")); @@ -35,117 +43,147 @@ public class outOrderServiceImpl implements outOrderService{ outOrder.setPrincipal(resultSet.getString("principal")); outOrders.add(outOrder); } - + } catch (SQLException e) { e.printStackTrace(); } finally { + // 关闭结果集、预编译语句以及数据库连接,释放相关资源 JDBCUtil.close(resultSet, preparedStatement, conn); } return outOrders; } + // 根据订单编号查询对应的出库订单信息 @Override public OutOrder findByIdOutOrder(String oNumber) { + // 用于存储查询到的出库订单信息的对象 OutOrder outOrder = new OutOrder(); + // 获取数据库连接 Connection conn = JDBCUtil.getConn(); PreparedStatement preparedStatement = null; ResultSet resultSet = null; try { - preparedStatement = conn.prepareStatement("select * from outOrder where oNumber = ?"); + // 根据订单编号查询对应的出库订单记录 + preparedStatement = conn.prepareStatement("select * from outOrder where oNumber =?"); + // 设置查询的订单编号 preparedStatement.setString(1, oNumber); + // 执行查询操作 resultSet = preparedStatement.executeQuery(); + // 如果结果集中有记录,说明找到了对应的订单,则将记录中的各字段值封装到outOrder对象中 if (resultSet.next()) { outOrder.setoNumber(resultSet.getString("oNumber")); outOrder.setAllOutPrice(resultSet.getFloat("allOutPrice")); outOrder.setoDate(resultSet.getDate("oDate")); outOrder.setPrincipal(resultSet.getString("principal")); } else { - return null; // 没有找到该订单或订单不存在,返回null - } + // 如果结果集中没有记录,说明没有找到该订单或订单不存在,返回null + return null; + } } catch (SQLException e) { e.printStackTrace(); } finally { + // 关闭结果集、预编译语句以及数据库连接,释放相关资源 JDBCUtil.close(resultSet, preparedStatement, conn); } return outOrder; - } + // 向数据库中添加一条出库订单记录 @Override public int addOutOrder(String oNumber, float allOutPrice) { int flag = 0; - Timestamp oDate = new Timestamp(System.currentTimeMillis()); - + // 获取当前系统时间戳,用于作为出库订单的日期(oDate)字段值,表示订单创建时间 + Timestamp oDate = new Timestamp(System.currentTimeMillis()); + + // 获取数据库连接 Connection conn = JDBCUtil.getConn(); PreparedStatement preparedStatement = null; - + try { - preparedStatement = conn.prepareStatement - ("insert into outOrder values (?,?,?,?)"); + // 创建预编译的SQL插入语句,向outOrder表中插入一条记录 + preparedStatement = conn.prepareStatement("insert into outOrder values (?,?,?,?)"); + // 设置预编译语句中的参数,依次为订单编号、总出库价格、订单日期、负责人(此处写死为"a1",可能后续需要改进) preparedStatement.setString(1, oNumber); preparedStatement.setFloat(2, allOutPrice); preparedStatement.setTimestamp(3, oDate); preparedStatement.setString(4, "a1"); + // 执行插入操作 preparedStatement.executeUpdate(); + // 如果插入成功,将标志位flag设置为1,表示操作成功 flag = 1; } catch (SQLException e) { + // 如果插入出现异常,将标志位flag设置为 -1,表示操作失败 flag = -1; e.printStackTrace(); } finally { - JDBCUtil.close(null,preparedStatement, conn); + // 关闭预编译语句以及数据库连接,释放相关资源 + JDBCUtil.close(null, preparedStatement, conn); } - + return flag; } + // 根据订单编号从数据库中删除对应的出库订单记录 @Override public int deleteOutOrder(String oNumber) { int flag = 0; - + + // 获取数据库连接 Connection conn = JDBCUtil.getConn(); PreparedStatement preparedStatement = null; - + try { - preparedStatement = conn.prepareStatement - ("delete from outOrder where oNumber = ?"); + // 创建预编译的SQL删除语句,根据订单编号(oNumber)删除对应的出库订单记录 + preparedStatement = conn.prepareStatement("delete from outOrder where oNumber =?"); + // 设置预编译语句中的参数,即要删除的订单编号 preparedStatement.setString(1, oNumber); + // 执行删除操作 preparedStatement.executeUpdate(); + // 如果删除成功,将标志位flag设置为1,表示操作成功 flag = 1; } catch (SQLException e) { + // 如果删除出现异常,将标志位flag设置为 -1,表示操作失败 flag = -1; e.printStackTrace(); } finally { - JDBCUtil.close(null,preparedStatement, conn); + // 关闭预编译语句以及数据库连接,释放相关资源 + JDBCUtil.close(null, preparedStatement, conn); } return flag; } - - //获取今日进货金额 - public Float TodayOutPrice(String date) { - - InOrder inOrder = new InOrder(); - Connection conn = JDBCUtil.getConn(); - PreparedStatement preparedStatement = null; - ResultSet resultSet = null; - Float allInPrice=(float) 0; - - try { - preparedStatement = conn.prepareStatement("select sum(allOutPrice) from outOrder where oDate>=? and oDate<=date_add(?,interval 1 day)"); - preparedStatement.setString(1, date); - preparedStatement.setString(2, date); - resultSet = preparedStatement.executeQuery(); - if (resultSet.next()) { - allInPrice=resultSet.getFloat("sum(allOutPrice)"); - } - } catch (SQLException e) { - e.printStackTrace(); - } finally { - JDBCUtil.close(resultSet, preparedStatement, conn); + // 获取指定日期的今日出库金额总和(此处方法名可能有点混淆,从代码逻辑看是获取指定日期的出库金额总和) + public Float TodayOutPrice(String date) { + // 创建一个InOrder对象 + InOrder inOrder = new InOrder(); + // 获取数据库连接 + Connection conn = JDBCUtil.getConn(); + PreparedStatement preparedStatement = null; + ResultSet resultSet = null; + // 用于存储查询到的今日出库金额总和,初始为0 + Float allInPrice = (float) 0; + + try { + // 通过求和函数查询指定日期范围内的总出库价格 + preparedStatement = conn.prepareStatement("select sum(allOutPrice) from outOrder where oDate>=? and oDate<=date_add(?,interval 1 day)"); + // 设置两个参数均为传入的日期值,用于限定查询的日期范围 + preparedStatement.setString(1, date); + preparedStatement.setString(2, date); + // 执行查询操作 + resultSet = preparedStatement.executeQuery(); + // 如果结果集中有记录,说明查询到了对应的金额数据,则将其取出赋值给allInPrice变量 + if (resultSet.next()) { + allInPrice = resultSet.getFloat("sum(allOutPrice)"); } - return allInPrice; + } catch (SQLException e) { + e.printStackTrace(); + } finally { + // 关闭结果集、预编译语句以及数据库连接,释放相关资源 + JDBCUtil.close(resultSet, preparedStatement, conn); } -} + return allInPrice; + } +} \ No newline at end of file diff --git a/Supermarket/src/com/lingnan/supermarket/dao/impl/outRecordServiceImpl.java b/Supermarket/src/com/lingnan/supermarket/dao/impl/outRecordServiceImpl.java index 5347d19..98f4958 100644 --- a/Supermarket/src/com/lingnan/supermarket/dao/impl/outRecordServiceImpl.java +++ b/Supermarket/src/com/lingnan/supermarket/dao/impl/outRecordServiceImpl.java @@ -12,49 +12,66 @@ import com.lingnan.supermarket.dto.InRecord; import com.lingnan.supermarket.dto.OutRecord; import com.lingnan.supermarket.utils.JDBCUtil; -public class outRecordServiceImpl implements outRecordService{ +// 实现了outRecordService接口--用于处理出库记录相关的数据操作逻辑 +public class outRecordServiceImpl implements outRecordService { + // 查询所有出库记录信息 @Override public Vector findAllOutRecord() { + // 用于存储查询到的所有出库记录信息的向量集合 Vector outRecords = new Vector(); + // 通过JDBCUtil工具类的静态方法来获取数据库连接 Connection conn = JDBCUtil.getConn(); PreparedStatement preparedStatement = null; - ResultSet resultSet=null; - + ResultSet resultSet = null; + + // 从outRecord表中获取所有记录 String SQL = "select * from outRecord"; - + try { + // 根据SQL语句创建预编译的Statement对象 preparedStatement = conn.prepareStatement(SQL); + // 执行查询操作 resultSet = preparedStatement.executeQuery(); - while(resultSet.next()) { + // 遍历结果集,将每条记录封装成OutRecord对象,并添加到outRecords集合中 + while (resultSet.next()) { OutRecord outRecord = new OutRecord(); outRecord.setoNumber(resultSet.getString("oNumber")); outRecord.setSum(resultSet.getInt("sum")); outRecord.setOutPrice(resultSet.getFloat("outPrice")); outRecords.add(outRecord); } - + } catch (SQLException e) { e.printStackTrace(); } finally { + // 关闭结果集、预编译语句以及数据库连接,释放相关资源 JDBCUtil.close(resultSet, preparedStatement, conn); } return outRecords; } + // 根据订单编号查询对应的出库记录信息,返回符合条件的多条记录 @Override public Vector findByIdOutRecordr(String oNumber) { - OutRecord outRecord ; + // 用于临时存储单个出库记录信息的对象 + OutRecord outRecord; + // 获取数据库连接 Connection conn = JDBCUtil.getConn(); PreparedStatement preparedStatement = null; ResultSet resultSet = null; + // 存储查询到的符合条件的所有出库记录信息的向量集合 Vector v = new Vector(); try { - preparedStatement = conn.prepareStatement("select * from outRecord where oNumber = ?"); + //根据给定的订单编号查询outRecord表中对应的记录 + preparedStatement = conn.prepareStatement("select * from outRecord where oNumber =?"); + // 设置要查询的订单编号 preparedStatement.setString(1, oNumber); + // 执行查询操作,获取结果集 resultSet = preparedStatement.executeQuery(); + // 遍历结果集,将每条符合条件的记录封装成OutRecord对象,并添加到向量集合v中 while (resultSet.next()) { outRecord = new OutRecord(); outRecord.setoNumber(resultSet.getString("oNumber")); @@ -62,68 +79,83 @@ public class outRecordServiceImpl implements outRecordService{ outRecord.setSum(resultSet.getInt("sum")); outRecord.setOutPrice(resultSet.getFloat("Price")); v.add(outRecord); - } + } } catch (SQLException e) { e.printStackTrace(); } finally { + // 关闭结果集、预编译语句以及数据库连接,释放相关资源 JDBCUtil.close(resultSet, preparedStatement, conn); } return v; } + // 向数据库中添加一条出库记录信息 @Override public int addoutRecord(OutRecord or) { - int flag = 0; - + + // 获取要添加的出库记录对象中的订单编号 String oNumber = or.getoNumber(); + // 获取要添加的出库记录对象中的数量 int sum = or.getSum(); + // 获取要添加的出库记录对象中的出库价格 Float outPrice = or.getOutPrice(); - + + // 获取数据库连接 Connection conn = JDBCUtil.getConn(); PreparedStatement preparedStatement = null; - + try { - preparedStatement = conn.prepareStatement - ("insert into outRecord values (?,?,?)"); + // 创建预编译的SQL插入语句,向outRecord表中插入一条记录,包含订单编号、数量、出库价格三个字段的值 + preparedStatement = conn.prepareStatement("insert into outRecord values (?,?,?)"); + // 设置预编译语句中的参数,依次为订单编号、数量、出库价格 preparedStatement.setString(1, oNumber); preparedStatement.setInt(2, sum); preparedStatement.setFloat(3, outPrice); + // 执行插入操作 preparedStatement.executeUpdate(); + // 如果插入成功,将标志位flag设置为1,表示操作成功 flag = 1; } catch (SQLException e) { + // 如果插入出现异常,将标志位flag设置为 -1,表示操作失败 flag = -1; e.printStackTrace(); } finally { - JDBCUtil.close(null,preparedStatement, conn); + // 关闭预编译语句以及数据库连接,释放相关资源,此处结果集为null + JDBCUtil.close(null, preparedStatement, conn); } - + return flag; } + // 根据订单编号从数据库中删除对应的出库记录信息 @Override public int deleteOutOrder(String oNumber) { int flag = 0; - + + // 获取数据库连接 Connection conn = JDBCUtil.getConn(); PreparedStatement preparedStatement = null; - + try { - preparedStatement = conn.prepareStatement - ("delete from outRecord where oNumber = ?"); + // 创建预编译的SQL删除语句,根据给定的订单编号删除outRecord表中对应的记录 + preparedStatement = conn.prepareStatement("delete from outRecord where oNumber =?"); + // 设置要删除的订单编号 preparedStatement.setString(1, oNumber); + // 执行删除操作 preparedStatement.executeUpdate(); + // 如果删除成功,将标志位flag设置为1,表示操作成功 flag = 1; } catch (SQLException e) { + // 如果删除出现异常,将标志位flag设置为 -1,表示操作失败 flag = -1; e.printStackTrace(); } finally { - JDBCUtil.close(null,preparedStatement, conn); + // 关闭预编译语句以及数据库连接,释放相关资源,此处结果集为null + JDBCUtil.close(null, preparedStatement, conn); } return flag; } - - -} +} \ No newline at end of file diff --git a/Supermarket/src/com/lingnan/supermarket/dao/impl/prodCatalogImpl.java b/Supermarket/src/com/lingnan/supermarket/dao/impl/prodCatalogImpl.java index 805f16f..917c235 100644 --- a/Supermarket/src/com/lingnan/supermarket/dao/impl/prodCatalogImpl.java +++ b/Supermarket/src/com/lingnan/supermarket/dao/impl/prodCatalogImpl.java @@ -12,214 +12,241 @@ import com.lingnan.supermarket.dao.prodCatalogService; import com.lingnan.supermarket.dto.ProdCatalog; import com.lingnan.supermarket.utils.JDBCUtil; -public class prodCatalogImpl implements prodCatalogService{ +// 实现prodCatalogService接口--用于处理商品目录相关的数据持久化操作 +public class prodCatalogImpl implements prodCatalogService { - /*将商品目录表和商品表联合查询*/ + // 将商品目录表和商品表联合查询,获取商品目录及相关商品信息 @Override public Vector findProdCatalogAndProd() { - Connection conn=JDBCUtil.getConn(); + // 通过JDBCUtil工具类来获取已经配置好的连接对象 + Connection conn = JDBCUtil.getConn(); + // 创建一个Vector容器,存放查询到的ProdCatalog对象 Vector v = new Vector(); ProdCatalog prodCatalog; PreparedStatement pstmt = null; - ResultSet resultSet=null; + ResultSet resultSet = null; try { + // 通过预编译语句准备调用存储过程allProdCatalog pstmt = conn.prepareStatement("call allProdCatalog()"); + // 执行查询操作 resultSet = pstmt.executeQuery(); - while(resultSet.next()){ + // 遍历结果集,将每一条记录封装成ProdCatalog对象,并添加到Vector容器中 + while (resultSet.next()) { prodCatalog = new ProdCatalog(); + // 设置ProdCatalog对象的id属性 prodCatalog.setId(resultSet.getString("id")); + // 设置ProdCatalog对象的name属性 prodCatalog.setName(resultSet.getString("name")); v.add(prodCatalog); } } catch (SQLException e) { - // TODO Auto-generated catch block + // 若出现SQL异常,打印异常栈信息 e.printStackTrace(); - }finally{ + } finally { + // 通过JDBCUtil工具类提供的方法进行关闭操作 JDBCUtil.close(resultSet, pstmt, conn); } - - + return v; - - + } - - + + // 根据给定的id1查找商品目录名称 @Override - public String findProdCatalog(String id1 ) { - Connection conn=JDBCUtil.getConn(); - + public String findProdCatalog(String id1) { + // 获取数据库连接 + Connection conn = JDBCUtil.getConn(); + PreparedStatement pstmt = null; - ResultSet resultSet=null; - String catalog=null; + ResultSet resultSet = null; + String catalog = null; try { + // 预编译SQL语句,用于根据给定的id2查询prodCatalog表中的记录 pstmt = conn.prepareStatement("select *from prodCatalog where id2 =?"); - pstmt.setString(1,id1); - + // 设置SQL语句中的参数,将传入的id1赋值给查询语句中的占位符 + pstmt.setString(1, id1); + // 执行查询操作 resultSet = pstmt.executeQuery(); - if(resultSet.next()){ - catalog=resultSet.getString("name1"); + // 如果结果集中有下一条记录,则获取对应记录中的name1字段值作为商品目录名称 + if (resultSet.next()) { + catalog = resultSet.getString("name1"); } } catch (SQLException e) { - // TODO Auto-generated catch block e.printStackTrace(); - }finally{ + } finally { + // 关闭相关资源 JDBCUtil.close(resultSet, pstmt, conn); } - - + return catalog; - - + } + // 向商品目录表prodCatalog中添加一条记录 @Override public int addProdCatalog(String id1, String id2) { - int flag=0; - String name1=null; - //01 食品 02 电器 03 生活用品 04 其他 - if(id1.equals("01")) - name1="食品"; - else if(id1.equals("02")) - name1="电器"; - else if(id1.equals("03")) - name1="生活用品"; - else - name1="其他"; - - //连接jdbc - Connection conn=JDBCUtil.getConn(); + int flag = 0; + String name1 = null; + // 根据传入的id1判断商品类别名称,01对应食品,02对应电器,03对应生活用品,04对应其他 + if (id1.equals("01")) + name1 = "食品"; + else if (id1.equals("02")) + name1 = "电器"; + else if (id1.equals("03")) + name1 = "生活用品"; + else + name1 = "其他"; + + // 获取数据库连接 + Connection conn = JDBCUtil.getConn(); PreparedStatement pstmt = null; - ResultSet resultSet=null; - + ResultSet resultSet = null; + try { + // 预编译插入数据的SQL语句,向prodCatalog表中插入三条数据 pstmt = conn.prepareStatement("insert into prodCatalog values(?,?,?)"); - pstmt.setString(1,id1); - pstmt.setString(2,name1); - pstmt.setString(3,id2); - + // 设置SQL语句中的第一个参数 + pstmt.setString(1, id1); + // 设置SQL语句中的第二个参数 + pstmt.setString(2, name1); + // 设置SQL语句中的第三个参数 + pstmt.setString(3, id2); + // 执行插入操作,若插入成功,将flag置为1,表示添加成功 pstmt.executeUpdate(); - flag=1; - + flag = 1; + } catch (SQLException e) { e.printStackTrace(); - }finally{ + } finally { + // 关闭相关资源 JDBCUtil.close(resultSet, pstmt, conn); } - + return flag; } - + // 根据给定的id2删除商品目录表prodCatalog中的一条记录 @Override public int deleteProdCatalog(String id2) { - int flag=0; - //连接jdbc - Connection conn=JDBCUtil.getConn(); + int flag = 0; + // 获取数据库连接 + Connection conn = JDBCUtil.getConn(); PreparedStatement pstmt = null; - ResultSet resultSet=null; - + ResultSet resultSet = null; + try { + // 预编译删除数据的SQL语句,根据传入的id2作为条件,从prodCatalog表中删除对应的记录 pstmt = conn.prepareStatement("delete from prodCatalog where id2=?"); - pstmt.setString(1,id2); + // 设置SQL语句中的参数,将传入的id2赋值给查询语句中的占位符(?) + pstmt.setString(1, id2); + // 执行删除操作,若删除成功,将flag置为1,表示删除成功 pstmt.executeUpdate(); - flag=1; - + flag = 1; + } catch (SQLException e) { - // TODO Auto-generated catch block + // 若出现SQL异常打印异常栈信息 e.printStackTrace(); - }finally{ + } finally { + // 关闭相关资源 JDBCUtil.close(resultSet, pstmt, conn); } - + return flag; } - + // 根据商品类production的name查询并输出类别id,如果传入的name为"全部",则直接返回默认的catalogid "0" @Override - //根据商品类production的name查询并输出类别id public String findProdCatalogByname(String name) { - Connection conn=JDBCUtil.getConn(); - + Connection conn = JDBCUtil.getConn(); + PreparedStatement pstmt = null; - ResultSet resultSet=null; - - String catalogid="0"; + ResultSet resultSet = null; + + String catalogid = "0"; try { - if(name.equals("全部")){ + // 如果传入的商品名称为"全部",则直接返回默认的catalogid + if (name.equals("全部")) { return catalogid; } + // 预编译SQL语句,用于根据给定的商品名称查询prodCatalog表中的记录,获取对应的类别id pstmt = conn.prepareStatement("select * from prodCatalog where name =?"); - pstmt.setString(1,name); - + // 设置SQL语句中的参数,将传入的name赋值给查询语句中的占位符 + pstmt.setString(1, name); + // 执行查询操作,获取结果集 resultSet = pstmt.executeQuery(); - if(resultSet.next()){ - catalogid=resultSet.getString("id"); + // 如果结果集中有下一条记录,则获取对应记录中的id字段值作为类别id + if (resultSet.next()) { + catalogid = resultSet.getString("id"); } } catch (SQLException e) { - // TODO Auto-generated catch block + // 若出现SQL异常,打印异常栈信息 e.printStackTrace(); - }finally{ + } finally { + // 关闭相关资源 JDBCUtil.close(resultSet, pstmt, conn); } - - + return catalogid; } -/* public static void main(String[] args) { - ProdCatalog p=new ProdCatalog(); - prodCatalogImpl pi=new prodCatalogImpl(); - p.setName("全部"); - System.out.println(pi.findProdCatalogByname(p.getName())); - }*/ - + /* + public static void main(String[] args) { + ProdCatalog p = new ProdCatalog(); + prodCatalogImpl pi = new prodCatalogImpl(); + p.setName("全部"); + System.out.println(pi.findProdCatalogByname(p.getName())); + } + */ + // 查询商品目录表prodCatalog中的所有商品类别名称,并添加"全部"作为第一个元素后返回 @Override public ArrayList findNameProdCatalog() { - Connection conn=JDBCUtil.getConn(); + Connection conn = JDBCUtil.getConn(); ArrayList v = new ArrayList(); + // 先添加"全部"作为默认的第一个类别名称 v.add("全部"); ProdCatalog prodCatalog; PreparedStatement pstmt = null; - ResultSet resultSet=null; + ResultSet resultSet = null; try { + // 预编译查询所有记录的SQL语句,用于获取prodCatalog表中的所有商品类别名称 pstmt = conn.prepareStatement("select * from prodCatalog"); + // 执行查询操作 resultSet = pstmt.executeQuery(); - while(resultSet.next()){ - + // 遍历结果集,将每条记录中的商品类别名称添加到ArrayList容器中 + while (resultSet.next()) { + v.add(resultSet.getString("name")); } } catch (SQLException e) { - // TODO Auto-generated catch block + // 若出现SQL异常,打印异常栈信息 e.printStackTrace(); - }finally{ + } finally { + // 关闭相关资源 JDBCUtil.close(resultSet, pstmt, conn); } - - + return v; } - /*public static void main(String[] args) { - prodCatalogImpl pi=new prodCatalogImpl(); - ArrayListlog=null; - - - log=pi.findNameProdCatalog(); - String []s=new String[log.size()]; - for(int i=0;i log = null; + + + log = pi.findNameProdCatalog(); + String[] s = new String[log.size()]; + for (int i = 0; i < log.size(); i++) { + s[i] = log.get(i); + System.out.println(log.get(i)); + } + for (int i = 0; i < s.length; i++) { + System.out.println(s[i]); + } -} + } + */ +} \ No newline at end of file diff --git a/Supermarket/src/com/lingnan/supermarket/dao/impl/storageRecordImpl.java b/Supermarket/src/com/lingnan/supermarket/dao/impl/storageRecordImpl.java index 265d09e..745adae 100644 --- a/Supermarket/src/com/lingnan/supermarket/dao/impl/storageRecordImpl.java +++ b/Supermarket/src/com/lingnan/supermarket/dao/impl/storageRecordImpl.java @@ -6,13 +6,50 @@ import java.sql.ResultSet; import java.sql.SQLException; 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; import com.lingnan.supermarket.utils.JDBCUtil; +// 实现storageRecordService接口--用于处理库存记录相关的数据持久化操作 public class storageRecordImpl implements storageRecordService { +<<<<<<< HEAD + // 查询所有库存记录信息,并以Vector容器存储返回 + @Override + public Vector findAllStorageRecord() { + // 创建一个Vector容器,用于存放查询到的StorageRecord对象 + Vector v = new Vector(); + + // 获取数据库连接,通过JDBCUtil工具类来获取已经配置好的连接对象 + Connection conn = JDBCUtil.getConn(); + PreparedStatement pstmt = null; + ResultSet resultSet = null; + try { + // 编写SQL查询语句,从storageRecord表中查询所有记录,并按照cDate字段降序排序 + String sql = "select * from storageRecord order by cDate desc"; + // 使用获取到的数据库连接对象,预编译SQL语句 + pstmt = conn.prepareStatement(sql); + + // 执行查询操作 + resultSet = pstmt.executeQuery(); + // 遍历结果集,将每一条记录封装成StorageRecord对象,并添加到Vector容器中 + while (resultSet.next()) { + StorageRecord sr = new StorageRecord(); + // 设置StorageRecord对象的id属性 + sr.setId(resultSet.getString("id")); + // 设置StorageRecord对象的库存编号属性 + sr.setTheNumber(resultSet.getString("theNumber")); + // 设置StorageRecord对象的数量属性 + sr.setNum(resultSet.getInt("num")); + // 设置StorageRecord对象的执行情况属性 + sr.setExecute(resultSet.getString("execute")); + // 通过DateUtil工具类的dateToString方法将数据库中获取的时间戳类型的日期数据转换为字符串类型,方便后续使用(第二个参数为null可能表示使用默认的日期格式转换,具体看DateUtil实现) +======= /** * 获取所有存储记录 * @@ -52,11 +89,34 @@ public class storageRecordImpl implements storageRecordService { 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异常,打印异常栈信息 + e.printStackTrace(); + } finally { + // 通过JDBCUtil工具类提供的方法进行关闭操作 + JDBCUtil.close(resultSet, pstmt, conn); + + } + + return v; + } + + // 根据给定的库存编号(theNumber)查找对应的库存记录信息并返回 + @Override + public StorageRecord findByIdStorageRecord(String theNumber) { + // 初始化一个StorageRecord对象为null,用于存放查询到的库存记录信息,如果没查到则返回null + StorageRecord sr = null; + // 获取数据库连接 + Connection conn = JDBCUtil.getConn(); +======= } catch (SQLException e) { // 如果出现SQL异常,打印错误信息 e.printStackTrace(); @@ -85,10 +145,25 @@ public class storageRecordImpl implements storageRecordService { Connection conn = JDBCUtil.getConn(); // 声明PreparedStatement和ResultSet对象 +>>>>>>> remotes/origin/main PreparedStatement pstmt = null; ResultSet resultSet = null; try { +<<<<<<< HEAD + // 创建一个新的StorageRecord对象,用于后续封装查询到的数据 + sr = new StorageRecord(); + // 预编译SQL语句,用于根据给定的库存编号(theNumber)查询storageRecord表中的记录 + pstmt = conn.prepareStatement("select *from storageRecord where theNumber=?"); + // 设置SQL语句中的参数,将传入的库存编号赋值给查询语句中的占位符 + pstmt.setString(1, theNumber); + // 执行查询操作,获取结果集 + resultSet = pstmt.executeQuery(); + // 如果结果集中有下一条记录,则将对应记录中的各字段值封装到StorageRecord对象中 + if (resultSet.next()) { + sr.setTheNumber((resultSet.getString("theNumber"))); + sr.setId((resultSet.getString("id"))); +======= // 初始化StorageRecord对象 sr = new StorageRecord(); @@ -105,11 +180,32 @@ public class storageRecordImpl implements storageRecordService { 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异常,打印异常栈信息 + e.printStackTrace(); + } finally { + // 关闭相关资源 + JDBCUtil.close(resultSet, pstmt, conn); + } + + return sr; + } + + // 向库存记录表storageRecord中插入一条新的库存记录信息 + public boolean insertStorageRecord(String iNumber, String time, String prodId, String execute, int sum) { + // 定义一个布尔变量用于标记插入操作是否成功,初始化为false + boolean flag = false; + // 获取数据库连接 + Connection conn = JDBCUtil.getConn(); +======= } catch (SQLException e) { // 如果发生SQLException,打印堆栈信息 e.printStackTrace(); @@ -141,10 +237,39 @@ public class storageRecordImpl implements storageRecordService { 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语句中的第一个参数 + pstmt.setString(1, iNumber); + // 设置SQL语句中的第二个参数 + pstmt.setString(2, time); + // 设置SQL语句中的第三个参数 + pstmt.setString(3, prodId); + // 设置SQL语句中的第四个参数 + pstmt.setString(4, execute); + // 设置SQL语句中的第五个参数 + pstmt.setInt(5, sum); + + // 执行插入操作,若受影响的行数为1,则将flag置为true,表示插入成功 + if (pstmt.executeUpdate() == 1) { + flag = true; + } + + } catch (SQLException e) { + // 若出现SQL异常,打印异常栈信息 + e.printStackTrace(); + } finally { + // 关闭相关资源 + JDBCUtil.close(resultSet, pstmt, conn); + } + +======= // 编写SQL插入语句,将数据插入到storageRecord表中 pstmt = conn.prepareStatement("insert into storageRecord values(?,?,?,?,?)"); @@ -179,6 +304,7 @@ public class storageRecordImpl implements storageRecordService { } // 返回插入操作的结果(成功返回true,失败返回false) +>>>>>>> remotes/origin/main return flag; } -} +} \ No newline at end of file diff --git a/Supermarket/src/com/lingnan/supermarket/utils/CreateOrder.java b/Supermarket/src/com/lingnan/supermarket/utils/CreateOrder.java index 0321009..7acb4ca 100644 --- a/Supermarket/src/com/lingnan/supermarket/utils/CreateOrder.java +++ b/Supermarket/src/com/lingnan/supermarket/utils/CreateOrder.java @@ -5,8 +5,21 @@ import java.util.Vector; import com.lingnan.supermarket.dto.Buffer; import com.lingnan.supermarket.dto.Production; +// 用于创建订单相关文本内容 public class CreateOrder { +<<<<<<< HEAD + // 用于生成一个完整的订单文本信息,接收商品信息向量、订单编号、时间、总价以及负责人用户名等参数 + public String CreateOrder(Vector v, String oNumber, String time, Float allPrice, String username) { + // 分割线 + String xx = "----------------------------------------------------------------------------\r\n"; + // 初始化订单文本内容 + String InRequireText = time + "\r\n" + xx; + + // 添加订单小票中商品信息展示的表头部分 + InRequireText += "#名称 #单价 #数量 #金额\r\n"; + //循环遍历传入的商品信息向量,将每个商品的具体信息按照设定的格式拼接添加到订单文本中 +======= // 方法:生成订单小票文本 public String CreateOrder(Vector v, String oNumber, String time, Float allPrice, String username) { // 初始化分隔符 @@ -19,10 +32,31 @@ public class CreateOrder { 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; + + // 显示本次进货的总价金额 + InRequireText += "#总进货金额:" + allPrice + "元"; + // 显示订单的负责人 + InRequireText += "\r\n#负责人:" + username; + // 添加订单编号信息到订单文本中 + InRequireText += "\r\n#订单编号:" + oNumber; + // 添加超市地址信息到订单文本中,注明订单对应的收货地址等相关信息 + InRequireText += "\r\n#地址:新民超市"; + // 添加联系电话信息到订单文本中 + InRequireText += "\r\n#联系电话:xxx"; + + // 返回最终生成的完整订单文本内容 + return InRequireText; + } +} +======= // 订单总金额 InRequireText += "\r\n" + xx; InRequireText += "#总进货金额:" + allPrice + "元"; @@ -93,3 +127,4 @@ public class CreateOrder { return orderList.toString(); } } +>>>>>>> remotes/origin/main diff --git a/Supermarket/src/com/lingnan/supermarket/utils/DateUtil.java b/Supermarket/src/com/lingnan/supermarket/utils/DateUtil.java index 21e4522..8297759 100644 --- a/Supermarket/src/com/lingnan/supermarket/utils/DateUtil.java +++ b/Supermarket/src/com/lingnan/supermarket/utils/DateUtil.java @@ -3,20 +3,23 @@ package com.lingnan.supermarket.utils; import java.text.SimpleDateFormat; import java.util.Date; +// DateUtil类,从名称可以推测是用于处理日期相关操作的工具类 public class DateUtil { - - + /** - * 格式化日期 - * @param date - * @param pattern - * @return + * dateToString方法用于将给定的Date类型日期对象按照指定的格式转换为字符串表示形式。 + * + * @param date 要进行格式化的Date类型日期对象,代表一个具体的时间点,例如某个操作发生的时间等。 + * @param pattern 用于指定日期格式化的模式字符串,例如"yyyy-MM-dd HH:mm:ss"表示年-月-日 时:分:秒的格式。 + * 如果传入的pattern为null,则默认使用"yyyy-MM-dd HH:mm:ss"格式进行格式化。 + * @return 返回一个按照指定格式(或默认格式)格式化后的日期字符串,方便在界面显示、数据存储等场景使用。 */ - public static String dateToString(Date date,String pattern) { + public static String dateToString(Date date, String pattern) { + // 创建SimpleDateFormat对象,它是Java中用于格式化日期的类,通过指定的模式将日期转换为相应格式的字符串。 SimpleDateFormat simpleDateFormat = new SimpleDateFormat(); - simpleDateFormat.applyPattern(pattern==null?"yyyy-MM-dd HH:mm:ss":pattern); + // 使用applyPattern方法设置日期格式化的模式。如果传入的pattern为null,就使用默认的"yyyy-MM-dd HH:mm:ss"格式。 + simpleDateFormat.applyPattern(pattern == null? "yyyy-MM-dd HH:mm:ss" : pattern); + // 调用format方法,将传入的Date对象按照设置好的模式进行格式化,最终返回格式化后的日期字符串。 return simpleDateFormat.format(date); } - - -} +} \ No newline at end of file diff --git a/Supermarket/src/com/lingnan/supermarket/utils/EmailTest.java b/Supermarket/src/com/lingnan/supermarket/utils/EmailTest.java index f3769fb..7fcaf89 100644 --- a/Supermarket/src/com/lingnan/supermarket/utils/EmailTest.java +++ b/Supermarket/src/com/lingnan/supermarket/utils/EmailTest.java @@ -3,12 +3,12 @@ package com.lingnan.supermarket.utils; import javax.mail.MessagingException; import javax.mail.internet.AddressException; +// EmailTest类 public class EmailTest { + //Java程序的入口点 + // 这里声明抛出AddressException和MessagingException异常,意味着在方法执行过程中如果出现邮件地址相关或邮件发送相关的异常,将直接向上抛出,由调用者处理 public static void main(String[] args) throws AddressException, MessagingException { // TODO Auto-generated method stub - - } - -} +} \ No newline at end of file diff --git a/Supermarket/src/com/lingnan/supermarket/utils/JDBCUtil.java b/Supermarket/src/com/lingnan/supermarket/utils/JDBCUtil.java index e16b49d..4da3682 100644 --- a/Supermarket/src/com/lingnan/supermarket/utils/JDBCUtil.java +++ b/Supermarket/src/com/lingnan/supermarket/utils/JDBCUtil.java @@ -9,23 +9,52 @@ 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; + // 数据库连接的用户名 private static String user; + // 数据库连接的密码 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) { + // 若加载配置文件出现IO异常,打印异常栈信息 + e.printStackTrace(); + } finally { + // 在完成配置文件读取后释放资源 + if (inputStream!= null) { +======= // 加载配置文件 properties.load(inputStream); } catch (IOException e) { @@ -34,6 +63,7 @@ public class JDBCUtil { } finally { // 关闭输入流 if (inputStream != null) { +>>>>>>> remotes/origin/main try { inputStream.close(); } catch (IOException e) { @@ -43,6 +73,21 @@ public class JDBCUtil { } } +<<<<<<< HEAD + // 注册数据库驱动 + try { + // 从配置文件中获取驱动类名属性,并加载该驱动类,类加载过程会执行驱动类中相关的静态代码,完成驱动在系统中的注册 + Class.forName(properties.getProperty("driver")); + + // 从配置文件中获取数据库连接的URL地址属性 + url = properties.getProperty("url"); + // 从配置文件中获取数据库连接的用户名属性 + user = properties.getProperty("user"); + // 从配置文件中获取数据库连接的密码属性 + password = properties.getProperty("password"); + } catch (ClassNotFoundException e) { + // 若找不到指定的驱动类,打印异常栈信息 +======= // 注册JDBC驱动 try { // 加载JDBC驱动类 @@ -55,14 +100,22 @@ public class JDBCUtil { } catch (ClassNotFoundException e) { // 如果驱动类加载失败,打印错误信息 +>>>>>>> remotes/origin/main e.printStackTrace(); } } /** +<<<<<<< HEAD + * 获取数据库连接的方法,通过DriverManager根据之前从配置文件中读取并设置好的URL、用户名和密码来建立数据库连接,并返回该连接对象。 + * 如果建立连接过程中出现SQL异常,会打印异常栈信息,并返回null,表示获取连接失败。 + * + * @return 返回建立好的数据库连接对象,若失败则返回null +======= * 获取数据库连接 * * @return 数据库连接 +>>>>>>> remotes/origin/main */ public static Connection getConn() { try { @@ -76,6 +129,29 @@ public class JDBCUtil { } /** +<<<<<<< HEAD + * 释放数据库相关资源的方法,用于关闭ResultSet(结果集)、Statement(语句执行对象)以及Connection(数据库连接对象),避免资源泄漏。 + * 分别判断传入的对象是否为null,若不为null则调用相应的close方法进行关闭操作,若关闭过程中出现SQL异常,会打印异常栈信息。 + * + * @param resultSet 要关闭的结果集对象,通常是执行查询语句后返回的结果集,可为null + * @param statement 要关闭的语句执行对象,如PreparedStatement、Statement等,用于执行SQL语句,可为null + * @param connection 要关闭的数据库连接对象,用于与数据库建立连接,可为null + */ + public static void close(ResultSet resultSet, Statement statement, Connection connection) { + try { + // 如果结果集对象不为null,则关闭结果集,释放相关资源 + if (resultSet!= null) { + resultSet.close(); + } + // 如果语句执行对象不为null,则关闭语句执行对象,释放相关资源 + if (statement!= null) { + statement.close(); + } + // 如果数据库连接对象不为null,则关闭数据库连接,释放相关资源 + if (connection!= null) { + connection.close(); + } +======= * 释放数据库资源 * * @param resultSet 结果集对象 @@ -99,11 +175,15 @@ public class JDBCUtil { connection.close(); } +>>>>>>> remotes/origin/main } catch (SQLException e) { // 如果关闭资源时发生错误,打印错误信息 e.printStackTrace(); } } +<<<<<<< HEAD +} +======= /** * 打印当前数据库配置信息(用于调试) @@ -164,3 +244,4 @@ public class JDBCUtil { System.out.println("数据库连接已关闭。"); } } +>>>>>>> remotes/origin/main diff --git a/Supermarket/src/com/lingnan/supermarket/utils/Test.java b/Supermarket/src/com/lingnan/supermarket/utils/Test.java index 0a416b5..ab6921b 100644 --- a/Supermarket/src/com/lingnan/supermarket/utils/Test.java +++ b/Supermarket/src/com/lingnan/supermarket/utils/Test.java @@ -1,9 +1,9 @@ package com.lingnan.supermarket.utils; +//测试类,用于演示静态代码块的使用 public class Test { - static { - System.out.println("tasdasd."); + System.out.println("tasdasd."); // 打印一条测试信息 } -} +} \ No newline at end of file diff --git a/Supermarket/src/com/lingnan/supermarket/utils/TimeAndOrder.java b/Supermarket/src/com/lingnan/supermarket/utils/TimeAndOrder.java index eb05f55..bf7d9cf 100644 --- a/Supermarket/src/com/lingnan/supermarket/utils/TimeAndOrder.java +++ b/Supermarket/src/com/lingnan/supermarket/utils/TimeAndOrder.java @@ -4,9 +4,52 @@ import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Random; +//具类,用于生成订单号和时间戳 public class TimeAndOrder { /** +<<<<<<< HEAD + * 生成订单号和当前时间戳。 + * 订单号由用户名、随机数、当前时间戳和另一个随机数组成。 + * 时间戳格式为 "yyyy-MM-dd HH:mm:ss"。 + * + * @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"); // 格式化时间为 "yyyy-MM-dd HH:mm:ss" + SimpleDateFormat sdf2 = new SimpleDateFormat("yyyyMMddHHmmss"); // 格式化时间为 "yyyyMMddHHmmss" + + // 获取当前时间的Calendar实例 + Calendar cal = Calendar.getInstance(); + + // 获取当前时间并格式化为字符串 + String date1 = sdf1.format(cal.getTime()); // 格式化时间为 "yyyy-MM-dd HH:mm:ss" + String date2 = sdf2.format(cal.getTime()); // 格式化时间为 "yyyyMMddHHmmss" + + // 创建一个随机数生成器 + 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]); // 打印时间戳 + + // 返回包含订单号和时间戳的字符串数组 +======= * 生成一个包含订单号和时间的字符串数组 * @param username 用户名,用于生成订单号 * @return 一个包含订单号和当前时间的字符串数组 @@ -40,10 +83,29 @@ public class TimeAndOrder { System.out.println(s[1]); // 返回包含订单号和时间的字符串数组 +>>>>>>> remotes/origin/main return s; } /** +<<<<<<< HEAD + * 生成当前日期,格式为 "yyyy-MM-dd"。 + * + * @return 返回当前日期的字符串表示。 + */ + public static String yMdTime() { + // 创建一个SimpleDateFormat对象,用于格式化日期 + SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd"); // 格式化日期为 "yyyy-MM-dd" + + // 获取当前时间的Calendar实例 + Calendar cal = Calendar.getInstance(); + + // 获取当前日期并格式化为字符串 + String date = sdf1.format(cal.getTime()); // 格式化日期为 "yyyy-MM-dd" + + // 返回当前日期的字符串表示 + return date; +======= * 获取当前日期(不包含时间) * @return 当前日期的字符串(格式:yyyy-MM-dd) */ @@ -76,6 +138,6 @@ public class TimeAndOrder { private static void logMethodCall(String methodName) { // 模拟打印方法调用日志 System.out.println("Method " + methodName + " was called."); +>>>>>>> remotes/origin/main } - -} +} \ No newline at end of file diff --git a/Supermarket/src/com/lingnan/supermarket/utils/tplbTest.java b/Supermarket/src/com/lingnan/supermarket/utils/tplbTest.java index 07db185..c466bd4 100644 --- a/Supermarket/src/com/lingnan/supermarket/utils/tplbTest.java +++ b/Supermarket/src/com/lingnan/supermarket/utils/tplbTest.java @@ -1,82 +1,79 @@ package com.lingnan.supermarket.utils; -import java.awt. *; + +import java.awt.*; import java.awt.datatransfer.Clipboard; import java.awt.datatransfer.DataFlavor; import java.awt.datatransfer.StringSelection; import java.awt.datatransfer.Transferable; - -import javax.swing. *; - - - +import javax.swing.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.Scanner; import java.awt.event.*; -public class tplbTest extends JFrame implements ActionListener -{ - static tplbTest tplb=new tplbTest(); - static JLabel pan=new JLabel(); - - static ImageIcon[] imgs = { - new ImageIcon("static\\bg\\bg1.jpg"), - new ImageIcon("static\\bg\\bg2.jpg"), - new ImageIcon("static\\bg\\bg3.jpg"), - new ImageIcon("static\\bg\\bg4.jpg"), - new ImageIcon("static\\bg\\bg5.jpg"), - new ImageIcon("static\\bg\\bg6.jpg"), - new ImageIcon("static\\bg\\bg7.jpg"), - new ImageIcon("static\\bg\\bg8.jpg"), - }; - - public static void settplb()/*�ܿ��*/ - { - tplb.setTitle("ͼƬ�ֲ�����"); - tplb.setLayout(null); - tplb.setSize(700,800); - tplb.setResizable(false); - tplb.setLocationRelativeTo(null);/*���þ���*/ - tplb.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);/*�رճ���*/ - tplb.setVisible(true); + +//用于展示图片轮播效果 +public class tplbTest extends JFrame implements ActionListener { + + // 创建一个tplbTest实例 + static tplbTest tplb = new tplbTest(); + + // 创建一个JLabel用于显示图片 + static JLabel pan = new JLabel(); + + // 定义图片数组,包含多个图片路径 + static ImageIcon[] imgs = { + new ImageIcon("static\\bg\\bg1.jpg"), + new ImageIcon("static\\bg\\bg2.jpg"), + new ImageIcon("static\\bg\\bg3.jpg"), + new ImageIcon("static\\bg\\bg4.jpg"), + new ImageIcon("static\\bg\\bg5.jpg"), + new ImageIcon("static\\bg\\bg6.jpg"), + new ImageIcon("static\\bg\\bg7.jpg"), + new ImageIcon("static\\bg\\bg8.jpg"), + }; + + //设置窗口的基本属性 + public static void settplb() { + tplb.setTitle("图片轮播测试"); // 设置窗口标题 + tplb.setLayout(null); // 设置布局为空布局 + tplb.setSize(700, 800); // 设置窗口大小 + tplb.setResizable(false); // 设置窗口不可调整大小 + tplb.setLocationRelativeTo(null); // 设置窗口居中显示 + tplb.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // 设置关闭窗口时退出程序 + tplb.setVisible(true); // 设置窗口可见 + } + + //设置图片显示区域,并启动定时器实现图片轮播 + public static void setpan() { + pan.setBounds(50, 50, 500, 500); // 设置图片显示区域的坐标和大小 + tplb.add(pan); // 将图片显示区域添加到窗口中 + + // 创建一个定时器,每隔1000毫秒(1秒)触发一次 + Timer timer = new Timer(1000, L); + timer.start(); // 启动定时器 } + //定义一个ActionListener,用于定时切换图片 + static ActionListener L = new ActionListener() { + int index; // 图片索引 - public static void setpan() - { - pan.setBounds(50, 50, 500, 500); - tplb.add(pan); - Timer timer = new Timer(1000,L); - timer.start(); - } - - static ActionListener L=new ActionListener() - { - int index; @Override - public void actionPerformed(ActionEvent e) - { - pan.setIcon(imgs[index]); - index++; - if(index==7) - index=0; + public void actionPerformed(ActionEvent e) { + pan.setIcon(imgs[index]); // 设置当前显示的图片 + index++; // 图片索引加1 + if (index == 7) // 如果索引超出图片数组范围 + index = 0; // 重置索引为0 } }; - - - - - public static void main(String[] args) { - settplb(); - setpan(); - } + public static void main(String[] args) { + settplb(); // 设置窗口属性 + setpan(); // 设置图片显示区域并启动定时器 + } + //实现ActionListener接口的方法,用于处理事件 @Override public void actionPerformed(ActionEvent e) { - // TODO �Զ����ɵķ������ - + // 未实现 } - - - -} +} \ No newline at end of file diff --git a/Supermarket/src/com/lingnan/supermarket/view/InView.java b/Supermarket/src/com/lingnan/supermarket/view/InView.java index 4845449..47112d0 100644 --- a/Supermarket/src/com/lingnan/supermarket/view/InView.java +++ b/Supermarket/src/com/lingnan/supermarket/view/InView.java @@ -20,7 +20,6 @@ import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTable; import javax.swing.JTextField; -import javax.swing.text.html.HTMLDocument.Iterator; import com.lingnan.supermarket.componet.BGPanel; import com.lingnan.supermarket.dao.impl.BufferImpl; @@ -43,15 +42,52 @@ import com.lingnan.supermarket.utils.SendQQMailUtil; import com.lingnan.supermarket.utils.TimeAndOrder; import com.lingnan.supermarket.view.ProdCatalogView.MyItemListener; +<<<<<<< HEAD +/** + * 用于显示进货系统的界面。 + * 包含进货系统的各种操作按钮、搜索框、表格等组件。 + */ +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 JLabel nameLabel, locationLabel; private JTextField nameSearchTF; +<<<<<<< HEAD + 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 v = new Vector(); + + // 状态下拉框 +======= private JButton searchBtn,StockBtn,exitBtn; private JPanel opePanel; @@ -70,10 +106,30 @@ public class InView extends JPanel implements ActionListener{ private static Vector v = new Vector(); +>>>>>>> remotes/origin/main private JComboBox combo; - private String[] status ={"全部","已入库","待入库","已取消"}; + private String[] status = {"全部", "已入库", "待入库", "已取消"}; private int catalog; +<<<<<<< HEAD + // 主窗口和用户信息 + private JFrame jFrame; + private User user; + + // 表格模型 + private InTableModel inTableModel; + + // 缓冲区实现类 + private BufferImpl bufferImpl = new BufferImpl(); + + // 标记从提醒那里来1是进货表,0是提醒过来的表 + private int mark; + + // 进货订单服务实现类 + private inOrderServiceImpl inOrderImpl; + + // 总价和行数 +======= private JFrame jFrame; private User user; @@ -85,10 +141,125 @@ public class InView extends JPanel implements ActionListener{ private inOrderServiceImpl inOrderImpl; +>>>>>>> remotes/origin/main private Float allPrice; private int row; private String uname; +<<<<<<< HEAD + //构造函数 + + public InView(JFrame jFrame, User user, Vector v, int mark) { + this.setLayout(new BorderLayout()); // 设置布局为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(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); // 将标签添加到底部左侧面板 + + 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 getVector() { + return v; + } + + //处理状态下拉框的选项变化 +======= public InView(JFrame jFrame,User user,Vector v,int mark) { this.setLayout(new BorderLayout()); this.jFrame = jFrame; @@ -224,10 +395,23 @@ public class InView extends JPanel implements ActionListener{ } +>>>>>>> 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("全部")) + catalog = 0; + else if (catalog1.equals("已入库")) + catalog = 1; + else if (catalog1.equals("待入库")) + catalog = 2; + else if (catalog1.equals("已取消")) + catalog = 3; +======= JComboBox cb = (JComboBox) e.getSource(); String catalog1 = (String) cb.getSelectedItem(); if(catalog1.equals("全部")) @@ -240,24 +424,46 @@ public class InView extends JPanel implements ActionListener{ catalog=3; resultOfFindStatus(catalog); +>>>>>>> remotes/origin/main + resultOfFindStatus(catalog); // 根据状态查询结果 } + } +<<<<<<< HEAD + //按钮组件隐藏。 +======= } //按钮组件隐藏 +>>>>>>> remotes/origin/main public void OrderView() { - backBtn.setVisible(true); - detailBtn.setVisible(true); - updateBtn.setVisible(true); - deleteBtn.setVisible(true); - addBtn.setVisible(false); - historyBtn.setVisible(false); + backBtn.setVisible(true); // 显示返回按钮 + detailBtn.setVisible(true); // 显示详情按钮 + updateBtn.setVisible(true); // 显示更新按钮 + deleteBtn.setVisible(true); // 显示删除按钮 + addBtn.setVisible(false); // 隐藏添加按钮 + historyBtn.setVisible(false); // 隐藏历史记录按钮 + } + +<<<<<<< HEAD + //根据订单号查询结果 + public void resultOfNumber(String iNumber) { + this.mark = 0; // 设置标记为0 + InOrderTM inOrderTM = new InOrderTM(); // 创建进货订单表格模型 + inOrderTM.resultOfNumber(iNumber); // 根据订单号查询结果 + inTable.setModel(inOrderTM); // 设置表格模型 + bottomPanelLeft.removeAll(); // 清空底部左侧面板 + countInfoLabel = new JLabel("共" + inOrderTM.getRowCount() + "条记录"); // 创建记录数标签 + bottomPanelLeft.add(countInfoLabel); // 将标签添加到底部左侧面板 + OrderView(); // 调用OrderView方法 } + //根据状态查询结果 +======= public void resultOfNumber(String iNumber) { this.mark=0; @@ -270,17 +476,51 @@ public class InView extends JPanel implements ActionListener{ OrderView(); } +>>>>>>> remotes/origin/main public void resultOfFindStatus(int catalog) { - this.mark=0; - InOrderTM inOrderTM = new InOrderTM(); - inOrderTM.resultOfFind(catalog); - inTable.setModel(inOrderTM); - bottomPanelLeft.removeAll(); - countInfoLabel = new JLabel("共"+inOrderTM.getRowCount()+"条记录"); - bottomPanelLeft.add(countInfoLabel); - OrderView(); + this.mark = 0; // 设置标记为0 + InOrderTM inOrderTM = new InOrderTM(); // 创建进货订单表格模型 + inOrderTM.resultOfFind(catalog); // 根据状态查询结果 + inTable.setModel(inOrderTM); // 设置表格模型 + bottomPanelLeft.removeAll(); // 清空底部左侧面板 + countInfoLabel = new JLabel("共" + inOrderTM.getRowCount() + "条记录"); // 创建记录数标签 + bottomPanelLeft.add(countInfoLabel); // 将标签添加到底部左侧面板 + OrderView(); // 调用OrderView方法 + } + +<<<<<<< HEAD + //刷新缓冲区 + public void refreshBuffer(Vector v) { + this.mark = 1; // 设置标记为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; // 设置标记为0 + InOrderTM inOrderTM = new InOrderTM(); // 创建进货订单表格模型 + inOrderTM.allInOrderRecord(); // 查询所有进货订单记录 + inTable.setModel(inOrderTM); // 设置表格模型 + bottomPanelLeft.removeAll(); // 清空底部左侧面板 + countInfoLabel = new JLabel("共" + inOrderTM.getRowCount() + "条记录"); // 创建记录数标签 + bottomPanelLeft.add(countInfoLabel); // 将标签添加到底部左侧面板 + OrderView(); // 调用OrderView方法 + } +======= /*刷新*/ public void refreshBuffer(Vector v) { @@ -336,10 +576,160 @@ public class InView extends JPanel implements ActionListener{ +>>>>>>> remotes/origin/main + + // 调出进货订单表 + public void InRecord(String iNumber) { + this.mark = 2; // 设置标记为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); // 隐藏删除按钮 + } - /*按钮监听时间*/ + //按钮监听事件 @Override public void actionPerformed(ActionEvent e) { +<<<<<<< HEAD + 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); // 获取选中行的ID + 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); // 获取选中行的ID + 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) { // 遍历商品向量 + 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("cwfeng5@qq.com", "wlcinslohrgpdiac", "1912638153@qq.com", "@新民超市进货需求申请", OrderText); // 创建邮件发送工具类 + } catch (MessagingException e1) { // 捕获异常 + e1.printStackTrace(); // 打印异常信息 + } + v = new Vector(); // 清空商品向量 + refreshBuffer(v); // 刷新缓冲区 + MainView.refreshRemind(); // 刷新提醒 + JOptionPane.showConfirmDialog(null, "发送邮件成功\r\n订单号:" + s[0] + "\r\n负责人:" + uname, "提示", JOptionPane.YES_OPTION); // 提示用户发送邮件成功 + } +======= BufferImpl = new BufferImpl();/*获得购物车*/ Object source = e.getSource(); @@ -507,7 +897,19 @@ public class InView extends JPanel implements ActionListener{ v=new Vector();/*将数组置空*/ refreshBuffer(v); JOptionPane.showConfirmDialog(null,"退出成功", "提示", JOptionPane.PLAIN_MESSAGE); +>>>>>>> remotes/origin/main + } + } else if (exitBtn == source) { // 如果是退出按钮 + int res = JOptionPane.showConfirmDialog(null, "确定退出并清空购物车吗", "结账", JOptionPane.YES_NO_OPTION); // 提示用户确认退出 + if (res == JOptionPane.YES_OPTION) { // 如果用户选择是 + v = new Vector(); // 清空商品向量 + refreshBuffer(v); // 刷新缓冲区 + JOptionPane.showConfirmDialog(null, "退出成功", "提示", JOptionPane.PLAIN_MESSAGE); // 提示用户退出成功 } } } +<<<<<<< HEAD +} +======= } +>>>>>>> remotes/origin/main diff --git a/Supermarket/src/com/lingnan/supermarket/view/MainView.java b/Supermarket/src/com/lingnan/supermarket/view/MainView.java index 6aff0af..0dfd24f 100644 --- a/Supermarket/src/com/lingnan/supermarket/view/MainView.java +++ b/Supermarket/src/com/lingnan/supermarket/view/MainView.java @@ -40,337 +40,282 @@ import com.lingnan.supermarket.view.base.BaseView; import java.awt.*; -public class MainView extends BaseView implements ActionListener, MouseListener,WindowListener{ - - - JMenuBar menuBar; - JMenu settingMenu,helpMenu; - - JMenuItem skinMenuItem,configMenuItem; - - - JSplitPane containerPanel; - - CardLayout rightPanelLayout; - JPanel leftPanel,rightPanel; - - /*菜单栏*/ - JLabel logoLabel,userMenuLabel1,homeMenuLabel,userMenuLabel,inMenuLabel, - outMenuLabel,storageMenuLabel,supplierMenuLabel,catalogMenuLabel; - - static JLabel remindMenuLabel;/*全局调用刷新*/ - - JPanel bottomPanel; - - JLabel timeLabel; - - JPanel purposePanel,timePanel; - JLabel purposeLabel; - - - JButton saveBtn,unSaveBtn,cancleBtn;/*退出时按钮*/ - - // - Timer timer; - - private User user ;/*从登录界面传过来的用户信息*/ - - private BufferImpl bufferImpl; - - private Image bgImage ; - private String iconSkin; - private int skin; - - private Vector vP=new Vector() ;/*用于进货缓存*/ - - - private int location; - - private int sSuper=-1;//界面权限 - - private static inOrderServiceImpl inOrderImpl = new inOrderServiceImpl(); - private static int unConfirmmark;/*未确认订单*/ - - public MainView(User user,int skin,String iconSkin) { - super(1300,850,"新民超市管理系统欢迎您",user,skin); - timer = new Timer(1000,this); - timer.start(); - this.user = user; - - this.sSuper=user.getUsuper();//界面权限 - System.out.println("userid="+user.getId()); - this.addWindowListener(this); - - this.skin = skin; - this.iconSkin = iconSkin; - ImageIcon icon=new ImageIcon(iconSkin); //xxx代表图片存放路径,2.png图片名称及格式 - this.setIconImage(icon.getImage()); - - //获得未进货的信息 +//主界面类,继承自BaseView,实现了ActionListener、MouseListener和WindowListener接口。 + +public class MainView extends BaseView implements ActionListener, MouseListener, WindowListener { + + JMenuBar menuBar; // 菜单栏 + JMenu settingMenu, helpMenu; // 设置菜单和帮助菜单 + JMenuItem skinMenuItem, configMenuItem; // 皮肤菜单项和配置菜单项 + JSplitPane containerPanel; // 主界面容器,分为左右两部分 + CardLayout rightPanelLayout; // 右侧面板的布局管理器 + JPanel leftPanel, rightPanel; // 左侧和右侧的面板 + + /* 菜单栏 */ + JLabel logoLabel, userMenuLabel1, homeMenuLabel, userMenuLabel, inMenuLabel, + outMenuLabel, storageMenuLabel, supplierMenuLabel, catalogMenuLabel; + + static JLabel remindMenuLabel; // 全局调用刷新的提醒标签 + + JPanel bottomPanel; // 底部面板 + JLabel timeLabel; // 显示时间的标签 + JPanel purposePanel, timePanel; // 显示当前位置和时间的面板 + JLabel purposeLabel; // 显示当前位置的标签 + + JButton saveBtn, unSaveBtn, cancleBtn; // 退出时的按钮 + + Timer timer; // 定时器,用于更新时间 + + private User user; // 从登录界面传过来的用户信息 + private BufferImpl bufferImpl; // 缓存实现类 + private Image bgImage; // 背景图片 + private String iconSkin; // 图标皮肤 + private int skin; // 当前皮肤编号 + private Vector vP = new Vector(); // 用于进货缓存 + private int location; // 当前界面的位置 + private int sSuper = -1; // 界面权限 + + private static inOrderServiceImpl inOrderImpl = new inOrderServiceImpl(); // 进货订单服务实现类 + private static int unConfirmmark; // 未确认订单数量 + + //构造函数,初始化主界面并设置用户信息和皮肤 + public MainView(User user, int skin, String iconSkin) { + super(1300, 850, "新民超市管理系统欢迎您", user, skin); + timer = new Timer(1000, this); // 创建定时器,每秒触发一次 + timer.start(); // 启动定时器 + this.user = user; // 设置用户信息 + this.sSuper = user.getUsuper(); // 获取用户权限 + System.out.println("userid=" + user.getId()); // 打印用户ID + this.addWindowListener(this); // 添加窗口监听器 + this.skin = skin; // 设置皮肤编号 + this.iconSkin = iconSkin; // 设置图标皮肤路径 + ImageIcon icon = new ImageIcon(iconSkin); // 创建图标 + this.setIconImage(icon.getImage()); // 设置窗口图标 + + // 获取未进货的信息 Vector vInOrder; - vInOrder = inOrderImpl.findUnconfirmInOrder(); - unConfirmmark=vInOrder.size(); - + vInOrder = inOrderImpl.findUnconfirmInOrder(); // 查找未确认的进货订单 + unConfirmmark = vInOrder.size(); // 设置未确认订单数量 - initView(user,skin); + initView(user, skin); // 初始化界面 } + //构造函数,初始化主界面并设置用户信息 public MainView(User user) { - super(1300,850,"新民超市管理系统欢迎您"); - timer = new Timer(1000,this); - timer.start(); - this.user = user; - - this.sSuper=user.getUsuper();//界面权限 - System.out.println("userid="+user.getId()); - this.addWindowListener(this); - - - //获得未进货的信息 + super(1300, 850, "新民超市管理系统欢迎您"); + timer = new Timer(1000, this); // 创建定时器,每秒触发一次 + timer.start(); // 启动定时器 + this.user = user; // 设置用户信息 + this.sSuper = user.getUsuper(); // 获取用户权限 + System.out.println("userid=" + user.getId()); // 打印用户ID + this.addWindowListener(this); // 添加窗口监听器 + + // 获取未进货的信息 Vector vInOrder; - vInOrder = inOrderImpl.findUnconfirmInOrder(); - unConfirmmark=vInOrder.size(); - + vInOrder = inOrderImpl.findUnconfirmInOrder(); // 查找未确认的进货订单 + unConfirmmark = vInOrder.size(); // 设置未确认订单数量 - initView(user,skin); + initView(user, skin); // 初始化界面 } + //刷新提醒标签,更新未确认订单数量 public static void refreshRemind() { Vector vInOrder; - vInOrder = inOrderImpl.findUnconfirmInOrder(); - unConfirmmark=vInOrder.size(); - remindMenuLabel.setText("待确认进货:"+unConfirmmark); + vInOrder = inOrderImpl.findUnconfirmInOrder(); // 查找未确认的进货订单 + unConfirmmark = vInOrder.size(); // 更新未确认订单数量 + remindMenuLabel.setText("待确认进货:" + unConfirmmark); // 更新提醒标签的文本 } - - - - -/* public static User getUserInf() { - return user; - }*/ - + //初始化界面,设置菜单栏、左侧菜单栏、右侧内容面板等 @Override - protected void initView(User user,int skin) { - - - - - /*菜单栏*/ - menuBar = new JMenuBar(); - - settingMenu = new JMenu("设置"); - - helpMenu = new JMenu("帮助"); - - skinMenuItem = new JMenuItem("随机切换皮肤",new ImageIcon("static\\icon\\skin.png")); - -/* for(int i = 3;i<9;i++) { - - }*/ - configMenuItem = new JMenuItem("参数设置",new ImageIcon("static\\icon\\setting.png")); - skinMenuItem.addActionListener(this); - - settingMenu.add(configMenuItem); - settingMenu.add(skinMenuItem); - menuBar.add(settingMenu); - menuBar.add(helpMenu); - - setJMenuBar(menuBar); - - - /*左边菜单栏设置*/ - - + protected void initView(User user, int skin) { + /* 菜单栏 */ + menuBar = new JMenuBar(); // 创建菜单栏 + settingMenu = new JMenu("设置"); // 创建设置菜单 + helpMenu = new JMenu("帮助"); // 创建帮助菜单 + skinMenuItem = new JMenuItem("随机切换皮肤", new ImageIcon("static\\icon\\skin.png")); // 创建皮肤菜单项 + configMenuItem = new JMenuItem("参数设置", new ImageIcon("static\\icon\\setting.png")); // 创建配置菜单项 + skinMenuItem.addActionListener(this); // 为皮肤菜单项添加事件监听器 + settingMenu.add(configMenuItem); // 将配置菜单项添加到设置菜单 + settingMenu.add(skinMenuItem); // 将皮肤菜单项添加到设置菜单 + menuBar.add(settingMenu); // 将设置菜单添加到菜单栏 + menuBar.add(helpMenu); // 将帮助菜单添加到菜单栏 + setJMenuBar(menuBar); // 设置窗口的菜单栏 + + //左边菜单栏设置 try { - bgImage = ImageIO.read(new File("static\\bg\\bg"+skin+".jpg")); + bgImage = ImageIO.read(new File("static\\bg\\bg" + skin + ".jpg")); // 读取背景图片 } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); + e.printStackTrace(); // 捕获并打印异常 } - leftPanel = new BGPanel(bgImage);/*皮肤*/ - leftPanel.setLayout(null); - - - /*菜单栏:用户登录信息*/ - System.out.println("用户头像地址=="+user.getImg()); - JLabel logoLabel = new JLabel(new ImageIcon(user.getImg()),JLabel.LEFT); - System.out.println(user.getImg()); - leftPanel.add(logoLabel); - logoLabel.setBounds(25, 30,150,150); - - /*账号名字*/ - String x = UsuperIcon(user.getUsuper());/*判断权限返回icon地址*/ - System.out.println("身份地址:"+x); - userMenuLabel1 = new JLabel("|"+user.getUsername()+"|"+user.getRname(),new ImageIcon(x),JLabel.LEFT); - userMenuLabel1.setFont(FontUtil.userFont); - userMenuLabel1.addMouseListener(this); - userMenuLabel1.setBounds(20, 170,180,32); - userMenuLabel1.setForeground(Color.white); - leftPanel.add(userMenuLabel1);/*添加用户选项到菜单栏*/ - - - - /*菜单栏:首页*/ - homeMenuLabel = new JLabel("新民首页",new ImageIcon("static\\icon\\home1.png"),JLabel.LEFT); - homeMenuLabel.setFont(FontUtil.menuFont); - homeMenuLabel.addMouseListener(this); - homeMenuLabel.setBounds(20, 250,150,32); - homeMenuLabel.setForeground(Color.white); - leftPanel.add(homeMenuLabel);/*添加用户选项到菜单栏*/ - - - - /*菜单栏:人员管理*/ - userMenuLabel = new JLabel("人员管理",new ImageIcon("static\\icon\\user1.png"),JLabel.LEFT); - userMenuLabel.setFont(FontUtil.menuFont); - userMenuLabel.addMouseListener(this); - userMenuLabel.setBounds(20, 300,150,32); - userMenuLabel.setForeground(Color.white); - leftPanel.add(userMenuLabel);/*添加用户选项到菜单栏*/ - - /*菜单栏:进货系统*/ - inMenuLabel = new JLabel("进货系统",new ImageIcon("static\\icon\\in1.png") ,JLabel.LEFT); - inMenuLabel.setFont(FontUtil.menuFont); - inMenuLabel.addMouseListener(this); - inMenuLabel.setBounds(20, 350,150,32); - inMenuLabel.setForeground(Color.white); - leftPanel.add(inMenuLabel); - - /*菜单栏:收银系统*/ - outMenuLabel = new JLabel("收银系统",new ImageIcon("static\\icon\\out1.png") ,JLabel.LEFT); - outMenuLabel.setFont(FontUtil.menuFont); - outMenuLabel.addMouseListener(this); - outMenuLabel.setBounds(20, 400,150,32); - outMenuLabel.setForeground(Color.white); - leftPanel.add(outMenuLabel); - - /*菜单栏:库存*/ - storageMenuLabel = new JLabel("商品库存",new ImageIcon("static\\icon\\storage1.png") ,JLabel.LEFT); - storageMenuLabel.setFont(FontUtil.menuFont); - storageMenuLabel.addMouseListener(this); - storageMenuLabel.setBounds(20, 450,150,32); - storageMenuLabel.setForeground(Color.white); - leftPanel.add(storageMenuLabel); - - /*菜单栏:供应商*/ - supplierMenuLabel = new JLabel("供应商",new ImageIcon("static\\icon\\supplier1.png") ,JLabel.LEFT); - supplierMenuLabel.setFont(FontUtil.menuFont); - supplierMenuLabel.addMouseListener(this); - supplierMenuLabel.setBounds(20, 500,150,32); - supplierMenuLabel.setForeground(Color.white); - leftPanel.add(supplierMenuLabel); - - /*菜单栏:商品目录*/ - catalogMenuLabel = new JLabel("商品目录",new ImageIcon("static\\icon\\catalog1.png") ,JLabel.LEFT); - catalogMenuLabel.setFont(FontUtil.menuFont); - catalogMenuLabel.addMouseListener(this); - catalogMenuLabel.setBounds(20,550,150,32); - catalogMenuLabel.setForeground(Color.white); - leftPanel.add(catalogMenuLabel); - - /*提醒进货确认模块*/ - remindMenuLabel = new JLabel("待确认进货:"+unConfirmmark,new ImageIcon("static\\icon\\remind1.png") ,JLabel.LEFT); - remindMenuLabel.setFont(FontUtil.remindFont); - remindMenuLabel.addMouseListener(this); - remindMenuLabel.setBounds(0,650,200,32); - remindMenuLabel.setForeground(Color.white); - leftPanel.add(remindMenuLabel); - - - rightPanelLayout = new CardLayout(); - - //0.超市首页展示 - JPanel homePanel = new HomeView(this); - - //1.用户管理界面:用户的列表 - JPanel userPanel = new UserView(this); - - //2.进货系统界面 - JPanel inPanel = new InView(this,user,vP,1); - - //3收银系统界面 - JPanel outPanel = new OutView(this,user); - - //4.库存系统界面 - JPanel storagePanel = new StorageView(this); - - //5.供应商界面 - JPanel supplierPanel = new SupplierView(this); - - //6商品目录界面 - JPanel ProdCatalogPanel = new ProdCatalogView(this); - - //7商品目录界面 - JPanel superPanel = new SuperView(this); - - //8进货信息提示 - JPanel inPanel2 = new InView(this,user,vP,0); - - /*添加界面并给索引*/ - rightPanel = new JPanel(rightPanelLayout); - rightPanel.add(homePanel, "0"); - rightPanel.add(userPanel, "1"); - rightPanel.add(inPanel, "2"); - rightPanel.add(outPanel, "3"); - rightPanel.add(storagePanel, "4"); - rightPanel.add(supplierPanel, "5"); - rightPanel.add(ProdCatalogPanel, "6"); - rightPanel.add(superPanel, "7"); - rightPanel.add(inPanel2, "8"); - - - containerPanel = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,leftPanel,rightPanel); - containerPanel.setDividerLocation(180); - containerPanel.setDividerSize(0); - - bottomPanel = new JPanel();//默认的布局是流式布局 - - bottomPanel.setBackground(Color.WHITE); - bottomPanel.setLayout(new BorderLayout()); - - purposePanel = new JPanel(); - purposePanel.setLayout(new FlowLayout(FlowLayout.LEFT)); - purposePanel.setBackground(Color.WHITE); - purposeLabel = new JLabel("当前位置是:超市首页"); - purposePanel.add(purposeLabel); - - timePanel=new JPanel(); - timePanel.setLayout(new FlowLayout(FlowLayout.TRAILING)); - timePanel.setBackground(Color.WHITE); - timeLabel = new JLabel(DateUtil.dateToString(new Date(),null)); - timePanel.add(timeLabel); - - bottomPanel.add(purposePanel,"West"); - bottomPanel.add(timePanel,"East"); - Container container = getContentPane(); - container.add(containerPanel,"Center"); - container.add(bottomPanel,"South"); + leftPanel = new BGPanel(bgImage); // 创建带有背景图片的面板 + leftPanel.setLayout(null); // 设置布局为空,自定义布局 + + //菜单栏:用户登录信息 + System.out.println("用户头像地址==" + user.getImg()); // 打印用户头像地址 + JLabel logoLabel = new JLabel(new ImageIcon(user.getImg()), JLabel.LEFT); // 创建用户头像标签 + System.out.println(user.getImg()); // 打印用户头像地址 + leftPanel.add(logoLabel); // 将用户头像标签添加到左侧面板 + logoLabel.setBounds(25, 30, 150, 150); // 设置用户头像标签的位置和大小 + + //账号名字 + String x = UsuperIcon(user.getUsuper()); // 根据用户权限返回对应的图标地址 + System.out.println("身份地址:" + x); // 打印身份图标地址 + userMenuLabel1 = new JLabel("|" + user.getUsername() + "|" + user.getRname(), new ImageIcon(x), JLabel.LEFT); // 创建用户信息标签 + userMenuLabel1.setFont(FontUtil.userFont); // 设置字体 + userMenuLabel1.addMouseListener(this); // 添加鼠标监听器 + userMenuLabel1.setBounds(20, 170, 180, 32); // 设置位置和大小 + userMenuLabel1.setForeground(Color.white); // 设置字体颜色为白色 + leftPanel.add(userMenuLabel1); // 将用户信息标签添加到左侧面板 + + // 菜单栏:首页 + homeMenuLabel = new JLabel("新民首页", new ImageIcon("static\\icon\\home1.png"), JLabel.LEFT); // 创建首页标签 + homeMenuLabel.setFont(FontUtil.menuFont); // 设置字体 + homeMenuLabel.addMouseListener(this); // 添加鼠标监听器 + homeMenuLabel.setBounds(20, 250, 150, 32); // 设置位置和大小 + homeMenuLabel.setForeground(Color.white); // 设置字体颜色为白色 + leftPanel.add(homeMenuLabel); // 将首页标签添加到左侧面板 + + // 菜单栏:人员管理 + userMenuLabel = new JLabel("人员管理", new ImageIcon("static\\icon\\user1.png"), JLabel.LEFT); // 创建人员管理标签 + userMenuLabel.setFont(FontUtil.menuFont); // 设置字体 + userMenuLabel.addMouseListener(this); // 添加鼠标监听器 + userMenuLabel.setBounds(20, 300, 150, 32); // 设置位置和大小 + userMenuLabel.setForeground(Color.white); // 设置字体颜色为白色 + leftPanel.add(userMenuLabel); // 将人员管理标签添加到左侧面板 + + // 菜单栏:进货系统 + inMenuLabel = new JLabel("进货系统", new ImageIcon("static\\icon\\in1.png"), JLabel.LEFT); // 创建进货系统标签 + inMenuLabel.setFont(FontUtil.menuFont); // 设置字体 + inMenuLabel.addMouseListener(this); // 添加鼠标监听器 + inMenuLabel.setBounds(20, 350, 150, 32); // 设置位置和大小 + inMenuLabel.setForeground(Color.white); // 设置字体颜色为白色 + leftPanel.add(inMenuLabel); // 将进货系统标签添加到左侧面板 + + // 菜单栏:收银系统 + outMenuLabel = new JLabel("收银系统", new ImageIcon("static\\icon\\out1.png"), JLabel.LEFT); // 创建收银系统标签 + outMenuLabel.setFont(FontUtil.menuFont); // 设置字体 + outMenuLabel.addMouseListener(this); // 添加鼠标监听器 + outMenuLabel.setBounds(20, 400, 150, 32); // 设置位置和大小 + outMenuLabel.setForeground(Color.white); // 设置字体颜色为白色 + leftPanel.add(outMenuLabel); // 将收银系统标签添加到左侧面板 + + // 菜单栏:库存 + storageMenuLabel = new JLabel("商品库存", new ImageIcon("static\\icon\\storage1.png"), JLabel.LEFT); // 创建库存标签 + storageMenuLabel.setFont(FontUtil.menuFont); // 设置字体 + storageMenuLabel.addMouseListener(this); // 添加鼠标监听器 + storageMenuLabel.setBounds(20, 450, 150, 32); // 设置位置和大小 + storageMenuLabel.setForeground(Color.white); // 设置字体颜色为白色 + leftPanel.add(storageMenuLabel); // 将库存标签添加到左侧面板 + + // 菜单栏:供应商 + supplierMenuLabel = new JLabel("供应商", new ImageIcon("static\\icon\\supplier1.png"), JLabel.LEFT); // 创建供应商标签 + supplierMenuLabel.setFont(FontUtil.menuFont); // 设置字体 + supplierMenuLabel.addMouseListener(this); // 添加鼠标监听器 + supplierMenuLabel.setBounds(20, 500, 150, 32); // 设置位置和大小 + supplierMenuLabel.setForeground(Color.white); // 设置字体颜色为白色 + leftPanel.add(supplierMenuLabel); // 将供应商标签添加到左侧面板 + + // 菜单栏:商品目录 + catalogMenuLabel = new JLabel("商品目录", new ImageIcon("static\\icon\\catalog1.png"), JLabel.LEFT); // 创建商品目录标签 + catalogMenuLabel.setFont(FontUtil.menuFont); // 设置字体 + catalogMenuLabel.addMouseListener(this); // 添加鼠标监听器 + catalogMenuLabel.setBounds(20, 550, 150, 32); // 设置位置和大小 + catalogMenuLabel.setForeground(Color.white); // 设置字体颜色为白色 + leftPanel.add(catalogMenuLabel); // 将商品目录标签添加到左侧面板 + + // 提醒进货确认模块 + remindMenuLabel = new JLabel("待确认进货:" + unConfirmmark, new ImageIcon("static\\icon\\remind1.png"), JLabel.LEFT); // 创建提醒标签 + remindMenuLabel.setFont(FontUtil.remindFont); // 设置字体 + remindMenuLabel.addMouseListener(this); // 添加鼠标监听器 + remindMenuLabel.setBounds(0, 650, 200, 32); // 设置位置和大小 + remindMenuLabel.setForeground(Color.white); // 设置字体颜色为白色 + leftPanel.add(remindMenuLabel); // 将提醒标签添加到左侧面板 + + rightPanelLayout = new CardLayout(); // 创建卡片布局管理器 + + // 0.超市首页展示 + JPanel homePanel = new HomeView(this); // 创建首页面板 + + // 1.用户管理界面:用户的列表 + JPanel userPanel = new UserView(this); // 创建用户管理面板 + + // 2.进货系统界面 + JPanel inPanel = new InView(this, user, vP, 1); // 创建进货系统面板 + + // 3收银系统界面 + JPanel outPanel = new OutView(this, user); // 创建收银系统面板 + + // 4.库存系统界面 + JPanel storagePanel = new StorageView(this); // 创建库存系统面板 + + // 5.供应商界面 + JPanel supplierPanel = new SupplierView(this); // 创建供应商面板 + + // 6商品目录界面 + JPanel ProdCatalogPanel = new ProdCatalogView(this); // 创建商品目录面板 + + // 7商品目录界面 + JPanel superPanel = new SuperView(this); // 创建普通用户界面 + + // 8进货信息提示 + JPanel inPanel2 = new InView(this, user, vP, 0); // 创建进货信息提示面板 + + /* 添加界面并给索引 */ + rightPanel = new JPanel(rightPanelLayout); // 创建右侧内容面板 + rightPanel.add(homePanel, "0"); // 添加首页面板并设置索引 + rightPanel.add(userPanel, "1"); // 添加用户管理面板并设置索引 + rightPanel.add(inPanel, "2"); // 添加进货系统面板并设置索引 + rightPanel.add(outPanel, "3"); // 添加收银系统面板并设置索引 + rightPanel.add(storagePanel, "4"); // 添加库存系统面板并设置索引 + rightPanel.add(supplierPanel, "5"); // 添加供应商面板并设置索引 + rightPanel.add(ProdCatalogPanel, "6"); // 添加商品目录面板并设置索引 + rightPanel.add(superPanel, "7"); // 添加普通用户面板并设置索引 + rightPanel.add(inPanel2, "8"); // 添加进货信息提示面板并设置索引 + + containerPanel = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, leftPanel, rightPanel); // 创建左右分割面板 + containerPanel.setDividerLocation(180); // 设置分割位置 + containerPanel.setDividerSize(0); // 设置分割线宽度为0 + + bottomPanel = new JPanel(); // 创建底部面板 + bottomPanel.setBackground(Color.WHITE); // 设置背景颜色为白色 + bottomPanel.setLayout(new BorderLayout()); // 设置布局为边界布局 + + purposePanel = new JPanel(); // 创建当前位置面板 + purposePanel.setLayout(new FlowLayout(FlowLayout.LEFT)); // 设置布局为流式布局(左对齐) + purposePanel.setBackground(Color.WHITE); // 设置背景颜色为白色 + purposeLabel = new JLabel("当前位置是:超市首页"); // 创建当前位置标签 + purposePanel.add(purposeLabel); // 将当前位置标签添加到当前位置面板 + + timePanel = new JPanel(); // 创建时间面板 + timePanel.setLayout(new FlowLayout(FlowLayout.TRAILING)); // 设置布局为流式布局(右对齐) + timePanel.setBackground(Color.WHITE); // 设置背景颜色为白色 + timeLabel = new JLabel(DateUtil.dateToString(new Date(), null)); // 创建时间标签 + timePanel.add(timeLabel); // 将时间标签添加到时间面板 + + bottomPanel.add(purposePanel, "West"); // 将当前位置面板添加到底部面板的左侧 + bottomPanel.add(timePanel, "East"); // 将时间面板添加到底部面板的右侧 + Container container = getContentPane(); // 获取内容面板 + container.add(containerPanel, "Center"); // 将主界面容器添加到内容面板的中间 + container.add(bottomPanel, "South"); // 将底部面板添加到内容面板的底部 } @Override public void actionPerformed(ActionEvent e) { - Object source = e.getSource(); - timeLabel.setText(DateUtil.dateToString(new Date(),null)); - if(source==skinMenuItem)/*换肤*/{ - System.out.println("切换皮肤"); - Random random=new Random(); - skin=random.nextInt(10); - this.dispose(); - new MainView(user,skin,iconSkin); + Object source = e.getSource(); // 获取事件来源 + timeLabel.setText(DateUtil.dateToString(new Date(), null)); // 更新时间标签 + if (source == skinMenuItem) /* 换肤 */ { + System.out.println("切换皮肤"); // 打印日志 + Random random = new Random(); // 创建随机数生成器 + skin = random.nextInt(10); // 随机生成皮肤编号 + this.dispose(); // 关闭当前窗口 + new MainView(user, skin, iconSkin); // 重新创建主界面 } - } - - /** - * cwf 2024/12/11 - * 修改不同权限用户的功能代码 - */ - + //左侧菜单栏点击事件处理方法。 @Override - /* 左侧菜单栏点击事件 */ public void mouseClicked(MouseEvent e) { Object source = e.getSource(); // 获取点击事件的来源 @@ -477,175 +422,146 @@ public class MainView extends BaseView implements ActionListener, MouseListener, refreshRemove(); // 刷新当前界面的位置信息 } - //获取当前位置 - public void refreshRemove(){ - - purposePanel.removeAll(); - if(location==0){ - purposeLabel = new JLabel("当前位置是:"+homeMenuLabel.getText()); - - }else if(location==1){ - purposeLabel = new JLabel("当前位置是:"+userMenuLabel.getText()); - - }else if(location==2){ - purposeLabel = new JLabel("当前位置是:"+inMenuLabel.getText()); - - }else if(location==3){ - purposeLabel = new JLabel("当前位置是:"+outMenuLabel.getText()); - - }else if(location==4){ - purposeLabel = new JLabel("当前位置是:"+storageMenuLabel.getText()); - - }else if(location==5){ - purposeLabel = new JLabel("当前位置是:"+supplierMenuLabel.getText()); - - }else{ - purposeLabel = new JLabel("当前位置是:"+catalogMenuLabel.getText()); + //刷新当前界面的位置信息。 + public void refreshRemove() { + purposePanel.removeAll(); // 移除当前位置面板的所有组件 + if (location == 0) { + purposeLabel = new JLabel("当前位置是:" + homeMenuLabel.getText()); // 设置当前位置为首页 + } else if (location == 1) { + purposeLabel = new JLabel("当前位置是:" + userMenuLabel.getText()); // 设置当前位置为人员管理 + } else if (location == 2) { + purposeLabel = new JLabel("当前位置是:" + inMenuLabel.getText()); // 设置当前位置为进货系统 + } else if (location == 3) { + purposeLabel = new JLabel("当前位置是:" + outMenuLabel.getText()); // 设置当前位置为收银系统 + } else if (location == 4) { + purposeLabel = new JLabel("当前位置是:" + storageMenuLabel.getText()); // 设置当前位置为库存系统 + } else if (location == 5) { + purposeLabel = new JLabel("当前位置是:" + supplierMenuLabel.getText()); // 设置当前位置为供应商 + } else { + purposeLabel = new JLabel("当前位置是:" + catalogMenuLabel.getText()); // 设置当前位置为商品目录 } - purposePanel.add(purposeLabel); - + purposePanel.add(purposeLabel); // 将当前位置标签添加到当前位置面板 } @Override public void mousePressed(MouseEvent e) { - // TODO Auto-generated method stub - + // 鼠标按下事件,暂未实现 } @Override public void mouseReleased(MouseEvent e) { - // TODO Auto-generated method stub - + // 鼠标释放事件,暂未实现 } - @Override/*鼠标焦点时*/ + @Override + // 鼠标焦点时 public void mouseEntered(MouseEvent e) { - Object source = e.getSource(); - if(source==homeMenuLabel) { - homeMenuLabel.setForeground(new Color(18, 150, 219)); - homeMenuLabel.setIcon(new ImageIcon("static\\icon\\home2.png")); + Object source = e.getSource(); // 获取事件来源 + if (source == homeMenuLabel) { + homeMenuLabel.setForeground(new Color(18, 150, 219)); // 设置字体颜色 + homeMenuLabel.setIcon(new ImageIcon("static\\icon\\home2.png")); // 设置图标 } - if(source==userMenuLabel) { - userMenuLabel.setForeground(new Color(18, 150, 219)); - userMenuLabel.setIcon(new ImageIcon("static\\icon\\user2.png")); - }else if(source==inMenuLabel) { - inMenuLabel.setForeground(new Color(18, 150, 219)); - inMenuLabel.setIcon(new ImageIcon("static\\icon\\in2.png")); - }else if(source==outMenuLabel) { - outMenuLabel.setForeground(new Color(18, 150, 219)); - outMenuLabel.setIcon(new ImageIcon("static\\icon\\out2.png")); - }else if(source==storageMenuLabel) { - storageMenuLabel.setForeground(new Color(18, 150, 219)); - storageMenuLabel.setIcon(new ImageIcon("static\\icon\\storage2.png")); - }else if(source==supplierMenuLabel) { - supplierMenuLabel.setForeground(new Color(18, 150, 219)); - supplierMenuLabel.setIcon(new ImageIcon("static\\icon\\supplier2.png")); - }else if(source==catalogMenuLabel) { - catalogMenuLabel.setForeground(new Color(18, 150, 219)); - catalogMenuLabel.setIcon(new ImageIcon("static\\icon\\catalog2.png")); - } else if(source==userMenuLabel1) { - userMenuLabel1.setForeground(new Color(18, 150, 219)); - + if (source == userMenuLabel) { + userMenuLabel.setForeground(new Color(18, 150, 219)); // 设置字体颜色 + userMenuLabel.setIcon(new ImageIcon("static\\icon\\user2.png")); // 设置图标 + } else if (source == inMenuLabel) { + inMenuLabel.setForeground(new Color(18, 150, 219)); // 设置字体颜色 + inMenuLabel.setIcon(new ImageIcon("static\\icon\\in2.png")); // 设置图标 + } else if (source == outMenuLabel) { + outMenuLabel.setForeground(new Color(18, 150, 219)); // 设置字体颜色 + outMenuLabel.setIcon(new ImageIcon("static\\icon\\out2.png")); // 设置图标 + } else if (source == storageMenuLabel) { + storageMenuLabel.setForeground(new Color(18, 150, 219)); // 设置字体颜色 + storageMenuLabel.setIcon(new ImageIcon("static\\icon\\storage2.png")); // 设置图标 + } else if (source == supplierMenuLabel) { + supplierMenuLabel.setForeground(new Color(18, 150, 219)); // 设置字体颜色 + supplierMenuLabel.setIcon(new ImageIcon("static\\icon\\supplier2.png")); // 设置图标 + } else if (source == catalogMenuLabel) { + catalogMenuLabel.setForeground(new Color(18, 150, 219)); // 设置字体颜色 + catalogMenuLabel.setIcon(new ImageIcon("static\\icon\\catalog2.png")); // 设置图标 + } else if (source == userMenuLabel1) { + userMenuLabel1.setForeground(new Color(18, 150, 219)); // 设置字体颜色 } -} + } @Override public void mouseExited(MouseEvent e) { - Object source = e.getSource(); - if(source==homeMenuLabel) { - homeMenuLabel.setForeground(Color.white); - homeMenuLabel.setIcon(new ImageIcon("static\\icon\\home1.png")); - } else if(source==userMenuLabel) { - userMenuLabel.setForeground(Color.white); - userMenuLabel.setIcon(new ImageIcon("static\\icon\\user1.png")); - }else if(source==inMenuLabel) { - inMenuLabel.setForeground(Color.white); - inMenuLabel.setIcon(new ImageIcon("static\\icon\\in1.png")); - }else if(source==outMenuLabel) { - outMenuLabel.setForeground(Color.white); - outMenuLabel.setIcon(new ImageIcon("static\\icon\\out1.png")); - }else if(source==storageMenuLabel) { - storageMenuLabel.setForeground(Color.white); - storageMenuLabel.setIcon(new ImageIcon("static\\icon\\storage1.png")); - }else if(source==supplierMenuLabel) { - supplierMenuLabel.setForeground(Color.white); - supplierMenuLabel.setIcon(new ImageIcon("static\\icon\\supplier1.png")); - }else if(source==catalogMenuLabel) { - catalogMenuLabel.setForeground(Color.white); - catalogMenuLabel.setIcon(new ImageIcon("static\\icon\\catalog1.png")); - } else { - userMenuLabel1.setForeground(Color.white); - + Object source = e.getSource(); // 获取事件来源 + if (source == homeMenuLabel) { + homeMenuLabel.setForeground(Color.white); // 设置字体颜色为白色 + homeMenuLabel.setIcon(new ImageIcon("static\\icon\\home1.png")); // 设置图标 + } else if (source == userMenuLabel) { + userMenuLabel.setForeground(Color.white); // 设置字体颜色为白色 + userMenuLabel.setIcon(new ImageIcon("static\\icon\\user1.png")); // 设置图标 + } else if (source == inMenuLabel) { + inMenuLabel.setForeground(Color.white); // 设置字体颜色为白色 + inMenuLabel.setIcon(new ImageIcon("static\\icon\\in1.png")); // 设置图标 + } else if (source == outMenuLabel) { + outMenuLabel.setForeground(Color.white); // 设置字体颜色为白色 + outMenuLabel.setIcon(new ImageIcon("static\\icon\\out1.png")); // 设置图标 + } else if (source == storageMenuLabel) { + storageMenuLabel.setForeground(Color.white); // 设置字体颜色为白色 + storageMenuLabel.setIcon(new ImageIcon("static\\icon\\storage1.png")); // 设置图标 + } else if (source == supplierMenuLabel) { + supplierMenuLabel.setForeground(Color.white); // 设置字体颜色为白色 + supplierMenuLabel.setIcon(new ImageIcon("static\\icon\\supplier1.png")); // 设置图标 + } else if (source == catalogMenuLabel) { + catalogMenuLabel.setForeground(Color.white); // 设置字体颜色为白色 + catalogMenuLabel.setIcon(new ImageIcon("static\\icon\\catalog1.png")); // 设置图标 + } else { + userMenuLabel1.setForeground(Color.white); // 设置字体颜色为白色 } - } - @Override protected void initView() { - // TODO Auto-generated method stub - + // 初始化界面,未实现 } @Override public void windowOpened(WindowEvent e) { - // TODO Auto-generated method stub - + // 窗口打开事件,未实现 } @Override public void windowClosing(WindowEvent e) { - // TODO Auto-generated method stub - Object source = e.getSource(); - if(source==this) {/*关闭窗口时检查进货系统和出货系统是否还有记录*/ - this.vP =InView.getVector(); - System.out.println("v的size="+vP.size()); - bufferImpl = new BufferImpl(); - if(vP.size()!=0||bufferImpl.allOutBuffer().size()!=0) {/*如果购物车还有记录*/ - CloseDialog closeDialog = new CloseDialog(this,vP); - closeDialog.setVisible(true); - }else - System.exit(0); - - + Object source = e.getSource(); // 获取事件来源 + if (source == this) { // 关闭窗口时检查进货系统和出货系统是否还有记录 + this.vP = InView.getVector(); // 获取进货缓存 + System.out.println("v的size=" + vP.size()); // 打印进货缓存大小 + bufferImpl = new BufferImpl(); // 创建缓存实现类 + if (vP.size() != 0 || bufferImpl.allOutBuffer().size() != 0) { // 如果购物车还有记录 + CloseDialog closeDialog = new CloseDialog(this, vP); // 创建关闭对话框 + closeDialog.setVisible(true); // 显示关闭对话框 + } else { + System.exit(0); // 退出程序 + } } } @Override public void windowClosed(WindowEvent e) { - // TODO Auto-generated method stub - + // 窗口关闭事件,未实现 } @Override public void windowIconified(WindowEvent e) { - // TODO Auto-generated method stub - + // 窗口最小化事件,未实现 } @Override public void windowDeiconified(WindowEvent e) { - // TODO Auto-generated method stub - + // 窗口恢复事件,未实现 } @Override public void windowActivated(WindowEvent e) { - // TODO Auto-generated method stub - + // 窗口激活事件,未实现 } @Override public void windowDeactivated(WindowEvent e) { - // TODO Auto-generated method stub - + // 窗口失活事件,未实现 } - - - - - - - -} +} \ No newline at end of file diff --git a/Supermarket/src/com/lingnan/supermarket/view/Nimbus.java b/Supermarket/src/com/lingnan/supermarket/view/Nimbus.java index bdfaac6..906fae8 100644 --- a/Supermarket/src/com/lingnan/supermarket/view/Nimbus.java +++ b/Supermarket/src/com/lingnan/supermarket/view/Nimbus.java @@ -1,14 +1,18 @@ package com.lingnan.supermarket.view; + import javax.swing.UIManager; +// 用于设置Java Swing界面的Nimbus风格 public class Nimbus { - /*nimbus风格*/ + // 用于设置Java Swing界面呈现为Nimbus风格 public static void Nimbus() { - try { - UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel"); - } catch (Exception e) { - e.printStackTrace(); - } + try { + // 通过UIManager的setLookAndFeel方法来设置界面的外观风格为Nimbus风格 + UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel"); + } catch (Exception e) { + // 如果在设置外观风格的过程中出现异常,则打印异常堆栈信息 + e.printStackTrace(); + } } -} +} \ No newline at end of file diff --git a/Supermarket/src/com/lingnan/supermarket/view/UserView.java b/Supermarket/src/com/lingnan/supermarket/view/UserView.java index d8eec3c..47edf1f 100644 --- a/Supermarket/src/com/lingnan/supermarket/view/UserView.java +++ b/Supermarket/src/com/lingnan/supermarket/view/UserView.java @@ -38,7 +38,7 @@ public class UserView extends JPanel implements ActionListener { // 用于触发搜索操作的按钮 private JButton searchBtn; - // 用于存放操作按钮(添加、更新、删除等)的面板 + // 用于存放操作按钮的面板 private JPanel opePanel; // 用于触发添加用户操作的按钮 private JButton addBtn, updateBtn, deleteBtn; @@ -86,9 +86,9 @@ public class UserView extends JPanel implements ActionListener { searchPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); // 创建一个显示当前位置提示信息的标签,这里显示为"当前位置>人员管理" locationLabel = new JLabel("当前位置>人员管理"); - // 设置标签的字体为通过FontUtil类获取的特定字体(这里假设FontUtil类用于统一管理字体相关设置) + // 设置标签的字体为通过FontUtil类获取的特定字体 locationLabel.setFont(new FontUtil().userFont); - // 设置标签的前景色(文字颜色)为特定的蓝色(RGB值为18, 150, 219) + // 设置标签的前景色为特定的蓝色 locationLabel.setForeground(new Color(18, 150, 219)); // 创建一个显示"姓名"文字的标签,用于提示用户在旁边的文本框中输入姓名进行搜索 nameLabel = new JLabel("姓名"); @@ -97,7 +97,7 @@ public class UserView extends JPanel implements ActionListener { // 创建一个按钮,使用指定路径下的图标文件作为按钮的图标,用于触发搜索操作 searchBtn = new JButton(new ImageIcon("static\\icon\\search.png")); - // 创建一个新的面板opePanel,设置其布局为FlowLayout,且组件右对齐,用于存放操作按钮(添加、更新、删除) + // 创建一个新的面板opePanel,设置其布局为FlowLayout,且组件右对齐,用于存放操作按钮 opePanel = new JPanel(new FlowLayout(FlowLayout.RIGHT)); // 创建一个按钮,使用指定路径下的图标文件("static\\icon\\add.png")作为按钮的图标,用于触发添加用户操作 addBtn = new JButton(new ImageIcon("static\\icon\\add.png")); @@ -106,7 +106,7 @@ public class UserView extends JPanel implements ActionListener { // 创建一个按钮,使用指定路径下的图标文件("static\\icon\\delete.png")作为按钮的图标,用于触发删除用户操作 deleteBtn = new JButton(new ImageIcon("static\\icon\\delete.png")); - // 为添加、更新、删除和搜索按钮添加点击事件监听器,将按钮的点击事件绑定到当前类(实现了ActionListener接口)的actionPerformed方法上,以便处理相应的操作逻辑 + // 为添加、更新、删除和搜索按钮添加点击事件监听器,将按钮的点击事件绑定到当前类的actionPerformed方法上,以便处理相应的操作逻辑 addBtn.addActionListener(this); updateBtn.addActionListener(this); deleteBtn.addActionListener(this); @@ -123,18 +123,18 @@ public class UserView extends JPanel implements ActionListener { searchPanel.add(nameSearchTF); searchPanel.add(searchBtn); - // 将搜索面板添加到toolBarPanel的西边(左侧)区域,将操作按钮面板添加到toolBarPanel的东边(右侧)区域 + // 将搜索面板添加到toolBarPanel的西边区域,将操作按钮面板添加到toolBarPanel的东边区域 toolBarPanel.add(searchPanel, "West"); toolBarPanel.add(opePanel, "East"); // 创建用户表格数据模型对象 userTableModel = new UserTableModel(); - // 调用数据模型的方法获取所有用户数据,用于初始化表格显示内容(这里假设UserTableModel类中的all方法用于从数据库等数据源获取全部用户数据并填充到模型中) + // 调用数据模型的方法获取所有用户数据,用于初始化表格显示内容 userTableModel.all(); // 创建一个JTable对象,使用前面创建的用户表格数据模型userTableModel来管理表格中的数据展示和交互 userTable = new JTable(userTableModel); - // 设置表格的字体为通过FontUtil类获取的适用于表格的特定字体(假设FontUtil类中定义了相关字体常量) + // 设置表格的字体为通过FontUtil类获取的适用于表格的特定字体 userTable.setFont(FontUtil.tableFont); // 设置表格每行的高度为50像素,调整表格的显示样式 userTable.setRowHeight(50); @@ -143,29 +143,29 @@ public class UserView extends JPanel implements ActionListener { // 创建一个新的面板bottomPanel,设置其布局为FlowLayout,且组件左对齐,用于存放记录数相关提示信息 bottomPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); - // 创建一个显示用户记录总数的标签,初始文本为"总共"加上通过用户表格数据模型获取的行数(假设UserTableModel类的getRowCount方法返回当前模型中的数据行数)以及"条"字 + // 创建一个显示用户记录总数的标签,初始文本为"总共"加上通过用户表格数据模型获取的行数 countInfoLabel = new JLabel("总共" + userTableModel.getRowCount() + "条"); // 将记录数标签添加到bottomPanel面板中 bottomPanel.add(countInfoLabel); - // 将顶部工具栏面板添加到当前面板(UserView)的北部(上方)区域 + // 将顶部工具栏面板添加到当前面板的北部区域 this.add(toolBarPanel, "North"); - // 将包含用户表格的滚动面板添加到当前面板(UserView)的中部区域,使其在界面中间显示 + // 将包含用户表格的滚动面板添加到当前面板的中部区域,使其在界面中间显示 this.add(tableScrollPane, "Center"); - // 将记录数面板添加到当前面板(UserView)的南部(下方)区域 + // 将记录数面板添加到当前面板的南部区域 this.add(bottomPanel, "South"); - // 设置当前面板(UserView)可见,使其在界面上显示出来 + // 设置当前面板可见,使其在界面上显示出来 setVisible(true); } // 处理按钮点击等用户交互动作的方法,实现了ActionListener接口中的方法 @Override public void actionPerformed(ActionEvent e) { - // 获取触发事件的源组件(即被点击的按钮等组件) + // 获取触发事件的源组件 Object source = e.getSource(); if (addBtn == source) { - // 如果点击的是添加按钮,执行以下操作: + // 如果点击的是添加按钮执行以下操作: // 创建一个用于添加用户信息的对话框 UserDialog userDialog = new UserDialog(jFrame); @@ -189,9 +189,9 @@ public class UserView extends JPanel implements ActionListener { // 弹出确认对话框,询问用户是否确定删除指定id的用户记录,提供"是"和"否"两个选项,返回用户选择的结果 int select = JOptionPane.showConfirmDialog(this, "是否删除id=" + id, "提示", JOptionPane.YES_NO_OPTION); if (select == JOptionPane.YES_OPTION) { - // 如果用户选择了"是"(确认删除),执行以下操作: + // 如果用户选择了是,执行以下操作: - // 调用用户服务接口的删除用户方法,传入要删除的用户id,尝试从数据库中删除对应的用户记录,并获取返回结果(假设返回1表示删除成功,其他值表示失败) + // 调用用户服务接口的删除用户方法,传入要删除的用户id,尝试从数据库中删除对应的用户记录,并获取返回结果 if (userService.deleteUser(id) == 1) { // 如果删除成功,弹出提示框显示"删除成功"的消息,提示框的图标为信息图标 JOptionPane.showMessageDialog(this, "删除成功", "提示", JOptionPane.INFORMATION_MESSAGE); @@ -203,7 +203,7 @@ public class UserView extends JPanel implements ActionListener { // 无论删除操作是否成功,都调用刷新用户数据的方法,更新界面上的用户数据显示,确保表格等显示内容与数据库中的最新数据一致 refreshUser(); } else { - // 如果点击的是搜索按钮(即其他未明确匹配的按钮点击情况,这里目前代码逻辑中只存在搜索按钮可能进入此分支),执行以下操作: + // 如果点击的是搜索按钮,执行以下操作: System.out.println("搜索"); // 调用刷新按姓名搜索结果的方法,根据用户在姓名搜索文本框中输入的内容进行数据刷新和表格显示更新 diff --git a/Supermarket/src/com/lingnan/supermarket/view/base/BaseView.java b/Supermarket/src/com/lingnan/supermarket/view/base/BaseView.java index 1a219ad..256c187 100644 --- a/Supermarket/src/com/lingnan/supermarket/view/base/BaseView.java +++ b/Supermarket/src/com/lingnan/supermarket/view/base/BaseView.java @@ -2,70 +2,92 @@ package com.lingnan.supermarket.view.base; import java.awt.Toolkit; import java.util.Vector; - import javax.swing.JFrame; +// 导入相关的业务数据对象类,用于在视图相关操作中可能涉及的数据传递等情况 import com.lingnan.supermarket.dto.Production; import com.lingnan.supermarket.dto.User; +// 定义抽象类BaseView继承自JFrame,用于统一管理视图的一些通用属性和行为 public abstract class BaseView extends JFrame { - - public BaseView(int initWidth,int initHeigth,String title) { + + // 基本构造方法,用于创建一个具有指定初始宽度、高度和标题的窗口,并进行一些初始化设置 + public BaseView(int initWidth, int initHeigth, String title) { + // 设置窗口的标题 this.setTitle(title); - this.setSize(initWidth,initHeigth); + // 设置窗口的初始大小 + this.setSize(initWidth, initHeigth); + + // 通过Toolkit.getDefaultToolkit().getScreenSize()方法获取屏幕尺寸信息 int width = Toolkit.getDefaultToolkit().getScreenSize().width; int height = Toolkit.getDefaultToolkit().getScreenSize().height; - this.setLocation((width-getWidth())/2,(height-getHeight())/2); - + // 通过计算屏幕中心与窗口大小差值的一半来确定窗口左上角坐标 + this.setLocation((width - getWidth()) / 2, (height - getHeight()) / 2); + + // 调用抽象方法initView() initView(); + // 设置窗口为可见状态,使其显示出来 this.setVisible(true); + // 设置窗口关闭操作的默认行为,当关闭窗口时,整个应用程序将退出 this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } - - /*带对象参数的构造方法*/ - public BaseView(int initWidth,int initHeigth,String title,User user,int skin) { + + // 用于创建一个具有指定初始宽度、高度、标题以及关联用户信息和皮肤相关参数的窗口,并进行一些初始化设置 + public BaseView(int initWidth, int initHeigth, String title, User user, int skin) { + // 设置窗口的标题 this.setTitle(title); - this.setSize(initWidth,initHeigth); + // 设置窗口的初始大小 + this.setSize(initWidth, initHeigth); + + // 获取屏幕的宽度和高度 int width = Toolkit.getDefaultToolkit().getScreenSize().width; int height = Toolkit.getDefaultToolkit().getScreenSize().height; - this.setLocation((width-getWidth())/2,(height-getHeight())/2); - - + // 设置窗口在屏幕中的位置,使其居中显示 + this.setLocation((width - getWidth()) / 2, (height - getHeight()) / 2); + // 设置窗口为可见状态,使其显示出来 this.setVisible(true); + // 设置窗口关闭操作的默认行为,这里设置为DO_NOTHING_ON_CLOSE,表示关闭窗口时不执行任何默认操作,通常由子类根据具体需求自定义关闭行为 this.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); } - - + // 抽象方法,由具体的子类实现,用于进行特定视图的初始化操作,比如添加各种组件、设置布局等 protected abstract void initView(); - protected abstract void initView(User user,int skin); - - /*判断权限并返回字符*/ + // 抽象方法,由具体的子类实现,用于进行特定视图的初始化操作 + protected abstract void initView(User user, int skin); + + // 根据传入的权限值判断对应的权限角色,并返回相应的角色名称字符串 public String Usuper(int usuper) { - String x=null; - if(usuper==0) - x="管理员"; - else if(usuper==1) - x="进货员"; - else if(usuper==2) - x="收银员"; + String x = null; + // 如果权限值为0,则对应的角色是管理员 + if (usuper == 0) + x = "管理员"; + // 如果权限值为1,则对应的角色是进货员 + else if (usuper == 1) + x = "进货员"; + // 如果权限值为2,则对应的角色是收银员 + else if (usuper == 2) + x = "收银员"; + // 如果权限值为3,则对应的角色是超级管理员 + else if (usuper == 3) + x = "超级管理员"; return x; } - - /*判断权限并返回icon地址*/ + + // 根据传入的权限值判断对应的权限角色,并返回相应角色对应的图标文件地址字符串 public String UsuperIcon(int usuper) { - String x=null; - if(usuper==0) - x="static\\icon\\admin.png"; - else if(usuper==1) - x="static\\icon\\carrier.png"; - else if(usuper==2) - x="static\\icon\\cashier.png"; + String x = null; + // 如果权限值为0,则返回管理员角色对应的图标文件地址 + if (usuper == 0) + x = "static\\icon\\admin.png"; + // 如果权限值为1,则返回进货员角色对应的图标文件地址 + else if (usuper == 1) + x = "static\\icon\\carrier.png"; + // 如果权限值为2,则返回收银员角色对应的图标文件地址 + else if (usuper == 2) + x = "static\\icon\\cashier.png"; return x; } - - -} +} \ No newline at end of file