using System; using System.Collections.Generic; using System.Linq; using System.Text; using SuperMap.RealEstate.Web.UI.WebControls; namespace HZQR.Common.Common { public class Common { /// /// 获得GridView的查询条件 /// /// SelectMethodParametersArgs /// public static string GetSqlWhereByParameter(SelectMethodParametersArgs e) { string sqlWhere = ""; string whereSqlString = e.WhereSqlString; foreach (var item in e.Parameters) { var key = item.Key; var val = item.Value.ToString(); if (val.StartsWith("%") && val.EndsWith("%")) { whereSqlString = whereSqlString.Replace(":" + key + " ", "'" + val + "' ").Replace(":" + key + ")", "'" + val + "')"); } else { whereSqlString = whereSqlString.Replace(":" + key, val); } } sqlWhere = whereSqlString.TrimStart(' '); if (!string.IsNullOrEmpty(sqlWhere) && !sqlWhere.StartsWith("where")) { sqlWhere = " WHERE " + sqlWhere; } if (sqlWhere.IndexOf("order by") > -1) { sqlWhere = sqlWhere.Substring(0, sqlWhere.IndexOf("order by")); } return sqlWhere; } } }