📄 304997807830001d14bca828f5ee0475
字号:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import java.util.*;
import java.sql.*;
public class CarInfo extends JPanel implements ActionListener, Runnable {
/**
* 汽车维修 车牌号码 车主姓名 车主身份证号 更 换 零 件 耗用零件数量 修理工时 小时工资 维修人员 维修原因
*
*/
private JLabel lbTitile = new JLabel("欢迎进入汽车维修界面", JLabel.CENTER);
private JLabel lbNum = new JLabel("车牌号码:");
private JLabel lbName = new JLabel("车主姓名:");
private JLabel lbID = new JLabel("车主身份证号:");
private JLabel lbResult = new JLabel("维修原因:");
private JLabel lbChange = new JLabel("更换部件名称:");
private JLabel lbChangePrice = new JLabel("零件价格");
private JLabel lbChangeNum = new JLabel("耗用零件数量:");
private JLabel lbUseTime = new JLabel("修理工时:");
private JLabel lbHourMoney = new JLabel("小时工资:");
private JLabel lbPerson = new JLabel("维修人员:");
private JTextField tfNum = new JTextField("", 10);
private JTextField tfName = new JTextField("", 10);
private JTextField tfID = new JTextField("", 10);
private JTextField tfResult = new JTextField("", 10);
private JTextField tfChange = new JTextField("", 10);
private JTextField tfChangePrice = new JTextField("", 10);
private JTextField tfChangeNum = new JTextField("", 10);
private JTextField tfUseTime = new JTextField("", 10);
private JTextField tfHourMoney = new JTextField("", 10);
private JTextField tfPerson = new JTextField("", 10);
private JButton btnSend = new JButton("提交");
private JButton btnCancle = new JButton("重置");
private ImageIcon icon = new ImageIcon("1.jpg");
private JLabel lbImg = new JLabel(icon);
private ImageIcon icon1 = new ImageIcon("13.jpg");
private JLabel lbicon1 = new JLabel(icon1);
private Thread thread;
private Color color;
private Vector vec;
int ss;
public CarInfo() {
thread = new Thread(this);
thread.start();
this.init();
this.setVisible(true);
}
public void init() {
lbTitile.setBounds(196, 70, 230, 80);
Font font = new Font("楷体", Font.BOLD, 15);
lbTitile.setFont(font);
lbTitile.setForeground(Color.BLUE);
lbNum.setBounds(200, 130, 150, 40);
lbName.setBounds(200, 160, 150, 40);
lbID.setBounds(200, 190, 150, 40);
lbResult.setBounds(200, 220, 150, 40);
lbChange.setBounds(200, 250, 150, 40);
lbChangePrice.setBounds(200, 280, 150, 40);
lbChangeNum.setBounds(200, 310, 150, 40);
lbUseTime.setBounds(200, 340, 150, 40);
lbHourMoney.setBounds(200, 370, 150, 40);
lbPerson.setBounds(200, 400, 150, 40);
lbNum.setForeground(Color.green);
lbName.setForeground(Color.green);
lbID.setForeground(Color.green);
lbResult.setForeground(Color.green);
lbChange.setForeground(Color.green);
lbChangePrice.setForeground(Color.green);
lbChangeNum.setForeground(Color.green);
lbUseTime.setForeground(Color.green);
lbHourMoney.setForeground(Color.green);
lbPerson.setForeground(Color.green);
chooseColor();
tfNum.setBounds(280, 138, 140, 20);
tfName.setBounds(280, 168, 140, 20);
tfID.setBounds(280, 198, 140, 20);
tfResult.setBounds(280, 228, 140, 20);
tfChange.setBounds(280, 258, 140, 20);
tfChangePrice.setBounds(280, 288, 140, 20);
tfChangeNum.setBounds(280, 318, 140, 20);
tfUseTime.setBounds(280, 348, 140, 20);
tfHourMoney.setBounds(280, 378, 140, 20);
tfPerson.setBounds(280, 408, 140, 20);
lbicon1.setBounds(480, 220, 139, 104);
btnSend.setBounds(210, 458, 80, 22);
btnCancle.setBounds(330, 458, 80, 22);
btnSend.addActionListener(this);
btnCancle.addActionListener(this);
// lbImg.add(lbicon1);
lbImg.add(lbTitile);
lbImg.add(lbNum);
lbImg.add(lbName);
lbImg.add(lbID);
lbImg.add(lbResult);
lbImg.add(lbChange);
lbImg.add(lbChangePrice);
lbImg.add(lbChangeNum);
lbImg.add(lbUseTime);
lbImg.add(lbHourMoney);
lbImg.add(lbPerson);
lbImg.add(tfNum);
lbImg.add(tfName);
lbImg.add(tfID);
lbImg.add(tfResult);
lbImg.add(tfChange);
lbImg.add(tfChangePrice);
lbImg.add(tfChangeNum);
lbImg.add(tfUseTime);
lbImg.add(tfHourMoney);
lbImg.add(tfPerson);
lbImg.add(btnSend);
lbImg.add(btnCancle);
add(lbImg, SwingConstants.CENTER);
}
public void chooseColor() {
color = JColorChooser.showDialog(CarInfo.this, "设置文本框背景颜色", color);
tfNum.setBackground(color);
tfName.setBackground(color);
tfID.setBackground(color);
tfResult.setBackground(color);
tfChange.setBackground(color);
tfChangePrice.setBackground(color);
tfChangeNum.setBackground(color);
tfUseTime.setBackground(color);
tfHourMoney.setBackground(color);
tfPerson.setBackground(color);
}
public void actionPerformed(ActionEvent e) {
if (e.getSource() == btnSend) {
dealBtnSend();
} else if (e.getSource() == btnCancle) {
dealBtnCancle();
}
}
public void dealBtnSend() {
try {
ConToDB DB = new ConToDB();
DB.LinkDB();
PreparedStatement st,st2;
String Num = tfNum.getText();
String Name = tfName.getText();
String ID = tfID.getText();
String Result = tfResult.getText();// 维修原因
String Change = tfChange.getText();// 更换部件名称
String cp = tfChangePrice.getText();
String cn = tfChangeNum.getText();
String usehour = tfUseTime.getText();
String chourpay = tfHourMoney.getText();
String Person = tfPerson.getText();
int CNum= Integer.parseInt(cn);
int partnum;
int partnum1;
float ChangePrice = Float.parseFloat(tfChangePrice.getText()
.trim());
float UseTime = Float.parseFloat(tfUseTime.getText().trim());
float HourMoney = Float.parseFloat(tfHourMoney.getText().trim());
float PersonMoney = 3 * (UseTime * HourMoney);// 修车费
float ChangAllMoney = ChangePrice * CNum;// 零件费用
float TotallMoney = PersonMoney + ChangAllMoney;// 修车费
String sql = "insert into CarInfo values(?,?,?,?,?,?,?,?,?,?,?,?,?)";
String sql1="select * from Part where partName=? ";
if (Num.equals("")) {
JOptionPane.showMessageDialog(this, "车牌号码不能为空");
} else if (Name.equals("")) {
JOptionPane.showMessageDialog(this, "车主姓名不能为空");
} else if (ID.equals("")) {
JOptionPane.showMessageDialog(this, "车主身份证不能为空!");
} else if (Result.equals("")) {
JOptionPane.showMessageDialog(this, "维修原因不能为空!");
} else if (Change.equals("")) {
JOptionPane.showMessageDialog(this, "更换部件不能为空!");
} else if (cp.equals("")) {
JOptionPane.showMessageDialog(this, "零件价格不能为空");
} else if (cn.equals("")) {
JOptionPane.showMessageDialog(this, "更换部件数量不能为空!");
} else if (usehour.equals("")) {
JOptionPane.showMessageDialog(this, "维修工时不能为空");
} else if (chourpay.equals("")) {
JOptionPane.showMessageDialog(this, "维修工小时工资不能为空!");
} else if (Person.equals("")) {
JOptionPane.showMessageDialog(this, "维修人员姓名不能为空 !");
} else {
boolean flag=false;
st = DB.con.prepareStatement(sql1);
st.setString(1, Change);
ResultSet rs=st.executeQuery();
vec=new Vector(1,1);
int s=0;
while(rs.next())
{
s++;
String partid=rs.getString(1);
String partname=rs.getString(2);
float partprice=rs.getFloat(3);
partnum=rs.getInt(4);
//System.out.println(partnum+":");
if(s==1)
{
ss=partnum;
}
flag=true;
}
if(!flag)
{
JOptionPane.showMessageDialog(this, "该更换部件已经卖空或根本就没进购,请核实!");
}
else
{
if(ss<CNum)
{
System.out.println("该零件库存数量不足了,满足不了你对零件的需求量!");
}
else
{
st2=DB.con.prepareStatement(sql);
st2.setString(1, Num);
st2.setString(2, Name);
st2.setString(3, ID);
st2.setString(4, Change);
st2.setFloat(5, ChangePrice);
st2.setInt(6, CNum);
st2.setFloat(7, UseTime);
st2.setFloat(8, HourMoney);
st2.setString(9, Person);
st2.setString(10, Result);
st2.setFloat(11, ChangAllMoney);
st2.setFloat(12, PersonMoney);
st2.setFloat(13, TotallMoney);
st2.executeUpdate();
JOptionPane.showMessageDialog(this, "维修信息添加成功!");
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
public void dealBtnCancle() {
try {
tfNum.setText("");
tfName.setText("");
tfID.setText("");
tfResult.setText("");
tfChange.setText("");
tfChangePrice.setText("");
tfChangeNum.setText("");
tfUseTime.setText("");
tfHourMoney.setText("");
tfPerson.setText("");
} catch (Exception e) {
e.printStackTrace();
}
}
public void run() {
while (true) {
Random rand = new Random();
int r = rand.nextInt(255);
int g = rand.nextInt(255);
int b = rand.nextInt(255);
Random rand1 = new Random();
int size = rand1.nextInt(3) + 20;
Font font = new Font("宋体", Font.BOLD, size);
Color color = new Color(r, g, b);
lbTitile.setForeground(color);
lbTitile.setFont(font);
try {
thread.sleep(500);
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -