all #25

Merged
p4vsywzlp merged 8 commits from :main into branch_cwf 1 year ago

@ -3,5 +3,5 @@
<component name="JavaScriptSettings">
<option name="languageLevel" value="ES6" />
</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>

@ -6,6 +6,6 @@
<classpathentry kind="src" path="config"/>
<classpathentry kind="lib" path="Supermarket/lib/activation.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"/>
</classpath>

@ -2,7 +2,7 @@
<project version="4">
<component name="dataSourceStorageLocal" created-in="IU-231.8109.175">
<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>
<identifier-quote-string>`</identifier-quote-string>
</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"?>
<module type="JAVA_MODULE" version="4">
<component name="EclipseModuleManager">
<libelement value="file://D:/大二下学期实训超市管理系统/Supermarket/lib/activation.jar" />
<libelement value="file://D:/大二下学期实训超市管理系统/Supermarket/lib/mail.jar" />
<libelement value="file://D:/大二下学期实训超市管理系统/Supermarket/lib/mysql-connector-java-5.1.32.jar" />
<libelement value="file://$MODULE_DIR$/../../../大二下学期实训超市管理系统/Supermarket/lib/activation.jar" />
<libelement value="file://$MODULE_DIR$/../../../大二下学期实训超市管理系统/Supermarket/lib/mail.jar" />
<libelement value="file://$MODULE_DIR$/../../../大二下学期实训超市管理系统/Supermarket/lib/mysql-connector-java-5.1.32.jar" />
<src_description expected_position="1">
<src_folder value="file://$MODULE_DIR$/src" expected_position="0" />
<src_folder value="file://$MODULE_DIR$" expected_position="1" />
@ -47,5 +47,6 @@
<SOURCES />
</library>
</orderEntry>
<orderEntry type="library" name="mysql.connector.java" level="project" />
</component>
</module>

@ -6,6 +6,6 @@
<classpathentry kind="src" path="config"/>
<classpathentry kind="lib" path="Supermarket/lib/activation.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"/>
</classpath>

@ -2,7 +2,7 @@
<project version="4">
<component name="dataSourceStorageLocal" created-in="IU-231.8109.175">
<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>
<identifier-quote-string>`</identifier-quote-string>
</database-info>

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

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

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

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

