private static IEnumerable <IDataRow> GetData(
            string prefixText,
            int start,
            int limit,
            bool isKz,
            IDataSourceView2 dataSourse,
            IDataSourceView3 ds3,
            string parameters,
            string refParent,
            out int countRows)
        {
            if (!dataSourse.CheckPermit())
            {
                // todo: log
                countRows = 0;
                return(null);
            }

            LocalizationHelper.SetThreadCulture(isKz ? "kk-kz" : "ru-ru", null);

            MainPageUrlBuilder.Current.IsDataControl = true;

            IQueryable <IDataRow> queryable;

            if (string.IsNullOrEmpty(refParent))
            {
                queryable = dataSourse.GetSelectIRow(GlobalObject.decodeURIComponent(parameters));
            }
            else
            {
                var queryParameters = GlobalObject.decodeURIComponent(parameters)
                                      + "&refParent=" + ("NaN".Equals(refParent) ? null : refParent);
                queryable = dataSourse.GetSelectIRow(queryParameters);
            }

            if (ds3 != null && ds3.SupportFlagCanAddChild)
            {
                queryable = queryable.Where(q => q.CanAddChild);
            }

            queryable = isKz
                            ? queryable.Where(q => q.nameKz.Contains(prefixText))
                            : queryable.Where(q => q.nameRu.Contains(prefixText));


            if (!parameters.Contains("RemoveDefaultSortOnAutocompleetRequset"))
            {
                queryable = isKz ? queryable.OrderBy(q => q.nameKz) : queryable.OrderBy(q => q.nameRu);
            }

            countRows = queryable.Count();
            return(queryable.Skip(start).Take(limit));
        }
        private static IEnumerable <IDataRow> GetCompletionList(HttpContext context, out IDataSourceView3 ds3, out int countRows)
        {
            var start           = 0;
            var limit           = 10;
            var prefixTextValue = string.Empty;
            var isKz            = false;
            var dataSourceType  = string.Empty;
            var parameters      = string.Empty;
            var refParent       = string.Empty;
            var fullModelData   = false;

            if (!string.IsNullOrEmpty(context.Request[Start]))
            {
                start = Convert.ToInt32(context.Request[Start]);
            }

            if (!string.IsNullOrEmpty(context.Request[Limit]))
            {
                limit = Convert.ToInt32(context.Request[Limit]);
            }

            if (!string.IsNullOrEmpty(context.Request[PrefixText]))
            {
                prefixTextValue = context.Request[PrefixText];
            }

            if (!string.IsNullOrEmpty(context.Request[DataSourceType]))
            {
                dataSourceType = context.Request[DataSourceType];
            }

            if (!string.IsNullOrEmpty(context.Request["isKz"]))
            {
                isKz = Convert.ToBoolean(context.Request["isKz"]);
            }

            if (!string.IsNullOrEmpty(context.Request["parameters"]))
            {
                parameters = context.Request["parameters"];
            }

            if (!string.IsNullOrEmpty(context.Request["node"]))
            {
                refParent = context.Request["node"];
            }

            var sourceObj = Activator.CreateInstance(BuildManager.GetType(dataSourceType, true, true), null);

            ds3 = (IDataSourceView3)sourceObj;
            return(GetData(prefixTextValue, start, limit, isKz, (IDataSourceView2)sourceObj, ds3, parameters, refParent, out countRows));
        }
Beispiel #3
0
        private static string[] GetData(string prefixText, int count, bool isKz, bool isCode, IDataSourceView2 dataSourse, IDataSourceView3 ds3, string value)
        {
            if (!dataSourse.CheckPermit())
            {
                //todo: log
                return(null);
            }

            MainPageUrlBuilder.Current.IsDataControl = true;
            var reslut = new List <string>(count);
            var jss    = new JavaScriptSerializer();

            if (dataSourse.SupportSelectICodeRow)
            {
                var queryable = dataSourse.
                                GetSelectICodeRow(GlobalObject.decodeURIComponent(value));
                if (ds3 != null && ds3.SupportFlagCanAddChild)
                {
                    queryable = queryable.Where(q => q.CanAddChild);
                }

                if (isKz)
                {
                    queryable = isCode
                                    ? queryable.Where(q => q.code.StartsWith(prefixText)).OrderBy(q => q.code).Take(count)
                                    : queryable.Where(q => q.nameKz.StartsWith(prefixText)).Take(count);
                    foreach (var row in queryable)
                    {
                        reslut.Add(jss.Serialize(new Pair(isCode ? row.code : row.nameKz, new Triplet(isCode ? row.nameKz : row.code, row.Value, ds3 != null ? row.GetAdditionalValues(ds3.SelectParameters) : null))));
                    }
                }
                else
                {
                    queryable = isCode
                                    ? queryable.Where(q => q.code.StartsWith(prefixText)).OrderBy(q => q.code).Take(count)
                                    : queryable.Where(q => q.nameRu.StartsWith(prefixText)).Take(count);
                    foreach (var row in queryable)
                    {
                        reslut.Add(jss.Serialize(new Pair(isCode ? row.code : row.nameRu, new Triplet(isCode ? row.nameRu : row.code, row.Value, ds3 != null ? row.GetAdditionalValues(ds3.SelectParameters) : null))));
                    }
                }
            }
            else
            {
                var queryable = dataSourse.
                                GetSelectIRow(GlobalObject.decodeURIComponent(value));
                if (ds3 != null && ds3.SupportFlagCanAddChild)
                {
                    queryable = queryable.Where(q => q.CanAddChild);
                }
                if (isKz)
                {
                    queryable = queryable.Where(q => q.nameKz.StartsWith(prefixText)).Take(count);
                    foreach (var row in queryable)
                    {
                        reslut.Add(jss.Serialize(new Pair(row.nameKz, new Triplet("", row.Value, ds3 != null ? row.GetAdditionalValues(ds3.SelectParameters) : null))));
                    }
                }
                else
                {
                    queryable = queryable.Where(q => q.nameRu.StartsWith(prefixText)).Take(count);
                    foreach (var row in queryable)
                    {
                        reslut.Add(jss.Serialize(new Pair(row.nameRu, new Triplet("", row.Value, ds3 != null ? row.GetAdditionalValues(ds3.SelectParameters) : null))));
                    }
                }
            }

            return(reslut.ToArray());
        }