Compare commits

...

98 Commits

Author SHA1 Message Date
p4vsywzlp 7a7c3179bd end
1 year ago
HouXinyu 3716d82083 end
1 year ago
HouXinyu ad2a162593 z5
1 year ago
HouXinyu b319190310 t3
1 year ago
HouXinyu 56521ce0d3 Merge remote-tracking branch 'remotes/origin/main' into developer
1 year ago
HouXinyu 2a5310d522 update
1 year ago
HouXinyu 4dbaa3a639 rollback
1 year ago
沈国良 93e6105851 增加备注
1 year ago
沈国良 7898a8bc8d 增加备注
1 year ago
沈国良 2cdeae95ab 增加备注
1 year ago
沈国良 4405166476 增加备注
1 year ago
沈国良 4cc69809c7 增加备注
1 year ago
沈国良 cbe7cb5560 增加备注
1 year ago
沈国良 ae7aaca6f6 增加备注
1 year ago
沈国良 8e14e78135 增加备注
1 year ago
沈国良 b5dfd2c50e 增加时间备注
1 year ago
沈国良 c554d51aa3 增加数据库备注
1 year ago
沈国良 849c0cd35a 增加模块备注
1 year ago
沈国良 22197c2e7e 增加收银模块备注
1 year ago
pxjfuz984 0a4699b5e1 Merge pull request '完成仓库管理部分注释' (#47) from pxjfuz984/test:branch_zyx into main
1 year ago
郑亦歆 31474a5234 仓库系统部分注释完成
1 year ago
pxjfuz984 a1c62bdaf9 Merge pull request '仓库管理部分已注释' (#46) from pxjfuz984/test:branch_zyx into main
1 year ago
郑亦歆 5639047a02 仓库管理部分已注释
1 year ago
pxjfuz984 623f0ce250 Merge pull request 'dto文件部分修改' (#45) from pxjfuz984/test:branch_zyx into main
1 year ago
郑亦歆 50f85cd555 dto文件部分修改
1 year ago
pxjfuz984 1110158a4f Merge pull request 'table部分修改' (#44) from pxjfuz984/test:branch_zyx into main
1 year ago
郑亦歆 8a6015ba57 table部分修改
1 year ago
pxjfuz984 5d679b62fb Merge pull request 'base文件夹部分修改' (#43) from pxjfuz984/test:branch_zyx into main
1 year ago
郑亦歆 43656d2b42 base文件夹部分修改
1 year ago
pxjfuz984 4edbca8770 Merge pull request 'SuperView注释' (#42) from pxjfuz984/test:branch_zyx into main
1 year ago
郑亦歆 a19fdbe104 SuperView.java修改
1 year ago
pxjfuz984 44f09f4a38 Merge pull request 'test.txt修改测试看代码行数是否改变' (#41) from pxjfuz984/test:branch_zyx into main
1 year ago
郑亦歆 0ecdef9993 test.txt修改测试3
1 year ago
郑亦歆 f19c4fa975 Merge branch 'main' into branch_zyx
1 year ago
沈国良 07d5eb3a49 解决冲突
1 year ago
p4vsywzlp 0860bf5380 Merge pull request '21' (#40) from branch_cwf into main
1 year ago
HouXinyu 9274bc6f1e 84925+
1 year ago
HouXinyu 6e730f22f2 111
1 year ago
HouXinyu 612c66f89e Merge remote-tracking branch 'remotes/origin/main' into branch_cwf
1 year ago
沈国良 2bd45ddbd2 d10
1 year ago
HouXinyu 29a9fa2f22 Merge remote-tracking branch 'remotes/origin/developer' into branch_cwf
1 year ago
Redmi ac909ed42f d89
1 year ago
HouXinyu caa1093536 d8
1 year ago
Redmi 4f20056302 d7
1 year ago
p4vsywzlp 0b500fb12f d56
1 year ago
Redmi f2932379f0 d56
1 year ago
m2fn43ypg c6f2c99109 d4
1 year ago
Redmi dad9e9eb0c d4
1 year ago
Redmi ef52d10929 1
1 year ago
HouXinyu e8f774d494 d3
1 year ago
p4vsywzlp d79f6a7cc2 d3
1 year ago
Redmi 5a42e467fa 1111
1 year ago
“郑亦歆” 272c25e960 test.txt修改测试2
1 year ago
p4vsywzlp 328a2d4c6f d2
1 year ago
HouXinyu d02b117bd8 d2
1 year ago
cwfeng a2e9b67ba3 txt
1 year ago
cwfeng fac9bb0d14 aall
1 year ago
cwfeng e7b79122d3 txt
1 year ago
cwfeng c3201163fa txt
1 year ago
p4vsywzlp 1244beae02 all
1 year ago
cwfeng 4d28ccac79 添加了进货员角色,修改了用户信息权限
1 year ago
p4vsywzlp dc9501074a Merge pull request 'all' (#25) from pxeyinm2q/test:main into branch_cwf
1 year ago
pxeyinm2q 2aae1bbccd Merge pull request 'all' (#1) from branch_cwf into main
1 year ago
p4vsywzlp bacaa766ac 测试2
1 year ago
p4vsywzlp 289fc02d3c 测试2
1 year ago
“郑亦歆” c2a8c327dd test.txt修改测试2
1 year ago
p4vsywzlp 10a7aa497e Merge pull request '测试' (#22) from branch_zyx into main
1 year ago
p4vsywzlp 6d29256b57 Merge pull request 'test.txt修改测试看代码行数是否改变' (#21) from pxjfuz984/test:branch_zyx into main
1 year ago
p4vsywzlp a911d1db30 测试
1 year ago
“郑亦歆” 7279fe86e2 解决合并冲突
1 year ago
“郑亦歆” 10e470c0b4 test.txt测试修改1
1 year ago
p4vsywzlp a1974fe786 回溯1
1 year ago
“郑亦歆” 24f0f0a5ab hui shu 1
1 year ago
p4vsywzlp 883489e48e 260
1 year ago
“郑亦歆” 826a686744 提交至:branch_zyx
1 year ago
“郑亦歆” e8dded798d Merge remote 'main' branch into local 'main' branch.
1 year ago
“郑亦歆” 805508f956 Merge branch 'main' of bdgit.educoder.net:p4vsywzlp/test
1 year ago
p4vsywzlp a00e955eb1 259
1 year ago
“郑亦歆” 865f39f7c0 branch
1 year ago
“郑亦歆” 0e72da5c2e 删除
1 year ago
“郑亦歆” ad2c3c0b1d branch
1 year ago
“郑亦歆” 73af0fcd38 branch
1 year ago
“郑亦歆” 9c2c34ed94 branch
1 year ago
Redmi 7fe44258db 第一次添加
1 year ago
cwfeng 2b551b5dee Merge remote-tracking branch 'origin/branch_cwf' into branch_cwf
1 year ago
cwfeng 0bc7bcfb34 添加了进货员角色并修改了用户权限
1 year ago
cwfeng 3b68c7ff00 添加了进货员角色并修改了用户权限
1 year ago
p4vsywzlp f0f38a4a13 257
1 year ago
p4vsywzlp 9d5da30c23 256
1 year ago
cwfeng 3bc2dbaac8 更新了配置文件
1 year ago
p4vsywzlp 81ff328230 Merge pull request '255' (#5) from developer into main
1 year ago
HouXinyu 7af44e20ca 4444
1 year ago
cwfeng 237242ca76 添加txt
1 year ago
pxeyinm2q 6935474bb6 修改了进货模块的代码注释 (#1)
1 year ago
pxeyinm2q 3e47192761 添加了注释信息 impl v1.0 (#3)
1 year ago
cwfeng 3b4f339f5a 添加了注释信息impl v1.0
1 year ago
cwfeng e9cf9c9e44 添加了进货模块注释
1 year ago
cwfeng e95c524ffd inOrderServiceImpl.java
1 year ago

@ -3,5 +3,5 @@
<component name="JavaScriptSettings"> <component name="JavaScriptSettings">
<option name="languageLevel" value="ES6" /> <option name="languageLevel" value="ES6" />
</component> </component>
<component name="ProjectRootManager" version="2" project-jdk-name="21" project-jdk-type="JavaSDK" /> <component name="ProjectRootManager" version="2" languageLevel="JDK_11" project-jdk-name="11" project-jdk-type="JavaSDK" />
</project> </project>

@ -6,6 +6,6 @@
<classpathentry kind="src" path="config"/> <classpathentry kind="src" path="config"/>
<classpathentry kind="lib" path="Supermarket/lib/activation.jar"/> <classpathentry kind="lib" path="Supermarket/lib/activation.jar"/>
<classpathentry kind="lib" path="Supermarket/lib/mail.jar"/> <classpathentry kind="lib" path="Supermarket/lib/mail.jar"/>
<classpathentry kind="lib" path="Supermarket/lib/mysql-connector-java-5.1.32.jar"/> <classpathentry kind="lib" path="Supermarket/lib/mysql-connector-java-8.0.20.jar"/>
<classpathentry kind="output" path="bin"/> <classpathentry kind="output" path="bin"/>
</classpath> </classpath>

@ -2,7 +2,7 @@
<project version="4"> <project version="4">
<component name="dataSourceStorageLocal" created-in="IU-231.8109.175"> <component name="dataSourceStorageLocal" created-in="IU-231.8109.175">
<data-source name="@localhost" uuid="5b23e521-053a-47c0-ae28-a98b513bc6ec"> <data-source name="@localhost" uuid="5b23e521-053a-47c0-ae28-a98b513bc6ec">
<database-info product="MySQL" version="5.7.44-log" jdbc-version="4.2" driver-name="MySQL Connector/J" driver-version="mysql-connector-j-8.2.0 (Revision: 06a1f724497fd81c6a659131fda822c9e5085b6c)" dbms="MYSQL" exact-version="5.7.44" exact-driver-version="8.2"> <database-info product="MySQL" version="8.4.0" jdbc-version="4.2" driver-name="MySQL Connector/J" driver-version="mysql-connector-j-8.2.0 (Revision: 06a1f724497fd81c6a659131fda822c9e5085b6c)" dbms="MYSQL" exact-version="8.4.0" exact-driver-version="8.2">
<extra-name-characters>#@</extra-name-characters> <extra-name-characters>#@</extra-name-characters>
<identifier-quote-string>`</identifier-quote-string> <identifier-quote-string>`</identifier-quote-string>
</database-info> </database-info>

@ -0,0 +1,11 @@
<component name="libraryTable">
<library name="mysql.connector.java" type="repository">
<properties maven-id="mysql:mysql-connector-java:8.0.20" />
<CLASSES>
<root url="jar://$PROJECT_DIR$/lib/mysql-connector-java-8.0.20.jar!/" />
<root url="jar://$PROJECT_DIR$/lib/protobuf-java-3.6.1.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</component>

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
</component>
</project>

@ -1,9 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4"> <module type="JAVA_MODULE" version="4">
<component name="EclipseModuleManager"> <component name="EclipseModuleManager">
<libelement value="file://D:/大二下学期实训超市管理系统/Supermarket/lib/activation.jar" /> <libelement value="file://$MODULE_DIR$/../../../大二下学期实训超市管理系统/Supermarket/lib/activation.jar" />
<libelement value="file://D:/大二下学期实训超市管理系统/Supermarket/lib/mail.jar" /> <libelement value="file://$MODULE_DIR$/../../../大二下学期实训超市管理系统/Supermarket/lib/mail.jar" />
<libelement value="file://D:/大二下学期实训超市管理系统/Supermarket/lib/mysql-connector-java-5.1.32.jar" /> <libelement value="file://$MODULE_DIR$/../../../大二下学期实训超市管理系统/Supermarket/lib/mysql-connector-java-5.1.32.jar" />
<src_description expected_position="1"> <src_description expected_position="1">
<src_folder value="file://$MODULE_DIR$/src" expected_position="0" /> <src_folder value="file://$MODULE_DIR$/src" expected_position="0" />
<src_folder value="file://$MODULE_DIR$" expected_position="1" /> <src_folder value="file://$MODULE_DIR$" expected_position="1" />
@ -47,5 +47,6 @@
<SOURCES /> <SOURCES />
</library> </library>
</orderEntry> </orderEntry>
<orderEntry type="library" name="mysql.connector.java" level="project" />
</component> </component>
</module> </module>

@ -6,6 +6,6 @@
<classpathentry kind="src" path="config"/> <classpathentry kind="src" path="config"/>
<classpathentry kind="lib" path="Supermarket/lib/activation.jar"/> <classpathentry kind="lib" path="Supermarket/lib/activation.jar"/>
<classpathentry kind="lib" path="Supermarket/lib/mail.jar"/> <classpathentry kind="lib" path="Supermarket/lib/mail.jar"/>
<classpathentry kind="lib" path="Supermarket/lib/mysql-connector-java-5.1.32.jar"/> <classpathentry kind="lib" path="Supermarket/lib/mysql-connector-java-8.0.20.jar"/>
<classpathentry kind="output" path="bin"/> <classpathentry kind="output" path="bin"/>
</classpath> </classpath>

@ -2,7 +2,7 @@
<project version="4"> <project version="4">
<component name="dataSourceStorageLocal" created-in="IU-231.8109.175"> <component name="dataSourceStorageLocal" created-in="IU-231.8109.175">
<data-source name="@localhost" uuid="5b23e521-053a-47c0-ae28-a98b513bc6ec"> <data-source name="@localhost" uuid="5b23e521-053a-47c0-ae28-a98b513bc6ec">
<database-info product="MySQL" version="5.7.44-log" jdbc-version="4.2" driver-name="MySQL Connector/J" driver-version="mysql-connector-j-8.2.0 (Revision: 06a1f724497fd81c6a659131fda822c9e5085b6c)" dbms="MYSQL" exact-version="5.7.44" exact-driver-version="8.2"> <database-info product="MySQL" version="8.4.0" jdbc-version="4.2" driver-name="MySQL Connector/J" driver-version="mysql-connector-j-8.2.0 (Revision: 06a1f724497fd81c6a659131fda822c9e5085b6c)" dbms="MYSQL" exact-version="8.4.0" exact-driver-version="8.2">
<extra-name-characters>#@</extra-name-characters> <extra-name-characters>#@</extra-name-characters>
<identifier-quote-string>`</identifier-quote-string> <identifier-quote-string>`</identifier-quote-string>
</database-info> </database-info>

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
</component>
</project>

@ -1,9 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4"> <module type="JAVA_MODULE" version="4">
<component name="EclipseModuleManager"> <component name="EclipseModuleManager">
<libelement value="file://D:/大二下学期实训超市管理系统/Supermarket/lib/activation.jar" /> <libelement value="file://$MODULE_DIR$/../../../大二下学期实训超市管理系统/Supermarket/lib/activation.jar" />
<libelement value="file://D:/大二下学期实训超市管理系统/Supermarket/lib/mail.jar" /> <libelement value="file://$MODULE_DIR$/../../../大二下学期实训超市管理系统/Supermarket/lib/mail.jar" />
<libelement value="file://D:/大二下学期实训超市管理系统/Supermarket/lib/mysql-connector-java-5.1.32.jar" /> <libelement value="file://$MODULE_DIR$/../../../大二下学期实训超市管理系统/Supermarket/lib/mysql-connector-java-5.1.32.jar" />
<src_description expected_position="1"> <src_description expected_position="1">
<src_folder value="file://$MODULE_DIR$/src" expected_position="0" /> <src_folder value="file://$MODULE_DIR$/src" expected_position="0" />
<src_folder value="file://$MODULE_DIR$" expected_position="1" /> <src_folder value="file://$MODULE_DIR$" expected_position="1" />
@ -47,5 +47,6 @@
<SOURCES /> <SOURCES />
</library> </library>
</orderEntry> </orderEntry>
<orderEntry type="library" name="mysql.connector.java" level="project" />
</component> </component>
</module> </module>

@ -1,4 +1,4 @@
driver=com.mysql.jdbc.Driver driver=com.mysql.cj.jdbc.Driver
url=jdbc:mysql://localhost:3306/supermarket url=jdbc:mysql://localhost:3306/supermarket?serverTimezone=UTC
user=root user=root
password=123456 password=123456

@ -1,4 +1,4 @@
driver=com.mysql.jdbc.Driver driver=com.mysql.cj.jdbc.Driver
url=jdbc:mysql://localhost:3306/supermarket url=jdbc:mysql://localhost:3306/supermarket?serverTimezone=UTC
user=root user=root
password=123456 password=123456

@ -1,4 +1,4 @@
driver=com.mysql.jdbc.Driver driver=com.mysql.cj.jdbc.Driver
url=jdbc:mysql://localhost:3306/supermarket url=jdbc:mysql://localhost:3306/supermarket?serverTimezone=UTC
user=root user=root
password=123456 password=123456

@ -8,16 +8,16 @@ public class BGPanel extends JPanel{
private Image image; private Image image;
public BGPanel(Image image) { public BGPanel(Image image) {
// 定义一个构造方法接收一个Image类型的参数image用于创建BGPanel对象时传入要显示的图像 // 定义构造方法
this.image = image; this.image = image;
// 将传入的参数image赋值给类的成员变量image // 将传入的参数image赋值给类的成员变量image
int width = Toolkit.getDefaultToolkit().getScreenSize().width; int width = Toolkit.getDefaultToolkit().getScreenSize().width;
// 通过默认工具包Toolkit获取屏幕的宽度存储在局部变量width中 // 通过默认工具包Toolkit获取屏幕的宽度
int height = Toolkit.getDefaultToolkit().getScreenSize().height; int height = Toolkit.getDefaultToolkit().getScreenSize().height;
// 通过默认工具包Toolkit获取屏幕的高度存储在局部变量height中 // 通过默认工具包Toolkit获取屏幕的高度
this.setSize(width, height); this.setSize(width, height);
// 设置该面板BGPanel的大小为整个屏幕的大小,即宽度和高度分别为获取到的屏幕宽高 // 设置该面板的大小为整个屏幕的大小
} }
public BGPanel(Image image, int width, int height) { public BGPanel(Image image, int width, int height) {
@ -37,7 +37,6 @@ public class BGPanel extends JPanel{
// 调用父类JPanel的paintComponent方法以确保完成一些默认的绘制操作比如背景清除等 // 调用父类JPanel的paintComponent方法以确保完成一些默认的绘制操作比如背景清除等
g.drawImage(image, 0, 0, getWidth(), getHeight(), this); g.drawImage(image, 0, 0, getWidth(), getHeight(), this);
// 使用传入的Graphics对象g在面板上绘制图像参数含义如下
// image要绘制的图像对象就是之前保存的成员变量image // image要绘制的图像对象就是之前保存的成员变量image
// 0, 0表示在面板上绘制图像的起始坐标x坐标和y坐标这里从面板的左上角0, 0位置开始绘制 // 0, 0表示在面板上绘制图像的起始坐标x坐标和y坐标这里从面板的左上角0, 0位置开始绘制
// getWidth(), getHeight():获取当前面板的宽度和高度,用于指定绘制图像时按照面板的实际大小进行拉伸或缩放,确保图像填满整个面板 // getWidth(), getHeight():获取当前面板的宽度和高度,用于指定绘制图像时按照面板的实际大小进行拉伸或缩放,确保图像填满整个面板

@ -52,9 +52,10 @@ public class inOrderServiceImpl implements inOrderService{
try { try {
// 准备SQL语句根据订单号查找特定的订单 // 准备SQL语句根据订单号查找特定的订单
preparedStatement = conn.prepareStatement("select * from inOrder where iNumber = ?"); preparedStatement = conn.prepareStatement("select * from inOrder where iNumber = ?"); //根据订单号查询订单
preparedStatement.setString(1, iNumber); // 设置订单号参数 preparedStatement.setString(1, iNumber); // 设置订单号参数
resultSet = preparedStatement.executeQuery(); // 执行查询 resultSet = preparedStatement.executeQuery(); // 执行查询
// 设置查询到的订单的属性到InOrder对象中
if (resultSet.next()) { // 如果找到对应记录 if (resultSet.next()) { // 如果找到对应记录
// 从结果集中获取属性并设置到inOrder对象 // 从结果集中获取属性并设置到inOrder对象
inOrder.setiNumber(resultSet.getString("iNumber")); inOrder.setiNumber(resultSet.getString("iNumber"));

@ -13,21 +13,29 @@ import com.lingnan.supermarket.dto.InOrder;
import com.lingnan.supermarket.dto.OutOrder; import com.lingnan.supermarket.dto.OutOrder;
import com.lingnan.supermarket.utils.JDBCUtil; import com.lingnan.supermarket.utils.JDBCUtil;
public class outOrderServiceImpl implements outOrderService{ // 实现outOrderService接口--用于处理与出库订单相关的数据访问操作
public class outOrderServiceImpl implements outOrderService {
// 查询所有出库订单信息,并按照日期降序排列返回
@Override @Override
public Vector<OutOrder> findAllOutOrder() { public Vector<OutOrder> findAllOutOrder() {
// 存储查询到的所有出库订单信息的向量集合
Vector<OutOrder> outOrders = new Vector<OutOrder>(); Vector<OutOrder> outOrders = new Vector<OutOrder>();
// 获取数据库连接
Connection conn = JDBCUtil.getConn(); Connection conn = JDBCUtil.getConn();
PreparedStatement preparedStatement = null; PreparedStatement preparedStatement = null;
ResultSet resultSet=null; ResultSet resultSet = null;
// 从OutOrder表中查询所有记录并按oDate字段降序排序
String SQL = "select * from OutOrder order by oDate desc"; String SQL = "select * from OutOrder order by oDate desc";
try { try {
// 根据SQL语句创建预编译的Statement对象
preparedStatement = conn.prepareStatement(SQL); preparedStatement = conn.prepareStatement(SQL);
// 执行查询操作
resultSet = preparedStatement.executeQuery(); resultSet = preparedStatement.executeQuery();
while(resultSet.next()) { // 遍历结果集将每条记录封装成OutOrder对象并添加到outOrders集合中
while (resultSet.next()) {
OutOrder outOrder = new OutOrder(); OutOrder outOrder = new OutOrder();
outOrder.setoNumber(resultSet.getString("oNumber")); outOrder.setoNumber(resultSet.getString("oNumber"));
outOrder.setAllOutPrice(resultSet.getFloat("allOutPrice")); outOrder.setAllOutPrice(resultSet.getFloat("allOutPrice"));
@ -39,113 +47,143 @@ public class outOrderServiceImpl implements outOrderService{
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace(); e.printStackTrace();
} finally { } finally {
// 关闭结果集、预编译语句以及数据库连接,释放相关资源
JDBCUtil.close(resultSet, preparedStatement, conn); JDBCUtil.close(resultSet, preparedStatement, conn);
} }
return outOrders; return outOrders;
} }
// 根据订单编号查询对应的出库订单信息
@Override @Override
public OutOrder findByIdOutOrder(String oNumber) { public OutOrder findByIdOutOrder(String oNumber) {
// 用于存储查询到的出库订单信息的对象
OutOrder outOrder = new OutOrder(); OutOrder outOrder = new OutOrder();
// 获取数据库连接
Connection conn = JDBCUtil.getConn(); Connection conn = JDBCUtil.getConn();
PreparedStatement preparedStatement = null; PreparedStatement preparedStatement = null;
ResultSet resultSet = null; ResultSet resultSet = null;
try { try {
preparedStatement = conn.prepareStatement("select * from outOrder where oNumber = ?"); // 根据订单编号查询对应的出库订单记录
preparedStatement = conn.prepareStatement("select * from outOrder where oNumber =?");
// 设置查询的订单编号
preparedStatement.setString(1, oNumber); preparedStatement.setString(1, oNumber);
// 执行查询操作
resultSet = preparedStatement.executeQuery(); resultSet = preparedStatement.executeQuery();
// 如果结果集中有记录说明找到了对应的订单则将记录中的各字段值封装到outOrder对象中
if (resultSet.next()) { if (resultSet.next()) {
outOrder.setoNumber(resultSet.getString("oNumber")); outOrder.setoNumber(resultSet.getString("oNumber"));
outOrder.setAllOutPrice(resultSet.getFloat("allOutPrice")); outOrder.setAllOutPrice(resultSet.getFloat("allOutPrice"));
outOrder.setoDate(resultSet.getDate("oDate")); outOrder.setoDate(resultSet.getDate("oDate"));
outOrder.setPrincipal(resultSet.getString("principal")); outOrder.setPrincipal(resultSet.getString("principal"));
} else { } else {
return null; // 没有找到该订单或订单不存在返回null // 如果结果集中没有记录说明没有找到该订单或订单不存在返回null
return null;
} }
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace(); e.printStackTrace();
} finally { } finally {
// 关闭结果集、预编译语句以及数据库连接,释放相关资源
JDBCUtil.close(resultSet, preparedStatement, conn); JDBCUtil.close(resultSet, preparedStatement, conn);
} }
return outOrder; return outOrder;
} }
// 向数据库中添加一条出库订单记录
@Override @Override
public int addOutOrder(String oNumber, float allOutPrice) { public int addOutOrder(String oNumber, float allOutPrice) {
int flag = 0; int flag = 0;
// 获取当前系统时间戳用于作为出库订单的日期oDate字段值表示订单创建时间
Timestamp oDate = new Timestamp(System.currentTimeMillis()); Timestamp oDate = new Timestamp(System.currentTimeMillis());
// 获取数据库连接
Connection conn = JDBCUtil.getConn(); Connection conn = JDBCUtil.getConn();
PreparedStatement preparedStatement = null; PreparedStatement preparedStatement = null;
try { try {
preparedStatement = conn.prepareStatement // 创建预编译的SQL插入语句向outOrder表中插入一条记录
("insert into outOrder values (?,?,?,?)"); preparedStatement = conn.prepareStatement("insert into outOrder values (?,?,?,?)");
// 设置预编译语句中的参数,依次为订单编号、总出库价格、订单日期、负责人(此处写死为"a1",可能后续需要改进)
preparedStatement.setString(1, oNumber); preparedStatement.setString(1, oNumber);
preparedStatement.setFloat(2, allOutPrice); preparedStatement.setFloat(2, allOutPrice);
preparedStatement.setTimestamp(3, oDate); preparedStatement.setTimestamp(3, oDate);
preparedStatement.setString(4, "a1"); preparedStatement.setString(4, "a1");
// 执行插入操作
preparedStatement.executeUpdate(); preparedStatement.executeUpdate();
// 如果插入成功将标志位flag设置为1表示操作成功
flag = 1; flag = 1;
} catch (SQLException e) { } catch (SQLException e) {
// 如果插入出现异常将标志位flag设置为 -1表示操作失败
flag = -1; flag = -1;
e.printStackTrace(); e.printStackTrace();
} finally { } finally {
JDBCUtil.close(null,preparedStatement, conn); // 关闭预编译语句以及数据库连接,释放相关资源
JDBCUtil.close(null, preparedStatement, conn);
} }
return flag; return flag;
} }
// 根据订单编号从数据库中删除对应的出库订单记录
@Override @Override
public int deleteOutOrder(String oNumber) { public int deleteOutOrder(String oNumber) {
int flag = 0; int flag = 0;
// 获取数据库连接
Connection conn = JDBCUtil.getConn(); Connection conn = JDBCUtil.getConn();
PreparedStatement preparedStatement = null; PreparedStatement preparedStatement = null;
try { try {
preparedStatement = conn.prepareStatement // 创建预编译的SQL删除语句根据订单编号oNumber删除对应的出库订单记录
("delete from outOrder where oNumber = ?"); preparedStatement = conn.prepareStatement("delete from outOrder where oNumber =?");
// 设置预编译语句中的参数,即要删除的订单编号
preparedStatement.setString(1, oNumber); preparedStatement.setString(1, oNumber);
// 执行删除操作
preparedStatement.executeUpdate(); preparedStatement.executeUpdate();
// 如果删除成功将标志位flag设置为1表示操作成功
flag = 1; flag = 1;
} catch (SQLException e) { } catch (SQLException e) {
// 如果删除出现异常将标志位flag设置为 -1表示操作失败
flag = -1; flag = -1;
e.printStackTrace(); e.printStackTrace();
} finally { } finally {
JDBCUtil.close(null,preparedStatement, conn); // 关闭预编译语句以及数据库连接,释放相关资源
JDBCUtil.close(null, preparedStatement, conn);
} }
return flag; return flag;
} }
// 获取指定日期的今日出库金额总和(此处方法名可能有点混淆,从代码逻辑看是获取指定日期的出库金额总和)
public Float TodayOutPrice(String date) {
// 创建一个InOrder对象
InOrder inOrder = new InOrder();
// 获取数据库连接
Connection conn = JDBCUtil.getConn();
PreparedStatement preparedStatement = null;
ResultSet resultSet = null;
// 用于存储查询到的今日出库金额总和初始为0
Float allInPrice = (float) 0;
//获取今日进货金额 try {
public Float TodayOutPrice(String date) { // 通过求和函数查询指定日期范围内的总出库价格
preparedStatement = conn.prepareStatement("select sum(allOutPrice) from outOrder where oDate>=? and oDate<=date_add(?,interval 1 day)");
InOrder inOrder = new InOrder(); // 设置两个参数均为传入的日期值,用于限定查询的日期范围
Connection conn = JDBCUtil.getConn(); preparedStatement.setString(1, date);
PreparedStatement preparedStatement = null; preparedStatement.setString(2, date);
ResultSet resultSet = null; // 执行查询操作
Float allInPrice=(float) 0; resultSet = preparedStatement.executeQuery();
// 如果结果集中有记录说明查询到了对应的金额数据则将其取出赋值给allInPrice变量
try { if (resultSet.next()) {
preparedStatement = conn.prepareStatement("select sum(allOutPrice) from outOrder where oDate>=? and oDate<=date_add(?,interval 1 day)"); allInPrice = resultSet.getFloat("sum(allOutPrice)");
preparedStatement.setString(1, date);
preparedStatement.setString(2, date);
resultSet = preparedStatement.executeQuery();
if (resultSet.next()) {
allInPrice=resultSet.getFloat("sum(allOutPrice)");
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
JDBCUtil.close(resultSet, preparedStatement, conn);
} }
return allInPrice; } catch (SQLException e) {
e.printStackTrace();
} finally {
// 关闭结果集、预编译语句以及数据库连接,释放相关资源
JDBCUtil.close(resultSet, preparedStatement, conn);
} }
return allInPrice;
}
} }

@ -12,21 +12,29 @@ import com.lingnan.supermarket.dto.InRecord;
import com.lingnan.supermarket.dto.OutRecord; import com.lingnan.supermarket.dto.OutRecord;
import com.lingnan.supermarket.utils.JDBCUtil; import com.lingnan.supermarket.utils.JDBCUtil;
public class outRecordServiceImpl implements outRecordService{ // 实现了outRecordService接口--用于处理出库记录相关的数据操作逻辑
public class outRecordServiceImpl implements outRecordService {
// 查询所有出库记录信息
@Override @Override
public Vector<OutRecord> findAllOutRecord() { public Vector<OutRecord> findAllOutRecord() {
// 用于存储查询到的所有出库记录信息的向量集合
Vector<OutRecord> outRecords = new Vector<OutRecord>(); Vector<OutRecord> outRecords = new Vector<OutRecord>();
// 通过JDBCUtil工具类的静态方法来获取数据库连接
Connection conn = JDBCUtil.getConn(); Connection conn = JDBCUtil.getConn();
PreparedStatement preparedStatement = null; PreparedStatement preparedStatement = null;
ResultSet resultSet=null; ResultSet resultSet = null;
// 从outRecord表中获取所有记录
String SQL = "select * from outRecord"; String SQL = "select * from outRecord";
try { try {
// 根据SQL语句创建预编译的Statement对象
preparedStatement = conn.prepareStatement(SQL); preparedStatement = conn.prepareStatement(SQL);
// 执行查询操作
resultSet = preparedStatement.executeQuery(); resultSet = preparedStatement.executeQuery();
while(resultSet.next()) { // 遍历结果集将每条记录封装成OutRecord对象并添加到outRecords集合中
while (resultSet.next()) {
OutRecord outRecord = new OutRecord(); OutRecord outRecord = new OutRecord();
outRecord.setoNumber(resultSet.getString("oNumber")); outRecord.setoNumber(resultSet.getString("oNumber"));
outRecord.setSum(resultSet.getInt("sum")); outRecord.setSum(resultSet.getInt("sum"));
@ -37,24 +45,33 @@ public class outRecordServiceImpl implements outRecordService{
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace(); e.printStackTrace();
} finally { } finally {
// 关闭结果集、预编译语句以及数据库连接,释放相关资源
JDBCUtil.close(resultSet, preparedStatement, conn); JDBCUtil.close(resultSet, preparedStatement, conn);
} }
return outRecords; return outRecords;
} }
// 根据订单编号查询对应的出库记录信息,返回符合条件的多条记录
@Override @Override
public Vector<OutRecord> findByIdOutRecordr(String oNumber) { public Vector<OutRecord> findByIdOutRecordr(String oNumber) {
OutRecord outRecord ; // 用于临时存储单个出库记录信息的对象
OutRecord outRecord;
// 获取数据库连接
Connection conn = JDBCUtil.getConn(); Connection conn = JDBCUtil.getConn();
PreparedStatement preparedStatement = null; PreparedStatement preparedStatement = null;
ResultSet resultSet = null; ResultSet resultSet = null;
// 存储查询到的符合条件的所有出库记录信息的向量集合
Vector<OutRecord> v = new Vector<OutRecord>(); Vector<OutRecord> v = new Vector<OutRecord>();
try { try {
preparedStatement = conn.prepareStatement("select * from outRecord where oNumber = ?"); //根据给定的订单编号查询outRecord表中对应的记录
preparedStatement = conn.prepareStatement("select * from outRecord where oNumber =?");
// 设置要查询的订单编号
preparedStatement.setString(1, oNumber); preparedStatement.setString(1, oNumber);
// 执行查询操作,获取结果集
resultSet = preparedStatement.executeQuery(); resultSet = preparedStatement.executeQuery();
// 遍历结果集将每条符合条件的记录封装成OutRecord对象并添加到向量集合v中
while (resultSet.next()) { while (resultSet.next()) {
outRecord = new OutRecord(); outRecord = new OutRecord();
outRecord.setoNumber(resultSet.getString("oNumber")); outRecord.setoNumber(resultSet.getString("oNumber"));
@ -67,63 +84,78 @@ public class outRecordServiceImpl implements outRecordService{
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace(); e.printStackTrace();
} finally { } finally {
// 关闭结果集、预编译语句以及数据库连接,释放相关资源
JDBCUtil.close(resultSet, preparedStatement, conn); JDBCUtil.close(resultSet, preparedStatement, conn);
} }
return v; return v;
} }
// 向数据库中添加一条出库记录信息
@Override @Override
public int addoutRecord(OutRecord or) { public int addoutRecord(OutRecord or) {
int flag = 0; int flag = 0;
// 获取要添加的出库记录对象中的订单编号
String oNumber = or.getoNumber(); String oNumber = or.getoNumber();
// 获取要添加的出库记录对象中的数量
int sum = or.getSum(); int sum = or.getSum();
// 获取要添加的出库记录对象中的出库价格
Float outPrice = or.getOutPrice(); Float outPrice = or.getOutPrice();
// 获取数据库连接
Connection conn = JDBCUtil.getConn(); Connection conn = JDBCUtil.getConn();
PreparedStatement preparedStatement = null; PreparedStatement preparedStatement = null;
try { try {
preparedStatement = conn.prepareStatement // 创建预编译的SQL插入语句向outRecord表中插入一条记录包含订单编号、数量、出库价格三个字段的值
("insert into outRecord values (?,?,?)"); preparedStatement = conn.prepareStatement("insert into outRecord values (?,?,?)");
// 设置预编译语句中的参数,依次为订单编号、数量、出库价格
preparedStatement.setString(1, oNumber); preparedStatement.setString(1, oNumber);
preparedStatement.setInt(2, sum); preparedStatement.setInt(2, sum);
preparedStatement.setFloat(3, outPrice); preparedStatement.setFloat(3, outPrice);
// 执行插入操作
preparedStatement.executeUpdate(); preparedStatement.executeUpdate();
// 如果插入成功将标志位flag设置为1表示操作成功
flag = 1; flag = 1;
} catch (SQLException e) { } catch (SQLException e) {
// 如果插入出现异常将标志位flag设置为 -1表示操作失败
flag = -1; flag = -1;
e.printStackTrace(); e.printStackTrace();
} finally { } finally {
JDBCUtil.close(null,preparedStatement, conn); // 关闭预编译语句以及数据库连接释放相关资源此处结果集为null
JDBCUtil.close(null, preparedStatement, conn);
} }
return flag; return flag;
} }
// 根据订单编号从数据库中删除对应的出库记录信息
@Override @Override
public int deleteOutOrder(String oNumber) { public int deleteOutOrder(String oNumber) {
int flag = 0; int flag = 0;
// 获取数据库连接
Connection conn = JDBCUtil.getConn(); Connection conn = JDBCUtil.getConn();
PreparedStatement preparedStatement = null; PreparedStatement preparedStatement = null;
try { try {
preparedStatement = conn.prepareStatement // 创建预编译的SQL删除语句根据给定的订单编号删除outRecord表中对应的记录
("delete from outRecord where oNumber = ?"); preparedStatement = conn.prepareStatement("delete from outRecord where oNumber =?");
// 设置要删除的订单编号
preparedStatement.setString(1, oNumber); preparedStatement.setString(1, oNumber);
// 执行删除操作
preparedStatement.executeUpdate(); preparedStatement.executeUpdate();
// 如果删除成功将标志位flag设置为1表示操作成功
flag = 1; flag = 1;
} catch (SQLException e) { } catch (SQLException e) {
// 如果删除出现异常将标志位flag设置为 -1表示操作失败
flag = -1; flag = -1;
e.printStackTrace(); e.printStackTrace();
} finally { } finally {
JDBCUtil.close(null,preparedStatement, conn); // 关闭预编译语句以及数据库连接释放相关资源此处结果集为null
JDBCUtil.close(null, preparedStatement, conn);
} }
return flag; return flag;
} }
} }

@ -12,214 +12,241 @@ import com.lingnan.supermarket.dao.prodCatalogService;
import com.lingnan.supermarket.dto.ProdCatalog; import com.lingnan.supermarket.dto.ProdCatalog;
import com.lingnan.supermarket.utils.JDBCUtil; import com.lingnan.supermarket.utils.JDBCUtil;
public class prodCatalogImpl implements prodCatalogService{ // 实现prodCatalogService接口--用于处理商品目录相关的数据持久化操作
public class prodCatalogImpl implements prodCatalogService {
/*将商品目录表和商品表联合查询*/ // 将商品目录表和商品表联合查询,获取商品目录及相关商品信息
@Override @Override
public Vector<ProdCatalog> findProdCatalogAndProd() { public Vector<ProdCatalog> findProdCatalogAndProd() {
Connection conn=JDBCUtil.getConn(); // 通过JDBCUtil工具类来获取已经配置好的连接对象
Connection conn = JDBCUtil.getConn();
// 创建一个Vector容器存放查询到的ProdCatalog对象
Vector<ProdCatalog> v = new Vector<ProdCatalog>(); Vector<ProdCatalog> v = new Vector<ProdCatalog>();
ProdCatalog prodCatalog; ProdCatalog prodCatalog;
PreparedStatement pstmt = null; PreparedStatement pstmt = null;
ResultSet resultSet=null; ResultSet resultSet = null;
try { try {
// 通过预编译语句准备调用存储过程allProdCatalog
pstmt = conn.prepareStatement("call allProdCatalog()"); pstmt = conn.prepareStatement("call allProdCatalog()");
// 执行查询操作
resultSet = pstmt.executeQuery(); resultSet = pstmt.executeQuery();
while(resultSet.next()){ // 遍历结果集将每一条记录封装成ProdCatalog对象并添加到Vector容器中
while (resultSet.next()) {
prodCatalog = new ProdCatalog(); prodCatalog = new ProdCatalog();
// 设置ProdCatalog对象的id属性
prodCatalog.setId(resultSet.getString("id")); prodCatalog.setId(resultSet.getString("id"));
// 设置ProdCatalog对象的name属性
prodCatalog.setName(resultSet.getString("name")); prodCatalog.setName(resultSet.getString("name"));
v.add(prodCatalog); v.add(prodCatalog);
} }
} catch (SQLException e) { } catch (SQLException e) {
// TODO Auto-generated catch block // 若出现SQL异常打印异常栈信息
e.printStackTrace(); e.printStackTrace();
}finally{ } finally {
// 通过JDBCUtil工具类提供的方法进行关闭操作
JDBCUtil.close(resultSet, pstmt, conn); JDBCUtil.close(resultSet, pstmt, conn);
} }
return v; return v;
} }
// 根据给定的id1查找商品目录名称
@Override @Override
public String findProdCatalog(String id1 ) { public String findProdCatalog(String id1) {
Connection conn=JDBCUtil.getConn(); // 获取数据库连接
Connection conn = JDBCUtil.getConn();
PreparedStatement pstmt = null; PreparedStatement pstmt = null;
ResultSet resultSet=null; ResultSet resultSet = null;
String catalog=null; String catalog = null;
try { try {
// 预编译SQL语句用于根据给定的id2查询prodCatalog表中的记录
pstmt = conn.prepareStatement("select *from prodCatalog where id2 =?"); pstmt = conn.prepareStatement("select *from prodCatalog where id2 =?");
pstmt.setString(1,id1); // 设置SQL语句中的参数将传入的id1赋值给查询语句中的占位符
pstmt.setString(1, id1);
// 执行查询操作
resultSet = pstmt.executeQuery(); resultSet = pstmt.executeQuery();
if(resultSet.next()){ // 如果结果集中有下一条记录则获取对应记录中的name1字段值作为商品目录名称
catalog=resultSet.getString("name1"); if (resultSet.next()) {
catalog = resultSet.getString("name1");
} }
} catch (SQLException e) { } catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace(); e.printStackTrace();
}finally{ } finally {
// 关闭相关资源
JDBCUtil.close(resultSet, pstmt, conn); JDBCUtil.close(resultSet, pstmt, conn);
} }
return catalog; return catalog;
} }
// 向商品目录表prodCatalog中添加一条记录
@Override @Override
public int addProdCatalog(String id1, String id2) { public int addProdCatalog(String id1, String id2) {
int flag=0; int flag = 0;
String name1=null; String name1 = null;
//01 食品 02 电器 03 生活用品 04 其他 // 根据传入的id1判断商品类别名称01对应食品02对应电器03对应生活用品04对应其他
if(id1.equals("01")) if (id1.equals("01"))
name1="食品"; name1 = "食品";
else if(id1.equals("02")) else if (id1.equals("02"))
name1="电器"; name1 = "电器";
else if(id1.equals("03")) else if (id1.equals("03"))
name1="生活用品"; name1 = "生活用品";
else else
name1="其他"; name1 = "其他";
//连接jdbc // 获取数据库连接
Connection conn=JDBCUtil.getConn(); Connection conn = JDBCUtil.getConn();
PreparedStatement pstmt = null; PreparedStatement pstmt = null;
ResultSet resultSet=null; ResultSet resultSet = null;
try { try {
// 预编译插入数据的SQL语句向prodCatalog表中插入三条数据
pstmt = conn.prepareStatement("insert into prodCatalog values(?,?,?)"); pstmt = conn.prepareStatement("insert into prodCatalog values(?,?,?)");
pstmt.setString(1,id1); // 设置SQL语句中的第一个参数
pstmt.setString(2,name1); pstmt.setString(1, id1);
pstmt.setString(3,id2); // 设置SQL语句中的第二个参数
pstmt.setString(2, name1);
// 设置SQL语句中的第三个参数
pstmt.setString(3, id2);
// 执行插入操作若插入成功将flag置为1表示添加成功
pstmt.executeUpdate(); pstmt.executeUpdate();
flag=1; flag = 1;
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace(); e.printStackTrace();
}finally{ } finally {
// 关闭相关资源
JDBCUtil.close(resultSet, pstmt, conn); JDBCUtil.close(resultSet, pstmt, conn);
} }
return flag; return flag;
} }
// 根据给定的id2删除商品目录表prodCatalog中的一条记录
@Override @Override
public int deleteProdCatalog(String id2) { public int deleteProdCatalog(String id2) {
int flag=0; int flag = 0;
//连接jdbc // 获取数据库连接
Connection conn=JDBCUtil.getConn(); Connection conn = JDBCUtil.getConn();
PreparedStatement pstmt = null; PreparedStatement pstmt = null;
ResultSet resultSet=null; ResultSet resultSet = null;
try { try {
// 预编译删除数据的SQL语句根据传入的id2作为条件从prodCatalog表中删除对应的记录
pstmt = conn.prepareStatement("delete from prodCatalog where id2=?"); pstmt = conn.prepareStatement("delete from prodCatalog where id2=?");
pstmt.setString(1,id2); // 设置SQL语句中的参数将传入的id2赋值给查询语句中的占位符?
pstmt.setString(1, id2);
// 执行删除操作若删除成功将flag置为1表示删除成功
pstmt.executeUpdate(); pstmt.executeUpdate();
flag=1; flag = 1;
} catch (SQLException e) { } catch (SQLException e) {
// TODO Auto-generated catch block // 若出现SQL异常打印异常栈信息
e.printStackTrace(); e.printStackTrace();
}finally{ } finally {
// 关闭相关资源
JDBCUtil.close(resultSet, pstmt, conn); JDBCUtil.close(resultSet, pstmt, conn);
} }
return flag; return flag;
} }
// 根据商品类production的name查询并输出类别id如果传入的name为"全部"则直接返回默认的catalogid "0"
@Override @Override
//根据商品类production的name查询并输出类别id
public String findProdCatalogByname(String name) { public String findProdCatalogByname(String name) {
Connection conn=JDBCUtil.getConn(); Connection conn = JDBCUtil.getConn();
PreparedStatement pstmt = null; PreparedStatement pstmt = null;
ResultSet resultSet=null; ResultSet resultSet = null;
String catalogid="0"; String catalogid = "0";
try { try {
if(name.equals("全部")){ // 如果传入的商品名称为"全部"则直接返回默认的catalogid
if (name.equals("全部")) {
return catalogid; return catalogid;
} }
// 预编译SQL语句用于根据给定的商品名称查询prodCatalog表中的记录获取对应的类别id
pstmt = conn.prepareStatement("select * from prodCatalog where name =?"); pstmt = conn.prepareStatement("select * from prodCatalog where name =?");
pstmt.setString(1,name); // 设置SQL语句中的参数将传入的name赋值给查询语句中的占位符
pstmt.setString(1, name);
// 执行查询操作,获取结果集
resultSet = pstmt.executeQuery(); resultSet = pstmt.executeQuery();
if(resultSet.next()){ // 如果结果集中有下一条记录则获取对应记录中的id字段值作为类别id
catalogid=resultSet.getString("id"); if (resultSet.next()) {
catalogid = resultSet.getString("id");
} }
} catch (SQLException e) { } catch (SQLException e) {
// TODO Auto-generated catch block // 若出现SQL异常打印异常栈信息
e.printStackTrace(); e.printStackTrace();
}finally{ } finally {
// 关闭相关资源
JDBCUtil.close(resultSet, pstmt, conn); JDBCUtil.close(resultSet, pstmt, conn);
} }
return catalogid; return catalogid;
} }
/* public static void main(String[] args) { /*
ProdCatalog p=new ProdCatalog(); public static void main(String[] args) {
prodCatalogImpl pi=new prodCatalogImpl(); ProdCatalog p = new ProdCatalog();
p.setName("全部"); prodCatalogImpl pi = new prodCatalogImpl();
System.out.println(pi.findProdCatalogByname(p.getName())); p.setName("全部");
}*/ System.out.println(pi.findProdCatalogByname(p.getName()));
}
*/
// 查询商品目录表prodCatalog中的所有商品类别名称并添加"全部"作为第一个元素后返回
@Override @Override
public ArrayList<String> findNameProdCatalog() { public ArrayList<String> findNameProdCatalog() {
Connection conn=JDBCUtil.getConn(); Connection conn = JDBCUtil.getConn();
ArrayList<String> v = new ArrayList<String>(); ArrayList<String> v = new ArrayList<String>();
// 先添加"全部"作为默认的第一个类别名称
v.add("全部"); v.add("全部");
ProdCatalog prodCatalog; ProdCatalog prodCatalog;
PreparedStatement pstmt = null; PreparedStatement pstmt = null;
ResultSet resultSet=null; ResultSet resultSet = null;
try { try {
// 预编译查询所有记录的SQL语句用于获取prodCatalog表中的所有商品类别名称
pstmt = conn.prepareStatement("select * from prodCatalog"); pstmt = conn.prepareStatement("select * from prodCatalog");
// 执行查询操作
resultSet = pstmt.executeQuery(); resultSet = pstmt.executeQuery();
while(resultSet.next()){ // 遍历结果集将每条记录中的商品类别名称添加到ArrayList容器中
while (resultSet.next()) {
v.add(resultSet.getString("name")); v.add(resultSet.getString("name"));
} }
} catch (SQLException e) { } catch (SQLException e) {
// TODO Auto-generated catch block // 若出现SQL异常打印异常栈信息
e.printStackTrace(); e.printStackTrace();
}finally{ } finally {
// 关闭相关资源
JDBCUtil.close(resultSet, pstmt, conn); JDBCUtil.close(resultSet, pstmt, conn);
} }
return v; return v;
} }
/*public static void main(String[] args) { /*
prodCatalogImpl pi=new prodCatalogImpl(); public static void main(String[] args) {
ArrayList<String>log=null; prodCatalogImpl pi = new prodCatalogImpl();
ArrayList<String> log = null;
log=pi.findNameProdCatalog();
String []s=new String[log.size()];
for(int i=0;i<log.size();i++)
{s[i]=log.get(i);
System.out.println(log.get(i));
}
for(int i=0;i<s.length;i++)
{
System.out.println(s[i]);
}
}*/ log = pi.findNameProdCatalog();
String[] s = new String[log.size()];
for (int i = 0; i < log.size(); i++) {
s[i] = log.get(i);
System.out.println(log.get(i));
}
for (int i = 0; i < s.length; i++) {
System.out.println(s[i]);
}
}
*/
} }

@ -19,73 +19,73 @@ public class productionImpl implements productionService {
public Vector<Production> findAllproduction() { public Vector<Production> findAllproduction() {
Vector<Production> productions = new Vector<Production>(); Vector<Production> productions = new Vector<Production>();
Connection conn = JDBCUtil.getConn(); Connection conn = JDBCUtil.getConn(); // 获取数据库连接
String SQL = "select * from production where delmark = 1"; String SQL = "select * from production where delmark = 1"; // SQL查询语句只查询未被删除的商品
PreparedStatement preparedStatement = null; PreparedStatement preparedStatement = null;
ResultSet resultSet = null; ResultSet resultSet = null;
try { try {
preparedStatement = conn.prepareStatement(SQL); preparedStatement = conn.prepareStatement(SQL); // 创建PreparedStatement对象
resultSet = preparedStatement.executeQuery(); resultSet = preparedStatement.executeQuery(); // 执行查询,获取结果集
while (resultSet.next()) { while (resultSet.next()) { // 遍历结果集
Production production = new Production(); Production production = new Production();
production.setId(resultSet.getString("id")); production.setId(resultSet.getString("id")); // 设置商品ID
production.setName(resultSet.getString("name")); production.setName(resultSet.getString("name")); // 设置商品名称
production.setInPrice(resultSet.getFloat("inPrice")); production.setInPrice(resultSet.getFloat("inPrice")); // 设置进价
production.setOutPrice(resultSet.getFloat("OutPrice")); production.setOutPrice(resultSet.getFloat("OutPrice")); // 设置售价
production.setLife(resultSet.getInt("life")); production.setLife(resultSet.getInt("life")); // 设置保质期
production.setSum(resultSet.getInt("sum")); production.setSum(resultSet.getInt("sum")); // 设置库存数量
production.setSupplyId(resultSet.getInt("supplyId")); production.setSupplyId(resultSet.getInt("supplyId")); // 设置供应商ID
production.setId2(resultSet.getString("id2")); production.setId2(resultSet.getString("id2")); // 设置商品类别ID
production.setName2(resultSet.getString("name2")); production.setName2(resultSet.getString("name2")); // 设置商品类别名称
production.setDelmark(resultSet.getInt("delmark")); production.setDelmark(resultSet.getInt("delmark")); // 设置删除标记
productions.add(production); productions.add(production); // 将商品信息添加到Vector中
} }
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace(); e.printStackTrace();
} finally { } finally {
JDBCUtil.close(resultSet, preparedStatement, conn); JDBCUtil.close(resultSet, preparedStatement, conn); // 关闭数据库资源
} }
return productions; return productions; // 返回所有商品信息
} }
/* 用于收银系统通过商品id返回所有信息 */ /* 用于收银系统通过商品id返回所有信息 */
public Production findByIdProduction(String id) { public Production findByIdProduction(String id) {
Production production = new Production(); Production production = new Production();
Connection conn = JDBCUtil.getConn(); Connection conn = JDBCUtil.getConn(); // 获取数据库连接
PreparedStatement preparedStatement = null; PreparedStatement preparedStatement = null;
ResultSet resultSet = null; ResultSet resultSet = null;
try { try {
preparedStatement = conn preparedStatement = conn
.prepareStatement("select * from production where id=? and delmark = 1"); .prepareStatement("select * from production where id=? and delmark = 1"); // 查询指定ID且未被删除的商品
preparedStatement.setString(1, id); preparedStatement.setString(1, id); // 设置查询参数
resultSet = preparedStatement.executeQuery(); resultSet = preparedStatement.executeQuery(); // 执行查询
if (resultSet.next()) { if (resultSet.next()) { // 如果找到商品
production.setId(resultSet.getString("id")); production.setId(resultSet.getString("id")); // 设置商品ID
production.setName(resultSet.getString("name")); production.setName(resultSet.getString("name")); // 设置商品名称
production.setInPrice(resultSet.getFloat("inPrice")); production.setInPrice(resultSet.getFloat("inPrice")); // 设置进价
production.setOutPrice(resultSet.getFloat("OutPrice")); production.setOutPrice(resultSet.getFloat("OutPrice")); // 设置售价
production.setLife(resultSet.getInt("life")); production.setLife(resultSet.getInt("life")); // 设置保质期
production.setSum(resultSet.getInt("sum")); production.setSum(resultSet.getInt("sum")); // 设置库存数量
production.setSupplyId(resultSet.getInt("supplyId")); production.setSupplyId(resultSet.getInt("supplyId")); // 设置供应商ID
production.setId2(resultSet.getString("id2")); production.setId2(resultSet.getString("id2")); // 设置商品类别ID
production.setName2(resultSet.getString("name2")); production.setName2(resultSet.getString("name2")); // 设置商品类别名称
production.setDelmark(resultSet.getInt("delmark")); production.setDelmark(resultSet.getInt("delmark")); // 设置删除标记
} else { } else {
System.out.println("未找到"); System.out.println("未找到");
return null; return null; // 如果未找到商品返回null
} }
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace(); e.printStackTrace();
} finally { } finally {
JDBCUtil.close(resultSet, preparedStatement, conn); JDBCUtil.close(resultSet, preparedStatement, conn); // 关闭数据库资源
} }
return production; return production; // 返回商品信息
} }
@Override @Override
@ -94,35 +94,35 @@ public class productionImpl implements productionService {
* *
*/ */
Vector<Production> productions = new Vector<Production>(); Vector<Production> productions = new Vector<Production>();
Connection conn = JDBCUtil.getConn(); Connection conn = JDBCUtil.getConn(); // 获取数据库连接
PreparedStatement preparedStatement = null; PreparedStatement preparedStatement = null;
ResultSet resultSet = null; ResultSet resultSet = null;
try { try {
preparedStatement = conn.prepareStatement("select * from production where name like ? and delmark = 1"); preparedStatement = conn.prepareStatement("select * from production where name like ? and delmark = 1"); // 模糊查询商品名称
String s='%'+name+'%'; String s = '%' + name + '%'; // 构造模糊查询字符串
preparedStatement.setString(1, s); preparedStatement.setString(1, s); // 设置查询参数
resultSet = preparedStatement.executeQuery(); resultSet = preparedStatement.executeQuery(); // 执行查询
while (resultSet.next()) { while (resultSet.next()) { // 遍历结果集
Production production = new Production(); Production production = new Production();
production.setId(resultSet.getString("id")); production.setId(resultSet.getString("id")); // 设置商品ID
production.setName(resultSet.getString("name")); production.setName(resultSet.getString("name")); // 设置商品名称
production.setInPrice(resultSet.getFloat("inPrice")); production.setInPrice(resultSet.getFloat("inPrice")); // 设置进价
production.setOutPrice(resultSet.getFloat("OutPrice")); production.setOutPrice(resultSet.getFloat("OutPrice")); // 设置售价
production.setLife(resultSet.getInt("life")); production.setLife(resultSet.getInt("life")); // 设置保质期
production.setSum(resultSet.getInt("sum")); production.setSum(resultSet.getInt("sum")); // 设置库存数量
production.setSupplyId(resultSet.getInt("supplyId")); production.setSupplyId(resultSet.getInt("supplyId")); // 设置供应商ID
production.setId2(resultSet.getString("id2")); production.setId2(resultSet.getString("id2")); // 设置商品类别ID
production.setName2(resultSet.getString("name2")); production.setName2(resultSet.getString("name2")); // 设置商品类别名称
production.setDelmark(resultSet.getInt("delmark")); production.setDelmark(resultSet.getInt("delmark")); // 设置删除标记
productions.add(production); productions.add(production); // 将商品信息添加到Vector中
} }
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace(); e.printStackTrace();
} finally { } finally {
JDBCUtil.close(resultSet, preparedStatement, conn); JDBCUtil.close(resultSet, preparedStatement, conn); // 关闭数据库资源
} }
return productions; return productions; // 返回所有匹配的商品信息
} }
@Override @Override
@ -131,34 +131,34 @@ public class productionImpl implements productionService {
*/ */
public Production findByNameProduction(String name) { public Production findByNameProduction(String name) {
Production production = new Production(); Production production = new Production();
Connection conn = JDBCUtil.getConn(); Connection conn = JDBCUtil.getConn(); // 获取数据库连接
PreparedStatement preparedStatement = null; PreparedStatement preparedStatement = null;
ResultSet resultSet = null; ResultSet resultSet = null;
try { try {
preparedStatement = conn preparedStatement = conn
.prepareStatement("select * from production where name=?"); .prepareStatement("select * from production where name=?"); // 精确查询商品名称
preparedStatement.setString(1, name); preparedStatement.setString(1, name); // 设置查询参数
resultSet = preparedStatement.executeQuery(); resultSet = preparedStatement.executeQuery(); // 执行查询
if (resultSet.next()) { if (resultSet.next()) { // 如果找到商品
production.setId(resultSet.getString("id")); production.setId(resultSet.getString("id")); // 设置商品ID
production.setName(resultSet.getString("name")); production.setName(resultSet.getString("name")); // 设置商品名称
production.setInPrice(resultSet.getFloat("inPrice")); production.setInPrice(resultSet.getFloat("inPrice")); // 设置进价
production.setOutPrice(resultSet.getFloat("OutPrice")); production.setOutPrice(resultSet.getFloat("OutPrice")); // 设置售价
production.setLife(resultSet.getInt("life")); production.setLife(resultSet.getInt("life")); // 设置保质期
production.setSum(resultSet.getInt("sum")); production.setSum(resultSet.getInt("sum")); // 设置库存数量
production.setSupplyId(resultSet.getInt("supplyId")); production.setSupplyId(resultSet.getInt("supplyId")); // 设置供应商ID
production.setDelmark(resultSet.getInt("delmark")); production.setDelmark(resultSet.getInt("delmark")); // 设置删除标记
} else { } else {
return null; return null; // 如果未找到商品返回null
} }
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace(); e.printStackTrace();
} finally { } finally {
JDBCUtil.close(resultSet, preparedStatement, conn); JDBCUtil.close(resultSet, preparedStatement, conn); // 关闭数据库资源
} }
return production; return production; // 返回商品信息
} }
@Override @Override
@ -167,39 +167,39 @@ public class productionImpl implements productionService {
*/ */
public int addProduction(Production p) { public int addProduction(Production p) {
int flag = 0; int flag = 0;
Connection conn = JDBCUtil.getConn(); Connection conn = JDBCUtil.getConn(); // 获取数据库连接
PreparedStatement preparedStatement = null; PreparedStatement preparedStatement = null;
PreparedStatement preparedStatement1 = null; PreparedStatement preparedStatement1 = null;
ResultSet resultSet1=null; ResultSet resultSet1 = null;
// 假设商品不存在 // 假设商品不存在
try { try {
preparedStatement1 = conn.prepareStatement("select * from production where id=?"); preparedStatement1 = conn.prepareStatement("select * from production where id=?"); // 检查商品是否已存在
preparedStatement1.setString(1, p.getId()); preparedStatement1.setString(1, p.getId()); // 设置查询参数
resultSet1=preparedStatement1.executeQuery(); resultSet1 = preparedStatement1.executeQuery(); // 执行查询
if(resultSet1.next()){ if (resultSet1.next()) {
return flag=2; return flag = 2; // 如果商品已存在返回2
} }
preparedStatement = conn.prepareStatement("insert into production values(?,?,?,?,?,?,?,?,?,?,?)"); preparedStatement = conn.prepareStatement("insert into production values(?,?,?,?,?,?,?,?,?,?,?)"); // 插入新商品
preparedStatement.setString(1, p.getId()); preparedStatement.setString(1, p.getId()); // 设置商品ID
preparedStatement.setString(2, p.getName()); preparedStatement.setString(2, p.getName()); // 设置商品名称
preparedStatement.setFloat(3, p.getInPrice()); preparedStatement.setFloat(3, p.getInPrice()); // 设置进价
preparedStatement.setFloat(4, p.getOutPrice()); preparedStatement.setFloat(4, p.getOutPrice()); // 设置售价
preparedStatement.setInt(5, p.getLife()); preparedStatement.setInt(5, p.getLife()); // 设置保质期
preparedStatement.setInt(6, p.getSum()); preparedStatement.setInt(6, p.getSum()); // 设置库存数量
preparedStatement.setInt(7, p.getSupplyId()); preparedStatement.setInt(7, p.getSupplyId()); // 设置供应商ID
preparedStatement.setString(8, p.getId2()); preparedStatement.setString(8, p.getId2()); // 设置商品类别ID
preparedStatement.setString(9, p.getName2()); preparedStatement.setString(9, p.getName2()); // 设置商品类别名称
preparedStatement.setFloat(10, 0); preparedStatement.setFloat(10, 0); // 设置未知字段
preparedStatement.setInt(11, 1); preparedStatement.setInt(11, 1); // 设置删除标记为1未删除
preparedStatement.executeUpdate(); preparedStatement.executeUpdate(); // 执行插入
flag=1; flag = 1; // 插入成功返回1
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace(); e.printStackTrace();
} finally { } finally {
JDBCUtil.close(null, preparedStatement, conn); JDBCUtil.close(null, preparedStatement, conn); // 关闭数据库资源
} }
return flag; return flag; // 返回操作结果
} }
@Override @Override
@ -208,22 +208,21 @@ public class productionImpl implements productionService {
*/ */
public int deleteProduction(String id) { public int deleteProduction(String id) {
int flag = 0; int flag = 0;
Connection conn = JDBCUtil.getConn(); Connection conn = JDBCUtil.getConn(); // 获取数据库连接
PreparedStatement preparedStatement = null; PreparedStatement preparedStatement = null;
try { try {
preparedStatement = conn preparedStatement = conn
.prepareStatement("delete from production where id = ?"); .prepareStatement("delete from production where id = ?"); // 删除指定ID的商品
preparedStatement.setString(1, id); preparedStatement.setString(1, id); // 设置查询参数
preparedStatement.executeUpdate(); preparedStatement.executeUpdate(); // 执行删除
flag = 1; flag = 1; // 删除成功返回1
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace(); e.printStackTrace();
} finally { } finally {
JDBCUtil.close(null, preparedStatement, conn); JDBCUtil.close(null, preparedStatement, conn); // 关闭数据库资源
} }
return flag; return flag; // 返回操作结果
} }
@Override @Override
@ -232,31 +231,31 @@ public class productionImpl implements productionService {
*/ */
public int updateProduction(Production p) { public int updateProduction(Production p) {
int flag = 0; int flag = 0;
Connection conn = JDBCUtil.getConn(); Connection conn = JDBCUtil.getConn(); // 获取数据库连接
PreparedStatement preparedStatement = null; PreparedStatement preparedStatement = null;
try { try {
preparedStatement = conn preparedStatement = conn
.prepareStatement("update production set name=?,inPrice=?,OutPrice=?,life=?,sum=?,delmark=? where id = ? and supplyId=?"); .prepareStatement("update production set name=?,inPrice=?,OutPrice=?,life=?,sum=?,delmark=? where id = ? and supplyId=?"); // 更新商品信息
preparedStatement.setString(1, p.getName()); preparedStatement.setString(1, p.getName()); // 设置商品名称
preparedStatement.setFloat(2, p.getInPrice()); preparedStatement.setFloat(2, p.getInPrice()); // 设置进价
preparedStatement.setFloat(3, p.getOutPrice()); preparedStatement.setFloat(3, p.getOutPrice()); // 设置售价
preparedStatement.setInt(4, p.getLife()); preparedStatement.setInt(4, p.getLife()); // 设置保质期
preparedStatement.setInt(5, p.getSum()); preparedStatement.setInt(5, p.getSum()); // 设置库存数量
preparedStatement.setInt(6, p.getDelmark()); preparedStatement.setInt(6, p.getDelmark()); // 设置删除标记
preparedStatement.setString(7, p.getId()); preparedStatement.setString(7, p.getId()); // 设置商品ID
preparedStatement.setInt(8, p.getSupplyId()); preparedStatement.setInt(8, p.getSupplyId()); // 设置供应商ID
preparedStatement.executeUpdate(); preparedStatement.executeUpdate(); // 执行更新
flag = 1; flag = 1; // 更新成功返回1
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace(); e.printStackTrace();
} finally { } finally {
JDBCUtil.close(null, preparedStatement, conn); JDBCUtil.close(null, preparedStatement, conn); // 关闭数据库资源
} }
return flag; return flag; // 返回操作结果
} }
@Override @Override
@ -266,64 +265,65 @@ public class productionImpl implements productionService {
*/ */
Vector<Production> productions = new Vector<Production>(); Vector<Production> productions = new Vector<Production>();
Connection conn = JDBCUtil.getConn(); Connection conn = JDBCUtil.getConn(); // 获取数据库连接
PreparedStatement preparedStatement = null; PreparedStatement preparedStatement = null;
ResultSet resultSet = null; ResultSet resultSet = null;
try { try {
if(id.equals("0")) if (id.equals("0"))
preparedStatement = conn.prepareStatement("select * from production where delmark = 1"); preparedStatement = conn.prepareStatement("select * from production where delmark = 1"); // 查询所有未删除的商品
else else {
{preparedStatement = conn.prepareStatement("select * from production where id2= ? and delmark = 1"); preparedStatement = conn.prepareStatement("select * from production where id2= ? and delmark = 1"); // 查询指定类别ID且未删除的商品
preparedStatement.setString(1, id);} preparedStatement.setString(1, id); // 设置查询参数
resultSet = preparedStatement.executeQuery(); }
resultSet = preparedStatement.executeQuery(); // 执行查询
while (resultSet.next()) {
while (resultSet.next()) { // 遍历结果集
Production production = new Production(); Production production = new Production();
production.setId(resultSet.getString("id")); production.setId(resultSet.getString("id")); // 设置商品ID
production.setName(resultSet.getString("name")); production.setName(resultSet.getString("name")); // 设置商品名称
production.setInPrice(resultSet.getFloat("inPrice")); production.setInPrice(resultSet.getFloat("inPrice")); // 设置进价
production.setOutPrice(resultSet.getFloat("OutPrice")); production.setOutPrice(resultSet.getFloat("OutPrice")); // 设置售价
production.setLife(resultSet.getInt("life")); production.setLife(resultSet.getInt("life")); // 设置保质期
production.setSum(resultSet.getInt("sum")); production.setSum(resultSet.getInt("sum")); // 设置库存数量
production.setSupplyId(resultSet.getInt("supplyId")); production.setSupplyId(resultSet.getInt("supplyId")); // 设置供应商ID
production.setId2(resultSet.getString("id2")); production.setId2(resultSet.getString("id2")); // 设置商品类别ID
production.setName2(resultSet.getString("name2")); production.setName2(resultSet.getString("name2")); // 设置商品类别名称
production.setDelmark(resultSet.getInt("delmark")); production.setDelmark(resultSet.getInt("delmark")); // 设置删除标记
productions.add(production); productions.add(production); // 将商品信息添加到Vector中
} }
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace(); e.printStackTrace();
} finally { } finally {
JDBCUtil.close(resultSet, preparedStatement, conn); JDBCUtil.close(resultSet, preparedStatement, conn); // 关闭数据库资源
} }
return productions; return productions; // 返回所有匹配的商品信息
} }
@Override @Override
/** /**
* *
*/ */
public boolean updateProductionSum(String prodId,int sum) { public boolean updateProductionSum(String prodId, int sum) {
boolean flag = false; boolean flag = false;
Connection conn = JDBCUtil.getConn(); Connection conn = JDBCUtil.getConn(); // 获取数据库连接
PreparedStatement preparedStatement = null; PreparedStatement preparedStatement = null;
try { try {
preparedStatement = conn preparedStatement = conn
.prepareStatement("update production set sum=?+(select sum from(select sum from production where id = ? and delmark=1 ) p) where id = ? and delmark=1;"); .prepareStatement("update production set sum=?+(select sum from(select sum from production where id = ? and delmark=1 ) p) where id = ? and delmark=1;"); // 更新商品库存数量
preparedStatement.setInt(1, sum); preparedStatement.setInt(1, sum); // 设置新增库存数量
preparedStatement.setString(2, prodId); preparedStatement.setString(2, prodId); // 设置商品ID
preparedStatement.setString(3, prodId); preparedStatement.setString(3, prodId); // 设置商品ID
if(preparedStatement.executeUpdate()==1); if (preparedStatement.executeUpdate() == 1)
flag = true; flag = true; // 更新成功返回true
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace(); e.printStackTrace();
} finally { } finally {
JDBCUtil.close(null, preparedStatement, conn); JDBCUtil.close(null, preparedStatement, conn); // 关闭数据库资源
} }
return flag; return flag; // 返回操作结果
} }
} }

@ -4,121 +4,141 @@ import java.sql.Connection;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.sql.Statement;
import java.util.Iterator;
import java.util.Vector; import java.util.Vector;
// 导入相关的业务逻辑接口、数据传输对象以及工具类,用于数据库操作和日期处理等功能
import com.lingnan.supermarket.dao.storageRecordService; import com.lingnan.supermarket.dao.storageRecordService;
import com.lingnan.supermarket.dto.StorageRecord; import com.lingnan.supermarket.dto.StorageRecord;
import com.lingnan.supermarket.utils.DateUtil; import com.lingnan.supermarket.utils.DateUtil;
import com.lingnan.supermarket.utils.JDBCUtil; import com.lingnan.supermarket.utils.JDBCUtil;
// 实现storageRecordService接口--用于处理库存记录相关的数据持久化操作
public class storageRecordImpl implements storageRecordService { public class storageRecordImpl implements storageRecordService {
// 查询所有库存记录信息并以Vector容器存储返回
@Override @Override
public Vector<StorageRecord> findAllStorageRecord() { public Vector<StorageRecord> findAllStorageRecord() {
Vector<StorageRecord> v=new Vector<StorageRecord>(); // 创建一个Vector容器用于存放查询到的StorageRecord对象
Vector<StorageRecord> v = new Vector<StorageRecord>();
// 获取数据库连接通过JDBCUtil工具类来获取已经配置好的连接对象
Connection conn=JDBCUtil.getConn(); Connection conn = JDBCUtil.getConn();
PreparedStatement pstmt = null; PreparedStatement pstmt = null;
ResultSet resultSet=null; ResultSet resultSet = null;
try { try {
// 编写SQL查询语句从storageRecord表中查询所有记录并按照cDate字段降序排序
String sql = "select * from storageRecord order by cDate desc";
// 使用获取到的数据库连接对象预编译SQL语句
pstmt = conn.prepareStatement(sql);
String sql="select * from storageRecord order by cDate desc"; // 执行查询操作
pstmt=conn.prepareStatement(sql); resultSet = pstmt.executeQuery();
// 遍历结果集将每一条记录封装成StorageRecord对象并添加到Vector容器中
resultSet=pstmt.executeQuery(); while (resultSet.next()) {
while(resultSet.next()) { StorageRecord sr = new StorageRecord();
StorageRecord sr=new StorageRecord(); // 设置StorageRecord对象的id属性
sr.setId(resultSet.getString("id")); sr.setId(resultSet.getString("id"));
// 设置StorageRecord对象的库存编号属性
sr.setTheNumber(resultSet.getString("theNumber")); sr.setTheNumber(resultSet.getString("theNumber"));
// 设置StorageRecord对象的数量属性
sr.setNum(resultSet.getInt("num")); sr.setNum(resultSet.getInt("num"));
// 设置StorageRecord对象的执行情况属性
sr.setExecute(resultSet.getString("execute")); sr.setExecute(resultSet.getString("execute"));
sr.setcDate(DateUtil.dateToString(resultSet.getTimestamp("cDate"), null)); // 通过DateUtil工具类的dateToString方法将数据库中获取的时间戳类型的日期数据转换为字符串类型方便后续使用第二个参数为null可能表示使用默认的日期格式转换具体看DateUtil实现
v.add(sr);
}
sr.setcDate(DateUtil.dateToString(resultSet.getTimestamp("cDate"), null));
} // 将StorageRecord对象添加到Vector中
v.add(sr);
}
catch (SQLException e) { } catch (SQLException e) {
// 若出现SQL异常打印异常栈信息
e.printStackTrace(); e.printStackTrace();
}finally { } finally {
// 通过JDBCUtil工具类提供的方法进行关闭操作
JDBCUtil.close(resultSet, pstmt, conn); JDBCUtil.close(resultSet, pstmt, conn);
} }
return v; return v;
} }
// 根据给定的库存编号theNumber查找对应的库存记录信息并返回
@Override @Override
public StorageRecord findByIdStorageRecord(String theNumber) { public StorageRecord findByIdStorageRecord(String theNumber) {
// 初始化一个StorageRecord对象为null用于存放查询到的库存记录信息如果没查到则返回null
StorageRecord sr=null; StorageRecord sr = null;
Connection conn=JDBCUtil.getConn(); // 获取数据库连接
Connection conn = JDBCUtil.getConn();
PreparedStatement pstmt = null; PreparedStatement pstmt = null;
ResultSet resultSet=null; ResultSet resultSet = null;
try { try {
sr=new StorageRecord(); // 创建一个新的StorageRecord对象用于后续封装查询到的数据
sr = new StorageRecord();
// 预编译SQL语句用于根据给定的库存编号theNumber查询storageRecord表中的记录
pstmt = conn.prepareStatement("select *from storageRecord where theNumber=?"); pstmt = conn.prepareStatement("select *from storageRecord where theNumber=?");
pstmt.setString(1,theNumber); // 设置SQL语句中的参数将传入的库存编号赋值给查询语句中的占位符
pstmt.setString(1, theNumber);
// 执行查询操作,获取结果集
resultSet = pstmt.executeQuery(); resultSet = pstmt.executeQuery();
if(resultSet.next()){ // 如果结果集中有下一条记录则将对应记录中的各字段值封装到StorageRecord对象中
if (resultSet.next()) {
sr.setTheNumber((resultSet.getString("theNumber"))); sr.setTheNumber((resultSet.getString("theNumber")));
sr.setId((resultSet.getString("id"))); sr.setId((resultSet.getString("id")));
sr.setNum(resultSet.getInt("num")); sr.setNum(resultSet.getInt("num"));
sr.setExecute(resultSet.getString("execute")); sr.setExecute(resultSet.getString("execute"));
// 设置存储记录的创建日期,并进行格式化
sr.setcDate(DateUtil.dateToString(resultSet.getTimestamp("cDate"), null)); sr.setcDate(DateUtil.dateToString(resultSet.getTimestamp("cDate"), null));
} }
} catch (SQLException e) { } catch (SQLException e) {
// TODO Auto-generated catch block // 若出现SQL异常打印异常栈信息
e.printStackTrace(); e.printStackTrace();
}finally{ } finally {
// 关闭相关资源
JDBCUtil.close(resultSet, pstmt, conn); JDBCUtil.close(resultSet, pstmt, conn);
} }
return sr; return sr;
} }
public boolean insertStorageRecord(String iNumber,String time,String prodId,String execute,int sum) { // 向库存记录表storageRecord中插入一条新的库存记录信息
public boolean insertStorageRecord(String iNumber, String time, String prodId, String execute, int sum) {
// 定义一个布尔变量用于标记插入操作是否成功初始化为false
boolean flag = false; boolean flag = false;
Connection conn=JDBCUtil.getConn(); // 获取数据库连接
Connection conn = JDBCUtil.getConn();
PreparedStatement pstmt = null; PreparedStatement pstmt = null;
ResultSet resultSet=null; ResultSet resultSet = null;
try { try {
// 预编译插入数据的SQL语句向storageRecord表中插入五条数据
pstmt = conn.prepareStatement("insert into storageRecord values(?,?,?,?,?) "); pstmt = conn.prepareStatement("insert into storageRecord values(?,?,?,?,?) ");
pstmt.setString(1,iNumber); // 设置SQL语句中的第一个参数
pstmt.setString(2,time); pstmt.setString(1, iNumber);
pstmt.setString(3,prodId); // 设置SQL语句中的第二个参数
pstmt.setString(4,execute); pstmt.setString(2, time);
pstmt.setInt(5,sum); // 设置SQL语句中的第三个参数
pstmt.setString(3, prodId);
if(pstmt.executeUpdate()==1){ // 设置SQL语句中的第四个参数
flag = true; pstmt.setString(4, execute);
// 设置SQL语句中的第五个参数
pstmt.setInt(5, sum);
// 执行插入操作若受影响的行数为1则将flag置为true表示插入成功
if (pstmt.executeUpdate() == 1) {
flag = true;
} }
} catch (SQLException e) { } catch (SQLException e) {
// TODO Auto-generated catch block // 若出现SQL异常打印异常栈信息
e.printStackTrace(); e.printStackTrace();
}finally{ } finally {
// 关闭相关资源
JDBCUtil.close(resultSet, pstmt, conn); JDBCUtil.close(resultSet, pstmt, conn);
} }
return flag; return flag;
} }
} }

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

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

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

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

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

@ -17,7 +17,6 @@ import javax.swing.JOptionPane;
import javax.swing.JPanel; import javax.swing.JPanel;
import javax.swing.JTextField; import javax.swing.JTextField;
import com.lingnan.supermarket.*;
import com.lingnan.supermarket.dao.SupplierInfService; import com.lingnan.supermarket.dao.SupplierInfService;
import com.lingnan.supermarket.dao.productionService; import com.lingnan.supermarket.dao.productionService;
import com.lingnan.supermarket.dao.impl.SupplierInfImpl; import com.lingnan.supermarket.dao.impl.SupplierInfImpl;
@ -28,172 +27,179 @@ import com.lingnan.supermarket.dto.Production;
import com.lingnan.supermarket.dto.SupplierInf; import com.lingnan.supermarket.dto.SupplierInf;
import com.lingnan.supermarket.table.ProdCatalogTM; import com.lingnan.supermarket.table.ProdCatalogTM;
import com.lingnan.supermarket.view.StorageView; import com.lingnan.supermarket.view.StorageView;
import com.lingnan.supermarket.view.SupplierView;
import com.lingnan.supermarket.view.ProdCatalogView.MyItemListener;
/**
*
* JDialog
*/
public class ProductionDialog extends JDialog implements ActionListener { public class ProductionDialog extends JDialog implements ActionListener {
// 定义各个面板,用于组织界面布局
private JPanel namePanel, addressPanel, contactPanel, private JPanel namePanel, addressPanel, contactPanel,
opePanel,idPanel,inpricePanel,outpricePanel,lifePanel, opePanel, idPanel, inpricePanel, outpricePanel, lifePanel,
sumPanel,supplyidPanel,id2Panel,name2Panel; sumPanel, supplyidPanel, id2Panel, name2Panel;
// 定义各个标签,用于显示提示信息
private JLabel nameLabel, addressLabel, contactLabel, private JLabel nameLabel, addressLabel, contactLabel,
idLabel,inpriceLabel,outpriceLabel,lifeLabel,sumLabel, idLabel, inpriceLabel, outpriceLabel, lifeLabel, sumLabel,
supplyidLabel,id2Label,name2Label; supplyidLabel, id2Label, name2Label;
// 定义各个文本框,用于用户输入数据
private JTextField nameTF, addressTF, contactTF, private JTextField nameTF, addressTF, contactTF,
idTF,inpriceTF,outpriceTF,lifeTF,sumTF, idTF, inpriceTF, outpriceTF, lifeTF, sumTF,
supplyidTF,id2TF,name2TF; supplyidTF, id2TF, name2TF;
// 定义保存和取消按钮
private JButton saveBtn, cancelBtn; private JButton saveBtn, cancelBtn;
// 商品服务接口的实现类,用于操作商品数据
private productionService productionService = new productionImpl(); private productionService productionService = new productionImpl();
//下拉类别 // 下拉类别相关变量
private String log[]=null; private String log[] = null; // 商品类别名称数组
private ArrayList<String>alog=null; private ArrayList<String> alog = null; // 商品类别名称列表
private ProdCatalogTM prodCatalogTM; private ProdCatalogTM prodCatalogTM; // 商品类别表格模型
private ProdCatalog pc; private ProdCatalog pc; // 商品类别对象
private prodCatalogImpl pci; private prodCatalogImpl pci; // 商品类别服务实现类
private JComboBox<String> combo; private JComboBox<String> combo; // 商品类别下拉框
private String id2; private String id2; // 商品类别ID
private String name2; private String name2; // 商品类别名称
//下拉供应商类别 // 下拉供应商类别相关变量
private String superlier[]=null; private String superlier[] = null; // 供应商名称数组
private ArrayList<String>asuperlier=null; private ArrayList<String> asuperlier = null; // 供应商名称列表
private SupplierInf si; private SupplierInf si; // 供应商对象
private SupplierInfImpl sii; private SupplierInfImpl sii; // 供应商服务实现类
private JComboBox<String> combo1; private JComboBox<String> combo1; // 供应商下拉框
private int supplyid; private int supplyid; // 供应商ID
private StorageView storageView; private StorageView storageView; // 库存视图
private Production production; private Production production; // 商品对象
/**
*
* @param parent
*/
public ProductionDialog(JFrame parent) { public ProductionDialog(JFrame parent) {
super(parent, "添加"); super(parent, "添加"); // 调用父类构造函数,设置标题为“添加”
// 设置对话框大小
setSize(350, 500); setSize(350, 500);
// 设置对话框居中显示
setLocationRelativeTo(null); setLocationRelativeTo(null);
// 设置为模态对话框,即打开对话框时,父窗口不可操作
setModal(true); setModal(true);
setResizable(false); setResizable(false); // 禁止调整对话框大小
// 设置布局为流式布局
this.setLayout(new FlowLayout()); this.setLayout(new FlowLayout());
// 初始化视图
initView(); initView();
} }
/**
*
*/
private void initView() { private void initView() {
// 商品编号面板
idPanel = new JPanel(); idPanel = new JPanel();
idLabel = new JLabel("商品编号"); idLabel = new JLabel("商品编号");
idTF = new JTextField(15); idTF = new JTextField(15);
idPanel.add(idLabel); idPanel.add(idLabel);
idPanel.add(idTF); idPanel.add(idTF);
// 商品名称面板
namePanel = new JPanel(); namePanel = new JPanel();
nameLabel = new JLabel("名称"); nameLabel = new JLabel("名称");
nameTF = new JTextField(15); nameTF = new JTextField(15);
namePanel.add(nameLabel); namePanel.add(nameLabel);
namePanel.add(nameTF); namePanel.add(nameTF);
// 进货单价面板
inpricePanel = new JPanel(); inpricePanel = new JPanel();
inpriceLabel = new JLabel("进货单价"); inpriceLabel = new JLabel("进货单价");
inpriceTF = new JTextField(15); inpriceTF = new JTextField(15);
inpricePanel.add(inpriceLabel); inpricePanel.add(inpriceLabel);
inpricePanel.add(inpriceTF); inpricePanel.add(inpriceTF);
// 购买单价面板
outpricePanel = new JPanel(); outpricePanel = new JPanel();
outpriceLabel = new JLabel("购买单价"); outpriceLabel = new JLabel("购买单价");
outpriceTF = new JTextField(15); outpriceTF = new JTextField(15);
outpricePanel.add(outpriceLabel); outpricePanel.add(outpriceLabel);
outpricePanel.add(outpriceTF); outpricePanel.add(outpriceTF);
// 保质期面板
lifePanel = new JPanel(); lifePanel = new JPanel();
lifeLabel = new JLabel("保质期(月份数)"); lifeLabel = new JLabel("保质期(月份数)");
lifeTF = new JTextField(15); lifeTF = new JTextField(15);
lifePanel.add(lifeLabel); lifePanel.add(lifeLabel);
lifePanel.add(lifeTF); lifePanel.add(lifeTF);
// 库存面板
sumPanel = new JPanel(); sumPanel = new JPanel();
sumLabel = new JLabel("库存"); sumLabel = new JLabel("库存");
sumTF = new JTextField(15); sumTF = new JTextField(15);
sumPanel.add(sumLabel); sumPanel.add(sumLabel);
sumPanel.add(sumTF); sumPanel.add(sumTF);
//供应商名下拉框 传递supplyid // 供应商名下拉框面板
supplyidPanel = new JPanel(); supplyidPanel = new JPanel();
supplyidLabel = new JLabel("供应商"); supplyidLabel = new JLabel("供应商");
// supplyidTF = new JTextField(15); sii = new SupplierInfImpl(); // 创建供应商服务实现类对象
this.asuperlier = sii.findNameSupplier(); // 获取所有供应商名称
this.superlier = new String[asuperlier.size()]; // 初始化供应商名称数组
for (int i = 0; i < asuperlier.size(); i++)
superlier[i] = asuperlier.get(i); // 将供应商名称存入数组
sii=new SupplierInfImpl(); combo1 = new JComboBox<String>(superlier); // 创建供应商下拉框
this.asuperlier=sii.findNameSupplier(); combo1.addItemListener(new MyItemListener1()); // 添加下拉框监听器
this.superlier=new String[asuperlier.size()];
for(int i=0;i<asuperlier.size();i++)
superlier[i]=asuperlier.get(i);
for(int i=0;i<superlier.length;i++)
{
System.out.println(superlier[i]);
}
combo1 = new JComboBox<String>(superlier);
combo1.addItemListener(new MyItemListener1());
supplyidPanel.add(supplyidLabel); supplyidPanel.add(supplyidLabel);
supplyidPanel.add(combo1); supplyidPanel.add(combo1);
// 类名下拉框面板
/* id2Panel = new JPanel();
id2Label = new JLabel("分类id");
id2TF = new JTextField(id2,15);
id2Panel.add(id2Label);
id2Panel.add(id2TF);*/
//类名下拉框
name2Panel = new JPanel(); name2Panel = new JPanel();
name2Label = new JLabel("类名"); name2Label = new JLabel("类名");
pci=new prodCatalogImpl(); pci = new prodCatalogImpl(); // 创建商品类别服务实现类对象
this.alog=pci.findNameProdCatalog(); this.alog = pci.findNameProdCatalog(); // 获取所有商品类别名称
this.log=new String[alog.size()]; this.log = new String[alog.size()]; // 初始化商品类别名称数组
for(int i=0;i<alog.size();i++) for (int i = 0; i < alog.size(); i++)
log[i]=alog.get(i); log[i] = alog.get(i); // 将商品类别名称存入数组
combo = new JComboBox<String>(log); // 创建商品类别下拉框
combo = new JComboBox<String>(log); combo.addItemListener(new MyItemListener()); // 添加下拉框监听器
combo.addItemListener(new MyItemListener());
name2Panel.add(name2Label); name2Panel.add(name2Label);
name2Panel.add(combo); name2Panel.add(combo);
// 地址面板
addressPanel = new JPanel(); addressPanel = new JPanel();
addressLabel = new JLabel("地址"); addressLabel = new JLabel("地址");
addressTF = new JTextField(15); addressTF = new JTextField(15);
addressPanel.add(addressLabel); addressPanel.add(addressLabel);
addressPanel.add(addressTF); addressPanel.add(addressTF);
// 电话面板
contactPanel = new JPanel(); contactPanel = new JPanel();
contactLabel = new JLabel("电话"); contactLabel = new JLabel("电话");
contactTF = new JTextField(15); contactTF = new JTextField(15);
contactPanel.add(contactLabel); contactPanel.add(contactLabel);
contactPanel.add(contactTF); contactPanel.add(contactTF);
// 操作按钮面板
opePanel = new JPanel(); opePanel = new JPanel();
saveBtn = new JButton("保存"); saveBtn = new JButton("保存");
cancelBtn = new JButton("取消"); cancelBtn = new JButton("取消");
saveBtn.addActionListener(this); saveBtn.addActionListener(this); // 添加保存按钮监听器
cancelBtn.addActionListener(this); cancelBtn.addActionListener(this); // 添加取消按钮监听器
opePanel.add(saveBtn); opePanel.add(saveBtn);
opePanel.add(cancelBtn); opePanel.add(cancelBtn);
// 将所有面板添加到容器中
Container container = getContentPane(); Container container = getContentPane();
container.add(idPanel); container.add(idPanel);
container.add(namePanel); container.add(namePanel);
@ -202,20 +208,19 @@ public class ProductionDialog extends JDialog implements ActionListener {
container.add(lifePanel); container.add(lifePanel);
container.add(sumPanel); container.add(sumPanel);
container.add(supplyidPanel); container.add(supplyidPanel);
// container.add(id2Panel);
container.add(name2Panel); container.add(name2Panel);
container.add(opePanel); container.add(opePanel);
} }
/**
*
* @param e
*/
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
Object source = e.getSource(); Object source = e.getSource();
if (source == saveBtn) { if (source == saveBtn) {
// 思路获取数据 // 获取输入的数据
// 保存到数据库
// 关闭对话框
// 刷新table
String name = nameTF.getText(); String name = nameTF.getText();
String id = idTF.getText(); String id = idTF.getText();
float inprice = Float.parseFloat((inpriceTF.getText())); float inprice = Float.parseFloat((inpriceTF.getText()));
@ -223,26 +228,25 @@ public class ProductionDialog extends JDialog implements ActionListener {
int life = Integer.parseInt(lifeTF.getText()); int life = Integer.parseInt(lifeTF.getText());
int sum = Integer.parseInt(sumTF.getText()); int sum = Integer.parseInt(sumTF.getText());
// 参数校验
// TODO 参数校验
if (this.production == null) { if (this.production == null) {
if(supplyid==-1){ if (supplyid == -1) {
JOptionPane.showMessageDialog(this, "商品检索出错", "提示", JOptionPane.showMessageDialog(this, "商品检索出错", "提示",
JOptionPane.ERROR_MESSAGE); JOptionPane.ERROR_MESSAGE);
return; return;
} }
if(supplyid==0){ if (supplyid == 0) {
JOptionPane.showMessageDialog(this, "请选择商品名", "提示", JOptionPane.showMessageDialog(this, "请选择商品名", "提示",
JOptionPane.ERROR_MESSAGE); JOptionPane.ERROR_MESSAGE);
return; return;
} }
if(id2.equals("0")){ if (id2.equals("0")) {
JOptionPane.showMessageDialog(this, "请选择商品类", "提示", JOptionPane.showMessageDialog(this, "请选择商品类", "提示",
JOptionPane.ERROR_MESSAGE); JOptionPane.ERROR_MESSAGE);
return; return;
} }
// 创建商品对象并设置属性
Production production = new Production(); Production production = new Production();
production.setId(id); production.setId(id);
production.setName(name); production.setName(name);
@ -253,69 +257,58 @@ public class ProductionDialog extends JDialog implements ActionListener {
production.setSupplyId(supplyid); production.setSupplyId(supplyid);
production.setId2(id2); production.setId2(id2);
production.setName2(name2); production.setName2(name2);
// 调用服务接口添加商品
int result = productionService.addProduction(production); int result = productionService.addProduction(production);
// int result = 1;
if (result == 1) { if (result == 1) {
JOptionPane.showMessageDialog(this, "添加成功", "提示", JOptionPane.showMessageDialog(this, "添加成功", "提示",
JOptionPane.INFORMATION_MESSAGE); JOptionPane.INFORMATION_MESSAGE);
this.dispose(); this.dispose(); // 关闭对话框
} else if(result == 2){ } else if (result == 2) {
JOptionPane.showMessageDialog(this, "已存在该商品", "提示", JOptionPane.showMessageDialog(this, "已存在该商品", "提示",
JOptionPane.ERROR_MESSAGE); JOptionPane.ERROR_MESSAGE);
} } else {
else {
JOptionPane.showMessageDialog(this, "出错!添加失败", "提示", JOptionPane.showMessageDialog(this, "出错!添加失败", "提示",
JOptionPane.ERROR_MESSAGE); JOptionPane.ERROR_MESSAGE);
} }
}/*else{ }
//更新
SupplierInf supplierInf= new SupplierInf();
supplierInf.setName(name);
supplierInf.setAddress(address);
supplierInf.setContact(contact);
supplierInf.setId(this.supplierInf.getId());
int result = supplierInfService.updateSupplierInf(supplierInf);
if(result==1){
JOptionPane.showMessageDialog(this, "更新成功", "提示",
JOptionPane.INFORMATION_MESSAGE);
}
}*/
} else if (source == cancelBtn) { } else if (source == cancelBtn) {
// 关闭对话框
this.dispose(); this.dispose();
} }
} }
/**
*
*/
public class MyItemListener implements ItemListener { public class MyItemListener implements ItemListener {
@Override @Override
public void itemStateChanged(ItemEvent e) { public void itemStateChanged(ItemEvent e) {
JComboBox cb = (JComboBox) e.getSource(); JComboBox cb = (JComboBox) e.getSource();
name2 = (String) cb.getSelectedItem(); name2 = (String) cb.getSelectedItem(); // 获取选中的商品类别名称
pci =new prodCatalogImpl(); pci = new prodCatalogImpl();
for(int i=0;i<log.length;i++){ for (int i = 0; i < log.length; i++) {
if(name2.equals(log[i])) if (name2.equals(log[i]))
id2=pci.findProdCatalogByname(name2); id2 = pci.findProdCatalogByname(name2); // 根据名称获取商品类别ID
} }
} }
} }
/**
*
*/
public class MyItemListener1 implements ItemListener { public class MyItemListener1 implements ItemListener {
@Override @Override
public void itemStateChanged(ItemEvent e) { public void itemStateChanged(ItemEvent e) {
JComboBox cb = (JComboBox) e.getSource(); JComboBox cb = (JComboBox) e.getSource();
String suppliername = (String) cb.getSelectedItem(); String suppliername = (String) cb.getSelectedItem(); // 获取选中的供应商名称
sii =new SupplierInfImpl(); sii = new SupplierInfImpl();
for(int i=0;i<superlier.length;i++){ for (int i = 0; i < superlier.length; i++) {
if(suppliername.equals(superlier[i])) if (suppliername.equals(superlier[i]))
supplyid=sii.findIdSupplierByName(suppliername); supplyid = sii.findIdSupplierByName(suppliername); // 根据名称获取供应商ID
} }
} }
} }
} }

@ -13,7 +13,6 @@ import javax.swing.JOptionPane;
import javax.swing.JPanel; import javax.swing.JPanel;
import javax.swing.JTextField; import javax.swing.JTextField;
import com.lingnan.supermarket.*;
import com.lingnan.supermarket.dao.SupplierInfService; import com.lingnan.supermarket.dao.SupplierInfService;
import com.lingnan.supermarket.dao.impl.SupplierInfImpl; import com.lingnan.supermarket.dao.impl.SupplierInfImpl;
import com.lingnan.supermarket.dto.SupplierInf; import com.lingnan.supermarket.dto.SupplierInf;
@ -21,68 +20,78 @@ import com.lingnan.supermarket.view.SupplierView;
public class SupplierInfDialog extends JDialog implements ActionListener { public class SupplierInfDialog extends JDialog implements ActionListener {
private JPanel namePanel, addressPanel, contactPanel,emailPanel, opePanel; private JPanel namePanel, addressPanel, contactPanel, emailPanel, opePanel;
private JLabel nameLabel, addressLabel, contactLabel,emailLabel; private JLabel nameLabel, addressLabel, contactLabel, emailLabel;
private JTextField nameTF, addressTF, contactTF,emailTF; private JTextField nameTF, addressTF, contactTF, emailTF;
private JButton saveBtn, cancelBtn; private JButton saveBtn, cancelBtn;
private SupplierInfService supplierInfService = new SupplierInfImpl(); private SupplierInfService supplierInfService = new SupplierInfImpl(); // 供应商信息服务接口的实现类
private SupplierView supplierView; private SupplierView supplierView; // 供应商视图对象
private SupplierInf supplierInf; private SupplierInf supplierInf; // 供应商信息对象
//构造函数,初始化对话框
public SupplierInfDialog(JFrame parent, SupplierView supplierView) { public SupplierInfDialog(JFrame parent, SupplierView supplierView) {
super(parent, "添加"); super(parent, "添加"); // 调用父类构造函数,设置对话框标题为“添加”
this.supplierView = supplierView; this.supplierView = supplierView; // 保存供应商视图对象
setSize(350, 300); setSize(350, 300); // 设置对话框大小
setLocationRelativeTo(null); setLocationRelativeTo(null); // 设置对话框居中显示
setModal(true); setModal(true); // 设置对话框为模态对话框
setResizable(false); setResizable(false); // 禁止调整对话框大小
this.setLayout(new FlowLayout()); this.setLayout(new FlowLayout()); // 设置对话框的布局为流式布局
initView(); initView(); // 初始化对话框界面
} }
/**
*
*/
private void initView() { private void initView() {
// 名称面板
namePanel = new JPanel(); namePanel = new JPanel();
nameLabel = new JLabel("名称"); nameLabel = new JLabel("名称");
nameTF = new JTextField(15); nameTF = new JTextField(15);
namePanel.add(nameLabel); namePanel.add(nameLabel);
namePanel.add(nameTF); namePanel.add(nameTF);
// 地址面板
addressPanel = new JPanel(); addressPanel = new JPanel();
addressLabel = new JLabel("地址"); addressLabel = new JLabel("地址");
addressTF = new JTextField(15); addressTF = new JTextField(15);
addressPanel.add(addressLabel); addressPanel.add(addressLabel);
addressPanel.add(addressTF); addressPanel.add(addressTF);
// 联系电话面板
contactPanel = new JPanel(); contactPanel = new JPanel();
contactLabel = new JLabel("电话"); contactLabel = new JLabel("电话");
contactTF = new JTextField(15); contactTF = new JTextField(15);
contactPanel.add(contactLabel); contactPanel.add(contactLabel);
contactPanel.add(contactTF); contactPanel.add(contactTF);
// 邮箱面板
emailPanel = new JPanel(); emailPanel = new JPanel();
emailLabel = new JLabel("邮箱"); emailLabel = new JLabel("邮箱");
emailTF = new JTextField(15); emailTF = new JTextField(15);
emailPanel.add(emailLabel); emailPanel.add(emailLabel);
emailPanel.add(emailTF); emailPanel.add(emailTF);
// 操作面板
opePanel = new JPanel(); opePanel = new JPanel();
saveBtn = new JButton("保存"); saveBtn = new JButton("保存");
cancelBtn = new JButton("取消"); cancelBtn = new JButton("取消");
saveBtn.addActionListener(this); saveBtn.addActionListener(this); // 为保存按钮添加事件监听器
cancelBtn.addActionListener(this); cancelBtn.addActionListener(this); // 为取消按钮添加事件监听器
opePanel.add(saveBtn); opePanel.add(saveBtn);
opePanel.add(cancelBtn); opePanel.add(cancelBtn);
// 将各个面板添加到对话框的内容面板中
Container container = getContentPane(); Container container = getContentPane();
container.add(namePanel); container.add(namePanel);
container.add(addressPanel); container.add(addressPanel);
@ -91,56 +100,51 @@ public class SupplierInfDialog extends JDialog implements ActionListener {
container.add(opePanel); container.add(opePanel);
} }
/**
*
*
* @param e
*/
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
Object source = e.getSource(); Object source = e.getSource(); // 获取事件源
if (source == saveBtn) { if (source == saveBtn) { // 如果事件源是保存按钮
// 思路获取数据 // 获取用户输入的数据
// 保存到数据库
// 关闭对话框
// 刷新table
String name = nameTF.getText(); String name = nameTF.getText();
String address = addressTF.getText(); String address = addressTF.getText();
String contact = contactTF.getText(); String contact = contactTF.getText();
String email = emailTF.getText(); String email = emailTF.getText();
// TODO 参数校验 // TODO 参数校验
if (this.supplierInf == null) { if (this.supplierInf == null) { // 如果当前没有供应商信息对象(即新增操作)
SupplierInf supplierInf = new SupplierInf(); SupplierInf supplierInf = new SupplierInf();
supplierInf.setName(name); supplierInf.setName(name);
supplierInf.setAddress(address); supplierInf.setAddress(address);
supplierInf.setContact(contact); supplierInf.setContact(contact);
supplierInf.setEmail(email); supplierInf.setEmail(email);
int result = supplierInfService.addSupplierInf(supplierInf); int result = supplierInfService.addSupplierInf(supplierInf); // 调用服务接口添加供应商信息
// int result = 1; if (result == 1) { // 如果添加成功
if (result == 1) { JOptionPane.showMessageDialog(this, "添加成功", "提示", JOptionPane.INFORMATION_MESSAGE);
this.dispose(); // 关闭对话框
JOptionPane.showMessageDialog(this, "添加成功", "提示", } else { // 如果添加失败
JOptionPane.INFORMATION_MESSAGE); JOptionPane.showMessageDialog(this, "添加失败", "提示", JOptionPane.ERROR_MESSAGE);
this.dispose();
} else {
JOptionPane.showMessageDialog(this, "添加失败", "提示",
JOptionPane.ERROR_MESSAGE);
}
}/*else{
//更新
SupplierInf supplierInf= new SupplierInf();
supplierInf.setName(name);
supplierInf.setAddress(address);
supplierInf.setContact(contact);
supplierInf.setId(this.supplierInf.getId());
int result = supplierInfService.updateSupplierInf(supplierInf);
if(result==1){
JOptionPane.showMessageDialog(this, "更新成功", "提示",
JOptionPane.INFORMATION_MESSAGE);
} }
}*/ } /*else {
// 更新操作(当前代码被注释掉)
} else if (source == cancelBtn) { SupplierInf supplierInf = new SupplierInf();
supplierInf.setName(name);
this.dispose(); supplierInf.setAddress(address);
supplierInf.setContact(contact);
supplierInf.setId(this.supplierInf.getId());
int result = supplierInfService.updateSupplierInf(supplierInf);
if (result == 1) {
JOptionPane.showMessageDialog(this, "更新成功", "提示", JOptionPane.INFORMATION_MESSAGE);
}
}*/
} else if (source == cancelBtn) { // 如果事件源是取消按钮
this.dispose(); // 关闭对话框
} }
} }
} }

@ -39,7 +39,7 @@ public class UserDialog extends JDialog implements ActionListener {
// 下拉框组件,用于选择用户权限 // 下拉框组件,用于选择用户权限
private JComboBox<String> combo; private JComboBox<String> combo;
// 下拉框中的选项内容,包括请选择身份以及不同的权限角色 // 下拉框中的选项内容,包括请选择身份以及不同的权限角色
private String[] identity = { "请选择身份", "收银员", "管理员", "超级管理员" }; private String[] identity = { "请选择身份", "进货员","收银员", "管理员", "超级管理员" };
// 构造函数,用于创建添加用户信息的对话框 // 构造函数,用于创建添加用户信息的对话框
public UserDialog(JFrame parent) { public UserDialog(JFrame parent) {
@ -168,6 +168,13 @@ public class UserDialog extends JDialog implements ActionListener {
} }
// 内部类实现了ItemListener接口用于监听下拉框选项变化事件 // 内部类实现了ItemListener接口用于监听下拉框选项变化事件
/**
*
*
* cwf
* 2024/12/11
*/
static class MyItemListener implements ItemListener { static class MyItemListener implements ItemListener {
@Override @Override
@ -182,6 +189,8 @@ public class UserDialog extends JDialog implements ActionListener {
sSuper = 2; sSuper = 2;
else if (sSuper1.equals("管理员")) else if (sSuper1.equals("管理员"))
sSuper = 1; sSuper = 1;
else if (sSuper1.equals("进货员")) // 2024/12/11 添加进货员权限
sSuper = 3; // 2024/12/11 添加进货员权限
else else
sSuper = 0; sSuper = 0;
} }

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save