完整版
This commit is contained in:
@@ -11,7 +11,7 @@ public class Home extends JFrame implements ActionListener {
|
|||||||
|
|
||||||
JMenuBar menuBar;
|
JMenuBar menuBar;
|
||||||
// 库存菜单 进货菜单 销售菜单
|
// 库存菜单 进货菜单 销售菜单
|
||||||
JButton StockMenu,InventoryMenu,SalesMenu,UserMenu;
|
JButton StockMenu,InventoryMenu,SalesMenu,UserMenu,LogoutMenu;
|
||||||
private String userIdentity;
|
private String userIdentity;
|
||||||
class BackgroundPanel extends JPanel {
|
class BackgroundPanel extends JPanel {
|
||||||
private Image bg;
|
private Image bg;
|
||||||
@@ -37,13 +37,16 @@ public class Home extends JFrame implements ActionListener {
|
|||||||
StockMenu = new JButton("库存信息管理");
|
StockMenu = new JButton("库存信息管理");
|
||||||
InventoryMenu = new JButton("进货信息管理");
|
InventoryMenu = new JButton("进货信息管理");
|
||||||
SalesMenu = new JButton("销售信息管理");
|
SalesMenu = new JButton("销售信息管理");
|
||||||
|
LogoutMenu = new JButton("退出登录");
|
||||||
menuBar.add(StockMenu);
|
menuBar.add(StockMenu);
|
||||||
menuBar.add(InventoryMenu);
|
menuBar.add(InventoryMenu);
|
||||||
menuBar.add(SalesMenu);
|
menuBar.add(SalesMenu);
|
||||||
|
menuBar.add(LogoutMenu);
|
||||||
setJMenuBar(menuBar);
|
setJMenuBar(menuBar);
|
||||||
StockMenu.addActionListener(this);
|
StockMenu.addActionListener(this);
|
||||||
InventoryMenu.addActionListener(this);
|
InventoryMenu.addActionListener(this);
|
||||||
SalesMenu.addActionListener(this);
|
SalesMenu.addActionListener(this);
|
||||||
|
LogoutMenu.addActionListener(this);
|
||||||
Jdbc jdbc = new Jdbc();
|
Jdbc jdbc = new Jdbc();
|
||||||
String sql = "select * from user where username='"+username+"'";
|
String sql = "select * from user where username='"+username+"'";
|
||||||
try {
|
try {
|
||||||
@@ -78,6 +81,10 @@ public class Home extends JFrame implements ActionListener {
|
|||||||
if(e.getSource()==UserMenu){
|
if(e.getSource()==UserMenu){
|
||||||
new UserManagement();
|
new UserManagement();
|
||||||
}
|
}
|
||||||
|
if(e.getSource()==LogoutMenu){
|
||||||
|
new Main();
|
||||||
|
this.dispose();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
new Home("admin");
|
new Home("admin");
|
||||||
|
|||||||
@@ -259,6 +259,6 @@ public class InventoryProductManagement extends JFrame implements ActionListener
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
SwingUtilities.invokeLater(InventoryProductManagement::new);
|
new InventoryProductManagement();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -46,7 +46,6 @@ public class Main extends JFrame implements ActionListener {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
|
||||||
if(e.getSource()==jb1){
|
if(e.getSource()==jb1){
|
||||||
Jdbc jdbc = new Jdbc();
|
Jdbc jdbc = new Jdbc();
|
||||||
String sql = "select * from user where username='"+tf1.getText()+"' and password='"+tf2.getText()+"'"; ;
|
String sql = "select * from user where username='"+tf1.getText()+"' and password='"+tf2.getText()+"'"; ;
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ import javax.swing.event.TableModelEvent;
|
|||||||
import javax.swing.table.DefaultTableModel;
|
import javax.swing.table.DefaultTableModel;
|
||||||
import javax.swing.table.TableCellRenderer;
|
import javax.swing.table.TableCellRenderer;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.awt.event.ActionEvent;
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
|
|
||||||
@@ -29,7 +28,7 @@ public class SalesProductManagement extends JFrame {
|
|||||||
|
|
||||||
JPanel mainPanel = new JPanel(new BorderLayout());
|
JPanel mainPanel = new JPanel(new BorderLayout());
|
||||||
|
|
||||||
// 顶部按钮面板 - 新增
|
// 顶部按钮面板
|
||||||
JPanel topPanel = new JPanel(new FlowLayout(FlowLayout.LEFT, 10, 10));
|
JPanel topPanel = new JPanel(new FlowLayout(FlowLayout.LEFT, 10, 10));
|
||||||
addBtn = new JButton("上架商品");
|
addBtn = new JButton("上架商品");
|
||||||
removeBtn = new JButton("从界面下架");
|
removeBtn = new JButton("从界面下架");
|
||||||
@@ -92,17 +91,14 @@ public class SalesProductManagement extends JFrame {
|
|||||||
setVisible(true);
|
setVisible(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 新增:统一设置事件监听器
|
// 设置事件监听器
|
||||||
private void setupEventListeners() {
|
private void setupEventListeners() {
|
||||||
// 结算按钮事件
|
// 结算按钮事件
|
||||||
checkoutBtn.addActionListener(e -> calculateTotal());
|
checkoutBtn.addActionListener(e -> calculateTotal());
|
||||||
|
|
||||||
// 上架按钮事件
|
// 上架按钮事件
|
||||||
addBtn.addActionListener(e -> addProductFromDatabase());
|
addBtn.addActionListener(e -> addProductFromDatabase());
|
||||||
|
|
||||||
// 下架按钮事件
|
// 下架按钮事件
|
||||||
removeBtn.addActionListener(e -> removeSelectedProducts());
|
removeBtn.addActionListener(e -> removeSelectedProducts());
|
||||||
|
|
||||||
// 表格模型监听器,处理数据更新
|
// 表格模型监听器,处理数据更新
|
||||||
tableModel.addTableModelListener(e -> {
|
tableModel.addTableModelListener(e -> {
|
||||||
if (e.getType() == TableModelEvent.UPDATE) {
|
if (e.getType() == TableModelEvent.UPDATE) {
|
||||||
@@ -127,7 +123,7 @@ public class SalesProductManagement extends JFrame {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// 新增:从数据库上架商品(选择数据库中未显示的商品添加到界面)
|
// 从数据库上架商品(选择数据库中未显示的商品添加到界面)
|
||||||
private void addProductFromDatabase() {
|
private void addProductFromDatabase() {
|
||||||
try {
|
try {
|
||||||
Jdbc jdbc = new Jdbc();
|
Jdbc jdbc = new Jdbc();
|
||||||
@@ -206,7 +202,7 @@ public class SalesProductManagement extends JFrame {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 新增:从界面下架商品(仅从当前界面移除,不删除数据库记录)
|
// 从界面下架商品(仅从当前界面移除,不删除数据库记录)
|
||||||
private void removeSelectedProducts() {
|
private void removeSelectedProducts() {
|
||||||
int[] selectedRows = table.getSelectedRows();
|
int[] selectedRows = table.getSelectedRows();
|
||||||
if (selectedRows.length == 0) {
|
if (selectedRows.length == 0) {
|
||||||
|
|||||||
@@ -15,16 +15,15 @@ public class StockProductManagement extends JFrame {
|
|||||||
private DefaultTableModel tableModel;
|
private DefaultTableModel tableModel;
|
||||||
private JTextField searchField;
|
private JTextField searchField;
|
||||||
private JComboBox<String> categoryComboBox;
|
private JComboBox<String> categoryComboBox;
|
||||||
private JButton resetButton; // 新增:重置按钮
|
private JButton resetButton;
|
||||||
|
|
||||||
public StockProductManagement() {
|
public StockProductManagement() {
|
||||||
super("库存商品信息管理");
|
super("库存商品信息管理");
|
||||||
|
|
||||||
setSize(900, 550);
|
setSize(900, 550);
|
||||||
setLocationRelativeTo(null);
|
setLocationRelativeTo(null);
|
||||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
|
||||||
|
|
||||||
// === 顶部工具面板 ===
|
//顶部工具面板
|
||||||
JPanel topPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
|
JPanel topPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
|
||||||
|
|
||||||
topPanel.add(new JLabel("搜索商品名称:"));
|
topPanel.add(new JLabel("搜索商品名称:"));
|
||||||
@@ -36,15 +35,15 @@ public class StockProductManagement extends JFrame {
|
|||||||
|
|
||||||
topPanel.add(new JLabel("筛选类别:"));
|
topPanel.add(new JLabel("筛选类别:"));
|
||||||
categoryComboBox = new JComboBox<>();
|
categoryComboBox = new JComboBox<>();
|
||||||
categoryComboBox.addItem("全部"); // 初始
|
categoryComboBox.addItem("全部");
|
||||||
topPanel.add(categoryComboBox);
|
topPanel.add(categoryComboBox);
|
||||||
|
|
||||||
resetButton = new JButton("重置"); // 新增
|
resetButton = new JButton("重置");
|
||||||
topPanel.add(resetButton);
|
topPanel.add(resetButton);
|
||||||
|
|
||||||
add(topPanel, BorderLayout.NORTH);
|
add(topPanel, BorderLayout.NORTH);
|
||||||
|
|
||||||
// === 表格 ===
|
// 表格
|
||||||
String[] columnNames = {"商品照片","商品名称","商品类别","商品数量","进货单价","销售单价","单个利润","销售数量"};
|
String[] columnNames = {"商品照片","商品名称","商品类别","商品数量","进货单价","销售单价","单个利润","销售数量"};
|
||||||
tableModel = new DefaultTableModel(columnNames, 0){
|
tableModel = new DefaultTableModel(columnNames, 0){
|
||||||
@Override
|
@Override
|
||||||
@@ -60,7 +59,7 @@ public class StockProductManagement extends JFrame {
|
|||||||
table = new JTable(tableModel);
|
table = new JTable(tableModel);
|
||||||
table.setRowHeight(60);
|
table.setRowHeight(60);
|
||||||
|
|
||||||
// 图片渲染器
|
// 图片渲染
|
||||||
table.getColumnModel().getColumn(0).setCellRenderer(new TableCellRenderer() {
|
table.getColumnModel().getColumn(0).setCellRenderer(new TableCellRenderer() {
|
||||||
JLabel label = new JLabel();
|
JLabel label = new JLabel();
|
||||||
@Override
|
@Override
|
||||||
@@ -94,7 +93,7 @@ public class StockProductManagement extends JFrame {
|
|||||||
JScrollPane scrollPane = new JScrollPane(table);
|
JScrollPane scrollPane = new JScrollPane(table);
|
||||||
add(scrollPane, BorderLayout.CENTER);
|
add(scrollPane, BorderLayout.CENTER);
|
||||||
|
|
||||||
// === 事件绑定 ===
|
|
||||||
searchButton.addActionListener(ev -> reloadData());
|
searchButton.addActionListener(ev -> reloadData());
|
||||||
categoryComboBox.addActionListener(ev -> reloadData());
|
categoryComboBox.addActionListener(ev -> reloadData());
|
||||||
resetButton.addActionListener(ev -> { // 重置功能
|
resetButton.addActionListener(ev -> { // 重置功能
|
||||||
@@ -173,6 +172,6 @@ public class StockProductManagement extends JFrame {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args){
|
public static void main(String[] args){
|
||||||
SwingUtilities.invokeLater(StockProductManagement::new);
|
new StockProductManagement();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -103,7 +103,7 @@ public class UserManagement extends JFrame implements ActionListener {
|
|||||||
|
|
||||||
Jdbc jdbc = new Jdbc();
|
Jdbc jdbc = new Jdbc();
|
||||||
try {
|
try {
|
||||||
jdbc.update("INSERT INTO user (username,password,email,phone,identity) VALUES ('"
|
jdbc.update("INSERT INTO user (username,password,identity) VALUES ('"
|
||||||
+ username + "','" + password + "','user')");
|
+ username + "','" + password + "','user')");
|
||||||
jdbc.close();
|
jdbc.close();
|
||||||
loadData();
|
loadData();
|
||||||
@@ -140,7 +140,7 @@ public class UserManagement extends JFrame implements ActionListener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 修改用户(选中一行后弹窗修改)
|
// 修改用户
|
||||||
else if (e.getSource() == updateItem) {
|
else if (e.getSource() == updateItem) {
|
||||||
int row = table.getSelectedRow();
|
int row = table.getSelectedRow();
|
||||||
if (row == -1) {
|
if (row == -1) {
|
||||||
|
|||||||
Reference in New Issue
Block a user