企业信息管理系统.zip
立即下载
资源介绍:
企业信息管理系统.zip
package com.ynou.view;
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import java.awt.Font;
import javax.swing.JTextField;
import javax.swing.JButton;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
import com.ynou.bean.Employee;
import com.ynou.dao.EmployeeDao;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.awt.event.ActionEvent;
import java.awt.Color;
public class MainFrame extends JFrame {
private JPanel contentPane;
private JTextField textField;
private JTable table;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
MainFrame frame = new MainFrame();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public MainFrame() {
setFont(new Font("华文行楷", Font.BOLD, 12));
setTitle("\u4EBA\u4E8B\u4FE1\u606F\u7BA1\u7406");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 1021, 689);
contentPane = new JPanel();
contentPane.setForeground(new Color(193, 173, 245));
contentPane.setBackground(new Color(235, 243, 175));
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
JLabel lblNewLabel = new JLabel("\u5458\u5DE5\u4FE1\u606F\u7BA1\u7406");
lblNewLabel.setForeground(new Color(175, 167, 252));
lblNewLabel.setFont(new Font("华文楷体", Font.BOLD, 52));
lblNewLabel.setBounds(311, 58, 402, 74);
contentPane.add(lblNewLabel);
JLabel lblNewLabel_1 = new JLabel("\u8BF7\u8F93\u5165\u5458\u5DE5\u59D3\u540D\u5173\u952E\u5B57\uFF1A");
lblNewLabel_1.setForeground(new Color(251, 185, 168));
lblNewLabel_1.setFont(new Font("华文楷体", Font.PLAIN, 36));
lblNewLabel_1.setBounds(10, 181, 420, 64);
contentPane.add(lblNewLabel_1);
textField = new JTextField();
textField.setBackground(new Color(193, 224, 186));
textField.setBounds(402, 189, 311, 45);
contentPane.add(textField);
textField.setColumns(10);
JScrollPane scrollPane = new JScrollPane();
scrollPane.setBounds(31, 255, 816, 190);
contentPane.add(scrollPane);
JButton btnNewButton = new JButton("\u67E5\u8BE2");
btnNewButton.setForeground(new Color(255, 164, 166));
btnNewButton.setBackground(new Color(206, 222, 236));
btnNewButton.setFont(new Font("华文行楷", Font.PLAIN, 28));
btnNewButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
//查询按钮点击事件
//1.获取输入框中得姓名关键字
String key=textField.getText();
//2.调用EmployeeDao里面得根据姓名关键字查
EmployeeDao dao=new EmployeeDao();
ArrayList list=dao.selectByKey(key);
//3.把list数据转二维数组然后放表格(复制下面全查得)
//2.把list转成二维数据
Object[][] datas=new Object[list.size()][5];
//3.把list数据传给datas
for(int i=0;i<=list.size()-1;i++) {
datas[i][0]=list.get(i).getEmpId();
datas[i][1]=list.get(i).getEmpName();
datas[i][2]=list.get(i).getEmpSex();
datas[i][3]=list.get(i).getEmpPhone();
datas[i][4]=list.get(i).getEmpAddress();
}
table = new JTable();
table.setForeground(new Color(0, 0, 0));
table.setBackground(new Color(241, 238, 205));
table.setFont(new Font("华文楷体", Font.PLAIN, 20));
table.setModel(new DefaultTableModel(
datas,
new String[] {
"\u5458\u5DE5\u5E8F\u53F7", "\u5458\u5DE5\u59D3\u540D", "\u5458\u5DE5\u6027\u522B", "\u5458\u5DE5\u624B\u673A", "\u5458\u5DE5\u5730\u5740"
}
));
scrollPane.setViewportView(table);
}
});
btnNewButton.setBounds(750, 191, 97, 35);
contentPane.add(btnNewButton);
//准备表格里得数据
//1.调用EmployeeDao里面得全查
EmployeeDao dao=new EmployeeDao();
ArrayList list=dao.selectAll();
//2.把list转成二维数据
Object[][] datas=new Object[list.size()][5];
//3.把list数据传给datas
for(int i=0;i<=list.size()-1;i++) {
datas[i][0]=list.get(i).getEmpId();
datas[i][1]=list.get(i).getEmpName();
datas[i][2]=list.get(i).getEmpSex();
datas[i][3]=list.get(i).getEmpPhone();
datas[i][4]=list.get(i).getEmpAddress();
}
table = new JTable();
table.setForeground(new Color(0, 0, 0));
table.setBackground(new Color(241, 238, 205));
table.setFont(new Font("华文楷体", Font.PLAIN, 20));
table.setModel(new DefaultTableModel(
datas,
new String[] {
"\u5458\u5DE5\u5E8F\u53F7", "\u5458\u5DE5\u59D3\u540D", "\u5458\u5DE5\u6027\u522B", "\u5458\u5DE5\u624B\u673A", "\u5458\u5DE5\u5730\u5740"
}
));
scrollPane.setViewportView(table);
JButton btnNewButton_1 = new JButton("\u5220\u9664\u5458\u5DE5");
btnNewButton_1.setForeground(new Color(255, 164, 166));
btnNewButton_1.setBackground(new Color(196, 208, 215));
btnNewButton_1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
//删除按钮得点击事件
int row=table.getSelectedRow();//获取选中得行号
if(row==-1) {
JOptionPane.showMessageDialog(null, "请至少选择一个员工进行删除!");
}else {
//获取这一行得员工的编号
int empId=(int) table.getValueAt(row, 0);
EmployeeDao dao1=new EmployeeDao();
int jg=dao1.deleteById(empId);
if(jg>=1) {
JOptionPane.showMessageDialog(null, "删除成功");
dispose();//关闭当前页面
new MainFrame().setVisible(true);//打开页面
}else {
JOptionPane.showMessageDialog(null, "删除失败");
}
}
}
});
btnNewButton_1.setFont(new Font("华文行楷", Font.PLAIN, 26));
btnNewButton_1.setBounds(672, 582, 186, 47);
contentPane.add(btnNewButton_1);
JButton btnNewButton_2 = new JButton("\u65B0\u589E");
btnNewButton_2.setBackground(new Color(243, 184, 194));
btnNewButton_2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
dispose();
new AddFrame().setVisible(true);
}
});
btnNewButton_2.setForeground(new Color(95, 87, 236));
btnNewButton_2.setFont(new Font("华文行楷", Font.BOLD, 24));
btnNewButton_2.setBounds(447, 582, 172, 43);
contentPane.add(btnNewButton_2);
}
}