本文共 6178 字,大约阅读时间需要 20 分钟。
网站的后台,多数是需要使用datatable来展示数据的,因为datatable的功能比较强大,可以更好的使用。
-
private object data = ""; private object result = ""; private int sEcho, iDisplayStart, iDisplayLength, sortid, count; private bool sorttype; protected void Page_Load(object sender, EventArgs e) { string act = null; try { act = Request["action"].ToString(); sEcho = Convert.ToInt32(Request["sEcho"]); iDisplayStart = Convert.ToInt32(Request["iDisplayStart"]);//开始记录数 iDisplayLength = Convert.ToInt32(Request["iDisplayLength"]);//结束记录数 if (!int.TryParse(Request["iSortCol_0"], out sortid))//按哪列来排序 { sortid = -1; } sorttype = Request["sSortDir_0"] == "asc" ? false : true;//升序还是降序 if (!string.IsNullOrEmpty(act)) { switch (act) { case "GetWorkerData": GetWorkerData(); break;//获取工作人员信息 } } result = data; } catch (Exception ex) { result = ReturnMsg(Enum_return.失败, ex.Message, null); } Response.Write(result); } #region 获取工作人员 private void GetWorkerData() { //按条件搜索 string mobile = Request["mobile"];//手机号码 string realname = Request["realname"];//用户类型 string logintimestart = Request["logintimestart"];//登录时间开始 string logintimeend = Request["logintimeend"];//登录时间结束 //获取所有数据 Listlist = null; IQueryable result = Ctx.yw_houseAgent_worker; #region 排序区分 switch (sortid) { case 0: if (sorttype) result = result.OrderByDescending(c => c.workerID); else result = result.OrderBy(c => c.workerID); break; case 1: if (sorttype) result = result.OrderByDescending(c => c.mobile); else result = result.OrderBy(c => c.mobile); break; case 2: if (sorttype) result = result.OrderByDescending(c => c.realName); else result = result.OrderBy(c => c.realName); break; case 3: if (sorttype) result = result.OrderByDescending(c => c.alipay); else result = result.OrderBy(c => c.alipay); break; case 5: if (sorttype) result = result.OrderByDescending(c => c.wechat); else result = result.OrderBy(c => c.wechat); break; case 7: if (sorttype) result = result.OrderByDescending(c => c.bank); else result = result.OrderBy(c => c.bank); break; case 8: if (sorttype) result = result.OrderByDescending(c => c.bankCardNumber); else result = result.OrderBy(c => c.bankCardNumber); break; case 9: if (sorttype) result = result.OrderByDescending(c => c.bankCardName); else result = result.OrderBy(c => c.bankCardName); break; case 10: if (sorttype) result = result.OrderByDescending(c => c.fund); else result = result.OrderBy(c => c.fund); break; case 11: if (sorttype) result = result.OrderByDescending(c => c.addTime); else result = result.OrderBy(c => c.addTime); break; default: if (sorttype) result = result.OrderByDescending(c => c.workerID); else result = result.OrderBy(c => c.workerID); break; } #endregion if (!string.IsNullOrEmpty(mobile) || !string.IsNullOrEmpty(realname) || !string.IsNullOrEmpty(logintimestart) || !string.IsNullOrEmpty(logintimeend)) //搜索情况 { #region 搜索情况 if (mobile.Trim().Length > 0)//手机号码 { result = result.Where(c => c.mobile.Contains(mobile)); } if (realname.Trim().Length > 0)//姓名 { result = result.Where(c => c.realName.Contains(realname)); } if (logintimestart.Trim().Length > 0 && logintimeend.Trim().Length > 0)//搜索查询时间 { DateTime bstart = Convert.ToDateTime(logintimestart); DateTime bend = Convert.ToDateTime(logintimeend); result = result.Where(c => c.addTime >= bstart && c.addTime <= bend); } #endregion } count = result.Where(c => c.serialID == CurrentSerialID && c.isDelete == false).Count(); list = result.Where(c => c.serialID == CurrentSerialID && c.isDelete == false).Skip(iDisplayStart).Take(iDisplayLength).ToList(); string str = SerializeTableData(sEcho, count, list); Response.Write(str); Response.End(); } #endregion
转载地址:http://mswza.baihongyu.com/