public void deleteAllAdmBranch(AdmTO admTO) { PreparedStatement pstmt = null; Connection con = null; try { con = DAOFactory.getInstance().getConnection(Connection.TRANSACTION_READ_UNCOMMITTED); pstmt = con.prepareStatement(SQLConstants.DELETE_ADMIN_BRANCH_SQL); pstmt.setString(1, Utility.trim(admTO.getId())); pstmt.executeUpdate(); } catch (SQLException e) { throw new DataException(e.getMessage()); } catch (NamingException e) { throw new DataException(e.getMessage()); } finally { Utility.closeAll(null, pstmt, con); } }
public AdmBranchTO[] listAdmBranch(AdmTO admTO) { PreparedStatement pstmt = null; Connection con = null; ResultSet rs = null; AdmBranchTO admBranchTO = null; ArrayList<AdmBranchTO> admBranchList = new ArrayList<AdmBranchTO>(); try { con = DAOFactory.getInstance().getConnection(Connection.TRANSACTION_READ_UNCOMMITTED); pstmt = con.prepareStatement(SQLConstants.LIST_ADMIN_BRANCH_SQL); pstmt.setString(1, Utility.trim(admTO.getId())); rs = pstmt.executeQuery(); while (rs.next()) { BranchTO branchTO = new BranchTO(); admBranchTO = new AdmBranchTO(); admBranchTO.setAdm(admTO); admBranchTO.setId(rs.getString("id")); admBranchTO.setStatus(Utility.trim(rs.getString("status"))); admBranchTO.setBranch(branchTO); admBranchTO.getBranch().setId(Utility.trim(rs.getString("branch_id"))); admBranchTO.getBranch().setCode(Utility.trim(rs.getString("code"))); admBranchTO.getBranch().setName(Utility.trim(rs.getString("name"))); admBranchList.add(admBranchTO); } return (AdmBranchTO[]) admBranchList.toArray(new AdmBranchTO[0]); } catch (SQLException e) { throw new DataException(e.getMessage()); } catch (NamingException e) { throw new DataException(e.getMessage()); } finally { Utility.closeAll(null, pstmt, con); } }
public String execute(HttpServletRequest request, HttpServletResponse arg1) throws Exception { ResourceBundle bundle = Resource.getInstance().getRequestToObjectMap(); this.txtId = generalTools.NullToEmpty((String) request.getParameter("txtId")); this.txtCode = generalTools.NullToEmpty((String) request.getParameter("txtCode")); this.txtName = generalTools.NullToEmpty((String) request.getParameter("txtName")); this.txtContact = generalTools.NullToEmpty((String) request.getParameter("txtContact")); this.txtEmail = generalTools.NullToEmpty((String) request.getParameter("txtEmail")); this.txtAdmin_group_id = generalTools.NullToEmpty((String) request.getParameter("txtAdmin_group_id")); this.txtCountry_id = generalTools.NullToEmpty((String) request.getParameter("txtCountry_id")); this.txtStatus = generalTools.NullToEmpty((String) request.getParameter("txtStatus")); this.hMode = generalTools.NullToEmpty((String) request.getParameter("hMode")); this.id = generalTools.NullToEmpty((String) request.getParameter("id")); // Get admin group list AdmGroupService admGroupService = new AdmGroupService(); AdmGroupTO[] listAdmGroup = admGroupService.getAllAdmGroup(); // Get country list CountryService countryService = new CountryService(); CountryTO[] listCountry = countryService.getAllCountry(); AdmTO admTO = admService.setAll( txtId, txtCode, txtName, txtContact, txtEmail, txtAdmin_group_id, txtCountry_id, txtStatus); String btn = (String) request.getParameter("btn"); if (btn != null) { if (btn.equalsIgnoreCase(Multilingual.getLabel(null, "common.save"))) { if (hMode.equalsIgnoreCase(ConstantValue.NEW)) { this.txtPassword = ConstantValue.DEFAULT_PWD; admTO.setPassword(this.txtPassword); if (admService.checkMandatoryValues(admTO, true)) { admService.insertRecord(admTO); admTO = admService.loadRecordByCode(admTO.getCode()); if (admTO != null) { AdmBranchTO[] listAdmBranchTO = branchService.listAdmBranch(admTO); admTO.setAdmBranchList(listAdmBranchTO); msg = "common.insert_success"; } else { msg = "alert.insert_error"; } } else { request.setAttribute("hMode", ConstantValue.NEW); msg = "alert.insert_mandatory"; } } else { if (admService.checkMandatoryValues(admTO, false)) { admService.updateRecord(admTO); admTO = admService.loadRecordById(admTO.getId()); if (admTO != null) { AdmBranchTO[] listAdmBranchTO = branchService.listAdmBranch(admTO); admTO.setAdmBranchList(listAdmBranchTO); msg = "common.update_success"; } else { msg = "alert.update_error"; } } else { admTO = admService.loadRecordById(txtId); msg = "alert.insert_mandatory"; } } } else if (btn.equalsIgnoreCase(Multilingual.getLabel(null, "common.branch"))) { // Get all branch by country list BranchService branchService = new BranchService(); BranchTO[] listBranch = branchService.getAllBranchByCountry(admTO.getCountry().getId()); AdmBranchTO[] listAdmBranch = branchService.listAdmBranch(admTO); admTO = admService.loadRecordById(admTO.getId()); request.setAttribute("listBranch", listBranch); request.setAttribute("listAdmBranch", listAdmBranch); request.setAttribute("admTO", admTO); request.setAttribute("includePage", bundle.getString("admin/admBranchIUD.URL")); return CommandHelper.getTempate(request, bundle); } else if (btn.equalsIgnoreCase(Multilingual.getLabel(null, "common.reset_pwd"))) { admService.resetPassword(admTO); admTO = admService.loadRecordById(admTO.getId()); if (admTO != null) { AdmBranchTO[] listAdmBranchTO = branchService.listAdmBranch(admTO); admTO.setAdmBranchList(listAdmBranchTO); msg = "common.reset_pwd_success"; } else { msg = "alert.reset_pwd_error"; } } } else if (this.id != null) { admTO = admService.loadRecordById(id); if (admTO != null) { AdmBranchTO[] listAdmBranchTO = branchService.listAdmBranch(admTO); admTO.setAdmBranchList(listAdmBranchTO); } else { msg = "alert.load_record_error"; } } else { hMode = ConstantValue.NEW; } request.setAttribute("listAdmGroup", listAdmGroup); request.setAttribute("listCountry", listCountry); request.setAttribute("admTO", admTO); request.setAttribute("msg", msg); request.setAttribute("includePage", bundle.getString("admin/admIUD.URL")); return CommandHelper.getTempate(request, bundle); }