Compare commits

..

2 Commits

Author SHA1 Message Date
pxeyinm2q 6935474bb6 修改了进货模块的代码注释 (#1)
1 year ago
pxeyinm2q 3e47192761 添加了注释信息 impl v1.0 (#3)
1 year ago

@ -1,7 +1,44 @@
<?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"/>
<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>
<collation id="2" parent="1" name="big5_chinese_ci">
<Charset>big5</Charset>
<DefaultForCharset>1</DefaultForCharset>

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

@ -1,7 +1,44 @@
<?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"/>
<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>
<collation id="2" parent="1" name="big5_chinese_ci">
<Charset>big5</Charset>
<DefaultForCharset>1</DefaultForCharset>

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

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

@ -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);
}

@ -1,3 +1,4 @@
package com.lingnan.supermarket.dialog;
import java.awt.Container;
@ -25,74 +26,54 @@ 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();
@ -103,53 +84,34 @@ 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);
@ -157,40 +119,26 @@ 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接口中的方法
@ -203,85 +151,60 @@ 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;
// 根据下拉框选中的不同选项内容来设置当前用户的权限级别不同的数字0、1、2对应不同的权限
else if (sSuper1.equals("管理员")):
sSuper = 1;
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]; // 返回列名
}
}
}

@ -1,94 +1,82 @@
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 java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Scanner;
import java.awt.event.*;
// Demo4类用于创建一个展示图片切换效果的图形界面程序
public class Demo4 extends JFrame implements ActionListener {
import javax.swing. *;
// 创建一个静态的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() {
// 设置窗口的标题
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>*/
{
tplb.setTitle("ͼƬ<CDBC>ֲ<EFBFBD><D6B2><EFBFBD><EFBFBD><EFBFBD>");
// 设置窗口的布局管理器为null意味着后续添加组件时需要手动指定组件的位置和大小绝对布局
tplb.setLayout(null);
// 设置窗口的大小为宽度700像素高度800像素
tplb.setSize(700, 800);
// 设置窗口大小不可调整,用户不能通过拖动边框等方式改变窗口大小
tplb.setSize(700,800);
tplb.setResizable(false);
// 设置窗口在屏幕上居中显示,使窗口展示位置更美观合理
tplb.setLocationRelativeTo(null);
// 设置当窗口关闭时,整个应用程序随之退出,这是一种常见的关闭窗口行为设置
tplb.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// 设置窗口可见,使其显示在屏幕上,否则窗口创建后是不可见的状态
tplb.setLocationRelativeTo(null);/*<2A><><EFBFBD>þ<EFBFBD><C3BE><EFBFBD>*/
tplb.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);/*<2A>رճ<D8B1><D5B3><EFBFBD>*/
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) {
// 将pan这个JLabel组件的图标设置为imgs数组中当前索引对应的图片实现图片的切换展示效果
public void actionPerformed(ActionEvent e)
{
pan.setIcon(imgs[index]);
// 将索引值加1准备切换到下一张图片
index++;
// 如果索引值达到了imgs数组的长度7表示已经到最后一张图片了将索引重置为0实现循环切换图片的效果
if (index == 7)
index = 0;
if(index==7)
index=0;
}
};
// 调用设置窗口和图片展示相关的方法来展示图形界面效果
public static void main(String[] args) {
// 调用settplb方法设置窗口的基本属性并使其显示出来
settplb();
// 调用setpan方法设置图片展示的JLabel组件相关属性并启动图片切换的定时器功能
setpan();
}
public static void main(String[] args) {
settplb();
setpan();
}
@Override
public void actionPerformed(ActionEvent e) {
// TODO <20>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD>ɵķ<C9B5><C4B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
}
}
}

