Beispiel #1
0
    public void Init(
      JsonStoreData packet,
      Params bioParams,
      JsonStoreFilter filter,
      JsonStoreSort sorter,
      String selection,
      Int32 timeout
    ) {

      this.rqPacket = packet;
      this._rq_bioParams = bioParams;
      this._rq_filter = filter;
      this._rq_sorter = sorter;
      this._rq_selection = selection;

      if (this.rqPacket == null)
        this.rqPacket = this._creJSData();
      XmlElement SQLtext = detectSQLTextElement(this.CursorIniDoc, this.bioCode);
      _applyParamsTypes((XmlElement)SQLtext.ParentNode, this.rqBioParams);
      this.InitCursorFields();
      if (this.rqBioParams == null)
        this._rq_bioParams = new Params();
      base.Init(SQLtext.InnerText, this.rqBioParams);
      String vSQL = this.preparedSQL;
      Boolean v_filterIsDefined = this._applyFilter(this._rq_filter, ref this._rq_bioParams, ref vSQL);
      Boolean v_sorterIsDefined = this._applySorter(this._rq_sorter, ref vSQL);

      if (String.IsNullOrEmpty(this._rq_selection)) {
        JsonStoreFilter vLocate = (this.rqPacket != null) ? this.rqPacket.Locate : null;
        if (vLocate != null) {
          // ищем запрошенную запись
          var v_min_start = vLocate.FromPosition;
          String vSQLStr = null;
          var v_lprms = new Params();
          vLocate.BuildSQLConditions(ref vSQLStr, v_lprms);
          if (!String.IsNullOrEmpty(vSQLStr))
            vSQLStr = vSQLStr + " AND";
          v_lprms = v_lprms.Merge(this.rqBioParams, true);
          v_lprms.SetValue("loc_start_from", v_min_start);
          vSQLStr = String.Format(csLocateNextSQLTemplate, vSQL, vSQLStr);
          int rnum = Convert.ToInt32(SQLCmd.ExecuteScalarSQL(this.Connection, vSQLStr, v_lprms, timeout));
          if (this.rqPacket.Limit > 0)
            this.rqPacket.Start = Math.Max(((rnum - 1) / this.rqPacket.Limit) * this.rqPacket.Limit, 0);
        }
        this._applyPagging(this.rqPacket, !v_filterIsDefined && !v_sorterIsDefined, ref this._rq_bioParams, ref vSQL, timeout);
      } else {
        this._buildSelectSelectionSQL(this._rq_selection, this.rqBioParams, ref vSQL);
      }
      this.preparedSQL = vSQL;
    }
 private JsonStoreSort _genJSSortDefinition(SortDescriptionCollection sort) {
   var rslt = new JsonStoreSort();
   foreach (var s in sort) {
     rslt.Add(s.PropertyName, (s.Direction == ListSortDirection.Ascending) ? JsonStoreSortOrder.Asc : JsonStoreSortOrder.Desc);
   }
   return rslt;
 }
Beispiel #3
0
 private Boolean _applySorter(JsonStoreSort sort, ref String vSQL) {
   // сортируем
   String vSort = (sort != null) ? sort.GetSQL() : null;
   //String vSortDir = (rq.sort != null) ? Utl.NameOfEnumValue<CJsonStoreSortOrder>(rq.sort.direction, false).ToUpper() : null;
   //Boolean vSorterIsDefined = (vSortField != null && vSortField != CJsonStoreMetadata.csPKField && vSortDir != null);
   Boolean vSorterIsDefined = !String.IsNullOrEmpty(vSort);
   if (vSorterIsDefined) {
     String pks = String.Empty;
     foreach (Field fld in this.PKFields.Values)
       pks += ", " + fld.FieldName;
     //vSQL = String.Format(csSortSQLTemplate, vSQL, vSortField + " " + vSortDir, pks);
     vSQL = String.Format(csSortSQLTemplate, vSQL, vSort, pks);
     return true;
   }
   return false;
 }