如下图,用户可能输入很多条件
在后端的处理方式:
使用键值对
private Dictionary<string, string> CreatSearchPara() { Dictionary<string, string> SearchPara = new Dictionary<string, string>(); if (!string.IsNullOrEmpty(txtMaterial.Text.Trim())) SearchPara["Material"] = txtMaterial.Text.Trim(); if (!string.IsNullOrEmpty(txtPurchaseOrder.Text.Trim())) SearchPara["PurchaseOrder"] = txtPurchaseOrder.Text.Trim(); if (!string.IsNullOrEmpty(txtPurchaser.Text.Trim())) SearchPara["Purchaser"] = txtPurchaser.Text.Trim(); }
Dictionary<string, string> SearchPara = CreatSearchPara();
dtReInpect = InspectReport.LoadIQCList(SearchPara);
//使用方法
public static DataTable LoadIQCList(Dictionary<string, string> SearchPara)
{
if (!(SearchPara != null && SearchPara.Count > 0)) return null;
string strSlectWhere = string.Empty;
string strWhere = string.Empty;
StringBuilder Sql_Where = new StringBuilder();
if (SearchPara.ContainsKey("Material"))
{
Sql_Where.Append(" and ( PN like '%" + SearchPara["Material"] + "%' or PN_DESC like '%" + SearchPara["Material"] + "%') ");
}
if (SearchPara.ContainsKey("PurchaseOrder"))
{
Sql_Where.Append(" and PO like '%" + SearchPara["PurchaseOrder"] + "%'");
}
}
标签:Trim,string,Dictionary,C#,Text,Material,SearchPara,处理,页面 From: https://www.cnblogs.com/kelenote/p/16724735.html