using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using Wuqi.Webdiyer; using System.Data; using System.Data.OleDb; using System.Configuration; using System.Collections; using System.Web.Security; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using System.Web.Configuration; using Microsoft.VisualBasic; public partial class book2020 : System.Web.UI.Page { OleDbConnection con; protected void Page_Load(object sender, EventArgs e) { //if (!Page.IsPostBack) //{ string MyConnString = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" + Server.MapPath(".") + "/App_Data/ASPNetDB.mdb;"; con = new OleDbConnection(MyConnString); con.Open(); OleDbCommand cmd = new OleDbCommand(); cmd.Connection = con; string seriesid = ""; if (Request.QueryString["series"] != null) { seriesid = Request.QueryString["series"]; Labelhead.Text=seriesid; resultBOX.Visible = true; } string strcategory = ""; if (Request.QueryString["category"] != null) { strcategory = Request.QueryString["category"]; Labelhead.Text=strcategory; resultBOX.Visible = true; } int xx = Request.QueryString.Count; string strKey = ""; if (Request.QueryString["key"] != null) { strKey = Server.UrlDecode(Request.QueryString["key"].ToString().Trim()); strKey = Microsoft.VisualBasic.Strings.StrConv(strKey, Microsoft.VisualBasic.VbStrConv.TraditionalChinese, 1); string aas = ""; aas=strKey; Labelhead.Text="搜索關鍵字:" + aas; resultBOX.Visible = true; } if(strcategory!="") { if (strKey != "") { if(strcategory=="全部") { cmd.CommandText = "SELECT COUNT(*) FROM [zh_book] WHERE ([title] LIKE '%'+ ? +'%' OR [isbn] LIKE '%'+ ? +'%' OR [author] LIKE '%'+ ? +'%')"; cmd.Parameters.AddWithValue("title", strKey); cmd.Parameters.AddWithValue("isbn", strKey); cmd.Parameters.AddWithValue("author", strKey); } else { cmd.CommandText = "SELECT COUNT(*) FROM [zh_book] WHERE ([category] LIKE '%'+ ? +'%') AND ([title] LIKE '%'+ ? +'%' OR [isbn] LIKE '%'+ ? +'%' OR [author] LIKE '%'+ ? +'%')"; cmd.Parameters.AddWithValue("category", strcategory); cmd.Parameters.AddWithValue("title", strKey); cmd.Parameters.AddWithValue("isbn", strKey); cmd.Parameters.AddWithValue("author", strKey); //=============================================== } } else { if(strcategory=="全部") { cmd.CommandText = "SELECT COUNT(*) FROM [zh_book]"; } else { cmd.CommandText = "SELECT COUNT(*) FROM [zh_book] WHERE ([category] LIKE '%'+ ? +'%')"; cmd.Parameters.AddWithValue("category", strcategory); //Response.Write(strcategory); //============================================== //=============================================== } } } else { // catagory is empty if (seriesid == "") { if (strKey != "") { cmd.CommandText = "SELECT COUNT(*) FROM [zh_book] WHERE [title] LIKE '%'+ ? +'%' OR [isbn] LIKE '%'+ ? +'%' OR [author] LIKE '%'+ ? +'%'"; cmd.Parameters.AddWithValue("title", strKey); cmd.Parameters.AddWithValue("isbn", strKey); cmd.Parameters.AddWithValue("author", strKey); } else { cmd.CommandText = "SELECT COUNT(*) FROM [zh_book]"; firstPIC.Visible = true; resultBOX.Visible = false; } } else { if(seriesid!="") { if (strKey != "") { cmd.CommandText = "SELECT COUNT(*) FROM [zh_book] WHERE ([series] = ?) AND ([title] LIKE '%'+ ? +'%' OR [isbn] LIKE '%'+ ? +'%' OR [author] LIKE '%'+ ? +'%')"; cmd.Parameters.AddWithValue("series", seriesid); cmd.Parameters.AddWithValue("title", strKey); cmd.Parameters.AddWithValue("isbn", strKey); cmd.Parameters.AddWithValue("author", strKey); } else { cmd.CommandText = "SELECT COUNT(*) FROM [zh_book] WHERE ([series] = ?)"; cmd.Parameters.AddWithValue("series", seriesid); } } else { if (strKey != "") { cmd.CommandText = "SELECT COUNT(*) FROM [zh_book] WHERE [title] LIKE '%'+ ? +'%' OR [isbn] LIKE '%'+ ? +'%' OR [author] LIKE '%'+ ? +'%'"; cmd.Parameters.AddWithValue("title", strKey); cmd.Parameters.AddWithValue("isbn", strKey); cmd.Parameters.AddWithValue("author", strKey); } else { cmd.CommandText = "SELECT COUNT(*) FROM [zh_book]"; } } } } pagelist.AlwaysShow = true; pagelist.PageSize = 12; //显示页数 pagelist.RecordCount = (int)cmd.ExecuteScalar(); //读出数据库里一共有多少条数据 con.Close(); DataBindlist(); // } } protected void DataBindlist() { string MyConnString = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" + Server.MapPath(".") + "/App_Data/ASPNetDB.mdb;"; //OleDbDataAdapter ad = new OleDbDataAdapter("SELECT [ID], [isbn], [title], [price], [series] FROM [zh_book]", con); string seriesid = ""; if (Request.QueryString["series"] != null) { seriesid = Request.QueryString["series"]; } string strcategory = ""; if (Request.QueryString["category"] != null) { strcategory = Request.QueryString["category"]; } int xx = Request.QueryString.Count; string strKey = ""; if (Request.QueryString["key"] != null) { strKey = Server.UrlDecode(Request.QueryString["key"].ToString().Trim()); } OleDbDataAdapter ad; if (seriesid == "") { if (strKey != "") { if (strcategory == "全部" || strcategory == "") { ad = new OleDbDataAdapter("SELECT [ID], [isbn], [title], [price], [series],[author] FROM [zh_book] WHERE ([title] LIKE '%" + strKey + "%') OR ([isbn] LIKE '%" + strKey + "%') OR ([author] LIKE '%" + strKey + "%') order by bookorder*1, [pubyear] DESC, [pubmonth]*1 DESC, [isbn] DESC", con); } else { ad = new OleDbDataAdapter("SELECT [ID], [isbn], [title], [price], [series],[author] FROM [zh_book] WHERE ([category] like '%" + strcategory + "%') AND (([title] LIKE '%" + strKey + "%') OR ([isbn] LIKE '%" + strKey + "%') OR ([author] LIKE '%" + strKey + "%')) ORDER BY bookorder*1, [pubyear] DESC, [pubmonth]*1 DESC, [isbn] DESC", con); } } else { if (strcategory == "全部" || strcategory == "") { ad = new OleDbDataAdapter("SELECT [ID], [isbn], [title], [price], [series],[author] FROM [zh_book] ORDER BY bookorder*1, [pubyear] DESC, [pubmonth]*1 DESC, [isbn] DESC", con); } else { ad = new OleDbDataAdapter("SELECT [ID], [isbn], [title], [price], [series],[author] FROM [zh_book] WHERE [category] like '%" + strcategory + "%' ORDER BY bookorder*1, [pubyear] DESC, [pubmonth]*1 DESC, [isbn] DESC", con); } } } else { if (seriesid == "") { if (strKey != "") { ad = new OleDbDataAdapter("SELECT [ID], [isbn], [title], [price], [series],[author] FROM [zh_book] WHERE ([title] LIKE '%" + strKey + "%') OR ([isbn] LIKE '%" + strKey + "%') OR ([author] LIKE '%" + strKey + "%') ORDER BY bookorder*1, [pubyear] DESC, [pubmonth]*1 DESC, [isbn] DESC", con); } else { ad = new OleDbDataAdapter("SELECT [ID], [isbn], [title], [price], [series],[author] FROM [zh_book] ORDER BY bookorder*1, [pubyear] DESC, [pubmonth]*1 DESC, [isbn] DESC", con); } } else { if (strKey != "") { ad = new OleDbDataAdapter("SELECT [ID], [isbn], [title], [price], [series],[author] FROM [zh_book] WHERE ([series] = '" + seriesid + "') AND (([title] LIKE '%" + strKey + "%') OR ([isbn] LIKE '%" + strKey + "%') OR ([author] LIKE '%" + strKey + "%')) ORDER BY bookorder*1, [pubyear] DESC, [pubmonth]*1 DESC, [isbn] DESC", con); } else { ad = new OleDbDataAdapter("SELECT [ID], [isbn], [title], [price], [series],[author] FROM [zh_book] WHERE ([series] = '" + seriesid + "') ORDER BY bookorder*1, [pubyear] DESC, [pubmonth]*1 DESC, [isbn] DESC", con); } } } DataSet ds = new DataSet(); ad.Fill(ds, pagelist.PageSize * (pagelist.CurrentPageIndex - 1), pagelist.PageSize, "zh_book"); list.DataSource = ds.Tables["zh_book"]; list.DataBind(); } protected void PageChanging(object src, PageChangingEventArgs e) { pagelist.CurrentPageIndex = e.NewPageIndex; DataBindlist(); } protected void ImageButton1_Click(object sender, ImageClickEventArgs e) { if (TextBox1.Text != "") { Response.Redirect("book.aspx?key=" + Microsoft.VisualBasic.Strings.StrConv(TextBox1.Text, Microsoft.VisualBasic.VbStrConv.TraditionalChinese, 1)); } } }