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));
        }
Ejemplo n.º 2
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());
        }