public IEnumerable <T> BindBoundControl <T>(string ClickedItemName, ToolStripTextBox tstb, ToolStripLabel tsl, Expression <Func <T, bool> > expr) where T : class { // , Expression<Func<T, Tkey>> exprOrderby Expression.Lambda(Expression.Property //(param, "ContactName"), try { pageSize = EMEWE.Common.Converter.ToInt(PageMaxCount.Replace("条", ""));//每页显示行数 if (rbool) { pageCurrent = 1; //当前页数从1开始 } else { if (!string.IsNullOrEmpty(tstb.Text)) { int.TryParse(tstb.Text, out pageCurrent); } } if (expr != null) { nMax = dc.GetTable <T>().Where <T>(expr).Count(); } else { nMax = dc.GetTable <T>().Count(); } pageCount = (nMax / pageSize); //计算出总页数 if ((nMax % pageSize) > 0) { pageCount++; } rbool = true; if (ClickedItemName != "") { itemClicked <T>(ClickedItemName); } tsl.Text = " 共 " + pageCount.ToString() + " 页 共 " + nMax.ToString() + " 条"; tstb.Text = Convert.ToString(pageCurrent); if (expr != null) { return(dc.GetTable <T>().Where <T>(expr).Skip <T>(nCurrent).Take <T>(pageSize).ToList());//.OrderBy<T, T>(exprOrderby) } else { return(dc.GetTable <T>().Skip <T>(nCurrent).Take <T>(pageSize).ToList()); } } catch (Exception ex) { Common.WriteTextLog("分页PageControl.BindBoundControl异常:" + ex.Message); return(null); } }
/// <summary> /// /// </summary> /// <typeparam name="T">操作对象</typeparam> /// <param name="ClickedItemName">操作行为名 传入空值表示返回数据前10条</param> /// <param name="tstb">显示当前页数控件</param> /// <param name="tsl">显示总条数和每页条数的控件</param> /// <param name="value">排序字段</param> /// <param name="fun">查询条件<</param> /// <returns></returns> public IEnumerable <T> BindBoundControl <T>(string ClickedItemName, ToolStripTextBox tstb, ToolStripLabel tsl, Expression <Func <T, bool> > expr, string value) where T : class { DCQUALITYDataContext dc = new DCQUALITYDataContext(); try { pageSize = EMEWE.Common.Converter.ToInt(PageMaxCount.Replace("条", ""));//每页显示行数 if (rbool) { pageCurrent = 1; //当前页数从1开始 } else { if (!string.IsNullOrEmpty(tstb.Text)) { int.TryParse(tstb.Text, out pageCurrent); } } if (expr != null) { nMax = dc.GetTable <T>().Where <T>(expr).Count(); } else { nMax = dc.GetTable <T>().Count(); } pageCount = (nMax / pageSize); //计算出总页数 if ((nMax % pageSize) > 0) { pageCount++; } rbool = true; if (ClickedItemName != "") { itemClicked <T>(ClickedItemName); } tsl.Text = " 共 " + pageCount.ToString() + " 页 共 " + nMax.ToString() + " 条"; tstb.Text = Convert.ToString(pageCurrent); Common.WriteTextLog("查询数据结束时间:" + DateTime.Now.ToString()); return(OrderBy <T>(value, expr)); } catch (Exception ex) { Common.WriteTextLog("分页FenYe.BindBoundControl异常:" + ex.Message); return(null); } }
private IEnumerable <T> ApplyOrder <T>(string property, string methodName, Expression <Func <T, bool> > expr1) where T : class { DCQUALITYDataContext db = new DCQUALITYDataContext(); Type type = typeof(T); ParameterExpression arg = Expression.Parameter(type, "a"); PropertyInfo pi = type.GetProperty(property); Expression expr = Expression.Property(arg, pi); type = pi.PropertyType; Type delegateType = typeof(Func <,>).MakeGenericType(typeof(T), type); LambdaExpression lambda = Expression.Lambda(delegateType, expr, arg); object result = typeof(Queryable).GetMethods().Single(a => a.Name == methodName && a.IsGenericMethodDefinition && a.GetGenericArguments().Length == 2 && a.GetParameters().Length == 2).MakeGenericMethod(typeof(T), type).Invoke(null, new object[] { expr1 != null ? db.GetTable <T>().Where <T>(expr1) : db.GetTable <T>(), lambda }); if (expr1 != null) { return(((IOrderedQueryable <T>)result).Skip <T>(nCurrent).Take <T>(pageSize).ToList()); } else { return(((IOrderedQueryable <T>)result).Skip <T>(nCurrent).Take <T>(pageSize).ToList()); } }
private void LoadData(string clickName) { if (clickName == "tslNextPage1") { if (currentPage != maxpage) { txtCurrentPage2.Text = (Convert.ToInt32(txtCurrentPage2.Text) + 1).ToString(); } else { MessageBox.Show("已经是最后一页!"); return; } } if (clickName == "tslPreviousPage2") { if (currentPage != 1) { txtCurrentPage2.Text = (Convert.ToInt32(txtCurrentPage2.Text) - 1).ToString(); } else { MessageBox.Show("已经是第一页!"); return; } } if (clickName == "tslHomPage1") { if (currentPage != 1) { txtCurrentPage2.Text = "1"; } else { MessageBox.Show("已经是第一页!"); return; } } if (clickName == "tslLastPage1") { if (currentPage != maxpage) { txtCurrentPage2.Text = maxpage.ToString(); } else { MessageBox.Show("已经是最后一页!"); return; } } sqlWhere = " 1=1"; if (expr == null) { expr = PredicateExtensionses.True <View_UnusualHandel>(); } if (txtCarNO.Text != "") { expr = expr.And(n => SqlMethods.Like(n.CNTR_NO, "%" + txtCarNO.Text.Trim() + "%")); } if (cbxPROD_ID.Text.Trim() != "全部") { expr = expr.And(n => SqlMethods.Like(n.PROD_ID, "%" + cbxPROD_ID.Text.Trim() + "%")); } if (cbxDictionary_Name.Text.Trim() != "全部") { expr = expr.And(n => SqlMethods.Like(n.Dictionary_Name, "%" + cbxDictionary_Name.Text.Trim() + "%")); } if (cbxTestItems_NAME.Text.Trim() != "全部") { expr = expr.And(n => SqlMethods.Like(n.TestItems_NAME, "%" + cbxTestItems_NAME.Text.Trim() + "%")); } if (cbxUnusual_State.Text.Trim() != "全部") { expr = expr.And(n => SqlMethods.Like(n.Unusual_State, "%" + cbxUnusual_State.Text.Trim() + "%")); } if (txtREF_NO.Text != "") { sqlWhere += " and REF_NO like '%" + txtREF_NO.Text.Trim() + "%'"; } pageSize = Convert.ToInt32(tscbxPageSize2.Text); currentPage = Convert.ToInt32(txtCurrentPage2.Text); int count = dc.GetTable <View_UnusualHandel>().Where <View_UnusualHandel>(expr).ToList().Count; maxpage = count % pageSize == 0 ? count % pageSize : Convert.ToInt32(count / pageSize) + 1; lblPageCount2.Text = "共" + maxpage + "页"; System.Collections.Generic.List <View_UnusualHandel> list = dc.GetTable <View_UnusualHandel>().Where <View_UnusualHandel>(expr).ToList().Skip((currentPage - 1) * pageSize).Take(pageSize).ToList(); DGVUnusual.DataSource = list; DGVUnusual.VirtualMode = false; listrecordID.Clear(); QCInfoIDS.Clear(); DRAW_EXAM_INTERFACE_ID_IDs.Clear(); DRAW_EXAM_INTERFACE_ID_IDs.Clear(); ids.Clear(); expr = null; }