/// <summary>
    /// Sets page size dropdown list according to PageSize property.
    /// </summary>
    private void SetPageSize(bool forceReload)
    {
        if ((drpPageSize.Items.Count == 0) || forceReload)
        {
            string currentPagesize = CurrentPageSize.ToString();

            if (!PagerLoaded && (PagerMode != UniPagerMode.Querystring))
            {
                currentPagesize = DefaultPageSize.ToString();
            }

            drpPageSize.Items.Clear();

            PageSizeOptionsData pageSizeOptionsData;

            if (!TryParsePageSizeOptions(PageSizeOptions, out pageSizeOptionsData))
            {
                EventLogProvider.LogEvent(EventType.ERROR, "UIPager", "ParseCustomOptions", "Could not parse custom page size options: '" + PageSizeOptions + "'. Correct format is values separated by comma.");
                TryParsePageSizeOptions(DEFAULT_PAGE_SIZE_OPTIONS, out pageSizeOptionsData);
            }

            // Add default page size if not present
            if ((DefaultPageSize > 0) && !pageSizeOptionsData.Options.Contains(DefaultPageSize))
            {
                pageSizeOptionsData.Options.Add(DefaultPageSize);
            }

            // Sort list of page sizes
            pageSizeOptionsData.Options.Sort();

            FillPageSizeDropdown(pageSizeOptionsData, currentPagesize);
        }
    }
        private SearchRequest BuildSearchRequest(NameValueCollection parameters)
        {
            string start = parameters["start"] ?? "1";
            string rows  = parameters["rows"] ?? DefaultPageSize.ToString(CultureInfo.InvariantCulture);
            string facet = parameters["facet"];

            if (!String.IsNullOrEmpty(facet))
            {
                string facets = string.Join(", ", Array.ConvertAll(facet.Split(',').ToArray(), i => String.Format("\"{0}\":{{\"sort\":\"bucket\",\"size\":" + MaxNumberOfFacets + "}}", i.ToString())));
                facet = "{" + facets + "}";
            }

            return(new SearchRequest
            {
                QueryParser = QueryParser.Simple,
                Query = parameters["q"],
                FilterQuery = parameters["fq"],
                QueryOptions = parameters["q.options"],
                Highlight = parameters["highlight"],
                Start = Convert.ToInt32(start) - 1, // SI4T uses 1 based indexing, but CloudSearch uses 0 based.
                Size = Convert.ToInt32(rows),
                Sort = parameters["sort"],
                Facet = facet
            });
        }
    protected DataSet FillGrid()
    {
        //===============================================================================
        //PAGE SIZE
        //===============================================================================

        if (!string.IsNullOrEmpty(Txt_PageSize.Text))
        {
            if (Convert.ToInt32(Txt_PageSize.Text) > 0)
            {
                Grd_ListGrid.PageSize = Convert.ToInt32(Txt_PageSize.Text.Trim());
            }
            else
            {
                Txt_PageSize.Text = Grd_ListGrid.PageSize.ToString();
            }
        }
        else
        {
            Grd_ListGrid.PageSize = DefaultPageSize;
            Txt_PageSize.Text     = DefaultPageSize.ToString();
        }

        DataSet Ds = default(DataSet);

        Ds = (DataSet)ViewState["DummyData"];
        if ((Ds.Tables.Count > 0))
        {
            lbl_Result.Text = Ds.Tables[0].Rows.Count.ToString() + (Ds.Tables[0].Rows.Count > 1 ? " records found!! " : " record found!! ");
        }
        TotalColumn             = Ds.Tables[0].Columns.Count;
        Grd_ListGrid.DataSource = Ds;
        Grd_ListGrid.DataBind();
        return(Ds);
    }
