示例#1
0
  private boolean searchGeoDesc(LazyValidatorForm frm, String geoFlag) {
    boolean isValid = false;

    frm.set(GEO_DESC, "");
    try {
      String geoSerial = ((String) frm.get(GEO_SERIAL));
      if (!Utils.isEmpty(geoSerial)) {
        geoSerial = geoSerial.trim();
        if (Utils.isValidNotZeroNumber(geoSerial, 6)) {
          String geoDesc = Geo.getGeoDesc(Integer.parseInt(geoSerial), geoFlag);
          if (!Utils.isEmpty(geoDesc)) {
            frm.set(GEO_DESC, geoDesc);
            isValid = true;
          }
        }
      }
    } catch (Exception ex) {
    }

    return isValid;
  }
示例#2
0
  public ActionForward execute(
      ActionMapping actionMapping,
      ActionForm actionForm,
      HttpServletRequest httpServletRequest,
      HttpServletResponse httpServletResponse) {
    LazyValidatorForm frm = (LazyValidatorForm) actionForm;
    resetFocusControl(frm, CANCEL);
    ActionMessages msgs = new ActionMessages();

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

    String geoFlag = (String) frm.get(GEO_FLAG);
    if (Utils.isEmpty(geoFlag)) {
      geoFlag = (String) httpServletRequest.getParameter(GEO_FLAG);
      frm.set(GEO_FLAG, geoFlag);
    }

    if (!formSaved(frm)) {
      setFormMode(frm, ((String) httpServletRequest.getParameter(BROWSE_ACTION)));
      setFormId(frm, (String) httpServletRequest.getParameter(BROWSE_ID));
      try {
        LoginInfo loginInfo = getLoginInfo(httpServletRequest);

        String geoFlagDesc = Misc.getHardCodeDesc(Constants.TableId.GEO_FLAG, geoFlag);
        frm.set(GEO_FLAG_DESC, geoFlagDesc);

        if (!loginInfo.userHasAccess("Geo_Conversion", getFormMode(frm))) {
          if (isFormInModifyMode(frm)
              && loginInfo.userHasAccess("Geo_Conversion", Constants.ActionType.ENQUERY)) {
            setFormMode(frm, Constants.ActionType.ENQUERY);
          } else {
            throw new Exception(INVALID_ACCESS);
          }
        }
        if (!geoFlag.equals(Constants.GeoFlag.VILLAGE)) {
          throw new Exception(INVALID_ACCESS);
        }
        if (!isFormInAddMode(frm)) {
          String formKey = (String) httpServletRequest.getParameter(BROWSE_KEY);
          GeoFormationInfo inf = Geo.getGeoFormationDetails(Integer.parseInt(formKey));
          frm.set(GEO_FORMATION_SERIAL, Integer.toString(inf.getGeoFormationSerial()));
          frm.set(GEO_SERIAL, Integer.toString(inf.getGeoSerial()));
          frm.set(APPROVAL_LETTER_NO, inf.getApprovalLetterNo());
          frm.set(APPROVAL_LETTER_DATE, DateUtils.revFormatDate(inf.getApprovalLetterDate()));
          frm.set(GEO_DESC, Geo.getGeoDesc(inf.getGeoSerial()));
        }
        frm.set(GEO_FLAG_DESC, geoFlagDesc);

        if (isFormInModifyMode(frm)) {
          resetFocusControl(frm, APPROVAL_LETTER_NO);
        }
      } catch (Exception ex) {
        addError(msgs, ex.getMessage());
        saveErrors(httpServletRequest, msgs);
      }
      return actionMapping.findForward(EDIT);
    } else {
      try {
        String geoFlagDesc = (String) frm.get(GEO_FLAG_DESC);
        if (!geoFlag.equals(Constants.GeoFlag.VILLAGE)) {
          addError(msgs, FIELD_CAN_NOT_BE_EMPTY, "علامت محل جغرافيايي");
          setFocusControl(frm, GEO_SERIAL);
        }
        GeoFormationInfo inf = new GeoFormationInfo();
        resetFocusControl(frm, "");
        if (isFormInDeleteMode(frm) || isFormInModifyMode(frm)) {
          String geoFormationSerial = ((String) frm.get(GEO_FORMATION_SERIAL)).trim();
          if (Utils.isEmpty(geoFormationSerial)) {
            addError(msgs, FIELD_CAN_NOT_BE_EMPTY, "سريال");
            setFocusControl(frm, GEO_SERIAL);
          } else if (!Utils.isValidNotZeroNumber(geoFormationSerial, 6)) {
            addError(msgs, FIELD_INVALID, "سريال");
            setFocusControl(frm, GEO_SERIAL);
          } else {
            inf.setGeoFormationSerial(Integer.parseInt(geoFormationSerial));
          }
        }

        if (isFormInAddMode(frm)) {
          String geoSerial = ((String) frm.get(GEO_SERIAL)).trim();
          if (Utils.isEmpty(geoSerial)) {
            addError(msgs, FIELD_CAN_NOT_BE_EMPTY, "سريال " + geoFlagDesc);
            setFocusControl(frm, GEO_SERIAL);
          }
          /*  else if (searchGeoDesc(frm, geoFlag) == false) {
            addError(msgs, FIELD_INVALID, "سريال " + geoFlagDesc);
            setFocusControl(frm, GEO_SERIAL);
          }  */
          else {
            inf.setGeoSerial(Integer.parseInt(geoSerial));
          }
        }

        if (!isFormInDeleteMode(frm)) {
          String approvalLetterNo = Utils.trimConvert((String) frm.get(APPROVAL_LETTER_NO));
          frm.set(APPROVAL_LETTER_NO, approvalLetterNo);
          if (Utils.isEmpty(approvalLetterNo)) {
            addError(msgs, FIELD_CAN_NOT_BE_EMPTY, "شماره تصويب نامه");
            setFocusControl(frm, APPROVAL_LETTER_NO);
          } else if (approvalLetterNo.length() > 20) {
            addError(msgs, FIELD_INVALID, "شماره تصويب نامه");
            setFocusControl(frm, APPROVAL_LETTER_NO);
          } else {
            inf.setApprovalLetterNo(approvalLetterNo);
          }

          String approvalLetterDate = ((String) frm.get(APPROVAL_LETTER_DATE)).trim();
          if (Utils.isEmpty(approvalLetterDate)) {
            addError(msgs, FIELD_CAN_NOT_BE_EMPTY, "تاريخ تصويب نامه");
            setFocusControl(frm, APPROVAL_LETTER_DATE);
          } else if (!DateUtils.isValidRevFormattedFDate(approvalLetterDate)) {
            addError(msgs, FIELD_INVALID, "تاريخ تصويب نامه");
            setFocusControl(frm, APPROVAL_LETTER_DATE);
          } else if (DateUtils.unformatRevFormattedFdate(approvalLetterDate)
                  .compareTo(DateUtils.fDate())
              > 0) {
            addError(msgs, FIELD_SHOULD_BE_LESS_THAN, "تاريخ تصويب نامه", "تاريخ روز");
            setFocusControl(frm, APPROVAL_LETTER_DATE);
          } else {
            inf.setApprovalLetterDate(DateUtils.unformatRevFormattedFdate(approvalLetterDate));
          }
        }

        if (!msgs.isEmpty()) {
          saveErrors(httpServletRequest, msgs);
          return actionMapping.findForward(EDIT);
        }
        resetFocusControl(frm, CANCEL);
        Geo.saveConversion(getFormMode(frm), inf, geoFlag);
        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);
      }
    }
  }