???????????е????

 

List<SearchModel> ss = new List<SearchModel>();
if (!string.IsNullOrEmpty(Request.Form["txtName"]))//?????????????????????????
{
SearchModel model = new SearchModel();
model.Name = "BookName";//???????????????
model.Value = Request.Form["txtName"];//???????????????????
model.Action = Action.Like;//?????like
ss.Add(model);
}//????????
if (!string.IsNullOrEmpty(Request.Form["txtAuthor"]))
{
SearchModel model = new SearchModel();
model.Name = "Author";
model.Value = Request.Form["txtAuthor"];
model.Action = Action.Like;
ss.Add(model);
}
if (!string.IsNullOrEmpty(Request.Form["categoryId"]))
{
SearchModel model = new SearchModel();
model.Name = "CategoryId";
model.Value = Request.Form["categoryId"];
model.Action = Action.Equart;
ss.Add(model);
}
if (!string.IsNullOrEmpty(Request.Form["publisherId"]))
{
SearchModel model = new SearchModel();
model.Name = "PublisherId";
model.Value = Request.Form["publisherId"];
model.Action = Action.Equart;
ss.Add(model);
}
if (!string.IsNullOrEmpty(Request.Form["txtISBN"]))
{
SearchModel model = new SearchModel();
model.Name = "ISBN";
model.Value = Request.Form["txtISBN"];
model.Action = Action.Like;
ss.Add(model);
}
if (!string.IsNullOrEmpty(Request.Form["isDiscount"]))
{
SearchModel model = new SearchModel();
model.Name = "Discount";
model.Value = "1";
model.Action = Action.Equart;
ss.Add(model);
}
List<T_Books> books = searchBll.Searc(ss);//???????Bll???в???

????Bll???????????Dal???sql???

 

public List<T_Books> Search(List<SearchModel> ss)//???????????????????????????????б???
{
string sql = "select * from T_Books where IsDelete=0 and ";//??????sql???
for (int i = 0; i < ss.Count; i++)
{
if (ss[i].Action == Action.Like)
{
sql += ss[i].Name + " like '%" + ss[i].Value + "%'";
}
if (ss[i].Action == Action.Equart)
{
sql += ss[i].Name + " = " + ss[i].Value;
}
if (ss[i].Action == Action.Greatthan)
{
sql += ss[i].Name + " > " + ss[i].Value;
}
if (ss[i].Action == Action.Lessthan)
{
sql += ss[i].Name + " < " + ss[i].Value;
}
if (i != ss.Count - 1)
{
sql += " and ";
}
}
List<T_Books> list = new List<T_Books>();
DataTable table = SqlHelper.ExecuteDataTable(sql?? CommandType.Text);//???????sql????????????????
foreach (DataRow row in table.Rows)
{
T_Books book = GetModelByDataRow.GetBooks(row);
list.Add(book);
}
return list;//???????????????鼯??????
}
??????????????????????????
?????????????????sql???????
????select * from T_Books where IsDelete=0 and BookName like '%C++%' and Author like '%JChubby%' and CategoryId = 15 and PublisherId = 16 and ISBN like '%1111%' and Discount = 1
?????????~??