@ -1,5 +1,9 @@
package com.lingnan.supermarket.dao.impl;
import com.lingnan.supermarket.dao.SupplierInfService;
import com.lingnan.supermarket.dto.SupplierInf;
import com.lingnan.supermarket.utils.JDBCUtil;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
@ -8,211 +12,255 @@ import java.util.ArrayList;
import java.util.Iterator;
import java.util.Vector;
import com.lingnan.supermarket.dao.SupplierInfService;
import com.lingnan.supermarket.dto.ProdCatalog;
import com.lingnan.supermarket.dto.SupplierInf;
import com.lingnan.supermarket.dto.User;
import com.lingnan.supermarket.utils.JDBCUtil;
/**
*
* @cwf 2210461197 2024/12/1
*/
// 实现供应商信息服务接口的类
public class SupplierInfImpl implements SupplierInfService{
// 查询所有供应商信息的方法
@Override
// 该方法用于查找所有未被标记为删除的供应商信息,返回一个供应商信息的向量
// 此方法连接数据库,执行查询,并将结果封装为供应商信息对象的向量
public Vector<SupplierInf> findAllSupplierInf() {
Vector<SupplierInf> supplierInfs = new Vector<SupplierInf>();
Connection conn = JDBCUtil.getConn();
PreparedStatement preparedStatement = null;
ResultSet resultSet=null;
String SQL = "select * from supplierInf where delmark = 1";
Vector<SupplierInf> supplierInfs = new Vector<SupplierInf>(); // 创建一个向量用于存储供应商信息
Connection conn = JDBCUtil.getConn(); // 获取数据库连接
PreparedStatement preparedStatement = null; // 初始化预编译语句对象
ResultSet resultSet=null; // 初始化结果集对象
String SQL = "select * from supplierInf where delmark = 1"; // SQL查询语句选择未被标记为删除的供应商信息
try {
preparedStatement = conn.prepareStatement(SQL);
resultSet = preparedStatement.executeQuery();
while(resultSet.next()) {
SupplierInf supplierInf = new SupplierInf();
supplierInf.setId(resultSet.getInt("id"));
supplierInf.setName(resultSet.getString("name"));
supplierInf.setContact(resultSet.getString("contact"));
supplierInf.setEmail(resultSet.getString("email"));
supplierInf.setAddress(resultSet.getString("address"));
supplierInf.setDelmark(resultSet.getInt("delmark"));
supplierInfs.add(supplierInf);
preparedStatement = conn.prepareStatement(SQL); // 准备SQL语句
resultSet = preparedStatement.executeQuery(); // 执行查询
while(resultSet.next()) { // 遍历结果集
SupplierInf supplierInf = new SupplierInf(); // 创建一个新的供应商信息对象
supplierInf.setId(resultSet.getInt("id")); // 设置供应商ID
supplierInf.setName(resultSet.getString("name")); // 设置供应商名称
supplierInf.setContact(resultSet.getString("contact")); // 设置供应商联系人
supplierInf.setEmail(resultSet.getString("email")); // 设置供应商邮箱
supplierInf.setAddress(resultSet.getString("address")); // 设置供应商地址
supplierInf.setDelmark(resultSet.getInt("delmark")); // 设置删除标记
supplierInfs.add(supplierInf); // 将供应商信息对象添加到向量中
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
JDBCUtil.close(resultSet, preparedStatement, conn);
} catch (SQLException e) { // 捕获SQL异常
e.printStackTrace(); // 打印异常堆栈信息
} finally { // 无论是否发生异常,都会执行的代码块
// 关闭数据库连接和相关资源
JDBCUtil.close(resultSet, preparedStatement, conn); // 关闭结果集、预编译语句和数据库连接
}
return supplierInfs;
return supplierInfs; // 返回存储所有供应商信息的向量
}
// 根据供应商名称查询供应商信息的方法
@Override
// 定义一个查找供应商信息的方法,根据传入的供应商对象进行查询
/**
*
* @param supplierInf
* @return
*/
public Vector<SupplierInf> findByNameSupplierInf(SupplierInf supplierInf) {
//SupplierInf supplierInf = new SupplierInf();
Connection conn = JDBCUtil.getConn();
Vector<SupplierInf> v = new Vector<>();
System.out.println(supplierInf.getName());
PreparedStatement preparedStatement = null;
ResultSet resultSet = null;
Connection conn = JDBCUtil.getConn(); // 获取数据库连接
Vector<SupplierInf> v = new Vector<>(); // 创建一个向量用于存储供应商信息
System.out.println(supplierInf.getName()); // 打印供应商名称
PreparedStatement preparedStatement = null; // 初始化预编译语句对象
ResultSet resultSet = null; // 初始化结果集对象
try {
if(!supplierInf.getName().equals("")){
String s='%'+supplierInf.getName()+'%';
preparedStatement = conn.prepareStatement("select * from supplierInf where name like ? and delmark = 1");
preparedStatement.setString(1, s);
if(!supplierInf.getName().equals("")){ // 如果供应商名称不为空
String s='%'+supplierInf.getName()+'%'; // 构建模糊查询字符串
preparedStatement = conn.prepareStatement("select * from supplierInf where name like ? and delmark = 1"); // 准备SQL查询语句
preparedStatement.setString(1, s); // 设置查询参数
}else
preparedStatement = conn.prepareStatement("select * from supplierInf where delmark = 1");
resultSet = preparedStatement.executeQuery();
while (resultSet.next()) {
supplierInf = new SupplierInf();
supplierInf.setId(resultSet.getInt("id"));
supplierInf.setName(resultSet.getString("name"));
supplierInf.setAddress(resultSet.getString("address"));
supplierInf.setContact(resultSet.getString("contact"));
supplierInf.setEmail(resultSet.getString("email"));
supplierInf.setDelmark(1);
v.add(supplierInf);
preparedStatement = conn.prepareStatement("select * from supplierInf where delmark = 1"); // 准备SQL查询语句选择未被标记为删除的供应商信息
resultSet = preparedStatement.executeQuery(); // 执行查询
while (resultSet.next()) { // 遍历结果集
supplierInf = new SupplierInf(); // 创建一个新的供应商信息对象
supplierInf.setId(resultSet.getInt("id")); // 设置供应商ID
supplierInf.setName(resultSet.getString("name")); // 设置供应商名称
supplierInf.setAddress(resultSet.getString("address")); // 设置供应商地址
supplierInf.setContact(resultSet.getString("contact")); // 设置供应商联系人
supplierInf.setEmail(resultSet.getString("email")); // 设置供应商邮箱
supplierInf.setDelmark(1); // 设置删除标记
v.add(supplierInf); // 将供应商信息对象添加到向量中
}
Iterator<SupplierInf> it=v.iterator(); // 获取向量的迭代器
while(it.hasNext()){ // 遍历向量
supplierInf=it.next(); // 获取下一个供应商信息对象
System.out.println(supplierInf.getId()+" "+supplierInf.getName()+" "+supplierInf.getAddress()+" "+supplierInf.getContact()+" "+supplierInf.getEmail()+" "+supplierInf.getDelmark()+" "); // 打印供应商信息
}
Iterator<SupplierInf> it=v.iterator();
while(it.hasNext()){
supplierInf=it.next();
System.out.println(supplierInf.getId()+" "+supplierInf.getName()+" "+supplierInf.getAddress()+" "+supplierInf.getContact()+" "+supplierInf.getEmail()+" "+supplierInf.getDelmark()+" ");
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
JDBCUtil.close(resultSet, preparedStatement, conn);
} catch (SQLException e) { // 捕获SQL异常
e.printStackTrace(); // 打印异常堆栈信息
} finally { // 无论是否发生异常,都会执行的代码块
JDBCUtil.close(resultSet, preparedStatement, conn); // 关闭结果集、预编译语句和数据库连接
}
return v;
return v; // 返回存储供应商信息的向量
}
// 添加供应商信息的方法
/**
*
*
* @param supplierInf
* @return 10
*/
@Override
public int addSupplierInf(SupplierInf supplierInf) {
int flag = 0;
Connection conn = JDBCUtil.getConn();
PreparedStatement preparedStatement = null;
int flag = 0; // 初始化标志为0
Connection conn = JDBCUtil.getConn(); // 获取数据库连接
PreparedStatement preparedStatement = null; // 初始化预编译语句对象
try {
preparedStatement = conn.prepareStatement
("insert into supplierInf values (null,?,?,?,?,?)");
("insert into supplierInf values (null,?,?,?,?,?)"); // 准备SQL插入语句
//preparedStatement.setInt(1, supplierInf.getId());
preparedStatement.setString(1, supplierInf.getName());
preparedStatement.setString(2, supplierInf.getAddress());
preparedStatement.setString(3, supplierInf.getContact());
preparedStatement.setString(4, supplierInf.getEmail());
preparedStatement.setInt(5, 1);
preparedStatement.executeUpdate();
flag = 1;
} catch (SQLException e) {
e.printStackTrace();
} finally {
JDBCUtil.close(null,preparedStatement, conn);
preparedStatement.setString(1, supplierInf.getName()); // 设置供应商名称
preparedStatement.setString(2, supplierInf.getAddress()); // 设置供应商地址
preparedStatement.setString(3, supplierInf.getContact()); // 设置供应商联系人
preparedStatement.setString(4, supplierInf.getEmail()); // 设置供应商邮箱
preparedStatement.setInt(5, 1); // 设置删除标记
preparedStatement.executeUpdate(); // 执行插入操作
flag = 1; // 设置标志为1表示插入成功
} catch (SQLException e) { // 捕获SQL异常
e.printStackTrace(); // 打印异常堆栈信息
} finally { // 无论是否发生异常,都会执行的代码块
JDBCUtil.close(null,preparedStatement, conn); // 关闭预编译语句和数据库连接
}
return flag;
}
return flag; // 返回插入结果标志
}
// 删除供应商信息的方法
/**
* ID
*
* @param id ID
* @return 10
*/
@Override
public int deleteSupplierInf(int id) {
int flag = 0;
Connection conn = JDBCUtil.getConn();
PreparedStatement preparedStatement = null;
int flag = 0; // 初始化标志为0
Connection conn = JDBCUtil.getConn(); // 获取数据库连接
PreparedStatement preparedStatement = null; // 初始化预编译语句对象
try {
preparedStatement = conn.prepareStatement
("delete from supplierInf where id = ?");
preparedStatement.setInt(1, id);
preparedStatement.executeUpdate();
flag = 1;
} catch (SQLException e) {
e.printStackTrace();
} finally {
JDBCUtil.close(null,preparedStatement, conn);
("delete from supplierInf where id = ?"); // 准备SQL删除语句
preparedStatement.setInt(1, id); // 设置供应商ID
preparedStatement.executeUpdate(); // 执行删除操作
flag = 1; // 设置标志为1表示删除成功
} catch (SQLException e) { // 捕获SQL异常
e.printStackTrace(); // 打印异常堆栈信息
} finally { // 无论是否发生异常,都会执行的代码块
JDBCUtil.close(null,preparedStatement, conn); // 关闭预编译语句和数据库连接
}
return flag;
return flag; // 返回删除结果标志
}
// 更新供应商信息的方法
/**
*
*
* @param supplierInf
* @return 10
*/
@Override
public int updateSupplierInf(SupplierInf supplierInf) {
int flag=0;
Connection conn = JDBCUtil.getConn();
PreparedStatement preparedStatement = null;
int flag=0; // 初始化标志为0
Connection conn = JDBCUtil.getConn(); // 获取数据库连接
PreparedStatement preparedStatement = null; // 初始化预编译语句对象
try {
preparedStatement = conn.prepareStatement("update supplierInf set name=?,address=?,contact=?,email=?,delmark=? where id = ?");
preparedStatement.setString(1,supplierInf.getName());
preparedStatement.setString(2,supplierInf.getAddress());
preparedStatement.setString(3,supplierInf.getContact());
preparedStatement.setString(4, supplierInf.getEmail());
preparedStatement.setInt(5, supplierInf.getDelmark());
preparedStatement.setInt(6,supplierInf.getId());
preparedStatement.executeUpdate();
flag = 1;
} catch (SQLException e) {
e.printStackTrace();
} finally {
JDBCUtil.close(null, preparedStatement, conn);
preparedStatement = conn.prepareStatement("update supplierInf set name=?,address=?,contact=?,email=?,delmark=? where id = ?"); // 准备SQL更新语句
preparedStatement.setString(1,supplierInf.getName()); // 设置供应商名称
preparedStatement.setString(2,supplierInf.getAddress()); // 设置供应商地址
preparedStatement.setString(3,supplierInf.getContact()); // 设置供应商联系人
preparedStatement.setString(4, supplierInf.getEmail()); // 设置供应商邮箱
preparedStatement.setInt(5, supplierInf.getDelmark()); // 设置删除标记
preparedStatement.setInt(6,supplierInf.getId()); // 设置供应商ID
preparedStatement.executeUpdate(); // 执行更新操作
flag = 1; // 设置标志为1表示更新成功
} catch (SQLException e) { // 捕获SQL异常
e.printStackTrace(); // 打印异常堆栈信息
} finally { // 无论是否发生异常,都会执行的代码块
JDBCUtil.close(null, preparedStatement, conn); // 关闭预编译语句和数据库连接
}
return flag;
return flag; // 返回更新结果标志
}
// 获取所有供应商名称的方法
// 该方法从数据库中查询所有供应商的名称,并将其存储在一个列表中返回
@Override
public ArrayList<String> findNameSupplier() {
Connection conn=JDBCUtil.getConn();
ArrayList<String> v = new ArrayList<String>();
SupplierInf supplierInf;
PreparedStatement pstmt = null;
ResultSet resultSet=null;
v.add("全部");
Connection conn=JDBCUtil.getConn(); // 获取数据库连接
ArrayList<String> v = new ArrayList<String>(); // 创建一个列表用于存储供应商名称
SupplierInf supplierInf; // 声明一个供应商信息对象
PreparedStatement pstmt = null; // 初始化预编译语句对象
ResultSet resultSet=null; // 初始化结果集对象
v.add("全部"); // 添加默认选项“全部”
try {
pstmt = conn.prepareStatement("select * from supplierInf");
resultSet = pstmt.executeQuery();
while(resultSet.next()){
v.add(resultSet.getString("name"));
pstmt = conn.prepareStatement("select * from supplierInf"); // 准备SQL查询语句
resultSet = pstmt.executeQuery(); // 执行查询
while(resultSet.next()){ // 遍历结果集
v.add(resultSet.getString("name")); // 将供应商名称添加到列表中
}
} catch (SQLException e) {
} catch (SQLException e) { // 捕获SQL异常
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
JDBCUtil.close(resultSet, pstmt, conn);
e.printStackTrace(); // 打印异常堆栈信息
}finally{ // 无论是否发生异常,都会执行的代码块
JDBCUtil.close(resultSet, pstmt, conn); // 关闭结果集、预编译语句和数据库连接
}
return v;
return v; // 返回存储供应商名称的列表
}
// 根据供应商名称查找其ID的方法
/**
* ID
* ID0
* -1
*
* @param name
* @return ID
*/
@Override
public int findIdSupplierByName(String name) {
int flag = -1;
Connection conn = JDBCUtil.getConn();
PreparedStatement preparedStatement = null;
ResultSet resultSet= null;
int id=0;
int flag = -1; // 初始化标志为-1
Connection conn = JDBCUtil.getConn(); // 获取数据库连接
PreparedStatement preparedStatement = null; // 初始化预编译语句对象
ResultSet resultSet= null; // 初始化结果集对象
int id=0; // 初始化供应商ID为0
try {
if(name.equals("全部"))
return id;
if(name.equals("全部")) // 如果供应商名称为“全部”
return id; // 返回默认ID
preparedStatement = conn.prepareStatement
("select * from supplierInf where name=?");
preparedStatement.setString(1, name);
resultSet=preparedStatement.executeQuery();
if(resultSet.next()){
return resultSet.getInt("id");
("select * from supplierInf where name=?"); // 准备SQL查询语句
preparedStatement.setString(1, name); // 设置查询参数
resultSet=preparedStatement.executeQuery(); // 执行查询
if(resultSet.next()){ // 如果找到对应记录
return resultSet.getInt("id"); // 返回供应商ID
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
JDBCUtil.close(null,preparedStatement, conn);
} catch (SQLException e) { // 捕获SQL异常
e.printStackTrace(); // 打印异常堆栈信息
} finally { // 无论是否发生异常,都会执行的代码块
JDBCUtil.close(null,preparedStatement, conn); // 关闭预编译语句和数据库连接
}
return flag;
return flag; // 返回查询结果标志
}
}
}

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

@ -1,152 +1,174 @@
package com.lingnan.supermarket.dao.impl;
import com.lingnan.supermarket.dao.inRecordService;
import com.lingnan.supermarket.dto.InRecord;
import com.lingnan.supermarket.dto.Production;
import com.lingnan.supermarket.utils.JDBCUtil;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.Vector;
import com.lingnan.supermarket.dao.inRecordService;
import com.lingnan.supermarket.dto.InOrder;
import com.lingnan.supermarket.dto.InRecord;
import com.lingnan.supermarket.dto.Production;
import com.lingnan.supermarket.dto.User;
import com.lingnan.supermarket.utils.JDBCUtil;
/**
*
* @cwf2210461197 2024/12/2
* @version 1.0
*/
public class inRecordServiceImpl implements inRecordService{
/**
*
* @return
*/
@Override
public Vector<InRecord> findAllinRecord() {
Vector<InRecord> inRecords = new Vector<InRecord>();
Connection conn = JDBCUtil.getConn();
PreparedStatement preparedStatement = null;
ResultSet resultSet=null;
String SQL = "select * from inRecord";
Vector<InRecord> inRecords = new Vector<InRecord>(); // 创建一个向量用于存储进货记录
Connection conn = JDBCUtil.getConn(); // 获取数据库连接
PreparedStatement preparedStatement = null; // 初始化预编译语句对象
ResultSet resultSet=null; // 初始化结果集对象
String SQL = "select * from inRecord"; // SQL查询语句选择所有进货记录
try {
preparedStatement = conn.prepareStatement(SQL);
resultSet = preparedStatement.executeQuery();
while(resultSet.next()) {
InRecord inRecord = new InRecord();
inRecord.setiNumber(resultSet.getString("iNumber"));
inRecord.setSum(resultSet.getInt("sum"));
inRecord.setInPrice(resultSet.getFloat("inPrice"));
inRecords.add(inRecord);
preparedStatement = conn.prepareStatement(SQL); // 准备SQL语句
resultSet = preparedStatement.executeQuery(); // 执行查询
while(resultSet.next()) { // 遍历结果集
InRecord inRecord = new InRecord(); // 创建一个新的进货记录对象
inRecord.setiNumber(resultSet.getString("iNumber")); // 设置进货单号
inRecord.setSum(resultSet.getInt("sum")); // 设置进货数量
inRecord.setInPrice(resultSet.getFloat("inPrice")); // 设置进货价格
inRecords.add(inRecord); // 将进货记录对象添加到向量中
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
JDBCUtil.close(resultSet, preparedStatement, conn);
} catch (SQLException e) { // 捕获SQL异常
e.printStackTrace(); // 打印异常堆栈信息
} finally { // 无论是否发生异常,都会执行的代码块
JDBCUtil.close(resultSet, preparedStatement, conn); // 关闭结果集、预编译语句和数据库连接
}
return inRecords;
return inRecords; // 返回存储所有进货记录的向量
}
@Override
/**
*
*
* @param iNumber
* @return
*/
@Override
public Vector<InRecord> findByIdinRecord(String iNumber) {
InRecord inRecord;
Vector<InRecord> v = new Vector<InRecord>();
Connection conn = JDBCUtil.getConn();
PreparedStatement preparedStatement = null;
ResultSet resultSet = null;
InRecord inRecord; // 声明一个进货记录对象
Vector<InRecord> v = new Vector<InRecord>(); // 创建一个向量用于存储进货记录
Connection conn = JDBCUtil.getConn(); // 获取数据库连接
PreparedStatement preparedStatement = null; // 初始化预编译语句对象
ResultSet resultSet = null; // 初始化结果集对象
try {
preparedStatement = conn.prepareStatement("select * from inRecord where iNumber = ?");
preparedStatement.setString(1, iNumber);
resultSet = preparedStatement.executeQuery();
while(resultSet.next()) {
inRecord = new InRecord();
inRecord.setiNumber(resultSet.getString("iNumber"));
inRecord.setId(resultSet.getString("id"));
inRecord.setSum(resultSet.getInt("sum"));
inRecord.setInPrice(resultSet.getFloat("Price"));
v.add(inRecord);
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
JDBCUtil.close(resultSet, preparedStatement, conn);
preparedStatement = conn.prepareStatement("select * from inRecord where iNumber = ?"); // 准备SQL查询语句
preparedStatement.setString(1, iNumber); // 设置查询参数
resultSet = preparedStatement.executeQuery(); // 执行查询
while(resultSet.next()) { // 遍历结果集
inRecord = new InRecord(); // 创建一个新的进货记录对象
inRecord.setiNumber(resultSet.getString("iNumber")); // 设置进货单号
inRecord.setId(resultSet.getString("id")); // 设置商品ID
inRecord.setSum(resultSet.getInt("sum")); // 设置进货数量
inRecord.setInPrice(resultSet.getFloat("Price")); // 设置进货价格
v.add(inRecord); // 将进货记录对象添加到向量中
}
} catch (SQLException e) { // 捕获SQL异常
e.printStackTrace(); // 打印异常堆栈信息
} finally { // 无论是否发生异常,都会执行的代码块
JDBCUtil.close(resultSet, preparedStatement, conn); // 关闭结果集、预编译语句和数据库连接
}
return v;
return v; // 返回存储进货记录的向量
}
@Override
public int addinRecord(InRecord ir) {
int flag = 0;
String iNumber = ir.getiNumber();
int sum = ir.getSum();
Float inPrice = ir.getInPrice();
Connection conn = JDBCUtil.getConn();
PreparedStatement preparedStatement = null;
// 该方法用于将进货记录添加到数据库中。
// 参数 ir 是一个包含进货信息的对象。
// 返回值 flag 表示插入的结果1表示成功-1表示失败。
public int addinRecord(InRecord ir) {
int flag = 0; // 初始化标志为0
String iNumber = ir.getiNumber(); // 获取进货单号
int sum = ir.getSum(); // 获取进货数量
Float inPrice = ir.getInPrice(); // 获取进货价格
Connection conn = JDBCUtil.getConn(); // 获取数据库连接
PreparedStatement preparedStatement = null; // 初始化预编译语句对象
try {
preparedStatement = conn.prepareStatement
("insert into inRecord values (?,?,?)");
preparedStatement.setString(1, iNumber);
preparedStatement.setInt(2, sum);
preparedStatement.setFloat(3, inPrice);
preparedStatement.executeUpdate();
flag = 1;
} catch (SQLException e) {
flag = -1;
e.printStackTrace();
} finally {
JDBCUtil.close(null,preparedStatement, conn);
("insert into inRecord values (?,?,?)"); // 准备SQL插入语句
preparedStatement.setString(1, iNumber); // 设置进货单号
preparedStatement.setInt(2, sum); // 设置进货数量
preparedStatement.setFloat(3, inPrice); // 设置进货价格
preparedStatement.executeUpdate(); // 执行插入操作
flag = 1; // 设置标志为1表示插入成功
} catch (SQLException e) { // 捕获SQL异常
flag = -1; // 设置标志为-1表示插入失败
e.printStackTrace(); // 打印异常堆栈信息
} finally { // 无论是否发生异常,都会执行的代码块
JDBCUtil.close(null,preparedStatement, conn); // 关闭预编译语句和数据库连接
}
return flag;
return flag; // 返回插入结果标志
}
@Override
// 删除进货记录方法,根据进货单号进行删除操作
@Override
public int deleteinRecord(String iNumber) {
int flag = 0;
Connection conn = JDBCUtil.getConn();
PreparedStatement preparedStatement = null;
int flag = 0; // 初始化标志为0
Connection conn = JDBCUtil.getConn(); // 获取数据库连接
PreparedStatement preparedStatement = null; // 初始化预编译语句对象
try {
preparedStatement = conn.prepareStatement
("delete from inRecord where iNumber = ?");
preparedStatement.setString(1, iNumber);
preparedStatement.executeUpdate();
flag = 1;
} catch (SQLException e) {
flag = -1;
e.printStackTrace();
} finally {
JDBCUtil.close(null,preparedStatement, conn);
("delete from inRecord where iNumber = ?"); // 准备SQL删除语句
preparedStatement.setString(1, iNumber); // 设置进货单号
preparedStatement.executeUpdate(); // 执行删除操作
flag = 1; // 设置标志为1表示删除成功
} catch (SQLException e) { // 捕获SQL异常
flag = -1; // 设置标志为-1表示删除失败
e.printStackTrace(); // 打印异常堆栈信息
} finally { // 无论是否发生异常,都会执行的代码块
JDBCUtil.close(null,preparedStatement, conn); // 关闭预编译语句和数据库连接
}
return flag;
return flag; // 返回删除结果标志
}
public boolean insertInRecord(String iNumber,Production p) {
boolean flag = false;
Connection conn = JDBCUtil.getConn();
PreparedStatement preparedStatement = null;
/**
*
*
* @param iNumber
* @param p
* @return truefalse
*/
public boolean insertInRecord(String iNumber,Production p) {
boolean flag = false; // 初始化标志为false
Connection conn = JDBCUtil.getConn(); // 获取数据库连接
PreparedStatement preparedStatement = null; // 初始化预编译语句对象
try {
preparedStatement = conn.prepareStatement("insert into inRecord values(?,?,?,?)");
preparedStatement.setString(1, iNumber);
preparedStatement.setString(2, p.getId());
preparedStatement.setInt(3,p.getSum());
preparedStatement.setFloat(4, p.getPrice());
if(preparedStatement.executeUpdate()==1)
flag = true;
} catch (SQLException e) {
e.printStackTrace();
} finally {
JDBCUtil.close(null,preparedStatement, conn);
preparedStatement = conn.prepareStatement("insert into inRecord values(?,?,?,?)"); // 准备SQL插入语句
preparedStatement.setString(1, iNumber); // 设置进货单号
preparedStatement.setString(2, p.getId()); // 设置商品ID
preparedStatement.setInt(3,p.getSum()); // 设置进货数量
preparedStatement.setFloat(4, p.getPrice()); // 设置进货价格
if(preparedStatement.executeUpdate()==1) // 执行插入操作
flag = true; // 如果成功执行插入设置标志为true
} catch (SQLException e) { // 捕获SQL异常
e.printStackTrace(); // 打印异常堆栈信息
} finally { // 无论是否发生异常,都会执行的代码块
JDBCUtil.close(null,preparedStatement, conn); // 关闭预编译语句和数据库连接
}
return flag;
return flag; // 返回插入结果标志
}
}
}

@ -1,18 +1,19 @@
package com.lingnan.supermarket.dao;
import java.util.Vector;
import com.lingnan.supermarket.dto.InOrder;
import java.util.Vector;
// 进货订单服务接口,定义了与进货订单相关的操作
public interface inOrderService {
//查询全部进货订单
Vector<InOrder> findAllInOrder ();
//查询某个进货订单
InOrder findByIdinOrder (String iNumber);
//默认princial为a1. 创建时new一个时间插入,总价随机模拟
// 添加新的进货订单
int addInOrder(String iNumber,float allInPrice );
// 删除指定的进货订单
int deleteInOrder(String iNumber);
}

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

@ -44,7 +44,7 @@ public class UserInfDialog extends JDialog implements ActionListener {
// 下拉框组件,用于选择用户权限(这里部分代码被注释掉,可能原本有完整的权限选择功能,后简化了)
private JComboBox<String> combo;
// 下拉框中的选项内容,包括当前权限以及不同的权限角色
private String[] identity = { "当前权限", "收银员", "管理员", "超级管理员" };
private String[] identity = { "当前权限", "进货员","收银员", "管理员", "超级管理员" };
// 父窗口JFrame的引用可能用于在某些操作后对父窗口进行处理
private JFrame JFrame;
@ -189,6 +189,14 @@ public class UserInfDialog extends JDialog implements ActionListener {
}
// 内部类实现了ItemListener接口用于监听下拉框选项变化事件这里部分代码被注释掉可能原本有完整的权限选择功能后简化了
/**
* cwf 2024/12/11
*
* sSuper1.equals("进货员")
* sSuper = 3;
*/
public class MyItemListener implements ItemListener {
@Override
@ -198,13 +206,15 @@ public class UserInfDialog extends JDialog implements ActionListener {
// 获取当前选中的下拉框选项内容
String sSuper1 = (String) cb.getSelectedItem();
if (sSuper1.equals("当前权限"))
sSuper = user.getUsuper();
sSuper = user.getUsuper(); // 保持原权限
else if (sSuper1.equals("收银员"))
sSuper = 2;
else if (sSuper1.equals("管理员")):
sSuper = 2; // 收银员权限
else if (sSuper1.equals("管理员")) // 新增权限角色
sSuper = 1;
else
sSuper = 0;
else if (sSuper1.equals("进货员")) // 新增权限角色
sSuper = 3;
else
sSuper = 0; // 超级管理员
}
}
}

@ -2,26 +2,40 @@ package com.lingnan.supermarket.dto;
import com.lingnan.supermarket.dto.base.BsDomain;
public class InRecord extends BsDomain{
private String iNumber;
private int sum;
private Float inPrice;
// 表示入库记录的数据传输对象类继承自BsDomain
public class InRecord extends BsDomain {
private String iNumber; // 入库编号
private int sum; // 入库总数
private Float inPrice; // 入库单价
// 获取入库编号
public String getiNumber() {
return iNumber;
}
// 设置入库编号
public void setiNumber(String iNumber) {
this.iNumber = iNumber;
}
// 获取入库总数
public int getSum() {
return sum;
}
// 设置入库总数
public void setSum(int sum) {
this.sum = sum;
}
// 获取入库单价
public Float getInPrice() {
return inPrice;
}
// 设置入库单价
public void setInPrice(Float inPrice) {
this.inPrice = inPrice;
}
}

@ -2,22 +2,20 @@ package com.lingnan.supermarket.dto;
import com.lingnan.supermarket.dto.base.BaseDomain;
// 供应商信息类继承自BaseDomain
public class SupplierInf extends BaseDomain{
private String name;
private String address;
private String contact;
private String email;
private String name; // 供应商名称
private String address; // 供应商地址
private String contact; // 供应商联系人
private String email; // 供应商电子邮件
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
private int delmark;
private int delmark; // 删除标记
public int getDelmark() {
return delmark;
}
@ -42,4 +40,4 @@ public class SupplierInf extends BaseDomain{
public void setContact(String contact) {
this.contact = contact;
}
}
}

@ -1,69 +1,70 @@
package com.lingnan.supermarket.table;
import java.util.List;
import java.util.Vector;
import javax.swing.JFrame;
import javax.swing.table.AbstractTableModel;
import com.lingnan.supermarket.dto.Buffer;
import com.lingnan.supermarket.dao.impl.inOrderServiceImpl;
import com.lingnan.supermarket.dao.impl.productionImpl;
import com.lingnan.supermarket.dto.InOrder;
import com.lingnan.supermarket.dto.Buffer;
import com.lingnan.supermarket.dto.Production;
import com.lingnan.supermarket.dto.User;
import com.lingnan.supermarket.dao.UserService;
import com.lingnan.supermarket.dao.impl.*;
import com.lingnan.supermarket.dialog.InDialog;
import javax.swing.table.AbstractTableModel;
import java.util.Vector;
// 定义InOrderTM类继承自AbstractTableModel
public class InOrderTM extends AbstractTableModel{
// 定义列名数组
private String [] columnName = {"订单号","总价","时间","负责人","状态"};
// 实例化生产实现类
private productionImpl prodDao = new productionImpl();
// 用于存储InOrder对象的向量
private Vector<InOrder> InOrders;
// 实例化入库订单服务实现类
private inOrderServiceImpl inOrderImpl= new inOrderServiceImpl();
// 用于存储当前操作的InOrder对象
private InOrder inOrder ;
// 用于存储当前操作的订单号
String iNumber ;/*订单号*/
// 获取所有入库订单记录
public void allInOrderRecord() {
//将添加的商品加入到静态变量Vector数组中
// 将添加的商品加入到静态变量Vector数组中
/*prod = InDialog.getProduction();*/
InOrders = inOrderImpl.findAllInOrder();
}
//查找分类结果
// 根据分类查找结果
public void resultOfFind(int catalog) {
if(catalog==0)
InOrders = inOrderImpl.findAllInOrder();
else
InOrders = inOrderImpl.FindStatus(catalog);
}
//根据订单查找
// 根据订单查找
public void resultOfNumber(String Number) {
InOrders=new Vector<InOrder>();
inOrder = inOrderImpl.findByIdinOrder(Number);
InOrders.add(inOrder);
}
// 返回表格行数
@Override
public int getRowCount() {
return InOrders.size();
}
/* public Float getAllPrice() {
return BufferImpl.InBufferAllPrice();
}
*/
/* public Float getAllPrice() {
return BufferImpl.InBufferAllPrice();
}
*/
// 返回列数
@Override
public int getColumnCount() {
public int getColumnCount() {
return columnName.length;
}
// 获取指定单元格的值
@Override
public Object getValueAt(int rowIndex, int columnIndex) {
inOrder = InOrders.get(rowIndex);
@ -76,7 +77,7 @@ public class InOrderTM extends AbstractTableModel{
}else if(columnIndex==1) {
return inOrder.getAllInPrice();
}else if(columnIndex==2) {
return inOrder.getInDate();
return inOrder.getInDate();
}else if(columnIndex==3) {
return inOrder.getPrincipal();
}else if(columnIndex==4) {
@ -92,16 +93,17 @@ public class InOrderTM extends AbstractTableModel{
return null;
}
}
// 返回要修改或删除的记录的订单号
public String getINumber() { /*返回要修改或删除的记录*/
return iNumber;
}
// 返回指定列的列名
@Override
public String getColumnName(int column) {
return columnName[column];
}
}
}

@ -1,62 +1,60 @@
package com.lingnan.supermarket.table;
import java.util.List;
import java.util.Vector;
import javax.swing.JFrame;
import javax.swing.table.AbstractTableModel;
import com.lingnan.supermarket.dto.Buffer;
import com.lingnan.supermarket.dto.InOrder;
import com.lingnan.supermarket.dao.impl.inRecordServiceImpl;
import com.lingnan.supermarket.dao.impl.productionImpl;
import com.lingnan.supermarket.dto.InRecord;
import com.lingnan.supermarket.dto.Buffer;
import com.lingnan.supermarket.dto.Production;
import com.lingnan.supermarket.dto.User;
import com.lingnan.supermarket.dao.UserService;
import com.lingnan.supermarket.dao.impl.*;
import com.lingnan.supermarket.dialog.InDialog;
import javax.swing.table.AbstractTableModel;
import java.util.Vector;
// 定义InRecordTM类继承自AbstractTableModel
public class InRecordTM extends AbstractTableModel{
// 定义列名数组
private String [] columnName = {"订单号","id","数量","金额"};
// 实例化生产实现类
private productionImpl prodDao = new productionImpl();
// 用于存储InRecord对象的向量
private Vector<InRecord> InRecords;
// 实例化入库记录服务实现类
private inRecordServiceImpl inRecordImpl = new inRecordServiceImpl();
// 用于存储当前操作的InRecord对象
private InRecord inRecord= new InRecord();
// 用于存储当前操作的订单号
private String iNumber ;/*订单号*/
// 构造方法,接收一个订单号作为参数
public InRecordTM(String iNumber) {
this.iNumber=iNumber;
}
// 根据订单号查找入库记录
public void findInRecordByINumber() {
//将添加的商品加入到静态变量Vector数组中
// 将添加的商品加入到静态变量Vector数组中
/*prod = InDialog.getProduction();*/
InRecords = inRecordImpl.findByIdinRecord(iNumber);
}
// 返回表格行数
@Override
public int getRowCount() {
return InRecords.size();
}
/* public Float getAllPrice() {
return BufferImpl.InBufferAllPrice();
}
*/
/* public Float getAllPrice() {
return BufferImpl.InBufferAllPrice();
}
*/
// 返回列数
@Override
public int getColumnCount() {
public int getColumnCount() {
return columnName.length;
}
// 获取指定单元格的值
@Override
public Object getValueAt(int rowIndex, int columnIndex) {
inRecord = InRecords.get(rowIndex);
@ -69,23 +67,24 @@ public class InRecordTM extends AbstractTableModel{
}else if(columnIndex==1) {
return inRecord.getId();
}else if(columnIndex==2) {
return inRecord.getSum();
return inRecord.getSum();
}else if(columnIndex==3) {
return inRecord.getInPrice();
}else {
return null;
}
}
// 返回要修改或删除的记录的订单号
public String getINumber() { /*返回要修改或删除的记录*/
return iNumber;
}
// 返回指定列的列名
@Override
public String getColumnName(int column) {
return columnName[column];
}
}
}

@ -1,99 +1,87 @@
package com.lingnan.supermarket.table;
package com.lingnan.supermarket.table; // 定义包名
import java.util.List;
import java.util.Vector;
import com.lingnan.supermarket.dao.impl.productionImpl;
import com.lingnan.supermarket.dto.Production;
import javax.swing.JFrame;
import javax.swing.table.AbstractTableModel;
import java.util.Vector;
// 定义InTableModel类继承自AbstractTableModel
public class InTableModel extends AbstractTableModel {
import com.lingnan.supermarket.dto.InOrder;
import com.lingnan.supermarket.dto.Production;
import com.lingnan.supermarket.dto.User;
import com.lingnan.supermarket.dao.UserService;
import com.lingnan.supermarket.dao.impl.*;
import com.lingnan.supermarket.dialog.InDialog;
// 列名数组
private String[] columnName = {"id", "名称", "数量", "单价", "价格", "保质期", "类别", "供应商id"};
// 声明生产实现类的实例
private productionImpl prodDao = new productionImpl();
public class InTableModel extends AbstractTableModel{
private String [] columnName = {"id","名称","数量","单价","价格","保质期","类别","供应商id"};
// 用于存储Production对象的向量
private Vector<Production> v;
private productionImpl prodDao = new productionImpl();
private Vector<Production> v;
// 用于存储选中记录的id
String id;
String id ;
// 构造方法接收一个Production的向量作为参数
public InTableModel(Vector<Production> v) {
System.out.println("调用imtablemodel里面的构造函数");
this.v=v;
System.out.println("调用InTableModel里面的构造函数");
this.v = v; // 将传入的向量赋值给实例变量
}
// 返回表格行数
public int getRowCount() {
return v.size();
return v.size(); // 向量的大小即为行数
}
// 计算并返回所有商品的总价格
public Float getAllPrice() {
Float allPrice=(float) 0;
for(Production p:v) {
allPrice+=p.getPrice();
Float allPrice = (float) 0; // 初始化总价格为0
for (Production p : v) { // 遍历每个Production对象
allPrice += p.getPrice(); // 累加单个产品的价格
}
return allPrice;
return allPrice; // 返回总价格
}
// 返回列数
@Override
public int getColumnCount() {
return columnName.length;
public int getColumnCount() {
return columnName.length; // 列数为列名数组的长度
}
// 获取指定单元格的值
@Override
public Object getValueAt(int rowIndex, int columnIndex) {
Production p = v.get(rowIndex);
/* System.out.println( "id="+users.get(rowIndex).getId());
System.out.println("rowIndex"+rowIndex);
System.out.println("columnIndex"+columnIndex);*/
id=p.getId();
if(columnIndex==0) {
return p.getId();
}else if(columnIndex==1) {
return p.getName();
}else if(columnIndex==2) {
return p.getSum();
}else if(columnIndex==3) {
return p.getInPrice() ;
}else if(columnIndex==4) {
return p.getPrice() ;
}else if(columnIndex==5) {
return p.getLife();
}else if(columnIndex==6) {
return p.getName2()+p.getId2();
}else if(columnIndex==7) {
return p.getSupplyId();
}else {
return null;
Production p = v.get(rowIndex); // 获取行索引对应的Production对象
id = p.getId(); // 获取产品ID
// 根据列索引返回相应的属性值
if (columnIndex == 0) {
return p.getId(); // 返回ID
} else if (columnIndex == 1) {
return p.getName(); // 返回名称
} else if (columnIndex == 2) {
return p.getSum(); // 返回数量
} else if (columnIndex == 3) {
return p.getInPrice(); // 返回单价
} else if (columnIndex == 4) {
return p.getPrice(); // 返回价格
} else if (columnIndex == 5) {
return p.getLife(); // 返回保质期
} else if (columnIndex == 6) {
return p.getName2() + p.getId2(); // 返回类别
} else if (columnIndex == 7) {
return p.getSupplyId(); // 返回供应商ID
} else {
return null; // 其他情况返回null
}
}
public String getId() { /*返回要修改或删除的记录*/
return id;
// 返回要修改或删除的记录的ID
public String getId() {
return id; // 返回当前选中记录的ID
}
// 返回指定列的列名
@Override
public String getColumnName(int column) {
return columnName[column];
return columnName[column]; // 返回列名
}
}
}

@ -486,7 +486,7 @@ public class InView extends JPanel implements ActionListener{
CreateOrder createOrder = new CreateOrder();
String OrderText = createOrder.CreateOrder(v, s[0], s[1], allPrice,uname);
try {/*发送邮件*/
SendQQMailUtil QQEmail = new SendQQMailUtil("sender@qq.com","自行获取 SMTP 授权码","receiver@qq.com","@新民超市进货需求申请",OrderText);
SendQQMailUtil QQEmail = new SendQQMailUtil("cwfeng5@qq.com","wlcinslohrgpdiac","1912638153@qq.com","@新民超市进货需求申请",OrderText);
} catch (MessagingException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();

@ -41,77 +41,77 @@ import com.lingnan.supermarket.view.base.BaseView;
import java.awt.*;
public class MainView extends BaseView implements ActionListener, MouseListener,WindowListener{
JMenuBar menuBar;
JMenu settingMenu,helpMenu;
JMenuItem skinMenuItem,configMenuItem;
JSplitPane containerPanel;
CardLayout rightPanelLayout;
JPanel leftPanel,rightPanel;
/*菜单栏*/
JLabel logoLabel,userMenuLabel1,homeMenuLabel,userMenuLabel,inMenuLabel,
outMenuLabel,storageMenuLabel,supplierMenuLabel,catalogMenuLabel;
outMenuLabel,storageMenuLabel,supplierMenuLabel,catalogMenuLabel;
static JLabel remindMenuLabel;/*全局调用刷新*/
JPanel bottomPanel;
JLabel timeLabel;
JPanel purposePanel,timePanel;
JLabel purposeLabel;
JButton saveBtn,unSaveBtn,cancleBtn;/*退出时按钮*/
//
Timer timer;
private User user ;/*从登录界面传过来的用户信息*/
private BufferImpl bufferImpl;
private Image bgImage ;
private String iconSkin;
private int skin;
private Vector<Production> vP=new Vector<Production>() ;/*用于进货缓存*/
private int location;
private int sSuper=-1;//界面权限
private static inOrderServiceImpl inOrderImpl = new inOrderServiceImpl();
private static int unConfirmmark;/*未确认订单*/
public MainView(User user,int skin,String iconSkin) {
super(1300,850,"新民超市管理系统欢迎您",user,skin);
timer = new Timer(1000,this);
timer.start();
this.user = user;
this.sSuper=user.getUsuper();//界面权限
System.out.println("userid="+user.getId());
this.addWindowListener(this);
this.skin = skin;
this.iconSkin = iconSkin;
ImageIcon icon=new ImageIcon(iconSkin); //xxx代表图片存放路径2.png图片名称及格式
this.setIconImage(icon.getImage());
//获得未进货的信息
Vector<InOrder> vInOrder;
vInOrder = inOrderImpl.findUnconfirmInOrder();
unConfirmmark=vInOrder.size();
initView(user,skin);
}
@ -120,50 +120,49 @@ public class MainView extends BaseView implements ActionListener, MouseListener,
timer = new Timer(1000,this);
timer.start();
this.user = user;
this.sSuper=user.getUsuper();//界面权限
System.out.println("userid="+user.getId());
this.addWindowListener(this);
//获得未进货的信息
Vector<InOrder> vInOrder;
vInOrder = inOrderImpl.findUnconfirmInOrder();
unConfirmmark=vInOrder.size();
initView(user,skin);
}
public static void refreshRemind() {
Vector<InOrder> vInOrder;
vInOrder = inOrderImpl.findUnconfirmInOrder();
unConfirmmark=vInOrder.size();
remindMenuLabel.setText("待确认进货:"+unConfirmmark);
}
/* public static User getUserInf() {
return user;
}*/
@Override
protected void initView(User user,int skin) {
/*菜单栏*/
menuBar = new JMenuBar();
settingMenu = new JMenu("设置");
helpMenu = new JMenu("帮助");
skinMenuItem = new JMenuItem("随机切换皮肤",new ImageIcon("static\\icon\\skin.png"));
/* for(int i = 3;i<9;i++) {
@ -171,36 +170,36 @@ public class MainView extends BaseView implements ActionListener, MouseListener,
}*/
configMenuItem = new JMenuItem("参数设置",new ImageIcon("static\\icon\\setting.png"));
skinMenuItem.addActionListener(this);
settingMenu.add(configMenuItem);
settingMenu.add(skinMenuItem);
menuBar.add(settingMenu);
menuBar.add(helpMenu);
setJMenuBar(menuBar);
/*左边菜单栏设置*/
try {
bgImage = ImageIO.read(new File("static\\bg\\bg"+skin+".jpg"));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
leftPanel = new BGPanel(bgImage);/*皮肤*/
leftPanel.setLayout(null);
/*菜单栏:用户登录信息*/
System.out.println("用户头像地址=="+user.getImg());
JLabel logoLabel = new JLabel(new ImageIcon(user.getImg()),JLabel.LEFT);
System.out.println(user.getImg());
leftPanel.add(logoLabel);
logoLabel.setBounds(25, 30,150,150);
/*账号名字*/
String x = UsuperIcon(user.getUsuper());/*判断权限返回icon地址*/
System.out.println("身份地址:"+x);
@ -210,9 +209,9 @@ public class MainView extends BaseView implements ActionListener, MouseListener,
userMenuLabel1.setBounds(20, 170,180,32);
userMenuLabel1.setForeground(Color.white);
leftPanel.add(userMenuLabel1);/*添加用户选项到菜单栏*/
/*菜单栏:首页*/
homeMenuLabel = new JLabel("新民首页",new ImageIcon("static\\icon\\home1.png"),JLabel.LEFT);
homeMenuLabel.setFont(FontUtil.menuFont);
@ -220,9 +219,9 @@ public class MainView extends BaseView implements ActionListener, MouseListener,
homeMenuLabel.setBounds(20, 250,150,32);
homeMenuLabel.setForeground(Color.white);
leftPanel.add(homeMenuLabel);/*添加用户选项到菜单栏*/
/*菜单栏:人员管理*/
userMenuLabel = new JLabel("人员管理",new ImageIcon("static\\icon\\user1.png"),JLabel.LEFT);
userMenuLabel.setFont(FontUtil.menuFont);
@ -230,7 +229,7 @@ public class MainView extends BaseView implements ActionListener, MouseListener,
userMenuLabel.setBounds(20, 300,150,32);
userMenuLabel.setForeground(Color.white);
leftPanel.add(userMenuLabel);/*添加用户选项到菜单栏*/
/*菜单栏:进货系统*/
inMenuLabel = new JLabel("进货系统",new ImageIcon("static\\icon\\in1.png") ,JLabel.LEFT);
inMenuLabel.setFont(FontUtil.menuFont);
@ -238,7 +237,7 @@ public class MainView extends BaseView implements ActionListener, MouseListener,
inMenuLabel.setBounds(20, 350,150,32);
inMenuLabel.setForeground(Color.white);
leftPanel.add(inMenuLabel);
/*菜单栏:收银系统*/
outMenuLabel = new JLabel("收银系统",new ImageIcon("static\\icon\\out1.png") ,JLabel.LEFT);
outMenuLabel.setFont(FontUtil.menuFont);
@ -246,7 +245,7 @@ public class MainView extends BaseView implements ActionListener, MouseListener,
outMenuLabel.setBounds(20, 400,150,32);
outMenuLabel.setForeground(Color.white);
leftPanel.add(outMenuLabel);
/*菜单栏:库存*/
storageMenuLabel = new JLabel("商品库存",new ImageIcon("static\\icon\\storage1.png") ,JLabel.LEFT);
storageMenuLabel.setFont(FontUtil.menuFont);
@ -254,7 +253,7 @@ public class MainView extends BaseView implements ActionListener, MouseListener,
storageMenuLabel.setBounds(20, 450,150,32);
storageMenuLabel.setForeground(Color.white);
leftPanel.add(storageMenuLabel);
/*菜单栏:供应商*/
supplierMenuLabel = new JLabel("供应商",new ImageIcon("static\\icon\\supplier1.png") ,JLabel.LEFT);
supplierMenuLabel.setFont(FontUtil.menuFont);
@ -262,7 +261,7 @@ public class MainView extends BaseView implements ActionListener, MouseListener,
supplierMenuLabel.setBounds(20, 500,150,32);
supplierMenuLabel.setForeground(Color.white);
leftPanel.add(supplierMenuLabel);
/*菜单栏:商品目录*/
catalogMenuLabel = new JLabel("商品目录",new ImageIcon("static\\icon\\catalog1.png") ,JLabel.LEFT);
catalogMenuLabel.setFont(FontUtil.menuFont);
@ -270,7 +269,7 @@ public class MainView extends BaseView implements ActionListener, MouseListener,
catalogMenuLabel.setBounds(20,550,150,32);
catalogMenuLabel.setForeground(Color.white);
leftPanel.add(catalogMenuLabel);
/*提醒进货确认模块*/
remindMenuLabel = new JLabel("待确认进货:"+unConfirmmark,new ImageIcon("static\\icon\\remind1.png") ,JLabel.LEFT);
remindMenuLabel.setFont(FontUtil.remindFont);
@ -278,37 +277,37 @@ public class MainView extends BaseView implements ActionListener, MouseListener,
remindMenuLabel.setBounds(0,650,200,32);
remindMenuLabel.setForeground(Color.white);
leftPanel.add(remindMenuLabel);
rightPanelLayout = new CardLayout();
//0.超市首页展示
JPanel homePanel = new HomeView(this);
//1.用户管理界面:用户的列表
JPanel userPanel = new UserView(this);
//2.进货系统界面
JPanel inPanel = new InView(this,user,vP,1);
//3收银系统界面
JPanel outPanel = new OutView(this,user);
//4.库存系统界面
JPanel storagePanel = new StorageView(this);
//5.供应商界面
JPanel supplierPanel = new SupplierView(this);
//6商品目录界面
JPanel ProdCatalogPanel = new ProdCatalogView(this);
//7商品目录界面
JPanel superPanel = new SuperView(this);
//8进货信息提示
JPanel inPanel2 = new InView(this,user,vP,0);
/*添加界面并给索引*/
rightPanel = new JPanel(rightPanelLayout);
rightPanel.add(homePanel, "0");
@ -320,29 +319,29 @@ public class MainView extends BaseView implements ActionListener, MouseListener,
rightPanel.add(ProdCatalogPanel, "6");
rightPanel.add(superPanel, "7");
rightPanel.add(inPanel2, "8");
containerPanel = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,leftPanel,rightPanel);
containerPanel.setDividerLocation(180);
containerPanel.setDividerSize(0);
bottomPanel = new JPanel();//默认的布局是流式布局
bottomPanel.setBackground(Color.WHITE);
bottomPanel.setLayout(new BorderLayout());
purposePanel = new JPanel();
purposePanel.setLayout(new FlowLayout(FlowLayout.LEFT));
purposePanel.setBackground(Color.WHITE);
purposeLabel = new JLabel("当前位置是:超市首页");
purposePanel.add(purposeLabel);
timePanel=new JPanel();
timePanel.setLayout(new FlowLayout(FlowLayout.TRAILING));
timePanel.setBackground(Color.WHITE);
timeLabel = new JLabel(DateUtil.dateToString(new Date(),null));
timePanel.add(timeLabel);
bottomPanel.add(purposePanel,"West");
bottomPanel.add(timePanel,"East");
Container container = getContentPane();
@ -361,96 +360,153 @@ public class MainView extends BaseView implements ActionListener, MouseListener,
this.dispose();
new MainView(user,skin,iconSkin);
}
}
@Override/*左侧菜单栏点击事件*/
/**
* cwf 2024/12/11
*
*/
@Override
/* 左侧菜单栏点击事件 */
public void mouseClicked(MouseEvent e) {
Object source = e.getSource();
if(source==homeMenuLabel) {
rightPanelLayout.show(rightPanel,"0");
location=0;
}else if(source==userMenuLabel) {
if(sSuper==0)
rightPanelLayout.show(rightPanel,"1");
else{
rightPanelLayout.show(rightPanel,"7");
Object source = e.getSource(); // 获取点击事件的来源
// 如果点击的是首页菜单
if (source == homeMenuLabel) {
rightPanelLayout.show(rightPanel, "0"); // 显示首页界面
location = 0; // 设置当前位置为首页
}
// 如果点击的是人员管理菜单
else if (source == userMenuLabel) {
// 如果用户是管理员 (sSuper == 0) 或进货员 (sSuper == 1)
if (sSuper == 0 || sSuper == 1) {
rightPanelLayout.show(rightPanel, "1"); // 显示人员管理界面
}
// 如果用户是普通用户 (sSuper == 3)
else if (sSuper == 3) {
rightPanelLayout.show(rightPanel, "7"); // 显示普通用户界面
}
// 其他情况(例如普通用户权限)
else {
rightPanelLayout.show(rightPanel, "7"); // 显示普通用户界面
}
location = 1; // 设置当前位置为人员管理
}
// 如果点击的是进货系统菜单
else if (source == inMenuLabel) {
// 如果用户是普通用户 (sSuper == 2) 或进货员 (sSuper == 1)
if (sSuper == 2 || sSuper == 1) {
rightPanelLayout.show(rightPanel, "7"); // 显示普通用户界面
}
// 其他情况(例如管理员权限)
else {
rightPanelLayout.show(rightPanel, "2"); // 显示进货系统界面
}
location=1;
location = 2; // 设置当前位置为进货系统
}
else if(source==inMenuLabel) {
if(sSuper==2)
rightPanelLayout.show(rightPanel,"7");
else{
rightPanelLayout.show(rightPanel,"2");
// 如果点击的是收银系统菜单
else if (source == outMenuLabel) {
// 如果用户是普通用户 (sSuper == 3) 或进货员 (sSuper == 1)
if (sSuper == 3 || sSuper == 1) {
rightPanelLayout.show(rightPanel, "7"); // 显示普通用户界面
}
// 其他情况(例如管理员权限)
else {
rightPanelLayout.show(rightPanel, "3"); // 显示收银系统界面
location = 3; // 设置当前位置为收银系统
}
location=2;
}
else if(source==outMenuLabel) {
rightPanelLayout.show(rightPanel,"3");
location=3;
// 如果点击的是库存系统菜单
else if (source == storageMenuLabel) {
// 如果用户是进货员 (sSuper == 1)
if (sSuper == 1) {
rightPanelLayout.show(rightPanel, "7"); // 显示普通用户界面
}
// 其他情况(例如管理员权限)
else {
rightPanelLayout.show(rightPanel, "4"); // 显示库存系统界面
location = 4; // 设置当前位置为库存系统
}
}
else if(source==storageMenuLabel) {
rightPanelLayout.show(rightPanel,"4");
location=4;
// 如果点击的是供应商菜单
else if (source == supplierMenuLabel) {
// 如果用户是进货员 (sSuper == 1)
if (sSuper == 1) {
rightPanelLayout.show(rightPanel, "7"); // 显示普通用户界面
}
// 其他情况(例如管理员权限)
else {
rightPanelLayout.show(rightPanel, "5"); // 显示供应商界面
location = 5; // 设置当前位置为供应商
}
}
else if(source==supplierMenuLabel) {
rightPanelLayout.show(rightPanel,"5");
location=5;
// 如果点击的是商品目录菜单
else if (source == catalogMenuLabel) {
// 如果用户是进货员 (sSuper == 1)
if (sSuper == 1) {
rightPanelLayout.show(rightPanel, "7"); // 显示普通用户界面
}
// 其他情况(例如管理员权限)
else {
rightPanelLayout.show(rightPanel, "6"); // 显示商品目录界面
location = 6; // 设置当前位置为商品目录
}
}
else if(source==catalogMenuLabel) {
rightPanelLayout.show(rightPanel,"6");
location=6;
}else if(source==remindMenuLabel) {
if(sSuper==2)
rightPanelLayout.show(rightPanel,"7");
else{
rightPanelLayout.show(rightPanel,"8");
// 如果点击的是提醒菜单
else if (source == remindMenuLabel) {
// 如果用户是普通用户 (sSuper == 2) 或进货员 (sSuper == 1)
if (sSuper == 2 || sSuper == 1) {
rightPanelLayout.show(rightPanel, "7"); // 显示普通用户界面
}
location=7;
}else if(source==userMenuLabel1){
UserInfDialog userInfDialog = new UserInfDialog(this,user);
userInfDialog.setVisible(true);
location=8;
// 其他情况(例如管理员权限)
else {
rightPanelLayout.show(rightPanel, "8"); // 显示进货信息提示界面
}
location = 7; // 设置当前位置为提醒
}
// 如果点击的是用户信息菜单
else if (source == userMenuLabel1) {
UserInfDialog userInfDialog = new UserInfDialog(this, user); // 创建用户信息对话框
userInfDialog.setVisible(true); // 显示用户信息对话框
location = 8; // 设置当前位置为用户信息
}
refreshRemove();
refreshRemove(); // 刷新当前界面的位置信息
}
//获取当前位置
public void refreshRemove(){
public void refreshRemove(){
purposePanel.removeAll();
if(location==0){
purposeLabel = new JLabel("当前位置是:"+homeMenuLabel.getText());
}else if(location==1){
purposeLabel = new JLabel("当前位置是:"+userMenuLabel.getText());
}else if(location==2){
purposeLabel = new JLabel("当前位置是:"+inMenuLabel.getText());
}else if(location==3){
purposeLabel = new JLabel("当前位置是:"+outMenuLabel.getText());
}else if(location==4){
purposeLabel = new JLabel("当前位置是:"+storageMenuLabel.getText());
}else if(location==5){
purposeLabel = new JLabel("当前位置是:"+supplierMenuLabel.getText());
}else{
purposeLabel = new JLabel("当前位置是:"+catalogMenuLabel.getText());
}
purposePanel.add(purposeLabel);
purposePanel.removeAll();
if(location==0){
purposeLabel = new JLabel("当前位置是:"+homeMenuLabel.getText());
}else if(location==1){
purposeLabel = new JLabel("当前位置是:"+userMenuLabel.getText());
}else if(location==2){
purposeLabel = new JLabel("当前位置是:"+inMenuLabel.getText());
}else if(location==3){
purposeLabel = new JLabel("当前位置是:"+outMenuLabel.getText());
}else if(location==4){
purposeLabel = new JLabel("当前位置是:"+storageMenuLabel.getText());
}else if(location==5){
purposeLabel = new JLabel("当前位置是:"+supplierMenuLabel.getText());
}else{
purposeLabel = new JLabel("当前位置是:"+catalogMenuLabel.getText());
}
purposePanel.add(purposeLabel);
}
@Override
public void mousePressed(MouseEvent e) {
// TODO Auto-generated method stub
@ -460,9 +516,9 @@ public class MainView extends BaseView implements ActionListener, MouseListener,
@Override
public void mouseReleased(MouseEvent e) {
// TODO Auto-generated method stub
}
@Override/*鼠标焦点时*/
public void mouseEntered(MouseEvent e) {
Object source = e.getSource();
@ -488,21 +544,19 @@ public class MainView extends BaseView implements ActionListener, MouseListener,
}else if(source==catalogMenuLabel) {
catalogMenuLabel.setForeground(new Color(18, 150, 219));
catalogMenuLabel.setIcon(new ImageIcon("static\\icon\\catalog2.png"));
}
else if(source==userMenuLabel1) {
} else if(source==userMenuLabel1) {
userMenuLabel1.setForeground(new Color(18, 150, 219));
}
}
}
@Override
public void mouseExited(MouseEvent e) {
Object source = e.getSource();
Object source = e.getSource();
if(source==homeMenuLabel) {
homeMenuLabel.setForeground(Color.white);
homeMenuLabel.setIcon(new ImageIcon("static\\icon\\home1.png"));
}
else if(source==userMenuLabel) {
} else if(source==userMenuLabel) {
userMenuLabel.setForeground(Color.white);
userMenuLabel.setIcon(new ImageIcon("static\\icon\\user1.png"));
}else if(source==inMenuLabel) {
@ -520,31 +574,30 @@ public class MainView extends BaseView implements ActionListener, MouseListener,
}else if(source==catalogMenuLabel) {
catalogMenuLabel.setForeground(Color.white);
catalogMenuLabel.setIcon(new ImageIcon("static\\icon\\catalog1.png"));
}
else {
} else {
userMenuLabel1.setForeground(Color.white);
}
}
}
@Override
protected void initView() {
// TODO Auto-generated method stub
}
@Override
public void windowOpened(WindowEvent e) {
// TODO Auto-generated method stub
}
@Override
public void windowClosing(WindowEvent e) {
// TODO Auto-generated method stub
Object source = e.getSource();
Object source = e.getSource();
if(source==this) {/*关闭窗口时检查进货系统和出货系统是否还有记录*/
this.vP =InView.getVector();
System.out.println("v的size="+vP.size());
@ -554,7 +607,7 @@ public class MainView extends BaseView implements ActionListener, MouseListener,
closeDialog.setVisible(true);
}else
System.exit(0);
}
}
@ -562,31 +615,31 @@ public class MainView extends BaseView implements ActionListener, MouseListener,
@Override
public void windowClosed(WindowEvent e) {
// TODO Auto-generated method stub
}
@Override
public void windowIconified(WindowEvent e) {
// TODO Auto-generated method stub
}
@Override
public void windowDeiconified(WindowEvent e) {
// TODO Auto-generated method stub
}
@Override
public void windowActivated(WindowEvent e) {
// TODO Auto-generated method stub
}
@Override
public void windowDeactivated(WindowEvent e) {
// TODO Auto-generated method stub
}

Loading…
Cancel
Save