package gui;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.regex.Pattern;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import service.StaffService;
import vo.Staff;
/**
*
* @author 王凯
* @date 2016-8-5
*
*/
public class StaffManage {
private JFrame frame;
private JLabel numLabel;
private JLabel nameLabel;
private JLabel sexLabel;
private JLabel salaryLabel;
private JLabel phoneLabel;
private JLabel deptLabel;
private JLabel dutyLabel;
private JTextField numField;
private JTextField nameField;
private JTextField sexField;
private JTextField salaryField;
private JTextField phoneField;
private JTextField deptField;
private JTextField dutyField;
private JButton addButton;
private JButton delButton;
private JButton queryButton;
private JButton updateButton;
private JButton exportButton;
public StaffManage() {
init();
addChilds();
}
private void init() {
ButtonListenerHandler listenrt = new ButtonListenerHandler();
frame = new JFrame();
frame.setSize(450, 550);
frame.setLocationRelativeTo(null);
frame.setLayout(null);
frame.setVisible(true);
frame.setTitle("员工管理");
frame.addWindowListener(new CustonWindowListener());
numLabel = new JLabel("员工编号:");
numField = new JTextField();
numLabel.setBounds(100, 40, 80, 30);
numField.setBounds(180, 40, 180, 30);
nameLabel = new JLabel("员工姓名:");
nameField = new JTextField();
nameLabel.setBounds(100, 90, 80, 30);
nameField.setBounds(180, 90, 180, 30);
sexLabel = new JLabel("员工性别:");
sexField = new JTextField();
sexLabel.setBounds(100, 140, 80, 30);
sexField.setBounds(180, 140, 180, 30);
salaryLabel = new JLabel("员工工资:");
salaryField = new JTextField();
salaryLabel.setBounds(100, 190, 80, 30);
salaryField.setBounds(180, 190, 180, 30);
phoneLabel = new JLabel("员工电话:");
phoneField = new JTextField();
phoneLabel.setBounds(100, 240, 80, 30);
phoneField.setBounds(180, 240, 180, 30);
deptLabel = new JLabel("员工部门:");
deptField = new JTextField();
deptLabel.setBounds(100, 290, 80, 30);
deptField.setBounds(180, 290, 180, 30);
dutyLabel = new JLabel("员工职务:");
dutyField = new JTextField();
dutyLabel.setBounds(100, 340, 80, 30);
dutyField.setBounds(180, 340, 180, 30);
addButton = new JButton("增加");
updateButton = new JButton("修改");
delButton = new JButton("删除");
queryButton = new JButton("查询");
exportButton = new JButton("导出");
addButton.addActionListener(listenrt);
updateButton.addActionListener(listenrt);
delButton.addActionListener(listenrt);
queryButton.addActionListener(listenrt);
exportButton.addActionListener(listenrt);
addButton.setBounds(30, 390, 60, 30);
updateButton.setBounds(110, 390, 60, 30);
delButton.setBounds(190, 390, 60, 30);
queryButton.setBounds(270, 390, 60, 30);
exportButton.setBounds(350, 390, 60, 30);
}
private void addChilds() {
frame.add(numLabel);
frame.add(nameLabel);
frame.add(sexLabel);
frame.add(salaryLabel);
frame.add(phoneLabel);
frame.add(deptLabel);
frame.add(dutyLabel);
frame.add(numField);
frame.add(nameField);
frame.add(sexField);
frame.add(salaryField);
frame.add(phoneField);
frame.add(deptField);
frame.add(dutyField);
frame.add(addButton);
frame.add(delButton);
frame.add(queryButton);
frame.add(updateButton);
frame.add(exportButton);
}
class ButtonListenerHandler implements ActionListener {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
StaffService staffService = new StaffService();
if (e.getActionCommand() == "导出") {
if (0 == staffService.exportAll())
JOptionPane.showMessageDialog(null, "导出成功", "登录成功",
JOptionPane.INFORMATION_MESSAGE);
return;
}
if (!Pattern.matches("[1-9][0-9]{3}", numField.getText())) {
JOptionPane.showMessageDialog(null, "编号填写无效", "提示",
JOptionPane.WARNING_MESSAGE);
return;
}
Staff staff = new Staff();
staff.setNum(numField.getText());
staff.setName(nameField.getText());
staff.setSex(sexField.getText());
staff.setSalary(salaryField.getText());
staff.setPhone(phoneField.getText());
staff.setDept(deptField.getText());
staff.setDuty(dutyField.getText());
switch (e.getActionCommand()) {
case "增加":
try {
if (!Pattern.matches("[1][3,4,5,7,8][0-9]{9}",
phoneField.getText())) {
JOptionPane.showMessageDialog(null, "手机号格式错误", "提示",
JOptionPane.WARNING_MESSAGE);
return;
}
if (staffService.query(staff) != null) {
JOptionPane.showMessageDialog(null, "该数据已存在", "提示",
JOptionPane.INFORMATION_MESSAGE);
return;
}
ResultSet rs = staffService.checkSalary(staff);
if (rs != null) {
JOptionPane.showMessageDialog(
null,
"该员工资在" + rs.getString("low") + "到"
+ rs.getString("high") + "之间", "提示",
JOptionPane.INFORMATION_MESSAGE);
return;
}
if (!staffService.checkDept(staff)) {
JOptionPane.showMessageDialog(null, "没有搜索到该部门", "提示",
JOptionPane.INFORMATION_MESSAGE);
return;
}
if (!staffService.checkDuty(staff)) {
JOptionPane.showMessageDialog(null, "没有搜索到该部门", "提示",
JOptionPane.INFORMATION_MESSAGE);
return;
}
if( staffService.insert(staff)>0)
JOptionPane.showMessageDialog(null, "插入成功", "提示",
JOptionPane.INFORMATION_MESSAGE);
else
JOptionPane.showMessageDialog(null, "插入失败", "提示",
JOptionPane.INFORMATION_MESSAGE);
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
break;
case "修改":
try {
if (!Pattern.matches("[1][3,4,5,7,8][0-9]{9}",
phoneField.getText())) {
JOptionPane.showMessageDialog(null, "手机号格式错误", "提示",
JOptionPane.WARNING_MESSAGE);
return;
}
ResultSet rs = staffService.checkSalary(staff);
if (rs != null) {
JOptionPane.showMessageDialog(
null,
"该员工资在" + rs.getString("low") + "到"
+ rs.getString("high") + "之间", "提示",
JOptionPane.INFORMATION_MESSAGE);
return;
}
if (!staffService.checkDept(staff)) {
JOptionPane.showMessageDialog(null, "没有搜索到该部门", "提示",
JOptionPane.INFORMATION_MESSAGE);
return;
}
if (!staffService.checkDuty(staff)) {
JOptionPane.showMessageDialog(null, "没有搜索到该职务", "提示",
JOptionPane.INFORMATION_MESSAGE);
return;
}
int result = staffService.update(staff);
if (result > 0)
JOptionPane.showMessageDialog(null, "更新成功", "提示",
JOptionPane.INFORMATION_MESSAGE);
else
JOptionPane.showMessageDialog(null, "更新失败", "提示",
JOptionPane.WARNING_MESSAGE);
} catch (SQLException e2) {
// TODO Auto-generated catch block
e2.printStackTrace();
}
break;
case "删除":
int jResult = JOptionPane.showConfirmDialog(null, "确定删除吗?",
"提示", JOptionPane.OK_CANCEL_OPTION,
JOptionPane.QUESTION_MESSAGE);
if (jResult == JOptionPane.OK_OPTION) {
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
staff.zip (58个子文件)
hr.sql 2KB
staff
.project 380B
bin
dao
DeptDao.class 2KB
AdminDao.class 1KB
DutyDao.class 2KB
DBUtil.class 2KB
StaffDao.class 3KB
vo
Admin.class 702B
Duty.class 1KB
Dept.class 863B
Staff.class 2KB
common
CustomSqlHelper.class 2KB
service
AdminService.class 430B
DutyService.class 3KB
DeptService.class 3KB
StaffService.class 4KB
gui
Login$CustomActionListener.class 2KB
DutyManage$CustonWindowListener.class 1KB
DeptManage$CustonWindowListener.class 1KB
Login$WindowHandler.class 1KB
MainManage.class 2KB
StaffManage$CustonWindowListener.class 1KB
StaffManage.class 4KB
StaffManage$ButtonListenerHandler.class 5KB
Login$keyEventListenner.class 1KB
DeptManage.class 3KB
Login.class 3KB
DutyManage.class 3KB
DeptManage$ButtonHandler.class 3KB
MainManage$ButtonHnadler.class 1KB
DutyManage$ButtonHandler.class 4KB
staff-20160805014736.xls 5KB
.settings
org.eclipse.jdt.core.prefs 598B
staff-20160805014715.xls 5KB
src
dao
DeptDao.java 2KB
DutyDao.java 2KB
StaffDao.java 3KB
DBUtil.java 1KB
AdminDao.java 657B
vo
Duty.java 626B
Admin.java 434B
Staff.java 1022B
Dept.java 489B
common
CustomSqlHelper.java 1KB
service
DutyService.java 2KB
StaffService.java 3KB
DeptService.java 2KB
AdminService.java 243B
gui
MainManage.java 2KB
DeptManage.java 7KB
StaffManage.java 10KB
Login.java 4KB
DutyManage.java 7KB
.classpath 548B
lib
poi-3.6-20091214.jar 1.47MB
zxing.jar 323KB
ojdbc14.jar 1.47MB
mysql-connector-java-5.1.38-bin.jar 961KB
共 58 条
- 1
王小北爱搬砖
- 粉丝: 34
- 资源: 28
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
前往页