码迷,mamicode.com
首页 > 其他好文 > 详细

好乱的代码

时间:2014-04-30 23:28:59      阅读:372      评论:0      收藏:0      [点我收藏+]

标签:com   http   class   img   java   c   t   tar   javascript   sp   ext   

<%@ WebHandler Language="C#" Class="Search_Book" %>

using System;
using System.Web;

public class Search_Book : IHttpHandler {

public void ProcessRequest (HttpContext context) {
context.Response.ContentType = "text/plain";


string txtTitle = context.Request["txtTitle"];
string txtAuthor = context.Request["txtAuthor"];
string txtPress = context.Request["txtPress"];

string sql = @"select * from Item where 1=1 ";
System.Data.DataTable dt;


if (!string.IsNullOrEmpty(txtTitle))
{
sql += @" and ItemName like ‘%" + @txtTitle + "%‘ ";

}

if (!string.IsNullOrEmpty(txtAuthor))
{
sql += @" and BookAuthor like ‘%" + @txtAuthor + "%‘ ";
}
if (!string.IsNullOrEmpty(txtPress))
{
sql += @" and publisher like ‘%" + @txtPress + "%‘ ";

}

if (!string.IsNullOrEmpty(txtTitle))
{
dt = SqlHelper.ExecuteDataTable(sql, new System.Data.SqlClient.SqlParameter(@txtTitle, txtTitle));

}
else if (!string.IsNullOrEmpty(txtAuthor))
{
dt = SqlHelper.ExecuteDataTable(sql, new System.Data.SqlClient.SqlParameter(@txtAuthor, txtAuthor));
}
else if (!string.IsNullOrEmpty(txtPress))
{
dt = SqlHelper.ExecuteDataTable(sql, new System.Data.SqlClient.SqlParameter(@txtPress, txtPress));
}
else if (!string.IsNullOrEmpty(txtTitle) && !string.IsNullOrEmpty(txtAuthor))
{
dt = SqlHelper.ExecuteDataTable(sql, new System.Data.SqlClient.SqlParameter(@txtTitle, txtTitle), new System.Data.SqlClient.SqlParameter(@txtAuthor, txtAuthor));
}
else if (!string.IsNullOrEmpty(txtTitle) && !string.IsNullOrEmpty(txtPress))
{
dt = SqlHelper.ExecuteDataTable(sql, new System.Data.SqlClient.SqlParameter(@txtTitle, txtTitle), new System.Data.SqlClient.SqlParameter(@txtPress, txtPress));

}
else if (!string.IsNullOrEmpty(txtAuthor) && !string.IsNullOrEmpty(txtPress))
{
dt = SqlHelper.ExecuteDataTable(sql, new System.Data.SqlClient.SqlParameter(@txtAuthor, txtAuthor), new System.Data.SqlClient.SqlParameter(@txtPress, txtPress));
}
else if (!string.IsNullOrEmpty(txtTitle) && !string.IsNullOrEmpty(txtAuthor) && !string.IsNullOrEmpty(txtPress))
{
dt = SqlHelper.ExecuteDataTable(sql, new System.Data.SqlClient.SqlParameter(@txtTitle, txtTitle), new System.Data.SqlClient.SqlParameter(@txtAuthor, txtAuthor), new System.Data.SqlClient.SqlParameter(@txtPress, txtPress));

}

dt = SqlHelper.ExecuteDataTable(sql);


if (dt.Rows.Count > 0)
{
// lblShow.Text = "";

//object[] datas = new object[dt.Rows.Count];
//for (int i = 0; i < datas.Length; i++)
//{
// System.Data.DataRow row = dt.Rows[i];
// DateTime addDT = (DateTime)row["AddTime"];
// datas[i] = new { BookId = row["BookId"], BookAuthor = row["BookAuthor"], Publisher = row["Publisher"], PublishDate = addDT.ToString(), BookPrice = row["BookPrice"], ItemName = row["ItemName"], ItemImage = row["ItemImage"] };
//}, ListPrice = row["ListPrice"]
//string json = new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(datas);

 

object[] comments = new object[dt.Rows.Count];
for (int i = 0; i < comments.Length; i++)
{
System.Data.DataRow row = dt.Rows[i];
DateTime creatDT = (DateTime)row["PublishDate"];
comments[i] = new { BookId = row["BookId"], BookAuthor = row["BookAuthor"], Publisher = row["Publisher"], PublishDate = creatDT.ToString("yyyy-MM-dd"), img = row["ItemImage"], ListPrice = row["ListPrice"], ItemName = row["ItemName"] };
}
string json = new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(comments);


context.Response.Write(json);


}
else if (dt.Rows.Count <= 0)
{

context.Response.Write("error_1");
}

 

}

public bool IsReusable {
get {
return false;
}
}

}

好乱的代码,码迷,mamicode.com

好乱的代码

标签:com   http   class   img   java   c   t   tar   javascript   sp   ext   

原文地址:http://www.cnblogs.com/cxzbk/p/3701304.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!