1 package test_33_1; 2 3 import java.text.DecimalFormat; 4 5 /** 6 * 职工类 7 */ 8 public class Staff { 9 10 /** 工号 */ 11 private String code; 12 /** 密码 */ 13 private String password; 14 /** 姓名 */ 15 private String name; 16 /** 职位 */ 17 private String position; 18 /** 编号 */ 19 private int id; 20 /** 编号生成 */ 21 private static int idCode = 1; 22 23 /** 24 * 无参构造方法 25 */ 26 public Staff() { 27 28 } 29 30 /** 31 * 带参构造方法 32 * 33 * @param name 姓名 34 * @param password 密码 35 * @param position 职位 36 */ 37 public Staff(String name, String password, String position) { 38 this.id = idCode; 39 this.code = new DecimalFormat("000").format(id); 40 this.name = name; 41 this.password = password; 42 this.position = position; 43 idCode++; 44 } 45 46 /** 47 * 获取姓名 48 * 49 * @return name 姓名 50 */ 51 public String getName() { 52 return name; 53 } 54 55 /** 56 * 获取密码 57 * 58 * @return password 密码 59 */ 60 public String getPassword() { 61 return password; 62 } 63 64 /** 65 * 设置密码 66 * 67 * @param password 密码 68 */ 69 public void setPassword(String password) { 70 this.password = password; 71 } 72 73 /** 74 * 获取职位 75 * 76 * @return position 职位 77 */ 78 public String getPosition() { 79 return position; 80 } 81 82 /** 83 * 设置职位 84 * 85 * @param position 职位 86 */ 87 public void setPosition(String position) { 88 this.position = position; 89 } 90 91 /** 92 * 获取工号 93 * 94 * @return code 工号 95 */ 96 public String getCode() { 97 return code; 98 } 99 100 /** 101 * 获取编号 102 * 103 * @return id 编号 104 */ 105 public int getId() { 106 return id; 107 } 108 109 }
1 package test_33_1; 2 3 import java.text.DecimalFormat; 4 import java.text.SimpleDateFormat; 5 import java.util.Date; 6 7 /** 8 * 货物类 9 */ 10 public class Package { 11 12 /** 取货码 */ 13 private String code; 14 /** 收件人 */ 15 private String consignee; 16 /** 收件人电话 */ 17 private String phone; 18 /** 入库时间 */ 19 private String inDate; 20 /** 出库时间 */ 21 private String outDate; 22 /** 取件人 */ 23 private String consigner; 24 /** 经办人 */ 25 private String agent; 26 /** 编号 */ 27 private int id; 28 /** 编号生成器 */ 29 private static int idCode; 30 31 /** 32 * 无参构造方法 33 */ 34 public Package() { 35 36 } 37 38 /** 39 * 带参构造方法 40 * 41 * @param code 取货码 42 * @param consignee 收件人 43 * @param phone 收件人电话 44 * @param agent 经办人 45 */ 46 public Package(String consignee, String phone) { 47 this.id = idCode; 48 this.code = new DecimalFormat("00000").format(id); 49 this.consignee = consignee; 50 this.phone = phone; 51 this.inDate = getNowDate(); 52 this.outDate = "未取货"; 53 this.consigner = "无"; 54 this.agent = "无"; 55 56 idCode++; 57 } 58 59 /** 60 * 获取取货码 61 * 62 * @return code 取货码 63 */ 64 public String getCode() { 65 return code; 66 } 67 68 /** 69 * 获取收件人 70 * 71 * @return consignee 收件人 72 */ 73 public String getConsignee() { 74 return consignee; 75 } 76 77 /** 78 * 获取收件人电话 79 * 80 * @return phone 收件人电话 81 */ 82 public String getPhone() { 83 return phone; 84 } 85 86 /** 87 * 获取入库时间 88 * 89 * @return inDate 入库时间 90 */ 91 public String getInDate() { 92 return inDate; 93 } 94 95 /** 96 * 获取出库时间 97 * 98 * @return outDate 出库时间 99 */ 100 public String getOutDate() { 101 return outDate; 102 } 103 104 /** 105 * 设置出库时间 106 * 107 * @param outDate 出库时间 108 */ 109 public void setOutDate() { 110 this.outDate = getNowDate(); 111 } 112 113 /** 114 * 获取取件人 115 * 116 * @return consigner 取件人 117 */ 118 public String getConsigner() { 119 return consigner; 120 } 121 122 /** 123 * 设置取件人 124 * 125 * @param consigner 取件人 126 */ 127 public void setConsigner(String consigner) { 128 this.consigner = consigner; 129 } 130 131 /** 132 * 获取经办人 133 * 134 * @return agent 经办人 135 */ 136 public String getAgent() { 137 return agent; 138 } 139 140 /** 141 * 设置经办人 142 * 143 * @param agent 经办人 144 */ 145 public void setAgent(String agent) { 146 this.agent = agent; 147 } 148 149 /** 150 * 获取当前时间 151 * 152 * @return 当前时间 153 */ 154 private String getNowDate() { 155 156 Date date = new Date(); 157 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); 158 159 return sdf.format(date); 160 } 161 162 /** 163 * 获取编号 164 * 165 * @return id 编号 166 */ 167 public int getId() { 168 return id; 169 } 170 171 }
1 package test_33_1; 2 3 /** 4 * 员工服务组件类 5 */ 6 public class StaffService { 7 8 /** 员工数组 */ 9 private static Staff[] staffs = new Staff[10]; 10 /** 员工数 */ 11 private static int staffNum; 12 13 static { 14 15 staffs[0] = (new Staff("Joker", "111", "管理员")); 16 staffs[1] = (new Staff("Navi", "222", "管理员")); 17 staffs[2] = (new Staff("Skull", "333", "职员")); 18 staffs[3] = (new Staff("Violet", "444", "职员")); 19 staffs[4] = (new Staff("Fox", "555", "职员")); 20 staffs[5] = (new Staff("Noir", "666", "职员")); 21 staffNum = 6; 22 23 } 24 25 /** 26 * 登陆 27 * 28 * @param code 工号 29 * @param password 密码 30 * @return 登陆员工 31 */ 32 public Staff login(String code, String password) { 33 34 for (int i = 0; i < staffNum; i++) { 35 if (staffs[i].getCode().equals(code) 36 && staffs[i].getPassword().equals(password)) { 37 return staffs[i]; 38 } 39 } 40 41 return null; 42 } 43 44 /** 45 * 修改密码 46 * 47 * @param staff 员工 48 * @param oldPwd 旧密码 49 * @param newPwd 新密码 50 * @param rePwd 确认新密码 51 * @return 验证信息 52 */ 53 public String updatePwd(Staff staff, String oldPwd, String newPwd, 54 String rePwd) { 55 56 String str = ""; 57 58 if (oldPwd.equals(staff.getPassword()) == false) { 59 str += "旧密码错误\n"; 60 } 61 62 if ("".equals(newPwd) || "".equals(rePwd)) { 63 str += "密码不能为空\n"; 64 } 65 66 if (newPwd.equals(rePwd) == false) { 67 str += "两次密码不一致\n"; 68 } 69 70 if ("".equals(str)) { 71 staff.setPassword(newPwd); 72 return ""; 73 } else { 74 return str; 75 } 76 } 77 78 /** 79 * 获取员工数组 80 * 81 * @return staffs 员工数组 82 */ 83 public Staff[] getStaffs() { 84 return staffs; 85 } 86 87 /** 88 * 设置员工数组 89 * 90 * @param staffs 员工数组 91 */ 92 public void setStaffs(Staff[] staffs) { 93 StaffService.staffs = staffs; 94 } 95 96 /** 97 * 获取员工数 98 * 99 * @return staffNum 员工数 100 */ 101 public int getStaffNum() { 102 return staffNum; 103 } 104 105 /** 106 * 设置员工数 107 * 108 * @param staffNum 员工数 109 */ 110 public void setStaffNum(int staffNum) { 111 StaffService.staffNum = staffNum; 112 } 113 114 }
1 package test_33_1; 2 3 import java.awt.event.ActionEvent; 4 import java.awt.event.ActionListener; 5 6 import javax.swing.JFrame; 7 import javax.swing.JLabel; 8 import javax.swing.JOptionPane; 9 10 import com.lovo.netCRM.component.LovoButton; 11 12 /** 13 * 欢迎窗体类 14 */ 15 public class WelcomeMenuFrame extends JFrame { 16 17 /** 18 * 无参构造方法 19 */ 20 public WelcomeMenuFrame() { 21 22 setLayout(null); 23 24 init(); 25 26 setSize(400, 300); 27 setDefaultCloseOperation(3); 28 setVisible(true); 29 setLocationRelativeTo(null); 30 } 31 32 /** 33 * 默认 34 */ 35 private void init() { 36 37 JLabel titleLabel = new JLabel("欢迎使用管理系统"); 38 titleLabel.setBounds(120, 55, 180, 20); 39 this.add(titleLabel); 40 41 LovoButton loginButton = new LovoButton("登陆系统", 150, 120, this); 42 LovoButton exitButton = new LovoButton("退出系统", 150, 180, this); 43 44 loginButton.addActionListener(new ActionListener() { 45 46 @Override 47 public void actionPerformed(ActionEvent e) { 48 49 new LoginFrame(); 50 dispose(); 51 } 52 }); 53 54 exitButton.addActionListener(new ActionListener() { 55 56 @Override 57 public void actionPerformed(ActionEvent e) { 58 59 JOptionPane.showMessageDialog(null, "已退出系统"); 60 System.exit(0); 61 } 62 }); 63 64 } 65 66 }
1 package test_33_1; 2 3 import java.awt.event.ActionEvent; 4 import java.awt.event.ActionListener; 5 6 import javax.swing.JFrame; 7 import javax.swing.JOptionPane; 8 9 import com.lovo.netCRM.component.LovoButton; 10 import com.lovo.netCRM.component.LovoTxt; 11 12 /** 13 * 登陆窗体类 14 */ 15 public class LoginFrame extends JFrame { 16 17 /** 服务组件 */ 18 private StaffService service = new StaffService(); 19 /** 工号文本框 */ 20 private LovoTxt codeTxt = new LovoTxt("工号", 90, 90, this); 21 /** 密码文本框 */ 22 private LovoTxt passwordTxt = new LovoTxt("密码", 90, 150, this); 23 /** 登陆计数 */ 24 private int count = 3; 25 26 /** 27 * 无参构造方法 28 */ 29 public LoginFrame() { 30 31 setLayout(null); 32 33 init(); 34 35 setSize(400, 350); 36 setDefaultCloseOperation(3); 37 setVisible(true); 38 setLocationRelativeTo(null); 39 } 40 41 /** 42 * 默认 43 */ 44 private void init() { 45 LovoButton loginButton = new LovoButton("登陆", 50, 210, this); 46 LovoButton cancelButton = new LovoButton("取消", 250, 210, this); 47 48 loginButton.addActionListener(new ActionListener() { 49 50 @Override 51 public void actionPerformed(ActionEvent e) { 52 53 loginStaff(); 54 } 55 }); 56 57 cancelButton.addActionListener(new ActionListener() { 58 59 @Override 60 public void actionPerformed(ActionEvent e) { 61 62 new WelcomeMenuFrame(); 63 dispose(); 64 } 65 }); 66 } 67 68 /** 69 * 登陆 70 */ 71 private void loginStaff() { 72 73 Staff staff = service.login(codeTxt.getText(), passwordTxt.getText()); 74 75 if ("".equals(codeTxt.getText()) || "".equals(passwordTxt.getText())) { 76 JOptionPane.showMessageDialog(null, "请输入工号和密码"); 77 return; 78 } 79 80 if ("管理员".equals(staff.getPosition())) { 81 new AdminMenuFrame(staff); 82 dispose(); 83 return; 84 } else if ("职员".equals(staff.getPosition())) { 85 new EmployeeMenuFrame(staff); 86 dispose(); 87 return; 88 } else { 89 JOptionPane.showMessageDialog(null, "工号或密码错误"); 90 count--; 91 } 92 93 if (count == 0) { 94 JOptionPane.showMessageDialog(null, "非法用户"); 95 System.exit(0); 96 } 97 } 98 99 }
1 package test_33_1; 2 3 /** 4 * 管理员服务组件类 5 */ 6 public class AdminService extends StaffService { 7 8 /** 被选员工数 */ 9 private int selected; 10 11 /** 12 * 添加员工 13 * 14 * @param staff 员工 15 */ 16 public void add(Staff staff) { 17 18 if (getStaffs().length == getStaffNum()) { 19 extendArr(); 20 } 21 22 getStaffs()[getStaffNum()] = staff; 23 setStaffNum(getStaffNum() + 1); 24 } 25 26 /** 27 * 扩展数组 28 */ 29 private void extendArr() { 30 31 Staff[] newArr = new Staff[10 + getStaffNum()]; 32 33 System.arraycopy(getStaffs(), 0, newArr, 0, getStaffNum()); 34 35 setStaffs(newArr); 36 37 } 38 39 /** 40 * 删除员工 41 * 42 * @param id 编号 43 */ 44 public void del(int id) { 45 46 int index = findIndexById(id); 47 48 for (int i = index; i < getStaffNum() - 1; i++) { 49 getStaffs()[i] = getStaffs()[i + 1]; 50 } 51 52 setStaffNum(getStaffNum() - 1); 53 } 54 55 /** 56 * 修改员工职位 57 * 58 * @param id 编号 59 * @param position 职位 60 */ 61 public void updatePosition(int id, String position) { 62 63 int index = findIndexById(id); 64 65 getStaffs()[index].setPosition(position); 66 } 67 68 /** 69 * 按照字段查询 70 * 71 * @param field 字段 72 * @param info 查询信息 73 * @return 被查询到的员工数组 74 */ 75 public Staff[] find(String field, String info) { 76 77 Staff[] newArr = new Staff[getStaffNum()]; 78 selected = 0; 79 80 if ("工号".equals(field)) { 81 for (int i = 0; i < getStaffNum(); i++) { 82 if (getStaffs()[i].getCode().indexOf(info) != -1) { 83 newArr[selected] = getStaffs()[i]; 84 selected++; 85 } 86 } 87 } 88 89 if ("姓名".equals(field)) { 90 for (int i = 0; i < getStaffNum(); i++) { 91 if (getStaffs()[i].getName().indexOf(info) != -1) { 92 newArr[selected] = getStaffs()[i]; 93 selected++; 94 } 95 } 96 } 97 98 if ("职位".equals(field)) { 99 for (int i = 0; i < getStaffNum(); i++) { 100 if (getStaffs()[i].getPosition().indexOf(info) != -1) { 101 newArr[selected] = getStaffs()[i]; 102 selected++; 103 } 104 } 105 } 106 107 return newArr; 108 } 109 110 /** 111 * 根据编号获取员工 112 * 113 * @param id 编号 114 * @return 员工 115 */ 116 public Staff get(int id) { 117 118 int index = findIndexById(id); 119 120 return getStaffs()[index]; 121 } 122 123 /** 124 * 根据编号查询下标 125 * 126 * @param id 编号 127 * @return 下标 128 */ 129 private int findIndexById(int id) { 130 131 for (int i = 0; i < getStaffNum(); i++) { 132 if (id == getStaffs()[i].getId()) { 133 return i; 134 } 135 } 136 137 return -1; 138 } 139 140 /** 141 * 获取被选员工数 142 * 143 * @return selected 被选员工数 144 */ 145 public int getSelected() { 146 return selected; 147 } 148 149 }
1 package test_33_1; 2 3 import java.awt.event.ActionEvent; 4 import java.awt.event.ActionListener; 5 6 import javax.swing.JFrame; 7 import javax.swing.JOptionPane; 8 9 import com.lovo.netCRM.component.LovoButton; 10 import com.lovo.netCRM.component.LovoComboBox; 11 import com.lovo.netCRM.component.LovoTable; 12 import com.lovo.netCRM.component.LovoTitlePanel; 13 import com.lovo.netCRM.component.LovoTxt; 14 15 /** 16 * 管理员主窗体类 17 */ 18 public class AdminMenuFrame extends JFrame { 19 20 /** 管理员服务组件 */ 21 private AdminService service = new AdminService(); 22 /** 当前登陆用户 */ 23 private Staff staff; 24 /** 员工信息表 */ 25 private LovoTable table = new LovoTable(this, 26 new String[] {"工号", "姓名", "职位"}, 27 new String[] {"code", "name", "position"}, "id"); 28 /** 字段下拉框 */ 29 private LovoComboBox<String> fieldBox; 30 /** 信息文本框 */ 31 private LovoTxt infoTxt; 32 33 /** 34 * 无参构造方法 35 */ 36 public AdminMenuFrame() { 37 38 } 39 40 /** 41 * 带参构造方法 42 * 43 * @param staff 登陆员工 44 */ 45 public AdminMenuFrame(Staff staff) { 46 47 setLayout(null); 48 49 this.staff = staff; 50 init(); 51 52 setSize(820, 650); 53 setDefaultCloseOperation(3); 54 setVisible(true); 55 setLocationRelativeTo(null); 56 } 57 58 /** 59 * 默认 60 */ 61 private void init() { 62 63 table.setSizeAndLocation(20, 20, 760, 250); 64 refresh(); 65 66 LovoButton addButton = new LovoButton("添加", 20, 350, this); 67 LovoButton updateButton = new LovoButton("修改", 220, 350, this); 68 LovoButton delButton = new LovoButton("删除", 20, 420, this); 69 LovoButton refreshButton = new LovoButton("显示全部", 220, 420, this); 70 LovoButton updatePwdButton = new LovoButton("修改密码", 20, 490, this); 71 LovoButton logOutButton = new LovoButton("注销", 220, 490, this); 72 73 LovoTitlePanel panel = new LovoTitlePanel("查找员工", 400, 330, 380, 220, this); 74 fieldBox = new LovoComboBox<>("查询字段", new String[] {"工号", "姓名", "职位"}, 60, 60, panel); 75 infoTxt = new LovoTxt("查询内容", 60, 120, panel); 76 77 LovoButton findButton = new LovoButton("查询", 120, 180, panel); 78 79 addButton.addActionListener(new ActionListener() { 80 81 @Override 82 public void actionPerformed(ActionEvent e) { 83 84 addStaff(); 85 } 86 }); 87 88 updateButton.addActionListener(new ActionListener() { 89 90 @Override 91 public void actionPerformed(ActionEvent e) { 92 93 updateStaff(); 94 } 95 }); 96 97 delButton.addActionListener(new ActionListener() { 98 99 @Override 100 public void actionPerformed(ActionEvent e) { 101 102 delStaff(); 103 } 104 }); 105 106 refreshButton.addActionListener(new ActionListener() { 107 108 @Override 109 public void actionPerformed(ActionEvent e) { 110 111 refresh(); 112 } 113 }); 114 115 updatePwdButton.addActionListener(new ActionListener() { 116 117 @Override 118 public void actionPerformed(ActionEvent e) { 119 120 updateStaffPwd(staff); 121 } 122 }); 123 124 logOutButton.addActionListener(new ActionListener() { 125 126 @Override 127 public void actionPerformed(ActionEvent e) { 128 129 loginOut(); 130 } 131 }); 132 133 findButton.addActionListener(new ActionListener() { 134 135 @Override 136 public void actionPerformed(ActionEvent e) { 137 138 findStaff(); 139 } 140 }); 141 } 142 143 /** 144 * 添加员工 145 */ 146 private void addStaff() { 147 148 new AddStaffFrame(this); 149 } 150 151 /** 152 * 修改员工 153 */ 154 private void updateStaff() { 155 156 int index = table.getKeyByInt(); 157 158 if (index == -1) { 159 JOptionPane.showMessageDialog(null, "请选择行"); 160 return; 161 } 162 163 if (staff.getId() == service.get(index).getId()) { 164 JOptionPane.showMessageDialog(null, "无法修改当前用户"); 165 return; 166 } 167 168 new UpdateStaffFrame(index, this); 169 } 170 171 /** 172 * 删除员工 173 */ 174 private void delStaff() { 175 176 int index = table.getKeyByInt(); 177 178 if (index == -1) { 179 JOptionPane.showMessageDialog(null, "请选择行"); 180 return; 181 } 182 183 if (staff.getId() == service.get(index).getId()) { 184 JOptionPane.showMessageDialog(null, "无法删除当前用户"); 185 return; 186 } 187 188 service.del(index); 189 refresh(); 190 } 191 192 /** 193 * 修改密码 194 * 195 * @param staff 当前员工 196 */ 197 private void updateStaffPwd(Staff staff) { 198 199 new UpdatePwdFrame(staff); 200 } 201 202 /** 203 * 注销 204 */ 205 private void loginOut() { 206 207 JOptionPane.showMessageDialog(null, "已注销"); 208 new LoginFrame(); 209 dispose(); 210 } 211 212 /** 213 * 查询员工 214 */ 215 private void findStaff() { 216 217 Staff[] selectedStaffs = service.find(fieldBox.getItem(), infoTxt.getText()); 218 table.updateLovoTable(selectedStaffs, service.getSelected()); 219 } 220 221 /** 222 * 刷新表格 223 */ 224 public void refresh() { 225 226 table.updateLovoTable(service.getStaffs(), service.getStaffNum()); 227 } 228 }
1 package test_33_1; 2 3 import java.awt.event.ActionEvent; 4 import java.awt.event.ActionListener; 5 6 import javax.swing.JFrame; 7 import javax.swing.JOptionPane; 8 9 import com.lovo.netCRM.component.LovoButton; 10 import com.lovo.netCRM.component.LovoComboBox; 11 import com.lovo.netCRM.component.LovoTxt; 12 13 /** 14 * 添加员工窗体类 15 */ 16 public class AddStaffFrame extends JFrame { 17 18 /** 管理员服务组件 */ 19 private AdminService service = new AdminService(); 20 /** 姓名文本框 */ 21 private LovoTxt nameTxt = new LovoTxt("姓名", 50, 90, this); 22 /** 职位下拉框 */ 23 private LovoComboBox<String> positionBox = new LovoComboBox<String> ("职位", 24 new String[] {"管理员", "职员"}, 50, 160, this); 25 /** 所在窗体 */ 26 private AdminMenuFrame m; 27 28 /** 29 * 无参构造方法 30 */ 31 public AddStaffFrame() { 32 33 } 34 35 /** 36 * 带参构造方法 37 * 38 * @param m 所在窗体 39 */ 40 public AddStaffFrame(AdminMenuFrame m) { 41 42 setLayout(null); 43 44 this.m = m; 45 init(); 46 47 setSize(400, 350); 48 setDefaultCloseOperation(2); 49 setVisible(true); 50 setLocationRelativeTo(null); 51 } 52 53 /** 54 * 默认 55 */ 56 private void init() { 57 58 LovoButton addButton = new LovoButton("添加", 50, 240, this); 59 LovoButton cancelButton = new LovoButton("取消", 250, 240, this); 60 61 addButton.addActionListener(new ActionListener() { 62 63 @Override 64 public void actionPerformed(ActionEvent e) { 65 66 addStaff(); 67 } 68 }); 69 70 cancelButton.addActionListener(new ActionListener() { 71 72 @Override 73 public void actionPerformed(ActionEvent e) { 74 75 dispose(); 76 } 77 }); 78 } 79 80 /** 81 * 添加员工 82 */ 83 private void addStaff() { 84 85 if ("".equals(nameTxt.getText())) { 86 JOptionPane.showMessageDialog(null, "请输入姓名"); 87 return; 88 } 89 90 Staff staff = new Staff(nameTxt.getText(), "666", positionBox.getItem()); 91 service.add(staff); 92 93 m.refresh(); 94 dispose(); 95 } 96 }
1 package test_33_1; 2 3 import java.awt.event.ActionEvent; 4 import java.awt.event.ActionListener; 5 6 import javax.swing.JFrame; 7 8 import com.lovo.netCRM.component.LovoButton; 9 import com.lovo.netCRM.component.LovoComboBox; 10 import com.lovo.netCRM.component.LovoLabel; 11 12 /** 13 * 修改员工窗体类 14 */ 15 public class UpdateStaffFrame extends JFrame { 16 17 /** 服务组件 */ 18 private AdminService service = new AdminService(); 19 /** 工号标签 */ 20 private LovoLabel codeLabel = new LovoLabel("工号", 50, 60, this); 21 /** 姓名标签 */ 22 private LovoLabel nameLabel = new LovoLabel("姓名", 50, 120, this); 23 /** 职位下拉框 */ 24 private LovoComboBox<String> positionBox = new LovoComboBox<String> ("职位", 25 new String[] {"管理员", "职员"}, 50, 180, this); 26 /** 下标 */ 27 private int index; 28 /** 所在窗体 */ 29 private AdminMenuFrame m; 30 31 /** 32 * 无参构造方法 33 */ 34 public UpdateStaffFrame() { 35 36 } 37 38 /** 39 * 带参构造方法 40 * 41 * @param index 选中下标 42 * @param m 所在窗体 43 */ 44 public UpdateStaffFrame(int index, AdminMenuFrame m) { 45 46 setLayout(null); 47 48 this.index = index; 49 this.m = m; 50 init(); 51 52 setSize(400, 350); 53 setDefaultCloseOperation(2); 54 setVisible(true); 55 setLocationRelativeTo(null); 56 } 57 58 /** 59 * 默认 60 */ 61 private void init() { 62 63 codeLabel.setText(service.get(index).getCode()); 64 nameLabel.setText(service.get(index).getName()); 65 positionBox.setItem(service.get(index).getPosition()); 66 67 LovoButton updateButton = new LovoButton("修改", 50, 240, this); 68 LovoButton cancelButton = new LovoButton("取消", 250, 240, this); 69 70 updateButton.addActionListener(new ActionListener() { 71 72 @Override 73 public void actionPerformed(ActionEvent e) { 74 75 updateStaff(); 76 } 77 }); 78 79 cancelButton.addActionListener(new ActionListener() { 80 81 @Override 82 public void actionPerformed(ActionEvent e) { 83 84 dispose(); 85 } 86 }); 87 } 88 89 /** 90 * 修改员工 91 */ 92 private void updateStaff() { 93 94 service.updatePosition(index, positionBox.getItem()); 95 m.refresh(); 96 dispose(); 97 } 98 99 }
1 package test_33_1; 2 3 import java.awt.event.ActionEvent; 4 import java.awt.event.ActionListener; 5 6 import javax.swing.JFrame; 7 import javax.swing.JOptionPane; 8 9 import com.lovo.netCRM.component.LovoButton; 10 import com.lovo.netCRM.component.LovoTxt; 11 12 /** 13 * 修改密码窗体类 14 */ 15 public class UpdatePwdFrame extends JFrame { 16 17 /** 旧密码文本框 */ 18 private LovoTxt oldPwdTxt = new LovoTxt("请输入旧密码", 50, 60, this); 19 /** 新密码文本框 */ 20 private LovoTxt newPwdTxt = new LovoTxt("请输入新密码", 50, 120, this); 21 /** 新密码确认文本框 */ 22 private LovoTxt rePwdTxt = new LovoTxt("请确认旧密码", 50, 180, this); 23 /** 服务组件 */ 24 private StaffService service = new StaffService(); 25 /** 当前登陆员工 */ 26 private Staff staff; 27 28 /** 29 * 无参构造方法 30 */ 31 public UpdatePwdFrame() { 32 33 } 34 35 /** 36 * 带参构造方法 37 * 38 * @param staff 当前登陆员工 39 */ 40 public UpdatePwdFrame(Staff staff) { 41 42 setLayout(null); 43 this.staff = staff; 44 45 init(); 46 47 setSize(400, 350); 48 setDefaultCloseOperation(2); 49 setVisible(true); 50 setLocationRelativeTo(null); 51 } 52 53 /** 54 * 默认 55 */ 56 private void init() { 57 58 LovoButton updateButton = new LovoButton("修改", 50, 240, this); 59 LovoButton cancelButton = new LovoButton("取消", 250, 240, this); 60 61 updateButton.addActionListener(new ActionListener() { 62 63 @Override 64 public void actionPerformed(ActionEvent e) { 65 66 updatePwd(); 67 } 68 }); 69 70 cancelButton.addActionListener(new ActionListener() { 71 72 @Override 73 public void actionPerformed(ActionEvent e) { 74 75 dispose(); 76 } 77 }); 78 79 } 80 81 /** 82 * 修改密码 83 */ 84 private void updatePwd() { 85 86 String str = service.updatePwd(staff, oldPwdTxt.getText(), 87 newPwdTxt.getText(), rePwdTxt.getText()); 88 89 if ("".equals(str)) { 90 JOptionPane.showMessageDialog(null, "修改成功"); 91 dispose(); 92 } else { 93 JOptionPane.showMessageDialog(null, str); 94 } 95 } 96 }
1 package test_33_1; 2 3 /** 4 * 职工服务组件类 5 */ 6 public class EmployeeService extends StaffService { 7 8 /** 货物数组 */ 9 private static Package[] packages = new Package[30]; 10 /** 货物数 */ 11 private static int packageNum; 12 /** 被选中货物数组 */ 13 private Package[] selectedPack; 14 /** 被选中货物数 */ 15 private int selectedNum; 16 17 static { 18 19 packages[0] = new Package("Lavenza", "110"); 20 packages[1] = new Package("Lavenza", "110"); 21 packages[2] = new Package("Caroline", "119"); 22 packages[3] = new Package("Justine", "120"); 23 packages[4] = new Package("Justine", "120"); 24 packageNum = 5; 25 26 } 27 28 /** 29 * 入库 30 */ 31 public void add(Package pack) { 32 33 packages[packageNum] = pack; 34 packageNum++; 35 } 36 37 /** 38 * 取货 39 */ 40 public void draw(int id, String consigner, String agent) { 41 42 int index = findIndexById(id); 43 44 packages[index].setOutDate(); 45 packages[index].setConsigner(consigner); 46 packages[index].setAgent(agent); 47 48 } 49 50 /** 51 * 获取未收货列表数组 52 * 53 * @return 未收货列表数组 54 */ 55 public Package[] showUnReceive() { 56 57 selectedPack = new Package[packageNum]; 58 selectedNum = 0; 59 60 for (int i = 0; i < packageNum; i++) { 61 if ("未取货".equals(packages[i].getOutDate())) { 62 selectedPack[selectedNum] = packages[i]; 63 selectedNum++; 64 } 65 } 66 67 return selectedPack; 68 } 69 70 /** 71 * 根据字段获取列表 72 * 73 * @param id 编号 74 * @param field 字段 75 * @param info 匹配信息 76 * @return 匹配列表 77 */ 78 public Package[] findByField(String field, String info) { 79 80 selectedPack = new Package[packageNum]; 81 selectedNum = 0; 82 83 if ("取货码".equals(field)) { 84 for (int i = 0; i < packageNum; i++) { 85 if (packages[i].getCode().indexOf(info) != -1) { 86 selectedPack[selectedNum] = packages[i]; 87 selectedNum++; 88 } 89 } 90 } 91 92 if ("收件人".equals(field)) { 93 for (int i = 0; i < packageNum; i++) { 94 if (packages[i].getConsignee().indexOf(info) != -1) { 95 selectedPack[selectedNum] = packages[i]; 96 selectedNum++; 97 } 98 } 99 } 100 101 return selectedPack; 102 103 } 104 105 public Package get(int id) { 106 107 int index = findIndexById(id); 108 109 return packages[index]; 110 } 111 112 /** 113 * @param id 114 * @return 115 */ 116 private int findIndexById(int id) { 117 118 for (int i = 0; i < packageNum; i++) { 119 if (packages[i].getId() == id) { 120 return i; 121 } 122 } 123 124 return -1; 125 } 126 127 /** 128 * 获取货物数组 129 * 130 * @return packages 货物数组 131 */ 132 public Package[] getPackages() { 133 return packages; 134 } 135 136 /** 137 * 获取货物数 138 * 139 * @return packageNum 货物数 140 */ 141 public int getPackageNum() { 142 return packageNum; 143 } 144 145 /** 146 * 获取被选中货物数 147 * 148 * @return selectedNum 被选中货物数 149 */ 150 public int getSelectedNum() { 151 return selectedNum; 152 } 153 154 }
1 package test_33_1; 2 3 import java.awt.event.ActionEvent; 4 import java.awt.event.ActionListener; 5 6 import javax.swing.JFrame; 7 import javax.swing.JOptionPane; 8 9 import com.lovo.netCRM.component.LovoButton; 10 import com.lovo.netCRM.component.LovoComboBox; 11 import com.lovo.netCRM.component.LovoTable; 12 import com.lovo.netCRM.component.LovoTitlePanel; 13 import com.lovo.netCRM.component.LovoTxt; 14 15 /** 16 * 职工主窗体类 17 */ 18 public class EmployeeMenuFrame extends JFrame { 19 20 /** 职工服务组件 */ 21 private EmployeeService service = new EmployeeService(); 22 /** 当前登陆用户 */ 23 private Staff staff; 24 /** 货物信息表 */ 25 private LovoTable table = new LovoTable(this, 26 new String[] {"取货码", "收件人", "收件人电话", "入库时间", "取货时间", "收货人", "经办人"}, 27 new String[] {"code", "consignee", "phone", "inDate", "outDate", "consigner", "agent"}, 28 "id"); 29 /** 字段下拉框 */ 30 private LovoComboBox<String> fieldBox; 31 /** 信息文本框 */ 32 private LovoTxt infoTxt; 33 34 /** 35 * 无参构造方法 36 */ 37 public EmployeeMenuFrame() { 38 39 } 40 41 /** 42 * 带参构造方法 43 * 44 * @param staff 登陆员工 45 */ 46 public EmployeeMenuFrame(Staff staff) { 47 48 setLayout(null); 49 50 this.staff = staff; 51 init(); 52 53 setSize(820, 650); 54 setDefaultCloseOperation(3); 55 setVisible(true); 56 setLocationRelativeTo(null); 57 } 58 59 /** 60 * 默认 61 */ 62 private void init() { 63 64 table.setSizeAndLocation(20, 20, 760, 250); 65 refresh(); 66 67 LovoButton addButton = new LovoButton("入库", 20, 350, this); 68 LovoButton drawButton = new LovoButton("取货", 220, 350, this); 69 LovoButton showUnRecButton = new LovoButton("显示未收货", 20, 420, this); 70 LovoButton refreshButton = new LovoButton("显示全部", 220, 420, this); 71 LovoButton updatePwdButton = new LovoButton("修改密码", 20, 490, this); 72 LovoButton logOutButton = new LovoButton("注销", 220, 490, this); 73 74 LovoTitlePanel panel = new LovoTitlePanel("查找货物", 400, 330, 380, 220, this); 75 fieldBox = new LovoComboBox<>("查询字段", new String[] {"取货码", "收件人"}, 60, 60, panel); 76 infoTxt = new LovoTxt("查询内容", 60, 120, panel); 77 78 LovoButton findButton = new LovoButton("查询", 120, 180, panel); 79 80 addButton.addActionListener(new ActionListener() { 81 82 @Override 83 public void actionPerformed(ActionEvent e) { 84 85 addPack(); 86 } 87 }); 88 89 drawButton.addActionListener(new ActionListener() { 90 91 @Override 92 public void actionPerformed(ActionEvent e) { 93 94 drawPack(); 95 } 96 }); 97 98 showUnRecButton.addActionListener(new ActionListener() { 99 100 @Override 101 public void actionPerformed(ActionEvent e) { 102 103 showUnRecPack(); 104 } 105 }); 106 107 refreshButton.addActionListener(new ActionListener() { 108 109 @Override 110 public void actionPerformed(ActionEvent e) { 111 112 refresh(); 113 } 114 }); 115 116 updatePwdButton.addActionListener(new ActionListener() { 117 118 @Override 119 public void actionPerformed(ActionEvent e) { 120 121 updateStaffPwd(staff); 122 } 123 124 }); 125 126 logOutButton.addActionListener(new ActionListener() { 127 128 @Override 129 public void actionPerformed(ActionEvent e) { 130 131 new LoginFrame(); 132 dispose(); 133 } 134 }); 135 136 findButton.addActionListener(new ActionListener() { 137 138 @Override 139 public void actionPerformed(ActionEvent e) { 140 141 findPack(); 142 } 143 }); 144 } 145 146 /** 147 * 入库 148 */ 149 private void addPack() { 150 151 new AddPackageFrame(this); 152 } 153 154 /** 155 * 取货 156 */ 157 private void drawPack() { 158 159 int index = table.getKeyByInt(); 160 161 if (index == -1) { 162 JOptionPane.showMessageDialog(null, "请选择行"); 163 return; 164 } 165 166 if ("未取货".equals(service.getPackages()[index].getOutDate()) == false) { 167 JOptionPane.showMessageDialog(null, "该货物已被取走"); 168 return; 169 } 170 171 new DrawPackageFrame(index, this); 172 } 173 174 /** 175 * 显示未收货订单 176 */ 177 private void showUnRecPack() { 178 179 Package[] selected = service.showUnReceive(); 180 table.updateLovoTable(selected, service.getSelectedNum()); 181 } 182 183 /** 184 * 修改密码 185 * 186 * @param staff 当前用户 187 */ 188 private void updateStaffPwd(Staff staff) { 189 190 new UpdatePwdFrame(staff); 191 } 192 193 /** 194 * 查询货物 195 */ 196 private void findPack() { 197 198 Package[] selected = service.findByField(fieldBox.getItem(), infoTxt.getText()); 199 table.updateLovoTable(selected, service.getSelectedNum()); 200 } 201 202 /** 203 * 刷新 204 */ 205 public void refresh() { 206 207 table.updateLovoTable(service.getPackages(), service.getPackageNum()); 208 } 209 210 /** 211 * 获取当前登陆用户 212 * 213 * @return staff 当前登陆用户 214 */ 215 public Staff getStaff() { 216 return staff; 217 } 218 219 }
1 package test_33_1; 2 3 import java.awt.event.ActionEvent; 4 import java.awt.event.ActionListener; 5 6 import javax.swing.JFrame; 7 import javax.swing.JOptionPane; 8 9 import com.lovo.netCRM.component.LovoButton; 10 import com.lovo.netCRM.component.LovoTxt; 11 12 /** 13 * 入库窗体类 14 */ 15 public class AddPackageFrame extends JFrame { 16 17 /** 职工服务组件 */ 18 private EmployeeService service = new EmployeeService(); 19 /** 收货人姓名文本框 */ 20 private LovoTxt nameTxt = new LovoTxt("姓名", 50, 90, this); 21 /** 收货人电话文本框 */ 22 private LovoTxt phonTxt = new LovoTxt("电话", 50, 160, this); 23 /** 所在窗体 */ 24 private EmployeeMenuFrame m; 25 26 /** 27 * 无参构造方法 28 */ 29 public AddPackageFrame() { 30 31 } 32 33 /** 34 * 带参构造方法 35 * 36 * @param m 所在窗体 37 */ 38 public AddPackageFrame(EmployeeMenuFrame m) { 39 40 setLayout(null); 41 42 this.m = m; 43 init(); 44 45 setSize(400, 350); 46 setDefaultCloseOperation(2); 47 setVisible(true); 48 setLocationRelativeTo(null); 49 } 50 51 /** 52 * 默认 53 */ 54 private void init() { 55 56 LovoButton addButton = new LovoButton("入库", 50, 240, this); 57 LovoButton cancelButton = new LovoButton("取消", 250, 240, this); 58 59 addButton.addActionListener(new ActionListener() { 60 61 @Override 62 public void actionPerformed(ActionEvent e) { 63 64 addPack(); 65 } 66 }); 67 68 cancelButton.addActionListener(new ActionListener() { 69 70 @Override 71 public void actionPerformed(ActionEvent e) { 72 73 dispose(); 74 } 75 }); 76 } 77 78 /** 79 * 入库 80 */ 81 private void addPack() { 82 83 if ("".equals(nameTxt.getText()) || "".equals(phonTxt.getText())) { 84 JOptionPane.showMessageDialog(null, "请输入收货人姓名和电话"); 85 return; 86 } 87 88 Package pack = new Package(nameTxt.getText(), phonTxt.getText()); 89 90 service.add(pack); 91 92 m.refresh(); 93 dispose(); 94 } 95 }
1 package test_33_1; 2 3 import java.awt.event.ActionEvent; 4 import java.awt.event.ActionListener; 5 6 import javax.swing.JFrame; 7 import javax.swing.JOptionPane; 8 9 import com.lovo.netCRM.component.LovoButton; 10 import com.lovo.netCRM.component.LovoLabel; 11 import com.lovo.netCRM.component.LovoTxt; 12 13 /** 14 * 取货窗体类 15 */ 16 public class DrawPackageFrame extends JFrame { 17 18 /** 职工服务组件 */ 19 private EmployeeService service = new EmployeeService(); 20 /** 工号标签 */ 21 private LovoLabel codeLabel = new LovoLabel("取货码", 50, 60, this); 22 /** 收件人标签 */ 23 private LovoLabel consignerLabel = new LovoLabel("收件人姓名", 50, 120, this); 24 /** 收件人电话标签 */ 25 private LovoLabel phoneLabel = new LovoLabel("收件人电话", 50, 180, this); 26 /** 入库时间标签 */ 27 private LovoLabel inDateLabel = new LovoLabel("入库时间", 50, 240, this); 28 /** 取件人文本框 */ 29 private LovoTxt consigneeTxt = new LovoTxt("取件人", 50, 300, this); 30 31 /** 下标 */ 32 private int index; 33 /** 所在窗体 */ 34 private EmployeeMenuFrame m; 35 36 /** 37 * 无参构造方法 38 */ 39 public DrawPackageFrame() { 40 41 } 42 43 /** 44 * 带参构造方法 45 * 46 * @param index 选中下标 47 * @param m 所在窗体 48 */ 49 public DrawPackageFrame(int index, EmployeeMenuFrame m) { 50 51 setLayout(null); 52 53 this.index = index; 54 this.m = m; 55 init(); 56 57 setSize(400, 500); 58 setDefaultCloseOperation(2); 59 setVisible(true); 60 setLocationRelativeTo(null); 61 } 62 63 /** 64 * 默认 65 */ 66 private void init() { 67 68 codeLabel.setText(service.get(index).getCode()); 69 consignerLabel.setText(service.get(index).getConsigner()); 70 phoneLabel.setText(service.get(index).getPhone()); 71 inDateLabel.setText(service.get(index).getInDate()); 72 73 LovoButton updateButton = new LovoButton("取货", 50, 360, this); 74 LovoButton cancelButton = new LovoButton("取消", 250, 360, this); 75 76 updateButton.addActionListener(new ActionListener() { 77 78 @Override 79 public void actionPerformed(ActionEvent e) { 80 81 drawPack(); 82 } 83 }); 84 85 cancelButton.addActionListener(new ActionListener() { 86 87 @Override 88 public void actionPerformed(ActionEvent e) { 89 90 dispose(); 91 } 92 }); 93 } 94 95 /** 96 * 取货 97 */ 98 private void drawPack() { 99 100 if ("".equals(consigneeTxt.getText())) { 101 JOptionPane.showMessageDialog(null, "请签名"); 102 } 103 104 service.draw(index, consigneeTxt.getText(), m.getStaff().getName()); 105 m.refresh(); 106 dispose(); 107 } 108 }
1 package test_33_1; 2 3 public class Test { 4 5 public static void main(String[] args) { 6 new LoginFrame(); 7 } 8 }
[20-06-07][Self-test 47]Java Staffs&Packages Manage
原文:https://www.cnblogs.com/mirai3usi9/p/13061438.html