diff --git a/Supermarket/.idea/dataSources/5b23e521-053a-47c0-ae28-a98b513bc6ec.xml b/Supermarket/.idea/dataSources/5b23e521-053a-47c0-ae28-a98b513bc6ec.xml index 905f93f..6ba1d51 100644 --- a/Supermarket/.idea/dataSources/5b23e521-053a-47c0-ae28-a98b513bc6ec.xml +++ b/Supermarket/.idea/dataSources/5b23e521-053a-47c0-ae28-a98b513bc6ec.xml @@ -1,44 +1,7 @@ - - lower/lower - InnoDB - InnoDB - |root||root|localhost|ALTER|G -|root||root|localhost|ALTER ROUTINE|G -|root||root|localhost|CREATE|G -|root||root|localhost|CREATE ROUTINE|G -|root||root|localhost|CREATE TABLESPACE|G -|root||root|localhost|CREATE TEMPORARY TABLES|G -|root||root|localhost|CREATE USER|G -|root||root|localhost|CREATE VIEW|G -|root||root|localhost|DELETE|G -|root||root|localhost|DROP|G -|root||root|localhost|EVENT|G -|root||root|localhost|EXECUTE|G -|root||root|localhost|FILE|G -|root||root|localhost|INDEX|G -|root||root|localhost|INSERT|G -|root||root|localhost|LOCK TABLES|G -|root||root|localhost|PROCESS|G -|root||root|localhost|REFERENCES|G -|root||root|localhost|RELOAD|G -|root||root|localhost|REPLICATION CLIENT|G -|root||root|localhost|REPLICATION SLAVE|G -|root||root|localhost|SELECT|G -|root||root|localhost|SHOW DATABASES|G -|root||root|localhost|SHOW VIEW|G -|root||root|localhost|SHUTDOWN|G -|root||mysql.session|localhost|SUPER|G -|root||root|localhost|SUPER|G -|root||root|localhost|TRIGGER|G -|root||root|localhost|UPDATE|G -|root||root|localhost|grant option|G -performance_schema|schema||mysql.session|localhost|SELECT|G -sys|schema||mysql.sys|localhost|TRIGGER|G - 5.7.44 - + big5 1 diff --git a/Supermarket/.idea/vcs.xml b/Supermarket/.idea/vcs.xml new file mode 100644 index 0000000..6c0b863 --- /dev/null +++ b/Supermarket/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Supermarket/bin/.idea/dataSources/5b23e521-053a-47c0-ae28-a98b513bc6ec.xml b/Supermarket/bin/.idea/dataSources/5b23e521-053a-47c0-ae28-a98b513bc6ec.xml index 905f93f..6ba1d51 100644 --- a/Supermarket/bin/.idea/dataSources/5b23e521-053a-47c0-ae28-a98b513bc6ec.xml +++ b/Supermarket/bin/.idea/dataSources/5b23e521-053a-47c0-ae28-a98b513bc6ec.xml @@ -1,44 +1,7 @@ - - lower/lower - InnoDB - InnoDB - |root||root|localhost|ALTER|G -|root||root|localhost|ALTER ROUTINE|G -|root||root|localhost|CREATE|G -|root||root|localhost|CREATE ROUTINE|G -|root||root|localhost|CREATE TABLESPACE|G -|root||root|localhost|CREATE TEMPORARY TABLES|G -|root||root|localhost|CREATE USER|G -|root||root|localhost|CREATE VIEW|G -|root||root|localhost|DELETE|G -|root||root|localhost|DROP|G -|root||root|localhost|EVENT|G -|root||root|localhost|EXECUTE|G -|root||root|localhost|FILE|G -|root||root|localhost|INDEX|G -|root||root|localhost|INSERT|G -|root||root|localhost|LOCK TABLES|G -|root||root|localhost|PROCESS|G -|root||root|localhost|REFERENCES|G -|root||root|localhost|RELOAD|G -|root||root|localhost|REPLICATION CLIENT|G -|root||root|localhost|REPLICATION SLAVE|G -|root||root|localhost|SELECT|G -|root||root|localhost|SHOW DATABASES|G -|root||root|localhost|SHOW VIEW|G -|root||root|localhost|SHUTDOWN|G -|root||mysql.session|localhost|SUPER|G -|root||root|localhost|SUPER|G -|root||root|localhost|TRIGGER|G -|root||root|localhost|UPDATE|G -|root||root|localhost|grant option|G -performance_schema|schema||mysql.session|localhost|SELECT|G -sys|schema||mysql.sys|localhost|TRIGGER|G - 5.7.44 - + big5 1 diff --git a/Supermarket/bin/.idea/vcs.xml b/Supermarket/bin/.idea/vcs.xml new file mode 100644 index 0000000..6c0b863 --- /dev/null +++ b/Supermarket/bin/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Supermarket/bin/com/lingnan/supermarket/componet/BGPanel.class b/Supermarket/bin/com/lingnan/supermarket/componet/BGPanel.class index 48fb917..a42e4a1 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/BufferImpl.class b/Supermarket/bin/com/lingnan/supermarket/dao/impl/BufferImpl.class index 9f357e5..0fd2a16 100644 Binary files a/Supermarket/bin/com/lingnan/supermarket/dao/impl/BufferImpl.class and b/Supermarket/bin/com/lingnan/supermarket/dao/impl/BufferImpl.class differ diff --git a/Supermarket/bin/com/lingnan/supermarket/dao/impl/SupplierInfImpl.class b/Supermarket/bin/com/lingnan/supermarket/dao/impl/SupplierInfImpl.class index eb58e55..edc9cfc 100644 Binary files a/Supermarket/bin/com/lingnan/supermarket/dao/impl/SupplierInfImpl.class and b/Supermarket/bin/com/lingnan/supermarket/dao/impl/SupplierInfImpl.class differ diff --git a/Supermarket/bin/com/lingnan/supermarket/dao/impl/UserServiceImpl.class b/Supermarket/bin/com/lingnan/supermarket/dao/impl/UserServiceImpl.class index 600997b..90181f1 100644 Binary files a/Supermarket/bin/com/lingnan/supermarket/dao/impl/UserServiceImpl.class and b/Supermarket/bin/com/lingnan/supermarket/dao/impl/UserServiceImpl.class differ diff --git a/Supermarket/bin/com/lingnan/supermarket/dao/impl/inOrderServiceImpl.class b/Supermarket/bin/com/lingnan/supermarket/dao/impl/inOrderServiceImpl.class index 6eb7a4a..faf169f 100644 Binary files a/Supermarket/bin/com/lingnan/supermarket/dao/impl/inOrderServiceImpl.class and b/Supermarket/bin/com/lingnan/supermarket/dao/impl/inOrderServiceImpl.class differ diff --git a/Supermarket/bin/com/lingnan/supermarket/dao/impl/inRecordServiceImpl.class b/Supermarket/bin/com/lingnan/supermarket/dao/impl/inRecordServiceImpl.class index 92a062b..c7bf777 100644 Binary files a/Supermarket/bin/com/lingnan/supermarket/dao/impl/inRecordServiceImpl.class and b/Supermarket/bin/com/lingnan/supermarket/dao/impl/inRecordServiceImpl.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 fdb1611..dfab04b 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/productionImpl.class b/Supermarket/bin/com/lingnan/supermarket/dao/impl/productionImpl.class index ff1bba4..90154e9 100644 Binary files a/Supermarket/bin/com/lingnan/supermarket/dao/impl/productionImpl.class and b/Supermarket/bin/com/lingnan/supermarket/dao/impl/productionImpl.class differ diff --git a/Supermarket/bin/com/lingnan/supermarket/dialog/ChangeStatusDialog$MyItemListener.class b/Supermarket/bin/com/lingnan/supermarket/dialog/ChangeStatusDialog$MyItemListener.class index f97e071..1a2b49c 100644 Binary files a/Supermarket/bin/com/lingnan/supermarket/dialog/ChangeStatusDialog$MyItemListener.class and b/Supermarket/bin/com/lingnan/supermarket/dialog/ChangeStatusDialog$MyItemListener.class differ diff --git a/Supermarket/bin/com/lingnan/supermarket/dialog/ChangeStatusDialog.class b/Supermarket/bin/com/lingnan/supermarket/dialog/ChangeStatusDialog.class index 1852673..84beb05 100644 Binary files a/Supermarket/bin/com/lingnan/supermarket/dialog/ChangeStatusDialog.class and b/Supermarket/bin/com/lingnan/supermarket/dialog/ChangeStatusDialog.class differ diff --git a/Supermarket/bin/com/lingnan/supermarket/dialog/ChangeSumDialog.class b/Supermarket/bin/com/lingnan/supermarket/dialog/ChangeSumDialog.class index c835e1e..edc1b10 100644 Binary files a/Supermarket/bin/com/lingnan/supermarket/dialog/ChangeSumDialog.class and b/Supermarket/bin/com/lingnan/supermarket/dialog/ChangeSumDialog.class differ diff --git a/Supermarket/bin/com/lingnan/supermarket/dialog/CloseDialog.class b/Supermarket/bin/com/lingnan/supermarket/dialog/CloseDialog.class index f75dc33..ab82379 100644 Binary files a/Supermarket/bin/com/lingnan/supermarket/dialog/CloseDialog.class and b/Supermarket/bin/com/lingnan/supermarket/dialog/CloseDialog.class differ diff --git a/Supermarket/bin/com/lingnan/supermarket/dialog/InDialog.class b/Supermarket/bin/com/lingnan/supermarket/dialog/InDialog.class index 47fd4db..fb0be84 100644 Binary files a/Supermarket/bin/com/lingnan/supermarket/dialog/InDialog.class and b/Supermarket/bin/com/lingnan/supermarket/dialog/InDialog.class differ diff --git a/Supermarket/bin/com/lingnan/supermarket/dialog/OutDialog.class b/Supermarket/bin/com/lingnan/supermarket/dialog/OutDialog.class index 519f6ff..48e52f6 100644 Binary files a/Supermarket/bin/com/lingnan/supermarket/dialog/OutDialog.class and b/Supermarket/bin/com/lingnan/supermarket/dialog/OutDialog.class differ diff --git a/Supermarket/bin/com/lingnan/supermarket/dialog/ProductionDialog.class b/Supermarket/bin/com/lingnan/supermarket/dialog/ProductionDialog.class index ea8ac5e..eb9ddd9 100644 Binary files a/Supermarket/bin/com/lingnan/supermarket/dialog/ProductionDialog.class and b/Supermarket/bin/com/lingnan/supermarket/dialog/ProductionDialog.class differ diff --git a/Supermarket/bin/com/lingnan/supermarket/dialog/SupplierInfDialog.class b/Supermarket/bin/com/lingnan/supermarket/dialog/SupplierInfDialog.class index bb919d1..d2ff2fe 100644 Binary files a/Supermarket/bin/com/lingnan/supermarket/dialog/SupplierInfDialog.class and b/Supermarket/bin/com/lingnan/supermarket/dialog/SupplierInfDialog.class differ diff --git a/Supermarket/bin/com/lingnan/supermarket/dialog/UserDialog$MyItemListener.class b/Supermarket/bin/com/lingnan/supermarket/dialog/UserDialog$MyItemListener.class index 545b75e..17d8f88 100644 Binary files a/Supermarket/bin/com/lingnan/supermarket/dialog/UserDialog$MyItemListener.class and b/Supermarket/bin/com/lingnan/supermarket/dialog/UserDialog$MyItemListener.class differ diff --git a/Supermarket/bin/com/lingnan/supermarket/dialog/UserDialog.class b/Supermarket/bin/com/lingnan/supermarket/dialog/UserDialog.class index cee959a..1c4ec24 100644 Binary files a/Supermarket/bin/com/lingnan/supermarket/dialog/UserDialog.class and b/Supermarket/bin/com/lingnan/supermarket/dialog/UserDialog.class differ diff --git a/Supermarket/bin/com/lingnan/supermarket/dialog/UserInfDialog$MyItemListener.class b/Supermarket/bin/com/lingnan/supermarket/dialog/UserInfDialog$MyItemListener.class index f3a2c27..47acaf6 100644 Binary files a/Supermarket/bin/com/lingnan/supermarket/dialog/UserInfDialog$MyItemListener.class and b/Supermarket/bin/com/lingnan/supermarket/dialog/UserInfDialog$MyItemListener.class differ diff --git a/Supermarket/bin/com/lingnan/supermarket/dialog/UserInfDialog.class b/Supermarket/bin/com/lingnan/supermarket/dialog/UserInfDialog.class index b3b2d9f..f8fd576 100644 Binary files a/Supermarket/bin/com/lingnan/supermarket/dialog/UserInfDialog.class and b/Supermarket/bin/com/lingnan/supermarket/dialog/UserInfDialog.class differ diff --git a/Supermarket/bin/com/lingnan/supermarket/dto/User.class b/Supermarket/bin/com/lingnan/supermarket/dto/User.class index 472ba94..c18a70e 100644 Binary files a/Supermarket/bin/com/lingnan/supermarket/dto/User.class and b/Supermarket/bin/com/lingnan/supermarket/dto/User.class differ diff --git a/Supermarket/bin/com/lingnan/supermarket/table/InOrderTM.class b/Supermarket/bin/com/lingnan/supermarket/table/InOrderTM.class index 4e0822f..c9bf084 100644 Binary files a/Supermarket/bin/com/lingnan/supermarket/table/InOrderTM.class and b/Supermarket/bin/com/lingnan/supermarket/table/InOrderTM.class differ diff --git a/Supermarket/bin/com/lingnan/supermarket/table/InRecordTM.class b/Supermarket/bin/com/lingnan/supermarket/table/InRecordTM.class index c95657a..e5bda6a 100644 Binary files a/Supermarket/bin/com/lingnan/supermarket/table/InRecordTM.class and b/Supermarket/bin/com/lingnan/supermarket/table/InRecordTM.class differ diff --git a/Supermarket/bin/com/lingnan/supermarket/table/InTableModel.class b/Supermarket/bin/com/lingnan/supermarket/table/InTableModel.class index 1d34276..d4ef217 100644 Binary files a/Supermarket/bin/com/lingnan/supermarket/table/InTableModel.class and b/Supermarket/bin/com/lingnan/supermarket/table/InTableModel.class differ diff --git a/Supermarket/bin/com/lingnan/supermarket/table/OutOrderTM.class b/Supermarket/bin/com/lingnan/supermarket/table/OutOrderTM.class index 807961f..cb4ca6e 100644 Binary files a/Supermarket/bin/com/lingnan/supermarket/table/OutOrderTM.class and b/Supermarket/bin/com/lingnan/supermarket/table/OutOrderTM.class differ diff --git a/Supermarket/bin/com/lingnan/supermarket/table/OutRecordTM.class b/Supermarket/bin/com/lingnan/supermarket/table/OutRecordTM.class index e674d5f..8c8a214 100644 Binary files a/Supermarket/bin/com/lingnan/supermarket/table/OutRecordTM.class and b/Supermarket/bin/com/lingnan/supermarket/table/OutRecordTM.class differ diff --git a/Supermarket/bin/com/lingnan/supermarket/table/OutTableModel.class b/Supermarket/bin/com/lingnan/supermarket/table/OutTableModel.class index 6190e1b..369e79a 100644 Binary files a/Supermarket/bin/com/lingnan/supermarket/table/OutTableModel.class and b/Supermarket/bin/com/lingnan/supermarket/table/OutTableModel.class differ diff --git a/Supermarket/bin/com/lingnan/supermarket/table/ProdCatalogTM.class b/Supermarket/bin/com/lingnan/supermarket/table/ProdCatalogTM.class index becc853..033463d 100644 Binary files a/Supermarket/bin/com/lingnan/supermarket/table/ProdCatalogTM.class and b/Supermarket/bin/com/lingnan/supermarket/table/ProdCatalogTM.class differ diff --git a/Supermarket/bin/com/lingnan/supermarket/table/StorageRecordTM.class b/Supermarket/bin/com/lingnan/supermarket/table/StorageRecordTM.class index 0a91b4d..e59a645 100644 Binary files a/Supermarket/bin/com/lingnan/supermarket/table/StorageRecordTM.class and b/Supermarket/bin/com/lingnan/supermarket/table/StorageRecordTM.class differ diff --git a/Supermarket/bin/com/lingnan/supermarket/table/StorageTableModel.class b/Supermarket/bin/com/lingnan/supermarket/table/StorageTableModel.class index 74d0fce..e0b4d57 100644 Binary files a/Supermarket/bin/com/lingnan/supermarket/table/StorageTableModel.class and b/Supermarket/bin/com/lingnan/supermarket/table/StorageTableModel.class differ diff --git a/Supermarket/bin/com/lingnan/supermarket/table/SupplierTableModel.class b/Supermarket/bin/com/lingnan/supermarket/table/SupplierTableModel.class index bf99e47..dddd3b2 100644 Binary files a/Supermarket/bin/com/lingnan/supermarket/table/SupplierTableModel.class and b/Supermarket/bin/com/lingnan/supermarket/table/SupplierTableModel.class differ diff --git a/Supermarket/bin/com/lingnan/supermarket/table/UserTableModel.class b/Supermarket/bin/com/lingnan/supermarket/table/UserTableModel.class index 9de7223..ac589ef 100644 Binary files a/Supermarket/bin/com/lingnan/supermarket/table/UserTableModel.class and b/Supermarket/bin/com/lingnan/supermarket/table/UserTableModel.class differ diff --git a/Supermarket/bin/com/lingnan/supermarket/utils/CreateOrder.class b/Supermarket/bin/com/lingnan/supermarket/utils/CreateOrder.class index ce8f346..1c9a168 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/FontUtil.class b/Supermarket/bin/com/lingnan/supermarket/utils/FontUtil.class index 314feda..8c89bca 100644 Binary files a/Supermarket/bin/com/lingnan/supermarket/utils/FontUtil.class and b/Supermarket/bin/com/lingnan/supermarket/utils/FontUtil.class differ diff --git a/Supermarket/bin/com/lingnan/supermarket/utils/tplbTest.class b/Supermarket/bin/com/lingnan/supermarket/utils/tplbTest.class index 85f0006..8eb35e4 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/Demo4.class b/Supermarket/bin/com/lingnan/supermarket/view/Demo4.class index cf447ff..b24e113 100644 Binary files a/Supermarket/bin/com/lingnan/supermarket/view/Demo4.class and b/Supermarket/bin/com/lingnan/supermarket/view/Demo4.class differ diff --git a/Supermarket/bin/com/lingnan/supermarket/view/HomeView.class b/Supermarket/bin/com/lingnan/supermarket/view/HomeView.class index 48591f1..4bdddef 100644 Binary files a/Supermarket/bin/com/lingnan/supermarket/view/HomeView.class and b/Supermarket/bin/com/lingnan/supermarket/view/HomeView.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 d229f62..998ea75 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 b79f969..c6d8d22 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/LoginView.class b/Supermarket/bin/com/lingnan/supermarket/view/LoginView.class index 0363364..0265a99 100644 Binary files a/Supermarket/bin/com/lingnan/supermarket/view/LoginView.class and b/Supermarket/bin/com/lingnan/supermarket/view/LoginView.class differ diff --git a/Supermarket/bin/com/lingnan/supermarket/view/MainView.class b/Supermarket/bin/com/lingnan/supermarket/view/MainView.class index 9184f41..c9026fb 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/OutView.class b/Supermarket/bin/com/lingnan/supermarket/view/OutView.class index 6e07973..c4c0a8f 100644 Binary files a/Supermarket/bin/com/lingnan/supermarket/view/OutView.class and b/Supermarket/bin/com/lingnan/supermarket/view/OutView.class differ diff --git a/Supermarket/bin/com/lingnan/supermarket/view/ProdCatalogView.class b/Supermarket/bin/com/lingnan/supermarket/view/ProdCatalogView.class index ad04087..006a906 100644 Binary files a/Supermarket/bin/com/lingnan/supermarket/view/ProdCatalogView.class and b/Supermarket/bin/com/lingnan/supermarket/view/ProdCatalogView.class differ diff --git a/Supermarket/bin/com/lingnan/supermarket/view/StorageView.class b/Supermarket/bin/com/lingnan/supermarket/view/StorageView.class index 33c5f3e..fdfbfcc 100644 Binary files a/Supermarket/bin/com/lingnan/supermarket/view/StorageView.class and b/Supermarket/bin/com/lingnan/supermarket/view/StorageView.class differ diff --git a/Supermarket/bin/com/lingnan/supermarket/view/SupplierView.class b/Supermarket/bin/com/lingnan/supermarket/view/SupplierView.class index 5e35ec5..2f20ef0 100644 Binary files a/Supermarket/bin/com/lingnan/supermarket/view/SupplierView.class and b/Supermarket/bin/com/lingnan/supermarket/view/SupplierView.class differ diff --git a/Supermarket/bin/com/lingnan/supermarket/view/UserView.class b/Supermarket/bin/com/lingnan/supermarket/view/UserView.class index 2de250a..7aac3e5 100644 Binary files a/Supermarket/bin/com/lingnan/supermarket/view/UserView.class and b/Supermarket/bin/com/lingnan/supermarket/view/UserView.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 58f926a..0f912c1 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 4b9bc0f..a953dc7 100644 --- a/Supermarket/src/com/lingnan/supermarket/componet/BGPanel.java +++ b/Supermarket/src/com/lingnan/supermarket/componet/BGPanel.java @@ -1,36 +1,46 @@ package com.lingnan.supermarket.componet; - import java.awt.Graphics; import java.awt.Image; import java.awt.Toolkit; - import javax.swing.JPanel; 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中 int height = Toolkit.getDefaultToolkit().getScreenSize().height; + // 通过默认工具包(Toolkit)获取屏幕的高度,存储在局部变量height中 this.setSize(width, height); + // 设置该面板(BGPanel)的大小为整个屏幕的大小,即宽度和高度分别为获取到的屏幕宽高 } - - public BGPanel(Image image,int width,int height) { + + public BGPanel(Image image, int width, int height) { + // 定义另一个构造方法,接收一个Image类型的参数image以及表示宽度和高度的两个int类型参数,用于更灵活地创建BGPanel对象并指定其大小 this.image = image; - - + // 将传入的参数image赋值给类的成员变量image + this.setSize(width, height); + // 设置该面板(BGPanel)的大小为传入的指定宽度width和指定高度height } - - + + @Override protected void paintComponent(Graphics g) { + // 重写JPanel类中的paintComponent方法,用于绘制面板上的图像 super.paintComponent(g); - g.drawImage(image,0,0,getWidth(),getHeight(),this); - - } + // 调用父类(JPanel)的paintComponent方法,以确保完成一些默认的绘制操作,比如背景清除等 -} + g.drawImage(image, 0, 0, getWidth(), getHeight(), this); + // 使用传入的Graphics对象g在面板上绘制图像,参数含义如下: + // image:要绘制的图像对象,就是之前保存的成员变量image + // 0, 0:表示在面板上绘制图像的起始坐标(x坐标和y坐标),这里从面板的左上角(0, 0)位置开始绘制 + // getWidth(), getHeight():获取当前面板的宽度和高度,用于指定绘制图像时按照面板的实际大小进行拉伸或缩放,确保图像填满整个面板 + // this:表示图像观察者,用于接收图像绘制过程中的相关通知等 + } +} \ No newline at end of file diff --git a/Supermarket/src/com/lingnan/supermarket/dao/impl/BufferImpl.java b/Supermarket/src/com/lingnan/supermarket/dao/impl/BufferImpl.java index 35da321..6133106 100644 --- a/Supermarket/src/com/lingnan/supermarket/dao/impl/BufferImpl.java +++ b/Supermarket/src/com/lingnan/supermarket/dao/impl/BufferImpl.java @@ -1,122 +1,122 @@ package com.lingnan.supermarket.dao.impl; +import com.lingnan.supermarket.dao.BufferService; +import com.lingnan.supermarket.dto.Buffer; +import com.lingnan.supermarket.dto.Production; +import com.lingnan.supermarket.utils.JDBCUtil; + import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.util.Vector; -import com.lingnan.supermarket.dao.BufferService; -import com.lingnan.supermarket.dto.Buffer; -import com.lingnan.supermarket.dto.Production; -import com.lingnan.supermarket.utils.JDBCUtil; - +// 实现BufferService接口的缓冲区操作类 public class BufferImpl implements BufferService { - - - - /*------------------------收银出货模块-----------------------*/ /*返回出货缓冲表所有delmark=1的记录并排序*/ + // 获取所有出货缓冲区的记录 public Vector allOutBuffer(){ - Connection conn = JDBCUtil.getConn(); - PreparedStatement pstmt = null; - ResultSet resultSet=null; - Vector v = new Vector(); - Buffer Buffer; + Connection conn = JDBCUtil.getConn(); // 获取数据库连接 + PreparedStatement pstmt = null; // 初始化预编译语句对象 + ResultSet resultSet=null; // 初始化结果集对象 + Vector v = new Vector(); // 创建一个向量用于存储Buffer对象 + Buffer Buffer; // 声明一个Buffer对象 try { - pstmt = conn.prepareStatement("select * from OutBuffer "); - resultSet = pstmt.executeQuery(); - while(resultSet.next()) { - Buffer = new Buffer(); - Buffer.setId(resultSet.getString("id")); - Buffer.setName(resultSet.getString("name")); - Buffer.setInPrice(resultSet.getFloat("inPrice")); - Buffer.setOutPrice(resultSet.getFloat("OutPrice")); - Buffer.setLife(resultSet.getInt("life")); - Buffer.setSum(resultSet.getInt("sum")); - Buffer.setSupplyId(resultSet.getInt("supplyId")); - Buffer.setId2(resultSet.getString("id2")); - Buffer.setName2(resultSet.getString("name2")); - Buffer.setPrice(resultSet.getFloat("price")); - Buffer.setDelmark(resultSet.getInt("delmark")); - v.add(Buffer); + pstmt = conn.prepareStatement("select * from OutBuffer "); // 准备SQL查询语句 + resultSet = pstmt.executeQuery(); // 执行查询 + while(resultSet.next()) { // 遍历结果集 + Buffer = new Buffer(); // 创建一个新的Buffer对象 + Buffer.setId(resultSet.getString("id")); // 设置商品ID + Buffer.setName(resultSet.getString("name")); // 设置商品名称 + Buffer.setInPrice(resultSet.getFloat("inPrice")); // 设置进货价格 + Buffer.setOutPrice(resultSet.getFloat("OutPrice")); // 设置出货价格 + Buffer.setLife(resultSet.getInt("life")); // 设置商品保质期 + Buffer.setSum(resultSet.getInt("sum")); // 设置商品数量 + Buffer.setSupplyId(resultSet.getInt("supplyId")); // 设置供应商ID + Buffer.setId2(resultSet.getString("id2")); // 设置商品类别ID + Buffer.setName2(resultSet.getString("name2")); // 设置商品类别名称 + Buffer.setPrice(resultSet.getFloat("price")); // 设置商品总价 + Buffer.setDelmark(resultSet.getInt("delmark")); // 设置删除标记 + v.add(Buffer); // 将Buffer对象添加到向量中 } - - } catch (SQLException e) { - e.printStackTrace(); - }finally { - JDBCUtil.close(resultSet, pstmt, conn); + + } catch (SQLException e) { // 捕获SQL异常 + e.printStackTrace(); // 打印异常堆栈信息 + }finally { // 无论是否发生异常,都会执行的代码块 + JDBCUtil.close(resultSet, pstmt, conn); // 关闭结果集、预编译语句和数据库连接 } - return v; + return v; // 返回存储所有Buffer对象的向量 } /*通过id查找返回boolean*/ - public Buffer findOutBufferbyId(String id) + // 根据ID查找出货缓冲区的记录 + public Buffer findOutBufferbyId(String id) { - boolean flag = false; - Connection conn = JDBCUtil.getConn(); - PreparedStatement pstmt = null; - ResultSet resultSet=null; - Buffer buffer = new Buffer(); - try { - pstmt = conn.prepareStatement("select * from OutBuffer where id=? "); - pstmt.setString(1, id); - resultSet = pstmt.executeQuery(); - - if(resultSet.next()) { - buffer.setId(resultSet.getString("id")); - buffer.setName(resultSet.getString("name")); - buffer.setInPrice(resultSet.getFloat("inPrice")); - buffer.setOutPrice(resultSet.getFloat("OutPrice")); - buffer.setLife(resultSet.getInt("life")); - buffer.setSum(resultSet.getInt("sum")); - buffer.setSupplyId(resultSet.getInt("supplyId")); - buffer.setId2(resultSet.getString("id2")); - buffer.setName2(resultSet.getString("name2")); - buffer.setPrice(resultSet.getFloat("price")); - buffer.setDelmark(resultSet.getInt("delmark")); - flag = true; - }else { - return null; + boolean flag = false; // 初始化标志为false + Connection conn = JDBCUtil.getConn(); // 获取数据库连接 + PreparedStatement pstmt = null; // 初始化预编译语句对象 + ResultSet resultSet=null; // 初始化结果集对象 + Buffer buffer = new Buffer(); // 创建一个新的Buffer对象 + try { + pstmt = conn.prepareStatement("select * from OutBuffer where id=? "); // 准备SQL查询语句 + pstmt.setString(1, id); // 设置查询参数 + resultSet = pstmt.executeQuery(); // 执行查询 + + if(resultSet.next()) { // 如果找到对应记录 + buffer.setId(resultSet.getString("id")); // 设置商品ID + buffer.setName(resultSet.getString("name")); // 设置商品名称 + buffer.setInPrice(resultSet.getFloat("inPrice")); // 设置进货价格 + buffer.setOutPrice(resultSet.getFloat("OutPrice")); // 设置出货价格 + buffer.setLife(resultSet.getInt("life")); // 设置商品保质期 + buffer.setSum(resultSet.getInt("sum")); // 设置商品数量 + buffer.setSupplyId(resultSet.getInt("supplyId")); // 设置供应商ID + buffer.setId2(resultSet.getString("id2")); // 设置商品类别ID + buffer.setName2(resultSet.getString("name2")); // 设置商品类别名称 + buffer.setPrice(resultSet.getFloat("price")); // 设置商品总价 + buffer.setDelmark(resultSet.getInt("delmark")); // 设置删除标记 + flag = true; // 设置标志为true + }else { + return null; // 没有找到该商品,返回null + } + + } catch (SQLException e) { // 捕获SQL异常 + e.printStackTrace(); // 打印异常堆栈信息 + }finally { // 无论是否发生异常,都会执行的代码块 + JDBCUtil.close(resultSet, pstmt, conn); // 关闭结果集、预编译语句和数据库连接 } - - } catch (SQLException e) { - e.printStackTrace(); - }finally { - JDBCUtil.close(resultSet, pstmt, conn); + return buffer; // 返回找到的Buffer对象 } - return buffer; -} /*如果缓冲区没有那就把整条记录插入插入操作*/ + // 向出货缓冲区添加新商品记录 public boolean addOutBufferNewProd(String id,int sum) { - boolean flag = false; - Connection conn = JDBCUtil.getConn(); - PreparedStatement pstmt = null; - ResultSet resultSet=null; + boolean flag = false; // 初始化标志为false + Connection conn = JDBCUtil.getConn(); // 获取数据库连接 + PreparedStatement pstmt = null; // 初始化预编译语句对象 + ResultSet resultSet=null; // 初始化结果集对象 try { - pstmt = conn.prepareStatement("call InsertOutBuffer(?,?) "); - pstmt.setString(1, id); - pstmt.setInt(2, sum); - - - if( pstmt.executeUpdate()==1) { - flag = true; + pstmt = conn.prepareStatement("call InsertOutBuffer(?,?) "); // 准备存储过程调用语句 + pstmt.setString(1, id); // 设置商品ID参数 + pstmt.setInt(2, sum); // 设置商品数量参数 + + + if( pstmt.executeUpdate()==1) { // 执行更新操作 + flag = true; // 如果成功执行插入,设置标志为true } - - } catch (SQLException e) { - e.printStackTrace(); - }finally { - JDBCUtil.close(resultSet, pstmt, conn); + + } catch (SQLException e) { // 捕获SQL异常 + e.printStackTrace(); // 打印异常堆栈信息 + }finally { // 无论是否发生异常,都会执行的代码块 + JDBCUtil.close(resultSet, pstmt, conn); // 关闭结果集、预编译语句和数据库连接 } - return flag; + return flag; // 返回插入结果标志 } - - + + /*根据商品id获取sum和outprice public Buffer findOutBufferSumAndOutPrice(String id) { Buffer Buffer = new Buffer(); @@ -127,13 +127,13 @@ public class BufferImpl implements BufferService { pstmt = conn.prepareStatement("select * from OutBuffer where id=? "); pstmt.setString(1, id); resultSet = pstmt.executeQuery(); - + if(resultSet.next()) { Buffer.setSum(resultSet.getInt("sum")); Buffer.setOutPrice(resultSet.getFloat("OutPrice")); } - + } catch (SQLException e) { e.printStackTrace(); }finally { @@ -143,320 +143,351 @@ public class BufferImpl implements BufferService { } */ - + /*如果delmark是1,即是已经添加的商品*/ + // 更新已存在商品的出货缓冲区记录 public boolean addOutBufferExeistProd(String id,int sum,Buffer buffer){ - boolean flag = false; - Connection conn = JDBCUtil.getConn(); - PreparedStatement pstmt = null; - ResultSet resultSet = null;; + boolean flag = false; // 初始化标志为false + Connection conn = JDBCUtil.getConn(); // 获取数据库连接 + PreparedStatement pstmt = null; // 初始化预编译语句对象 + ResultSet resultSet = null;; // 初始化结果集对象 try { - pstmt = conn.prepareStatement("update OutBuffer set sum=?,price=? where id=? "); - pstmt.setInt(1, sum+buffer.getSum()); - pstmt.setFloat(2,( sum+buffer.getSum()*buffer.getOutPrice())); - pstmt.setString(3, id); - if(pstmt.executeUpdate()==1) { - flag = true; + pstmt = conn.prepareStatement("update OutBuffer set sum=?,price=? where id=? "); // 准备SQL更新语句 + pstmt.setInt(1, sum+buffer.getSum()); // 设置更新后的商品数量 + pstmt.setFloat(2,( sum+buffer.getSum()*buffer.getOutPrice())); // 设置更新后的商品总价 + pstmt.setString(3, id); // 设置商品ID + if(pstmt.executeUpdate()==1) { // 执行更新操作 + flag = true; // 如果成功执行更新,设置标志为true } - - } catch (SQLException e) { - e.printStackTrace(); - }finally { - JDBCUtil.close(resultSet, pstmt, conn); + } catch (SQLException e) { // 捕获SQL异常 + e.printStackTrace(); // 打印异常堆栈信息 + }finally { // 无论是否发生异常,都会执行的代码块 + + JDBCUtil.close(resultSet, pstmt, conn); // 关闭结果集、预编译语句和数据库连接 } - return flag; + return flag; // 返回更新结果标志 } /*获得购物车总价*/ + // 计算出货缓冲区所有商品的总价 public Float OutBufferAllPrice(){ - boolean flag = false; - Connection conn = JDBCUtil.getConn(); - PreparedStatement pstmt = null; - ResultSet resultSet = null;; + boolean flag = false; // 初始化标志为false + Connection conn = JDBCUtil.getConn(); // 获取数据库连接 + PreparedStatement pstmt = null; // 初始化预编译语句对象 + ResultSet resultSet = null;; // 初始化结果集对象 try { - pstmt = conn.prepareStatement("select sum(price) from OutBuffer "); - resultSet=pstmt.executeQuery(); - if(resultSet.next()) { - return resultSet.getFloat("sum(price)"); + pstmt = conn.prepareStatement("select sum(price) from OutBuffer "); // 准备SQL查询语句 + resultSet=pstmt.executeQuery(); // 执行查询 + if(resultSet.next()) { // 如果有结果 + return resultSet.getFloat("sum(price)"); // 返回总价 } - - } catch (SQLException e) { - e.printStackTrace(); - }finally { - JDBCUtil.close(resultSet, pstmt, conn); + } catch (SQLException e) { // 捕获SQL异常 + e.printStackTrace(); // 打印异常堆栈信息 + }finally { // 无论是否发生异常,都会执行的代码块 + + JDBCUtil.close(resultSet, pstmt, conn); // 关闭结果集、预编译语句和数据库连接 } - return null; + return null; // 如果没有结果,返回null } - - + + /*结账后对5个表进行操作*/ + // 进行结账操作并更新数据库 public boolean Account(String number,String time,String id,int sum,Float price){ - boolean flag = false; - Connection conn = JDBCUtil.getConn(); - PreparedStatement pstmt = null; - ResultSet resultSet = null;; + boolean flag = false; // 初始化标志为false + Connection conn = JDBCUtil.getConn(); // 获取数据库连接 + PreparedStatement pstmt = null; // 初始化预编译语句对象 + ResultSet resultSet = null;; // 初始化结果集对象 try { - pstmt = conn.prepareStatement("call Account(?,?,?,?,?)"); - pstmt.setString(1,number); - pstmt.setString(2,time ); - pstmt.setString(3,id ); - pstmt.setInt(4,sum ); - pstmt.setFloat(5, price); - if(pstmt.execute()) - flag = true; + pstmt = conn.prepareStatement("call Account(?,?,?,?,?)"); // 准备存储过程调用语句 + pstmt.setString(1,number); // 设置订单号 + pstmt.setString(2,time ); // 设置时间 + pstmt.setString(3,id ); // 设置商品ID + pstmt.setInt(4,sum ); // 设置商品数量 + pstmt.setFloat(5, price); // 设置商品总价 + if(pstmt.execute()) // 执行更新操作 + flag = true; // 如果成功执行更新,设置标志为true - - } catch (SQLException e) { - e.printStackTrace(); - }finally { - JDBCUtil.close(resultSet, pstmt, conn); + + } catch (SQLException e) { // 捕获SQL异常 + e.printStackTrace(); // 打印异常堆栈信息 + }finally { // 无论是否发生异常,都会执行的代码块 + + JDBCUtil.close(resultSet, pstmt, conn); // 关闭结果集、预编译语句和数据库连接 } - return flag; + return flag; // 返回更新结果标志 } - + /*删除所有购物车*/ + // 清空出货缓冲区 public boolean DelAllOutBuffer(){ - boolean flag = false; - Connection conn = JDBCUtil.getConn(); - PreparedStatement pstmt = null; - ResultSet resultSet = null;; + boolean flag = false; // 初始化标志为false + Connection conn = JDBCUtil.getConn(); // 获取数据库连接 + PreparedStatement pstmt = null; // 初始化预编译语句对象 + ResultSet resultSet = null;; // 初始化结果集对象 try { - pstmt = conn.prepareStatement("delete from OutBuffer"); - if(pstmt.execute()) - flag = true; + pstmt = conn.prepareStatement("delete from OutBuffer"); // 准备SQL删除语句 + if(pstmt.execute()) // 执行删除操作 + flag = true; // 如果成功执行删除,设置标志为true - - } catch (SQLException e) { - e.printStackTrace(); - }finally { + flag = true; // 如果成功执行删除,设置标志为true - JDBCUtil.close(resultSet, pstmt, conn); + + } catch (SQLException e) { // 捕获SQL异常 + e.printStackTrace(); // 打印异常堆栈信息 + }finally { // 无论是否发生异常,都会执行的代码块 + + JDBCUtil.close(resultSet, pstmt, conn); // 关闭结果集、预编译语句和数据库连接 } - return flag; + return flag; // 返回删除结果标志 } /*往订单表插入一条记录*/ + // 向订单表插入一条新记录 public boolean InsertOutOrder(String number,Float allPrice,String time,String username){ - boolean flag = false; - Connection conn = JDBCUtil.getConn(); - PreparedStatement pstmt = null; - ResultSet resultSet = null;; + boolean flag = false; // 初始化标志为false + Connection conn = JDBCUtil.getConn(); // 获取数据库连接 + PreparedStatement pstmt = null; // 初始化预编译语句对象 + ResultSet resultSet = null;; // 初始化结果集对象 try { - pstmt = conn.prepareStatement("insert into OutOrder values(?,?,?,?,?)"); - pstmt.setString(1, number); - pstmt.setFloat(2, allPrice); - pstmt.setString(3, time); - pstmt.setString(4, username); - pstmt.setInt(5, 1); - if(pstmt.execute()) - flag = true; + pstmt = conn.prepareStatement("insert into OutOrder values(?,?,?,?,?)"); // 准备SQL插入语句 + pstmt.setString(1, number); // 设置订单号 + pstmt.setFloat(2, allPrice); // 设置总价 + pstmt.setString(3, time); // 设置时间 + pstmt.setString(4, username); // 设置用户名 + pstmt.setInt(5, 1); // 设置删除标记 + if(pstmt.execute()) // 执行插入操作 + flag = true; // 如果成功执行插入,设置标志为true - - } catch (SQLException e) { - e.printStackTrace(); - }finally { + } catch (SQLException e) { // 捕获SQL异常 + e.printStackTrace(); // 打印异常堆栈信息 + }finally { // 无论是否发生异常,都会执行的代码块 - JDBCUtil.close(resultSet, pstmt, conn); + JDBCUtil.close(resultSet, pstmt, conn); // 关闭结果集、预编译语句和数据库连接 } - return flag; + return flag; // 返回插入结果标志 } /*删除缓冲区OutBuffer一条记录通过id*/ + // 根据ID删除出货缓冲区的一条记录 public boolean DelOutBufferById(String id) { - boolean flag = false; - Connection conn = JDBCUtil.getConn(); - PreparedStatement pstmt = null; - ResultSet resultSet = null; + boolean flag = false; // 初始化标志为false + Connection conn = JDBCUtil.getConn(); // 获取数据库连接 + PreparedStatement pstmt = null; // 初始化预编译语句对象 + ResultSet resultSet = null; // 初始化结果集对象 try { - pstmt = conn.prepareStatement("delete from OutBuffer where id=?"); - pstmt.setString(1, id); - if(pstmt.executeUpdate()==1) - flag = true; - - } catch (SQLException e) { - e.printStackTrace(); - }finally { + pstmt = conn.prepareStatement("delete from OutBuffer where id=?"); // 准备SQL删除语句 + pstmt.setString(1, id); // 设置商品ID + if(pstmt.executeUpdate()==1) // 执行删除操作 + flag = true; // 如果成功执行删除,设置标志为true - JDBCUtil.close(resultSet, pstmt, conn); + } catch (SQLException e) { // 捕获SQL异常 + e.printStackTrace(); // 打印异常堆栈信息 + }finally { // 无论是否发生异常,都会执行的代码块 + + JDBCUtil.close(resultSet, pstmt, conn); // 关闭结果集、预编译语句和数据库连接 } - return flag; + return flag; // 返回删除结果标志 } - + /*更改记录通过id*/ + // 更新出货缓冲区记录 public boolean UpdateOutBufferById(String id,int sum) { - boolean flag = false; - Connection conn = JDBCUtil.getConn(); - PreparedStatement pstmt = null; - ResultSet resultSet = null; + boolean flag = false; // 初始化标志为false + Connection conn = JDBCUtil.getConn(); // 获取数据库连接 + PreparedStatement pstmt = null; // 初始化预编译语句对象 + ResultSet resultSet = null; // 初始化结果集对象 try { - pstmt = conn.prepareStatement("upadte OutBuffer set sum=? where id=?"); - pstmt.setInt(1, sum); - pstmt.setString(2, id); - if(pstmt.execute()) - flag = true; - - } catch (SQLException e) { - e.printStackTrace(); - }finally { + pstmt = conn.prepareStatement("update OutBuffer set sum=? where id=?"); // 准备SQL更新语句 + pstmt.setInt(1, sum); // 设置更新后的商品数量 + pstmt.setString(2, id); // 设置商品ID + if(pstmt.execute()) // 执行更新操作 + flag = true; // 如果成功执行更新,设置标志为true - JDBCUtil.close(resultSet, pstmt, conn); + } catch (SQLException e) { // 捕获SQL异常 + e.printStackTrace(); // 打印异常堆栈信息 + }finally { // 无论是否发生异常,都会执行的代码块 + + JDBCUtil.close(resultSet, pstmt, conn); // 关闭结果集、预编译语句和数据库连接 } - return flag; + return flag; // 返回更新结果标志 } - - - - - - - - - - - - + + + + + + + + + /*---------------------------进货模块----------------------------*/ + /*编辑人程文锋2210461197*/ /*返回出货缓冲表所有delmark=1的记录并排序*/ + // 获取所有进货缓冲区的记录 + /** + * 从数据库中获取所有在库的商品信息,并返回一个包含Production对象的向量。 + * + * @return 包含所有Production对象的向量 + */ public Vector allInBuffer(){ - Connection conn = JDBCUtil.getConn(); - PreparedStatement pstmt = null; - ResultSet resultSet=null; - Vector v = new Vector(); - Production production; + Connection conn = JDBCUtil.getConn(); // 获取数据库连接 + PreparedStatement pstmt = null; // 初始化预编译语句对象 + ResultSet resultSet=null; // 初始化结果集对象 + Vector v = new Vector(); // 创建一个向量用于存储Production对象 + Production production; // 声明一个Production对象 try { - pstmt = conn.prepareStatement("select * from InBuffer "); - resultSet = pstmt.executeQuery(); - while(resultSet.next()) { - production = new Production(); - production.setId(resultSet.getString("id")); - production.setName(resultSet.getString("name")); - production.setInPrice(resultSet.getFloat("inPrice")); - production.setOutPrice(resultSet.getFloat("OutPrice")); - production.setLife(resultSet.getInt("life")); - production.setSum(resultSet.getInt("sum")); - production.setSupplyId(resultSet.getInt("supplyId")); - production.setId2(resultSet.getString("id2")); - production.setName2(resultSet.getString("name2")); - production.setPrice(resultSet.getFloat("price")); - production.setDelmark(resultSet.getInt("delmark")); - v.add(production); + pstmt = conn.prepareStatement("select * from InBuffer "); // 准备SQL查询语句 + resultSet = pstmt.executeQuery(); // 执行查询 + while(resultSet.next()) { // 遍历结果集 + production = new Production(); // 创建一个新的Production对象 + production.setId(resultSet.getString("id")); // 设置商品ID + production.setName(resultSet.getString("name")); // 设置商品名称 + production.setInPrice(resultSet.getFloat("inPrice")); // 设置进货价格 + production.setOutPrice(resultSet.getFloat("OutPrice")); // 设置出货价格 + production.setLife(resultSet.getInt("life")); // 设置商品保质期 + production.setSum(resultSet.getInt("sum")); // 设置商品数量 + production.setSupplyId(resultSet.getInt("supplyId")); // 设置供应商ID + production.setId2(resultSet.getString("id2")); // 设置商品类别ID + production.setName2(resultSet.getString("name2")); // 设置商品类别名称 + production.setPrice(resultSet.getFloat("price")); // 设置商品总价 + production.setDelmark(resultSet.getInt("delmark")); // 设置删除标记 + v.add(production); // 将Production对象添加到向量中 } - - } catch (SQLException e) { - e.printStackTrace(); - }finally { - JDBCUtil.close(resultSet, pstmt, conn); + + } catch (SQLException e) { // 捕获SQL异常 + e.printStackTrace(); // 打印异常堆栈信息 + }finally { // 无论是否发生异常,都会执行的代码块 + JDBCUtil.close(resultSet, pstmt, conn); // 关闭结果集、预编译语句和数据库连接 } - return v; + return v; // 返回存储所有Production对象的向量 } - /*通过id查找返回boolean*/ - public Buffer findInBufferbyId(String id) + /** + * 根据商品ID在数据库中查找对应的Buffer对象 + * @param id 商品的ID + * @return 找到的Buffer对象,若未找到则返回null + */ + public Buffer findInBufferbyId(String id) { - Connection conn = JDBCUtil.getConn(); - PreparedStatement pstmt = null; - ResultSet resultSet=null; - Buffer buffer = new Buffer(); - try { - pstmt = conn.prepareStatement("select * from InBuffer where id=? "); - pstmt.setString(1, id); - resultSet = pstmt.executeQuery(); - - if(resultSet.next()) { - buffer.setId(resultSet.getString("id")); - buffer.setName(resultSet.getString("name")); - buffer.setInPrice(resultSet.getFloat("inPrice")); - buffer.setOutPrice(resultSet.getFloat("OutPrice")); - buffer.setLife(resultSet.getInt("life")); - buffer.setSum(resultSet.getInt("sum")); - buffer.setSupplyId(resultSet.getInt("supplyId")); - buffer.setId2(resultSet.getString("id2")); - buffer.setName2(resultSet.getString("name2")); - buffer.setPrice(resultSet.getFloat("price")); - buffer.setDelmark(resultSet.getInt("delmark")); - } - else { - return null; - } + Connection conn = JDBCUtil.getConn(); // 获取数据库连接 + PreparedStatement pstmt = null; // 初始化预编译语句对象 + ResultSet resultSet=null; // 初始化结果集对象 + Buffer buffer = new Buffer(); // 创建一个新的Buffer对象 + try { + pstmt = conn.prepareStatement("select * from InBuffer where id=? "); // 准备SQL查询语句 + pstmt.setString(1, id); // 设置查询参数 + resultSet = pstmt.executeQuery(); // 执行查询 + + if(resultSet.next()) { // 如果找到对应记录 + buffer.setId(resultSet.getString("id")); // 设置商品ID + buffer.setName(resultSet.getString("name")); // 设置商品名称 + buffer.setInPrice(resultSet.getFloat("inPrice")); // 设置进货价格 + buffer.setOutPrice(resultSet.getFloat("OutPrice")); // 设置出货价格 + buffer.setLife(resultSet.getInt("life")); // 设置商品保质期 + buffer.setSum(resultSet.getInt("sum")); // 设置商品数量 + buffer.setSupplyId(resultSet.getInt("supplyId")); // 设置供应商ID + buffer.setId2(resultSet.getString("id2")); // 设置商品类别ID + buffer.setName2(resultSet.getString("name2")); // 设置商品类别名称 + buffer.setPrice(resultSet.getFloat("price")); // 设置商品总价 + buffer.setDelmark(resultSet.getInt("delmark")); // 设置删除标记 + } + else { + return null; // 没有找到该商品,返回null + } + - - } catch (SQLException e) { - e.printStackTrace(); - }finally { - JDBCUtil.close(resultSet, pstmt, conn); + } catch (SQLException e) { // 捕获SQL异常 + e.printStackTrace(); // 打印异常堆栈信息 + }finally { // 无论是否发生异常,都会执行的代码块 + JDBCUtil.close(resultSet, pstmt, conn); // 关闭结果集、预编译语句和数据库连接 + } + return buffer; // 返回找到的Buffer对象 } - return buffer; -} + + /*如果缓冲区没有那就把整条记录插入插入操作*/ +// 向进货缓冲区添加新商品记录 + /** + * 添加新商品记录到进货缓冲区 + * + * @param id 商品ID + * @param sum 商品数量 + * @return 返回插入操作是否成功的标志 + */ public boolean addInBufferNewProd(String id,int sum) { - boolean flag = false; - Connection conn = JDBCUtil.getConn(); - PreparedStatement pstmt = null; - ResultSet resultSet=null; + boolean flag = false; // 初始化标志为false + Connection conn = JDBCUtil.getConn(); // 获取数据库连接 + PreparedStatement pstmt = null; // 初始化预编译语句对象 + ResultSet resultSet=null; // 初始化结果集对象 try { - pstmt = conn.prepareStatement("call InsertInBuffer(?,?) "); - pstmt.setString(1, id); - pstmt.setInt(2, sum); - - - if( pstmt.executeUpdate()==1) { - flag = true; + pstmt = conn.prepareStatement("call InsertInBuffer(?,?) "); // 准备存储过程调用语句 + pstmt.setString(1, id); // 设置商品ID参数 + pstmt.setInt(2, sum); // 设置商品数量参数 + + + if( pstmt.executeUpdate()==1) { // 执行更新操作 + flag = true; // 如果成功执行插入,设置标志为true } - - } catch (SQLException e) { - e.printStackTrace(); - }finally { - JDBCUtil.close(resultSet, pstmt, conn); + + } catch (SQLException e) { // 捕获SQL异常 + e.printStackTrace(); // 打印异常堆栈信息 + }finally { // 无论是否发生异常,都会执行的代码块 + JDBCUtil.close(resultSet, pstmt, conn); // 关闭结果集、预编译语句和数据库连接 } - return flag; + return flag; // 返回插入结果标志 } - + + + + // 向进货缓冲区插入一条记录 + // 此方法负责将一个商品记录插入到进货缓冲区中,并返回插入操作是否成功的标志 public boolean insertInBuffer(Production p) { - boolean flag = false; - Connection conn = JDBCUtil.getConn(); - PreparedStatement pstmt = null; - ResultSet resultSet=null; - try { - pstmt = conn.prepareStatement("insert into InBuffer values(?,?,?,?,?,?,?,?,?,?,?)"); - pstmt.setString(1, p.getId()); - pstmt.setString(2, p.getName()); - pstmt.setFloat(3, p.getInPrice()); - pstmt.setFloat(4, p.getOutPrice()); - pstmt.setInt(5, p.getLife()); - pstmt.setInt(6, p.getSum()); - pstmt.setInt(7, p.getSupplyId()); - pstmt.setString(8, p.getId2()); - pstmt.setString(9, p.getName2()); - pstmt.setFloat(10,p.getPrice()); - pstmt.setInt(11, 1); - pstmt.executeUpdate(); - - - if( pstmt.execute()) { - flag = true; - } + boolean flag = false; // 初始化标志为false + Connection conn = JDBCUtil.getConn(); // 获取数据库连接 + PreparedStatement pstmt = null; // 初始化预编译语句对象 + ResultSet resultSet=null; // 初始化结果集对象 + try { + pstmt = conn.prepareStatement("insert into InBuffer values(?,?,?,?,?,?,?,?,?,?,?)"); // 准备SQL插入语句 + pstmt.setString(1, p.getId()); // 设置商品ID + pstmt.setString(2, p.getName()); // 设置商品名称 + pstmt.setFloat(3, p.getInPrice()); // 设置进货价格 + pstmt.setFloat(4, p.getOutPrice()); // 设置出货价格 + pstmt.setInt(5, p.getLife()); // 设置商品保质期 + pstmt.setInt(6, p.getSum()); // 设置商品数量 + pstmt.setInt(7, p.getSupplyId()); // 设置供应商ID + pstmt.setString(8, p.getId2()); // 设置商品类别ID + pstmt.setString(9, p.getName2()); // 设置商品类别名称 + pstmt.setFloat(10,p.getPrice()); // 设置商品总价 + pstmt.setInt(11, 1); // 设置删除标记 + pstmt.executeUpdate(); // 执行插入操作 + + + if( pstmt.execute()) { // 如果成功执行插入,设置标志为true + flag = true; + } + - - } catch (SQLException e) { - e.printStackTrace(); - }finally { - JDBCUtil.close(resultSet, pstmt, conn); + } catch (SQLException e) { // 捕获SQL异常 + e.printStackTrace(); // 打印异常堆栈信息 + }finally { // 无论是否发生异常,都会执行的代码块 + JDBCUtil.close(resultSet, pstmt, conn); // 关闭结果集、预编译语句和数据库连接 + } + return flag; // 返回插入结果标志 } - return flag; -} - + /* 根据商品id获取sum和outprice public Buffer findInBufferSumAndInPrice(String id) { Buffer Buffer = new Buffer(); @@ -467,13 +498,13 @@ public class BufferImpl implements BufferService { pstmt = conn.prepareStatement("select * from InBuffer where id=? "); pstmt.setString(1, id); resultSet = pstmt.executeQuery(); - + if(resultSet.next()) { Buffer.setSum(resultSet.getInt("sum")); Buffer.setOutPrice(resultSet.getFloat("InPrice")); } - + } catch (SQLException e) { e.printStackTrace(); }finally { @@ -481,165 +512,206 @@ public class BufferImpl implements BufferService { } return Buffer; }*/ - /*如果delmark是1,即是已经添加的商品*/ + // 更新已存在商品的进货缓冲区记录 + // 方法名称:addInBufferExeistProd + // 参数: + // id - 商品的唯一标识符 + // sum - 要添加的商品数量 + // buffer - 包含商品信息的缓冲区对象 + // 返回值:布尔值,表示更新操作是否成功 public boolean addInBufferExeistProd(String id,int sum,Buffer buffer){ - boolean flag = false; - Connection conn = JDBCUtil.getConn(); - PreparedStatement pstmt = null; - ResultSet resultSet = null;; + boolean flag = false; // 初始化标志为false + Connection conn = JDBCUtil.getConn(); // 获取数据库连接 + PreparedStatement pstmt = null; // 初始化预编译语句对象 + ResultSet resultSet = null;; // 初始化结果集对象 try { - pstmt = conn.prepareStatement("update InBuffer set sum=?,price=? where id=? "); - pstmt.setInt(1, sum+buffer.getSum()); - pstmt.setFloat(2,( sum+buffer.getSum()*buffer.getInPrice())); - pstmt.setString(3, id); - if(pstmt.executeUpdate()==1) { - flag = true; + pstmt = conn.prepareStatement("update InBuffer set sum=?,price=? where id=? "); // 准备SQL更新语句 + pstmt.setInt(1, sum+buffer.getSum()); // 设置更新后的商品数量 + pstmt.setFloat(2,( sum+buffer.getSum()*buffer.getInPrice())); // 设置更新后的商品总价 + pstmt.setString(3, id); // 设置商品ID + if(pstmt.executeUpdate()==1) { // 执行更新操作 + flag = true; // 如果成功执行更新,设置标志为true } - - } catch (SQLException e) { - e.printStackTrace(); - }finally { + } catch (SQLException e) { // 捕获SQL异常 + e.printStackTrace(); // 打印异常堆栈信息 + }finally { // 无论是否发生异常,都会执行的代码块 - JDBCUtil.close(resultSet, pstmt, conn); + JDBCUtil.close(resultSet, pstmt, conn); // 关闭结果集、预编译语句和数据库连接 } - return flag; + return flag; // 返回更新结果标志 } + /*获得购物车总价*/ +// 计算进货缓冲区所有商品的总价 +// 此方法用于计算数据库中进货缓冲区所有商品的总价,并返回相应的浮点数值。 public Float InBufferAllPrice(){ - boolean flag = false; - Connection conn = JDBCUtil.getConn(); - PreparedStatement pstmt = null; - ResultSet resultSet = null;; + boolean flag = false; // 初始化标志为false + Connection conn = JDBCUtil.getConn(); // 获取数据库连接 + PreparedStatement pstmt = null; // 初始化预编译语句对象 + ResultSet resultSet = null;; // 初始化结果集对象 try { - pstmt = conn.prepareStatement("select sum(price) from InBuffer "); - resultSet=pstmt.executeQuery(); - if(resultSet.next()) { - return resultSet.getFloat("sum(price)"); + pstmt = conn.prepareStatement("select sum(price) from InBuffer "); // 准备SQL查询语句 + resultSet=pstmt.executeQuery(); // 执行查询 + if(resultSet.next()) { // 如果有结果 + return resultSet.getFloat("sum(price)"); // 返回总价 } - - } catch (SQLException e) { - e.printStackTrace(); - }finally { - JDBCUtil.close(resultSet, pstmt, conn); + } catch (SQLException e) { // 捕获SQL异常 + e.printStackTrace(); // 打印异常堆栈信息 + }finally { // 无论是否发生异常,都会执行的代码块 + + JDBCUtil.close(resultSet, pstmt, conn); // 关闭结果集、预编译语句和数据库连接 } - return null; + return null; // 如果没有结果,返回null } - - + + /*结账后对5个表进行操作*/ +// 进行进货时的记录操作 + /** + * 在库存中记录进货信息的函数 + * + * @param number 订单号 + * @param time 进货时间 + * @param id 商品ID + * @param sum 商品数量 + * @param price 商品总价 + * @return 返回操作是否成功的标志 + */ public boolean Stock(String number,String time,String id,int sum,Float price){ - boolean flag = false; - Connection conn = JDBCUtil.getConn(); - PreparedStatement pstmt = null; - ResultSet resultSet = null;; + boolean flag = false; // 初始化标志为false + Connection conn = JDBCUtil.getConn(); // 获取数据库连接 + PreparedStatement pstmt = null; // 初始化预编译语句对象 + ResultSet resultSet = null;; // 初始化结果集对象 try { - pstmt = conn.prepareStatement("call Stock(?,?,?,?,?)"); - pstmt.setString(1,number); - pstmt.setString(2,time ); - pstmt.setString(3,id ); - pstmt.setInt(4,sum ); - pstmt.setFloat(5, price); - if(pstmt.executeUpdate()==1) - flag = true; - - - - } catch (SQLException e) { - e.printStackTrace(); - }finally { - - JDBCUtil.close(resultSet, pstmt, conn); + pstmt = conn.prepareStatement("call Stock(?,?,?,?,?)"); // 准备存储过程调用语句 + pstmt.setString(1,number); // 设置订单号 + pstmt.setString(2,time ); // 设置时间 + pstmt.setString(3,id ); // 设置商品ID + pstmt.setInt(4,sum ); // 设置商品数量 + pstmt.setFloat(5, price); // 设置商品总价 + if(pstmt.executeUpdate()==1) // 执行更新操作 + flag = true; // 如果成功执行更新,设置标志为true + } catch (SQLException e) { // 捕获SQL异常 + e.printStackTrace(); // 打印异常堆栈信息 + }finally { // 无论是否发生异常,都会执行的代码块 + + JDBCUtil.close(resultSet, pstmt, conn); // 关闭结果集、预编译语句和数据库连接 } - return flag; + return flag; // 返回更新结果标志 } - + + /*删除所有购物车*/ + // 清空进货缓冲区 + /** + * 从数据库中删除进货缓冲区中的所有记录 + * + * @return 返回操作是否成功的标志 + */ public boolean DelAllInBuffer(){ - boolean flag = false; - Connection conn = JDBCUtil.getConn(); - PreparedStatement pstmt = null; - ResultSet resultSet = null;; + boolean flag = false; // 初始化标志为false + Connection conn = JDBCUtil.getConn(); // 获取数据库连接 + PreparedStatement pstmt = null; // 初始化预编译语句对象 + ResultSet resultSet = null;; // 初始化结果集对象 try { - pstmt = conn.prepareStatement("delete from InBuffer"); - if(pstmt.execute()) - flag = true; - - - - } catch (SQLException e) { - e.printStackTrace(); - }finally { - - JDBCUtil.close(resultSet, pstmt, conn); + pstmt = conn.prepareStatement("delete from InBuffer"); // 准备SQL删除语句 + if(pstmt.execute()) // 执行删除操作 + flag = true; // 如果成功执行删除,设置标志为true + } catch (SQLException e) { // 捕获SQL异常 + e.printStackTrace(); // 打印异常堆栈信息 + }finally { // 无论是否发生异常,都会执行的代码块 + + JDBCUtil.close(resultSet, pstmt, conn); // 关闭结果集、预编译语句和数据库连接 } - return flag; + return flag; // 返回删除结果标志 } - /*删除缓冲区InBuffer一条记录通过id*/ + // 根据ID删除进货缓冲区的一条记录 + /** + * 根据商品ID删除进货缓冲区中的一条记录 + * + * @param id 商品ID + * @return 删除操作是否成功的标志 + */ public boolean DelInBufferById(String id) { - boolean flag = false; - Connection conn = JDBCUtil.getConn(); - PreparedStatement pstmt = null; - ResultSet resultSet = null;; + boolean flag = false; // 初始化标志为false + Connection conn = JDBCUtil.getConn(); // 获取数据库连接 + PreparedStatement pstmt = null; // 初始化预编译语句对象 + ResultSet resultSet = null;; // 初始化结果集对象 try { - pstmt = conn.prepareStatement("delete from InBuffer where id=?"); - pstmt.setString(1, id); - if(pstmt.executeUpdate()==1) - flag = true; - - } catch (SQLException e) { - e.printStackTrace(); - }finally { + pstmt = conn.prepareStatement("delete from InBuffer where id=?"); // 准备SQL删除语句 + pstmt.setString(1, id); // 设置商品ID + if(pstmt.executeUpdate()==1) // 执行删除操作 + flag = true; // 如果成功执行删除,设置标志为true - JDBCUtil.close(resultSet, pstmt, conn); + } catch (SQLException e) { // 捕获SQL异常 + e.printStackTrace(); // 打印异常堆栈信息 + }finally { // 无论是否发生异常,都会执行的代码块 + + JDBCUtil.close(resultSet, pstmt, conn); // 关闭结果集、预编译语句和数据库连接 } - return flag; + return flag; // 返回删除结果标志 } - - - - /*更改记录通过id*/ - public boolean UpdateInBufferById(String id,int sum) { - boolean flag = false; - Connection conn = JDBCUtil.getConn(); - PreparedStatement pstmt = null; - ResultSet resultSet = null; + + + + + + /*更改记录通过id*/ + // 更新进货缓冲区记录 + /** + * 更新进货缓冲区中指定商品ID的数量。 + * + * @param id 商品的ID + * @param sum 更新后的商品数量 + * @return 返回更新是否成功的标志 + */ +public boolean UpdateInBufferById(String id,int sum) { + boolean flag = false; // 初始化标志为false + Connection conn = JDBCUtil.getConn(); // 获取数据库连接 + PreparedStatement pstmt = null; // 初始化预编译语句对象 + ResultSet resultSet = null; // 初始化结果集对象 try { - pstmt = conn.prepareStatement("upadte InBuffer set sum=? where id=?"); - pstmt.setInt(1, sum); - pstmt.setString(2, id); - if(pstmt.execute()) - flag = true; - - } catch (SQLException e) { - e.printStackTrace(); - }finally { + pstmt = conn.prepareStatement("update InBuffer set sum=? where id=?"); // 准备SQL更新语句 + pstmt.setInt(1, sum); // 设置更新后的商品数量 + pstmt.setString(2, id); // 设置商品ID + if(pstmt.execute()) // 执行更新操作 + flag = true; // 如果成功执行更新,设置标志为true - JDBCUtil.close(resultSet, pstmt, conn); + } catch (SQLException e) { // 捕获SQL异常 + e.printStackTrace(); // 打印异常堆栈信息 + }finally { // 无论是否发生异常,都会执行的代码块 + + JDBCUtil.close(resultSet, pstmt, conn); // 关闭结果集、预编译语句和数据库连接 } - return flag; + return flag; // 返回更新结果标志 } + + /** + * 按照顺序插入订单 + * + * @param number 订单编号 + * @param allPrice 总价格 + * @param time 订单时间 + * @param username 用户名 + * @return 返回插入成功与否 + */ @Override public boolean InsertInOrder(String number, Float allPrice, String time, String username) { // TODO Auto-generated method stub + // 插入订单的操作 return false; } - - - - } - - diff --git a/Supermarket/src/com/lingnan/supermarket/dao/impl/SupplierInfImpl.java b/Supermarket/src/com/lingnan/supermarket/dao/impl/SupplierInfImpl.java index 26b2dab..c35f6b1 100644 --- a/Supermarket/src/com/lingnan/supermarket/dao/impl/SupplierInfImpl.java +++ b/Supermarket/src/com/lingnan/supermarket/dao/impl/SupplierInfImpl.java @@ -1,5 +1,9 @@ package com.lingnan.supermarket.dao.impl; +import com.lingnan.supermarket.dao.SupplierInfService; +import com.lingnan.supermarket.dto.SupplierInf; +import com.lingnan.supermarket.utils.JDBCUtil; + import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; @@ -8,211 +12,255 @@ import java.util.ArrayList; import java.util.Iterator; import java.util.Vector; -import com.lingnan.supermarket.dao.SupplierInfService; -import com.lingnan.supermarket.dto.ProdCatalog; -import com.lingnan.supermarket.dto.SupplierInf; -import com.lingnan.supermarket.dto.User; -import com.lingnan.supermarket.utils.JDBCUtil; +/** + * 供应商信息服务实现类 + * @cwf 2210461197 2024/12/1 + */ + +// 实现供应商信息服务接口的类 public class SupplierInfImpl implements SupplierInfService{ + // 查询所有供应商信息的方法 @Override + // 该方法用于查找所有未被标记为删除的供应商信息,返回一个供应商信息的向量 + // 此方法连接数据库,执行查询,并将结果封装为供应商信息对象的向量 public Vector findAllSupplierInf() { - Vector supplierInfs = new Vector(); - Connection conn = JDBCUtil.getConn(); - PreparedStatement preparedStatement = null; - ResultSet resultSet=null; - - String SQL = "select * from supplierInf where delmark = 1"; - + Vector supplierInfs = new Vector(); // 创建一个向量用于存储供应商信息 + Connection conn = JDBCUtil.getConn(); // 获取数据库连接 + PreparedStatement preparedStatement = null; // 初始化预编译语句对象 + ResultSet resultSet=null; // 初始化结果集对象 + + String SQL = "select * from supplierInf where delmark = 1"; // SQL查询语句,选择未被标记为删除的供应商信息 + try { - preparedStatement = conn.prepareStatement(SQL); - resultSet = preparedStatement.executeQuery(); - while(resultSet.next()) { - SupplierInf supplierInf = new SupplierInf(); - supplierInf.setId(resultSet.getInt("id")); - supplierInf.setName(resultSet.getString("name")); - supplierInf.setContact(resultSet.getString("contact")); - supplierInf.setEmail(resultSet.getString("email")); - supplierInf.setAddress(resultSet.getString("address")); - supplierInf.setDelmark(resultSet.getInt("delmark")); - supplierInfs.add(supplierInf); + preparedStatement = conn.prepareStatement(SQL); // 准备SQL语句 + resultSet = preparedStatement.executeQuery(); // 执行查询 + while(resultSet.next()) { // 遍历结果集 + SupplierInf supplierInf = new SupplierInf(); // 创建一个新的供应商信息对象 + supplierInf.setId(resultSet.getInt("id")); // 设置供应商ID + supplierInf.setName(resultSet.getString("name")); // 设置供应商名称 + supplierInf.setContact(resultSet.getString("contact")); // 设置供应商联系人 + supplierInf.setEmail(resultSet.getString("email")); // 设置供应商邮箱 + supplierInf.setAddress(resultSet.getString("address")); // 设置供应商地址 + supplierInf.setDelmark(resultSet.getInt("delmark")); // 设置删除标记 + supplierInfs.add(supplierInf); // 将供应商信息对象添加到向量中 } - - } catch (SQLException e) { - e.printStackTrace(); - } finally { - JDBCUtil.close(resultSet, preparedStatement, conn); + + } catch (SQLException e) { // 捕获SQL异常 + e.printStackTrace(); // 打印异常堆栈信息 + } finally { // 无论是否发生异常,都会执行的代码块 + // 关闭数据库连接和相关资源 + JDBCUtil.close(resultSet, preparedStatement, conn); // 关闭结果集、预编译语句和数据库连接 } - return supplierInfs; + return supplierInfs; // 返回存储所有供应商信息的向量 } + // 根据供应商名称查询供应商信息的方法 @Override + // 定义一个查找供应商信息的方法,根据传入的供应商对象进行查询 + /** + * 根据供应商名称查找供应商信息 + * @param supplierInf 包含供应商名称的供应商信息对象 + * @return 返回包含查询到的供应商信息的向量 + */ public Vector findByNameSupplierInf(SupplierInf supplierInf) { //SupplierInf supplierInf = new SupplierInf(); - Connection conn = JDBCUtil.getConn(); - Vector v = new Vector<>(); - System.out.println(supplierInf.getName()); - PreparedStatement preparedStatement = null; - ResultSet resultSet = null; + Connection conn = JDBCUtil.getConn(); // 获取数据库连接 + Vector v = new Vector<>(); // 创建一个向量用于存储供应商信息 + System.out.println(supplierInf.getName()); // 打印供应商名称 + PreparedStatement preparedStatement = null; // 初始化预编译语句对象 + ResultSet resultSet = null; // 初始化结果集对象 try { - if(!supplierInf.getName().equals("")){ - String s='%'+supplierInf.getName()+'%'; - preparedStatement = conn.prepareStatement("select * from supplierInf where name like ? and delmark = 1"); - preparedStatement.setString(1, s); + if(!supplierInf.getName().equals("")){ // 如果供应商名称不为空 + String s='%'+supplierInf.getName()+'%'; // 构建模糊查询字符串 + preparedStatement = conn.prepareStatement("select * from supplierInf where name like ? and delmark = 1"); // 准备SQL查询语句 + preparedStatement.setString(1, s); // 设置查询参数 }else - preparedStatement = conn.prepareStatement("select * from supplierInf where delmark = 1"); - resultSet = preparedStatement.executeQuery(); - while (resultSet.next()) { - supplierInf = new SupplierInf(); - supplierInf.setId(resultSet.getInt("id")); - supplierInf.setName(resultSet.getString("name")); - supplierInf.setAddress(resultSet.getString("address")); - supplierInf.setContact(resultSet.getString("contact")); - supplierInf.setEmail(resultSet.getString("email")); - supplierInf.setDelmark(1); - v.add(supplierInf); + preparedStatement = conn.prepareStatement("select * from supplierInf where delmark = 1"); // 准备SQL查询语句,选择未被标记为删除的供应商信息 + + resultSet = preparedStatement.executeQuery(); // 执行查询 + while (resultSet.next()) { // 遍历结果集 + supplierInf = new SupplierInf(); // 创建一个新的供应商信息对象 + supplierInf.setId(resultSet.getInt("id")); // 设置供应商ID + supplierInf.setName(resultSet.getString("name")); // 设置供应商名称 + supplierInf.setAddress(resultSet.getString("address")); // 设置供应商地址 + supplierInf.setContact(resultSet.getString("contact")); // 设置供应商联系人 + supplierInf.setEmail(resultSet.getString("email")); // 设置供应商邮箱 + supplierInf.setDelmark(1); // 设置删除标记 + v.add(supplierInf); // 将供应商信息对象添加到向量中 + } + Iterator it=v.iterator(); // 获取向量的迭代器 + while(it.hasNext()){ // 遍历向量 + supplierInf=it.next(); // 获取下一个供应商信息对象 + System.out.println(supplierInf.getId()+" "+supplierInf.getName()+" "+supplierInf.getAddress()+" "+supplierInf.getContact()+" "+supplierInf.getEmail()+" "+supplierInf.getDelmark()+" "); // 打印供应商信息 } - Iterator it=v.iterator(); - while(it.hasNext()){ - supplierInf=it.next(); - System.out.println(supplierInf.getId()+" "+supplierInf.getName()+" "+supplierInf.getAddress()+" "+supplierInf.getContact()+" "+supplierInf.getEmail()+" "+supplierInf.getDelmark()+" "); - } - } catch (SQLException e) { - e.printStackTrace(); - } finally { - JDBCUtil.close(resultSet, preparedStatement, conn); + } catch (SQLException e) { // 捕获SQL异常 + e.printStackTrace(); // 打印异常堆栈信息 + } finally { // 无论是否发生异常,都会执行的代码块 + JDBCUtil.close(resultSet, preparedStatement, conn); // 关闭结果集、预编译语句和数据库连接 } - return v; + return v; // 返回存储供应商信息的向量 } - +// 添加供应商信息的方法 + /** + * 添加供应商信息 + * + * @param supplierInf 供应商信息对象 + * @return 插入结果标志,1表示成功,0表示失败 + */ @Override public int addSupplierInf(SupplierInf supplierInf) { - int flag = 0; - Connection conn = JDBCUtil.getConn(); - PreparedStatement preparedStatement = null; - + int flag = 0; // 初始化标志为0 + Connection conn = JDBCUtil.getConn(); // 获取数据库连接 + PreparedStatement preparedStatement = null; // 初始化预编译语句对象 + try { preparedStatement = conn.prepareStatement - ("insert into supplierInf values (null,?,?,?,?,?)"); + ("insert into supplierInf values (null,?,?,?,?,?)"); // 准备SQL插入语句 //preparedStatement.setInt(1, supplierInf.getId()); - preparedStatement.setString(1, supplierInf.getName()); - preparedStatement.setString(2, supplierInf.getAddress()); - preparedStatement.setString(3, supplierInf.getContact()); - preparedStatement.setString(4, supplierInf.getEmail()); - preparedStatement.setInt(5, 1); - preparedStatement.executeUpdate(); - flag = 1; - } catch (SQLException e) { - e.printStackTrace(); - } finally { - JDBCUtil.close(null,preparedStatement, conn); + preparedStatement.setString(1, supplierInf.getName()); // 设置供应商名称 + preparedStatement.setString(2, supplierInf.getAddress()); // 设置供应商地址 + preparedStatement.setString(3, supplierInf.getContact()); // 设置供应商联系人 + preparedStatement.setString(4, supplierInf.getEmail()); // 设置供应商邮箱 + preparedStatement.setInt(5, 1); // 设置删除标记 + preparedStatement.executeUpdate(); // 执行插入操作 + flag = 1; // 设置标志为1,表示插入成功 + } catch (SQLException e) { // 捕获SQL异常 + e.printStackTrace(); // 打印异常堆栈信息 + } finally { // 无论是否发生异常,都会执行的代码块 + JDBCUtil.close(null,preparedStatement, conn); // 关闭预编译语句和数据库连接 } - - return flag; - } + return flag; // 返回插入结果标志 + } + // 删除供应商信息的方法 + /** + * 删除指定ID的供应商信息 + * + * @param id 要删除的供应商ID + * @return 删除操作的结果标志,1表示成功,0表示失败 + */ @Override public int deleteSupplierInf(int id) { - int flag = 0; - - Connection conn = JDBCUtil.getConn(); - PreparedStatement preparedStatement = null; - + int flag = 0; // 初始化标志为0 + + Connection conn = JDBCUtil.getConn(); // 获取数据库连接 + PreparedStatement preparedStatement = null; // 初始化预编译语句对象 + try { preparedStatement = conn.prepareStatement - ("delete from supplierInf where id = ?"); - preparedStatement.setInt(1, id); - preparedStatement.executeUpdate(); - flag = 1; - } catch (SQLException e) { - e.printStackTrace(); - } finally { - JDBCUtil.close(null,preparedStatement, conn); + ("delete from supplierInf where id = ?"); // 准备SQL删除语句 + preparedStatement.setInt(1, id); // 设置供应商ID + preparedStatement.executeUpdate(); // 执行删除操作 + flag = 1; // 设置标志为1,表示删除成功 + } catch (SQLException e) { // 捕获SQL异常 + e.printStackTrace(); // 打印异常堆栈信息 + } finally { // 无论是否发生异常,都会执行的代码块 + JDBCUtil.close(null,preparedStatement, conn); // 关闭预编译语句和数据库连接 } - return flag; + return flag; // 返回删除结果标志 } + // 更新供应商信息的方法 + /** + * 更新供应商信息 + * + * @param supplierInf 供应商信息对象 + * @return 更新结果标志,1表示成功,0表示失败 + */ @Override public int updateSupplierInf(SupplierInf supplierInf) { - int flag=0; - Connection conn = JDBCUtil.getConn(); - PreparedStatement preparedStatement = null; + int flag=0; // 初始化标志为0 + Connection conn = JDBCUtil.getConn(); // 获取数据库连接 + PreparedStatement preparedStatement = null; // 初始化预编译语句对象 try { - preparedStatement = conn.prepareStatement("update supplierInf set name=?,address=?,contact=?,email=?,delmark=? where id = ?"); - preparedStatement.setString(1,supplierInf.getName()); - preparedStatement.setString(2,supplierInf.getAddress()); - preparedStatement.setString(3,supplierInf.getContact()); - preparedStatement.setString(4, supplierInf.getEmail()); - preparedStatement.setInt(5, supplierInf.getDelmark()); - preparedStatement.setInt(6,supplierInf.getId()); - preparedStatement.executeUpdate(); - flag = 1; - - } catch (SQLException e) { - e.printStackTrace(); - } finally { - JDBCUtil.close(null, preparedStatement, conn); + preparedStatement = conn.prepareStatement("update supplierInf set name=?,address=?,contact=?,email=?,delmark=? where id = ?"); // 准备SQL更新语句 + preparedStatement.setString(1,supplierInf.getName()); // 设置供应商名称 + preparedStatement.setString(2,supplierInf.getAddress()); // 设置供应商地址 + preparedStatement.setString(3,supplierInf.getContact()); // 设置供应商联系人 + preparedStatement.setString(4, supplierInf.getEmail()); // 设置供应商邮箱 + preparedStatement.setInt(5, supplierInf.getDelmark()); // 设置删除标记 + preparedStatement.setInt(6,supplierInf.getId()); // 设置供应商ID + preparedStatement.executeUpdate(); // 执行更新操作 + flag = 1; // 设置标志为1,表示更新成功 + + } catch (SQLException e) { // 捕获SQL异常 + e.printStackTrace(); // 打印异常堆栈信息 + } finally { // 无论是否发生异常,都会执行的代码块 + JDBCUtil.close(null, preparedStatement, conn); // 关闭预编译语句和数据库连接 } - return flag; + return flag; // 返回更新结果标志 } - + + + // 获取所有供应商名称的方法 + // 该方法从数据库中查询所有供应商的名称,并将其存储在一个列表中返回 @Override public ArrayList findNameSupplier() { - Connection conn=JDBCUtil.getConn(); - ArrayList v = new ArrayList(); - SupplierInf supplierInf; - PreparedStatement pstmt = null; - ResultSet resultSet=null; - v.add("全部"); + Connection conn=JDBCUtil.getConn(); // 获取数据库连接 + ArrayList v = new ArrayList(); // 创建一个列表用于存储供应商名称 + SupplierInf supplierInf; // 声明一个供应商信息对象 + PreparedStatement pstmt = null; // 初始化预编译语句对象 + ResultSet resultSet=null; // 初始化结果集对象 + v.add("全部"); // 添加默认选项“全部” try { - pstmt = conn.prepareStatement("select * from supplierInf"); - resultSet = pstmt.executeQuery(); - while(resultSet.next()){ - - v.add(resultSet.getString("name")); + pstmt = conn.prepareStatement("select * from supplierInf"); // 准备SQL查询语句 + resultSet = pstmt.executeQuery(); // 执行查询 + while(resultSet.next()){ // 遍历结果集 + + v.add(resultSet.getString("name")); // 将供应商名称添加到列表中 } - } catch (SQLException e) { + } catch (SQLException e) { // 捕获SQL异常 // TODO Auto-generated catch block - e.printStackTrace(); - }finally{ - JDBCUtil.close(resultSet, pstmt, conn); + e.printStackTrace(); // 打印异常堆栈信息 + }finally{ // 无论是否发生异常,都会执行的代码块 + JDBCUtil.close(resultSet, pstmt, conn); // 关闭结果集、预编译语句和数据库连接 } - - - return v; + + + return v; // 返回存储供应商名称的列表 } + // 根据供应商名称查找其ID的方法 + /** + * 根据给定的供应商名称查找对应的供应商ID。 + * 如果名称为“全部”,返回默认ID(0)。 + * 如果未找到对应的供应商,返回-1作为标志。 + * + * @param name 供应商名称 + * @return 供应商ID或标志 + */ @Override public int findIdSupplierByName(String name) { - int flag = -1; - Connection conn = JDBCUtil.getConn(); - PreparedStatement preparedStatement = null; - ResultSet resultSet= null; - int id=0; + int flag = -1; // 初始化标志为-1 + Connection conn = JDBCUtil.getConn(); // 获取数据库连接 + PreparedStatement preparedStatement = null; // 初始化预编译语句对象 + ResultSet resultSet= null; // 初始化结果集对象 + int id=0; // 初始化供应商ID为0 try { - if(name.equals("全部")) - return id; + if(name.equals("全部")) // 如果供应商名称为“全部” + return id; // 返回默认ID preparedStatement = conn.prepareStatement - ("select * from supplierInf where name=?"); - preparedStatement.setString(1, name); - resultSet=preparedStatement.executeQuery(); - if(resultSet.next()){ - return resultSet.getInt("id"); + ("select * from supplierInf where name=?"); // 准备SQL查询语句 + preparedStatement.setString(1, name); // 设置查询参数 + resultSet=preparedStatement.executeQuery(); // 执行查询 + if(resultSet.next()){ // 如果找到对应记录 + return resultSet.getInt("id"); // 返回供应商ID } - - } catch (SQLException e) { - e.printStackTrace(); - } finally { - JDBCUtil.close(null,preparedStatement, conn); + + } catch (SQLException e) { // 捕获SQL异常 + e.printStackTrace(); // 打印异常堆栈信息 + } finally { // 无论是否发生异常,都会执行的代码块 + JDBCUtil.close(null,preparedStatement, conn); // 关闭预编译语句和数据库连接 } - - return flag; + + return flag; // 返回查询结果标志 } - -} + +} \ No newline at end of file diff --git a/Supermarket/src/com/lingnan/supermarket/dao/impl/inOrderServiceImpl.java b/Supermarket/src/com/lingnan/supermarket/dao/impl/inOrderServiceImpl.java index fd81c3b..620a3f3 100644 --- a/Supermarket/src/com/lingnan/supermarket/dao/impl/inOrderServiceImpl.java +++ b/Supermarket/src/com/lingnan/supermarket/dao/impl/inOrderServiceImpl.java @@ -1,68 +1,62 @@ package com.lingnan.supermarket.dao.impl; -import java.sql.Connection; - -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.sql.Timestamp; -import java.util.Date; -import java.util.Vector; - import com.lingnan.supermarket.dao.inOrderService; import com.lingnan.supermarket.dto.InOrder; -import com.lingnan.supermarket.utils.DateUtil; import com.lingnan.supermarket.utils.JDBCUtil; +import java.sql.*; +import java.util.Vector; + public class inOrderServiceImpl implements inOrderService{ - + @Override - public Vector findAllInOrder (){ - Vector inOrders = new Vector(); - Connection conn = JDBCUtil.getConn(); - PreparedStatement preparedStatement = null; - ResultSet resultSet=null; - + public Vector findAllInOrder() { + Vector inOrders = new Vector(); // 创建一个向量用于存储InOrder对象 + Connection conn = JDBCUtil.getConn(); // 获取数据库连接 + PreparedStatement preparedStatement = null; // 声明预编译语句对象 + ResultSet resultSet = null; // 声明结果集对象 + + // SQL查询语句,选择未删除的订单并按入库日期降序排列 String SQL = "select * from inOrder where delmark=1 order by inDate desc"; - + try { - preparedStatement = conn.prepareStatement(SQL); - resultSet = preparedStatement.executeQuery(); - while(resultSet.next()) { - InOrder inOrder = new InOrder(); + preparedStatement = conn.prepareStatement(SQL); // 准备SQL语句 + resultSet = preparedStatement.executeQuery(); // 执行查询 + while (resultSet.next()) { // 遍历结果集 + InOrder inOrder = new InOrder(); // 创建InOrder对象 + // 从结果集中获取属性并设置到inOrder对象 inOrder.setiNumber(resultSet.getString("iNumber")); inOrder.setAllInPrice(resultSet.getFloat("allInPrice")); inOrder.setInDate(resultSet.getString("inDate")); inOrder.setPrincipal(resultSet.getString("principal")); inOrder.setStatus(resultSet.getInt("status")); inOrder.setDelmark(resultSet.getInt("Delmark")); - inOrders.add(inOrder); + inOrders.add(inOrder); // 将InOrder对象添加到向量中 } - + } catch (SQLException e) { - e.printStackTrace(); + e.printStackTrace(); // 捕获并打印异常堆栈信息 } finally { - JDBCUtil.close(resultSet, preparedStatement, conn); + JDBCUtil.close(resultSet, preparedStatement, conn); // 关闭结果集、预编译语句和数据库连接 } - return inOrders; - + return inOrders; // 返回存储所有InOrder对象的向量 } - - + @Override public InOrder findByIdinOrder(String iNumber) { - - InOrder inOrder = new InOrder(); - Connection conn = JDBCUtil.getConn(); - PreparedStatement preparedStatement = null; - ResultSet resultSet = null; + InOrder inOrder = new InOrder(); // 创建InOrder对象 + Connection conn = JDBCUtil.getConn(); // 获取数据库连接 + PreparedStatement preparedStatement = null; // 声明预编译语句对象 + ResultSet resultSet = null; // 声明结果集对象 try { + // 准备SQL语句,根据订单号查找特定的订单 preparedStatement = conn.prepareStatement("select * from inOrder where iNumber = ?"); - preparedStatement.setString(1, iNumber); - resultSet = preparedStatement.executeQuery(); - if (resultSet.next()) { + preparedStatement.setString(1, iNumber); // 设置订单号参数 + resultSet = preparedStatement.executeQuery(); // 执行查询 + if (resultSet.next()) { // 如果找到对应记录 + // 从结果集中获取属性并设置到inOrder对象 inOrder.setiNumber(resultSet.getString("iNumber")); inOrder.setAllInPrice(resultSet.getFloat("allInPrice")); inOrder.setInDate(resultSet.getString("inDate")); @@ -70,205 +64,204 @@ public class inOrderServiceImpl implements inOrderService{ inOrder.setStatus(resultSet.getInt("status")); } else { return null; // 没有找到该订单或订单不存在,返回null - } + } } catch (SQLException e) { - e.printStackTrace(); + e.printStackTrace(); // 捕获并打印异常堆栈信息 } finally { - JDBCUtil.close(resultSet, preparedStatement, conn); + JDBCUtil.close(resultSet, preparedStatement, conn); // 关闭结果集、预编译语句和数据库连接 } - return inOrder; + return inOrder; // 返回找到的InOrder对象 } - - + @Override public int addInOrder(String iNumber, float allInPrice) { - int flag = 0; - Timestamp inDate = new Timestamp(System.currentTimeMillis()); - //System.out.println(inDate); - Connection conn = JDBCUtil.getConn(); - PreparedStatement preparedStatement = null; - + int flag = 0; // 状态标志,初始化为0 + Timestamp inDate = new Timestamp(System.currentTimeMillis()); // 获取当前时间戳 + Connection conn = JDBCUtil.getConn(); // 获取数据库连接 + PreparedStatement preparedStatement = null; // 声明预编译语句对象 + try { - preparedStatement = conn.prepareStatement - ("insert into inOrder values (?,?,?,?)"); - preparedStatement.setString(1, iNumber); - preparedStatement.setFloat(2, allInPrice); - preparedStatement.setTimestamp(3, inDate); - preparedStatement.setString(4, "a1"); - preparedStatement.executeUpdate(); - flag = 1; + // 准备SQL插入语句 + preparedStatement = conn.prepareStatement("insert into inOrder values (?,?,?,?)"); + preparedStatement.setString(1, iNumber); // 设置订单号参数 + preparedStatement.setFloat(2, allInPrice); // 设置总价格参数 + preparedStatement.setTimestamp(3, inDate); // 设置入库日期 + preparedStatement.setString(4, "a1"); // 设置其他固定参数(例如:默认的负责人ID) + preparedStatement.executeUpdate(); // 执行插入操作 + flag = 1; // 标记插入成功 } catch (SQLException e) { - flag = -1; - e.printStackTrace(); + flag = -1; // 插入失败时标记为-1 + e.printStackTrace(); // 捕获并打印异常堆栈信息 } finally { - JDBCUtil.close(null,preparedStatement, conn); + JDBCUtil.close(null, preparedStatement, conn); // 关闭预编译语句和数据库连接 } - - return flag; - } + return flag; // 返回插入结果标志 + } @Override public int deleteInOrder(String iNumber) { - int flag = 0; - - Connection conn = JDBCUtil.getConn(); - PreparedStatement preparedStatement = null; - + int flag = 0; // 状态标志,初始化为0 + + Connection conn = JDBCUtil.getConn(); // 获取数据库连接 + PreparedStatement preparedStatement = null; // 声明预编译语句对象 + try { - preparedStatement = conn.prepareStatement - ("update inOrder set delmark=0 where iNumber = ?"); - preparedStatement.setString(1, iNumber); - preparedStatement.executeUpdate(); - flag = 1; + // 准备SQL更新语句,将delmark标记为0表示逻辑删除 + preparedStatement = conn.prepareStatement("update inOrder set delmark=0 where iNumber = ?"); + preparedStatement.setString(1, iNumber); // 设置订单号参数 + preparedStatement.executeUpdate(); // 执行更新操作 + flag = 1; // 标记删除成功 } catch (SQLException e) { - flag = -1; - e.printStackTrace(); + flag = -1; // 删除失败时标记为-1 + e.printStackTrace(); // 捕获并打印异常堆栈信息 } finally { - JDBCUtil.close(null,preparedStatement, conn); + JDBCUtil.close(null, preparedStatement, conn); // 关闭预编译语句和数据库连接 } - return flag; + return flag; // 返回删除结果标志 } /*往订单表插入一条记录*/ - public boolean InsertInOrder(String number,Float allPrice,String time,String username,int c){ - boolean flag = false; - Connection conn = JDBCUtil.getConn(); - PreparedStatement pstmt = null; - ResultSet resultSet = null;; + // 插入新的进货订单 + public boolean InsertInOrder(String number, Float allPrice, String time, String username, int c) { + boolean flag = false; // 初始化标志为false + Connection conn = JDBCUtil.getConn(); // 获取数据库连接 + PreparedStatement pstmt = null; // 声明预编译语句对象 + ResultSet resultSet = null; // 声明结果集对象 try { + // 准备SQL插入语句 pstmt = conn.prepareStatement("insert into InOrder values(?,?,?,?,?,?)"); - pstmt.setString(1, number); - pstmt.setFloat(2, allPrice); - pstmt.setString(3, time); - pstmt.setString(4, username); - pstmt.setInt(5, 2); - pstmt.setInt(6, 1); - - if(pstmt.execute()) - flag = true; - - - - } catch (SQLException e) { - e.printStackTrace(); - }finally { + pstmt.setString(1, number); // 设置订单号 + pstmt.setFloat(2, allPrice); // 设置总价格 + pstmt.setString(3, time); // 设置入库时间 + pstmt.setString(4, username); // 设置负责人用户名 + pstmt.setInt(5, 2); // 设置状态,假设2代表某个特定状态 + pstmt.setInt(6, 1); // 设置删除标记,假设1表示未删除 + + // 执行插入操作 + if (pstmt.execute()) + flag = true; // 如果成功执行插入,设置标志为true - JDBCUtil.close(resultSet, pstmt, conn); + } catch (SQLException e) { + e.printStackTrace(); // 捕获并打印异常堆栈信息 + } finally { + JDBCUtil.close(resultSet, pstmt, conn); // 关闭结果集、预编译语句和数据库连接 } - return flag; + return flag; // 返回插入结果标志 } - /*更新状态*/ - public boolean updateInOrderStatus(String iNumber,int status) { - boolean flag = false; - Connection conn = JDBCUtil.getConn(); - PreparedStatement preparedStatement = null; + /* 更新状态 */ + public boolean updateInOrderStatus(String iNumber, int status) { + boolean flag = false; // 初始化标志为false + Connection conn = JDBCUtil.getConn(); // 获取数据库连接 + PreparedStatement preparedStatement = null; // 声明预编译语句对象 try { + // 准备SQL更新语句,更新指定订单号的状态 preparedStatement = conn.prepareStatement("update inOrder set status=? where iNumber=?"); - preparedStatement.setInt(1, status); - preparedStatement.setString(2,iNumber); - if(preparedStatement.executeUpdate()==1) + preparedStatement.setInt(1, status); // 设置状态 + preparedStatement.setString(2, iNumber); // 设置订单号 + // 如果更新操作影响了一行,则设置标志为true + if (preparedStatement.executeUpdate() == 1) flag = true; } catch (SQLException e) { - e.printStackTrace(); + e.printStackTrace(); // 捕获并打印异常堆栈信息 } finally { - JDBCUtil.close(null,preparedStatement, conn); + JDBCUtil.close(null, preparedStatement, conn); // 关闭预编译语句和数据库连接 } - return flag; + return flag; // 返回更新结果标志 } - - //查找所有待入库订单*/待确认 - public Vector findUnconfirmInOrder(){ - Vector inOrders = new Vector(); - Connection conn = JDBCUtil.getConn(); - PreparedStatement preparedStatement = null; - ResultSet resultSet=null; - + + // 查找所有待入库订单(待确认) + public Vector findUnconfirmInOrder() { + Vector inOrders = new Vector(); // 创建一个向量用于存储InOrder对象 + Connection conn = JDBCUtil.getConn(); // 获取数据库连接 + PreparedStatement preparedStatement = null; // 声明预编译语句对象 + ResultSet resultSet = null; // 声明结果集对象 + + // SQL查询语句,选择状态为2并且未删除的订单 String SQL = "select * from inOrder where status=2 and delmark=1"; - + try { - preparedStatement = conn.prepareStatement(SQL); - resultSet = preparedStatement.executeQuery(); - while(resultSet.next()) { - InOrder inOrder = new InOrder(); - inOrder.setiNumber(resultSet.getString("iNumber")); - inOrder.setAllInPrice(resultSet.getFloat("allInPrice")); - inOrder.setInDate(resultSet.getString("inDate")); - inOrder.setPrincipal(resultSet.getString("principal")); - inOrder.setStatus(resultSet.getInt("status")); - inOrder.setDelmark(resultSet.getInt("Delmark")); - inOrders.add(inOrder); + preparedStatement = conn.prepareStatement(SQL); // 准备SQL语句 + resultSet = preparedStatement.executeQuery(); // 执行查询 + while (resultSet.next()) { // 遍历结果集 + InOrder inOrder = new InOrder(); // 创建InOrder对象 + // 从结果集中获取属性并设置到inOrder对象 + inOrder.setiNumber(resultSet.getString("iNumber")); // 设置订单号 + inOrder.setAllInPrice(resultSet.getFloat("allInPrice")); // 设置总价格 + inOrder.setInDate(resultSet.getString("inDate")); // 设置入库日期 + inOrder.setPrincipal(resultSet.getString("principal")); // 设置负责人 + inOrder.setStatus(resultSet.getInt("status")); // 设置订单状态 + inOrder.setDelmark(resultSet.getInt("Delmark")); // 设置删除标记 + inOrders.add(inOrder); // 将InOrder对象添加到向量中 } - + } catch (SQLException e) { - e.printStackTrace(); + e.printStackTrace(); // 捕获并打印异常堆栈信息 } finally { - JDBCUtil.close(resultSet, preparedStatement, conn); + JDBCUtil.close(resultSet, preparedStatement, conn); // 关闭结果集、预编译语句和数据库连接 } - return inOrders; - + return inOrders; // 返回存储待确认订单的向量 } - - //获取今日进货金额 - public Float TodayInPrice(String date) { - InOrder inOrder = new InOrder(); - Connection conn = JDBCUtil.getConn(); - PreparedStatement preparedStatement = null; - ResultSet resultSet = null; - Float allInPrice=(float) 0; + // 获取今日进货金额 + public Float TodayInPrice(String date) { + InOrder inOrder = new InOrder(); // 创建InOrder对象 + Connection conn = JDBCUtil.getConn(); // 获取数据库连接 + PreparedStatement preparedStatement = null; // 声明预编译语句对象 + ResultSet resultSet = null; // 声明结果集对象 + Float allInPrice = (float) 0; // 初始化总进货金额为0 try { + // 准备SQL查询语句,计算指定日期的进货金额总和 preparedStatement = conn.prepareStatement("select sum(allInPrice) from inOrder where inDate>=? and inDate<=date_add(?,interval 1 day)"); - preparedStatement.setString(1, date); - preparedStatement.setString(2, date); - resultSet = preparedStatement.executeQuery(); - if (resultSet.next()) { - allInPrice=resultSet.getFloat("sum(allInPrice)"); - } + preparedStatement.setString(1, date); // 设置起始日期 + preparedStatement.setString(2, date); // 设置结束日期(起始日期+1天) + resultSet = preparedStatement.executeQuery(); // 执行查询 + if (resultSet.next()) { // 如果有结果 + allInPrice = resultSet.getFloat("sum(allInPrice)"); // 获取总进货金额 + } } catch (SQLException e) { - e.printStackTrace(); + e.printStackTrace(); // 捕获并打印异常堆栈信息 } finally { - JDBCUtil.close(resultSet, preparedStatement, conn); + JDBCUtil.close(resultSet, preparedStatement, conn); // 关闭结果集、预编译语句和数据库连接 } - return allInPrice; + return allInPrice; // 返回总进货金额 } - //查找指定状态订单 - public Vector FindStatus(int status){ - Vector inOrders = new Vector(); - Connection conn = JDBCUtil.getConn(); - PreparedStatement preparedStatement = null; - ResultSet resultSet=null; - - - - try { + // 查找指定状态订单 + public Vector FindStatus(int status) { + Vector inOrders = new Vector(); // 创建一个向量用于存储InOrder对象 + Connection conn = JDBCUtil.getConn(); // 获取数据库连接 + PreparedStatement preparedStatement = null; // 声明预编译语句对象 + ResultSet resultSet = null; // 声明结果集对象 + + try { + // 准备SQL查询语句,根据状态查找订单 preparedStatement = conn.prepareStatement("select * from inOrder where status=? and delmark=1 order by inDate desc"); - preparedStatement.setInt(1, status); - resultSet = preparedStatement.executeQuery(); - while(resultSet.next()) { - InOrder inOrder = new InOrder(); - inOrder.setiNumber(resultSet.getString("iNumber")); - inOrder.setAllInPrice(resultSet.getFloat("allInPrice")); - inOrder.setInDate(resultSet.getString("inDate")); - inOrder.setPrincipal(resultSet.getString("principal")); - inOrder.setStatus(resultSet.getInt("status")); - inOrder.setDelmark(resultSet.getInt("Delmark")); - inOrders.add(inOrder); + preparedStatement.setInt(1, status); // 设置状态参数 + resultSet = preparedStatement.executeQuery(); // 执行查询 + while (resultSet.next()) { // 遍历结果集 + InOrder inOrder = new InOrder(); // 创建InOrder对象 + // 从结果集中获取属性并设置到inOrder对象 + inOrder.setiNumber(resultSet.getString("iNumber")); // 设置订单号 + inOrder.setAllInPrice(resultSet.getFloat("allInPrice")); // 设置总价格 + inOrder.setInDate(resultSet.getString("inDate")); // 设置入库日期 + inOrder.setPrincipal(resultSet.getString("principal")); // 设置负责人 + inOrder.setStatus(resultSet.getInt("status")); // 设置订单状态 + inOrder.setDelmark(resultSet.getInt("Delmark")); // 设置删除标记 + inOrders.add(inOrder); // 将InOrder对象添加到向量中 } - + } catch (SQLException e) { - e.printStackTrace(); + e.printStackTrace(); // 捕获并打印异常堆栈信息 } finally { - JDBCUtil.close(resultSet, preparedStatement, conn); + JDBCUtil.close(resultSet, preparedStatement, conn); // 关闭结果集、预编译语句和数据库连接 } - return inOrders; - + return inOrders; // 返回指定状态的订单向量 } } diff --git a/Supermarket/src/com/lingnan/supermarket/dao/impl/inRecordServiceImpl.java b/Supermarket/src/com/lingnan/supermarket/dao/impl/inRecordServiceImpl.java index bf5f585..9964df6 100644 --- a/Supermarket/src/com/lingnan/supermarket/dao/impl/inRecordServiceImpl.java +++ b/Supermarket/src/com/lingnan/supermarket/dao/impl/inRecordServiceImpl.java @@ -1,152 +1,174 @@ package com.lingnan.supermarket.dao.impl; +import com.lingnan.supermarket.dao.inRecordService; +import com.lingnan.supermarket.dto.InRecord; +import com.lingnan.supermarket.dto.Production; +import com.lingnan.supermarket.utils.JDBCUtil; + import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; -import java.sql.Timestamp; import java.util.Vector; - -import com.lingnan.supermarket.dao.inRecordService; -import com.lingnan.supermarket.dto.InOrder; -import com.lingnan.supermarket.dto.InRecord; -import com.lingnan.supermarket.dto.Production; -import com.lingnan.supermarket.dto.User; -import com.lingnan.supermarket.utils.JDBCUtil; +/** + * 进货记录服务实现类 + * @cwf2210461197 2024/12/2 + * @version 1.0 + */ public class inRecordServiceImpl implements inRecordService{ - + /** + * 查询所有进货记录的方法 + * @return 包含所有进货记录的向量 + */ @Override public Vector findAllinRecord() { - Vector inRecords = new Vector(); - Connection conn = JDBCUtil.getConn(); - PreparedStatement preparedStatement = null; - ResultSet resultSet=null; - - String SQL = "select * from inRecord"; - + Vector inRecords = new Vector(); // 创建一个向量用于存储进货记录 + Connection conn = JDBCUtil.getConn(); // 获取数据库连接 + PreparedStatement preparedStatement = null; // 初始化预编译语句对象 + ResultSet resultSet=null; // 初始化结果集对象 + + String SQL = "select * from inRecord"; // SQL查询语句,选择所有进货记录 + try { - preparedStatement = conn.prepareStatement(SQL); - resultSet = preparedStatement.executeQuery(); - while(resultSet.next()) { - InRecord inRecord = new InRecord(); - inRecord.setiNumber(resultSet.getString("iNumber")); - inRecord.setSum(resultSet.getInt("sum")); - inRecord.setInPrice(resultSet.getFloat("inPrice")); - inRecords.add(inRecord); + preparedStatement = conn.prepareStatement(SQL); // 准备SQL语句 + resultSet = preparedStatement.executeQuery(); // 执行查询 + while(resultSet.next()) { // 遍历结果集 + InRecord inRecord = new InRecord(); // 创建一个新的进货记录对象 + inRecord.setiNumber(resultSet.getString("iNumber")); // 设置进货单号 + inRecord.setSum(resultSet.getInt("sum")); // 设置进货数量 + inRecord.setInPrice(resultSet.getFloat("inPrice")); // 设置进货价格 + inRecords.add(inRecord); // 将进货记录对象添加到向量中 } - - } catch (SQLException e) { - e.printStackTrace(); - } finally { - JDBCUtil.close(resultSet, preparedStatement, conn); + + } catch (SQLException e) { // 捕获SQL异常 + e.printStackTrace(); // 打印异常堆栈信息 + } finally { // 无论是否发生异常,都会执行的代码块 + JDBCUtil.close(resultSet, preparedStatement, conn); // 关闭结果集、预编译语句和数据库连接 } - return inRecords; + return inRecords; // 返回存储所有进货记录的向量 } - @Override + + /** + * 根据进货单号查询进货记录 + * + * @param iNumber 进货单号 + * @return 包含符合条件的进货记录的向量 + */ +@Override public Vector findByIdinRecord(String iNumber) { - InRecord inRecord; - Vector v = new Vector(); - Connection conn = JDBCUtil.getConn(); - PreparedStatement preparedStatement = null; - ResultSet resultSet = null; + InRecord inRecord; // 声明一个进货记录对象 + Vector v = new Vector(); // 创建一个向量用于存储进货记录 + Connection conn = JDBCUtil.getConn(); // 获取数据库连接 + PreparedStatement preparedStatement = null; // 初始化预编译语句对象 + ResultSet resultSet = null; // 初始化结果集对象 try { - preparedStatement = conn.prepareStatement("select * from inRecord where iNumber = ?"); - preparedStatement.setString(1, iNumber); - resultSet = preparedStatement.executeQuery(); - while(resultSet.next()) { - inRecord = new InRecord(); - inRecord.setiNumber(resultSet.getString("iNumber")); - inRecord.setId(resultSet.getString("id")); - inRecord.setSum(resultSet.getInt("sum")); - inRecord.setInPrice(resultSet.getFloat("Price")); - v.add(inRecord); - } - - } catch (SQLException e) { - e.printStackTrace(); - } finally { - JDBCUtil.close(resultSet, preparedStatement, conn); + preparedStatement = conn.prepareStatement("select * from inRecord where iNumber = ?"); // 准备SQL查询语句 + preparedStatement.setString(1, iNumber); // 设置查询参数 + resultSet = preparedStatement.executeQuery(); // 执行查询 + while(resultSet.next()) { // 遍历结果集 + inRecord = new InRecord(); // 创建一个新的进货记录对象 + inRecord.setiNumber(resultSet.getString("iNumber")); // 设置进货单号 + inRecord.setId(resultSet.getString("id")); // 设置商品ID + inRecord.setSum(resultSet.getInt("sum")); // 设置进货数量 + inRecord.setInPrice(resultSet.getFloat("Price")); // 设置进货价格 + v.add(inRecord); // 将进货记录对象添加到向量中 + } + + } catch (SQLException e) { // 捕获SQL异常 + e.printStackTrace(); // 打印异常堆栈信息 + } finally { // 无论是否发生异常,都会执行的代码块 + JDBCUtil.close(resultSet, preparedStatement, conn); // 关闭结果集、预编译语句和数据库连接 } - return v; + return v; // 返回存储进货记录的向量 } + @Override - public int addinRecord(InRecord ir) { - int flag = 0; - - String iNumber = ir.getiNumber(); - int sum = ir.getSum(); - Float inPrice = ir.getInPrice(); - - Connection conn = JDBCUtil.getConn(); - PreparedStatement preparedStatement = null; - + // 该方法用于将进货记录添加到数据库中。 +// 参数 ir 是一个包含进货信息的对象。 +// 返回值 flag 表示插入的结果,1表示成功,-1表示失败。 +public int addinRecord(InRecord ir) { + int flag = 0; // 初始化标志为0 + + String iNumber = ir.getiNumber(); // 获取进货单号 + int sum = ir.getSum(); // 获取进货数量 + Float inPrice = ir.getInPrice(); // 获取进货价格 + + Connection conn = JDBCUtil.getConn(); // 获取数据库连接 + PreparedStatement preparedStatement = null; // 初始化预编译语句对象 + try { preparedStatement = conn.prepareStatement - ("insert into inRecord values (?,?,?)"); - preparedStatement.setString(1, iNumber); - preparedStatement.setInt(2, sum); - preparedStatement.setFloat(3, inPrice); - preparedStatement.executeUpdate(); - flag = 1; - } catch (SQLException e) { - flag = -1; - e.printStackTrace(); - } finally { - JDBCUtil.close(null,preparedStatement, conn); + ("insert into inRecord values (?,?,?)"); // 准备SQL插入语句 + preparedStatement.setString(1, iNumber); // 设置进货单号 + preparedStatement.setInt(2, sum); // 设置进货数量 + preparedStatement.setFloat(3, inPrice); // 设置进货价格 + preparedStatement.executeUpdate(); // 执行插入操作 + flag = 1; // 设置标志为1,表示插入成功 + } catch (SQLException e) { // 捕获SQL异常 + flag = -1; // 设置标志为-1,表示插入失败 + e.printStackTrace(); // 打印异常堆栈信息 + } finally { // 无论是否发生异常,都会执行的代码块 + JDBCUtil.close(null,preparedStatement, conn); // 关闭预编译语句和数据库连接 } - - return flag; + + return flag; // 返回插入结果标志 } - @Override + + // 删除进货记录方法,根据进货单号进行删除操作 +@Override public int deleteinRecord(String iNumber) { - int flag = 0; - - Connection conn = JDBCUtil.getConn(); - PreparedStatement preparedStatement = null; - + int flag = 0; // 初始化标志为0 + + Connection conn = JDBCUtil.getConn(); // 获取数据库连接 + PreparedStatement preparedStatement = null; // 初始化预编译语句对象 + try { preparedStatement = conn.prepareStatement - ("delete from inRecord where iNumber = ?"); - preparedStatement.setString(1, iNumber); - preparedStatement.executeUpdate(); - flag = 1; - } catch (SQLException e) { - flag = -1; - e.printStackTrace(); - } finally { - JDBCUtil.close(null,preparedStatement, conn); + ("delete from inRecord where iNumber = ?"); // 准备SQL删除语句 + preparedStatement.setString(1, iNumber); // 设置进货单号 + preparedStatement.executeUpdate(); // 执行删除操作 + flag = 1; // 设置标志为1,表示删除成功 + } catch (SQLException e) { // 捕获SQL异常 + flag = -1; // 设置标志为-1,表示删除失败 + e.printStackTrace(); // 打印异常堆栈信息 + } finally { // 无论是否发生异常,都会执行的代码块 + JDBCUtil.close(null,preparedStatement, conn); // 关闭预编译语句和数据库连接 } - return flag; + return flag; // 返回删除结果标志 } - public boolean insertInRecord(String iNumber,Production p) { - boolean flag = false; - Connection conn = JDBCUtil.getConn(); - PreparedStatement preparedStatement = null; - + /** + * 将进货记录插入到数据库中 + * + * @param iNumber 进货单号 + * @param p 进货的商品对象 + * @return 成功插入返回true,失败返回false + */ +public boolean insertInRecord(String iNumber,Production p) { + boolean flag = false; // 初始化标志为false + Connection conn = JDBCUtil.getConn(); // 获取数据库连接 + PreparedStatement preparedStatement = null; // 初始化预编译语句对象 + try { - preparedStatement = conn.prepareStatement("insert into inRecord values(?,?,?,?)"); - preparedStatement.setString(1, iNumber); - preparedStatement.setString(2, p.getId()); - preparedStatement.setInt(3,p.getSum()); - preparedStatement.setFloat(4, p.getPrice()); - - if(preparedStatement.executeUpdate()==1) - flag = true; - } catch (SQLException e) { - e.printStackTrace(); - } finally { - JDBCUtil.close(null,preparedStatement, conn); + preparedStatement = conn.prepareStatement("insert into inRecord values(?,?,?,?)"); // 准备SQL插入语句 + preparedStatement.setString(1, iNumber); // 设置进货单号 + preparedStatement.setString(2, p.getId()); // 设置商品ID + preparedStatement.setInt(3,p.getSum()); // 设置进货数量 + preparedStatement.setFloat(4, p.getPrice()); // 设置进货价格 + + if(preparedStatement.executeUpdate()==1) // 执行插入操作 + flag = true; // 如果成功执行插入,设置标志为true + } catch (SQLException e) { // 捕获SQL异常 + e.printStackTrace(); // 打印异常堆栈信息 + } finally { // 无论是否发生异常,都会执行的代码块 + JDBCUtil.close(null,preparedStatement, conn); // 关闭预编译语句和数据库连接 } - return flag; + return flag; // 返回插入结果标志 } - - - -} +} \ No newline at end of file diff --git a/Supermarket/src/com/lingnan/supermarket/dialog/UserInfDialog.java b/Supermarket/src/com/lingnan/supermarket/dialog/UserInfDialog.java index 7fa02c7..a4a7721 100644 --- a/Supermarket/src/com/lingnan/supermarket/dialog/UserInfDialog.java +++ b/Supermarket/src/com/lingnan/supermarket/dialog/UserInfDialog.java @@ -1,4 +1,3 @@ - package com.lingnan.supermarket.dialog; import java.awt.Container; @@ -26,54 +25,74 @@ import com.lingnan.supermarket.view.LoginView; // UserInfDialog类继承自JDialog,用于创建一个修改用户信息的对话框窗口,并实现了ActionListener接口来处理按钮点击事件 public class UserInfDialog extends JDialog implements ActionListener { - // 以下是用于构建对话框界面的各个面板、标签、文本框和按钮等组件的声明 + // 构建对话框界面的各个面板、标签、文本框和按钮等组件的声明 private JPanel namePanel, loginNamePanel, phonePanel, opePanel, passwordPanel, sSuperPanel; + // 用于存放姓名相关组件的面板 private JLabel nameLabel, loginNameLabel, phoneLabel, passwordLabel, sSuperLabel; + // 分别对应姓名、登录名、联系电话、密码、权限等信息的标签组件,用于在界面上显示相应的文字提示 private JTextField nameTF, loginNameTF, phoneTF, passwordTF, sSuperTF; + // 分别对应姓名、登录名、联系电话、密码、权限等信息的文本框组件,用于用户输入或显示相应信息 private JButton saveBtn, cancelBtn; + // 保存按钮和取消按钮,用于触发保存修改信息或取消操作的动作 // 用户服务接口的实现类实例,用于调用与用户相关的数据库操作方法 private UserService userService = new UserServiceImpl(); + // 创建UserServiceImpl类的实例,通过该实例可以调用具体实现的用户相关数据库操作,比如更新用户信息等 // 要修改信息的用户对象 private User user; + // 存储当前要在对话框中进行信息修改操作的用户对象,包含了该用户原本的各种信息 // 用于存储用户权限级别,初始值为从传入的用户对象中获取的权限级别 private int sSuper = -1; + // 记录用户的权限级别,初始化为 -1,后续会根据传入用户对象的权限情况进行赋值 - // 下拉框组件,用于选择用户权限(这里部分代码被注释掉,可能原本有完整的权限选择功能,后简化了) + // 下拉框组件,用于选择用户权限 private JComboBox combo; + // 定义一个下拉框组件,用于展示可选的用户权限选项,其选项内容为字符串类型 + // 下拉框中的选项内容,包括当前权限以及不同的权限角色 - private String[] identity = { "当前权限", "收银员", "管理员", "超级管理员" }; + private String[] identity = { "当前权限", "收银员", "管理员", "超级管理员","进货员" }; + // 定义一个字符串数组,存储下拉框中可供选择的用户权限选项内容 // 父窗口JFrame的引用,可能用于在某些操作后对父窗口进行处理 private JFrame JFrame; + // 保存传入的父窗口(JFrame类型)的引用 // 构造函数,用于创建修改用户信息的对话框,传入父窗口JFrame和要修改信息的用户对象 public UserInfDialog(JFrame parent, User user) { - // 调用父类JDialog的构造函数,设置对话框的标题为"添加"(这里标题可能需要根据实际情况修改为更合适的,比如"修改用户信息") + // 调用父类JDialog的构造函数,设置对话框的标题为"添加" super(parent, "添加"); this.user = user; + // 将传入的要修改信息的用户对象赋值给当前类的成员变量user + // 设置当前用户的权限级别 this.sSuper = user.getUsuper(); + // 从传入的用户对象中获取其原本的权限级别,并赋值给当前类的成员变量sSuper // 设置对话框的大小 setSize(350, 300); + // 设置对话框的宽度为350像素,高度为300像素,确定对话框在屏幕上显示的初始大小 // 设置对话框在屏幕中央显示 setLocationRelativeTo(null); + // 通过传入null参数,使对话框在屏幕的中心位置显示 // 设置对话框为模态对话框,即显示时会阻塞其他窗口的操作 setModal(true); + // 模态对话框会强制用户在关闭它之前只能与该对话框进行交互,不能操作其他窗口 // 设置对话框大小不可调整 setResizable(false); + // 禁止用户通过拖动边框等方式改变对话框的大小,保持固定的布局和显示效果 // 设置对话框的布局为流式布局 this.setLayout(new FlowLayout()); + // 使用流式布局来排列对话框内的组件,组件会按照添加的顺序从左到右、从上到下依次排列 // 保存父窗口的引用 this.JFrame = parent; + // 将传入的父窗口引用赋值给当前类的成员变量JFrame // 初始化对话框的视图组件 initView(); @@ -84,34 +103,53 @@ public class UserInfDialog extends JDialog implements ActionListener { // 姓名面板及相关组件的初始化,文本框中显示当前用户的姓名信息 namePanel = new JPanel(); + // 创建一个新的面板,用于存放姓名相关的标签和文本框组件 nameLabel = new JLabel("姓名"); + // 创建一个显示"姓名"文字的标签组件 nameTF = new JTextField(user.getRname(), 15); + // 创建一个文本框组件,初始内容设置为传入用户对象的真实姓名(通过user.getRname()获取),文本框宽度设置为可显示15个字符左右 namePanel.add(nameLabel); + // 将姓名标签添加到姓名面板中 namePanel.add(nameTF); + // 将姓名文本框添加到姓名面板中 // 账号面板及相关组件的初始化,文本框中显示当前用户的账号信息 loginNamePanel = new JPanel(); + // 创建一个新的面板,用于存放账号相关的标签和文本框组件 loginNameLabel = new JLabel("账号"); + // 创建一个显示"账号"文字的标签组件 loginNameTF = new JTextField(user.getUsername(), 15); + // 创建一个文本框组件,初始内容设置为传入用户对象的用户名(通过user.getUsername()获取),文本框宽度设置为可显示15个字符左右 loginNamePanel.add(loginNameLabel); + // 将账号标签添加到账号面板中 loginNamePanel.add(loginNameTF); + // 将账号文本框添加到账号面板中 // 手机面板及相关组件的初始化,文本框中显示当前用户的手机信息 phonePanel = new JPanel(); - phoneLabel = new JLabel("联系"); + // 创建一个新的面板,用于存放手机相关的标签和文本框组件 + phoneLabel = new JLabel("电话"); + // 创建一个显示"联系"文字的标签组件 phoneTF = new JTextField(user.getPhone(), 15); + // 创建一个文本框组件,初始内容设置为传入用户对象的手机号码(通过user.getPhone()获取),文本框宽度设置为可显示15个字符左右 phonePanel.add(phoneLabel); + // 将手机标签添加到手机面板中 phonePanel.add(phoneTF); + // 将手机文本框添加到手机面板中 // 密码面板及相关组件的初始化,文本框中显示当前用户的密码信息 passwordPanel = new JPanel(); + // 创建一个新的面板,用于存放密码相关的标签和文本框组件 passwordLabel = new JLabel("密码"); + // 创建一个显示"密码"文字的标签组件 passwordTF = new JTextField(user.getPassword(), 15); + // 创建一个文本框组件,初始内容设置为传入用户对象的密码(通过user.getPassword()获取),文本框宽度设置为可显示15个字符左右 passwordPanel.add(passwordLabel); + // 将密码标签添加到密码面板中 passwordPanel.add(passwordTF); + // 将密码文本框添加到密码面板中 + - // 权限面板及相关组件的初始化,这里部分代码被注释掉,可能原本有完整的权限选择功能,后简化了 - /* sSuperPanel = new JPanel(); sSuperLabel = new JLabel("权限"); // sSuperTF = new JTextField(15); @@ -119,26 +157,40 @@ public class UserInfDialog extends JDialog implements ActionListener { combo.addItemListener(new MyItemListener()); sSuperPanel.add(sSuperLabel); sSuperPanel.add(combo); - */ + + // 上述被注释掉的代码原本用于创建权限相关的面板、标签、下拉框组件,并为下拉框添加选项改变的监听器,用于实现完整的权限选择功能,但目前处于简化状态 // 操作按钮面板及相关组件的初始化 opePanel = new JPanel(); + // 创建一个新的面板,用于存放操作按钮(保存和取消按钮) saveBtn = new JButton("保存"); + // 创建一个显示"保存"文字的按钮组件,用于触发保存用户信息修改的操作 cancelBtn = new JButton("取消"); + // 创建一个显示"取消"文字的按钮组件,用于触发取消当前修改操作的动作 // 为保存按钮和取消按钮添加点击事件监听器 saveBtn.addActionListener(this); + // 将保存按钮的点击事件绑定到当前类(实现了ActionListener接口)的actionPerformed方法上,以便处理保存按钮被点击后的操作逻辑 cancelBtn.addActionListener(this); + // 将取消按钮的点击事件绑定到当前类(实现了ActionListener接口)的actionPerformed方法上,以便处理取消按钮被点击后的操作逻辑 opePanel.add(saveBtn); + // 将保存按钮添加到操作按钮面板中 opePanel.add(cancelBtn); + // 将取消按钮添加到操作按钮面板中 // 将各个面板添加到对话框的内容面板中 Container container = getContentPane(); + // 获取对话框的内容面板,用于添加其他组件面板 container.add(namePanel); + // 将姓名面板添加到对话框的内容面板中 container.add(loginNamePanel); + // 将账号面板添加到对话框的内容面板中 container.add(passwordPanel); + // 将密码面板添加到对话框的内容面板中 container.add(phonePanel); - /*container.add(sSuperPanel);*/ + container.add(sSuperPanel); + // 原本可能添加权限面板 container.add(opePanel); + // 将操作按钮面板添加到对话框的内容面板中 } // 处理按钮点击事件的方法,实现了ActionListener接口中的方法 @@ -151,60 +203,85 @@ public class UserInfDialog extends JDialog implements ActionListener { // 获取用户在文本框中修改后的姓名、账号、手机和密码信息 String name = nameTF.getText(); + // 获取姓名文本框中用户输入或修改后的姓名内容 String loginName = loginNameTF.getText(); + // 获取账号文本框中用户输入或修改后的账号内容 String phone = phoneTF.getText(); + // 获取手机文本框中用户输入或修改后的手机号码内容 String password = passwordTF.getText(); + // 获取密码文本框中用户输入或修改后的密码内容 - // TODO 参数校验部分,这里应该对获取到的用户输入信息进行合法性校验,比如非空、格式等校验,但目前未实现具体逻辑 + // 此处注释提示了后续应该添加对获取到的用户输入信息进行合法性校验的代码 // 创建一个新的User对象,用于存储要更新到数据库的用户信息,设置了部分从原用户对象获取的信息以及修改后的信息 User user1 = new User(); user1.setId(user.getId()); + // 设置新用户对象的id为原用户对象的id,确保更新的是正确的用户记录 user1.setRname(name); + // 设置新用户对象的真实姓名为获取到的修改后的姓名内容 user1.setUsername(loginName); + // 设置新用户对象的用户名(账号)为获取到的修改后的账号内容 user1.setPhone(phone); + // 设置新用户对象的手机号码为获取到的修改后的手机号码内容 user1.setPassword(password); + // 设置新用户对象的密码为获取到的修改后的密码内容 user1.setImg(user.getImg()); + // 设置新用户对象的图片相关信息(这里不太明确具体用途,可能是用户头像之类的图片信息)为原用户对象的对应信息 user1.setUsuper(sSuper); + // 设置新用户对象的权限级别为当前记录的权限级别(在构造函数或其他地方已确定) // 调用用户服务接口的根据用户id更新用户信息的方法,将更新后的用户信息保存到数据库中,并获取返回结果 int result = userService.updateByIdUser(user1); if (result == 1) { // 如果更新成功,关闭当前对话框 this.dispose(); + // 通过调用dispose方法关闭当前的对话框窗口,释放相关资源 + // 弹出提示框显示修改成功信息,并提示重新登录 JOptionPane.showMessageDialog(this, "修改成功,请重新登陆", "提示", JOptionPane.INFORMATION_MESSAGE); + // 使用JOptionPane弹出一个信息提示框,向用户显示修改成功的消息,并提示需要重新登录,提示框的图标为信息图标(INFORMATION_MESSAGE表示) + // 关闭父窗口 this.JFrame.dispose(); + // 通过调用父窗口的dispose方法关闭父窗口 + // 创建并显示新的登录视图 new LoginView(); + // 创建一个新的登录视图(LoginView类的实例)并显示出来,方便用户重新登录系统 } else { // 如果更新失败,弹出提示框显示修改失败信息 JOptionPane.showMessageDialog(this, "修改失败", "提示", JOptionPane.ERROR_MESSAGE); + // 使用JOptionPane弹出一个错误提示框,向用户显示修改失败的消息 } } else if (source == cancelBtn) { // 如果点击的是取消按钮,直接关闭当前对话框 this.dispose(); + // 通过调用dispose方法关闭当前对话框,放弃本次修改操作,释放相关资源 } } - // 内部类,实现了ItemListener接口,用于监听下拉框选项变化事件(这里部分代码被注释掉,可能原本有完整的权限选择功能,后简化了) + // 实现了ItemListener接口,用于监听下拉框选项变化事件 public class MyItemListener implements ItemListener { @Override public void itemStateChanged(ItemEvent e) { // 获取触发事件的下拉框组件 JComboBox cb = (JComboBox) e.getSource(); + // 从事件源中获取触发选项改变事件的下拉框对象 + // 获取当前选中的下拉框选项内容 String sSuper1 = (String) cb.getSelectedItem(); + // 获取下拉框当前选中的选项对应的字符串内容 + if (sSuper1.equals("当前权限")) sSuper = user.getUsuper(); else if (sSuper1.equals("收银员")) sSuper = 2; - else if (sSuper1.equals("管理员")): - sSuper = 1; - else - sSuper = 0; + else if (sSuper1.equals("管理员")) + sSuper = 1; + else + sSuper = 0; + // 根据下拉框选中的不同选项内容,来设置当前用户的权限级别,不同的数字0、1、2对应不同的权限 } } } \ No newline at end of file diff --git a/Supermarket/src/com/lingnan/supermarket/view/Demo4.java b/Supermarket/src/com/lingnan/supermarket/view/Demo4.java index a9d35fb..b7d015c 100644 --- a/Supermarket/src/com/lingnan/supermarket/view/Demo4.java +++ b/Supermarket/src/com/lingnan/supermarket/view/Demo4.java @@ -1,82 +1,94 @@ package com.lingnan.supermarket.view; -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 Demo4 extends JFrame implements ActionListener -{ - static Demo4 tplb=new Demo4(); - static JLabel pan=new JLabel(); - - static ImageIcon[] imgs = { - new ImageIcon("s"), - 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"), - }; - - public static void settplb()/*�ܿ��*/ - { + +// Demo4类用于创建一个展示图片切换效果的图形界面程序 +public class Demo4 extends JFrame implements ActionListener { + + // 创建一个静态的Demo4类的实例tplb,用于在静态方法中方便地访问该类的相关属性和方法,实现类似单例模式的效果 + static Demo4 tplb = new Demo4(); + + // 创建一个静态的JLabel组件pan,用于在界面上显示图片等内容,作为图片展示的载体 + static JLabel pan = new JLabel(); + + // 创建一个静态的ImageIcon数组imgs,用于存储多个图片资源 + static ImageIcon[] imgs = { + new ImageIcon("s"), + 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"), + }; + + // settplb方法用于设置JFrame的一些基本属性,使其成为一个合适的图形界面窗口展示出来 + public static void settplb() { + // 设置窗口的标题 tplb.setTitle("ͼƬ�ֲ�����"); + // 设置窗口的布局管理器为null,意味着后续添加组件时需要手动指定组件的位置和大小(绝对布局) tplb.setLayout(null); - tplb.setSize(700,800); + // 设置窗口的大小为宽度700像素,高度800像素 + tplb.setSize(700, 800); + // 设置窗口大小不可调整,用户不能通过拖动边框等方式改变窗口大小 tplb.setResizable(false); - tplb.setLocationRelativeTo(null);/*���þ���*/ - tplb.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);/*�رճ���*/ + // 设置窗口在屏幕上居中显示,使窗口展示位置更美观合理 + tplb.setLocationRelativeTo(null); + // 设置当窗口关闭时,整个应用程序随之退出,这是一种常见的关闭窗口行为设置 + tplb.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + // 设置窗口可见,使其显示在屏幕上,否则窗口创建后是不可见的状态 tplb.setVisible(true); } + // setpan方法用于设置JLabel组件的位置等属性,并添加到窗口中,同时启动一个定时器来实现图片的定时切换功能 + public static void setpan() { + // 设置JLabel组件pan的位置和大小,x坐标为50像素,y坐标为50像素,宽度和高度都为500像素,确定其在窗口中的显示区域 + pan.setBounds(50, 50, 500, 500); + // 将pan这个JLabel组件添加到tplb这个窗口实例中,使其成为窗口内容的一部分 + tplb.add(pan); + // 创建一个定时器对象timer,设置每隔1秒触发一次事件,并且指定事件监听器为L + Timer timer = new Timer(1000, L); + // 启动定时器,开始计时,一旦达到设定的时间间隔就会切换图片 + timer.start(); + } + + // 定义一个实现了ActionListener接口的匿名内部类L,用于处理定时器触发的事件,实现图片在JLabel组件上的切换效果 + static ActionListener L = new ActionListener() { + int index; // 定义一个整型变量index,用于记录当前要显示的图片在imgs数组中的索引位置 - 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) - { + public void actionPerformed(ActionEvent e) { + // 将pan这个JLabel组件的图标设置为imgs数组中当前索引对应的图片,实现图片的切换展示效果 pan.setIcon(imgs[index]); + // 将索引值加1,准备切换到下一张图片 index++; - if(index==7) - index=0; + // 如果索引值达到了imgs数组的长度7,表示已经到最后一张图片了,将索引重置为0,实现循环切换图片的效果 + if (index == 7) + index = 0; } }; - - - - - public static void main(String[] args) { - settplb(); - setpan(); - } + + // 调用设置窗口和图片展示相关的方法来展示图形界面效果 + public static void main(String[] args) { + // 调用settplb方法,设置窗口的基本属性并使其显示出来 + settplb(); + // 调用setpan方法,设置图片展示的JLabel组件相关属性并启动图片切换的定时器功能 + setpan(); + } @Override public void actionPerformed(ActionEvent e) { // TODO �Զ����ɵķ������ - } - - - -} +} \ No newline at end of file diff --git a/Supermarket/src/com/lingnan/supermarket/view/HomeView.java b/Supermarket/src/com/lingnan/supermarket/view/HomeView.java index d98388d..0c3b1f1 100644 --- a/Supermarket/src/com/lingnan/supermarket/view/HomeView.java +++ b/Supermarket/src/com/lingnan/supermarket/view/HomeView.java @@ -1,13 +1,12 @@ package com.lingnan.supermarket.view; -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.imageio.ImageIO; -import javax.swing. *; - +import javax.swing.*; import com.lingnan.supermarket.componet.BGPanel; import com.lingnan.supermarket.dao.impl.inOrderServiceImpl; import com.lingnan.supermarket.dao.impl.outOrderServiceImpl; @@ -16,161 +15,221 @@ import com.lingnan.supermarket.table.UserTableModel; import com.lingnan.supermarket.utils.FontUtil; import com.lingnan.supermarket.utils.TimeAndOrder; import com.lingnan.supermarket.view.base.BaseView; - import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.File; import java.io.IOException; import java.util.Scanner; import java.awt.event.*; -public class HomeView extends JPanel implements ActionListener -{ - - private JLabel pan; - -private static JLabel pan1; - -private static JLabel pan2; - -private static JLabel pan3; - - private JFrame jFrame; - - private JPanel tplbPanel; - - private Image bgImage = null; - - private ImageIcon[] imgs; - - private static Float allInPrice; - -private static Float allOutPrice; - - private JButton refreshBtn; - - private JPanel priceJPanel; - - private static String date; - - private static inOrderServiceImpl inOrderImpl ; - private static outOrderServiceImpl outOrderImpl; - - - - public HomeView(JFrame jFrame) { - this.setLayout(null); - this.jFrame = jFrame; - initView(); - - } - - - private void initView() { - - - - pan = new JLabel(); - pan.setBounds(0,0, 1280,351); - - /*tplbPanel.add(pan);*/ - - imgs =new ImageIcon[7]; - for(int i =0;i<7;i++) { - imgs[i]=new ImageIcon("static\\轮播\\0"+i+".jpg"); - } - pan.setIcon(imgs[6]); - Timer timer = new Timer(2500,L); - timer.start(); - this.add(pan); - - date= TimeAndOrder.yMdTime();/*获取今天时间*/ - inOrderImpl = new inOrderServiceImpl(); - outOrderImpl = new outOrderServiceImpl(); - - allInPrice=inOrderImpl.TodayInPrice(date); - allOutPrice=outOrderImpl.TodayOutPrice(date); - System.out.println("今日allInprice="+allInPrice); - System.out.println("今日allOutprice="+allOutPrice); - - pan1 = new JLabel("今日进货总金额:"+allInPrice+"元",new ImageIcon("static\\icon\\money.png"),JLabel.LEFT); - pan2 = new JLabel("今日收银总金额:"+allOutPrice+"元",new ImageIcon("static\\icon\\income.png"),JLabel.LEFT); - pan3 = new JLabel("今日被投诉次数:0次",new ImageIcon("static\\icon\\complaints.png"),JLabel.LEFT); - - pan1.setFont(FontUtil.homeFont); - pan2.setFont(FontUtil.homeFont); - pan3.setFont(FontUtil.homeFont); - - pan1.setBounds(280,300, 600,200); - pan2.setBounds(280,400, 600,200); - pan3.setBounds(280,500, 600,200); - - /* priceJPanel = new JPanel(); - priceJPanel.setBounds(100,200,700,500);*/ - this.add(pan1); - this.add(pan2); - this.add(pan3); - - - - refreshBtn = new JButton(new ImageIcon("static\\icon\\refresh.png")); - refreshBtn.addActionListener(this); - refreshBtn.setBounds(1050,700, 40,40); - this.add(refreshBtn); - - - - - } - ActionListener L=new ActionListener() - { - int index; - @Override - public void actionPerformed(ActionEvent e) - { - pan.setIcon(imgs[index]); - index++; - if(index==7) - index=0; - } - }; - + +// HomeView类用于构建超市管理系统中首页的视图界面,展示如图片轮播、关键业务数据以及提供数据刷新功能 +public class HomeView extends JPanel implements ActionListener { + + // 用于展示图片轮播效果的JLabel组件 + private JLabel pan; + + // 用于显示今日进货总金额相关信息 + private static JLabel pan1; + + // 用于显示今日收银总金额相关信息 + private static JLabel pan2; + + // 用于显示今日被投诉次数相关信息 + private static JLabel pan3; + + private JFrame jFrame; + + private JPanel tplbPanel; + + // 用于存储背景图片的Image对象,初始化为null + private Image bgImage = null; + + // 定义的ImageIcon数组,用于存储多张图片资源,以实现图片轮播功能 + private ImageIcon[] imgs; + + // 静态的Float类型变量,记录今日进货的总金额 + private static Float allInPrice; + + // 静态的Float类型变量,记录今日收银的总金额 + private static Float allOutPrice; + + // 用于触发刷新操作的按钮组件 + private JButton refreshBtn; + + private JPanel priceJPanel; + + // 存储当前日期信息,方便在类内不同方法中按日期查询业务数据 + private static String date; + + // 是实现进货订单相关业务逻辑的服务层接口的类实例,用于获取进货相关数据 + private static inOrderServiceImpl inOrderImpl; + + // 用于实现销售订单相关业务逻辑,获取收银相关数据 + private static outOrderServiceImpl outOrderImpl; + + // 构造函数,用于创建HomeView实例并初始化界面相关组件 + public HomeView(JFrame jFrame) { + this.setLayout(null); //设置布局为null + this.jFrame = jFrame; //保存父窗口引用 + initView(); //调用initView方法初始化组件 + } + + // 初始化视图界面组件的方法,负责创建、配置各组件并设置其属性、添加组件到面板以及为按钮添加事件监听器等操作,构建首页界面展示效果 + private void initView() { + + // 创建一个JLabel组件pan,设置其初始位置和大小,用于后续图片轮播展示 + pan = new JLabel(); + pan.setBounds(0, 0, 1280, 351); + + /*tplbPanel.add(pan);*/ + + // 创建包含7个元素的ImageIcon数组imgs,用于存储图片轮播的图片资源,通过循环从指定路径加载图片文件创建ImageIcon对象 + imgs = new ImageIcon[7]; + for (int i = 0; i < 7; i++) { + imgs[i] = new ImageIcon("static\\轮播\\0" + i + ".jpg"); + } + + // 设置图片轮播起始图片 + pan.setIcon(imgs[6]); + + // 创建一个定时器对象timer,设置时间间隔为2500毫秒(2.5秒),指定事件监听器为L,然后启动定时器实现图片定时轮播 + Timer timer = new Timer(2500, L); + timer.start(); + + // 将pan这个JLabel组件添加到当前面板中,使其能在界面上显示出来参与图片轮播 + this.add(pan); + + // 调用TimeAndOrder工具类的yMdTime方法获取当前日期信息 + date = TimeAndOrder.yMdTime(); + + //用于调用其实现的与进货订单相关业务方法获取数据 + inOrderImpl = new inOrderServiceImpl(); + + // 创建outOrderServiceImpl类的实例,用于调用与销售订单相关业务方法获取销售相关数据,如获取今日收银总金额 + outOrderImpl = new outOrderServiceImpl(); + + // 调用inOrderImpl的TodayInPrice方法,传入当前日期date,获取今日进货的总金额,用于界面显示及其他业务逻辑处理 + allInPrice = inOrderImpl.TodayInPrice(date); + + // 调用outOrderImpl的TodayOutPrice方法,传入date获取今日收银总金额,用于展示销售数据及相关操作 + allOutPrice = outOrderImpl.TodayOutPrice(date); + + // 在控制台打印今日进货总金额信息,用于调试或简单日志记录 + System.out.println("今日allInprice=" + allInPrice); + + // 在控制台打印今日收银总金额信息,起到调试或日志记录作用 + System.out.println("今日allOutprice=" + allOutPrice); + + // 创建一个JLabel组件pan1,设置其显示文本为包含今日进货总金额的内容,并设置图标及文本在图标的左侧显示,用于直观展示进货金额信息 + pan1 = new JLabel("今日进货总金额:" + allInPrice + "元", new ImageIcon("static\\icon\\money.png"), JLabel.LEFT); + + // 设置pan1这个JLabel组件的字体为通过FontUtil类获取的适用于首页显示的特定字体 + pan1.setFont(FontUtil.homeFont); + + // 设置pan1在界面中的位置和大小 + pan1.setBounds(280, 300, 600, 200); + + // 创建JLabel组件pan2,设置其显示文本为包含今日收银总金额的内容,同样设置图标及文本位置,用于展示收银金额信息 + pan2 = new JLabel("今日收银总金额:" + allOutPrice + "元", new ImageIcon("static\\icon\\income.png"), JLabel.LEFT); + + // 设置pan2的字体为首页特定字体 + pan2.setFont(FontUtil.homeFont); + + // 设置pan2在界面中的位置和大小 + pan2.setBounds(280, 400, 600, 200); + + // 创建JLabel组件pan3,设置其显示文本为今日被投诉次数相关内容(初值为0次),设置图标及文本位置,用于展示投诉情况信息 + pan3 = new JLabel("今日被投诉次数:0次", new ImageIcon("static\\icon\\complaints.png"), JLabel.LEFT); + + // 设置pan3的字体为首页特定字体 + pan3.setFont(FontUtil.homeFont); + + // 设置pan3在界面中的位置和大小 + pan3.setBounds(280, 500, 600, 200); + + + /*priceJPanel = new JPanel(); + priceJPanel.setBounds(100, 200, 700, 500);*/ + + // 将pan1、pan2、pan3这三个用于显示关键信息的JLabel组件添加到当前面板(HomeView)中,使其在界面上展示出来供用户查看相关业务数据 + this.add(pan1); + this.add(pan2); + this.add(pan3); + + // 创建一个按钮组件refreshBtn,使用指定图标文件创建按钮图标 + refreshBtn = new JButton(new ImageIcon("static\\icon\\refresh.png")); + + // 为refreshBtn按钮添加点击事件监听器,将点击事件绑定到当前类的actionPerformed方法上 + refreshBtn.addActionListener(this); + + // 设置refreshBtn按钮在界面中的位置和大小 + refreshBtn.setBounds(1050, 700, 40, 40); + + // 将refreshBtn按钮添加到当前面板(HomeView)中 + this.add(refreshBtn); + } + + // 定义一个实现了ActionListener接口的匿名内部类L,用于处理定时器触发的事件,实现图片在pan这个JLabel组件上的定时切换展示,达到图片轮播效果 + ActionListener L = new ActionListener() { + int index; // 定义变量index,用于记录当前要显示图片在imgs数组中的索引位置,初始默认为0 + + @Override + public void actionPerformed(ActionEvent e) { + // 将pan这个JLabel组件的图标设置为imgs数组中当前索引index对应的图片,实现图片切换展示效果,定时器触发时更新显示图片 + pan.setIcon(imgs[index]); + // 将索引值index加1,准备切换到下一张图片 + index++; + // 判断索引值是否达到imgs数组长度7,若达到则重置为0,实现图片循环轮播 + if (index == 7) + index = 0; + } + }; + + // 定义静态方法refreshHome,用于刷新首页界面上显示的关键数据(进货、收银金额等) public static void refreshHome() { - date= TimeAndOrder.yMdTime();/*获取今天时间*/ - - allInPrice=inOrderImpl.TodayInPrice(date); - allOutPrice=outOrderImpl.TodayOutPrice(date); - System.out.println("今日allInprice="+allInPrice); - System.out.println("今日allOutprice="+allOutPrice); - - pan1.setText("今日进货总金额:"+allInPrice+"元"); - pan2.setText("今日收银总金额:"+allOutPrice+"元"); - pan3.setText("今日被投诉次数:0次"); - - - /* priceJPanel = new JPanel(); - priceJPanel.setBounds(100,200,700,500);*/ -/* this.add(pan1); - this.add(pan2); - this.add(pan3);*/ + // 再次调用TimeAndOrder工具类的yMdTime方法获取当前最新日期信息 + date = TimeAndOrder.yMdTime(); + + // 调用inOrderImpl的TodayInPrice方法,传入最新日期date,重新获取今日进货总金额并更新allInPrice变量的值 + allInPrice = inOrderImpl.TodayInPrice(date); + + // 调用outOrderImpl的TodayOutPrice方法,传入date重新获取今日收银总金额并更新allOutPrice变量的值 + allOutPrice = outOrderImpl.TodayOutPrice(date); + + // 在控制台打印更新后的今日进货总金额信息 + System.out.println("今日allInPrice=" + allInPrice); + + // 在控制台打印更新后的今日收银总金额信息 + System.out.println("今日allOutPrice=" + allOutPrice); + + // 更新pan1这个JLabel组件的文本内容,显示最新的进货总金额信息,实现界面数据实时刷新 + pan1.setText("今日进货总金额:" + allInPrice + "元"); + + // 更新pan2的文本内容,显示最新的收银总金额信息,保证销售数据在界面上及时更新展示 + pan2.setText("今日收银总金额:" + allOutPrice + "元"); + + // 更新pan3的文本内容,开始显示0次投诉 + pan3.setText("今日被投诉次数:0次"); + + /*priceJPanel = new JPanel(); + priceJPanel.setBounds(100, 200, 700, 500);*/ + + /*this.add(pan1); + this.add(pan2); + this.add(pan3);*/ } - - - - - - + + // 实现ActionListener接口的actionPerformed方法 @Override public void actionPerformed(ActionEvent e) { - // TODO Auto-generated method stub + // 获取触发被点击的按钮 Object source = e.getSource(); - if(source==refreshBtn) { + if (source == refreshBtn) { + // 如果点击的是refreshBtn按钮,创建一个新的HomeView实例 new HomeView(jFrame); + // 调用refreshHome方法,刷新首页界面上显示的关键数据,更新界面展示内容 refreshHome(); } - } - - - } \ No newline at end of file diff --git a/Supermarket/src/com/lingnan/supermarket/view/LoginView.java b/Supermarket/src/com/lingnan/supermarket/view/LoginView.java index e52dcb4..6579aa3 100644 --- a/Supermarket/src/com/lingnan/supermarket/view/LoginView.java +++ b/Supermarket/src/com/lingnan/supermarket/view/LoginView.java @@ -24,135 +24,160 @@ import javax.swing.JPasswordField; import javax.swing.JRadioButton; import javax.swing.JTextField; +// 导入用户相关服务层接口及实现类,用于处理用户登录等业务逻辑 import com.lingnan.supermarket.dao.UserService; import com.lingnan.supermarket.dao.impl.UserServiceImpl; +// 导入用户数据传输对象相关类,用于传递用户相关的数据信息 import com.lingnan.supermarket.dto.Production; import com.lingnan.supermarket.dto.User; import com.lingnan.supermarket.componet.BGPanel; import com.lingnan.supermarket.view.base.BaseView; -public class LoginView extends BaseView implements ActionListener{ - - //setLayout(null); - //setBounds(x,y,width,height) - private JPanel containerPanel,namePanel,passwordPanel; - - private JLabel nameLabel,pwdLabel; - private JTextField nameTF; - private JPasswordField pwdTF; - - private JButton loginBtn; - - private User user=null; - - - /*创建窗口*/ - public LoginView() { +// 登录视图类,实现ActionListener接口用于处理按钮点击等事件 +public class LoginView extends BaseView implements ActionListener { + + // 组件声明 + + // 用于容纳其他面板和组件的主面板,整体布局容器 + private JPanel containerPanel; + // 用于放置用户名相关组件的面板 + private JPanel namePanel; + // 用于放置密码相关组件的面板 + private JPanel passwordPanel; + + // 用户名标签 + private JLabel nameLabel; + // 密码标签 + private JLabel pwdLabel; + // 用于输入用户名的文本框 + private JTextField nameTF; + // 用于输入密码的密码框 + private JPasswordField pwdTF; + + // 登录按钮,点击后触发登录验证等相关操作 + private JButton loginBtn; + + // 用于存储登录成功后的用户对象信息,初始化为null + private User user = null; + + /* + * 创建窗口的构造方法 + * 参数: + * int width:窗口的宽度 + * int height:窗口的高度 + * String title:窗口的标题 + */ + public LoginView() { + // 调用父类(BaseView)的构造方法来设置窗口的大小和标题 super(350, 250, "新民超市"); - ImageIcon icon=new ImageIcon("static\\icon\\新.png"); //xxx代表图片存放路径,2.png图片名称及格式 + // 创建一个ImageIcon对象,用于设置窗口的图标,传入的参数是图标图片的路径及文件名 + ImageIcon icon = new ImageIcon("static\\icon\\新.png"); + // 设置窗口的图标,通过获取ImageIcon中的Image对象来设置 this.setIconImage(icon.getImage()); - } - /*添加组件*/ - @Override/*界面*/ + /* + * 添加组件到界面的方法,重写自父类的initView方法,用于初始化界面视图组件及布局等 + */ + @Override protected void initView() { - Image bgImage = null; try { + // 尝试从指定文件路径读取背景图片,若读取失败会抛出IOException异常 bgImage = ImageIO.read(new File("static\\bg\\bg1.jpg")); } catch (IOException e) { e.printStackTrace(); } - containerPanel = new BGPanel(bgImage); - - - - //用户名 - namePanel = new JPanel(); + // 创建一个自定义的背景面板,传入读取到的背景图片,用于作为整个界面的背景容器 + containerPanel = new BGPanel(bgImage); + + // 用户名相关组件的设置 + // 创建放置用户名相关组件的面板 + namePanel = new JPanel(); + // 创建用户名标签,通过传入一个ImageIcon来显示带有图标的提示信息 nameLabel = new JLabel(new ImageIcon("static\\icon\\loginName.png")); - nameTF = new JTextField("z001",22); + // 创建用户名输入文本框,并设置默认显示的文本内容以及文本框的宽度 + nameTF = new JTextField("z001", 22); + // 将用户名标签和输入文本框添加到用户名面板中 namePanel.add(nameLabel); namePanel.add(nameTF); - - //密码 + // 密码相关组件的设置 + // 创建放置密码相关组件的面板 passwordPanel = new JPanel(); + // 创建密码标签,通过传入一个ImageIcon来显示带有图标的提示信息 pwdLabel = new JLabel(new ImageIcon("static\\icon\\pwd.png")); - pwdTF = new JPasswordField("0.00.0",22); + // 创建密码输入文本框 + pwdTF = new JPasswordField("0.00.0", 22); + // 将密码标签和密码输入文本框添加到密码面板中 passwordPanel.add(pwdLabel); passwordPanel.add(pwdTF); - - //登录 + + // 创建登录按钮,并设置按钮上显示的文本内容 loginBtn = new JButton("登录"); + // 为登录按钮添加ActionListener监听器,当按钮被点击时会触发相应的事件处理方法 loginBtn.addActionListener(this); - - - - - /*添加组件*/ + // 将用户名面板、密码面板和登录按钮添加到主容器面板中,确定它们在界面中的布局顺序等 containerPanel.add(namePanel); containerPanel.add(passwordPanel); containerPanel.add(loginBtn); - - - + // 获取窗口的内容面板,将主容器面板添加到内容面板中,使得界面组件能够正确显示在窗口内 Container container = getContentPane(); container.add(containerPanel); } - - /*事件处理*/ + + /* + * 处理按钮点击等事件的方法,实现ActionListener接口的抽象方法,用于处理界面中的交互事件 + * 参数: + * ActionEvent e:包含了事件相关的信息,例如事件源(哪个组件触发的事件)等 + */ @Override public void actionPerformed(ActionEvent e) { - /*如果点击登录*/ - if(e.getSource()==loginBtn){ - String loginName = nameTF.getText(); - String password = new String(pwdTF.getPassword()); - System.out.println("点击登录后"); - System.out.println("用户名为"+loginName); - System.out.println("密码为"+password); - //TODO 参数校验 - UserServiceImpl userService = new UserServiceImpl(); - user = userService.login(loginName, password); - - if(user==null) { - JOptionPane.showMessageDialog(this,"账号或密码错误"); - }else { - //去到主界面 - Random random=new Random(); - int skin=random.nextInt(10); - System.out.println("skin="+skin); - String iconSkin = "static\\icon\\新.png";/*默认icon*/ - new MainView(user,skin,iconSkin); - this.dispose(); - } + // 判断事件源是否是登录按钮 + if (e.getSource() == loginBtn) { + // 获取用户名输入文本框中的文本内容,作为登录用户名 + String loginName = nameTF.getText(); + // 获取密码输入文本框中的密码内容,通过将char数组转换为字符串的方式获取 + String password = new String(pwdTF.getPassword()); + System.out.println("点击登录后"); + System.out.println("用户名为" + loginName); + System.out.println("密码为" + password); + // 创建用户服务层的实现类对象,用于调用登录相关的业务逻辑方法 + UserServiceImpl userService = new UserServiceImpl(); + // 调用用户服务层的登录方法,传入用户名和密码进行登录验证,返回验证后的用户对象 + user = userService.login(loginName, password); + + // 根据登录验证结果进行相应处理 + if (user == null) { + // 如果用户对象为null,说明登录失败,弹出提示框告知用户账号或密码错误 + JOptionPane.showMessageDialog(this, "账号或密码错误"); + } else { + // 如果登录成功,生成一个随机数,用于后续可能的界面皮肤等相关随机选择逻辑 + Random random = new Random(); + int skin = random.nextInt(10); + System.out.println("skin=" + skin); + // 设置默认的图标皮肤 + String iconSkin = "static\\icon\\新.png"; + // 创建主界面对象,传入登录成功的用户对象、随机生成的皮肤编号以及图标皮肤路径,进入主界面展示相关功能 + new MainView(user, skin, iconSkin); + // 关闭当前登录窗口,释放资源等 + this.dispose(); + } } - } - - public static void main(String[] args) { + //设置界面外观 Nimbus.Nimbus(); + // 创建登录视图(LoginView)对象,启动登录界面展示 LoginView loginView = new LoginView(); - } + } @Override - protected void initView(User user,int skin) { + protected void initView(User user, int skin) { // TODO Auto-generated method stub - - } - - - - - - - -} - - - + } +} \ 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 6d460d0..d8eec3c 100644 --- a/Supermarket/src/com/lingnan/supermarket/view/UserView.java +++ b/Supermarket/src/com/lingnan/supermarket/view/UserView.java @@ -23,163 +23,231 @@ import com.lingnan.supermarket.dto.User; import com.lingnan.supermarket.table.UserTableModel; import com.lingnan.supermarket.utils.FontUtil; -public class UserView extends JPanel implements ActionListener{ - - - //上面 +// UserView类继承自JPanel并实现ActionListener接口,用于构建用户管理界面相关的视图,处理用户交互动作 +public class UserView extends JPanel implements ActionListener { + + // 用于存放整个顶部工具栏相关组件的面板 private JPanel toolBarPanel; - + + // 用于存放搜索相关组件的面板 private JPanel searchPanel; - private JLabel nameLabel,locationLabel; + // 用于显示"姓名"提示文字的标签 + private JLabel nameLabel, locationLabel; + // 用于输入姓名进行搜索的文本框 private JTextField nameSearchTF; + // 用于触发搜索操作的按钮 private JButton searchBtn; - + + // 用于存放操作按钮(添加、更新、删除等)的面板 private JPanel opePanel; - private JButton addBtn,updateBtn,deleteBtn; - - //中间 + // 用于触发添加用户操作的按钮 + private JButton addBtn, updateBtn, deleteBtn; + + // 界面中部相关组件声明 + // 用于存放表格并提供滚动功能的滚动面板,以便在表格内容较多时可以滚动查看 private JScrollPane tableScrollPane; + // 用于展示用户数据的表格组件 private JTable userTable; - - //删除时选中赋值给id + + // 用于记录删除操作时选中记录的用户id,初始化为0 private int id; - - //下面 + + // 界面下部相关组件声明 + // 用于存放记录数相关提示信息的面板 private JPanel bottomPanel; + // 用于显示用户记录总数相关提示信息的标签 private JLabel countInfoLabel; - + + // 对父窗口(JFrame类型)的引用 private JFrame jFrame; - - - private UserTableModel userTableModel ; - - - private UserService userService=new UserServiceImpl(); + + // 用户表格数据模型对象,用于管理表格中的数据,与数据库等数据源进行交互获取和更新数据等 + private UserTableModel userTableModel; + + // 用户服务接口的实现类实例,通过它可以调用与用户相关的数据库操作方法,如增删改查等功能 + private UserService userService = new UserServiceImpl(); + + // 构造函数,接收一个JFrame类型的参数jFrame,用于创建用户管理视图,并初始化界面组件 public UserView(JFrame jFrame) { + // 设置该面板(UserView)的布局为BorderLayout,将界面划分为北、南、东、西、中五个区域来放置组件 this.setLayout(new BorderLayout()); + // 调用初始化视图组件的方法 initView(); + // 将传入的父窗口引用保存到成员变量jFrame中 this.jFrame = jFrame; } - + + // 初始化用户管理视图界面组件的方法 private void initView() { - - toolBarPanel = new JPanel(new BorderLayout()); - - searchPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); - locationLabel=new JLabel("当前位置>人员管理"); + // 创建一个新的面板toolBarPanel,设置其布局为BorderLayout,用于存放顶部的搜索和操作按钮等组件 + toolBarPanel = new JPanel(new BorderLayout()); + + // 创建一个新的面板searchPanel,设置其布局为FlowLayout,且组件左对齐,用于存放搜索相关的组件 + searchPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); + // 创建一个显示当前位置提示信息的标签,这里显示为"当前位置>人员管理" + locationLabel = new JLabel("当前位置>人员管理"); + // 设置标签的字体为通过FontUtil类获取的特定字体(这里假设FontUtil类用于统一管理字体相关设置) locationLabel.setFont(new FontUtil().userFont); + // 设置标签的前景色(文字颜色)为特定的蓝色(RGB值为18, 150, 219) locationLabel.setForeground(new Color(18, 150, 219)); + // 创建一个显示"姓名"文字的标签,用于提示用户在旁边的文本框中输入姓名进行搜索 nameLabel = new JLabel("姓名"); + // 创建一个文本框,用于用户输入要搜索的姓名,设置其可显示的宽度大致为10个字符左右 nameSearchTF = new JTextField(10); - + // 创建一个按钮,使用指定路径下的图标文件作为按钮的图标,用于触发搜索操作 searchBtn = new JButton(new ImageIcon("static\\icon\\search.png")); - - /*右边功能模块*/ - opePanel = new JPanel(new FlowLayout(FlowLayout.RIGHT)); - addBtn =new JButton(new ImageIcon("static\\icon\\add.png")); - updateBtn =new JButton(new ImageIcon("static\\icon\\update.png")); - deleteBtn =new JButton(new ImageIcon("static\\icon\\delete.png")); - + + // 创建一个新的面板opePanel,设置其布局为FlowLayout,且组件右对齐,用于存放操作按钮(添加、更新、删除) + opePanel = new JPanel(new FlowLayout(FlowLayout.RIGHT)); + // 创建一个按钮,使用指定路径下的图标文件("static\\icon\\add.png")作为按钮的图标,用于触发添加用户操作 + addBtn = new JButton(new ImageIcon("static\\icon\\add.png")); + // 创建一个按钮,使用指定路径下的图标文件("static\\icon\\update.png")作为按钮的图标,用于触发更新用户操作 + updateBtn = new JButton(new ImageIcon("static\\icon\\update.png")); + // 创建一个按钮,使用指定路径下的图标文件("static\\icon\\delete.png")作为按钮的图标,用于触发删除用户操作 + deleteBtn = new JButton(new ImageIcon("static\\icon\\delete.png")); + + // 为添加、更新、删除和搜索按钮添加点击事件监听器,将按钮的点击事件绑定到当前类(实现了ActionListener接口)的actionPerformed方法上,以便处理相应的操作逻辑 addBtn.addActionListener(this); updateBtn.addActionListener(this); deleteBtn.addActionListener(this); searchBtn.addActionListener(this); - + + // 将添加、更新、删除按钮依次添加到操作按钮面板opePanel中 opePanel.add(addBtn); opePanel.add(updateBtn); opePanel.add(deleteBtn); - + + // 将位置提示标签、姓名标签、姓名搜索文本框和搜索按钮依次添加到搜索面板searchPanel中 searchPanel.add(locationLabel); searchPanel.add(nameLabel); searchPanel.add(nameSearchTF); searchPanel.add(searchBtn); - - - toolBarPanel.add(searchPanel,"West"); - toolBarPanel.add(opePanel,"East"); - - - //中间表格 - userTableModel = new UserTableModel(); + + // 将搜索面板添加到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类中定义了相关字体常量) userTable.setFont(FontUtil.tableFont); + // 设置表格每行的高度为50像素,调整表格的显示样式 userTable.setRowHeight(50); + // 创建一个滚动面板,将用户表格添加到滚动面板中,以便在表格内容较多时可以通过滚动条查看全部内容 tableScrollPane = new JScrollPane(userTable); - - //下面 + + // 创建一个新的面板bottomPanel,设置其布局为FlowLayout,且组件左对齐,用于存放记录数相关提示信息 bottomPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); - countInfoLabel = new JLabel("总共"+userTableModel.getRowCount()+"条"); + // 创建一个显示用户记录总数的标签,初始文本为"总共"加上通过用户表格数据模型获取的行数(假设UserTableModel类的getRowCount方法返回当前模型中的数据行数)以及"条"字 + countInfoLabel = new JLabel("总共" + userTableModel.getRowCount() + "条"); + // 将记录数标签添加到bottomPanel面板中 bottomPanel.add(countInfoLabel); - - - this.add(toolBarPanel,"North"); - this.add(tableScrollPane,"Center");/*将表格放到中间*/ - this.add(bottomPanel,"South"); - + + // 将顶部工具栏面板添加到当前面板(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) { - //添加数据的对话框 + if (addBtn == source) { + // 如果点击的是添加按钮,执行以下操作: + + // 创建一个用于添加用户信息的对话框 UserDialog userDialog = new UserDialog(jFrame); + // 设置该对话框可见,显示在屏幕上,让用户进行添加用户信息的操作 userDialog.setVisible(true); + // 调用刷新用户数据的方法,用于在添加操作完成后更新界面上的用户数据显示 refreshUser(); - }else if(updateBtn==source) { - + } else if (updateBtn == source) { + // 如果点击的是更新按钮,调用刷新用户数据的方法,用于在更新操作相关逻辑完成后更新界面上的用户数据显示 refreshUser(); - }else if(deleteBtn==source) { - //获取选中记录 + } else if (deleteBtn == source) { + // 如果点击的是删除按钮,获取用户在表格中选中的行索引,如果没有选中任何行,则返回 -1 int rowIndex = userTable.getSelectedRow(); - if(rowIndex==-1) { - JOptionPane.showMessageDialog(this,"请选中一条"); + if (rowIndex == -1) { + // 如果没有选中行,弹出提示框提醒用户需要选中一条记录后再进行删除操作 + JOptionPane.showMessageDialog(this, "请选中一条"); return; } - int id = (Integer)userTable.getValueAt(rowIndex,0); - int select=JOptionPane.showConfirmDialog(this,"是否删除id="+id,"提示",JOptionPane.YES_NO_OPTION); - if(select==JOptionPane.YES_OPTION){ - - if(userService.deleteUser(id)==1) { - JOptionPane.showMessageDialog(this,"删除成功","提示",JOptionPane.INFORMATION_MESSAGE); - - }else { - JOptionPane.showMessageDialog(this,"删除失败","提示",JOptionPane.ERROR_MESSAGE); + // 获取选中行的第一列的值,并转换为整数类型,赋值给id变量,用于后续删除操作时确定要删除的用户记录 + int id = (Integer) userTable.getValueAt(rowIndex, 0); + // 弹出确认对话框,询问用户是否确定删除指定id的用户记录,提供"是"和"否"两个选项,返回用户选择的结果 + int select = JOptionPane.showConfirmDialog(this, "是否删除id=" + id, "提示", JOptionPane.YES_NO_OPTION); + if (select == JOptionPane.YES_OPTION) { + // 如果用户选择了"是"(确认删除),执行以下操作: + + // 调用用户服务接口的删除用户方法,传入要删除的用户id,尝试从数据库中删除对应的用户记录,并获取返回结果(假设返回1表示删除成功,其他值表示失败) + if (userService.deleteUser(id) == 1) { + // 如果删除成功,弹出提示框显示"删除成功"的消息,提示框的图标为信息图标 + JOptionPane.showMessageDialog(this, "删除成功", "提示", JOptionPane.INFORMATION_MESSAGE); + } else { + // 如果删除失败,弹出提示框显示"删除失败"的消息,提示框的图标为错误图标 + JOptionPane.showMessageDialog(this, "删除失败", "提示", JOptionPane.ERROR_MESSAGE); } } + // 无论删除操作是否成功,都调用刷新用户数据的方法,更新界面上的用户数据显示,确保表格等显示内容与数据库中的最新数据一致 refreshUser(); - - }else{ + } else { + // 如果点击的是搜索按钮(即其他未明确匹配的按钮点击情况,这里目前代码逻辑中只存在搜索按钮可能进入此分支),执行以下操作: + System.out.println("搜索"); + // 调用刷新按姓名搜索结果的方法,根据用户在姓名搜索文本框中输入的内容进行数据刷新和表格显示更新 refreshFindRname(); } - } + + // 根据姓名进行搜索并刷新表格显示内容的方法 public void refreshFindRname() { + // 获取用户在姓名搜索文本框中输入的姓名内容 String rname = nameSearchTF.getText(); - User user =new User(); + // 创建一个临时的User对象,用于传递搜索条件 + User user = new User(); + // 将获取到的姓名设置到临时User对象中,作为搜索条件 user.setRname(rname); + // 创建一个新的用户表格数据模型对象,用于重新获取和设置符合搜索条件的数据 userTableModel = new UserTableModel(); + // 调用用户表格数据模型的方法,根据传入的包含姓名条件的User对象进行数据查询,获取符合条件的用户数据 userTableModel.Byrname(user); + // 将更新后的用户表格数据模型设置给用户表格 userTable.setModel(userTableModel); - //同时更新下面的记录数 - refreshCount(); + // 同时调用刷新记录数的方法,更新界面下方显示的用户记录总数提示信息 + refreshCount(); } + + // 刷新用户数据显示 public void refreshUser() { + // 创建一个新的用户表格数据模型对象 userTableModel = new UserTableModel(); + // 调用数据模型的方法获取所有用户数据,重新填充模型 userTableModel.all(); + // 将更新后的用户表格数据模型设置给用户表格,使表格显示最新的全部用户数据内容 userTable.setModel(userTableModel); - //同时更新下面的记录数 + // 同时调用刷新记录数的方法,更新界面下方显示的用户记录总数提示信息 refreshCount(); - } - public void refreshCount(){ + + // 刷新界面下方显示的用户记录总数提示信息的方法 + public void refreshCount() { + // 移除bottomPanel面板中之前添加的所有组件,更新显示新的记录数 bottomPanel.removeAll(); - countInfoLabel = new JLabel("总共"+userTableModel.getRowCount()+"条"); + // 创建一个新的显示用户记录总数的标签,文本内容为"总共"加上通过用户表格数据模型获取的当前行数以及"条"字 + countInfoLabel = new JLabel("总共" + userTableModel.getRowCount() + "条"); + // 将新的记录数标签添加到bottomPanel面板中,实现记录数提示信息的更新显示 bottomPanel.add(countInfoLabel); } -} - +} \ No newline at end of file diff --git a/test.txt b/test.txt index d800886..00bca14 100644 --- a/test.txt +++ b/test.txt @@ -1 +1,4 @@ -123 \ No newline at end of file + +123 +z1 +