Example #1
0
  public ActionForward execute(
      ActionMapping actionMapping,
      ActionForm actionForm,
      HttpServletRequest httpServletRequest,
      HttpServletResponse httpServletResponse) {
    LazyValidatorForm frm = (LazyValidatorForm) actionForm;

    if (formCanceled(frm)) {
      return actionMapping.findForward(SUCCESS);
    }

    resetFocusControl(frm, CANCEL);
    ActionMessages msgs = new ActionMessages();
    if (!formSaved(frm)) {
      setFormMode(frm, ((String) httpServletRequest.getParameter(BROWSE_ACTION)));
      setFormId(frm, (String) httpServletRequest.getParameter(BROWSE_ID));
      try {
        httpServletRequest
            .getSession()
            .setAttribute("hozehKindList", Misc.listHardCode(Constants.TableId.HOZEH_KIND));

        LoginInfo loginInfo = getLoginInfo(httpServletRequest);
        if (!loginInfo.userHasAccess(getFormId(frm), getFormMode(frm))) {
          if (isFormInModifyMode(frm)
              && loginInfo.userHasAccess(getFormId(frm), Constants.ActionType.ENQUERY)) {
            setFormMode(frm, Constants.ActionType.ENQUERY);
          } else {
            throw new Exception(INVALID_ACCESS);
          }
        }
        if (!isFormInAddMode(frm)) {
          String formKey = (String) httpServletRequest.getParameter(BROWSE_KEY);
          frm.set("formKey", formKey);
          String key[] = formKey.split(Constants.DATA_SEPARATOR_SPLIT);
          short officeCode = Short.parseShort(key[0]);
          short hozehCode = Short.parseShort(key[1]);
          String hozehKind = key[2];

          HozehInfo inf = Place.getHozehDetails(officeCode, hozehCode, hozehKind);
          frm.set(OFFICE_CODE, Short.toString(inf.getOfficeCode()));
          frm.set(HOZEH_CODE, Short.toString(inf.getHozehCode()));
          frm.set(HOZEH_KIND, inf.getHozehKind());
          frm.set(HOZEH_DESC, inf.getHozehDesc());
          if (inf.isInactive()) {
            frm.set(CODE_ACTIVE_FLAG, "on");
          }
        }
        String officeCode = (String) frm.get(OFFICE_CODE);
        if (Utils.isEmpty(officeCode)) {
          officeCode = "0";
          frm.set(OFFICE_CODE, officeCode);
        }
        frm.set(OFFICE_NAME, Place.getOfficeName(Short.parseShort(officeCode)));

        if (isFormInAddMode(frm)) {
          resetFocusControl(frm, HOZEH_CODE);
        } else if (isFormInModifyMode(frm)) {
          resetFocusControl(frm, HOZEH_DESC);
        }
      } catch (Exception ex) {
        addError(msgs, ex.getMessage());
        saveErrors(httpServletRequest, msgs);
      }
      return actionMapping.findForward(EDIT);
    } else {
      HozehInfo inf = new HozehInfo();
      resetFocusControl(frm, "");

      if (isFormInAddMode(frm)) {

        String officeCode = ((String) frm.get(OFFICE_CODE)).trim();
        resetFocusControl(frm, "");
        if (Utils.isEmpty(officeCode)) {
          addError(msgs, FIELD_CAN_NOT_BE_EMPTY, "اداره");
          setFocusControl(frm, OFFICE_CODE);
        } else if (!Utils.isValidNotZeroNumber(officeCode, 3)) {
          addError(msgs, FIELD_INVALID, "اداره");
          setFocusControl(frm, OFFICE_CODE);
        } else {
          inf.setOfficeCode(Short.parseShort(officeCode));
        }

        String hozehCode = ((String) frm.get(HOZEH_CODE)).trim();
        if (Utils.isEmpty(hozehCode)) {
          addError(msgs, FIELD_CAN_NOT_BE_EMPTY, "كد");
          setFocusControl(frm, HOZEH_CODE);
        } else if (!Utils.isValidNotZeroNumber(hozehCode, 3)) {
          addError(msgs, FIELD_INVALID, "كد");
          setFocusControl(frm, HOZEH_CODE);
        } else {
          inf.setHozehCode(Short.parseShort(hozehCode));
        }

        String hozehKind = ((String) frm.get(HOZEH_KIND)).trim();
        if (Utils.isEmpty(hozehKind)) {
          addError(msgs, FIELD_CAN_NOT_BE_EMPTY, "نوع");
          setFocusControl(frm, HOZEH_KIND);
        } else if (hozehKind.length() > 1) {
          addError(msgs, FIELD_INVALID, "نوع");
          setFocusControl(frm, HOZEH_KIND);
        } else {
          inf.setHozehKind(hozehKind);
        }

      } else {
        String formKey = (String) frm.get("formKey");
        String key[] = formKey.split(Constants.DATA_SEPARATOR_SPLIT);

        inf.setOfficeCode(Short.parseShort(key[0]));
        inf.setHozehCode(Short.parseShort(key[1]));
        inf.setHozehKind(key[2]);
      }

      if (!isFormInDeleteMode(frm)) {
        String hozehDesc = Utils.charVal((String) frm.get(HOZEH_DESC));
        frm.set(HOZEH_DESC, hozehDesc);
        if (Utils.isEmpty(hozehDesc)) {
          addError(msgs, FIELD_CAN_NOT_BE_EMPTY, "شرح");
          setFocusControl(frm, HOZEH_DESC);
        } else if (hozehDesc.length() > 50) {
          addError(msgs, FIELD_INVALID, "شرح");
          setFocusControl(frm, HOZEH_DESC);
        } else {
          inf.setHozehDesc(hozehDesc);
        }

        if (frm.get(CODE_ACTIVE_FLAG) == null) {
          inf.setCodeActiveFlag(Constants.CodeActiveFlag.ACTIVE);
        } else {
          inf.setCodeActiveFlag(Constants.CodeActiveFlag.INACTIVE);
        }
      }

      if (!msgs.isEmpty()) {
        saveErrors(httpServletRequest, msgs);
        return actionMapping.findForward(EDIT);
      }

      resetFocusControl(frm, CANCEL);
      try {
        Place.saveHozeh(getFormMode(frm), inf);
        httpServletRequest.setAttribute(BROWSE_KEY, inf.getKey());
        return actionMapping.findForward(SUCCESS);
      } catch (Exception ex) {
        resetFocusControl(frm, CANCEL);
        addError(msgs, ex.getMessage());
        saveErrors(httpServletRequest, msgs);
        return actionMapping.findForward(EDIT);
      }
    }
  }
