private void _doProcessRecord(JsonStoreMetadata metadata, JsonStoreRow row) {
   var conn = this.dbSess.GetConnection();
   try {
     var vCmd = new CJSCursor(conn, this._exec_ds, this._request.ExecBioCode);
     vCmd.DoExecuteSQL(metadata, row, this._request.BioParams, 120);
   } finally {
     if (conn != null)
       conn.Close();
   }
 }
 public object Clone() {
   var rslt = new JsonStoreMetadata();
   rslt.CopyFrom(this);
   return rslt;
 }
 public static JsonStoreRow CreateNewRow(JsonStoreMetadata metadata) {
   var newRow = new JsonStoreRow { InternalROWUID = Guid.NewGuid().ToString("N"), ChangeType = JsonStoreRowChangeType.Unchanged };
   if (metadata != null) {
     foreach (var fd in metadata.Fields)
       newRow.Values.Add(null);
   }
   return newRow;
 }
    /*
    /// <summary>
    /// Формирует описание структуры JSON-ответа для клиентского JsonStore из XML-описания.
    /// </summary>
    /// <param name="pCursorDef">XML-описание курсора.</param>
    /// <param name="jw">Объект LisJson.JsonWriter, в который запишутся метаданные.</param>
    public static JsonStoreMetadata ConstructMetadata(XPathNavigator cursorDef) {
      JsonStoreMetadata vResult = new JsonStoreMetadata();
      vResult.fields = new List<JsonStoreMetadataFieldDef>();
      XPathNodeIterator xmlFields = cursorDef.Select("fields/field[not(@generate) or (@generate='true')]");
      if (xmlFields == null || xmlFields.Count <= 0)
        return vResult;
       
      if (cursorDef.SelectSingleNode("fields/field/@pk") != null) {
        vResult.fields.Add(new JsonStoreMetadataFieldDef() {
          name = csPKFieldName,
          type = CJsonStoreMetadataFieldType.ftString,
          hidden = true
        });
      }
      while (xmlFields.MoveNext()){
        XPathNavigator curNode = xmlFields.Current;
        JsonStoreMetadataFieldDef fldDef = new JsonStoreMetadataFieldDef();
        fldDef.name = Xml.getAttribute(curNode, "name");
        if (String.IsNullOrEmpty(fldDef.name))
          continue;
        fldDef.hidden = String.Equals(Xml.getAttribute(curNode, "hidden"), "true");
        fldDef.header = Xml.getAttribute(curNode, "header");
        fldDef.type = detectFieldType(Xml.getAttribute(curNode, "type"));
        String v_group_str = Xml.getAttribute(curNode, "group");
        fldDef.group = Int32.Parse(!String.IsNullOrEmpty(v_group_str) ? v_group_str : "-1");
        fldDef.group_aggr = curNode.GetAttribute("group_aggr", null);
        int pkIndx = Int32.Parse(Xml.hasAttribute(curNode, "pk") ? Xml.getAttribute(curNode, "pk") : "0");
        String boolVals = Xml.getAttribute(curNode, "boolVals");
        String defaultVal = Xml.getAttribute(curNode, "defaultVal");
        //if (fldDef.type == "currency") fldDef.Type = "float";
        if (pkIndx > 0)
          fldDef.pk = pkIndx;
        if (fldDef.type == CJsonStoreMetadataFieldType.ftDate)
          fldDef.dateFormat = "Y-m-d\\TH:i:s";
        else if (fldDef.type == CJsonStoreMetadataFieldType.ftBoolean && !String.IsNullOrEmpty(boolVals))
          fldDef.boolVals = boolVals;
        if (!String.IsNullOrEmpty(defaultVal) && fldDef.type != CJsonStoreMetadataFieldType.ftDate)
          if (fldDef.type == CJsonStoreMetadataFieldType.ftBoolean)
            fldDef.defaultVal = Utl.Convert2Type<Boolean>(defaultVal);
          else if (fldDef.type == CJsonStoreMetadataFieldType.ftString)
            fldDef.defaultVal = defaultVal;
          else
            fldDef.defaultVal = Utl.Convert2Type<Double>(defaultVal);
        vResult.fields.Add(fldDef);
      }
      return vResult;
    }
    */
#endif

