C# 当页面有很多选择条件时的处理方式

如下图,用户可能输入很多条件

 

 

在后端的处理方式:

使用键值对

  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"] + "%'");
  }
}

 

 

posted on 2022-09-24 00:05  写个笔记  阅读(107)  评论(0编辑  收藏  举报

导航