private void getList() { string entityName = context.Request["entityName"]; string where = context.Request["extraFilter"] ?? ""; string orderBy = (context.Request["sort"] ?? "") + " " + (context.Request["dir"] ?? ""); if (orderBy != null) { orderBy = orderBy.Replace("__", "."); } string page = String.IsNullOrEmpty(context.Request["start"]) ? "0" : context.Request["start"]; string limit = String.IsNullOrEmpty(context.Request["limit"]) ? "20" : context.Request["limit"]; int fieldNo = 0; while (context.Request.Form["f_" + fieldNo] != null) { string op = context.Request.Form["o_" + fieldNo]; string field = context.Request.Form["f_" + fieldNo]; string val = context.Request.Form["c_" + fieldNo]; where += (where == "" ? "" : " AND ") + field + op + val; fieldNo++; } FilterParser filterParser = new FilterParser(where, entityName); where = filterParser.GetWhere(); object[] parameters = filterParser.GetParams(); DataTable dt = Provider.ReadList(Provider.GetEntityType(entityName), Int32.Parse(page) / Int32.Parse(limit), Int32.Parse(limit), orderBy, where, parameters); int totalCount = Provider.ReadListTotalCount(Provider.GetEntityType(entityName), where, parameters); List <string> jsonItems = new List <string>(); foreach (DataRow dr in dt.Rows) { string jsonItem = "{"; foreach (DataColumn dc in dr.Table.Columns) { jsonItem += string.Format("{0}:{1},", dc.ColumnName.Replace(".", "__").ToJS(), dr[dc].ToJS()); } jsonItem = jsonItem.Remove(jsonItem.Length - 1, 1); jsonItem += "}"; jsonItems.Add(jsonItem); } string res = "{root:[" + string.Join(",", jsonItems.ToArray()) + "], totalCount:" + totalCount + "}"; context.Response.Write(res); }
private void getEntityList() { string entityName = context.Request["entityName"]; string orderBy = context.Request["orderBy"] ?? "OrderNo"; string orderAsc = context.Request["orderAsc"] ?? "1"; Type tip = Provider.GetEntityType(entityName); string filter = context.Request["filter"] ?? ""; FilterParser filterParser = new FilterParser(filter, entityName); filter = filterParser.GetWhere(); string where = "where " + (String.IsNullOrEmpty(filter) ? "1=1" : "(" + filter + ")"); IDatabaseEntity[] entities = currentDatabase.ReadList(tip, "select * from [" + entityName + "] " + where + " order by " + orderBy + (orderAsc == "1" ? "" : " desc"), filterParser.GetParams()).SafeCastToArray <IDatabaseEntity>(); context.Response.Write(entities.ToJSON()); }
private void getGridList() { string entityName = context.Request["entityName"]; string where = context.Request["extraFilter"] ?? ""; string orderBy = context.Request["orderBy"] ?? ""; string page = String.IsNullOrEmpty(context.Request["page"]) ? "0" : context.Request["page"]; string limit = String.IsNullOrEmpty(context.Request["limit"]) ? "20" : context.Request["limit"]; int fieldNo = 0; Type entityType = Provider.GetEntityType(entityName); BaseEntity sampleEntity = Provider.CreateEntity(entityType); while (context.Request.Form["f_" + fieldNo] != null) { string op = context.Request.Form["o_" + fieldNo]; string field = context.Request.Form["f_" + fieldNo]; string val = context.Request.Form["c_" + fieldNo]; where += (where == "" ? "" : " AND ") + field + op + val; fieldNo++; } if (!string.IsNullOrWhiteSpace(context.Request.Form["search"])) { string search = context.Request.Form["search"]; if (!search.Contains("%")) { search = "%" + search + "%"; } where += " AND " + sampleEntity.GetNameColumn() + "like" + search; } FilterParser filterParser = new FilterParser(where, entityName); where = filterParser.GetWhere(); DataTable dt = Provider.ReadList(entityType, Int32.Parse(page), Int32.Parse(limit), orderBy, where, filterParser.GetParams()); context.Response.Write("<table class=\"bk-grid\" border=\"0\" cellspacing=\"0\" cellpadding=\"2\">\n"); if (dt != null) { context.Response.Write("\t<tr>\n"); foreach (DataColumn dc in dt.Columns) { if (dc.ColumnName == "_CinarRowNumber") { continue; //*** } string columnName = dc.ColumnName; string columnTitle = Provider.TranslateColumnName(entityName, columnName); context.Response.Write("\t\t<th id=\"h_" + dc.ColumnName + "\">" + columnTitle + "</th>\n"); } context.Response.Write("\t</tr>\n"); } if (dt != null) { if (dt.Rows.Count == 0) { context.Response.Write("\t<tr><td style=\"padding:30px;text-align:center\" colspan=\"50\">" + Provider.GetResource("No record") + "</td></tr>\n"); } else { for (int i = 0; i < dt.Rows.Count; i++) { DataRow dr = dt.Rows[i]; context.Response.Write("\t<tr id=\"r_" + dr[0] + "\">\n"); foreach (DataColumn dc in dt.Columns) { if (dc.ColumnName == "_CinarRowNumber") { continue; //*** } object valObj = dr[dc.ColumnName]; string dispVal = ""; if (dr.IsNull(dc)) { dispVal = ""; } else if (dc.DataType == typeof(Boolean)) { dispVal = ((bool)valObj) ? Provider.GetResource("Yes") : Provider.GetResource("No"); } else if (dc.DataType == typeof(String)) { string str = Regex.Replace(valObj.ToString(), "<.*?>", string.Empty); if (str.Length > 50) { dispVal = CMSUtility.HtmlEncode(str.StrCrop(50)); // str.Substring(0, 50) + "..." } else { dispVal = str; } } else if (dc.DataType == typeof(DateTime)) { dispVal = ((DateTime)valObj).ToString(Provider.Configuration.DefaultDateFormat); } else { dispVal = valObj.ToString(); } context.Response.Write("\t\t<td value=\"" + CMSUtility.HtmlEncode(valObj) + "\">" + dispVal + "</td>\n"); } context.Response.Write("\t</tr>\n"); } } } context.Response.Write("</table>"); }