/// <summary> /// 创建分页查询 /// </summary> /// <param name="query"></param> /// <param name="pageSize"></param> /// <param name="pageIndex"></param> /// <returns></returns> protected internal override QuerySection <T> CreatePageQuery <T>(QuerySection <T> query, int itemCount, int skipCount) { if (skipCount == 0) { ((IPaging)query).Prefix("TOP " + itemCount); return(query); } else { //如果没有指定Order 则由指定的key来排序 if (string.IsNullOrEmpty(query.OrderString)) { Field pagingField = query.PagingField; if ((IField)pagingField == null) { throw new DataException("请指定分页主键或设置排序!"); } query.OrderBy(pagingField.Asc); } ((IPaging)query).Suffix(",ROW_NUMBER() OVER(" + query.OrderString + ") AS TMP__ROWID"); query.OrderBy(OrderByClip.None); query.SetPagingField(null); QuerySection <T> jquery = query.SubQuery("TMP_TABLE"); jquery.Where(new WhereClip("TMP__ROWID BETWEEN " + (skipCount + 1) + " AND " + (itemCount + skipCount))); jquery.Select(Field.All.At("TMP_TABLE")); return(jquery); } }
public QueryField(QuerySection section, PropertyInfo pi, GetCountsResult counts) { ParentSection = section; Title = pi.GetCustomAttribute <DisplayNameAttribute>()?.DisplayName ?? pi.Name; var pt = pi.PropertyType; if (pt.IsNumber()) { QueryFieldType = QueryFieldTypes.Numeric; } else if (pt == typeof(bool)) { QueryFieldType = QueryFieldTypes.Boolean; } else if (pt == typeof(DateTime)) { QueryFieldType = QueryFieldTypes.Date; } else { QueryFieldType = QueryFieldTypes.Text; } PropertyPath = (ParentSection.PropertyPath.AppendIfHasData(".") ?? "") + pi.Name; JPath = (ParentSection.JPath.AppendIfHasData(".") ?? "") + pi.GetSerializedPropertyName(); if (counts != null) { var cntByVal = counts.CntByValByField.FindOrDefault(JPath); if (cntByVal != null && cntByVal.Count > 0) { ValuesList = cntByVal.ConvertAll(kvp => new SelectListItem { Value = kvp.Key, Text = $"{kvp.Key} ({kvp.Value})" }); } } }
/// <summary> /// 创建分页查询 /// </summary> /// <param name="query"></param> /// <param name="pageSize"></param> /// <param name="pageIndex"></param> /// <returns></returns> protected internal override QuerySection <T> CreatePageQuery <T>(QuerySection <T> query, int itemCount, int skipCount) { if (skipCount == 0) { ((IPaging)query).Prefix("top " + itemCount); return(query); } else { //如果没有指定Order 则由指定的key来排序 if (query.OrderString == null) { Field pagingField = query.PagingField; if ((IField)pagingField == null) { throw new MySoftException("请指定分页主键或设置排序!"); } query.OrderBy(pagingField.Asc); } ((IPaging)query).Suffix(",row_number() over(" + query.OrderString + ") as tmp__rowid"); query.OrderBy(OrderByClip.Default); QuerySection <T> jquery = query.SubQuery("tmp_table"); jquery.Where(new WhereClip("tmp__rowid between " + (skipCount + 1) + " and " + (itemCount + skipCount))); jquery.Select(Field.All.At("tmp_table")); return(jquery); } }
/// <summary> /// 创建分页查询 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="query"></param> /// <param name="itemCount"></param> /// <param name="skipCount"></param> /// <returns></returns> protected internal override QuerySection <T> CreatePageQuery <T>(QuerySection <T> query, int itemCount, int skipCount) { if (skipCount == 0) { ((IPaging)query).Prefix("TOP " + itemCount); return(query); } else { ((IPaging)query).Prefix("TOP " + itemCount); Field pagingField = query.PagingField; if ((IField)pagingField == null) { throw new DataException("SqlServer2000或Access请使用SetPagingField设定分页主键!"); } QuerySection <T> jquery = query.CreateQuery <T>(); ((IPaging)jquery).Prefix("TOP " + skipCount); jquery.Select(pagingField); //sqlserver2000分页条件操作 query.PageWhere = !pagingField.In(jquery); return(query); } }
// GET: Product/Delete/5 public ActionResult Delete(QuerySection qry) { var d = nZFurniture.QuerySections.Where(x => x.id == qry.id).FirstOrDefault(); nZFurniture.QuerySections.Remove(d); nZFurniture.SaveChanges(); return(RedirectToAction("ManageQuery")); }
public QuerySection(CollectionNames collection, Type baseType, MemberInfo baseMember, bool includePhi, GetCountsResult counts, QuerySection parentSection = null) { Collection = collection; ParentSection = parentSection; Title = baseType.GetCustomAttribute <DisplayNameAttribute>()?.DisplayName ?? baseType.Name; if (baseMember != null) { PropertyPath = parentSection.PropertyPath + "." + baseMember.Name; JPath = parentSection.JPath + "." + baseMember.GetSerializedPropertyName(); } baseType.MemberWalk <QuerySection>( BindingFlags.GetProperty | BindingFlags.Public | BindingFlags.Instance, (parent, t, mi) => this, (ctx, t, mi) => { var pi = (PropertyInfo)mi; if (ShouldIgnore(pi)) { return; } if (t.GetTypeInfo().IsClass&& t.Namespace.StartsWith("Traffk.")) { var s = new QuerySection(collection, t, mi, includePhi, counts, this); if (s.Children.Count > 0) { Children.Add(s); } } else { var qf = new QueryField(this, pi, counts); Children.Add(qf); } }, (ctx, t, mi) => { if (t.IsA(typeof(IEnumerable))) { return(false); } if (!t.Namespace.StartsWith("Traffk.")) { return(false); } if (ShouldIgnore((PropertyInfo)mi)) { return(false); } return(true); } ); }
public async Task Populate(TraffkRdbContext rdb, CrmDdbContext crm, bool includePhi, params CollectionNames[] supportedCollections) { foreach (var collection in supportedCollections) { Type baseType; GetCountsResult counts = null; switch (collection) { case CollectionNames.Contacts: counts = await rdb.GetContrainedFieldCountsAsync <Contact>(true); baseType = typeof(Contact); break; case CollectionNames.Eligibility: counts = await rdb.GetContrainedFieldCountsAsync <Eligibility>(true); baseType = typeof(Eligibility); break; case CollectionNames.Scores: counts = await rdb.GetContrainedFieldCountsAsync <Score>(true); baseType = typeof(Score); break; case CollectionNames.Demographics: counts = await rdb.GetContrainedFieldCountsAsync <Demographic>(true); baseType = typeof(Demographic); break; case CollectionNames.Pcp: counts = await rdb.GetContrainedFieldCountsAsync <MemberPCP>(true); baseType = typeof(MemberPCP); break; case CollectionNames.HighCostDiagnosis: counts = await rdb.GetContrainedFieldCountsAsync <HighCostDiagnosi>(true); baseType = typeof(HighCostDiagnosi); break; default: throw new UnexpectedSwitchValueException(collection); } var section = new QuerySection(collection, baseType, null, includePhi, counts); Sections.Add(section); } }
/// <summary> /// 创建分页 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="query"></param> /// <param name="itemCount"></param> /// <param name="skipCount"></param> /// <returns></returns> protected override QuerySection <T> CreatePageQuery <T>(QuerySection <T> query, int itemCount, int skipCount) { if (skipCount == 0) { ((IPaging)query).End("LIMIT " + itemCount); return(query); } else { string suffix = string.Format("LIMIT {0} OFFSET {1}", itemCount, skipCount); ((IPaging)query).End(suffix); return(query); } }
/// <summary> /// 创建分页 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="query"></param> /// <param name="itemCount"></param> /// <param name="skipCount"></param> /// <returns></returns> protected override QuerySection <T> CreatePageQuery <T>(QuerySection <T> query, int itemCount, int skipCount) { if (skipCount == 0) { ((IPaging)query).Prefix("FIRST " + itemCount); return(query); } else { string prefix = string.Format("FIRST {0} SKIP {1}", itemCount, skipCount); ((IPaging)query).Prefix(prefix); return(query); } }
internal NodeQuerySectionEventArgs(QuerySection Section, NodeQuery Query, MessageEventArgs Message) : base(Query, Message) { this.section = Section; }