Esempio n. 1
0
        public static string getDataJson(HttpRequestBase Request, int?companyID, SASContext db)
        {
            EISDataTables TableParams = new EISDataTables();

            TableParams.BindModel(Request);

            QueryBuilder query = new QueryBuilder(TableParams);

            query.FilterPagingSortingSearch(companyID);

            ButtonTemplates buttonTemplates = new ButtonTemplates();

            buttonTemplates.fillTemplates(TableParams.buttonsOptions);

            jsonBuilder json = new jsonBuilder(TableParams);

            return(json.getDataJson(db, query, buttonTemplates));
        }
Esempio n. 2
0
        public string getDataJson(SASContext db, QueryBuilder query, ButtonTemplates buttons)
        {
            IEnumerable <object[]> result;

            using (var cmd = db.Database.Connection.CreateCommand())
            {
                db.Database.Connection.Open();
                cmd.CommandText = query.fullQuery;
                using (var reader = cmd.ExecuteReader())
                    result = ReadDataReader(reader).ToList();
                db.Database.Connection.Close();
            }

            var filteredResult = result.Skip(datatables.iDisplayStart).Take(datatables.iDisplayLength).ToList();

            int iTotalRecords        = result.Count();
            int iTotalDisplayRecords = result.ToList().Skip(0).Count();

            string json = string.Format("{2}\"iTotalRecords\": {0},\"iTotalDisplayRecords\": {1},  "
                                        + "\"sEcho\":{3},"
                                        + "\"aaData\":["
                                        , iTotalRecords, iTotalDisplayRecords, "{", datatables.sEcho, datatables.iDisplayStart);

            for (int h = 0; h < filteredResult.Count(); h++)
            {
                json += "[";
                for (int i = 0; i < datatables.colums.Count() - 1; i++)
                {
                    json += "\"" + filteredResult[h][i] + "\",";
                }
                json += "\"";
                foreach (string template in buttons.ButtonMasks)
                {
                    json += template.Replace("#id", filteredResult[h][datatables.colums.Count() - 1].ToString());
                }
                json += "\",],**";
                json  = json.Replace(",],**", "],");
            }

            json += "]}**";
            json  = json.Replace(",]}**", "]}");
            json  = json.Replace("}**", "}");
            return(json);
        }