public ActionResult FindCustomList(int?pageSize, int?pageIndex, string sortOrder, string sortName, string queryName, string queryValue) { #region CWICCard cwiccd = new CWICCard(); List <Customer> custLst = cwiccd.FindCustList(cust => true); List <CustomerModel> models = new List <CustomerModel>(); foreach (Customer cust in custLst) { CustomerModel model = new CustomerModel(); model.ID = cust.ID; model.UserName = cust.UserName; model.PlateNum = cust.PlateNum; model.Type = cust.Type; model.Warehouse = cust.Warehouse; model.LocAddress = cust.LocAddress; model.MobilePhone = cust.MobilePhone; model.Deadline = cust.Deadline.ToString(); model.FamilyAddress = cust.FamilyAddress; ICCard iccd = cwiccd.Find(ic => ic.CustID == cust.ID); if (iccd != null) { model.UserCode = iccd.UserCode; model.Status = iccd.Status; } models.Add(model); } List <CustomerModel> firstQuery = new List <CustomerModel>(); if (queryName != "0" && !string.IsNullOrEmpty(queryValue)) { #region if (queryName == "UserCode") { firstQuery = models.Where(md => md.UserCode.Contains(queryValue)).ToList(); } else if (queryName == "Type") { EnmICCardType type = EnmICCardType.Init; if (queryValue.Contains("临时")) { type = EnmICCardType.Temp; } else if (queryValue.Contains("定期")) { type = EnmICCardType.Periodical; } else if (queryValue.Contains("固定")) { type = EnmICCardType.FixedLocation; } else if (queryValue.ToUpper().Contains("VIP")) { type = EnmICCardType.VIP; } firstQuery = models.Where(md => md.Type == type).ToList(); } else if (queryName == "UserName") { firstQuery = models.Where(md => md.UserName.Contains(queryValue)).ToList(); } else if (queryName == "FamilyAddress") { firstQuery = models.Where(md => md.FamilyAddress.Contains(queryValue)).ToList(); } else if (queryName == "MobilePhone") { firstQuery = models.Where(md => md.MobilePhone.Contains(queryValue)).ToList(); } else if (queryName == "LocAddress") { firstQuery = models.Where(md => md.LocAddress == queryValue).ToList(); } else if (queryName == "PlateNum") { firstQuery = models.Where(md => md.PlateNum.Contains(queryValue)).ToList(); } #endregion } else { firstQuery.AddRange(models); } #region 排序 只允许几个字段可以排序 List <CustomerModel> sortList = new List <CustomerModel>(); if (!string.IsNullOrEmpty(sortName)) { if (sortName == "ID") { if (sortOrder.ToLower() == "asc") { var sort = from cu in firstQuery orderby cu.ID ascending select cu; sortList.AddRange(sort); } else { var sort = from cu in firstQuery orderby cu.ID descending select cu; sortList.AddRange(sort); } } else if (sortName == "Type") { if (sortOrder.ToLower() == "asc") { var sort = from cu in firstQuery orderby(int) cu.Type ascending select cu; sortList.AddRange(sort); } else { var sort = from cu in firstQuery orderby(int) cu.Type descending select cu; sortList.AddRange(sort); } } else if (sortName == "LocAddress") { if (sortOrder.ToLower() == "asc") { var sort = from cu in firstQuery orderby cu.LocAddress ascending select cu; sortList.AddRange(sort); } else { var sort = from cu in firstQuery orderby cu.LocAddress descending select cu; sortList.AddRange(sort); } } else if (sortName == "UserCode") { if (sortOrder.ToLower() == "asc") { var sort = from cu in firstQuery orderby cu.UserCode ascending select cu; sortList.AddRange(sort); } else { var sort = from cu in firstQuery orderby cu.UserCode descending select cu; sortList.AddRange(sort); } } else { sortList.AddRange(firstQuery); } } else { sortList.AddRange(firstQuery); } #endregion #endregion #region 分页 int index = 1; int size = 10; if (pageSize != null) { size = (int)pageSize; } if (pageIndex != null) { index = (int)pageIndex; } int total = firstQuery.Count; List <CustomerModel> last = sortList.Skip((index - 1) * size).Take(size).ToList(); #endregion var value = new { total = total, rows = last }; Task.Factory.StartNew(() => { #region 除没有绑定用户的指纹(垃圾指纹) CWFingerPrint cwfinger = new CWFingerPrint(); List <FingerPrint> noCustFPrintLst = cwfinger.FindList(fp => fp.CustID == 0); foreach (FingerPrint print in noCustFPrintLst) { cwfinger.Delete(print.ID, false); } #endregion }); return(Json(value)); }