Example #2
0
  public ActionForward execute(
      ActionMapping actionMapping,
      ActionForm actionForm,
      HttpServletRequest httpServletRequest,
      HttpServletResponse httpServletResponse)
      throws Exception {

    LazyValidatorForm frm = (LazyValidatorForm) actionForm;
    LoginInfo loginInfo = (LoginInfo) httpServletRequest.getSession().getAttribute("loginInfo");
    if (formCanceled(frm)) {
      return actionMapping.findForward(SUCCESS);
    }
    resetFocusControl(frm, CANCEL);
    ActionMessages msgs = new ActionMessages();
    DocInvTransactionInfo inf = new DocInvTransactionInfo();
    if (!formSaved(frm)) {
      setFormMode(frm, ((String) httpServletRequest.getParameter(BROWSE_ACTION)));
      setFormId(frm, (String) httpServletRequest.getParameter(BROWSE_ID));
      try {
        short officeCode = loginInfo.getOfficeCode();
        if (!loginInfo.userHasAccess(getFormId(frm), getFormMode(frm))) {
          if (isFormInModifyMode(frm)
              && loginInfo.userHasAccess(getFormId(frm), Constants.ActionType.ENQUERY)) {
            setFormMode(frm, Constants.ActionType.ENQUERY);
          } else {
            throw new Exception(INVALID_ACCESS);
          }
        }
        if (!isFormInAddMode(frm)) {
          String formKey = (String) httpServletRequest.getParameter(BROWSE_KEY);
          frm.set("formKey", formKey);
          StringTokenizer st = new StringTokenizer(formKey, Constants.DATA_SEPARATOR);
          officeCode = Short.parseShort(st.nextToken());
          String eventType = st.nextToken();
          String docType = st.nextToken();
          String docSeri = st.nextToken().trim();
          int docStartSrno = Integer.parseInt(st.nextToken());
          inf = Inventory.getDetails(officeCode, eventType, docType, docSeri, docStartSrno);
          frm.set(ASSIGN_DATE, DateUtils.revFormatDate(inf.getEventDate()));
          frm.set(DOC_SERI, inf.getDocSeri());
          frm.set(DOC_START_SRNO, Integer.toString(inf.getDocStartSrno()));
          frm.set(DOC_END_SRNO, Integer.toString(inf.getDocEndSrno()));
        }
        if (isFormInAddMode(frm)) {
          frm.set(ASSIGN_DATE, DateUtils.fDateRevFormatted());
          resetFocusControl(frm, DOC_SERI);
        }

      } catch (Exception ex) {
        addError(msgs, ex.getMessage());
        saveErrors(httpServletRequest, msgs);
      }
      return actionMapping.findForward(EDIT);

    } else {
      String assignDate = ((String) frm.get(ASSIGN_DATE)).trim();
      if (Utils.isEmpty(assignDate)) {
        addError(msgs, FIELD_CAN_NOT_BE_EMPTY, "تاريخ تخصيص");
        setFocusControl(frm, ASSIGN_DATE);
      } else if (!DateUtils.isValidRevFormattedFDate(assignDate)
          || Integer.parseInt(DateUtils.unformatRevFormattedFdate(assignDate))
              > Integer.parseInt(DateUtils.fDate())) {
        addError(msgs, FIELD_INVALID, "تاريخ تخصيص");
        setFocusControl(frm, ASSIGN_DATE);
      } else {
        inf.setEventDate(DateUtils.unformatRevFormattedFdate(assignDate));
      }
      inf.setOfficeCode(loginInfo.getOfficeCode());
      inf.setEventType(Constants.EventType.ASSIGN);

      String docSeri = Utils.charVal2((String) frm.get(DOC_SERI));
      if (Utils.isEmpty(docSeri)) {
        addError(msgs, FIELD_INVALID, "سري كارتهاي شناسايي");
        setFocusControl(frm, DOC_SERI);
      } else {
        inf.setDocSeri(docSeri);
        frm.set(DOC_SERI, docSeri);
      }
      String docStartSrno = ((String) frm.get(DOC_START_SRNO)).trim();
      if (Utils.isEmpty(docStartSrno)) {
        addError(msgs, FIELD_CAN_NOT_BE_EMPTY, "سريال شروع");
        setFocusControl(frm, DOC_START_SRNO);
      }
      String docEndSrno = ((String) frm.get(DOC_END_SRNO)).trim();
      if (Utils.isEmpty(docEndSrno)) {
        addError(msgs, FIELD_CAN_NOT_BE_EMPTY, "سريال خاتمه");
        setFocusControl(frm, DOC_END_SRNO);
      } else {
        if (!Utils.isValidNumber(docStartSrno, 6) || !Utils.isValidNumber(docEndSrno, 6)) {
          addError(msgs, FIELD_INVALID, "محدوده سريال كارت شناسايي");
          setFocusControl(frm, DOC_START_SRNO);
        } else {
          if (Integer.parseInt(docStartSrno) > Integer.parseInt(docEndSrno)) {
            addError(msgs, FIELD_INVALID, "محدوده سريال كارت شناسايي");
            setFocusControl(frm, DOC_START_SRNO);
          } else {
            inf.setDocStartSrno(Integer.parseInt(docStartSrno));
            inf.setDocEndSrno(Integer.parseInt(docEndSrno));
          }
        }
      }

      inf.setMamoorId("9991");
      inf.setUserId(loginInfo.getUserId());
      inf.setDocType(Constants.DocType.ID_CARD_CENTRAL_BANK);

      if (!msgs.isEmpty()) {
        saveErrors(httpServletRequest, msgs);
        return actionMapping.findForward(EDIT);
      }
      resetFocusControl(frm, CANCEL);
      // Save Data
      try {
        String eventErrorCode = null;
        if (isFormInDeleteMode(frm)) {
          eventErrorCode = Inventory.deleteAssign(inf);
        } else {
          eventErrorCode = Inventory.addAssign(inf);
        }
        if (!Utils.isEmpty(eventErrorCode)) {
          StringTokenizer st = new StringTokenizer(eventErrorCode, Constants.FIELD_SEPARATOR);
          int countErrorToken = st.countTokens();
          for (int countError = 1; countError <= countErrorToken; countError++) {
            addError(msgs, st.nextToken());
          }
          saveErrors(httpServletRequest, msgs);
          return actionMapping.findForward(EDIT);
        } else {
          httpServletRequest.setAttribute(BROWSE_KEY, inf.getKey());
          return actionMapping.findForward(SUCCESS);
        }
      } catch (Exception ex) {
        resetFocusControl(frm, CANCEL);
        addError(msgs, ex.getMessage());
        saveErrors(httpServletRequest, msgs);
        return actionMapping.findForward(EDIT);
      }
    }
  }