public int validateDate(FormItem formItem) {
    Date dt = ((CurrentTimeItem) formItem).getValueAsDate();
    if (dt == null) dt = DocFlow.getCurrentDate();
    trimDate(dt);
    Date now = DocFlow.getCurrentDate();
    trimDate(now);
    long ldt = dt.getTime();
    long lnow = now.getTime();

    ldt = trimDate(ldt);
    lnow = trimDate(lnow);
    if (ldt > lnow) return -1;

    String dayadds[] = docType.getDelayinterval().split(",");
    int warring = Integer.parseInt(dayadds[0]);
    int error = Integer.parseInt(dayadds[1]);
    int fatalerror = Integer.parseInt(dayadds[2]);
    long dayms = 1000 * 60 * 60 * 24;
    long errordate = lnow - (dayms * error);
    long fatalerrordate = lnow - (dayms * fatalerror);

    long warringdate = lnow - (dayms * warring);
    if (ldt <= fatalerrordate) return -2;
    if (ldt <= errordate) return 2;
    if (ldt <= warringdate) return 1;
    return 0;
  }
 public void setDocTypeId(int docType) {
   this.docTypeId = docType;
   bashConfirm.setDisabled(docType < 0);
   bashConfirm.setVisible(
       DocFlow.hasPermition(PermissionNames.CAN_CONFIRM_BASH)
           || (docType == 30 && DocFlow.hasPermition(PermissionNames.CAN_CONFIRM_BASH_COEF)));
 }
 public ArrayList<String> createCriteria() {
   ArrayList<String> criterias = new ArrayList<String>();
   criterias.add("system_id=" + DocFlow.system_id);
   addCriteria(criterias, tiUserName, "user_name='%s'", "");
   addCriteria(criterias, addrComp.getSiRegion(), "regionid=%s", "-1");
   addCriteria(criterias, addrComp.getSiSubregion(), "subregionid=%s", "-1");
   addCriteria(criterias, addrComp.getSiCity(), "cityid=%s", "-1");
   addCriteria(criterias, iiZona, "czona=%s", "");
   addCriteria(criterias, siDocStatus, "doc_status_id=%s", "-1");
   addCriteria(criterias, iiCustomer, "cust_id=%s", "");
   addCriteria(criterias, tiContent, "content_xml like '%%s%'", "");
   addCriteria(criterias, tiDocId, "id::character varying like '%s%'", "");
   addCriteria(criterias, tiCancelary, "cancelary_nom like '%%s%'", "");
   String doctypeFilter = "doc_type_id=" + docTypeId;
   if (docTypeId <= 0) doctypeFilter = "group_id=" + Math.abs(docTypeId);
   criterias.add(doctypeFilter);
   if (!DocFlow.hasPermition(PermissionNames.VIEW_ALL_DOCUMENTS))
     criterias.add("user_id=" + DocFlow.user_id);
   return criterias;
 }
  public FormDefinitionPanel(
      FormDefinition definition,
      FieldDefinitionListValue listValue,
      DocType docType,
      DocPanelSettingDataComplete dataComplete) {
    super();
    this.listValue = listValue;
    this.dataComplete = dataComplete;
    this.docType = docType;
    this.setWidth100();
    this.setHeight100();
    ArrayList<FormGroup> formGroups = definition.getFormGroups();
    formitemMap = new HashMap<String, FieldDefinitionItem>();
    ArrayList<MyDynamicForm> dynFields = new ArrayList<MyDynamicForm>();
    for (FormGroup formGroup : formGroups) {
      ArrayList<FieldDefinition> fields = formGroup.getFieldDefinitions();
      MyDynamicForm dynamicForm = new MyDynamicForm();
      dynamicForm.setNewLine(formGroup.getNewLine() == 1);
      ArrayList<FormItem> items = new ArrayList<FormItem>();
      for (FieldDefinition fieldDefinition : fields) {
        FieldDefinitionItem fi = createField(fieldDefinition);
        if (fi != null) {
          items.add(fi.getFormItem());
          if (fieldDefinition.isFieldReadOnly()) fi.getFormItem().setCanEdit(false);
          formitemMap.put(fieldDefinition.getFieldName(), fi);
        }
      }

      //
      dynamicForm.setAlign(Alignment.LEFT);
      switch (formGroup.getLabelOrientation()) {
        case FormGroup.FTORIENTATION_LEFT:
          dynamicForm.setTitleOrientation(TitleOrientation.LEFT);
          break;
        case FormGroup.FTORIENTATION_TOP:
          dynamicForm.setTitleOrientation(TitleOrientation.TOP);
          break;
        case FormGroup.FTORIENTATION_RIGHT:
          dynamicForm.setTitleOrientation(TitleOrientation.RIGHT);
          break;
        default:
          break;
      }

      int numofColumns = 0;
      if (definition.isHorizontal()) {
        numofColumns = formGroup.getNumofColumns() > 0 ? formGroup.getNumofColumns() : 1;
      } else {

        numofColumns = formGroup.getNumofColumns() > 0 ? formGroup.getNumofColumns() : items.size();
      }
      numofColumns =
          numofColumns * (formGroup.getLabelOrientation() == FormGroup.FTORIENTATION_TOP ? 1 : 2);
      dynamicForm.setNumCols(numofColumns);

      if (formGroup.getGroupHeight() != null && !formGroup.getGroupHeight().isEmpty()) {
        dynamicForm.setHeight(formGroup.getGroupHeight());
      }

      if (formGroup.getGroupWidth() != null && !formGroup.getGroupWidth().isEmpty()) {
        dynamicForm.setWidth(formGroup.getGroupWidth());
      }
      dynamicForm.setFields(items.toArray(new FormItem[] {}));
      dynFields.add(dynamicForm);
      if (formGroup.getGroupTitle() != null && formGroup.getGroupTitle().length() > 0) {
        dynamicForm.setIsGroup(true);
        dynamicForm.setGroupTitle(
            DocFlow.getCaption(formGroup.getFieldCaptionId(), formGroup.getGroupTitle()));
      }
      // this.addMember(dynamicForm);
      listValue.setFieldDefinitionListValue(formitemMap, this);
    }
    Layout container = this;
    if (definition.isHorizontal()) {
      container = createNewPanel();
    }

    for (MyDynamicForm dynamicForm : dynFields) {
      if (dynamicForm.isNewLine()) {
        container = createNewPanel();
      }
      container.addMember(dynamicForm);
    }

    Set<String> fieldKeys = formitemMap.keySet();

    for (String key : fieldKeys) {
      final FieldDefinitionItem item = formitemMap.get(key);
      FieldDefinition fieldDef = item.getFieldDef();
      if (fieldDef.getCalculatorClass() != null) {
        final ICalculatorClass classCalculator =
            listValue.getCalculetorClass(fieldDef.getCalculatorClass());
        if (classCalculator != null) {
          item.getFormItem()
              .addChangedHandler(
                  new ChangedHandler() {
                    @Override
                    public void onChanged(ChangedEvent event) {
                      classCalculator.calculate(formitemMap, item);
                    }
                  });
        }
      }
      if (fieldDef.isClearComboValue()) {
        PickerIcon eraserValuePicker =
            new PickerIcon(
                new Picker("eraser.png"),
                new FormItemClickHandler() {
                  public void onFormItemClick(FormItemIconClickEvent event) {
                    item.getFormItem().setValue((Object) null);
                    fireChangedEvent(item.getFormItem());
                  }
                });
        item.getFormItem().setIcons(eraserValuePicker);
      }

      if ((fieldDef.getFieldType() == FieldDefinition.FT_COMBO
          || fieldDef.getFieldType() == FieldDefinition.FT_SELECTION)) {
        if (fieldDef.getFieldSelectMethode() > 0) {
          String depFields = fieldDef.getDependencyFields();
          depFields = depFields == null ? "" : depFields;
          final String[] depFieldNames = depFields.split(";");
          final String parent_type = fieldDef.getFieldSelectMethode() + "";
          if (depFieldNames.length > 0 && depFieldNames[0].length() > 0) {
            item.getFormItem()
                .addChangedHandler(
                    new ChangedHandler() {
                      @Override
                      public void onChanged(ChangedEvent event) {
                        if (settingMyself) return;
                        try {
                          settingMyself = true;
                          comboValueChanged(depFieldNames, event.getValue(), parent_type);
                        } finally {
                          settingMyself = false;
                        }
                      }
                    });
          }
        }
      }
    }
  }
  public void setData(
      HashMap<String, String> values, long customer_id, HashMap<String, String> displayValues) {
    if (displayValues == null) displayValues = new HashMap<String, String>();
    newData = true;
    Set<String> fieldKeys = formitemMap.keySet();
    for (String key : fieldKeys) {
      FieldDefinitionItem item = formitemMap.get(key);
      FieldDefinition fieldDef = item.getFieldDef();
      if (fieldDef.getFieldType() == FieldDefinition.FT_IMAGE_ITEM
          && displayValues.containsKey(key))
        ((ImageItem) item.getFormItem()).setDisplayValue(displayValues.get(key));

      if ((fieldDef.getFieldType() == FieldDefinition.FT_COMBO
          || fieldDef.getFieldType() == FieldDefinition.FT_SELECTION
          || fieldDef.getFieldType() == FieldDefinition.FT_CHK_GRID)) {
        String val = fieldDef.getDefaultValue();
        if (val != null && val.trim().length() > 0) {
          val = val.trim();
          if (DocFlow.hasPermition("CAN_VIEW_ALL_REGIONS")
              && (val.toLowerCase().equals("$regionId".toLowerCase())
                  || val.toLowerCase().equals("$subregionId".toLowerCase()))) {
            if (values.get(key) != null) continue;
          }
          if (val.toLowerCase().equals("$regionId".toLowerCase())
              && DocFlow.user_obj.getUser().getRegionid() >= 0) {
            values.put(key, "" + DocFlow.user_obj.getUser().getRegionid());
            if (!item.getFieldDef().isFieldReadOnly())
              item.getFormItem().setDisabled(!DocFlow.hasPermition("CAN_VIEW_ALL_REGIONS"));
          }
          if (val.toLowerCase().equals("$subregionId".toLowerCase())
              && DocFlow.user_obj.getUser().getSubregionid() >= 0) {
            values.put(key, "" + DocFlow.user_obj.getUser().getSubregionid());
            if (!item.getFieldDef().isFieldReadOnly())
              item.getFormItem().setDisabled(!DocFlow.hasPermition("CAN_VIEW_ALL_REGIONS"));
          }
        }
      }
      setDefaultValue(fieldDef, item.getFormItem());
    }

    HashMap<String, String> listSqls = new HashMap<String, String>();
    for (String key : fieldKeys) {
      FieldDefinitionItem item = formitemMap.get(key);
      FieldDefinition fieldDef = item.getFieldDef();

      if (fieldDef.getFieldType() == FieldDefinition.FT_COMBO
          || fieldDef.getFieldType() == FieldDefinition.FT_SELECTION
          || fieldDef.getFieldType() == FieldDefinition.FT_CHK_GRID) {
        String value = "";
        if (fieldDef.getFieldSelectMethode() > 0) {
          value = fieldDef.getFieldSelectMethode() + "";
          String parentField = fieldDef.getParentField();
          parentField = parentField == null ? "" : parentField;
          if (parentField.length() != 0) {
            FieldDefinitionItem pItem = formitemMap.get(parentField);
            String parent_id = values.get(parentField);
            if (parent_id == null || parent_id.trim().length() == 0) {
              parent_id = "-1";
            }
            parent_id = parent_id.trim();

            if (pItem != null && pItem.getFieldDef() != null)
              value += "_" + pItem.getFieldDef().getFieldSelectMethode() + "_" + parent_id;
          }

        } else value = fieldDef.getFieldSelectionSQL();
        if (value == null || value.length() < 1) continue;
        listSqls.put(key, value);
      }
    }

    getRemouteValues(values, customer_id, listSqls, true);
  }
  @SuppressWarnings("deprecation")
  private void setData(HashMap<String, String> values) {
    Set<String> keys = formitemMap.keySet();
    if (values == null) {
      values = new HashMap<String, String>();
    }
    for (String key : keys) {
      Object obj = values == null ? null : values.get(key);
      FieldDefinitionItem item = formitemMap.get(key);
      if (item == null) continue;
      if (!item.getFieldDef().isFieldReadOnly())
        item.getFormItem().setCanEdit(true); // .setAttribute("readOnly",
      // false);
      if (item.getFormItem() instanceof CurrentTimeItem) {
        if (obj != null) {
          try {
            Long lng = Long.parseLong(obj.toString());
            item.getFormItem().setValue(new Date(lng.longValue()));
          } catch (Exception e) {
            try {
              Date dt = new Date(obj.toString());
              item.getFormItem().setValue(dt);
            } catch (Exception e2) {
              item.getFormItem().setValue(DocFlow.getCurrentDate());
            }
          }
        } else item.getFormItem().setValue(DocFlow.getCurrentDate());
      }
      if (item.getFormItem() instanceof CheckboxItem) {
        try {
          Integer lng = Integer.parseInt(obj.toString());
          item.getFormItem().setValue(lng.intValue() == 1);
        } catch (Exception e) {
          // TODO: handle exception
        }
      }
      Object val = obj;
      if (val == null
          && item.getFieldDef().getDefaultValue() != null
          && item.getFieldDef().getDefaultValue().trim().length() > 0) {
        val = item.getFieldDef().getDefaultValue().trim();
        if (val.toString().startsWith("$")) val = null;
      }
      if (item.getFieldDef().getFieldType() == FieldDefinition.FT_DATE
          && item.getFormItem() instanceof CurrentTimeItem
          && val != null) {
        try {
          Long lng = Long.parseLong(val.toString());
          val = new Date(lng);
        } catch (Exception e) {
          // TODO: handle exception
        }
      }
      if (item.getFieldDef().getFieldType() == FieldDefinition.FT_BOOLEAN
          && item.getFormItem() instanceof CheckboxItem) {
        try {
          if (val == null) val = new Boolean(false);
          else {
            Long lng = Long.parseLong(val.toString());
            val = new Boolean(lng == 1);
          }
        } catch (Exception e) {
          // TODO: handle exception
        }
      }
      item.getFormItem().setValue(val);
      // if (item.getFieldDef().isCalculateOnSet())
      // setCalculatorCalculate(item);

    }
    if (dataComplete != null && newData) {
      newData = false;
      dataComplete.settingDataComplete();
    }
  }
 private FieldDefinitionItem createField(FieldDefinition field) {
   FormItem fi = null;
   switch (field.getFieldType()) {
     case FieldDefinition.FT_STRING:
       fi = new TextItem();
       break;
     case FieldDefinition.FT_INTEGER:
       fi = new IntegerItem();
       break;
     case FieldDefinition.FT_DOUBLE:
       fi = new FloatItem();
       break;
     case FieldDefinition.FT_BOOLEAN:
       fi = new CheckboxItem();
       break;
     case FieldDefinition.FT_TEXTAREA:
       fi = new TextAreaItem();
       // fi.setWidth("10000px");
       break;
     case FieldDefinition.FT_STATICTEXT:
       fi = new StaticTextItem();
       break;
     case FieldDefinition.FT_COMBO:
       fi = new ComboBoxItem();
       if (field.isNoUnknownValueComboValue())
         ((ComboBoxItem) fi).setAddUnknownValues(!field.isNoUnknownValueComboValue());
       break;
     case FieldDefinition.FT_SELECTION:
       fi = new SelectItem();
       if (field.isNoUnknownValueComboValue())
         ((SelectItem) fi).setAddUnknownValues(!field.isNoUnknownValueComboValue());
       break;
     case FieldDefinition.FT_DATE:
       fi = new CurrentTimeItem();
       break;
     case FieldDefinition.FT_CHK_GRID:
       fi = new ChkGridItem();
       break;
     case FieldDefinition.FT_MAP_ITEM:
       fi = new MapButton(this, field);
       break;
     case FieldDefinition.FT_IMAGE_ITEM:
       fi = new ImageItem(this, field);
       break;
     case FieldDefinition.FT_CUSTOM:
       fi = new CanvasItem();
       break;
     default:
       break;
   }
   if (fi == null) {
     return null;
   }
   fi.setTitle(DocFlow.getCaption(field.getFieldCaptionId(), field.getFieldCaption()));
   if (field.getFieldWidth() != null && !field.getFieldWidth().isEmpty()) {
     fi.setWidth(field.getFieldWidth());
   }
   if (field.getFieldHeight() != null && !field.getFieldHeight().isEmpty()) {
     fi.setHeight(field.getFieldHeight());
   }
   if (field.isFieldReadOnly()) {
     if (field.getFieldType() == FieldDefinition.FT_COMBO
         || field.getFieldType() == FieldDefinition.FT_SELECTION
         || field.getFieldType() == FieldDefinition.FT_DATE) fi.setCanEdit(false);
     else fi.setCanEdit(false);
   }
   setDefaultValue(field, fi);
   if (field.isHidden()) fi.setVisible(false);
   if (field.isDisabled()) {
     fi.setDisabled(true);
   }
   return new FieldDefinitionItem(field, fi);
 }
 public void setCurrentDate() {
   diStart.setValue(DocFlow.getCurrentDate());
   diEnd.setValue(new Date(DocFlow.currenttime + (1000 * 60 * 60 * 24)));
 }
