public static IList GetListData(DbContext db, string model, FilterGroup filter, string orderby, string EntityType = "Report") { try { Type entityType = GetEntityType(model, EntityType); if (entityType == null) { return(null); } IDbContextHelper helper = db.GetHelper(entityType); FilterTranslator filterTranslator = new FilterTranslator(); if (filter != null) { filterTranslator.Group = filter; } filterTranslator.Translate(); string commandText = filterTranslator.CommandText; commandText = (string.IsNullOrEmpty(commandText) ? "" : ("where " + commandText)); if (!string.IsNullOrEmpty(orderby)) { commandText = commandText + " " + orderby; } return(helper.Fetch(commandText, filterTranslator.Parms.ToArray())); } catch (Exception) { return(null); } }
public static PagedData GetPageData(DbContext db, string model, QueryDescriptor descriptor) { Type entityType = GetEntityType(model); string text = null; string text2 = null; bool flag = false; bool flag2 = false; List <string> list = entityType.GetProperties().Select(p => p.Name).ToList(); if (descriptor.OrderBy != null && descriptor.OrderBy.Any()) { text = descriptor.OrderBy[0].Key; if (!list.Contains(text)) { text = entityType.GetProperties().Where(p => p.PropertyType == typeof(string)).Select(p => p.Name) .FirstOrDefault(); } text2 = ((descriptor.OrderBy[0].Order == OrderSequence.ASC) ? "asc" : "desc"); } if (descriptor.PageIndex.HasValue && descriptor.PageSize.HasValue) { flag2 = true; if (descriptor.PageSize == 0L) { descriptor.PageSize = 20L; } } if (!StringExtensions.IsNullOrEmpty(text)) { flag = true; text2 = ((StringExtensions.IsNullOrEmpty(text2) || StringExtensions.EqualsTo(text2, "asc")) ? "asc" : "desc"); } FilterTranslator filterTranslator = new FilterTranslator(); if (descriptor.Condition != null) { filterTranslator.Group = descriptor.Condition; } filterTranslator.Translate(); string commandText = filterTranslator.CommandText; commandText = (string.IsNullOrEmpty(commandText) ? "" : ("where " + commandText)); if (flag) { commandText += string.Format(" order by {0} {1}", text, text2); } if (flag2) { return(db.GetHelper(entityType).Page(descriptor.PageIndex.Value, descriptor.PageSize.Value, commandText, filterTranslator.Parms.ToArray())); } IList list2 = db.GetHelper(entityType).Fetch(commandText, filterTranslator.Parms.ToArray()); return(new PagedData(list2, list2.Count)); }
public static List <T> GetFieldValues <T>(DbContext db, string field, string name, FilterGroup filter) { FilterTranslator filterTranslator = new FilterTranslator(); if (filter != null) { filterTranslator.Group = filter; } filterTranslator.Translate(); string commandText = filterTranslator.CommandText; commandText = (string.IsNullOrEmpty(commandText) ? "" : ("where " + commandText)); return(db.Fetch <T>(string.Format("select {0} from {1}", field, name), filterTranslator.Parms.ToArray())); }
public static string GetId(DbContext db, string modelName, FilterGroup filter) { FilterTranslator filterTranslator = new FilterTranslator(); if (filter != null) { filterTranslator.Group = filter; } filterTranslator.Translate(); string commandText = filterTranslator.CommandText; commandText = (string.IsNullOrEmpty(commandText) ? "" : ("where " + commandText)); commandText = string.Format("select ID from {0} ", modelName.ToUpper()) + commandText; return(db.ExecuteScalar <string>(commandText, filterTranslator.Parms.ToArray())); }
public static bool Exist(DbContext db, Type type, FilterGroup filter) { IDbContextHelper helper = db.GetHelper(type); FilterTranslator filterTranslator = new FilterTranslator(); if (filter != null) { filterTranslator.Group = filter; } filterTranslator.Translate(); string commandText = filterTranslator.CommandText; commandText = (string.IsNullOrEmpty(commandText) ? "" : commandText); return(helper.Exist(commandText, filterTranslator.Parms.ToArray())); }
public static IList GetListData(DbContext db, string[] fields, string model, FilterGroup filter) { FilterTranslator filterTranslator = new FilterTranslator(); if (filter != null) { filterTranslator.Group = filter; } filterTranslator.Translate(); string commandText = filterTranslator.CommandText; commandText = (string.IsNullOrEmpty(commandText) ? "" : ("where " + commandText)); commandText = string.Format("select {0} from {1} ", string.Join(",", fields), model) + commandText; return(db.Fetch <object>(commandText, filterTranslator.Parms.ToArray())); }
public static PagedData GetPagedData(DbContext db, Type type, QueryDescriptor descripter) { DbContext currentDb = db; string text = null; string text2 = null; bool flag = false; bool flag2 = false; if (descripter.OrderBy != null && descripter.OrderBy.Any()) { text = descripter.OrderBy[0].Key; text2 = ((descripter.OrderBy[0].Order == OrderSequence.ASC) ? "asc" : "desc"); } if (descripter.PageIndex.HasValue && descripter.PageSize.HasValue) { flag2 = true; if (descripter.PageSize == 0L) { descripter.PageSize = 20L; } } if (!StringExtensions.IsNullOrEmpty(text)) { flag = true; text2 = ((StringExtensions.IsNullOrEmpty(text2) || StringExtensions.EqualsTo(text2, "asc")) ? "asc" : "desc"); } FilterTranslator filterTranslator = new FilterTranslator(); if (descripter.Condition != null) { filterTranslator.Group = descripter.Condition; } filterTranslator.Translate(); string commandText = filterTranslator.CommandText; commandText = (string.IsNullOrEmpty(commandText) ? "" : ("where " + commandText)); if (flag) { commandText += string.Format(" order by {0} {1}", text, text2); } if (flag2) { return(currentDb.GetHelper(type).Page(descripter.PageIndex.Value, descripter.PageSize.Value, commandText, filterTranslator.Parms.ToArray())); } IList list = currentDb.GetHelper(type).Fetch(commandText, filterTranslator.Parms.ToArray()); return(new PagedData(list, list.Count)); }
public static IList GetListData(DbContext db, Type type, string orderby, FilterGroup filter) { IDbContextHelper helper = db.GetHelper(type); FilterTranslator filterTranslator = new FilterTranslator(); if (filter != null) { filterTranslator.Group = filter; } filterTranslator.Translate(); string commandText = filterTranslator.CommandText; commandText = (string.IsNullOrEmpty(commandText) ? "" : ("where " + commandText)); if (!string.IsNullOrEmpty(orderby)) { commandText = commandText + " " + orderby; } return(helper.Fetch(commandText, filterTranslator.Parms.ToArray())); }
public static IList GetCommonListData(DbContext db, string model, FilterGroup filter, string orderby) { try { FilterTranslator filterTranslator = new FilterTranslator(); if (filter != null) { filterTranslator.Group = filter; } filterTranslator.Translate(); string commandText = filterTranslator.CommandText; commandText = (string.IsNullOrEmpty(commandText) ? "" : ("where " + commandText)); if (!string.IsNullOrEmpty(orderby)) { commandText = commandText + " " + orderby; } DataTable dataTable = new DataTable(); commandText = "select * from " + model + " " + commandText; db.Fill(dataTable, commandText, new object[1] { filterTranslator.Parms }); List <Dictionary <string, object> > list = new List <Dictionary <string, object> >(); foreach (DataRow row in dataTable.Rows) { Dictionary <string, object> dictionary = new Dictionary <string, object>(); foreach (DataColumn column in dataTable.Columns) { dictionary.Add(column.ColumnName, row[column.ColumnName]); } list.Add(dictionary); } return(list); } catch (Exception) { return(null); } }
public static PagedData GetCommonPageData(DbContext db, string viewName, QueryDescriptor descriptor) { string sortName = descriptor.SortName; string text = descriptor.SortOrder; bool flag = false; bool flag2 = false; if (descriptor.PageIndex.HasValue && descriptor.PageSize.HasValue) { flag2 = true; if (descriptor.PageSize == 0L) { descriptor.PageSize = 20L; } } if (!StringExtensions.IsNullOrEmpty(sortName)) { flag = true; text = ((StringExtensions.IsNullOrEmpty(text) || StringExtensions.EqualsTo(text, "asc")) ? "asc" : "desc"); } FilterTranslator filterTranslator = new FilterTranslator(); if (descriptor.Condition != null) { filterTranslator.Group = descriptor.Condition; } filterTranslator.Translate(); string commandText = filterTranslator.CommandText; int num = 0; if (flag2) { commandText = (string.IsNullOrEmpty(commandText) ? "" : ("where " + commandText)); commandText = string.Format("SELECT * FROM (SELECT ROW_NUMBER() OVER (order by {1} {2}) peta_rn, * FROM [{0}] {3} ) peta_paged WHERE peta_rn> {4} AND peta_rn<= {5}", viewName, sortName ?? "ID", text, commandText, (descriptor.PageIndex.Value - 1L) * descriptor.PageSize.Value, descriptor.PageIndex.Value * descriptor.PageSize.Value); num = db.ExecuteScalar <int>("select count(*) from " + viewName + " " + (string.IsNullOrEmpty(filterTranslator.CommandText) ? "" : (" where " + filterTranslator.CommandText)), new object[1] { filterTranslator.Parms }); } else { commandText = (string.IsNullOrEmpty(commandText) ? "" : ("where " + commandText)); if (flag) { commandText += string.Format(" order by {0} {1}", sortName, text); } commandText = "select * from " + viewName + " " + commandText; } DataTable dataTable = new DataTable(); db.Fill(dataTable, commandText, new object[1] { filterTranslator.Parms }); List <Dictionary <string, object> > list = new List <Dictionary <string, object> >(); foreach (DataRow row in dataTable.Rows) { Dictionary <string, object> dictionary = new Dictionary <string, object>(); foreach (DataColumn column in dataTable.Columns) { dictionary.Add(column.ColumnName, row[column.ColumnName]); } list.Add(dictionary); } if (!flag2) { num = list.Count; } return(new PagedData(list, num)); }