Exemplo n.º 4
0
    /// <summary>
    /// Sets page size dropdown list according to PageSize property.
    /// </summary>
    private void SetPageSize(bool forceReload)
    {
        if ((pagerElem.PageSizeDropdown.Items.Count == 0) || forceReload)
        {
            pagerElem.PageSizeDropdown.Items.Clear();

            string[] sizes = PageSizeOptions.Split(',');
            if (sizes.Length > 0)
            {
                List <int> sizesInt = new List <int>();
                // Indicates if contains 'Select ALL' macro
                bool containsAll = false;
                foreach (string size in sizes)
                {
                    if (size.ToUpper() == "##ALL##")
                    {
                        containsAll = true;
                    }
                    else
                    {
                        sizesInt.Add(ValidationHelper.GetInteger(size.Trim(), 0));
                    }
                }
                // Add default page size if not pressents
                if ((DefaultPageSize > 0) && !sizesInt.Contains(DefaultPageSize))
                {
                    sizesInt.Add(DefaultPageSize);
                }
                // Sort list of page sizes
                sizesInt.Sort();

                ListItem item = null;

                foreach (int size in sizesInt)
                {
                    // Skip zero values
                    if (size != 0)
                    {
                        item = new ListItem(size.ToString());
                        if (item.Value == DefaultPageSize.ToString())
                        {
                            item.Selected = true;
                        }
                        pagerElem.PageSizeDropdown.Items.Add(item);
                    }
                }
                // Add 'Select ALL' macro at the end of list
                if (containsAll)
                {
                    item = new ListItem(GetString("general.selectall"), "-1");
                    if (DefaultPageSize == -1)
                    {
                        item.Selected = true;
                    }
                    pagerElem.PageSizeDropdown.Items.Add(item);
                }
            }
        }
    }
        private SearchRequest BuildSearchRequest(NameValueCollection parameters)
        {
            string start = parameters["start"] ?? "1";
            string rows  = parameters["rows"] ?? DefaultPageSize.ToString(CultureInfo.InvariantCulture);
            //string facet = parameters["facet"];
            //if (!String.IsNullOrEmpty(facet))
            //{
            //    string facets = string.Join(", ", Array.ConvertAll(facet.Split(',').ToArray(), i => String.Format("\"{0}\":{{\"sort\":\"bucket\",\"size\":" + MaxNumberOfFacets + "}}", i.ToString())));
            //    facet = "{" + facets + "}";
            //}

            List <QueryContainer> mustClauses   = new List <QueryContainer>();
            List <QueryContainer> filterClauses = new List <QueryContainer>();

            if (parameters["q"] != null)
            {
                mustClauses.Add(new QueryStringQuery
                {
                    Query           = parameters["q"],
                    AnalyzeWildcard = false,
                    Lenient         = false
                });
            }

            if (!string.IsNullOrEmpty(parameters["fq"]))
            {
                string[] filterQueryParameters = parameters["fq"].Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries);
                foreach (string item in filterQueryParameters)
                {
                    string[] keyValue = item.Split(':');
                    {
                        if (keyValue.Length > 0)
                        {
                            if (keyValue[0] == "date")
                            {
                                string[] range = keyValue[1].Split(',');
                                if (range.Length > 0)
                                {
                                    filterClauses.Add(new DateRangeQuery
                                    {
                                        Field = new Field("date"),
                                        GreaterThanOrEqualTo = DateTime.ParseExact(range[0], "yyyy-MM-dd", CultureInfo.InvariantCulture),
                                        LessThanOrEqualTo    = DateTime.ParseExact(range[1], "yyyy-MM-dd", CultureInfo.InvariantCulture)
                                    });
                                }
                                else
                                {
                                    filterClauses.Add(new TermQuery
                                    {
                                        Field = new Field("date"),
                                        Value = keyValue[1]
                                    });
                                }
                            }
                            else
                            {
                                mustClauses.Add(new TermQuery
                                {
                                    Field = new Field(keyValue[0]),
                                    Value = keyValue[1]
                                });
                            }
                        }
                    }
                }
            }

            QueryContainer query = new BoolQuery
            {
                Must   = mustClauses,
                Filter = filterClauses
            };

            Highlight highlight = new Highlight
            {
                Order  = "score",
                Fields = new Dictionary <Field, IHighlightField>
                {
                    { "body", new HighlightField
                      {
                          Type              = HighlighterType.Plain,
                          ForceSource       = true,
                          FragmentSize      = 150,
                          Fragmenter        = HighlighterFragmenter.Span,
                          NumberOfFragments = 3,
                          NoMatchSize       = 150
                      } }
                }
            };

            List <ISort> sort = new List <ISort>();

            if (!string.IsNullOrEmpty(parameters["sort"]))
            {
                string[] sortQueryParameter = parameters["sort"].Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries);

                if (sortQueryParameter.Length > 0)
                {
                    sort.Add(new SortField {
                        Field = sortQueryParameter[0], Order = sortQueryParameter[1] == "desc" ? SortOrder.Descending : SortOrder.Ascending
                    });
                }
            }

            return(new SearchRequest
            {
                From = Convert.ToInt32(start) - 1, // SI4T uses 1 based indexing, but CloudSearch and Elasticsearch uses 0 based.
                Size = Convert.ToInt32(rows),
                Query = query,
                Highlight = highlight,
                Sort = sort
            });
        }
Exemplo n.º 6
0
    /// <summary>
    /// Sets page size dropdown list according to PageSize property.
    /// </summary>
    private void SetPageSize(bool forceReload)
    {
        if ((drpPageSize.Items.Count == 0) || forceReload)
        {
            string currentPagesize = CurrentPageSize.ToString();

            if (!PagerLoaded && (PagerMode != UniPagerMode.Querystring))
            {
                currentPagesize = DefaultPageSize.ToString();
            }

            drpPageSize.Items.Clear();

            string[] sizes = PageSizeOptions.Split(',');
            if (sizes.Length > 0)
            {
                List <int> sizesInt = new List <int>();

                // Indicates if contains 'Select ALL' macro
                bool containsAll = false;
                foreach (string size in sizes)
                {
                    if (size.ToUpperCSafe() == UniGrid.ALL)
                    {
                        containsAll = true;
                    }
                    else
                    {
                        sizesInt.Add(ValidationHelper.GetInteger(size.Trim(), 0));
                    }
                }

                // Add default page size if not pressents
                if ((DefaultPageSize > 0) && !sizesInt.Contains(DefaultPageSize))
                {
                    sizesInt.Add(DefaultPageSize);
                }

                // Sort list of page sizes
                sizesInt.Sort();

                ListItem item;

                foreach (int size in sizesInt)
                {
                    // Skip zero values
                    if (size != 0)
                    {
                        item = new ListItem(size.ToString());
                        if (item.Value == currentPagesize)
                        {
                            item.Selected = true;
                        }
                        drpPageSize.Items.Add(item);
                    }
                }

                // Add 'Select ALL' macro at the end of list
                if (containsAll)
                {
                    item = new ListItem(GetString("general.selectall"), "-1");
                    if (currentPagesize == "-1")
                    {
                        item.Selected = true;
                    }
                    drpPageSize.Items.Add(item);
                }
            }
        }
    }