示例#9
0
  public PZoneChange() {
    restrictedEdits = DocFlow.user_obj.getZoneConfiguration().getRestricted_edits();
    CHARCOUNT = DocFlow.user_obj.getZoneConfiguration().getCharcount();
    tsMain = new ToolStrip();
    tsMain.setWidth100();
    HashMap<String, String> listSqls = new HashMap<String, String>();
    listSqls.put("" + ClSelection.T_REGION, "" + ClSelection.T_REGION);
    listSqls.put("" + ClSelection.T_CUST_TYPE, "" + ClSelection.T_CUST_TYPE);
    dsZoneDS = DocFlow.getDataSource("ZoneDS");
    dsCustomer = DocFlow.getDataSource("CustomerDS");
    miSearch = new ToolStripButton("Search");
    tiNewZone = new TextItem("newzone", "New Zone");
    biSaveData = new ButtonItem("saveData", "Change Zone");

    tiNewZone.addKeyPressHandler(
        new KeyPressHandler() {

          @Override
          public void onKeyPress(KeyPressEvent event) {
            newZoneKeyPressed(event);
          }
        });
    VLayout vl = new VLayout();

    dmCriteria = new DynamicForm();
    dmCriteria.setNumCols(4);
    dmCriteria.setHeight("8%");
    dmCriteria.setTitleOrientation(TitleOrientation.TOP);
    siCustomerType = new SelectItem("custypeid", "Customer Type");
    siZones = new SelectItem("zones", "Zones");
    siZones.setValueField("zone");
    siZones.setAutoFetchData(false);
    siZones.setDisplayField("zone");
    siZones.setOptionDataSource(dsZoneDS);

    tsMain.setHeight("15");
    vl.addMember(tsMain);
    tsMain.addButton(miSearch);
    vl.addMember(dmCriteria);
    lgCustomers = new ListGrid();
    lgCustomers.setDataSource(dsCustomer);
    lgCustomers.setAutoFetchData(false);
    lgCustomers.setShowResizeBar(false);
    lgCustomers.setCanDragRecordsOut(true);
    lgCustomers.setDragDataAction(DragDataAction.COPY);
    lgCustomers.setHeight100();
    lgCustomers.setHeight100();

    DataSource dsSelectedData = new DataSource();
    dsSelectedData.setClientOnly(true);

    DataSourceIntegerField dsfcusid = new DataSourceIntegerField("cusid", "Customer ID");
    dsfcusid.setPrimaryKey(true);

    DataSourceTextField dsZone = new DataSourceTextField("zone", "Zone");
    dsSelectedData.setFields(dsfcusid, dsZone);

    lgZoneCustomers = new ListGrid();
    lgZoneCustomers.setDataSource(dsSelectedData);
    lgZoneCustomers.setAutoFetchData(false);
    lgZoneCustomers.setCanAcceptDroppedRecords(true);
    lgZoneCustomers.setCanRemoveRecords(true);
    lgZoneCustomers.setAutoFetchData(false);
    lgZoneCustomers.setPreventDuplicates(true);
    lgZoneCustomers.setHeight100();
    lgZoneCustomers.setWidth100();

    HStack hStack = new HStack(10);
    hStack.setWidth100();
    hStack.setHeight100();
    hStack.setShowEdges(true);

    VStack vStack = new VStack();
    vStack.setHeight100();
    vStack.setWidth("60%");
    vStack.addMember(lgCustomers);
    hStack.addMember(vStack);
    TransferImgButton arrowImg = new TransferImgButton(TransferImgButton.RIGHT);
    arrowImg.addClickHandler(
        new ClickHandler() {
          public void onClick(ClickEvent event) {
            lgZoneCustomers.transferSelectedData(lgCustomers);
          }
        });

    TransferImgButton arrowImgLeft = new TransferImgButton(TransferImgButton.LEFT);
    arrowImgLeft.addClickHandler(
        new ClickHandler() {
          public void onClick(ClickEvent event) {
            lgZoneCustomers.removeSelectedData();
          }
        });
    hStack.addMember(arrowImg);
    hStack.addMember(arrowImgLeft);
    VStack vStack2 = new VStack();
    vStack2.setHeight100();
    vStack2.setWidth("40%");
    vStack2.addMember(lgZoneCustomers);
    hStack.addMember(vStack2);

    miSearch.addClickHandler(
        new ClickHandler() {

          @Override
          public void onClick(ClickEvent event) {
            search();
          }
        });

    lgCustomers.addClickHandler(
        new com.smartgwt.client.widgets.events.ClickHandler() {

          @Override
          public void onClick(com.smartgwt.client.widgets.events.ClickEvent event) {}
        });

    vl.addMember(hStack);

    this.addMember(vl);
    DocFlow.docFlowService.getListTypesForDocument(
        listSqls,
        -1,
        new AsyncCallback<HashMap<String, ArrayList<ClSelectionItem>>>() {

          @Override
          public void onFailure(Throwable caught) {
            setResults(null);
          }

          @Override
          public void onSuccess(HashMap<String, ArrayList<ClSelectionItem>> result) {

            setResults(result);
          }
        });
  }