Merge pull request 'lx' (#2) from lx into master

Reviewed-on: #2
This commit is contained in:
lcm
2025-09-18 14:38:28 +00:00
3 changed files with 105 additions and 3 deletions

View File

@@ -12,7 +12,7 @@ public class Home extends JFrame implements ActionListener {
JMenuItem StockMenuItem,InventoryMenuItem,SalesMenuItem; JMenuItem StockMenuItem,InventoryMenuItem,SalesMenuItem;
Home() { Home() {
super("市进销存信息管理系统"); super("市进销存信息管理系统");
menuBar = new JMenuBar(); menuBar = new JMenuBar();
menu = new JMenu("菜单"); menu = new JMenu("菜单");
StockMenuItem = new JMenuItem("库存信息管理"); StockMenuItem = new JMenuItem("库存信息管理");

View File

@@ -49,7 +49,7 @@ public class Main extends JFrame implements ActionListener {
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()+"'"; ;
try { try {
ResultSet rs = jdbc.query(sql); ResultSet rs = jdbc.query(sql);
jdbc.close();
if(rs.next()&&tf3.getText().equals(jl5.getText())) { if(rs.next()&&tf3.getText().equals(jl5.getText())) {
JOptionPane.showMessageDialog(null, "登录成功"); JOptionPane.showMessageDialog(null, "登录成功");
new Home(); new Home();
@@ -70,4 +70,5 @@ public class Main extends JFrame implements ActionListener {
public static void main(String[] args) { public static void main(String[] args) {
new Main(); new Main();
} }
} }

View File

@@ -1,4 +1,105 @@
package com.example; package com.example;
public class SalesProductManagement { import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class SalesProductManagement extends JFrame implements ActionListener {
JButton btn1;
JLabel lab1,lab2,lab3,lab4,lab5,lab6,lab7;
JTextField text2,text3,text5,text6,text8,text9,text10;
// JPasswordField passwordfile;
JPanel panel1,panel2,panel3;
SalesProductManagement(){
super("销售信息管理");
panel1 = new JPanel();
panel2 = new JPanel();
panel3 = new JPanel();
lab1=new JLabel("名称",JLabel.CENTER);
lab2=new JLabel("单价",JLabel.CENTER);
lab3=new JLabel("数量",JLabel.CENTER);
lab4=new JLabel("总计:",JLabel.CENTER);
lab5=new JLabel("苹果",JLabel.CENTER);
lab6=new JLabel("香蕉",JLabel.CENTER);
lab7=new JLabel("橘子",JLabel.CENTER);
text2=new JTextField("2"+"",JTextField.CENTER);
text3=new JTextField(3);
text5=new JTextField("3"+"",JTextField.CENTER);
text6=new JTextField(3);
text8=new JTextField("5"+"",JTextField.CENTER);
text9=new JTextField(3);
text10=new JTextField(5);
btn1=new JButton("结算");
btn1.addActionListener(this);
add(panel1);
panel1.setLayout(new GridLayout(1,3,5,5));
panel1.add(lab1);
panel1.add(lab2);
panel1.add(lab3);
panel1.setMaximumSize(new Dimension(Integer.MAX_VALUE, 40));
add(panel2);
panel2.setLayout(new GridLayout(3,3,5,5));
panel2.add(lab5);
panel2.add(text2);
panel2.add(text3);
panel2.add(lab6);
panel2.add(text5);
panel2.add(text6);
panel2.add(lab7);
panel2.add(text8);
panel2.add(text9);
panel2.setMaximumSize(new Dimension(Integer.MAX_VALUE, 120));
add(panel3);
panel3.setLayout(new GridLayout(1,3,5,5));
panel3.add(btn1);
panel3.add(lab4);
panel3.add(text10);
panel3.setMaximumSize(new Dimension(Integer.MAX_VALUE, 40));
setLayout(new GridLayout(3,1));
setSize(500,500);
setLocationRelativeTo(null);
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // 添加窗口关闭功能
}
@Override
public void actionPerformed(ActionEvent e) {
// 判断事件源是否为结算按钮
if (e.getSource() == btn1) {
try {
// 获取单价(从文本框提取数字部分)
double applePrice = Double.parseDouble(text2.getText().replace("", ""));
double bananaPrice = Double.parseDouble(text5.getText().replace("", ""));
double orangePrice = Double.parseDouble(text8.getText().replace("", ""));
// 获取数量(处理空输入情况)
int appleCount = text3.getText().trim().isEmpty() ? 0 : Integer.parseInt(text3.getText().trim());
int bananaCount = text6.getText().trim().isEmpty() ? 0 : Integer.parseInt(text6.getText().trim());
int orangeCount = text9.getText().trim().isEmpty() ? 0 : Integer.parseInt(text9.getText().trim());
// 计算总金额
double total = (applePrice * appleCount) + (bananaPrice * bananaCount) + (orangePrice * orangeCount);
// 显示结果,保留两位小数
text10.setText(String.format("%.2f元", total));
} catch (NumberFormatException ex) {
// 处理输入非数字的情况
JOptionPane.showMessageDialog(this, "请输入有效的数字", "输入错误", JOptionPane.ERROR_MESSAGE);
}
}
}
public static void main(String[] args) {
new SalesProductManagement();
}
} }