public static Paging <Drug> drugsPaging(int start, int limit, string sort, string dir, string filter) { List <Drug> drugs = Drug.Getdrugname; if (filter.Length > 0) { drugs.Clear(); DBMysql db = new DBMysql(); List <Drug> data = new List <Drug>(); string sql = "SELECT drg_name FROM drug_list "; //簡碼輸入 sql += "WHERE short_code LIKE '%" + filter + "%' AND drg_status='Y'"; DataTable dt1 = db.Query(sql); if (dt1.Rows.Count > 0) { for (int j = 0; j < dt1.Rows.Count; j++) { Drug drug = new Drug(); drug.py = filter; drug.drugname = dt1.Rows[j]["drg_name"].ToString(); //drg_name drugs.Add(drug); } } else //直接輸入中文字 { sql = "SELECT drg_name FROM drug_list "; sql += "WHERE drg_name LIKE '%" + filter + "%' AND drg_status='Y' "; dt1 = db.Query(sql); if (dt1.Rows.Count > 0) { for (int j = 0; j < dt1.Rows.Count; j++) { Drug drug = new Drug(); drug.py = filter; drug.drugname = dt1.Rows[j]["drg_name"].ToString(); //drg_name drugs.Add(drug); } } else { sql = "SELECT PY, HZ, ZM FROM pinyin "; if (filter != "*") { sql += "WHERE PY LIKE '" + filter + "%' AND ZM='" + filter.Substring(0, 1) + "' "; } DataTable dt = db.Query(sql); if (dt.Rows.Count > 0) //使用拼音輸入 { sql = "SELECT drg_name FROM drug_list WHERE (1=0 "; for (int i = 0; i < dt.Rows.Count; i++) { sql += "OR drg_name LIKE '" + dt.Rows[i]["HZ"].ToString() + "%' "; } sql += ") AND drg_status='Y'"; dt1 = db.Query(sql); if (dt1.Rows.Count > 0) { for (int j = 0; j < dt1.Rows.Count; j++) { Drug drug = new Drug(); drug.py = filter.Substring(0, 1); drug.drugname = dt1.Rows[j]["drg_name"].ToString(); //drg_name drugs.Add(drug); } } } dt.Dispose(); } dt1.Dispose(); db.Close(); } } //if (!string.IsNullOrEmpty(filter) && filter != "*") //{ // drugs.RemoveAll(drug => !drug.py.StartsWith(filter)); //} if (!string.IsNullOrEmpty(sort)) { drugs.Sort(delegate(Drug x, Drug y) { object a; object b; int direction = dir == "DESC" ? -1 : 1; a = x.GetType().GetProperty(sort).GetValue(x, null); b = y.GetType().GetProperty(sort).GetValue(y, null); return(CaseInsensitiveComparer.Default.Compare(a, b) * direction); }); } if ((start + limit) > drugs.Count) { limit = drugs.Count - start; } List <Drug> rangeDrugs = (start < 0 || limit < 0) ? drugs : drugs.GetRange(start, limit); return(new Paging <Drug>(rangeDrugs, drugs.Count)); }
public static Paging <Patinfo> PatinfosPaging(int start, int limit, string sort, string dir, string filter) { List <Patinfo> patinfos = Patinfo.Getpatname; if (filter.Length > 0) { patinfos.Clear(); DBMysql db = new DBMysql(); List <Patinfo> data = new List <Patinfo>(); string sql = "SELECT PY, HZ, ZM FROM pinyin "; if (filter != "*") { sql += "WHERE PY LIKE '%" + filter + "%' AND ZM='" + filter.Substring(0, 1) + "' "; } DataTable dt = db.Query(sql); if (dt.Rows.Count > 0) //使用拼音輸入 { sql = "SELECT pif_ic, pif_name FROM pat_info WHERE (1=0 "; for (int i = 0; i < dt.Rows.Count; i++) { sql += "OR pif_name LIKE '" + dt.Rows[i]["HZ"].ToString() + "%' "; } sql += ") "; DataTable dt1 = db.Query(sql); if (dt1.Rows.Count > 0) { for (int j = 0; j < dt1.Rows.Count; j++) { Patinfo patinfo = new Patinfo(); patinfo.patic = dt1.Rows[j]["pif_ic"].ToString(); patinfo.patname = dt1.Rows[j]["pif_name"].ToString(); patinfos.Add(patinfo); } } dt1.Dispose(); } else { sql = "SELECT pif_ic, pif_name FROM pat_info "; //直接輸入中文字 sql += "WHERE pif_name LIKE '%" + filter + "%' "; dt = db.Query(sql); if (dt.Rows.Count > 0) { for (int j = 0; j < dt.Rows.Count; j++) { Patinfo patinfo = new Patinfo(); patinfo.patic = dt.Rows[j]["pif_ic"].ToString();; patinfo.patname = dt.Rows[j]["pif_name"].ToString(); patinfos.Add(patinfo); } } } dt.Dispose(); db.Close(); } if (!string.IsNullOrEmpty(sort)) { patinfos.Sort(delegate(Patinfo x, Patinfo y) { object a; object b; int direction = dir == "DESC" ? -1 : 1; a = x.GetType().GetProperty(sort).GetValue(x, null); b = y.GetType().GetProperty(sort).GetValue(y, null); return(CaseInsensitiveComparer.Default.Compare(a, b) * direction); }); } if ((start + limit) > patinfos.Count) { limit = patinfos.Count - start; } List <Patinfo> rangePatinfos = (start < 0 || limit < 0) ? patinfos : patinfos.GetRange(start, limit); return(new Paging <Patinfo>(rangePatinfos, patinfos.Count)); }
public static Paging <Doctor> DoctorsPaging(int start, int limit, string sort, string dir, string filter) { List <Doctor> doctors = new List <Doctor>(); if (filter.Length > 0) { doctors.Clear(); DBMysql db = new DBMysql(); List <Doctor> data = new List <Doctor>(); string sql = "SELECT PY, HZ, ZM FROM pinyin "; if (filter != "*") { sql += "WHERE PY LIKE '" + filter + "%' AND ZM='" + filter.Substring(0, 1) + "' "; } DataTable dt = db.Query(sql); if (dt.Rows.Count > 0) //使用拼音輸入 { sql = "SELECT a.acclv_id, a.acclv_fname FROM access_level a "; sql += "INNER JOIN associate_list b ON a.acclv_id=b.associate_id "; sql += "WHERE (b.associate_type='DC' OR b.associate_type='DH') AND (1=0 "; for (int i = 0; i < dt.Rows.Count; i++) { sql += "OR a.acclv_fname LIKE '%" + dt.Rows[i]["HZ"].ToString() + "%' "; } sql += ") "; DataTable dt1 = db.Query(sql); if (dt1.Rows.Count > 0) { for (int j = 0; j < dt1.Rows.Count; j++) { Doctor doctor = new Doctor(); doctor.acclv_id = dt1.Rows[j]["acclv_id"].ToString(); doctor.acclv_fname = dt1.Rows[j]["acclv_fname"].ToString(); doctors.Add(doctor); } } dt1.Dispose(); } else { sql = "SELECT a.acclv_id, a.acclv_fname FROM access_level a "; //直接輸入中文字 sql += "INNER JOIN associate_list b ON a.acclv_id=b.associate_id "; sql += "WHERE (b.associate_type='DC' OR b.associate_type='DH') AND a.acclv_fname LIKE '%" + filter + "%' "; dt = db.Query(sql); if (dt.Rows.Count > 0) { for (int j = 0; j < dt.Rows.Count; j++) { Doctor doctor = new Doctor(); doctor.acclv_id = dt.Rows[j]["acclv_id"].ToString(); doctor.acclv_fname = dt.Rows[j]["acclv_fname"].ToString(); doctors.Add(doctor); } } } dt.Dispose(); db.Close(); } if (!string.IsNullOrEmpty(sort)) { doctors.Sort(delegate(Doctor x, Doctor y) { object a; object b; int direction = dir == "DESC" ? -1 : 1; a = x.GetType().GetProperty(sort).GetValue(x, null); b = y.GetType().GetProperty(sort).GetValue(y, null); return(CaseInsensitiveComparer.Default.Compare(a, b) * direction); }); } if ((start + limit) > doctors.Count) { limit = doctors.Count - start; } List <Doctor> rangeDoctors = (start < 0 || limit < 0) ? doctors : doctors.GetRange(start, limit); return(new Paging <Doctor>(rangeDoctors, doctors.Count)); }