¹Ø±Õ

Asp.netÓÃÈý²ãʵÏÖ¶àÌõ¼þ¼ìË÷

·¢±íÓÚ£º2014-7-16 10:24

×ÖÌ壺´ó ÖРС | ÉÏһƪ | ÏÂһƪ | ÎÒҪͶ¸å

 ×÷ÕߣºJchubby¡¡¡¡ÖÚËùÖÜÖª£    À´Ô´£º51TestingÈí¼þ²âÊÔÍø²É±à

¡¡¡¡ÔÚ½çÃæ²ãÖеĴúÂ룺
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
¡¡¡¡´ó¹¦¸æ³É~£¡
22/2<12
¡¶2023Èí¼þ²âÊÔÐÐÒµÏÖ×´µ÷²é±¨¸æ¡·¶À¼Ò·¢²¼~

¹Ø×¢51Testing

ÁªÏµÎÒÃÇ

¿ì½ÝÃæ°å Õ¾µãµØͼ ÁªÏµÎÒÃÇ ¹ã¸æ·þÎñ ¹ØÓÚÎÒÃÇ Õ¾³¤Í³¼Æ ·¢Õ¹Àú³Ì

·¨ÂɹËÎÊ£ºÉϺ£À¼µÏÂÉʦÊÂÎñËù ÏîÆåÂÉʦ
°æȨËùÓÐ ÉϺ£²©Îª·åÈí¼þ¼¼Êõ¹É·ÝÓÐÏÞ¹«Ë¾ Copyright©51testing.com 2003-2024
ͶËß¼°Òâ¼û·´À¡£ºwebmaster@51testing.com; ÒµÎñÁªÏµ£ºservice@51testing.com 021-64471599-8017

»¦ICP±¸05003035ºÅ

»¦¹«Íø°²±¸ 31010102002173ºÅ