index.aspx.cs

来自「这是我做的第一个网络购书中心asp.net网站!」· CS 代码 · 共 96 行

CS
96
字号
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class User_index : System.Web.UI.Page
{
    UserInfo ui = new UserInfo();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!this.IsPostBack)
        {            
            refineBind();
            hotBind();
            hotDiscount();
        }
    }
    public void refineBind()
    {
        ui.DGBind(1, "refine", dlRefinement, true);
    }
    public void hotBind()
    {
        ui.DGBind(2, "hot", dlHot, true);
    }
    public void hotDiscount()
    {
        ui.DGBind(3, "Discount", dlDiscount, true);
    }
    protected void dlRefinement_ItemCommand(object source, DataListCommandEventArgs e)
    {
        if (e.CommandName == "detail")
        {
            Session["address"] = "";
            Session["address"] = "~/User/index.aspx";
            Response.Redirect("~/User/GoodsDetail.aspx?GoodsID=" + Convert.ToInt32(dlRefinement.DataKeys[e.Item.ItemIndex].ToString()));
        }
        else if (e.CommandName == "buy")
        {
            addShopCart(e, dlRefinement);

        }
    }
    protected void dlHot_ItemCommand(object source, DataListCommandEventArgs e)
    {
        if (e.CommandName == "detail")
        {
            Session["address"] = "";
            Session["address"] = "~/User/index.aspx";
            Response.Redirect("~/User/GoodsDetail.aspx?GoodsID=" + Convert.ToInt32(dlHot.DataKeys[e.Item.ItemIndex].ToString()));
        }
        else if (e.CommandName == "buy")
        {
            addShopCart(e, dlHot);
        }
    }
    protected void dlDiscount_ItemCommand(object source, DataListCommandEventArgs e)
    {
        if (e.CommandName == "detail")
        {
            Session["address"] = "";
            Session["address"] = "~/User/index.aspx";
            Response.Redirect("~/User/GoodsDetail.aspx?GoodsID=" + Convert.ToInt32(dlDiscount.DataKeys[e.Item.ItemIndex].ToString()));
        }
        else if (e.CommandName == "buy")
        {
            addShopCart(e, dlDiscount);
        }
    }
    public void addShopCart(DataListCommandEventArgs e, DataList dlName)
    {
        if (Session["UID"] != null)
        {
            SaveGoodsClass sgc = getSaveGoodsClass(e, dlName);
            string userID = Session["UID"].ToString();
            ui.addShopCart(sgc.GoodsID, sgc.MemberPrice, userID);
            ui.MessageBox(Page, "添加成功");
        }
    }
    public SaveGoodsClass getSaveGoodsClass(DataListCommandEventArgs e, DataList dlName)
    {
        SaveGoodsClass goods = new SaveGoodsClass();
        goods.MemberPrice = Convert.ToDouble(e.CommandArgument.ToString());
        goods.GoodsID = dlName.DataKeys[e.Item.ItemIndex].ToString();
        return goods;
    }

   
}

⌨️ 快捷键说明

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