public Model.PageModel <Model.CASInfo> PageSearchCasList(QueryModel.CASInfoQuery casQuery) { int num = 0; try { IQueryable <CASInfo> cas = context.CASInfo.AsQueryable <CASInfo>(); if (!string.IsNullOrWhiteSpace(casQuery.CAS_NUMBER)) { cas = from d in cas where d.Pub_CID.Equals(casQuery.CAS_NUMBER) || d.CHINESE.Equals(casQuery.CAS_NUMBER) || d.CHINESE_ALIAS.Equals(casQuery.CAS_NUMBER) || d.Record_Title.Equals(casQuery.CAS_NUMBER) select d; } if (!string.IsNullOrWhiteSpace(casQuery.CAS_NUMBERList)) { List <string> listcas = new List <string>(); string[] array = casQuery.CAS_NUMBERList.Split('~'); for (int i = 0; i < array.Length; i++) { if (!string.IsNullOrWhiteSpace(array[i])) { listcas.Add(array[i]); } } cas = from d in cas where (from p in listcas select p).Contains(d.Pub_CID.ToString()) select d; } cas = cas.GetPage(out num, casQuery.PageNo, casQuery.PageSize, (IQueryable <CASInfo> d) => from o in d orderby o.Pub_CID ascending select o); return(new PageModel <CASInfo>() { Models = cas, Total = num }); } catch (Exception) { return(null); } }
public Model.PageModel <Model.CASInfo> GetCasList(QueryModel.CASInfoQuery casQuery) { int num = 0; IQueryable <CASInfo> cas = context.CASInfo.AsQueryable <CASInfo>(); if (!string.IsNullOrWhiteSpace(casQuery.CHINESE)) { cas = from d in cas where d.CHINESE.Equals(casQuery.CHINESE) select d; } if (!string.IsNullOrWhiteSpace(casQuery.Molecular_Formula)) { cas = from d in cas where d.Molecular_Formula.Equals(casQuery.Molecular_Formula) select d; } if (!string.IsNullOrWhiteSpace(casQuery.CAS)) { cas = from d in cas where d.CAS.Equals(casQuery.CAS) select d; } cas = cas.GetPage(out num, casQuery.PageNo, casQuery.PageSize, (IQueryable <CASInfo> d) => from o in d orderby o.Pub_CID ascending select o); return(new PageModel <CASInfo>() { Models = cas, Total = num }); }
public int SearchCasInfoListCount(QueryModel.CASInfoQuery casQuery, string islike) { int num = 0; try { IQueryable <CASInfo> cas = context.CASInfo.AsQueryable <CASInfo>(); if (!string.IsNullOrWhiteSpace(casQuery.CAS_NUMBER)) { string search = casQuery.CAS_NUMBER; if (islike == "0") { if (Regex.IsMatch(search, @"[0-9?-]") && !Regex.IsMatch(search, @"[A-Za-z]+")) { cas = (from u in cas where u.Pub_CID.ToString().Contains(search) orderby u.Pub_CID descending select u); } else if (Regex.IsMatch(search, @"[\u4E00-\u9FA5]")) { cas = (from u in cas where u.CHINESE.Contains(search) || u.CHINESE_ALIAS.Contains(search) orderby u.Pub_CID descending select u); } //else if (Regex.IsMatch(search, @"[A-Za-z0-9]+")) else { cas = (from u in cas where u.Record_Title.Contains(search) || u.Record_Title.Contains(search) orderby u.Pub_CID descending select u); } } else //精确查询 { if (Regex.IsMatch(search, @"[0-9?-]") && !Regex.IsMatch(search, @"[A-Za-z]+")) { cas = (from u in cas where u.Pub_CID.Equals(search) orderby u.Pub_CID descending select u); } else if (Regex.IsMatch(search, @"[\u4E00-\u9FA5]")) { cas = (from u in cas where u.CHINESE.Equals(search) || u.CHINESE_ALIAS.Equals(search) orderby u.Pub_CID descending select u); } //else if (Regex.IsMatch(search, @"[A-Za-z0-9]+")) else { cas = (from u in cas where u.Record_Title.Equals(search) || u.Record_Title.Equals(search) orderby u.Pub_CID descending select u); } } } if (!string.IsNullOrWhiteSpace(casQuery.CAS_NUMBERList)) { List <string> listcas = new List <string>(); string[] array = casQuery.CAS_NUMBERList.Split('~'); for (int i = 0; i < array.Length; i++) { if (!string.IsNullOrWhiteSpace(array[i])) { listcas.Add(array[i]); } } cas = from d in cas where (from p in listcas select p).Contains(d.Pub_CID.ToString()) select d; } cas = cas.GetPage(out num, casQuery.PageNo, casQuery.PageSize, (IQueryable <CASInfo> d) => from o in d orderby o.Pub_CID descending select o); return(num); } catch (Exception) { return(0); } }
public PageModel <CASInfo> SearchCasInfoList(QueryModel.CASInfoQuery casQuery, string islike) { int num = 0; try { IQueryable <CASInfo> cas = context.CASInfo.AsQueryable <CASInfo>(); if (!string.IsNullOrWhiteSpace(casQuery.CAS_NUMBER)) { string search = casQuery.CAS_NUMBER; #region 模糊查询 if (islike == "0") { if (Regex.IsMatch(search, @"[0-9?-]") && !Regex.IsMatch(search, @"[A-Za-z]+")) { cas = (from u in cas where u.Pub_CID.ToString().Contains(search) orderby u.Pub_CID ascending select u).Skip(casQuery.PageSize * (casQuery.PageNo - 1)).Take(casQuery.PageSize); } else if (Regex.IsMatch(search, @"[\u4E00-\u9FA5]")) { cas = (from u in cas where u.CHINESE.Contains(search) || u.CHINESE_ALIAS.Contains(search) orderby u.Pub_CID ascending select u).Skip(casQuery.PageSize * (casQuery.PageNo - 1)).Take(casQuery.PageSize); } else { cas = (from u in cas where u.Record_Title.Contains(search) || u.Record_Title.Contains(search) orderby u.Pub_CID ascending select u).Skip(casQuery.PageSize * (casQuery.PageNo - 1)).Take(casQuery.PageSize); } } #endregion #region 精确查询 else { if (Regex.IsMatch(search, @"[0-9?-]") && !Regex.IsMatch(search, @"[A-Za-z]+")) { cas = (from u in cas where u.Pub_CID.ToString().Equals(search) orderby u.Pub_CID ascending select u).Skip(casQuery.PageSize * (casQuery.PageNo - 1)).Take(casQuery.PageSize); } else if (Regex.IsMatch(search, @"[\u4E00-\u9FA5]")) { cas = (from u in cas where u.CHINESE.Equals(search) || u.CHINESE_ALIAS.Equals(search) orderby u.Pub_CID ascending select u).Skip(casQuery.PageSize * (casQuery.PageNo - 1)).Take(casQuery.PageSize); } else { cas = (from u in cas where u.Record_Title.Equals(search) || u.Record_Title.Equals(search) orderby u.Pub_CID ascending select u).Skip(casQuery.PageSize * (casQuery.PageNo - 1)).Take(casQuery.PageSize); } } #endregion } if (!string.IsNullOrWhiteSpace(casQuery.CAS_NUMBERList)) { List <string> listcas = new List <string>(); string[] array = casQuery.CAS_NUMBERList.Split('~'); for (int i = 0; i < array.Length; i++) { if (!string.IsNullOrWhiteSpace(array[i])) { listcas.Add(array[i]); } } cas = (from d in cas where (from p in listcas select p).Contains(d.Pub_CID.ToString()) orderby d.Pub_CID ascending select d).Skip(casQuery.PageSize * (casQuery.PageNo - 1)).Take(casQuery.PageSize); } return(new PageModel <CASInfo>() { Models = cas, Total = cas.Count <CASInfo>() }); } catch (Exception) { return(null); } }