/// <summary> /// 处理SQL语句, 关于简写 /// </summary> /// <param name="s">SQL语句</param> /// <returns></returns> public static string DealSQL <ObjectType>(string s) { //s = " =Adminname and =Pwd and <>SortId1 or %Sex or -Sex% or %Sex% "; s = " " + s + " "; Regex _R = new Regex(@"\s(=|<>|%|-)([_a-zA-Z][_a-zA-Z0-9]*)%?\s"); MatchCollection _mc = _R.Matches(s); foreach (Match m in _mc) { string c = m.Value; string a1 = m.Result("$1"); string a2 = m.Result("$2"); switch (a1) { case "=": s = s.Replace(c, " " + a2 + a1 + "@" + a2 + " "); break; case "<>": s = s.Replace(c, " " + a2 + a1 + "@" + a2 + " "); break; case "%": if (c.LastIndexOf("%") > 1) { s = s.Replace(c, " " + a2 + " like " + "'%' + @" + a2 + " + '%' "); } else { s = s.Replace(c, " " + a2 + " like " + "'%' + @" + a2 + " "); } break; case "-": if (c.LastIndexOf("%") > 1) { s = s.Replace(c, " " + a2 + " like " + "@" + a2 + " + '%' "); } break; } } //加入分站条件 s = s.Trim(); string SubSite = Common.Base.CookieClass.getCookie("SubSite"); if (!string.IsNullOrEmpty(SubSite) && SubSite.ToInt32() != 0 && IsOpenSubSite) { TableInfo tableInfo = AttributeHelper.GetInfo <ObjectType>(); foreach (ColumnAttribute ca in tableInfo.Columns) { if (ca.Name.ToLower() == "SiteCityID".ToLower()) { if (string.IsNullOrEmpty(s)) { s = " 1=1 "; } s += " and SiteCityID=" + SubSite.ToInt32().ToString() + " "; break; } } } return(s.Trim()); }