#if !SILVERLIGHT
    /// <summary>
    /// Формирует описание структуры JSON-ответа для клиентского JsonStore из объекта System.Data.DataTable.
    /// </summary>
    /// <param name="table">Объект System.Data.DataTable, из которого нужно взять структуру.</param>
    public static JsonStoreMetadata ConstructMetadata(DataTable table) {
      JsonStoreMetadata vResult = new JsonStoreMetadata();
      vResult.Fields = new List<JsonStoreMetadataFieldDef>();
      if (table == null || table.Columns.Count <= 0)
        return vResult;
      foreach (DataColumn col in table.Columns) {
        //if (col.ColumnName == CExParams.C_RowNumberFieldName)
        //  continue;
        JsonStoreMetadataFieldDef fldDef = new JsonStoreMetadataFieldDef();
        fldDef.Name = col.ColumnName.ToUpper();
        fldDef.Type = jsonUtl.detectFieldType(ftypeHelper.ConvertTypeToStr(col.DataType).ToLower());
        var boolVals = (col.ExtendedProperties.ContainsKey("boolVals")) ? (String)col.ExtendedProperties["boolVals"] : null;
        if (fldDef.Type == JSFieldType.Date)
          fldDef.Format = "Y-m-d\\TH:i:s";
        else if (fldDef.Type == JSFieldType.Boolean && !String.IsNullOrEmpty(fldDef.BoolVals))
          fldDef.BoolVals = boolVals;
        if (col.DefaultValue != DBNull.Value && fldDef.Type != JSFieldType.Date)
          fldDef.DefaultVal = col.DefaultValue;
        vResult.Fields.Add(fldDef);
      }
      return vResult;
    }
 public void CopyFrom(JsonStoreMetadata mdata) {
   this.ID = mdata.ID;
   if (this.Fields == null)
     this.Fields = new List<JsonStoreMetadataFieldDef>();
   this.Fields.Clear();
   foreach (JsonStoreMetadataFieldDef fd in mdata.Fields) {
     var newFld = new JsonStoreMetadataFieldDef() {
       Name = fd.Name,
       Type = fd.Type,
       PK = fd.PK,
       DefaultVal = fd.DefaultVal,
       Format = fd.Format,
       Align = fd.Align,
       BoolVals = fd.BoolVals,
       Hidden = fd.Hidden,
       Header = fd.Header,
       Group = fd.Group,
       GroupAggr = fd.GroupAggr,
       ReadOnly = fd.ReadOnly,
       Width = fd.Width
     };
     this.Fields.Add(newFld);
   }
 }
    private void _load (
      CJSRequestGetType getType,
      Params bioPrms, 
      AjaxRequestDelegate callback, 
      JsonStoreFilter locate, 
      Int64? pageSize,
      Int64? startFrom,
      String selection
    ) {
      var v_selection = selection;
      var v_locate = locate;
      if (pageSize.HasValue)
        this.PageSize = pageSize.Value;
      if (startFrom.HasValue)
        this.StartFrom = startFrom.Value;

      if (this.AjaxMng == null)
        throw new EBioException("Свойство \"ajaxMng\" должно быть определено!");
      if (String.IsNullOrEmpty(this.BioCode))
        throw new EBioException("Свойство \"bioCode\" должно быть определено!");

      this._doBeforLoadData(bla => {
        if (bla.Cancel) {
          return;
        }
        if (bioPrms != null) {
          if (this.BioParams == null)
            this.BioParams = bioPrms.Clone() as Params;
          else {
            this.BioParams.Clear();
            this.BioParams = this.BioParams.Merge(bioPrms, true);
          }
        } else {
          if (this.BioParams == null)
            this.BioParams = new Params();
        }

        var isMetadataObsolete = false;
        var isFirstLoad = false;
        this._detectIsFirstLoad(this.BioCode, this.BioParams, ref isMetadataObsolete, ref isFirstLoad);
        if (isFirstLoad) {
          this.StartFrom = 0;
        }

        this._lastRequestedBioCode = this.BioCode;
        JsonStoreSort sortDefinition = null;
        if (!isMetadataObsolete && (this.DS0 != null)) {
          var cv = (this.DS0 as ICollectionView);
          if (cv != null)
            sortDefinition = this._genJSSortDefinition(cv.SortDescriptions);
        }

        this._lastRequestedParams = (Params)this.BioParams.Clone();
        var reqst = new JsonStoreRequestGet {
          BioCode = this.BioCode,
          getType = getType,
          BioParams = this.BioParams,
          Prms = null,
          Packet = new JsonStoreData {
            Limit = this.PageSize,
            Start = this.StartFrom,
            IsFirstLoad = isFirstLoad,
            IsMetadataObsolete = isMetadataObsolete,
            Locate = v_locate
          },
          Sort = sortDefinition,
          selection = v_selection,
          Callback = (sndr, args) => {
            try {
              Type rowType = null;
              var rq = (JsonStoreRequest)args.Request;
              var rsp = args.Response as JsonStoreResponse;
              if (rsp != null) {
                if ((rsp.packet != null) && (rsp.packet.Rows != null)) {
                  if (BioGlobal.Debug) {
                    if (rsp.Ex != null)
                      throw new EBioException("Unhandled exception!!!! silent:[" + rq.Silent + "]", rsp.Ex);
                  }
                  if (rq.Packet.IsMetadataObsolete) {
                    this._metadata = rsp.packet.MetaData;
                    var fldDefs = _creFldDefsRmt(this._metadata);
                    rowType = this._creRowType(fldDefs);
                    this.DS0 = this._creDSInst(rowType);
                  }

                  this._doOnJsonStoreResponseSuccess(rq, rsp);

                  this._loadDS(rowType, rsp);

                  this._doOnJsonStoreDSLoaded(this.DS0, rq, rsp);

                  if (rq.Packet.Locate != null) 
                    this._lastLocatedRow = this._locateInternal(rq.Packet.Locate);

                } else {
                  if (BioGlobal.Debug) {
                    var m = "Bad response: ";
                    if (rsp.packet == null)
                      m = m + "rsp.packet=null;";
                    else if (rsp.packet.Rows == null)
                      m = m + "rsp.packet.rows=null;";
                    throw new EBioException(m);
                  }
                }
              } else {
                //if (BioGlobal.Debug) {
                //  var biorsp = args.Response as BioResponse;
                //  if (biorsp == null)
                //    throw new EBioException("Bad response: biorsp=null");
                //}
              }
            } finally {
              this._doOnAfterLoadData(args);
              if (callback != null) callback(this, args);
            }
          }
        };
        this.AjaxMng.Request(reqst);


      });
    }
    /// <summary>
    /// Формирует описание структуры JSON-ответа для клиентского JsonStore из XML-описания.
    /// </summary>
    /// <param name="bioCode"/>
    /// <param name="cursorDef">XML-описание курсора.</param>
    public static JsonStoreMetadata ConstructMetadata(String bioCode, XmlNode cursorDef) {
      JsonStoreMetadata vResult = new JsonStoreMetadata();
      vResult.Fields = new List<JsonStoreMetadataFieldDef>();
      vResult.ReadOnly = Xml.getAttribute<Boolean>(cursorDef as XmlElement, "readOnly", true);
      vResult.Multiselection = Xml.getAttribute<Boolean>(cursorDef as XmlElement, "multiselection", false);
      XmlNodeList xmlFields = cursorDef.SelectNodes("fields/field[not(@generate) or (@generate='true')]");
      if (xmlFields == null || xmlFields.Count <= 0)
        return vResult;

      foreach (XmlElement xmlEl in xmlFields) {
        String v_field_name = xmlEl.GetAttribute("name");
        if (vResult.IndexOf(v_field_name) >= 0)
          throw new EBioException(String.Format("В описании объекта {0} поле {1} определено более 1 раза.", bioCode, v_field_name));
        JsonStoreMetadataFieldDef fldDef = new JsonStoreMetadataFieldDef();
        if (xmlEl.HasAttribute("generate") && xmlEl.GetAttribute("generate") != "true")
          continue;

        fldDef.Name = v_field_name;
        if (String.IsNullOrEmpty(fldDef.Name))
          continue;

        fldDef.Header = xmlEl.GetAttribute("header");
        if (!String.IsNullOrEmpty(fldDef.Header))
          fldDef.Header = fldDef.Header.Replace("\\n", "\n");
        fldDef.Hidden = Xml.getAttribute<Boolean>(xmlEl, "hidden", false);
        fldDef.ReadOnly = Xml.getAttribute<Boolean>(xmlEl, "readOnly", vResult.ReadOnly);
        fldDef.Type = jsonUtl.detectFieldType(xmlEl.GetAttribute("type"));
        fldDef.Width = Xml.getAttribute<Int32>(xmlEl, "width", 0);
        fldDef.Format = Xml.getAttribute<String>(xmlEl, "format", null);
        if (String.IsNullOrEmpty(fldDef.Format)) {
          if ((fldDef.Type == JSFieldType.Date) || (fldDef.Type == JSFieldType.DateUTC))
            fldDef.Format = "dd.MM.yyyy HH:mm:ss";
          if (fldDef.Type == JSFieldType.Int)
            fldDef.Format = "0";
          if (fldDef.Type == JSFieldType.Currency)
            fldDef.Format = "#,##0.00 р";
        }
        fldDef.Align = jsonUtl.detectAlignment(fldDef.Type, xmlEl.GetAttribute("align"));
        fldDef.Group = Xml.getAttribute<Int32>(xmlEl, "group", -1);
        fldDef.GroupAggr = xmlEl.GetAttribute("group_aggr");
        Int32 pkIndx = Xml.getAttribute<Int32>(xmlEl, "pk", 0);
        String boolVals = xmlEl.GetAttribute("boolVals");
        String defaultVal = xmlEl.GetAttribute("defaultVal");
        //if (fldDef.type == "currency") fldDef.Type = "float";
        if (pkIndx > 0)
          fldDef.PK = pkIndx;
        //if (fldDef.type == CJsonStoreMetadataFieldType.ftDate)
        //  fldDef.dateFormat = "Y-m-d\\TH:i:s";
        else if (fldDef.Type == JSFieldType.Boolean && !String.IsNullOrEmpty(boolVals))
          fldDef.BoolVals = boolVals;
        if (!String.IsNullOrEmpty(defaultVal) && fldDef.Type != JSFieldType.Date)
          if (fldDef.Type == JSFieldType.Boolean)
            fldDef.DefaultVal = Utl.Convert2Type<Boolean>(defaultVal);
          else if (fldDef.Type == JSFieldType.String)
            fldDef.DefaultVal = defaultVal;
          else
            fldDef.DefaultVal = Utl.Convert2Type<Double>(defaultVal);
        vResult.Fields.Add(fldDef);
      }
      if (vResult.Multiselection) {
        var v_pks = vResult.GetPKFields();
        if ((v_pks == null) || (v_pks.Length != 1))
          throw new Exception(String.Format("Для режима multiselection, необходимо чтобы для ио [{0}] был определен первичный ключь(не составной).", bioCode));
      }
      return vResult;
    }
 private static List<JsonStoreMetadataFieldDef> _creFldDefsRmt(JsonStoreMetadata metaData) {
   var flds = new List<JsonStoreMetadataFieldDef>();
   foreach (var fld in metaData.Fields)
     flds.Add(fld);
   return flds;
 }
 /// <summary>
 /// Выполняет скрипт с параметрами из строки
 /// </summary>
 /// <param name="metadata"></param>
 /// <param name="row"></param>
 /// <param name="bioParams"></param>
 /// <param name="timeout"/>
 public void DoExecuteSQL(JsonStoreMetadata metadata, JsonStoreRow row, Params bioParams, Int32 timeout) {
   var v_params = this._buildPostParams(metadata, row, bioParams);
   this._doExecute(v_params, "execute", timeout);
 }
