完整版

This commit is contained in:
lu
2025-10-07 14:13:18 +08:00
parent d98573b777
commit a3f85588c6
6 changed files with 23 additions and 22 deletions

View File

@@ -11,7 +11,7 @@ public class Home extends JFrame implements ActionListener {
JMenuBar menuBar;
// 库存菜单 进货菜单 销售菜单
JButton StockMenu,InventoryMenu,SalesMenu,UserMenu;
JButton StockMenu,InventoryMenu,SalesMenu,UserMenu,LogoutMenu;
private String userIdentity;
class BackgroundPanel extends JPanel {
private Image bg;
@@ -37,13 +37,16 @@ public class Home extends JFrame implements ActionListener {
StockMenu = new JButton("库存信息管理");
InventoryMenu = new JButton("进货信息管理");
SalesMenu = new JButton("销售信息管理");
LogoutMenu = new JButton("退出登录");
menuBar.add(StockMenu);
menuBar.add(InventoryMenu);
menuBar.add(SalesMenu);
menuBar.add(LogoutMenu);
setJMenuBar(menuBar);
StockMenu.addActionListener(this);
InventoryMenu.addActionListener(this);
SalesMenu.addActionListener(this);
LogoutMenu.addActionListener(this);
Jdbc jdbc = new Jdbc();
String sql = "select * from user where username='"+username+"'";
try {
@@ -78,6 +81,10 @@ public class Home extends JFrame implements ActionListener {
if(e.getSource()==UserMenu){
new UserManagement();
}
if(e.getSource()==LogoutMenu){
new Main();
this.dispose();
}
}
public static void main(String[] args) {
new Home("admin");

View File

@@ -259,6 +259,6 @@ public class InventoryProductManagement extends JFrame implements ActionListener
}
public static void main(String[] args) {
SwingUtilities.invokeLater(InventoryProductManagement::new);
new InventoryProductManagement();
}
}

View File

@@ -46,7 +46,6 @@ public class Main extends JFrame implements ActionListener {
@Override
public void actionPerformed(ActionEvent e) {
if(e.getSource()==jb1){
Jdbc jdbc = new Jdbc();
String sql = "select * from user where username='"+tf1.getText()+"' and password='"+tf2.getText()+"'"; ;

View File

@@ -5,7 +5,6 @@ import javax.swing.event.TableModelEvent;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableCellRenderer;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.io.File;
import java.sql.ResultSet;
@@ -29,7 +28,7 @@ public class SalesProductManagement extends JFrame {
JPanel mainPanel = new JPanel(new BorderLayout());
// 顶部按钮面板 - 新增
// 顶部按钮面板
JPanel topPanel = new JPanel(new FlowLayout(FlowLayout.LEFT, 10, 10));
addBtn = new JButton("上架商品");
removeBtn = new JButton("从界面下架");
@@ -92,17 +91,14 @@ public class SalesProductManagement extends JFrame {
setVisible(true);
}
// 新增:统一设置事件监听器
// 设置事件监听器
private void setupEventListeners() {
// 结算按钮事件
checkoutBtn.addActionListener(e -> calculateTotal());
// 上架按钮事件
addBtn.addActionListener(e -> addProductFromDatabase());
// 下架按钮事件
removeBtn.addActionListener(e -> removeSelectedProducts());
// 表格模型监听器,处理数据更新
tableModel.addTableModelListener(e -> {
if (e.getType() == TableModelEvent.UPDATE) {
@@ -127,7 +123,7 @@ public class SalesProductManagement extends JFrame {
});
}
// 新增:从数据库上架商品(选择数据库中未显示的商品添加到界面)
// 从数据库上架商品(选择数据库中未显示的商品添加到界面)
private void addProductFromDatabase() {
try {
Jdbc jdbc = new Jdbc();
@@ -206,7 +202,7 @@ public class SalesProductManagement extends JFrame {
}
}
// 新增:从界面下架商品(仅从当前界面移除,不删除数据库记录)
// 从界面下架商品(仅从当前界面移除,不删除数据库记录)
private void removeSelectedProducts() {
int[] selectedRows = table.getSelectedRows();
if (selectedRows.length == 0) {

View File

@@ -15,16 +15,15 @@ public class StockProductManagement extends JFrame {
private DefaultTableModel tableModel;
private JTextField searchField;
private JComboBox<String> categoryComboBox;
private JButton resetButton; // 新增:重置按钮
private JButton resetButton;
public StockProductManagement() {
super("库存商品信息管理");
setSize(900, 550);
setLocationRelativeTo(null);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// === 顶部工具面板 ===
//顶部工具面板
JPanel topPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
topPanel.add(new JLabel("搜索商品名称:"));
@@ -36,15 +35,15 @@ public class StockProductManagement extends JFrame {
topPanel.add(new JLabel("筛选类别:"));
categoryComboBox = new JComboBox<>();
categoryComboBox.addItem("全部"); // 初始
categoryComboBox.addItem("全部");
topPanel.add(categoryComboBox);
resetButton = new JButton("重置"); // 新增
resetButton = new JButton("重置");
topPanel.add(resetButton);
add(topPanel, BorderLayout.NORTH);
// === 表格 ===
// 表格
String[] columnNames = {"商品照片","商品名称","商品类别","商品数量","进货单价","销售单价","单个利润","销售数量"};
tableModel = new DefaultTableModel(columnNames, 0){
@Override
@@ -60,7 +59,7 @@ public class StockProductManagement extends JFrame {
table = new JTable(tableModel);
table.setRowHeight(60);
// 图片渲染
// 图片渲染
table.getColumnModel().getColumn(0).setCellRenderer(new TableCellRenderer() {
JLabel label = new JLabel();
@Override
@@ -94,7 +93,7 @@ public class StockProductManagement extends JFrame {
JScrollPane scrollPane = new JScrollPane(table);
add(scrollPane, BorderLayout.CENTER);
// === 事件绑定 ===
searchButton.addActionListener(ev -> reloadData());
categoryComboBox.addActionListener(ev -> reloadData());
resetButton.addActionListener(ev -> { // 重置功能
@@ -173,6 +172,6 @@ public class StockProductManagement extends JFrame {
}
public static void main(String[] args){
SwingUtilities.invokeLater(StockProductManagement::new);
new StockProductManagement();
}
}

View File

@@ -103,7 +103,7 @@ public class UserManagement extends JFrame implements ActionListener {
Jdbc jdbc = new Jdbc();
try {
jdbc.update("INSERT INTO user (username,password,email,phone,identity) VALUES ('"
jdbc.update("INSERT INTO user (username,password,identity) VALUES ('"
+ username + "','" + password + "','user')");
jdbc.close();
loadData();
@@ -140,7 +140,7 @@ public class UserManagement extends JFrame implements ActionListener {
}
}
// 修改用户(选中一行后弹窗修改)
// 修改用户
else if (e.getSource() == updateItem) {
int row = table.getSelectedRow();
if (row == -1) {