?? shopcartproduct.aspx.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 + -