Exemple #10
0
 /// <summary>
 /// Обрабатывает изменения в данных
 /// </summary>
 /// <param name="metadata"></param>
 /// <param name="row"></param>
 /// <param name="bioParams"></param>
 /// <param name="timeout"/>
 public void DoProcessRowPost(JsonStoreMetadata metadata, JsonStoreRow row, Params bioParams, Int32 timeout) {
   var v_params = this._buildPostParams(metadata, row, bioParams);
   if ((row.ChangeType == JsonStoreRowChangeType.Added) ||
       (row.ChangeType == JsonStoreRowChangeType.Modified)) {
         this._doExecute(v_params, "insertupdate", timeout);
     this._returnParamsToRow(metadata, row, v_params);
   } else if (row.ChangeType == JsonStoreRowChangeType.Deleted)
     this._doExecute(v_params, "delete", timeout);
 }
Exemple #11
0
 private void _returnParamsToRow(JsonStoreMetadata metadata, JsonStoreRow row, Params bioParams) {
   var v_out_params = bioParams.Where(p => { return (p.ParamDir != ParamDirection.Input)/* || String.Equals(p.Name, CJsonStoreMetadata.csPKFieldName)*/; });
   foreach (var p in v_out_params)
     row.Values[metadata.IndexOf(p.Name)] = p.Value;
 }
Exemple #12
0
    /*
    /// <summary>
    /// Удаляет запись по признаку первичного ключа.
    /// </summary>
    /// <exception cref="EBioException">Возбуждается, когда операция завершилась с ошибкой.</exception>
    public void DoDelete(Params @params) {
      this.doExecute(@params, "delete");
    }

    /// <summary>
    /// Добавляет/Изменяет запись по признаку первичного ключа.
    /// </summary>
    /// <exception cref="EBioException">Возбуждается, когда операция завершилась с ошибкой.</exception>
    public void DoInsertUpdate(Params @params) {
      this.doExecute(@params, "insertupdate");
    }
    */

    private Params _buildPostParams(JsonStoreMetadata metadata, JsonStoreRow row, Params bioParams) {
      Params v_rslt = new Params();
      for (int i = 0; i < metadata.Fields.Count; i++)
        v_rslt.Add(metadata.Fields[i].Name.ToLower(), row.Values[i]);
      v_rslt = v_rslt.Merge(bioParams, false);
      return v_rslt;

    }