Cart.aspx.cs
上传用户:shjujing
上传日期:2022-07-28
资源大小:11244k
文件大小:5k
源码类别:

Email客户端

开发平台:

Visual C++

  1. using System;
  2. using System.Data;
  3. using System.Configuration;
  4. using System.Collections;
  5. using System.Web;
  6. using System.Web.Security;
  7. using System.Web.UI;
  8. using System.Web.UI.WebControls;
  9. using System.Web.UI.WebControls.WebParts;
  10. using System.Web.UI.HtmlControls;
  11. using ShopCart;
  12. using System.Text.RegularExpressions;
  13. public partial class Cart : PageBase
  14. {
  15.     UserInfoClass ucObj = new UserInfoClass();
  16.     classDB dd = new classDB();
  17.     protected void Page_Load(object sender, EventArgs e)
  18.     {
  19.         if (Session["Login"] == null)
  20.         {
  21.             Response.Write("<script>alert('对不起,你没有登陆,不能购买物品');</script>");
  22.             Panel1.Visible = true;
  23.             panel2.Visible = false;
  24.         }
  25.         else
  26.         {
  27.             Panel1.Visible = false;
  28.             panel2.Visible = true;
  29.             if (!IsPostBack)
  30.             {
  31.                 ShopCartBind();
  32.                 TotalDs();
  33.             }
  34.         }
  35.     }
  36.     //绑定市场价
  37.     public string GetMKPStr(string P_Str_MarketPrice)
  38.     {
  39.         return ucObj.VarStr(P_Str_MarketPrice, 1);
  40.     }
  41.     //绑定会员价
  42.     public string GetMBPStr(string P_Str_MemberPrice)
  43.     {
  44.         return ucObj.VarStr(P_Str_MemberPrice, 1);
  45.     }
  46.     //绑定小计
  47.     public string GetSPStr(string P_Str_SumPrice)
  48.     {
  49.         return ucObj.VarStr(P_Str_SumPrice, 1);
  50.     }
  51.     /// <summary>
  52.     /// 获取购物车中的商品信息
  53.     /// </summary>
  54.     public void ShopCartBind()
  55.     {
  56.         ucObj.SCIBind("ShopCart", gvShopCart, Convert.ToInt32(Session["Login"].ToString()));
  57.     }
  58.     /// <summary>
  59.     /// 显示购物车中的商品合计金额和商品数量
  60.     /// </summary>
  61.     public void TotalDs()
  62.     {
  63.         DataSet ds = ucObj.ReturnTotalDs(Convert.ToInt32(Session["Login"].ToString()), "TotalInfo");
  64.         lbSumPrice.Text = ucObj.VarStr(ds.Tables["TotalInfo"].Rows[0][0].ToString(), 1);
  65.         lbSumNum.Text = ucObj.VarStr(ds.Tables["TotalInfo"].Rows[0][2].ToString(), 1);
  66.         Session["totalNumber"] = lbSumNum.Text;
  67.         Session["totalPrice"] = lbSumPrice.Text;
  68.     }
  69.     protected void lnkbtnContinue_Click(object sender, EventArgs e)
  70.     {
  71.         Response.Redirect("produce.aspx");
  72.     }
  73.     protected void lnkbtnClear_Click(object sender, EventArgs e)
  74.     {
  75.         ucObj.DeleteShopCart(Convert.ToInt32(Session["Login"].ToString()));
  76.         ShopCartBind();
  77.         TotalDs();
  78.         lbLag.Visible = true;
  79.     }
  80.     protected void gvShopCart_PageIndexChanging(object sender, GridViewPageEventArgs e)
  81.     {
  82.         gvShopCart.PageIndex = e.NewPageIndex;
  83.         ShopCartBind();
  84.     }
  85.     protected void gvShopCart_RowDeleting(object sender, GridViewDeleteEventArgs e)
  86.     {
  87.         int P_Int_CartID = Convert.ToInt32(gvShopCart.DataKeys[e.RowIndex].Value.ToString());
  88.         ucObj.DeleteShopCartByID(Convert.ToInt32(Session["Login"].ToString()), P_Int_CartID);
  89.         ShopCartBind();
  90.         TotalDs();
  91.     }
  92.     protected void gvShopCart_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
  93.     {
  94.         gvShopCart.EditIndex = -1;
  95.         ShopCartBind();
  96.         TotalDs();
  97.     }
  98.     protected void gvShopCart_RowUpdating(object sender, GridViewUpdateEventArgs e)
  99.     {
  100.         int P_Int_CartID = Convert.ToInt32(gvShopCart.DataKeys[e.RowIndex].Value.ToString());
  101.         int P_Int_Num = Convert.ToInt32(((TextBox)(gvShopCart.Rows[e.RowIndex].Cells[3].Controls[0])).Text.ToString());
  102.         if (IsValidNum(P_Int_Num.ToString()) == true)
  103.         {
  104.             ucObj.UpdateSCI(Convert.ToInt32(Session["Login"].ToString()), P_Int_CartID, P_Int_Num);
  105.             gvShopCart.EditIndex = -1;
  106.             ShopCartBind();
  107.             TotalDs();
  108.         }
  109.         else
  110.         {
  111.             gvShopCart.EditIndex = -1;
  112.             ShopCartBind();
  113.             TotalDs();
  114.         }
  115.     }
  116.     protected void gvShopCart_RowEditing(object sender, GridViewEditEventArgs e)
  117.     {
  118.         gvShopCart.EditIndex = e.NewEditIndex;
  119.         ShopCartBind();
  120.         TotalDs();
  121.     }
  122.     //判断修改的数据是否为有效的数据
  123.     public bool IsValidNum(string num)
  124.     {
  125.         return Regex.IsMatch(num, @"^+?[1-9][0-9]*$");
  126.     }
  127.     protected void LinkButton1_Click(object sender, EventArgs e)
  128.     {
  129.         String oid = Session["Login"].ToString();
  130.         if (dd.IsCartNO(oid) != 0)
  131.         {
  132.             Response.Redirect("UserOrder.aspx");
  133.         }
  134.         else
  135.         {
  136.             Response.Write("<script>alert('购物车没有商品,不能提交!');</script>");
  137.         }
  138.     }
  139. }