解决合并冲突

pull/20/head
“郑亦歆” 9 months ago
commit 7279fe86e2

@ -1,44 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<dataSource name="@localhost">
<database-model serializer="dbm" dbms="MYSQL" family-id="MYSQL" format-version="4.48">
<root id="1">
<DefaultCasing>lower/lower</DefaultCasing>
<DefaultEngine>InnoDB</DefaultEngine>
<DefaultTmpEngine>InnoDB</DefaultTmpEngine>
<Grants>|root||root|localhost|ALTER|G
|root||root|localhost|ALTER ROUTINE|G
|root||root|localhost|CREATE|G
|root||root|localhost|CREATE ROUTINE|G
|root||root|localhost|CREATE TABLESPACE|G
|root||root|localhost|CREATE TEMPORARY TABLES|G
|root||root|localhost|CREATE USER|G
|root||root|localhost|CREATE VIEW|G
|root||root|localhost|DELETE|G
|root||root|localhost|DROP|G
|root||root|localhost|EVENT|G
|root||root|localhost|EXECUTE|G
|root||root|localhost|FILE|G
|root||root|localhost|INDEX|G
|root||root|localhost|INSERT|G
|root||root|localhost|LOCK TABLES|G
|root||root|localhost|PROCESS|G
|root||root|localhost|REFERENCES|G
|root||root|localhost|RELOAD|G
|root||root|localhost|REPLICATION CLIENT|G
|root||root|localhost|REPLICATION SLAVE|G
|root||root|localhost|SELECT|G
|root||root|localhost|SHOW DATABASES|G
|root||root|localhost|SHOW VIEW|G
|root||root|localhost|SHUTDOWN|G
|root||mysql.session|localhost|SUPER|G
|root||root|localhost|SUPER|G
|root||root|localhost|TRIGGER|G
|root||root|localhost|UPDATE|G
|root||root|localhost|grant option|G
performance_schema|schema||mysql.session|localhost|SELECT|G
sys|schema||mysql.sys|localhost|TRIGGER|G</Grants>
<ServerVersion>5.7.44</ServerVersion>
</root>
<root id="1"/>
<collation id="2" parent="1" name="big5_chinese_ci">
<Charset>big5</Charset>
<DefaultForCharset>1</DefaultForCharset>

@ -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,44 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<dataSource name="@localhost">
<database-model serializer="dbm" dbms="MYSQL" family-id="MYSQL" format-version="4.48">
<root id="1">
<DefaultCasing>lower/lower</DefaultCasing>
<DefaultEngine>InnoDB</DefaultEngine>
<DefaultTmpEngine>InnoDB</DefaultTmpEngine>
<Grants>|root||root|localhost|ALTER|G
|root||root|localhost|ALTER ROUTINE|G
|root||root|localhost|CREATE|G
|root||root|localhost|CREATE ROUTINE|G
|root||root|localhost|CREATE TABLESPACE|G
|root||root|localhost|CREATE TEMPORARY TABLES|G
|root||root|localhost|CREATE USER|G
|root||root|localhost|CREATE VIEW|G
|root||root|localhost|DELETE|G
|root||root|localhost|DROP|G
|root||root|localhost|EVENT|G
|root||root|localhost|EXECUTE|G
|root||root|localhost|FILE|G
|root||root|localhost|INDEX|G
|root||root|localhost|INSERT|G
|root||root|localhost|LOCK TABLES|G
|root||root|localhost|PROCESS|G
|root||root|localhost|REFERENCES|G
|root||root|localhost|RELOAD|G
|root||root|localhost|REPLICATION CLIENT|G
|root||root|localhost|REPLICATION SLAVE|G
|root||root|localhost|SELECT|G
|root||root|localhost|SHOW DATABASES|G
|root||root|localhost|SHOW VIEW|G
|root||root|localhost|SHUTDOWN|G
|root||mysql.session|localhost|SUPER|G
|root||root|localhost|SUPER|G
|root||root|localhost|TRIGGER|G
|root||root|localhost|UPDATE|G
|root||root|localhost|grant option|G
performance_schema|schema||mysql.session|localhost|SELECT|G
sys|schema||mysql.sys|localhost|TRIGGER|G</Grants>
<ServerVersion>5.7.44</ServerVersion>
</root>
<root id="1"/>
<collation id="2" parent="1" name="big5_chinese_ci">
<Charset>big5</Charset>
<DefaultForCharset>1</DefaultForCharset>

@ -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,36 +1,46 @@
package com.lingnan.supermarket.componet;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Toolkit;
import javax.swing.JPanel;
public class BGPanel extends JPanel{
private Image image;
public BGPanel(Image image) {
// 定义一个构造方法接收一个Image类型的参数image用于创建BGPanel对象时传入要显示的图像
this.image = image;
// 将传入的参数image赋值给类的成员变量image
int width = Toolkit.getDefaultToolkit().getScreenSize().width;
// 通过默认工具包Toolkit获取屏幕的宽度存储在局部变量width中
int height = Toolkit.getDefaultToolkit().getScreenSize().height;
// 通过默认工具包Toolkit获取屏幕的高度存储在局部变量height中
this.setSize(width, height);
// 设置该面板BGPanel的大小为整个屏幕的大小即宽度和高度分别为获取到的屏幕宽高
}
public BGPanel(Image image,int width,int height) {
public BGPanel(Image image, int width, int height) {
// 定义另一个构造方法接收一个Image类型的参数image以及表示宽度和高度的两个int类型参数用于更灵活地创建BGPanel对象并指定其大小
this.image = image;
// 将传入的参数image赋值给类的成员变量image
this.setSize(width, height);
// 设置该面板BGPanel的大小为传入的指定宽度width和指定高度height
}
@Override
protected void paintComponent(Graphics g) {
// 重写JPanel类中的paintComponent方法用于绘制面板上的图像
super.paintComponent(g);
g.drawImage(image,0,0,getWidth(),getHeight(),this);
}
// 调用父类JPanel的paintComponent方法以确保完成一些默认的绘制操作比如背景清除等
}
g.drawImage(image, 0, 0, getWidth(), getHeight(), this);
// 使用传入的Graphics对象g在面板上绘制图像参数含义如下
// image要绘制的图像对象就是之前保存的成员变量image
// 0, 0表示在面板上绘制图像的起始坐标x坐标和y坐标这里从面板的左上角0, 0位置开始绘制
// getWidth(), getHeight():获取当前面板的宽度和高度,用于指定绘制图像时按照面板的实际大小进行拉伸或缩放,确保图像填满整个面板
// this表示图像观察者用于接收图像绘制过程中的相关通知等
}
}

@ -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; // 返回查询结果标志
}
}
}

