@Override
  public DGuiValidation validateForm() {
    String message = "";
    DDbDpsSeriesNumber dpsSeriesNumber =
        DTrnUtils.getDpsSeriesNumber(
            miClient.getSession(),
            moRegistry.getDpsTypeKey(),
            moTextSeries.getValue(),
            moIntNumber.getValue());
    DGuiValidation validation = moFields.validateFields();

    if (validation.isValid()) {
      if (DLibTimeUtils.digestYear(moDateDate.getValue())[0] != mnOriginalYear) {
        validation.setMessage(
            DGuiConsts.ERR_MSG_FIELD_DATE_
                + "'"
                + DGuiUtils.getLabelName(jlDateDate.getText())
                + "'"
                + DGuiConsts.ERR_MSG_FIELD_DATE_YEAR
                + DLibUtils.DecimalFormatCalendarYear.format(mnOriginalYear)
                + ".");
        validation.setComponent(moDateDate);
      } else if (dpsSeriesNumber != null
          && dpsSeriesNumber.getApprobationDate_n() != null
          && dpsSeriesNumber.getApprobationDate_n().after(moDateDate.getValue())) {
        validation.setMessage(
            DGuiConsts.ERR_MSG_FIELD_DATE_
                + "'"
                + DGuiUtils.getLabelName(jlDateDate.getText())
                + "'"
                + DGuiConsts.ERR_MSG_FIELD_DATE_GREAT_EQUAL
                + DLibUtils.DateFormatDate.format(dpsSeriesNumber.getApprobationDate_n())
                + ", fecha de aprobación de los folios del documento.");
        validation.setComponent(moDateDate);
      } else {
        // Validate document number:

        if (validation.isValid()) {
          moRegistry.setSeries(moTextSeries.getValue());
          moRegistry.setNumber(moIntNumber.getValue());

          message = DTrnUtils.validateNumberForDps(miClient.getSession(), moRegistry);
          if (!message.isEmpty()) {
            validation.setMessage(message);
            validation.setComponent(moIntNumber);
          } else if (moRegistry.isRegistryNew()
              && DTrnUtils.isDpsNumberAutomatic(moRegistry.getDpsClassKey())) {
            moIntNumber.setValue(moRegistry.getNumber()); // new document number could be updated
          }
        }
      }
    }

    return validation;
  }
  @Override
  public void setRegistry(DDbRegistry registry) throws Exception {
    moRegistry = (DDbDps) registry;

    mnFormResult = DLibConsts.UNDEFINED;
    mbFirstActivation = true;

    // Set registry:

    removeAllListeners();
    reloadCatalogues();

    if (moRegistry.isRegistryNew()) {
      throw new Exception(DGuiConsts.ERR_MSG_FORM_EXIST_REG);
    } else {
      jtfRegistryKey.setText("");
    }

    setFormEditable(true); // enable all controls before setting form values

    mtOriginalDate = moRegistry.getDate();
    mnOriginalYear = DLibTimeUtils.digestYear(mtOriginalDate)[0];

    moTextSeries.setValue(moRegistry.getSeries());
    moIntNumber.setValue(moRegistry.getNumber());
    moDateDate.setValue(mtOriginalDate);
    moKeyEmissionType.setValue(new int[] {moRegistry.getFkEmissionTypeId()});

    jtfDocType.setText(
        (String)
            miClient
                .getSession()
                .readField(
                    DModConsts.TS_DPS_TP, moRegistry.getDpsTypeKey(), DDbRegistry.FIELD_NAME));
    jtfDocType.setCaretPosition(0);

    moPanelDps.setValue(DModSysConsts.PARAM_YEAR, mnOriginalYear);
    moPanelDps.setRegistry(moRegistry);

    moTextSeries.setEditable(false);
    moDateDate.setEditable(false);

    addAllListeners();
  }
  @Override
  public DDbDpsSigning getRegistry() throws Exception {
    DDbDpsSigning registry = moRegistry.createDpsSigning();

    if (registry.isRegistryNew()) {}

    registry.setSeries(moTextSeries.getValue());
    registry.setNumber(moIntNumber.getValue());
    // registry.setOrder(?);
    registry.setDate(moDateDate.getValue());
    // registry.setDeleted(?);
    registry.setFkEmissionTypeId(moKeyEmissionType.getValue()[0]);
    // registry.setFkDpsCategoryId(?);
    // registry.setFkDpsClassId(?);
    // registry.setFkDpsTypeId(?);

    return registry;
  }