Compare commits
8 Commits
| Author | SHA1 | Date |
|---|---|---|
|
|
29722d2c93 | 2 years ago |
|
|
2591bc2271 | 2 years ago |
|
|
3a57e72fd3 | 2 years ago |
|
|
47e8d582f1 | 2 years ago |
|
|
f10003b9f4 | 2 years ago |
|
|
d42028aba9 | 2 years ago |
|
|
d7f3f99f42 | 2 years ago |
|
|
82c5190acb | 2 years ago |
@ -0,0 +1,277 @@
|
||||
package com.view;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Container;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.event.MouseListener;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.JTable;
|
||||
import javax.swing.JTextField;
|
||||
|
||||
import com.controller.CarActionlyx;
|
||||
import com.utils.BackgroundImagelyx;
|
||||
import com.utils.FrameOptionlyx;
|
||||
import com.utils.MenuBarlyx;
|
||||
import com.utils.SetTablelyx;
|
||||
import com.utils.SetTablelyx;
|
||||
|
||||
public class CarViewlyx {
|
||||
JFrame main = new JFrame("Car Sale System");
|
||||
Container container = main.getContentPane();
|
||||
JButton buttonAdd, buttonDel, buttonChange, buttonReset;
|
||||
JTextField textFieldCarID, // 汽车ID
|
||||
textFieldModel, // 汽车型号
|
||||
textFieldColor, // 汽车颜色
|
||||
textFieldManuFactory, // 生产厂商
|
||||
textFieldFactoryDate, // 出厂日期
|
||||
textFieldPrice;// 价格
|
||||
JTable table;// 表格
|
||||
// 显示表格的滚动面板
|
||||
JScrollPane scrollPane;
|
||||
CarActionlyx carAction;
|
||||
|
||||
public CarViewlyx() {
|
||||
// TODO Auto-generated constructor stub
|
||||
main.setLayout(null);
|
||||
new BackgroundImagelyx(main, container, "CarBackground.jpg");
|
||||
new FrameOptionlyx(main);
|
||||
new MenuBarlyx(main);
|
||||
|
||||
// 实例化标签和文本框
|
||||
JLabel JLabelCarID = new JLabel("CarID");
|
||||
JLabelCarID.setForeground(Color.green);
|
||||
JLabelCarID.setBounds(75, 350, 100, 20);
|
||||
JTextField textFieldCarID = new JTextField();
|
||||
textFieldCarID.setBounds(175, 350, 100, 20);
|
||||
|
||||
|
||||
JLabel JLabelModel = new JLabel("Model");
|
||||
JLabelModel.setForeground(Color.green);
|
||||
JLabelModel.setBounds(350, 350, 100, 20);
|
||||
JTextField textFieldModel = new JTextField();
|
||||
textFieldModel.setBounds(450, 350, 100, 20);
|
||||
|
||||
JLabel JLabelColor = new JLabel("Color");
|
||||
JLabelColor.setForeground(Color.green);
|
||||
JLabelColor.setBounds(625, 350, 100, 20);
|
||||
JTextField textFieldColor = new JTextField();
|
||||
textFieldColor.setBounds(725, 350, 100, 20);
|
||||
|
||||
JLabel JLabelManuFactory = new JLabel("ManuFactory");
|
||||
JLabelManuFactory.setForeground(Color.green);
|
||||
JLabelManuFactory.setBounds(75, 400, 100, 20);
|
||||
JTextField textFieldManuFactory = new JTextField();
|
||||
textFieldManuFactory.setBounds(175, 400, 100, 20);
|
||||
|
||||
JLabel JLabelFactorydate = new JLabel("FactoryDate");
|
||||
JLabelFactorydate.setForeground(Color.green);
|
||||
JLabelFactorydate.setBounds(350, 400, 100, 20);
|
||||
JTextField textFieldFactoryDate = new JTextField();
|
||||
textFieldFactoryDate.setBounds(450, 400, 100, 20);
|
||||
|
||||
JLabel JLabelPrice = new JLabel("Price");
|
||||
JLabelPrice.setForeground(Color.green);
|
||||
JLabelPrice.setBounds(625, 400, 100, 20);
|
||||
JTextField textFieldPrice = new JTextField();
|
||||
textFieldPrice.setBounds(725, 400, 100, 20);
|
||||
|
||||
// 使文本框透明
|
||||
textFieldCarID.setOpaque(false);
|
||||
textFieldModel.setOpaque(false);
|
||||
textFieldColor.setOpaque(false);
|
||||
textFieldColor.setOpaque(false);
|
||||
textFieldManuFactory.setOpaque(false);
|
||||
textFieldFactoryDate.setOpaque(false);
|
||||
textFieldPrice.setOpaque(false);
|
||||
//修改输入字体颜色
|
||||
textFieldCarID.setForeground(new Color(19, 190, 196));
|
||||
textFieldModel.setForeground(new Color(19, 190, 196));
|
||||
textFieldColor.setForeground(new Color(19, 190, 196));
|
||||
textFieldManuFactory.setForeground(new Color(19, 190, 196));
|
||||
textFieldFactoryDate.setForeground(new Color(19, 190, 196));
|
||||
textFieldPrice.setForeground(new Color(19, 190, 196));
|
||||
|
||||
container.add(JLabelCarID);
|
||||
container.add(JLabelModel);
|
||||
container.add(JLabelColor);
|
||||
container.add(JLabelManuFactory);
|
||||
container.add(JLabelFactorydate);
|
||||
container.add(JLabelPrice);
|
||||
|
||||
container.add(textFieldCarID);
|
||||
container.add(textFieldModel);
|
||||
container.add(textFieldColor);
|
||||
container.add(textFieldManuFactory);
|
||||
container.add(textFieldFactoryDate);
|
||||
container.add(textFieldPrice);
|
||||
|
||||
// 实例化按钮
|
||||
buttonAdd = new JButton("Add");
|
||||
buttonAdd.setBounds(100, 480, 100, 20);
|
||||
buttonDel = new JButton("Delect");
|
||||
buttonDel.setBounds(300, 480, 100, 20);
|
||||
buttonChange = new JButton("Change");
|
||||
buttonChange.setBounds(500, 480, 100, 20);
|
||||
buttonReset = new JButton("Query");
|
||||
buttonReset.setBounds(700, 480, 100, 20);
|
||||
|
||||
//添加按钮
|
||||
container.add(buttonAdd);
|
||||
container.add(buttonDel);
|
||||
container.add(buttonChange);
|
||||
container.add(buttonReset);
|
||||
|
||||
carAction = new CarActionlyx();
|
||||
//初始化表格
|
||||
setTable();
|
||||
|
||||
//设置按钮监听
|
||||
//添加按钮
|
||||
buttonAdd.addActionListener(new ActionListener() {
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
// TODO Auto-generated method stub
|
||||
try {
|
||||
carAction.addCarInformation(textFieldCarID, textFieldModel, textFieldColor,
|
||||
textFieldManuFactory, textFieldFactoryDate, textFieldPrice);
|
||||
main.setVisible(false);
|
||||
new CarViewlyx();
|
||||
} catch (Exception e2) {
|
||||
// TODO: handle exception
|
||||
e2.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
//删除按钮
|
||||
buttonDel.addActionListener(new ActionListener() {
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
// TODO Auto-generated method stub
|
||||
try {
|
||||
carAction.delCarInformation(Integer.parseInt(textFieldCarID.getText()));
|
||||
main.setVisible(false);
|
||||
new CarViewlyx();
|
||||
} catch (Exception e2) {
|
||||
// TODO: handle exception
|
||||
}
|
||||
}
|
||||
});
|
||||
//修改按钮
|
||||
buttonChange.addActionListener(new ActionListener() {
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
try {
|
||||
carAction.changeCarInformation(textFieldCarID, textFieldModel, textFieldColor,
|
||||
textFieldManuFactory, textFieldFactoryDate, textFieldPrice);
|
||||
main.setVisible(false);
|
||||
new CarViewlyx();
|
||||
} catch (Exception e2) {
|
||||
// TODO: handle exception
|
||||
JOptionPane.showMessageDialog(null,"表中没有该数据","错误"
|
||||
, JOptionPane.PLAIN_MESSAGE);
|
||||
}
|
||||
}
|
||||
});
|
||||
//查询按钮
|
||||
buttonReset.addActionListener(new ActionListener() {
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
// TODO Auto-generated method stub
|
||||
try {
|
||||
setTable();
|
||||
main.setVisible(false);
|
||||
new CarViewlyx();
|
||||
JOptionPane.showMessageDialog(null, "数据更新成功","tips",JOptionPane.PLAIN_MESSAGE);
|
||||
} catch (Exception e1) {
|
||||
// TODO: handle exception
|
||||
JOptionPane.showMessageDialog(null, "数据更新失败","tips",JOptionPane.PLAIN_MESSAGE);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
private void setTable() {
|
||||
// TODO Auto-generated method stub
|
||||
// 列名
|
||||
String[] columnNames = { "轿车编号", "型号", "颜色", "生产厂家", "出厂日期", "价格(元)" };
|
||||
try {
|
||||
CarActionlyx carAction = new CarActionlyx();
|
||||
Object[][] results = carAction.query(columnNames);
|
||||
|
||||
table = new JTable(results, columnNames);
|
||||
scrollPane = new JScrollPane(table);
|
||||
// 设置表格
|
||||
new SetTablelyx(scrollPane,table,columnNames,main);
|
||||
|
||||
table.addMouseListener(new MouseListener() {
|
||||
|
||||
@Override
|
||||
public void mouseReleased(MouseEvent e) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mousePressed(MouseEvent e) {
|
||||
// TODO Auto-generated method stub
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseExited(MouseEvent e) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseEntered(MouseEvent e) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
// TODO Auto-generated method stub
|
||||
// String car_id, model, color, manufactory, factory_date, price;
|
||||
//
|
||||
// int selRow = table.getSelectedRow();
|
||||
//
|
||||
// car_id = table.getValueAt(selRow, 0).toString();
|
||||
// model = table.getValueAt(selRow, 1).toString();
|
||||
// color = table.getValueAt(selRow, 2).toString();
|
||||
// manufactory = table.getValueAt(selRow, 3).toString();
|
||||
// factory_date = table.getValueAt(selRow, 4).toString();
|
||||
// price = table.getValueAt(selRow, 5).toString();
|
||||
|
||||
// textFieldCarID.setText(car_id);
|
||||
// textFieldModel.setText(model);
|
||||
// textFieldColor.setText(color);
|
||||
// textFieldManuFactory.setText(manufactory);
|
||||
// textFieldFactoryDate.setText(factory_date);
|
||||
// textFieldPrice.setText(price);
|
||||
}
|
||||
});
|
||||
} catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,230 @@
|
||||
package com.view;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Container;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.event.MouseListener;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
import com.controller.GuestActionhxr;
|
||||
import com.utils.BackgroundImagelyx;
|
||||
import com.utils.FrameOptionlyx;
|
||||
import com.utils.MenuBarlyx;
|
||||
import com.utils.SetTablelyx;
|
||||
|
||||
public class GuestViewhxr {
|
||||
JFrame main = new JFrame("Car Sale System");
|
||||
Container container = main.getContentPane();
|
||||
private JScrollPane scrollPane;
|
||||
private JButton buttonAdd;
|
||||
private JButton buttonReset;
|
||||
private JButton buttonChange;
|
||||
private JButton buttonDel;
|
||||
JTable table;
|
||||
JTextField guestNameField, contactInformationField, addressField, businessRecordField;
|
||||
private GuestActionhxr guestAction;
|
||||
|
||||
public GuestViewhxr() {
|
||||
// TODO Auto-generated constructor stub
|
||||
main.setLayout(null);
|
||||
new BackgroundImagelyx(main, container, "GuestBackground.jpg");
|
||||
new FrameOptionlyx(main);
|
||||
new MenuBarlyx(main);
|
||||
// 实例化标签和文本框
|
||||
JLabel guestNameJLabel = new JLabel("GuestName");
|
||||
guestNameJLabel.setForeground(Color.green);
|
||||
guestNameJLabel.setBounds(100, 350, 125, 20);
|
||||
JTextField guestNameField = new JTextField();
|
||||
guestNameField.setBounds(225, 350, 175, 20);
|
||||
JLabel contactInformationJLabel = new JLabel("ContactInformation");
|
||||
contactInformationJLabel.setForeground(Color.green);
|
||||
contactInformationJLabel.setBounds(500, 350, 125, 20);
|
||||
JTextField contactInformationField = new JTextField();
|
||||
contactInformationField.setBounds(625, 350, 150, 20);
|
||||
JLabel addressJLabel = new JLabel("Address");
|
||||
addressJLabel.setForeground(Color.green);
|
||||
addressJLabel.setBounds(100, 400, 125, 20);
|
||||
JTextField addressField = new JTextField();
|
||||
addressField.setBounds(225, 400, 175, 20);
|
||||
JLabel businessRecordJLabel = new JLabel("BusinessRecord");
|
||||
businessRecordJLabel.setForeground(Color.green);
|
||||
businessRecordJLabel.setBounds(500, 400, 125, 20);
|
||||
JTextField businessRecordField = new JTextField();
|
||||
businessRecordField.setBounds(625, 400, 150, 20);
|
||||
|
||||
// 修改输入字体颜色
|
||||
guestNameField.setForeground(new Color(19, 190, 196));
|
||||
contactInformationField.setForeground(new Color(19, 190, 196));
|
||||
addressField.setForeground(new Color(19, 190, 196));
|
||||
businessRecordField.setForeground(new Color(19, 190, 196));
|
||||
|
||||
// 使文本框透明
|
||||
guestNameField.setOpaque(false);
|
||||
contactInformationField.setOpaque(false);
|
||||
addressField.setOpaque(false);
|
||||
businessRecordField.setOpaque(false);
|
||||
|
||||
container.add(guestNameJLabel);
|
||||
container.add(guestNameField);
|
||||
container.add(contactInformationJLabel);
|
||||
container.add(contactInformationField);
|
||||
container.add(addressJLabel);
|
||||
container.add(addressField);
|
||||
container.add(businessRecordJLabel);
|
||||
container.add(businessRecordField);
|
||||
|
||||
// 实例化按钮
|
||||
buttonAdd = new JButton("Add");
|
||||
buttonAdd.setBounds(100, 480, 100, 20);
|
||||
|
||||
buttonDel = new JButton("Delect");
|
||||
buttonDel.setBounds(300, 480, 100, 20);
|
||||
|
||||
buttonChange = new JButton("Change");
|
||||
buttonChange.setBounds(500, 480, 100, 20);
|
||||
|
||||
buttonReset = new JButton("Query");
|
||||
buttonReset.setBounds(700, 480, 100, 20);
|
||||
|
||||
|
||||
container.add(buttonAdd);
|
||||
container.add(buttonDel);
|
||||
container.add(buttonChange);
|
||||
container.add(buttonReset);
|
||||
|
||||
guestAction = new GuestActionhxr();
|
||||
//初始化表格
|
||||
setTable();
|
||||
//添加按钮监听
|
||||
//添加按钮
|
||||
buttonAdd.addActionListener(new ActionListener() {
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
// TODO Auto-generated method stub
|
||||
try {
|
||||
guestAction.addGuestInformation(guestNameField, contactInformationField, addressField,
|
||||
businessRecordField);
|
||||
main.setVisible(false);
|
||||
new GuestViewhxr();
|
||||
} catch (Exception e2) {
|
||||
// TODO: handle exception
|
||||
}
|
||||
}
|
||||
});
|
||||
//删除按钮
|
||||
buttonDel.addActionListener(new ActionListener() {
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
// TODO Auto-generated method stub
|
||||
try {
|
||||
guestAction.delGuestInformation(guestNameField.getText());
|
||||
main.setVisible(false);
|
||||
new GuestViewhxr();
|
||||
} catch (Exception e2) {
|
||||
// TODO: handle exception
|
||||
}
|
||||
}
|
||||
});
|
||||
//修改按钮
|
||||
buttonChange.addActionListener(new ActionListener() {
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
// TODO Auto-generated method stub
|
||||
try {
|
||||
guestAction.changeGuestInformation(guestNameField, contactInformationField, addressField,
|
||||
businessRecordField);
|
||||
main.setVisible(false);
|
||||
new GuestViewhxr();
|
||||
} catch (Exception e1) {
|
||||
// TODO Auto-generated catch block
|
||||
e1.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
//查询按钮
|
||||
buttonReset.addActionListener(new ActionListener() {
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
// TODO Auto-generated method stub
|
||||
try {
|
||||
setTable();
|
||||
main.setVisible(false);
|
||||
new GuestViewhxr();
|
||||
JOptionPane.showMessageDialog(null, "数据更新成功", "tips", JOptionPane.PLAIN_MESSAGE);
|
||||
} catch (Exception e1) {
|
||||
// TODO: handle exception
|
||||
JOptionPane.showMessageDialog(null, "数据更新失败", "tips", JOptionPane.PLAIN_MESSAGE);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void setTable() {
|
||||
String[] columnNames = { "姓名", "联系方式", "地址", "业务联系记录" };
|
||||
try {
|
||||
GuestActionhxr guestAction = new GuestActionhxr();
|
||||
Object[][] results = guestAction.query(columnNames);
|
||||
|
||||
table = new JTable(results, columnNames);
|
||||
scrollPane = new JScrollPane(table);
|
||||
// 设置表格
|
||||
new SetTablelyx(scrollPane, table, columnNames, main);
|
||||
|
||||
table.addMouseListener(new MouseListener() {
|
||||
|
||||
@Override
|
||||
public void mouseReleased(MouseEvent e) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mousePressed(MouseEvent e) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseExited(MouseEvent e) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseEntered(MouseEvent e) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
// TODO Auto-generated method stub
|
||||
// String guest_name, contact_inf, address, business_re;
|
||||
//
|
||||
// int selRow = table.getSelectedRow();
|
||||
//
|
||||
// guest_name = table.getValueAt(selRow, 0).toString();
|
||||
// contact_inf = table.getValueAt(selRow, 1).toString();
|
||||
// address = table.getValueAt(selRow, 2).toString();
|
||||
// business_re = table.getValueAt(selRow, 3).toString();
|
||||
//
|
||||
// guestNameField.setText(guest_name);
|
||||
// contactInformationField.setText(contact_inf);
|
||||
// addressField.setText(address);
|
||||
// businessRecordField.setText(business_re);
|
||||
}
|
||||
});
|
||||
} catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,121 @@
|
||||
package com.view;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.event.MouseListener;
|
||||
import javax.swing.*;
|
||||
import com.controller.UserActiondyh;
|
||||
import com.controller.UserActiondyh;
|
||||
import com.view.MainFrame;
|
||||
|
||||
public class Loginhxr {
|
||||
|
||||
public void loginGUi(char[] passwordStrings) {
|
||||
JFrame login = new JFrame();
|
||||
login.setTitle("Welcome login system");
|
||||
login.setSize(500, 400);
|
||||
login.setLocationRelativeTo(null);
|
||||
login.setResizable(false);
|
||||
login.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
login.setLayout(new GridLayout(3, 1));
|
||||
|
||||
JLabel jl_username = new JLabel("UserName: ", JLabel.CENTER);
|
||||
JTextField JTextFieldUser = new JTextField(JTextField.LEFT);
|
||||
JLabel jl_password = new JLabel("Password: ", JLabel.CENTER);
|
||||
JPasswordField JPasswordField = new JPasswordField(SwingConstants.LEFT);
|
||||
|
||||
jl_username.setFont(new Font("comic sans MS", Font.BOLD, 20));
|
||||
JTextFieldUser.setFont(new Font("Segoe Print", Font.BOLD, 20));
|
||||
jl_password.setFont(new Font("comic sans MS", Font.BOLD, 20));
|
||||
JPasswordField.setFont(new Font("Segoe Print", Font.BOLD, 20));
|
||||
|
||||
JButton jb_login = new JButton("Login");
|
||||
JButton jb_exit = new JButton("Exit");
|
||||
|
||||
jb_login.setFont(new Font("Segoe Print", Font.BOLD, 20));
|
||||
jb_exit.setFont(new Font("Segoe Print", Font.BOLD, 20));
|
||||
|
||||
ImageIcon bgimg = new ImageIcon("res/Welcome.jpg");
|
||||
JLabel imgLabel = new JLabel(bgimg);
|
||||
login.add(imgLabel);
|
||||
|
||||
JPanel jp1 = new JPanel();
|
||||
JPanel jp2 = new JPanel();
|
||||
jp2.setLayout(new GridLayout(2, 2, 5, 10));
|
||||
JPanel jp3 = new JPanel();
|
||||
jp3.setLayout(new FlowLayout(FlowLayout.CENTER, 100, 50));
|
||||
|
||||
jp1.add(imgLabel);
|
||||
jp2.add(jl_username);
|
||||
jp2.add(JTextFieldUser);
|
||||
jp2.add(jl_password);
|
||||
jp2.add(JPasswordField);
|
||||
jp3.add(jb_login);
|
||||
jp3.add(jb_exit);
|
||||
|
||||
login.add(jp1);
|
||||
login.add(jp2);
|
||||
login.add(jp3);
|
||||
login.setVisible(true);
|
||||
// 设置键盘监听事件
|
||||
jb_login.addActionListener(new ActionListener() {
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
// TODO Auto-generated method stub
|
||||
String username=JTextFieldUser.getText();
|
||||
String passwd = new String(JPasswordField.getPassword());
|
||||
|
||||
com.controller.UserActiondyh userAction = new UserActiondyh();
|
||||
String result = userAction.login(username,passwd);
|
||||
|
||||
if (result.equals("1")) {
|
||||
login.setVisible(false);
|
||||
new MainFrame().MainGUI();
|
||||
}else if(result.equals("2")) {
|
||||
JOptionPane.showMessageDialog(null,"用户名或密码不能为空","错误"
|
||||
,JOptionPane.PLAIN_MESSAGE);
|
||||
} else if(result.equals("3")) {
|
||||
JOptionPane.showMessageDialog(null,"用户名或密码错误","错误"
|
||||
,JOptionPane.PLAIN_MESSAGE);
|
||||
}
|
||||
}
|
||||
});
|
||||
// 退出按钮鼠标监听
|
||||
jb_exit.addMouseListener(new MouseListener() {
|
||||
|
||||
@Override
|
||||
public void mouseReleased(MouseEvent e) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mousePressed(MouseEvent e) {
|
||||
// TODO Auto-generated method stub
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseExited(MouseEvent e) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseEntered(MouseEvent e) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,246 @@
|
||||
package com.view;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Container;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.event.MouseListener;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.JTable;
|
||||
import javax.swing.JTextField;
|
||||
|
||||
import com.controller.SaleActionyzz;
|
||||
import com.utils.BackgroundImagelyx;
|
||||
import com.utils.FrameOptionlyx;
|
||||
import com.utils.FrameOptionlyx;
|
||||
import com.utils.MenuBarlyx;
|
||||
import com.utils.SetTablelyx;
|
||||
|
||||
public class SaleViewyzz {
|
||||
JFrame main = new JFrame("Car Sale System");
|
||||
Container container = main.getContentPane();
|
||||
private JScrollPane scrollPane;
|
||||
private JButton buttonReset;
|
||||
private JButton buttonChange;
|
||||
private JButton buttonDel;
|
||||
private JButton buttonAdd;
|
||||
private JTable table;
|
||||
private SaleActionyzz saleAction;
|
||||
|
||||
public SaleViewyzz() {
|
||||
// TODO Auto-generated constructor stub
|
||||
main.setLayout(null);
|
||||
new BackgroundImagelyx(main, container, "SaleBackground.jpg");
|
||||
new FrameOptionlyx(main);
|
||||
new MenuBarlyx(main);
|
||||
|
||||
// 实例化标签和文本框
|
||||
JLabel saleDateJLabel = new JLabel("SaleDate");
|
||||
saleDateJLabel.setForeground(Color.green);
|
||||
saleDateJLabel.setBounds(75, 350, 100, 20);
|
||||
JTextField saleDateField = new JTextField();
|
||||
saleDateField.setBounds(175, 350, 100, 20);
|
||||
JLabel carTypeJLabel = new JLabel("CarType");
|
||||
carTypeJLabel.setForeground(Color.green);
|
||||
carTypeJLabel.setBounds(350, 350, 100, 20);
|
||||
JTextField carTypeField = new JTextField();
|
||||
carTypeField.setBounds(450, 350, 100, 20);
|
||||
JLabel colorJLabel = new JLabel("Color");
|
||||
colorJLabel.setForeground(Color.green);
|
||||
colorJLabel.setBounds(625, 350, 100, 20);
|
||||
JTextField colorField = new JTextField();
|
||||
colorField.setBounds(725, 350, 100, 20);
|
||||
JLabel numberJLabel = new JLabel("Number");
|
||||
numberJLabel.setForeground(Color.green);
|
||||
numberJLabel.setBounds(150, 400, 125, 20);
|
||||
JTextField numberField = new JTextField();
|
||||
numberField.setBounds(225, 400, 175, 20);
|
||||
JLabel handlerJLabel = new JLabel("Handler");
|
||||
handlerJLabel.setForeground(Color.green);
|
||||
handlerJLabel.setBounds(500, 400, 125, 20);
|
||||
JTextField handlerField = new JTextField();
|
||||
handlerField.setBounds(625, 400, 150, 20);
|
||||
|
||||
// 修改输入文字颜色
|
||||
saleDateField.setForeground(new Color(12, 239, 34));
|
||||
carTypeField.setForeground(new Color(12, 239, 34));
|
||||
colorField.setForeground(new Color(12, 239, 34));
|
||||
numberField.setForeground(new Color(12, 239, 34));
|
||||
handlerField.setForeground(new Color(12, 239, 34));
|
||||
|
||||
// 使文本框透明
|
||||
saleDateField.setOpaque(false);
|
||||
carTypeField.setOpaque(false);
|
||||
colorField.setOpaque(false);
|
||||
numberField.setOpaque(false);
|
||||
handlerField.setOpaque(false);
|
||||
|
||||
container.add(saleDateJLabel);
|
||||
container.add(saleDateField);
|
||||
container.add(carTypeJLabel);
|
||||
container.add(carTypeField);
|
||||
container.add(colorJLabel);
|
||||
container.add(colorField);
|
||||
container.add(numberJLabel);
|
||||
container.add(numberField);
|
||||
container.add(handlerJLabel);
|
||||
container.add(handlerField);
|
||||
|
||||
// 实例化按钮
|
||||
buttonAdd = new JButton("Add");
|
||||
buttonAdd.setBounds(100, 480, 100, 20);
|
||||
|
||||
buttonDel = new JButton("Delect");
|
||||
buttonDel.setBounds(300, 480, 100, 20);
|
||||
|
||||
buttonChange = new JButton("Change");
|
||||
buttonChange.setBounds(500, 480, 100, 20);
|
||||
|
||||
buttonReset = new JButton("Query");
|
||||
buttonReset.setBounds(700, 480, 100, 20);
|
||||
|
||||
container.add(buttonAdd);
|
||||
container.add(buttonDel);
|
||||
container.add(buttonChange);
|
||||
container.add(buttonReset);
|
||||
|
||||
saleAction = new SaleActionyzz();
|
||||
// 初始化表格
|
||||
setTable();
|
||||
// 添加按钮监听
|
||||
// 添加按钮
|
||||
buttonAdd.addActionListener(new ActionListener() {
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
// TODO Auto-generated method stub
|
||||
try {
|
||||
saleAction.addSaleInformation(saleDateField, carTypeField, colorField, numberField, handlerField);
|
||||
main.setVisible(false);
|
||||
new SaleViewyzz();
|
||||
} catch (Exception e2) {
|
||||
// TODO: handle exception
|
||||
}
|
||||
}
|
||||
});
|
||||
// 删除按钮
|
||||
buttonDel.addActionListener(new ActionListener() {
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
// TODO Auto-generated method stub
|
||||
// System.out.printf(saleDateField.getText()+handlerField.getText());
|
||||
try {
|
||||
saleAction.delSaleInformation(saleDateField.getText());
|
||||
main.setVisible(false);
|
||||
new SaleViewyzz();
|
||||
} catch (Exception e2) {
|
||||
// TODO: handle exception
|
||||
}
|
||||
}
|
||||
});
|
||||
// 修改按钮
|
||||
buttonChange.addActionListener(new ActionListener() {
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
// TODO Auto-generated method stub
|
||||
try {
|
||||
saleAction.changeSaleInformation(saleDateField, carTypeField, colorField, numberField,
|
||||
handlerField);
|
||||
main.setVisible(false);
|
||||
new SaleViewyzz();
|
||||
} catch (Exception e2) {
|
||||
// TODO: handle exception
|
||||
}
|
||||
}
|
||||
});
|
||||
// 查询按钮
|
||||
buttonReset.addActionListener(new ActionListener() {
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
// TODO Auto-generated method stub
|
||||
try {
|
||||
setTable();
|
||||
main.setVisible(false);
|
||||
new SaleViewyzz();
|
||||
JOptionPane.showMessageDialog(null, "数据更新成功", "tips", JOptionPane.PLAIN_MESSAGE);
|
||||
} catch (Exception e1) {
|
||||
// TODO: handle exception
|
||||
JOptionPane.showMessageDialog(null, "数据更新失败", "tips", JOptionPane.PLAIN_MESSAGE);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void setTable() {
|
||||
// TODO Auto-generated method stub
|
||||
String[] columnNames = { "销售日期", "轿车类型", "颜色", "数量", "经手人" };
|
||||
try {
|
||||
SaleActionyzz saleAction = new SaleActionyzz();
|
||||
Object[][] results = saleAction.query(columnNames);
|
||||
|
||||
table = new JTable(results, columnNames);
|
||||
scrollPane = new JScrollPane(table);
|
||||
// 设置表格
|
||||
new SetTablelyx(scrollPane, table, columnNames, main);
|
||||
|
||||
table.addMouseListener(new MouseListener() {
|
||||
|
||||
@Override
|
||||
public void mouseReleased(MouseEvent e) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mousePressed(MouseEvent e) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseExited(MouseEvent e) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseEntered(MouseEvent e) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
// TODO Auto-generated method stub
|
||||
// String sale_date, car_type, color, number, handler;
|
||||
//
|
||||
// int selRow = table.getSelectedRow();
|
||||
//
|
||||
// sale_date = table.getValueAt(selRow, 0).toString();
|
||||
// car_type = table.getValueAt(selRow, 1).toString();
|
||||
// color = table.getValueAt(selRow, 2).toString();
|
||||
// number = table.getValueAt(selRow, 3).toString();
|
||||
// handler = table.getValueAt(selRow, 4).toString();
|
||||
//
|
||||
// saleDateField.setText(sale_date);
|
||||
// carTypeField.setText(car_type);
|
||||
// colorField.setText(color);
|
||||
// numberField.setText(number);
|
||||
// handlerField.setText(handler);
|
||||
}
|
||||
});
|
||||
} catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,27 @@
|
||||
package com.controller;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.dao.UserDaodyh;
|
||||
import com.entity.Userdyh;
|
||||
|
||||
public class UserActiondyh {
|
||||
public String login(String username, String passwd) {
|
||||
String result = null;
|
||||
try {
|
||||
List<Userdyh> userList = UserDaodyh.query();
|
||||
for (Userdyh user : userList) {
|
||||
if (user.getUserName().equals(username) && user.getPassword().equals(passwd)) {
|
||||
result = "1";
|
||||
} else if(username.equals("") || passwd.equals("")) {
|
||||
result = "2";
|
||||
}
|
||||
else result="3";
|
||||
}
|
||||
} catch (Exception e) {
|
||||
|
||||
e.printStackTrace();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,80 @@
|
||||
package com.controller;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.swing.JTable;
|
||||
import javax.swing.JTextField;
|
||||
|
||||
import com.dao.WorkerDaodyh;
|
||||
import com.entity.Workerdyh;
|
||||
|
||||
public class WorkerActiondyh {
|
||||
//添加员工信息
|
||||
public void addWorkerInformation(JTextField workerIDField,
|
||||
JTextField nameField,
|
||||
JTextField sexField,
|
||||
JTextField ageField,
|
||||
JTextField originField,
|
||||
JTextField educationField) throws Exception{
|
||||
|
||||
WorkerDaodyh workerDao = new WorkerDaodyh();
|
||||
Workerdyh worker=new Workerdyh();
|
||||
|
||||
worker.setWorker_id(Integer.parseInt(workerIDField.getText()));
|
||||
worker.setName(nameField.getText());
|
||||
worker.setSex(sexField.getText());
|
||||
worker.setAge(ageField.getText());
|
||||
worker.setOrigin(originField.getText());
|
||||
worker.setEducation(educationField.getText());
|
||||
|
||||
workerDao.addWorker(worker);
|
||||
|
||||
}
|
||||
//删除员工信息
|
||||
public void delWorkerInformation(int worker_id) throws Exception {
|
||||
WorkerDaodyh workerDao = new WorkerDaodyh();
|
||||
workerDao.delWorker(worker_id);
|
||||
}
|
||||
//修改员工信息
|
||||
public void changeWorkerinformation(
|
||||
JTextField nameField,
|
||||
JTextField sexField,
|
||||
JTextField ageField,
|
||||
JTextField originField,
|
||||
JTextField educationField, JTable table)throws Exception {
|
||||
WorkerDaodyh workerDao = new WorkerDaodyh();
|
||||
Workerdyh worker =new Workerdyh();
|
||||
int selRow = table.getSelectedRow();
|
||||
|
||||
int worker_id= Integer.parseInt(table.getValueAt(selRow, 0).toString());
|
||||
worker.setWorker_id(worker_id);
|
||||
worker.setName(nameField.getText());
|
||||
worker.setSex(sexField.getText());
|
||||
worker.setAge(ageField.getText());
|
||||
worker.setOrigin(originField.getText());
|
||||
worker.setEducation(educationField.getText());
|
||||
|
||||
workerDao.changeWorker(worker);
|
||||
|
||||
}
|
||||
//查询表信息并放入二维数组中保存
|
||||
public Object[][] query(String[] columnNames) throws Exception{
|
||||
// TODO Auto-generated method stub
|
||||
WorkerDaodyh workerDao = new WorkerDaodyh();
|
||||
List<Workerdyh> list = workerDao.query();
|
||||
Object[][] results= new Object[list.size()][columnNames.length];
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
Workerdyh worker= (Workerdyh)list.get(i);
|
||||
|
||||
results[i][0] = worker.getWorker_id();
|
||||
results[i][1] = worker.getName();
|
||||
results[i][2]=worker.getSex();
|
||||
results[i][3]=worker.getAge();
|
||||
results[i][4]=worker.getOrigin();
|
||||
results[i][5]=worker.getEducation();
|
||||
|
||||
|
||||
}
|
||||
return results;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in new issue