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

📄 shopcartproduct.aspx.cs

📁 是一个很好的电子商务系统,是用C#语言开发的,能够完成网上购物的功能
💻 CS
字号:
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;
using System.Data.SqlClient;

public partial class ShopCartProduct : System.Web.UI.Page
{
    decimal total = 0;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!User.Identity.IsAuthenticated)
        {
            Response.Redirect("~/login_Register.aspx");
        }
        if (!Page.IsPostBack)
        {
            ShopcarDB Sdb = new ShopcarDB();
            if (Sdb.GetShopcartCount(User.Identity.Name) > 0)
            {
                this.GetShopCartBind();
                this.Label1.Visible = false;
            }
            else
            {
                this.Label1.Visible = true;
                this.GridViewshopcart.Visible = false;
            }
        }
    }
    private void GetShopCartBind()
    {
        ShopcarDB Sdb = new ShopcarDB();
        SqlDataReader Sdr = Sdb.GetShopcartData(User.Identity.Name);
        this.GridViewshopcart.DataSource = Sdr;
        this.GridViewshopcart.DataBind();
        Sdr.Close();
    }

    protected void GridViewshopcart_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        int PID = Int32.Parse(this.GridViewshopcart.DataKeys[e.RowIndex].Value.ToString());
        Shopcart Scart = new Shopcart();
        Scart.CustomerID = User.Identity.Name;
        Scart.ProductID = PID;
        ShopcarDB Sdb = new ShopcarDB();
        Sdb.DeleteShopcartItem(Scart);
        if (Sdb.GetShopcartCount(User.Identity.Name) > 0)
        {
            this.GetShopCartBind();
            this.Label1.Visible = false;
        }
        else 
        {
            this.Label1.Visible = true;
            this.GridViewshopcart.Visible = false;
        }
    }
    protected void btnUpdate_Click(object sender, EventArgs e)
    {
        for (int i = 0; i < this.GridViewshopcart.Rows.Count; i++)
        {
            GridViewRow row = this.GridViewshopcart.Rows[i];
            if (row.RowType == DataControlRowType.DataRow)
            {
                int PID = Int32.Parse(row.Cells[0].Text);
                int quantity = Int32.Parse(((TextBox)row.FindControl("txtQuantity")).Text);
                String customerid = User.Identity.Name;
                Shopcart scart = new Shopcart();
                scart.CustomerID = customerid;
                scart.ProductID = PID;
                scart.Quantity = quantity;
                ShopcarDB Sdb = new ShopcarDB();
                if (quantity > 0)
                {
                    Sdb.UpdateShopCartFirst(scart, false);
                }
            }
        }
        this.GetShopCartBind();

    }

    protected void GridViewshopcart_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            String str = e.Row.Cells[2].Text;
            decimal unitcost = Convert.ToDecimal(str.Substring(1));
            int quantity = Int32.Parse(((TextBox)(e.Row.FindControl("txtQuantity"))).Text);
            total += unitcost * quantity;
            LinkButton Mydeletebutton;
            Mydeletebutton = (LinkButton)(e.Row.FindControl("Linkbutton1"));
            Mydeletebutton.Attributes.Add("onclick", "return confirm('你是否确认删除?')");     
        }
        if(e.Row.RowType==DataControlRowType.Footer)
        {
            ((Label)(e.Row.FindControl("TotalLabel"))).Text = "Price:" + total.ToString();
        }

    }
}

⌨️ 快捷键说明

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