/** Method edit employee on database and edit on employee table */ private void editEmp() { parent.doBlur(); // Get Id employee selected String empID = view.getTblEmp().getValueAt(view.getTblEmp().getSelectedRow(), 0).toString(); // Get employee from database Employee emp = AccessEmp.getInstance().getEmpInfo(new Integer(empID)); // Create instance of Employee edit dialog and display it editEmp = new EditEmployeeController(new EditEmployeeDialog(parent.getView()), emp); editEmp.getView().setVisible(true); // Update data on database if (editEmp.getEmp() != null) { if (AccessEmp.getInstance().editEmp(editEmp.getEmp())) { JOptionPane.showMessageDialog( view, Messages.getString("EmployeeController.14"), // $NON-NLS-1$ Messages.getString("EmployeeController.15"), JOptionPane.INFORMATION_MESSAGE); // Remove old data on table model empModel.removeRow(view.getTblEmp().getSelectedRow()); // Add new row empModel.addRow(emp.toVector()); } else { JOptionPane.showMessageDialog( view, Messages.getString("EmployeeController.16") // $NON-NLS-1$ + Messages.getString("EmployeeController.17"), Messages.getString("EmployeeController.18"), // $NON-NLS-1$ JOptionPane.ERROR_MESSAGE); } } parent.doBlur(); // Set selection to employee book view.getTblEmp().changeSelection(view.getTblEmp().getRowCount() - 1, 0, false, false); }
/** Delete an employee */ private void deleteEmp() { parent.doBlur(); int sure = JOptionPane.showConfirmDialog( parent.getView(), Messages.getString("EmployeeController.7"), Messages.getString("EmployeeController.8"), // $NON-NLS-1$ JOptionPane.YES_NO_OPTION, JOptionPane.INFORMATION_MESSAGE); if (sure == JOptionPane.OK_OPTION) { // Get Id employee selected String empID = view.getTblEmp().getValueAt(view.getTblEmp().getSelectedRow(), 0).toString(); if (!AccessEmp.getInstance().deleteEmp(Integer.parseInt(empID))) { JOptionPane.showMessageDialog( parent.getView(), Messages.getString("EmployeeController.9") // $NON-NLS-1$ + Messages.getString("EmployeeController.10"), // $NON-NLS-1$ Messages.getString("EmployeeController.11"), JOptionPane.ERROR_MESSAGE); } else { JOptionPane.showMessageDialog( parent.getView(), Messages.getString("EmployeeController.12"), Messages.getString("EmployeeController.13"), // $NON-NLS-1$ JOptionPane.INFORMATION_MESSAGE); empModel.removeRow(view.getTblEmp().getSelectedRow()); } } tableFocus(); parent.doBlur(); }
/** Method add employee on database */ private void addEmp() { parent.doBlur(); // Display Add employee dialog addEmp = new AddEmployeeController(new AddEmployeeDialog(parent.getView())); addEmp.getView().setVisible(true); // invoked method add employee if (addEmp.getEmp() != null) { if (AccessEmp.getInstance().addEmp(addEmp.getEmp())) { JOptionPane.showMessageDialog( view, Messages.getString("EmployeeController.0"), // $NON-NLS-1$ Messages.getString("EmployeeController.1"), JOptionPane.INFORMATION_MESSAGE); // Move last page and show newest employee view.getTxtEmpID().setText(Messages.getString("EmptyText")); // $NON-NLS-1$ view.getTxtEmpName().setText(Messages.getString("EmptyText")); // $NON-NLS-1$ view.getBtnLast().doClick(); } else { JOptionPane.showMessageDialog( view, Messages.getString("EmployeeController.4") // $NON-NLS-1$ + Messages.getString("EmployeeController.5"), Messages.getString("EmployeeController.6"), // $NON-NLS-1$ JOptionPane.ERROR_MESSAGE); } } parent.doBlur(); // Set selection to new employee view.getTblEmp().changeSelection(view.getTblEmp().getRowCount() - 1, 0, false, false); }
/** Method view full information employee */ private void viewEmp() { // Get Id employee selected String empID = view.getTblEmp().getValueAt(view.getTblEmp().getSelectedRow(), 0).toString(); // Get employee from database Employee emp = AccessEmp.getInstance().getEmpInfo(new Integer(empID)); parent.doBlur(); // Create instance of Employee edit dialog and display it viewEmp = new ViewEmployeeController(new ViewEmployeeDialog(parent.getView()), emp); viewEmp.getView().setVisible(true); tableFocus(); parent.doBlur(); }