⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 product.ascx.cs

📁 网上书店
💻 CS
字号:
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

public partial class DefaultControl_Product : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            int howManyPages = 0;
            if (Request.QueryString["CategoryID"] != null)
            {
                string categoryID = Request.QueryString["CategoryID"].ToString();
             
                GetBooksInCategory(categoryID, 1, out howManyPages);

            }
            else
                if (Request.QueryString["DepartmentID"] != null)
                {
                    string departmentID = Request.QueryString["DepartmentID"].ToString();
                    
                    GetBooksInDepartment(departmentID, 1, out howManyPages);
                }

            if (Request.QueryString["IsNewBook"] != null)
            {

                GetBooksNew(1, out howManyPages);

            }

            if (Request.QueryString["IsHotBook"] != null)
            {

                GetBooksHot(1, out howManyPages);

            }

            if (Request.QueryString["xx"] != null)
            {

               
                GetBooksInNO(Int32.Parse( Request.QueryString["xx"].ToString()));

            }

            if (Request.QueryString["Search"] != null)
            {
                ExcuteSearch(Request.QueryString["Search"].ToString(), Request.QueryString["AllWords"].ToString(), 1, out howManyPages);


            }

            DropDownList1.Items.Clear();
            Label6.Text = howManyPages.ToString();
            for (int i = 1; i <= howManyPages; i++)
            {
                DropDownList1.Items.Add(i.ToString());
            }
        }
    }

    private void GetBooksInNO(int bookNO)
    {
        
        DataList1.DataSource = CommonDataAccess.GetBooksInNO(bookNO);
        DataList1.DataBind();
             
    }

    protected void ExcuteSearch(string searchString, string allWords, int pageNumber, out int howManyPages)
    {
        DataList1.DataSource = CommonDataAccess.Search(searchString, allWords, pageNumber.ToString(), out howManyPages);
        DataList1.DataBind();

    }

    protected void GetBooksHot(int pageNumber, out int howManyPages)
    {
        DataList1.DataSource = CommonDataAccess.GetBooksHot(pageNumber, out howManyPages);
        DataList1.DataBind();
    }

    protected void GetBooksNew(int pageNumber, out int howManyPages)
    {
        DataList1.DataSource = CommonDataAccess.GetBooksNew(pageNumber, out howManyPages);
        DataList1.DataBind();
    }

    private void GetBooksInDepartment(string departmentID, int pageNumber, out int howManyPages)
    {
        DataList1.DataSource = CommonDataAccess.GetBooksInDepartment(departmentID, pageNumber, out howManyPages);
        DataList1.DataBind();
    }
    protected void GetBooksInCategory(string categoryID, int pageNumber, out int howManyPages)
    {
        DataList1.DataSource = CommonDataAccess.GetBooksInCategory(categoryID, pageNumber, out howManyPages);
        DataList1.DataBind();

    }
    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        int pageNumber = Int32.Parse(DropDownList1.SelectedItem.Text);
        int howManyPage;
        if (Request.QueryString["CategoryID"] != null)
        {
            GetBooksInCategory(Request.QueryString["CategoryID"].ToString(), pageNumber, out howManyPage);
        }
        else
        {
            if (Request.QueryString["DepartmentID"] != null)
            {
                GetBooksInDepartment(Request.QueryString["DepartmentID"].ToString(), pageNumber, out howManyPage);
            }
        }

        if (Request.QueryString["IsNewBook"] != null)
        {
            GetBooksNew(pageNumber, out howManyPage);
        }

        if (Request.QueryString["IsHotBook"] != null)
        {
            GetBooksHot(pageNumber, out howManyPage);
        }
        if (Request.QueryString["Search"] != null)
        {
            ExcuteSearch(Request.QueryString["Search"].ToString(), Request.QueryString["AllWords"].ToString(), pageNumber, out howManyPage);
        }
    }

    protected void DataList1_ItemCommand(object source, DataListCommandEventArgs e)
    {
        if (e.CommandName == "xx")
        {
             
            string bookID = e.CommandArgument.ToString();
            CommonDataAccess.HotClick(Int32.Parse(bookID));
            Response.Redirect(Request.ApplicationPath + @"\Product.aspx?xx=" + bookID);

        }
        if (e.CommandName == "sc")
        {

            if (Session["Customer"] == null)
            {
                Response.Write("<script language='javascript' type='text/javascript'>alert('你还没有登陆,请先登陆');window.location.href='Default.aspx';</script>");
            }
            else
            {
                string bookID = e.CommandArgument.ToString();
                CommonDataAccess.HotClick(Int32.Parse(bookID));
                
                if (CommonDataAccess.AddShouCang(Session["Customer"].ToString(), Int32.Parse(bookID)))
                {
                    Message.ShowMsgBox(Page, "图书已被收藏");
                }
            }

        }

        if (e.CommandName == "Buy")
        {
            
            string bookID = e.CommandArgument.ToString();
            CommonDataAccess.HotClick(Int32.Parse(bookID));
            if (ShoppingCartAccess.ShoppingCartAddItem(bookID))
            {
                Message.ShowMsgBox(Page, "该图书已放入购物车");
            }
        }
    }
}
       


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -