Exemplo n.º 1
0
        public void ProcessRequest(HttpContext context)
        {
            HttpRequest request = context.Request;
            HttpResponse response = context.Response;
            string output;

            try
            {
                string numberOfRows = request["rows"];
                string pageIndex = request["page"];
                string sortColumnName = request["sidx"];
                string sortOrderBy = request["sord"];
                string _search = request["_search"];

                if (_search.Equals("true"))
                {
                    JqSearchIn jqgridInputs = new JqSearchIn();
                    jqgridInputs.rows = Convert.ToInt32(numberOfRows);
                    jqgridInputs.page = Convert.ToInt32(pageIndex);
                    jqgridInputs.sidx = sortColumnName;
                    jqgridInputs.sord = sortOrderBy;

                    jqgridInputs._search = Convert.ToBoolean(_search);
                    jqgridInputs.searchField = request["searchField"];
                    jqgridInputs.searchOper = request["searchOper"];
                    jqgridInputs.searchString = request["searchString"];
                    jqgridInputs.filters = request["filters"];

                    output = BuildJQGridResults(jqgridInputs);
                }
                else
                {
                    // For server side sorting and filtering
                    output = BuildJQGridResults(sortColumnName, sortOrderBy, Convert.ToInt32(numberOfRows), Convert.ToInt32(pageIndex));

                    // For client side sorting and filtering
                    // string output = BuildJQGridResults( Convert.ToInt32(numberOfRows), Convert.ToInt32(pageIndex));
                }
            }
            catch (Exception ex)
            {
                if (logger.IsDebugEnabled)
                {
                    output = ex.Message;
                }
                else
                {
                    output = "Error loading data!";
                }

                logger.Error(ex);
            }

            response.Clear();
            response.ContentType = "application/json; charset=utf-8";
            response.Write(output);
        }
Exemplo n.º 2
0
        private string BuildJQGridResults(JqSearchIn jqInputs)
        {
            using (ProductRepository repo = new ProductRepository())
            {
                int totalRecordsCount;

                // Now call the actual function which reads from the database and performs search and filtering
                List<Product> filteredProducts = repo.GetProductList(jqInputs, out totalRecordsCount);

                JQGridResults result = new JQGridResults();
                List<JQGridRow> rows = new List<JQGridRow>();

                foreach (Product prod in filteredProducts)
                {
                    JQGridRow row = new JQGridRow();
                    row.id = prod.ProductID;
                    row.cell = new string[6];
                    row.cell[0] = prod.ProductID.ToString();
                    row.cell[1] = prod.ProductName;
                    row.cell[2] = prod.SupplierID.ToString();
                    row.cell[3] = prod.UnitPrice.ToString();
                    row.cell[4] = prod.UnitsInStock.ToString();
                    row.cell[5] = prod.UnitsOnOrder.ToString();

                    rows.Add(row);
                }

                result.rows = rows.ToArray();
                result.page = jqInputs.page;
                result.total = (totalRecordsCount + jqInputs.rows - 1) / jqInputs.rows;
                result.records = totalRecordsCount;

                String jsonResult = new JavaScriptSerializer().Serialize(result);

                return jsonResult;
            }
        }