@ -1,12 +1,13 @@
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;
@ -15,221 +16,161 @@ 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.*;
// 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 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;
}
};
public static void refreshHome() {
// 再次调用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);*/
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);*/
}
// 实现ActionListener接口的actionPerformed方法
@Override
public void actionPerformed(ActionEvent e) {
// 获取触发被点击的按钮
// TODO Auto-generated method stub
Object source = e.getSource();
if (source == refreshBtn) {
// 如果点击的是refreshBtn按钮创建一个新的HomeView实例
if(source==refreshBtn) {
new HomeView(jFrame);
// 调用refreshHome方法刷新首页界面上显示的关键数据更新界面展示内容
refreshHome();
}
}
}

@ -24,160 +24,135 @@ 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;
// 登录视图类实现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的构造方法来设置窗口的大小和标题
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() {
super(350, 250, "新民超市");
// 创建一个ImageIcon对象用于设置窗口的图标传入的参数是图标图片的路径及文件名
ImageIcon icon = new ImageIcon("static\\icon\\新.png");
// 设置窗口的图标通过获取ImageIcon中的Image对象来设置
ImageIcon icon=new ImageIcon("static\\icon\\新.png"); //xxx代表图片存放路径2.png图片名称及格式
this.setIconImage(icon.getImage());
}
/*
* initView
*/
@Override
/*添加组件*/
@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();
// 创建用户名标签通过传入一个ImageIcon来显示带有图标的提示信息
containerPanel = new BGPanel(bgImage);
//用户名
namePanel = new JPanel();
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();
// 获取密码输入文本框中的密码内容通过将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();
}
/*如果点击登录*/
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();
}
}
}
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,231 +23,163 @@ import com.lingnan.supermarket.dto.User;
import com.lingnan.supermarket.table.UserTableModel;
import com.lingnan.supermarket.utils.FontUtil;
// UserView类继承自JPanel并实现ActionListener接口用于构建用户管理界面相关的视图处理用户交互动作
public class UserView extends JPanel implements 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初始化为0
//删除时选中赋值给id
private int id;
// 界面下部相关组件声明
// 用于存放记录数相关提示信息的面板
//下面
private JPanel bottomPanel;
// 用于显示用户记录总数相关提示信息的标签
private JLabel countInfoLabel;
// 对父窗口JFrame类型的引用
private JFrame jFrame;
// 用户表格数据模型对象,用于管理表格中的数据,与数据库等数据源进行交互获取和更新数据等
private UserTableModel userTableModel;
// 用户服务接口的实现类实例,通过它可以调用与用户相关的数据库操作方法,如增删改查等功能
private UserService userService = new UserServiceImpl();
// 构造函数接收一个JFrame类型的参数jFrame用于创建用户管理视图并初始化界面组件
private UserTableModel userTableModel ;
private UserService userService=new UserServiceImpl();
public UserView(JFrame jFrame) {
// 设置该面板UserView的布局为BorderLayout将界面划分为北、南、东、西、中五个区域来放置组件
this.setLayout(new BorderLayout());
// 调用初始化视图组件的方法
initView();
// 将传入的父窗口引用保存到成员变量jFrame中
this.jFrame = jFrame;
}
// 初始化用户管理视图界面组件的方法
private void initView() {
// 创建一个新的面板toolBarPanel设置其布局为BorderLayout用于存放顶部的搜索和操作按钮等组件
toolBarPanel = new JPanel(new BorderLayout());
// 创建一个新的面板searchPanel设置其布局为FlowLayout且组件左对齐用于存放搜索相关的组件
searchPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
// 创建一个显示当前位置提示信息的标签,这里显示为"当前位置>人员管理"
locationLabel = new JLabel("当前位置>人员管理");
// 设置标签的字体为通过FontUtil类获取的特定字体这里假设FontUtil类用于统一管理字体相关设置
toolBarPanel = new JPanel(new BorderLayout());
searchPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
locationLabel=new JLabel("当前位置>人员管理");
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设置其布局为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方法上以便处理相应的操作逻辑
/*右边功能模块*/
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"));
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的西边左侧区域将操作按钮面板添加到toolBarPanel的东边右侧区域
toolBarPanel.add(searchPanel, "West");
toolBarPanel.add(opePanel, "East");
// 创建用户表格数据模型对象
userTableModel = new UserTableModel();
// 调用数据模型的方法获取所有用户数据用于初始化表格显示内容这里假设UserTableModel类中的all方法用于从数据库等数据源获取全部用户数据并填充到模型中
toolBarPanel.add(searchPanel,"West");
toolBarPanel.add(opePanel,"East");
//中间表格
userTableModel = new UserTableModel();
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));
// 创建一个显示用户记录总数的标签,初始文本为"总共"加上通过用户表格数据模型获取的行数假设UserTableModel类的getRowCount方法返回当前模型中的数据行数以及"条"字
countInfoLabel = new JLabel("总共" + userTableModel.getRowCount() + "条");
// 将记录数标签添加到bottomPanel面板中
countInfoLabel = new JLabel("总共"+userTableModel.getRowCount()+"条");
bottomPanel.add(countInfoLabel);
// 将顶部工具栏面板添加到当前面板UserView的北部上方区域
this.add(toolBarPanel, "North");
// 将包含用户表格的滚动面板添加到当前面板UserView的中部区域使其在界面中间显示
this.add(tableScrollPane, "Center");
// 将记录数面板添加到当前面板UserView的南部下方区域
this.add(bottomPanel, "South");
// 设置当前面板UserView可见使其在界面上显示出来
this.add(toolBarPanel,"North");
this.add(tableScrollPane,"Center");/*将表格放到中间*/
this.add(bottomPanel,"South");
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) {
// 如果点击的是删除按钮,获取用户在表格中选中的行索引,如果没有选中任何行,则返回 -1
}else if(deleteBtn==source) {
//获取选中记录
int rowIndex = userTable.getSelectedRow();
if (rowIndex == -1) {
// 如果没有选中行,弹出提示框提醒用户需要选中一条记录后再进行删除操作
JOptionPane.showMessageDialog(this, "请选中一条");
if(rowIndex==-1) {
JOptionPane.showMessageDialog(this,"请选中一条");
return;
}
// 获取选中行的第一列的值并转换为整数类型赋值给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);
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);
}
}
// 无论删除操作是否成功,都调用刷新用户数据的方法,更新界面上的用户数据显示,确保表格等显示内容与数据库中的最新数据一致
refreshUser();
} else {
// 如果点击的是搜索按钮(即其他未明确匹配的按钮点击情况,这里目前代码逻辑中只存在搜索按钮可能进入此分支),执行以下操作:
}else{
System.out.println("搜索");
// 调用刷新按姓名搜索结果的方法,根据用户在姓名搜索文本框中输入的内容进行数据刷新和表格显示更新
refreshFindRname();
}
}
// 根据姓名进行搜索并刷新表格显示内容的方法
public void refreshFindRname() {
// 获取用户在姓名搜索文本框中输入的姓名内容
String rname = nameSearchTF.getText();
// 创建一个临时的User对象用于传递搜索条件
User user = new User();
// 将获取到的姓名设置到临时User对象中作为搜索条件
User user =new 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() {
// 移除bottomPanel面板中之前添加的所有组件更新显示新的记录数
public void refreshCount(){
bottomPanel.removeAll();
// 创建一个新的显示用户记录总数的标签,文本内容为"总共"加上通过用户表格数据模型获取的当前行数以及"条"字
countInfoLabel = new JLabel("总共" + userTableModel.getRowCount() + "条");
// 将新的记录数标签添加到bottomPanel面板中实现记录数提示信息的更新显示
countInfoLabel = new JLabel("总共"+userTableModel.getRowCount()+"条");
bottomPanel.add(countInfoLabel);
}
}
}

@ -1 +1 @@
1234566464
123
Loading…
Cancel
Save