@ -1,68 +1,62 @@
package com.lingnan.supermarket.dao.impl;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.Date;
import java.util.Vector;
import com.lingnan.supermarket.dao.inOrderService;
import com.lingnan.supermarket.dto.InOrder;
import com.lingnan.supermarket.utils.DateUtil;
import com.lingnan.supermarket.utils.JDBCUtil;
import java.sql.*;
import java.util.Vector;
public class inOrderServiceImpl implements inOrderService{
@Override
public Vector<InOrder> findAllInOrder (){
Vector<InOrder> inOrders = new Vector<InOrder>();
Connection conn = JDBCUtil.getConn();
PreparedStatement preparedStatement = null;
ResultSet resultSet=null;
public Vector<InOrder> findAllInOrder() {
Vector<InOrder> inOrders = new Vector<InOrder>(); // 创建一个向量用于存储InOrder对象
Connection conn = JDBCUtil.getConn(); // 获取数据库连接
PreparedStatement preparedStatement = null; // 声明预编译语句对象
ResultSet resultSet = null; // 声明结果集对象
// SQL查询语句选择未删除的订单并按入库日期降序排列
String SQL = "select * from inOrder where delmark=1 order by inDate desc";
try {
preparedStatement = conn.prepareStatement(SQL);
resultSet = preparedStatement.executeQuery();
while(resultSet.next()) {
InOrder inOrder = new InOrder();
preparedStatement = conn.prepareStatement(SQL); // 准备SQL语句
resultSet = preparedStatement.executeQuery(); // 执行查询
while (resultSet.next()) { // 遍历结果集
InOrder inOrder = new InOrder(); // 创建InOrder对象
// 从结果集中获取属性并设置到inOrder对象
inOrder.setiNumber(resultSet.getString("iNumber"));
inOrder.setAllInPrice(resultSet.getFloat("allInPrice"));
inOrder.setInDate(resultSet.getString("inDate"));
inOrder.setPrincipal(resultSet.getString("principal"));
inOrder.setStatus(resultSet.getInt("status"));
inOrder.setDelmark(resultSet.getInt("Delmark"));
inOrders.add(inOrder);
inOrders.add(inOrder); // 将InOrder对象添加到向量中
}
} catch (SQLException e) {
e.printStackTrace();
e.printStackTrace(); // 捕获并打印异常堆栈信息
} finally {
JDBCUtil.close(resultSet, preparedStatement, conn);
JDBCUtil.close(resultSet, preparedStatement, conn); // 关闭结果集、预编译语句和数据库连接
}
return inOrders;
return inOrders; // 返回存储所有InOrder对象的向量
}
@Override
public InOrder findByIdinOrder(String iNumber) {
InOrder inOrder = new InOrder();
Connection conn = JDBCUtil.getConn();
PreparedStatement preparedStatement = null;
ResultSet resultSet = null;
InOrder inOrder = new InOrder(); // 创建InOrder对象
Connection conn = JDBCUtil.getConn(); // 获取数据库连接
PreparedStatement preparedStatement = null; // 声明预编译语句对象
ResultSet resultSet = null; // 声明结果集对象
try {
// 准备SQL语句根据订单号查找特定的订单
preparedStatement = conn.prepareStatement("select * from inOrder where iNumber = ?");
preparedStatement.setString(1, iNumber);
resultSet = preparedStatement.executeQuery();
if (resultSet.next()) {
preparedStatement.setString(1, iNumber); // 设置订单号参数
resultSet = preparedStatement.executeQuery(); // 执行查询
if (resultSet.next()) { // 如果找到对应记录
// 从结果集中获取属性并设置到inOrder对象
inOrder.setiNumber(resultSet.getString("iNumber"));
inOrder.setAllInPrice(resultSet.getFloat("allInPrice"));
inOrder.setInDate(resultSet.getString("inDate"));
@ -70,205 +64,204 @@ public class inOrderServiceImpl implements inOrderService{
inOrder.setStatus(resultSet.getInt("status"));
} else {
return null; // 没有找到该订单或订单不存在返回null
}
}
} catch (SQLException e) {
e.printStackTrace();
e.printStackTrace(); // 捕获并打印异常堆栈信息
} finally {
JDBCUtil.close(resultSet, preparedStatement, conn);
JDBCUtil.close(resultSet, preparedStatement, conn); // 关闭结果集、预编译语句和数据库连接
}
return inOrder;
return inOrder; // 返回找到的InOrder对象
}
@Override
public int addInOrder(String iNumber, float allInPrice) {
int flag = 0;
Timestamp inDate = new Timestamp(System.currentTimeMillis());
//System.out.println(inDate);
Connection conn = JDBCUtil.getConn();
PreparedStatement preparedStatement = null;
int flag = 0; // 状态标志初始化为0
Timestamp inDate = new Timestamp(System.currentTimeMillis()); // 获取当前时间戳
Connection conn = JDBCUtil.getConn(); // 获取数据库连接
PreparedStatement preparedStatement = null; // 声明预编译语句对象
try {
preparedStatement = conn.prepareStatement
("insert into inOrder values (?,?,?,?)");
preparedStatement.setString(1, iNumber);
preparedStatement.setFloat(2, allInPrice);
preparedStatement.setTimestamp(3, inDate);
preparedStatement.setString(4, "a1");
preparedStatement.executeUpdate();
flag = 1;
// 准备SQL插入语句
preparedStatement = conn.prepareStatement("insert into inOrder values (?,?,?,?)");
preparedStatement.setString(1, iNumber); // 设置订单号参数
preparedStatement.setFloat(2, allInPrice); // 设置总价格参数
preparedStatement.setTimestamp(3, inDate); // 设置入库日期
preparedStatement.setString(4, "a1"); // 设置其他固定参数例如默认的负责人ID
preparedStatement.executeUpdate(); // 执行插入操作
flag = 1; // 标记插入成功
} catch (SQLException e) {
flag = -1;
e.printStackTrace();
flag = -1; // 插入失败时标记为-1
e.printStackTrace(); // 捕获并打印异常堆栈信息
} finally {
JDBCUtil.close(null,preparedStatement, conn);
JDBCUtil.close(null, preparedStatement, conn); // 关闭预编译语句和数据库连接
}
return flag;
}
return flag; // 返回插入结果标志
}
@Override
public int deleteInOrder(String iNumber) {
int flag = 0;
Connection conn = JDBCUtil.getConn();
PreparedStatement preparedStatement = null;
int flag = 0; // 状态标志初始化为0
Connection conn = JDBCUtil.getConn(); // 获取数据库连接
PreparedStatement preparedStatement = null; // 声明预编译语句对象
try {
preparedStatement = conn.prepareStatement
("update inOrder set delmark=0 where iNumber = ?");
preparedStatement.setString(1, iNumber);
preparedStatement.executeUpdate();
flag = 1;
// 准备SQL更新语句将delmark标记为0表示逻辑删除
preparedStatement = conn.prepareStatement("update inOrder set delmark=0 where iNumber = ?");
preparedStatement.setString(1, iNumber); // 设置订单号参数
preparedStatement.executeUpdate(); // 执行更新操作
flag = 1; // 标记删除成功
} catch (SQLException e) {
flag = -1;
e.printStackTrace();
flag = -1; // 删除失败时标记为-1
e.printStackTrace(); // 捕获并打印异常堆栈信息
} finally {
JDBCUtil.close(null,preparedStatement, conn);
JDBCUtil.close(null, preparedStatement, conn); // 关闭预编译语句和数据库连接
}
return flag;
return flag; // 返回删除结果标志
}
/*往订单表插入一条记录*/
public boolean InsertInOrder(String number,Float allPrice,String time,String username,int c){
boolean flag = false;
Connection conn = JDBCUtil.getConn();
PreparedStatement pstmt = null;
ResultSet resultSet = null;;
// 插入新的进货订单
public boolean InsertInOrder(String number, Float allPrice, String time, String username, int c) {
boolean flag = false; // 初始化标志为false
Connection conn = JDBCUtil.getConn(); // 获取数据库连接
PreparedStatement pstmt = null; // 声明预编译语句对象
ResultSet resultSet = null; // 声明结果集对象
try {
// 准备SQL插入语句
pstmt = conn.prepareStatement("insert into InOrder values(?,?,?,?,?,?)");
pstmt.setString(1, number);
pstmt.setFloat(2, allPrice);
pstmt.setString(3, time);
pstmt.setString(4, username);
pstmt.setInt(5, 2);
pstmt.setInt(6, 1);
if(pstmt.execute())
flag = true;
} catch (SQLException e) {
e.printStackTrace();
}finally {
pstmt.setString(1, number); // 设置订单号
pstmt.setFloat(2, allPrice); // 设置总价格
pstmt.setString(3, time); // 设置入库时间
pstmt.setString(4, username); // 设置负责人用户名
pstmt.setInt(5, 2); // 设置状态假设2代表某个特定状态
pstmt.setInt(6, 1); // 设置删除标记假设1表示未删除
// 执行插入操作
if (pstmt.execute())
flag = true; // 如果成功执行插入设置标志为true
JDBCUtil.close(resultSet, pstmt, conn);
} catch (SQLException e) {
e.printStackTrace(); // 捕获并打印异常堆栈信息
} finally {
JDBCUtil.close(resultSet, pstmt, conn); // 关闭结果集、预编译语句和数据库连接
}
return flag;
return flag; // 返回插入结果标志
}
/*更新状态*/
public boolean updateInOrderStatus(String iNumber,int status) {
boolean flag = false;
Connection conn = JDBCUtil.getConn();
PreparedStatement preparedStatement = null;
/* 更新状态 */
public boolean updateInOrderStatus(String iNumber, int status) {
boolean flag = false; // 初始化标志为false
Connection conn = JDBCUtil.getConn(); // 获取数据库连接
PreparedStatement preparedStatement = null; // 声明预编译语句对象
try {
// 准备SQL更新语句更新指定订单号的状态
preparedStatement = conn.prepareStatement("update inOrder set status=? where iNumber=?");
preparedStatement.setInt(1, status);
preparedStatement.setString(2,iNumber);
if(preparedStatement.executeUpdate()==1)
preparedStatement.setInt(1, status); // 设置状态
preparedStatement.setString(2, iNumber); // 设置订单号
// 如果更新操作影响了一行则设置标志为true
if (preparedStatement.executeUpdate() == 1)
flag = true;
} catch (SQLException e) {
e.printStackTrace();
e.printStackTrace(); // 捕获并打印异常堆栈信息
} finally {
JDBCUtil.close(null,preparedStatement, conn);
JDBCUtil.close(null, preparedStatement, conn); // 关闭预编译语句和数据库连接
}
return flag;
return flag; // 返回更新结果标志
}
//查找所有待入库订单*/待确认
public Vector<InOrder> findUnconfirmInOrder(){
Vector<InOrder> inOrders = new Vector<InOrder>();
Connection conn = JDBCUtil.getConn();
PreparedStatement preparedStatement = null;
ResultSet resultSet=null;
// 查找所有待入库订单(待确认)
public Vector<InOrder> findUnconfirmInOrder() {
Vector<InOrder> inOrders = new Vector<InOrder>(); // 创建一个向量用于存储InOrder对象
Connection conn = JDBCUtil.getConn(); // 获取数据库连接
PreparedStatement preparedStatement = null; // 声明预编译语句对象
ResultSet resultSet = null; // 声明结果集对象
// SQL查询语句选择状态为2并且未删除的订单
String SQL = "select * from inOrder where status=2 and delmark=1";
try {
preparedStatement = conn.prepareStatement(SQL);
resultSet = preparedStatement.executeQuery();
while(resultSet.next()) {
InOrder inOrder = new InOrder();
inOrder.setiNumber(resultSet.getString("iNumber"));
inOrder.setAllInPrice(resultSet.getFloat("allInPrice"));
inOrder.setInDate(resultSet.getString("inDate"));
inOrder.setPrincipal(resultSet.getString("principal"));
inOrder.setStatus(resultSet.getInt("status"));
inOrder.setDelmark(resultSet.getInt("Delmark"));
inOrders.add(inOrder);
preparedStatement = conn.prepareStatement(SQL); // 准备SQL语句
resultSet = preparedStatement.executeQuery(); // 执行查询
while (resultSet.next()) { // 遍历结果集
InOrder inOrder = new InOrder(); // 创建InOrder对象
// 从结果集中获取属性并设置到inOrder对象
inOrder.setiNumber(resultSet.getString("iNumber")); // 设置订单号
inOrder.setAllInPrice(resultSet.getFloat("allInPrice")); // 设置总价格
inOrder.setInDate(resultSet.getString("inDate")); // 设置入库日期
inOrder.setPrincipal(resultSet.getString("principal")); // 设置负责人
inOrder.setStatus(resultSet.getInt("status")); // 设置订单状态
inOrder.setDelmark(resultSet.getInt("Delmark")); // 设置删除标记
inOrders.add(inOrder); // 将InOrder对象添加到向量中
}
} catch (SQLException e) {
e.printStackTrace();
e.printStackTrace(); // 捕获并打印异常堆栈信息
} finally {
JDBCUtil.close(resultSet, preparedStatement, conn);
JDBCUtil.close(resultSet, preparedStatement, conn); // 关闭结果集、预编译语句和数据库连接
}
return inOrders;
return inOrders; // 返回存储待确认订单的向量
}
//获取今日进货金额
public Float TodayInPrice(String date) {
InOrder inOrder = new InOrder();
Connection conn = JDBCUtil.getConn();
PreparedStatement preparedStatement = null;
ResultSet resultSet = null;
Float allInPrice=(float) 0;
// 获取今日进货金额
public Float TodayInPrice(String date) {
InOrder inOrder = new InOrder(); // 创建InOrder对象
Connection conn = JDBCUtil.getConn(); // 获取数据库连接
PreparedStatement preparedStatement = null; // 声明预编译语句对象
ResultSet resultSet = null; // 声明结果集对象
Float allInPrice = (float) 0; // 初始化总进货金额为0
try {
// 准备SQL查询语句计算指定日期的进货金额总和
preparedStatement = conn.prepareStatement("select sum(allInPrice) from inOrder where inDate>=? and inDate<=date_add(?,interval 1 day)");
preparedStatement.setString(1, date);
preparedStatement.setString(2, date);
resultSet = preparedStatement.executeQuery();
if (resultSet.next()) {
allInPrice=resultSet.getFloat("sum(allInPrice)");
}
preparedStatement.setString(1, date); // 设置起始日期
preparedStatement.setString(2, date); // 设置结束日期(起始日期+1天
resultSet = preparedStatement.executeQuery(); // 执行查询
if (resultSet.next()) { // 如果有结果
allInPrice = resultSet.getFloat("sum(allInPrice)"); // 获取总进货金额
}
} catch (SQLException e) {
e.printStackTrace();
e.printStackTrace(); // 捕获并打印异常堆栈信息
} finally {
JDBCUtil.close(resultSet, preparedStatement, conn);
JDBCUtil.close(resultSet, preparedStatement, conn); // 关闭结果集、预编译语句和数据库连接
}
return allInPrice;
return allInPrice; // 返回总进货金额
}
//查找指定状态订单
public Vector<InOrder> FindStatus(int status){
Vector<InOrder> inOrders = new Vector<InOrder>();
Connection conn = JDBCUtil.getConn();
PreparedStatement preparedStatement = null;
ResultSet resultSet=null;
try {
// 查找指定状态订单
public Vector<InOrder> FindStatus(int status) {
Vector<InOrder> inOrders = new Vector<InOrder>(); // 创建一个向量用于存储InOrder对象
Connection conn = JDBCUtil.getConn(); // 获取数据库连接
PreparedStatement preparedStatement = null; // 声明预编译语句对象
ResultSet resultSet = null; // 声明结果集对象
try {
// 准备SQL查询语句根据状态查找订单
preparedStatement = conn.prepareStatement("select * from inOrder where status=? and delmark=1 order by inDate desc");
preparedStatement.setInt(1, status);
resultSet = preparedStatement.executeQuery();
while(resultSet.next()) {
InOrder inOrder = new InOrder();
inOrder.setiNumber(resultSet.getString("iNumber"));
inOrder.setAllInPrice(resultSet.getFloat("allInPrice"));
inOrder.setInDate(resultSet.getString("inDate"));
inOrder.setPrincipal(resultSet.getString("principal"));
inOrder.setStatus(resultSet.getInt("status"));
inOrder.setDelmark(resultSet.getInt("Delmark"));
inOrders.add(inOrder);
preparedStatement.setInt(1, status); // 设置状态参数
resultSet = preparedStatement.executeQuery(); // 执行查询
while (resultSet.next()) { // 遍历结果集
InOrder inOrder = new InOrder(); // 创建InOrder对象
// 从结果集中获取属性并设置到inOrder对象
inOrder.setiNumber(resultSet.getString("iNumber")); // 设置订单号
inOrder.setAllInPrice(resultSet.getFloat("allInPrice")); // 设置总价格
inOrder.setInDate(resultSet.getString("inDate")); // 设置入库日期
inOrder.setPrincipal(resultSet.getString("principal")); // 设置负责人
inOrder.setStatus(resultSet.getInt("status")); // 设置订单状态
inOrder.setDelmark(resultSet.getInt("Delmark")); // 设置删除标记
inOrders.add(inOrder); // 将InOrder对象添加到向量中
}
} catch (SQLException e) {
e.printStackTrace();
e.printStackTrace(); // 捕获并打印异常堆栈信息
} finally {
JDBCUtil.close(resultSet, preparedStatement, conn);
JDBCUtil.close(resultSet, preparedStatement, conn); // 关闭结果集、预编译语句和数据库连接
}
return inOrders;
return inOrders; // 返回指定状态的订单向量
}
}

@ -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,4 +1,3 @@
package com.lingnan.supermarket.dialog;
import java.awt.Container;
@ -26,54 +25,74 @@ import com.lingnan.supermarket.view.LoginView;
// UserInfDialog类继承自JDialog用于创建一个修改用户信息的对话框窗口并实现了ActionListener接口来处理按钮点击事件
public class UserInfDialog extends JDialog implements ActionListener {
// 以下是用于构建对话框界面的各个面板、标签、文本框和按钮等组件的声明
// 构建对话框界面的各个面板、标签、文本框和按钮等组件的声明
private JPanel namePanel, loginNamePanel, phonePanel, opePanel, passwordPanel, sSuperPanel;
// 用于存放姓名相关组件的面板
private JLabel nameLabel, loginNameLabel, phoneLabel, passwordLabel, sSuperLabel;
// 分别对应姓名、登录名、联系电话、密码、权限等信息的标签组件,用于在界面上显示相应的文字提示
private JTextField nameTF, loginNameTF, phoneTF, passwordTF, sSuperTF;
// 分别对应姓名、登录名、联系电话、密码、权限等信息的文本框组件,用于用户输入或显示相应信息
private JButton saveBtn, cancelBtn;
// 保存按钮和取消按钮,用于触发保存修改信息或取消操作的动作
// 用户服务接口的实现类实例,用于调用与用户相关的数据库操作方法
private UserService userService = new UserServiceImpl();
// 创建UserServiceImpl类的实例通过该实例可以调用具体实现的用户相关数据库操作比如更新用户信息等
// 要修改信息的用户对象
private User user;
// 存储当前要在对话框中进行信息修改操作的用户对象,包含了该用户原本的各种信息
// 用于存储用户权限级别,初始值为从传入的用户对象中获取的权限级别
private int sSuper = -1;
// 记录用户的权限级别,初始化为 -1后续会根据传入用户对象的权限情况进行赋值
// 下拉框组件,用于选择用户权限(这里部分代码被注释掉,可能原本有完整的权限选择功能,后简化了)
// 下拉框组件,用于选择用户权限
private JComboBox<String> combo;
// 定义一个下拉框组件,用于展示可选的用户权限选项,其选项内容为字符串类型
// 下拉框中的选项内容,包括当前权限以及不同的权限角色
private String[] identity = { "当前权限", "收银员", "管理员", "超级管理员" };
private String[] identity = { "当前权限", "收银员", "管理员", "超级管理员","进货员" };
// 定义一个字符串数组,存储下拉框中可供选择的用户权限选项内容
// 父窗口JFrame的引用可能用于在某些操作后对父窗口进行处理
private JFrame JFrame;
// 保存传入的父窗口JFrame类型的引用
// 构造函数用于创建修改用户信息的对话框传入父窗口JFrame和要修改信息的用户对象
public UserInfDialog(JFrame parent, User user) {
// 调用父类JDialog的构造函数设置对话框的标题为"添加"(这里标题可能需要根据实际情况修改为更合适的,比如"修改用户信息"
// 调用父类JDialog的构造函数设置对话框的标题为"添加"
super(parent, "添加");
this.user = user;
// 将传入的要修改信息的用户对象赋值给当前类的成员变量user
// 设置当前用户的权限级别
this.sSuper = user.getUsuper();
// 从传入的用户对象中获取其原本的权限级别并赋值给当前类的成员变量sSuper
// 设置对话框的大小
setSize(350, 300);
// 设置对话框的宽度为350像素高度为300像素确定对话框在屏幕上显示的初始大小
// 设置对话框在屏幕中央显示
setLocationRelativeTo(null);
// 通过传入null参数使对话框在屏幕的中心位置显示
// 设置对话框为模态对话框,即显示时会阻塞其他窗口的操作
setModal(true);
// 模态对话框会强制用户在关闭它之前只能与该对话框进行交互,不能操作其他窗口
// 设置对话框大小不可调整
setResizable(false);
// 禁止用户通过拖动边框等方式改变对话框的大小,保持固定的布局和显示效果
// 设置对话框的布局为流式布局
this.setLayout(new FlowLayout());
// 使用流式布局来排列对话框内的组件,组件会按照添加的顺序从左到右、从上到下依次排列
// 保存父窗口的引用
this.JFrame = parent;
// 将传入的父窗口引用赋值给当前类的成员变量JFrame
// 初始化对话框的视图组件
initView();
@ -84,34 +103,53 @@ public class UserInfDialog extends JDialog implements ActionListener {
// 姓名面板及相关组件的初始化,文本框中显示当前用户的姓名信息
namePanel = new JPanel();
// 创建一个新的面板,用于存放姓名相关的标签和文本框组件
nameLabel = new JLabel("姓名");
// 创建一个显示"姓名"文字的标签组件
nameTF = new JTextField(user.getRname(), 15);
// 创建一个文本框组件初始内容设置为传入用户对象的真实姓名通过user.getRname()获取文本框宽度设置为可显示15个字符左右
namePanel.add(nameLabel);
// 将姓名标签添加到姓名面板中
namePanel.add(nameTF);
// 将姓名文本框添加到姓名面板中
// 账号面板及相关组件的初始化,文本框中显示当前用户的账号信息
loginNamePanel = new JPanel();
// 创建一个新的面板,用于存放账号相关的标签和文本框组件
loginNameLabel = new JLabel("账号");
// 创建一个显示"账号"文字的标签组件
loginNameTF = new JTextField(user.getUsername(), 15);
// 创建一个文本框组件初始内容设置为传入用户对象的用户名通过user.getUsername()获取文本框宽度设置为可显示15个字符左右
loginNamePanel.add(loginNameLabel);
// 将账号标签添加到账号面板中
loginNamePanel.add(loginNameTF);
// 将账号文本框添加到账号面板中
// 手机面板及相关组件的初始化,文本框中显示当前用户的手机信息
phonePanel = new JPanel();
phoneLabel = new JLabel("联系");
// 创建一个新的面板,用于存放手机相关的标签和文本框组件
phoneLabel = new JLabel("电话");
// 创建一个显示"联系"文字的标签组件
phoneTF = new JTextField(user.getPhone(), 15);
// 创建一个文本框组件初始内容设置为传入用户对象的手机号码通过user.getPhone()获取文本框宽度设置为可显示15个字符左右
phonePanel.add(phoneLabel);
// 将手机标签添加到手机面板中
phonePanel.add(phoneTF);
// 将手机文本框添加到手机面板中
// 密码面板及相关组件的初始化,文本框中显示当前用户的密码信息
passwordPanel = new JPanel();
// 创建一个新的面板,用于存放密码相关的标签和文本框组件
passwordLabel = new JLabel("密码");
// 创建一个显示"密码"文字的标签组件
passwordTF = new JTextField(user.getPassword(), 15);
// 创建一个文本框组件初始内容设置为传入用户对象的密码通过user.getPassword()获取文本框宽度设置为可显示15个字符左右
passwordPanel.add(passwordLabel);
// 将密码标签添加到密码面板中
passwordPanel.add(passwordTF);
// 将密码文本框添加到密码面板中
// 权限面板及相关组件的初始化,这里部分代码被注释掉,可能原本有完整的权限选择功能,后简化了
/*
sSuperPanel = new JPanel();
sSuperLabel = new JLabel("权限");
// sSuperTF = new JTextField(15);
@ -119,26 +157,40 @@ public class UserInfDialog extends JDialog implements ActionListener {
combo.addItemListener(new MyItemListener());
sSuperPanel.add(sSuperLabel);
sSuperPanel.add(combo);
*/
// 上述被注释掉的代码原本用于创建权限相关的面板、标签、下拉框组件,并为下拉框添加选项改变的监听器,用于实现完整的权限选择功能,但目前处于简化状态
// 操作按钮面板及相关组件的初始化
opePanel = new JPanel();
// 创建一个新的面板,用于存放操作按钮(保存和取消按钮)
saveBtn = new JButton("保存");
// 创建一个显示"保存"文字的按钮组件,用于触发保存用户信息修改的操作
cancelBtn = new JButton("取消");
// 创建一个显示"取消"文字的按钮组件,用于触发取消当前修改操作的动作
// 为保存按钮和取消按钮添加点击事件监听器
saveBtn.addActionListener(this);
// 将保存按钮的点击事件绑定到当前类实现了ActionListener接口的actionPerformed方法上以便处理保存按钮被点击后的操作逻辑
cancelBtn.addActionListener(this);
// 将取消按钮的点击事件绑定到当前类实现了ActionListener接口的actionPerformed方法上以便处理取消按钮被点击后的操作逻辑
opePanel.add(saveBtn);
// 将保存按钮添加到操作按钮面板中
opePanel.add(cancelBtn);
// 将取消按钮添加到操作按钮面板中
// 将各个面板添加到对话框的内容面板中
Container container = getContentPane();
// 获取对话框的内容面板,用于添加其他组件面板
container.add(namePanel);
// 将姓名面板添加到对话框的内容面板中
container.add(loginNamePanel);
// 将账号面板添加到对话框的内容面板中
container.add(passwordPanel);
// 将密码面板添加到对话框的内容面板中
container.add(phonePanel);
/*container.add(sSuperPanel);*/
container.add(sSuperPanel);
// 原本可能添加权限面板
container.add(opePanel);
// 将操作按钮面板添加到对话框的内容面板中
}
// 处理按钮点击事件的方法实现了ActionListener接口中的方法
@ -151,60 +203,85 @@ public class UserInfDialog extends JDialog implements ActionListener {
// 获取用户在文本框中修改后的姓名、账号、手机和密码信息
String name = nameTF.getText();
// 获取姓名文本框中用户输入或修改后的姓名内容
String loginName = loginNameTF.getText();
// 获取账号文本框中用户输入或修改后的账号内容
String phone = phoneTF.getText();
// 获取手机文本框中用户输入或修改后的手机号码内容
String password = passwordTF.getText();
// 获取密码文本框中用户输入或修改后的密码内容
// TODO 参数校验部分,这里应该对获取到的用户输入信息进行合法性校验,比如非空、格式等校验,但目前未实现具体逻辑
// 此处注释提示了后续应该添加对获取到的用户输入信息进行合法性校验的代码
// 创建一个新的User对象用于存储要更新到数据库的用户信息设置了部分从原用户对象获取的信息以及修改后的信息
User user1 = new User();
user1.setId(user.getId());
// 设置新用户对象的id为原用户对象的id确保更新的是正确的用户记录
user1.setRname(name);
// 设置新用户对象的真实姓名为获取到的修改后的姓名内容
user1.setUsername(loginName);
// 设置新用户对象的用户名(账号)为获取到的修改后的账号内容
user1.setPhone(phone);
// 设置新用户对象的手机号码为获取到的修改后的手机号码内容
user1.setPassword(password);
// 设置新用户对象的密码为获取到的修改后的密码内容
user1.setImg(user.getImg());
// 设置新用户对象的图片相关信息(这里不太明确具体用途,可能是用户头像之类的图片信息)为原用户对象的对应信息
user1.setUsuper(sSuper);
// 设置新用户对象的权限级别为当前记录的权限级别(在构造函数或其他地方已确定)
// 调用用户服务接口的根据用户id更新用户信息的方法将更新后的用户信息保存到数据库中并获取返回结果
int result = userService.updateByIdUser(user1);
if (result == 1) {
// 如果更新成功,关闭当前对话框
this.dispose();
// 通过调用dispose方法关闭当前的对话框窗口释放相关资源
// 弹出提示框显示修改成功信息,并提示重新登录
JOptionPane.showMessageDialog(this, "修改成功,请重新登陆", "提示", JOptionPane.INFORMATION_MESSAGE);
// 使用JOptionPane弹出一个信息提示框向用户显示修改成功的消息并提示需要重新登录提示框的图标为信息图标INFORMATION_MESSAGE表示
// 关闭父窗口
this.JFrame.dispose();
// 通过调用父窗口的dispose方法关闭父窗口
// 创建并显示新的登录视图
new LoginView();
// 创建一个新的登录视图LoginView类的实例并显示出来方便用户重新登录系统
} else {
// 如果更新失败,弹出提示框显示修改失败信息
JOptionPane.showMessageDialog(this, "修改失败", "提示", JOptionPane.ERROR_MESSAGE);
// 使用JOptionPane弹出一个错误提示框向用户显示修改失败的消息
}
} else if (source == cancelBtn) {
// 如果点击的是取消按钮,直接关闭当前对话框
this.dispose();
// 通过调用dispose方法关闭当前对话框放弃本次修改操作释放相关资源
}
}
// 内部类,实现了ItemListener接口用于监听下拉框选项变化事件(这里部分代码被注释掉,可能原本有完整的权限选择功能,后简化了)
// 实现了ItemListener接口用于监听下拉框选项变化事件
public class MyItemListener implements ItemListener {
@Override
public void itemStateChanged(ItemEvent e) {
// 获取触发事件的下拉框组件
JComboBox cb = (JComboBox) e.getSource();
// 从事件源中获取触发选项改变事件的下拉框对象
// 获取当前选中的下拉框选项内容
String sSuper1 = (String) cb.getSelectedItem();
// 获取下拉框当前选中的选项对应的字符串内容
if (sSuper1.equals("当前权限"))
sSuper = user.getUsuper();
else if (sSuper1.equals("收银员"))
sSuper = 2;
else if (sSuper1.equals("管理员")):
sSuper = 1;
else
sSuper = 0;
else if (sSuper1.equals("管理员"))
sSuper = 1;
else
sSuper = 0;
// 根据下拉框选中的不同选项内容来设置当前用户的权限级别不同的数字0、1、2对应不同的权限
}
}
}

@ -1,82 +1,94 @@
package com.lingnan.supermarket.view;
import java.awt. *;
import java.awt.*;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.StringSelection;
import java.awt.datatransfer.Transferable;
import javax.swing. *;
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Scanner;
import java.awt.event.*;
public class Demo4 extends JFrame implements ActionListener
{
static Demo4 tplb=new Demo4();
static JLabel pan=new JLabel();
static ImageIcon[] imgs = {
new ImageIcon("s"),
new ImageIcon("static\\bg\\bg1.jpg"),
new ImageIcon("static\\bg\\bg2.jpg"),
new ImageIcon("static\\bg\\bg3.jpg"),
new ImageIcon("static\\bg\\bg4.jpg"),
new ImageIcon("static\\bg\\bg5.jpg"),
new ImageIcon("static\\bg\\bg6.jpg"),
new ImageIcon("static\\bg\\bg7.jpg"),
};
public static void settplb()/*<2A>ܿ<EFBFBD><DCBF>*/
{
// Demo4类用于创建一个展示图片切换效果的图形界面程序
public class Demo4 extends JFrame implements ActionListener {
// 创建一个静态的Demo4类的实例tplb用于在静态方法中方便地访问该类的相关属性和方法实现类似单例模式的效果
static Demo4 tplb = new Demo4();
// 创建一个静态的JLabel组件pan用于在界面上显示图片等内容作为图片展示的载体
static JLabel pan = new JLabel();
// 创建一个静态的ImageIcon数组imgs用于存储多个图片资源
static ImageIcon[] imgs = {
new ImageIcon("s"),
new ImageIcon("static\\bg\\bg1.jpg"),
new ImageIcon("static\\bg\\bg2.jpg"),
new ImageIcon("static\\bg\\bg3.jpg"),
new ImageIcon("static\\bg\\bg4.jpg"),
new ImageIcon("static\\bg\\bg5.jpg"),
new ImageIcon("static\\bg\\bg6.jpg"),
new ImageIcon("static\\bg\\bg7.jpg"),
};
// settplb方法用于设置JFrame的一些基本属性使其成为一个合适的图形界面窗口展示出来
public static void settplb() {
// 设置窗口的标题
tplb.setTitle("ͼƬ<CDBC>ֲ<EFBFBD><D6B2><EFBFBD><EFBFBD><EFBFBD>");
// 设置窗口的布局管理器为null意味着后续添加组件时需要手动指定组件的位置和大小绝对布局
tplb.setLayout(null);
tplb.setSize(700,800);
// 设置窗口的大小为宽度700像素高度800像素
tplb.setSize(700, 800);
// 设置窗口大小不可调整,用户不能通过拖动边框等方式改变窗口大小
tplb.setResizable(false);
tplb.setLocationRelativeTo(null);/*<2A><><EFBFBD>þ<EFBFBD><C3BE><EFBFBD>*/
tplb.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);/*<2A>رճ<D8B1><D5B3><EFBFBD>*/
// 设置窗口在屏幕上居中显示,使窗口展示位置更美观合理
tplb.setLocationRelativeTo(null);
// 设置当窗口关闭时,整个应用程序随之退出,这是一种常见的关闭窗口行为设置
tplb.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// 设置窗口可见,使其显示在屏幕上,否则窗口创建后是不可见的状态
tplb.setVisible(true);
}
// setpan方法用于设置JLabel组件的位置等属性并添加到窗口中同时启动一个定时器来实现图片的定时切换功能
public static void setpan() {
// 设置JLabel组件pan的位置和大小x坐标为50像素y坐标为50像素宽度和高度都为500像素确定其在窗口中的显示区域
pan.setBounds(50, 50, 500, 500);
// 将pan这个JLabel组件添加到tplb这个窗口实例中使其成为窗口内容的一部分
tplb.add(pan);
// 创建一个定时器对象timer设置每隔1秒触发一次事件并且指定事件监听器为L
Timer timer = new Timer(1000, L);
// 启动定时器,开始计时,一旦达到设定的时间间隔就会切换图片
timer.start();
}
// 定义一个实现了ActionListener接口的匿名内部类L用于处理定时器触发的事件实现图片在JLabel组件上的切换效果
static ActionListener L = new ActionListener() {
int index; // 定义一个整型变量index用于记录当前要显示的图片在imgs数组中的索引位置
public static void setpan()
{
pan.setBounds(50, 50, 500, 500);
tplb.add(pan);
Timer timer = new Timer(1000,L);
timer.start();
}
static ActionListener L=new ActionListener()
{
int index;
@Override
public void actionPerformed(ActionEvent e)
{
public void actionPerformed(ActionEvent e) {
// 将pan这个JLabel组件的图标设置为imgs数组中当前索引对应的图片实现图片的切换展示效果
pan.setIcon(imgs[index]);
// 将索引值加1准备切换到下一张图片
index++;
if(index==7)
index=0;
// 如果索引值达到了imgs数组的长度7表示已经到最后一张图片了将索引重置为0实现循环切换图片的效果
if (index == 7)
index = 0;
}
};
public static void main(String[] args) {
settplb();
setpan();
}
// 调用设置窗口和图片展示相关的方法来展示图形界面效果
public static void main(String[] args) {
// 调用settplb方法设置窗口的基本属性并使其显示出来
settplb();
// 调用setpan方法设置图片展示的JLabel组件相关属性并启动图片切换的定时器功能
setpan();
}
@Override
public void actionPerformed(ActionEvent e) {
// TODO <20>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD>ɵķ<C9B5><C4B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
}
}
}

@ -1,13 +1,12 @@
package com.lingnan.supermarket.view;
import java.awt. *;
import java.awt.*;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.StringSelection;
import java.awt.datatransfer.Transferable;
import javax.imageio.ImageIO;
import javax.swing. *;
import javax.swing.*;
import com.lingnan.supermarket.componet.BGPanel;
import com.lingnan.supermarket.dao.impl.inOrderServiceImpl;
import com.lingnan.supermarket.dao.impl.outOrderServiceImpl;
@ -16,161 +15,221 @@ import com.lingnan.supermarket.table.UserTableModel;
import com.lingnan.supermarket.utils.FontUtil;
import com.lingnan.supermarket.utils.TimeAndOrder;
import com.lingnan.supermarket.view.base.BaseView;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.IOException;
import java.util.Scanner;
import java.awt.event.*;
public class HomeView extends JPanel implements ActionListener
{
private JLabel pan;
private static JLabel pan1;
private static JLabel pan2;
private static JLabel pan3;
private JFrame jFrame;
private JPanel tplbPanel;
private Image bgImage = null;
private ImageIcon[] imgs;
private static Float allInPrice;
private static Float allOutPrice;
private JButton refreshBtn;
private JPanel priceJPanel;
private static String date;
private static inOrderServiceImpl inOrderImpl ;
private static outOrderServiceImpl outOrderImpl;
public HomeView(JFrame jFrame) {
this.setLayout(null);
this.jFrame = jFrame;
initView();
}
private void initView() {
pan = new JLabel();
pan.setBounds(0,0, 1280,351);
/*tplbPanel.add(pan);*/
imgs =new ImageIcon[7];
for(int i =0;i<7;i++) {
imgs[i]=new ImageIcon("static\\轮播\\0"+i+".jpg");
}
pan.setIcon(imgs[6]);
Timer timer = new Timer(2500,L);
timer.start();
this.add(pan);
date= TimeAndOrder.yMdTime();/*获取今天时间*/
inOrderImpl = new inOrderServiceImpl();
outOrderImpl = new outOrderServiceImpl();
allInPrice=inOrderImpl.TodayInPrice(date);
allOutPrice=outOrderImpl.TodayOutPrice(date);
System.out.println("今日allInprice="+allInPrice);
System.out.println("今日allOutprice="+allOutPrice);
pan1 = new JLabel("今日进货总金额:"+allInPrice+"元",new ImageIcon("static\\icon\\money.png"),JLabel.LEFT);
pan2 = new JLabel("今日收银总金额:"+allOutPrice+"元",new ImageIcon("static\\icon\\income.png"),JLabel.LEFT);
pan3 = new JLabel("今日被投诉次数:0次",new ImageIcon("static\\icon\\complaints.png"),JLabel.LEFT);
pan1.setFont(FontUtil.homeFont);
pan2.setFont(FontUtil.homeFont);
pan3.setFont(FontUtil.homeFont);
pan1.setBounds(280,300, 600,200);
pan2.setBounds(280,400, 600,200);
pan3.setBounds(280,500, 600,200);
/* priceJPanel = new JPanel();
priceJPanel.setBounds(100,200,700,500);*/
this.add(pan1);
this.add(pan2);
this.add(pan3);
refreshBtn = new JButton(new ImageIcon("static\\icon\\refresh.png"));
refreshBtn.addActionListener(this);
refreshBtn.setBounds(1050,700, 40,40);
this.add(refreshBtn);
}
ActionListener L=new ActionListener()
{
int index;
@Override
public void actionPerformed(ActionEvent e)
{
pan.setIcon(imgs[index]);
index++;
if(index==7)
index=0;
}
};
// HomeView类用于构建超市管理系统中首页的视图界面展示如图片轮播、关键业务数据以及提供数据刷新功能
public class HomeView extends JPanel implements ActionListener {
// 用于展示图片轮播效果的JLabel组件
private JLabel pan;
// 用于显示今日进货总金额相关信息
private static JLabel pan1;
// 用于显示今日收银总金额相关信息
private static JLabel pan2;
// 用于显示今日被投诉次数相关信息
private static JLabel pan3;
private JFrame jFrame;
private JPanel tplbPanel;
// 用于存储背景图片的Image对象初始化为null
private Image bgImage = null;
// 定义的ImageIcon数组用于存储多张图片资源以实现图片轮播功能
private ImageIcon[] imgs;
// 静态的Float类型变量记录今日进货的总金额
private static Float allInPrice;
// 静态的Float类型变量记录今日收银的总金额
private static Float allOutPrice;
// 用于触发刷新操作的按钮组件
private JButton refreshBtn;
private JPanel priceJPanel;
// 存储当前日期信息,方便在类内不同方法中按日期查询业务数据
private static String date;
// 是实现进货订单相关业务逻辑的服务层接口的类实例,用于获取进货相关数据
private static inOrderServiceImpl inOrderImpl;
// 用于实现销售订单相关业务逻辑,获取收银相关数据
private static outOrderServiceImpl outOrderImpl;
// 构造函数用于创建HomeView实例并初始化界面相关组件
public HomeView(JFrame jFrame) {
this.setLayout(null); //设置布局为null
this.jFrame = jFrame; //保存父窗口引用
initView(); //调用initView方法初始化组件
}
// 初始化视图界面组件的方法,负责创建、配置各组件并设置其属性、添加组件到面板以及为按钮添加事件监听器等操作,构建首页界面展示效果
private void initView() {
// 创建一个JLabel组件pan设置其初始位置和大小用于后续图片轮播展示
pan = new JLabel();
pan.setBounds(0, 0, 1280, 351);
/*tplbPanel.add(pan);*/
// 创建包含7个元素的ImageIcon数组imgs用于存储图片轮播的图片资源通过循环从指定路径加载图片文件创建ImageIcon对象
imgs = new ImageIcon[7];
for (int i = 0; i < 7; i++) {
imgs[i] = new ImageIcon("static\\轮播\\0" + i + ".jpg");
}
// 设置图片轮播起始图片
pan.setIcon(imgs[6]);
// 创建一个定时器对象timer设置时间间隔为2500毫秒2.5秒指定事件监听器为L然后启动定时器实现图片定时轮播
Timer timer = new Timer(2500, L);
timer.start();
// 将pan这个JLabel组件添加到当前面板中使其能在界面上显示出来参与图片轮播
this.add(pan);
// 调用TimeAndOrder工具类的yMdTime方法获取当前日期信息
date = TimeAndOrder.yMdTime();
//用于调用其实现的与进货订单相关业务方法获取数据
inOrderImpl = new inOrderServiceImpl();
// 创建outOrderServiceImpl类的实例用于调用与销售订单相关业务方法获取销售相关数据如获取今日收银总金额
outOrderImpl = new outOrderServiceImpl();
// 调用inOrderImpl的TodayInPrice方法传入当前日期date获取今日进货的总金额用于界面显示及其他业务逻辑处理
allInPrice = inOrderImpl.TodayInPrice(date);
// 调用outOrderImpl的TodayOutPrice方法传入date获取今日收银总金额用于展示销售数据及相关操作
allOutPrice = outOrderImpl.TodayOutPrice(date);
// 在控制台打印今日进货总金额信息,用于调试或简单日志记录
System.out.println("今日allInprice=" + allInPrice);
// 在控制台打印今日收银总金额信息,起到调试或日志记录作用
System.out.println("今日allOutprice=" + allOutPrice);
// 创建一个JLabel组件pan1设置其显示文本为包含今日进货总金额的内容并设置图标及文本在图标的左侧显示用于直观展示进货金额信息
pan1 = new JLabel("今日进货总金额:" + allInPrice + "元", new ImageIcon("static\\icon\\money.png"), JLabel.LEFT);
// 设置pan1这个JLabel组件的字体为通过FontUtil类获取的适用于首页显示的特定字体
pan1.setFont(FontUtil.homeFont);
// 设置pan1在界面中的位置和大小
pan1.setBounds(280, 300, 600, 200);
// 创建JLabel组件pan2设置其显示文本为包含今日收银总金额的内容同样设置图标及文本位置用于展示收银金额信息
pan2 = new JLabel("今日收银总金额:" + allOutPrice + "元", new ImageIcon("static\\icon\\income.png"), JLabel.LEFT);
// 设置pan2的字体为首页特定字体
pan2.setFont(FontUtil.homeFont);
// 设置pan2在界面中的位置和大小
pan2.setBounds(280, 400, 600, 200);
// 创建JLabel组件pan3设置其显示文本为今日被投诉次数相关内容初值为0次设置图标及文本位置用于展示投诉情况信息
pan3 = new JLabel("今日被投诉次数:0次", new ImageIcon("static\\icon\\complaints.png"), JLabel.LEFT);
// 设置pan3的字体为首页特定字体
pan3.setFont(FontUtil.homeFont);
// 设置pan3在界面中的位置和大小
pan3.setBounds(280, 500, 600, 200);
/*priceJPanel = new JPanel();
priceJPanel.setBounds(100, 200, 700, 500);*/
// 将pan1、pan2、pan3这三个用于显示关键信息的JLabel组件添加到当前面板HomeView使其在界面上展示出来供用户查看相关业务数据
this.add(pan1);
this.add(pan2);
this.add(pan3);
// 创建一个按钮组件refreshBtn使用指定图标文件创建按钮图标
refreshBtn = new JButton(new ImageIcon("static\\icon\\refresh.png"));
// 为refreshBtn按钮添加点击事件监听器将点击事件绑定到当前类的actionPerformed方法上
refreshBtn.addActionListener(this);
// 设置refreshBtn按钮在界面中的位置和大小
refreshBtn.setBounds(1050, 700, 40, 40);
// 将refreshBtn按钮添加到当前面板HomeView
this.add(refreshBtn);
}
// 定义一个实现了ActionListener接口的匿名内部类L用于处理定时器触发的事件实现图片在pan这个JLabel组件上的定时切换展示达到图片轮播效果
ActionListener L = new ActionListener() {
int index; // 定义变量index用于记录当前要显示图片在imgs数组中的索引位置初始默认为0
@Override
public void actionPerformed(ActionEvent e) {
// 将pan这个JLabel组件的图标设置为imgs数组中当前索引index对应的图片实现图片切换展示效果定时器触发时更新显示图片
pan.setIcon(imgs[index]);
// 将索引值index加1准备切换到下一张图片
index++;
// 判断索引值是否达到imgs数组长度7若达到则重置为0实现图片循环轮播
if (index == 7)
index = 0;
}
};
// 定义静态方法refreshHome用于刷新首页界面上显示的关键数据进货、收银金额等
public static void refreshHome() {
date= TimeAndOrder.yMdTime();/*获取今天时间*/
allInPrice=inOrderImpl.TodayInPrice(date);
allOutPrice=outOrderImpl.TodayOutPrice(date);
System.out.println("今日allInprice="+allInPrice);
System.out.println("今日allOutprice="+allOutPrice);
pan1.setText("今日进货总金额:"+allInPrice+"元");
pan2.setText("今日收银总金额:"+allOutPrice+"元");
pan3.setText("今日被投诉次数:0次");
/* priceJPanel = new JPanel();
priceJPanel.setBounds(100,200,700,500);*/
/* this.add(pan1);
this.add(pan2);
this.add(pan3);*/
// 再次调用TimeAndOrder工具类的yMdTime方法获取当前最新日期信息
date = TimeAndOrder.yMdTime();
// 调用inOrderImpl的TodayInPrice方法传入最新日期date重新获取今日进货总金额并更新allInPrice变量的值
allInPrice = inOrderImpl.TodayInPrice(date);
// 调用outOrderImpl的TodayOutPrice方法传入date重新获取今日收银总金额并更新allOutPrice变量的值
allOutPrice = outOrderImpl.TodayOutPrice(date);
// 在控制台打印更新后的今日进货总金额信息
System.out.println("今日allInPrice=" + allInPrice);
// 在控制台打印更新后的今日收银总金额信息
System.out.println("今日allOutPrice=" + allOutPrice);
// 更新pan1这个JLabel组件的文本内容显示最新的进货总金额信息实现界面数据实时刷新
pan1.setText("今日进货总金额:" + allInPrice + "元");
// 更新pan2的文本内容显示最新的收银总金额信息保证销售数据在界面上及时更新展示
pan2.setText("今日收银总金额:" + allOutPrice + "元");
// 更新pan3的文本内容开始显示0次投诉
pan3.setText("今日被投诉次数:0次");
/*priceJPanel = new JPanel();
priceJPanel.setBounds(100, 200, 700, 500);*/
/*this.add(pan1);
this.add(pan2);
this.add(pan3);*/
}
// 实现ActionListener接口的actionPerformed方法
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
// 获取触发被点击的按钮
Object source = e.getSource();
if(source==refreshBtn) {
if (source == refreshBtn) {
// 如果点击的是refreshBtn按钮创建一个新的HomeView实例
new HomeView(jFrame);
// 调用refreshHome方法刷新首页界面上显示的关键数据更新界面展示内容
refreshHome();
}
}
}

@ -24,135 +24,160 @@ import javax.swing.JPasswordField;
import javax.swing.JRadioButton;
import javax.swing.JTextField;
// 导入用户相关服务层接口及实现类,用于处理用户登录等业务逻辑
import com.lingnan.supermarket.dao.UserService;
import com.lingnan.supermarket.dao.impl.UserServiceImpl;
// 导入用户数据传输对象相关类,用于传递用户相关的数据信息
import com.lingnan.supermarket.dto.Production;
import com.lingnan.supermarket.dto.User;
import com.lingnan.supermarket.componet.BGPanel;
import com.lingnan.supermarket.view.base.BaseView;
public class LoginView extends BaseView implements ActionListener{
//setLayout(null);
//setBounds(x,y,width,height)
private JPanel containerPanel,namePanel,passwordPanel;
private JLabel nameLabel,pwdLabel;
private JTextField nameTF;
private JPasswordField pwdTF;
private JButton loginBtn;
private User user=null;
/*创建窗口*/
public LoginView() {
// 登录视图类实现ActionListener接口用于处理按钮点击等事件
public class LoginView extends BaseView implements ActionListener {
// 组件声明
// 用于容纳其他面板和组件的主面板,整体布局容器
private JPanel containerPanel;
// 用于放置用户名相关组件的面板
private JPanel namePanel;
// 用于放置密码相关组件的面板
private JPanel passwordPanel;
// 用户名标签
private JLabel nameLabel;
// 密码标签
private JLabel pwdLabel;
// 用于输入用户名的文本框
private JTextField nameTF;
// 用于输入密码的密码框
private JPasswordField pwdTF;
// 登录按钮,点击后触发登录验证等相关操作
private JButton loginBtn;
// 用于存储登录成功后的用户对象信息初始化为null
private User user = null;
/*
*
*
* int width
* int height
* String title
*/
public LoginView() {
// 调用父类BaseView的构造方法来设置窗口的大小和标题
super(350, 250, "新民超市");
ImageIcon icon=new ImageIcon("static\\icon\\新.png"); //xxx代表图片存放路径2.png图片名称及格式
// 创建一个ImageIcon对象用于设置窗口的图标传入的参数是图标图片的路径及文件名
ImageIcon icon = new ImageIcon("static\\icon\\新.png");
// 设置窗口的图标通过获取ImageIcon中的Image对象来设置
this.setIconImage(icon.getImage());
}
/*添加组件*/
@Override/*界面*/
/*
* initView
*/
@Override
protected void initView() {
Image bgImage = null;
try {
// 尝试从指定文件路径读取背景图片若读取失败会抛出IOException异常
bgImage = ImageIO.read(new File("static\\bg\\bg1.jpg"));
} catch (IOException e) {
e.printStackTrace();
}
containerPanel = new BGPanel(bgImage);
//用户名
namePanel = new JPanel();
// 创建一个自定义的背景面板,传入读取到的背景图片,用于作为整个界面的背景容器
containerPanel = new BGPanel(bgImage);
// 用户名相关组件的设置
// 创建放置用户名相关组件的面板
namePanel = new JPanel();
// 创建用户名标签通过传入一个ImageIcon来显示带有图标的提示信息
nameLabel = new JLabel(new ImageIcon("static\\icon\\loginName.png"));
nameTF = new JTextField("z001",22);
// 创建用户名输入文本框,并设置默认显示的文本内容以及文本框的宽度
nameTF = new JTextField("z001", 22);
// 将用户名标签和输入文本框添加到用户名面板中
namePanel.add(nameLabel);
namePanel.add(nameTF);
//密码
// 密码相关组件的设置
// 创建放置密码相关组件的面板
passwordPanel = new JPanel();
// 创建密码标签通过传入一个ImageIcon来显示带有图标的提示信息
pwdLabel = new JLabel(new ImageIcon("static\\icon\\pwd.png"));
pwdTF = new JPasswordField("0.00.0",22);
// 创建密码输入文本框
pwdTF = new JPasswordField("0.00.0", 22);
// 将密码标签和密码输入文本框添加到密码面板中
passwordPanel.add(pwdLabel);
passwordPanel.add(pwdTF);
//登录
// 创建登录按钮,并设置按钮上显示的文本内容
loginBtn = new JButton("登录");
// 为登录按钮添加ActionListener监听器当按钮被点击时会触发相应的事件处理方法
loginBtn.addActionListener(this);
/*添加组件*/
// 将用户名面板、密码面板和登录按钮添加到主容器面板中,确定它们在界面中的布局顺序等
containerPanel.add(namePanel);
containerPanel.add(passwordPanel);
containerPanel.add(loginBtn);
// 获取窗口的内容面板,将主容器面板添加到内容面板中,使得界面组件能够正确显示在窗口内
Container container = getContentPane();
container.add(containerPanel);
}
/*事件处理*/
/*
* ActionListener
*
* ActionEvent e
*/
@Override
public void actionPerformed(ActionEvent e) {
/*如果点击登录*/
if(e.getSource()==loginBtn){
String loginName = nameTF.getText();
String password = new String(pwdTF.getPassword());
System.out.println("点击登录后");
System.out.println("用户名为"+loginName);
System.out.println("密码为"+password);
//TODO 参数校验
UserServiceImpl userService = new UserServiceImpl();
user = userService.login(loginName, password);
if(user==null) {
JOptionPane.showMessageDialog(this,"账号或密码错误");
}else {
//去到主界面
Random random=new Random();
int skin=random.nextInt(10);
System.out.println("skin="+skin);
String iconSkin = "static\\icon\\新.png";/*默认icon*/
new MainView(user,skin,iconSkin);
this.dispose();
}
// 判断事件源是否是登录按钮
if (e.getSource() == loginBtn) {
// 获取用户名输入文本框中的文本内容,作为登录用户名
String loginName = nameTF.getText();
// 获取密码输入文本框中的密码内容通过将char数组转换为字符串的方式获取
String password = new String(pwdTF.getPassword());
System.out.println("点击登录后");
System.out.println("用户名为" + loginName);
System.out.println("密码为" + password);
// 创建用户服务层的实现类对象,用于调用登录相关的业务逻辑方法
UserServiceImpl userService = new UserServiceImpl();
// 调用用户服务层的登录方法,传入用户名和密码进行登录验证,返回验证后的用户对象
user = userService.login(loginName, password);
// 根据登录验证结果进行相应处理
if (user == null) {
// 如果用户对象为null说明登录失败弹出提示框告知用户账号或密码错误
JOptionPane.showMessageDialog(this, "账号或密码错误");
} else {
// 如果登录成功,生成一个随机数,用于后续可能的界面皮肤等相关随机选择逻辑
Random random = new Random();
int skin = random.nextInt(10);
System.out.println("skin=" + skin);
// 设置默认的图标皮肤
String iconSkin = "static\\icon\\新.png";
// 创建主界面对象,传入登录成功的用户对象、随机生成的皮肤编号以及图标皮肤路径,进入主界面展示相关功能
new MainView(user, skin, iconSkin);
// 关闭当前登录窗口,释放资源等
this.dispose();
}
}
}
public static void main(String[] args) {
//设置界面外观
Nimbus.Nimbus();
// 创建登录视图LoginView对象启动登录界面展示
LoginView loginView = new LoginView();
}
}
@Override
protected void initView(User user,int skin) {
protected void initView(User user, int skin) {
// TODO Auto-generated method stub
}
}
}
}

@ -23,163 +23,231 @@ import com.lingnan.supermarket.dto.User;
import com.lingnan.supermarket.table.UserTableModel;
import com.lingnan.supermarket.utils.FontUtil;
public class UserView extends JPanel implements ActionListener{
//上面
// UserView类继承自JPanel并实现ActionListener接口用于构建用户管理界面相关的视图处理用户交互动作
public class UserView extends JPanel implements ActionListener {
// 用于存放整个顶部工具栏相关组件的面板
private JPanel toolBarPanel;
// 用于存放搜索相关组件的面板
private JPanel searchPanel;
private JLabel nameLabel,locationLabel;
// 用于显示"姓名"提示文字的标签
private JLabel nameLabel, locationLabel;
// 用于输入姓名进行搜索的文本框
private JTextField nameSearchTF;
// 用于触发搜索操作的按钮
private JButton searchBtn;
// 用于存放操作按钮(添加、更新、删除等)的面板
private JPanel opePanel;
private JButton addBtn,updateBtn,deleteBtn;
//中间
// 用于触发添加用户操作的按钮
private JButton addBtn, updateBtn, deleteBtn;
// 界面中部相关组件声明
// 用于存放表格并提供滚动功能的滚动面板,以便在表格内容较多时可以滚动查看
private JScrollPane tableScrollPane;
// 用于展示用户数据的表格组件
private JTable userTable;
//删除时选中赋值给id
// 用于记录删除操作时选中记录的用户id初始化为0
private int id;
//下面
// 界面下部相关组件声明
// 用于存放记录数相关提示信息的面板
private JPanel bottomPanel;
// 用于显示用户记录总数相关提示信息的标签
private JLabel countInfoLabel;
// 对父窗口JFrame类型的引用
private JFrame jFrame;
private UserTableModel userTableModel ;
private UserService userService=new UserServiceImpl();
// 用户表格数据模型对象,用于管理表格中的数据,与数据库等数据源进行交互获取和更新数据等
private UserTableModel userTableModel;
// 用户服务接口的实现类实例,通过它可以调用与用户相关的数据库操作方法,如增删改查等功能
private UserService userService = new UserServiceImpl();
// 构造函数接收一个JFrame类型的参数jFrame用于创建用户管理视图并初始化界面组件
public UserView(JFrame jFrame) {
// 设置该面板UserView的布局为BorderLayout将界面划分为北、南、东、西、中五个区域来放置组件
this.setLayout(new BorderLayout());
// 调用初始化视图组件的方法
initView();
// 将传入的父窗口引用保存到成员变量jFrame中
this.jFrame = jFrame;
}
// 初始化用户管理视图界面组件的方法
private void initView() {
toolBarPanel = new JPanel(new BorderLayout());
searchPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
locationLabel=new JLabel("当前位置>人员管理");
// 创建一个新的面板toolBarPanel设置其布局为BorderLayout用于存放顶部的搜索和操作按钮等组件
toolBarPanel = new JPanel(new BorderLayout());
// 创建一个新的面板searchPanel设置其布局为FlowLayout且组件左对齐用于存放搜索相关的组件
searchPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
// 创建一个显示当前位置提示信息的标签,这里显示为"当前位置>人员管理"
locationLabel = new JLabel("当前位置>人员管理");
// 设置标签的字体为通过FontUtil类获取的特定字体这里假设FontUtil类用于统一管理字体相关设置
locationLabel.setFont(new FontUtil().userFont);
// 设置标签的前景色文字颜色为特定的蓝色RGB值为18, 150, 219
locationLabel.setForeground(new Color(18, 150, 219));
// 创建一个显示"姓名"文字的标签,用于提示用户在旁边的文本框中输入姓名进行搜索
nameLabel = new JLabel("姓名");
// 创建一个文本框用于用户输入要搜索的姓名设置其可显示的宽度大致为10个字符左右
nameSearchTF = new JTextField(10);
// 创建一个按钮,使用指定路径下的图标文件作为按钮的图标,用于触发搜索操作
searchBtn = new JButton(new ImageIcon("static\\icon\\search.png"));
/*右边功能模块*/
opePanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
addBtn =new JButton(new ImageIcon("static\\icon\\add.png"));
updateBtn =new JButton(new ImageIcon("static\\icon\\update.png"));
deleteBtn =new JButton(new ImageIcon("static\\icon\\delete.png"));
// 创建一个新的面板opePanel设置其布局为FlowLayout且组件右对齐用于存放操作按钮添加、更新、删除
opePanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
// 创建一个按钮,使用指定路径下的图标文件("static\\icon\\add.png")作为按钮的图标,用于触发添加用户操作
addBtn = new JButton(new ImageIcon("static\\icon\\add.png"));
// 创建一个按钮,使用指定路径下的图标文件("static\\icon\\update.png")作为按钮的图标,用于触发更新用户操作
updateBtn = new JButton(new ImageIcon("static\\icon\\update.png"));
// 创建一个按钮,使用指定路径下的图标文件("static\\icon\\delete.png")作为按钮的图标,用于触发删除用户操作
deleteBtn = new JButton(new ImageIcon("static\\icon\\delete.png"));
// 为添加、更新、删除和搜索按钮添加点击事件监听器将按钮的点击事件绑定到当前类实现了ActionListener接口的actionPerformed方法上以便处理相应的操作逻辑
addBtn.addActionListener(this);
updateBtn.addActionListener(this);
deleteBtn.addActionListener(this);
searchBtn.addActionListener(this);
// 将添加、更新、删除按钮依次添加到操作按钮面板opePanel中
opePanel.add(addBtn);
opePanel.add(updateBtn);
opePanel.add(deleteBtn);
// 将位置提示标签、姓名标签、姓名搜索文本框和搜索按钮依次添加到搜索面板searchPanel中
searchPanel.add(locationLabel);
searchPanel.add(nameLabel);
searchPanel.add(nameSearchTF);
searchPanel.add(searchBtn);
toolBarPanel.add(searchPanel,"West");
toolBarPanel.add(opePanel,"East");
//中间表格
userTableModel = new UserTableModel();
// 将搜索面板添加到toolBarPanel的西边左侧区域将操作按钮面板添加到toolBarPanel的东边右侧区域
toolBarPanel.add(searchPanel, "West");
toolBarPanel.add(opePanel, "East");
// 创建用户表格数据模型对象
userTableModel = new UserTableModel();
// 调用数据模型的方法获取所有用户数据用于初始化表格显示内容这里假设UserTableModel类中的all方法用于从数据库等数据源获取全部用户数据并填充到模型中
userTableModel.all();
// 创建一个JTable对象使用前面创建的用户表格数据模型userTableModel来管理表格中的数据展示和交互
userTable = new JTable(userTableModel);
// 设置表格的字体为通过FontUtil类获取的适用于表格的特定字体假设FontUtil类中定义了相关字体常量
userTable.setFont(FontUtil.tableFont);
// 设置表格每行的高度为50像素调整表格的显示样式
userTable.setRowHeight(50);
// 创建一个滚动面板,将用户表格添加到滚动面板中,以便在表格内容较多时可以通过滚动条查看全部内容
tableScrollPane = new JScrollPane(userTable);
//下面
// 创建一个新的面板bottomPanel设置其布局为FlowLayout且组件左对齐用于存放记录数相关提示信息
bottomPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
countInfoLabel = new JLabel("总共"+userTableModel.getRowCount()+"条");
// 创建一个显示用户记录总数的标签,初始文本为"总共"加上通过用户表格数据模型获取的行数假设UserTableModel类的getRowCount方法返回当前模型中的数据行数以及"条"字
countInfoLabel = new JLabel("总共" + userTableModel.getRowCount() + "条");
// 将记录数标签添加到bottomPanel面板中
bottomPanel.add(countInfoLabel);
this.add(toolBarPanel,"North");
this.add(tableScrollPane,"Center");/*将表格放到中间*/
this.add(bottomPanel,"South");
// 将顶部工具栏面板添加到当前面板UserView的北部上方区域
this.add(toolBarPanel, "North");
// 将包含用户表格的滚动面板添加到当前面板UserView的中部区域使其在界面中间显示
this.add(tableScrollPane, "Center");
// 将记录数面板添加到当前面板UserView的南部下方区域
this.add(bottomPanel, "South");
// 设置当前面板UserView可见使其在界面上显示出来
setVisible(true);
}
// 处理按钮点击等用户交互动作的方法实现了ActionListener接口中的方法
@Override
public void actionPerformed(ActionEvent e) {
// 获取触发事件的源组件(即被点击的按钮等组件)
Object source = e.getSource();
if(addBtn==source) {
//添加数据的对话框
if (addBtn == source) {
// 如果点击的是添加按钮,执行以下操作:
// 创建一个用于添加用户信息的对话框
UserDialog userDialog = new UserDialog(jFrame);
// 设置该对话框可见,显示在屏幕上,让用户进行添加用户信息的操作
userDialog.setVisible(true);
// 调用刷新用户数据的方法,用于在添加操作完成后更新界面上的用户数据显示
refreshUser();
}else if(updateBtn==source) {
} else if (updateBtn == source) {
// 如果点击的是更新按钮,调用刷新用户数据的方法,用于在更新操作相关逻辑完成后更新界面上的用户数据显示
refreshUser();
}else if(deleteBtn==source) {
//获取选中记录
} else if (deleteBtn == source) {
// 如果点击的是删除按钮,获取用户在表格中选中的行索引,如果没有选中任何行,则返回 -1
int rowIndex = userTable.getSelectedRow();
if(rowIndex==-1) {
JOptionPane.showMessageDialog(this,"请选中一条");
if (rowIndex == -1) {
// 如果没有选中行,弹出提示框提醒用户需要选中一条记录后再进行删除操作
JOptionPane.showMessageDialog(this, "请选中一条");
return;
}
int id = (Integer)userTable.getValueAt(rowIndex,0);
int select=JOptionPane.showConfirmDialog(this,"是否删除id="+id,"提示",JOptionPane.YES_NO_OPTION);
if(select==JOptionPane.YES_OPTION){
if(userService.deleteUser(id)==1) {
JOptionPane.showMessageDialog(this,"删除成功","提示",JOptionPane.INFORMATION_MESSAGE);
}else {
JOptionPane.showMessageDialog(this,"删除失败","提示",JOptionPane.ERROR_MESSAGE);
// 获取选中行的第一列的值并转换为整数类型赋值给id变量用于后续删除操作时确定要删除的用户记录
int id = (Integer) userTable.getValueAt(rowIndex, 0);
// 弹出确认对话框询问用户是否确定删除指定id的用户记录提供"是"和"否"两个选项,返回用户选择的结果
int select = JOptionPane.showConfirmDialog(this, "是否删除id=" + id, "提示", JOptionPane.YES_NO_OPTION);
if (select == JOptionPane.YES_OPTION) {
// 如果用户选择了"是"(确认删除),执行以下操作:
// 调用用户服务接口的删除用户方法传入要删除的用户id尝试从数据库中删除对应的用户记录并获取返回结果假设返回1表示删除成功其他值表示失败
if (userService.deleteUser(id) == 1) {
// 如果删除成功,弹出提示框显示"删除成功"的消息,提示框的图标为信息图标
JOptionPane.showMessageDialog(this, "删除成功", "提示", JOptionPane.INFORMATION_MESSAGE);
} else {
// 如果删除失败,弹出提示框显示"删除失败"的消息,提示框的图标为错误图标
JOptionPane.showMessageDialog(this, "删除失败", "提示", JOptionPane.ERROR_MESSAGE);
}
}
// 无论删除操作是否成功,都调用刷新用户数据的方法,更新界面上的用户数据显示,确保表格等显示内容与数据库中的最新数据一致
refreshUser();
}else{
} else {
// 如果点击的是搜索按钮(即其他未明确匹配的按钮点击情况,这里目前代码逻辑中只存在搜索按钮可能进入此分支),执行以下操作:
System.out.println("搜索");
// 调用刷新按姓名搜索结果的方法,根据用户在姓名搜索文本框中输入的内容进行数据刷新和表格显示更新
refreshFindRname();
}
}
// 根据姓名进行搜索并刷新表格显示内容的方法
public void refreshFindRname() {
// 获取用户在姓名搜索文本框中输入的姓名内容
String rname = nameSearchTF.getText();
User user =new User();
// 创建一个临时的User对象用于传递搜索条件
User user = new User();
// 将获取到的姓名设置到临时User对象中作为搜索条件
user.setRname(rname);
// 创建一个新的用户表格数据模型对象,用于重新获取和设置符合搜索条件的数据
userTableModel = new UserTableModel();
// 调用用户表格数据模型的方法根据传入的包含姓名条件的User对象进行数据查询获取符合条件的用户数据
userTableModel.Byrname(user);
// 将更新后的用户表格数据模型设置给用户表格
userTable.setModel(userTableModel);
//同时更新下面的记录数
refreshCount();
// 同时调用刷新记录数的方法,更新界面下方显示的用户记录总数提示信息
refreshCount();
}
// 刷新用户数据显示
public void refreshUser() {
// 创建一个新的用户表格数据模型对象
userTableModel = new UserTableModel();
// 调用数据模型的方法获取所有用户数据,重新填充模型
userTableModel.all();
// 将更新后的用户表格数据模型设置给用户表格,使表格显示最新的全部用户数据内容
userTable.setModel(userTableModel);
//同时更新下面的记录数
// 同时调用刷新记录数的方法,更新界面下方显示的用户记录总数提示信息
refreshCount();
}
public void refreshCount(){
// 刷新界面下方显示的用户记录总数提示信息的方法
public void refreshCount() {
// 移除bottomPanel面板中之前添加的所有组件更新显示新的记录数
bottomPanel.removeAll();
countInfoLabel = new JLabel("总共"+userTableModel.getRowCount()+"条");
// 创建一个新的显示用户记录总数的标签,文本内容为"总共"加上通过用户表格数据模型获取的当前行数以及"条"字
countInfoLabel = new JLabel("总共" + userTableModel.getRowCount() + "条");
// 将新的记录数标签添加到bottomPanel面板中实现记录数提示信息的更新显示
bottomPanel.add(countInfoLabel);
}
}
}

@ -1,2 +1,4 @@
123
z1
z1

Loading…
Cancel
Save