예제 #1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Session.Contents["TrangThaiUse"].ToString() == "ChuaDangNhap")
                {
                    Response.Redirect("GioHang.aspx");
                }
                else
                {
                    bool kiemtra = false;
                    int masp = int.Parse(Request.QueryString.Get("MaSanPham").ToString());
                    dt = (DataTable)Session["Cart"];
                    XulyLayTen_GiaSanPham name_cost = new XulyLayTen_GiaSanPham();
                    name_cost.Thongtinsanpham.MaSanPham = masp;
                    name_cost.Thucthi();
                    string tensp = name_cost.LaytenSP();
                    int giasp = int.Parse(name_cost.LayGiaSP().ToString());
                    if (dt.Rows.Count != 0)
                    {
                        foreach (DataRow dr in dt.Rows)
                        {

                            if (int.Parse(dr[0].ToString()) == masp)
                            {
                                dr[3] = Convert.ToInt32(dr[3].ToString()) + 1;
                                dr[4] = Convert.ToInt32(dr[2].ToString()) * Convert.ToInt32(dr[3].ToString());
                                kiemtra = true;
                            }
                        }
                    }
                    if (kiemtra == false)
                    {
                        DataRow dr = dt.NewRow();
                        dr[0] = masp;
                        dr[1] = tensp;
                        dr[2] = giasp;
                        dr[3] = 1;
                        dr[4] = Convert.ToInt32(dr[2].ToString()) * (Convert.ToInt32(dr[3].ToString()));
                        dt.Rows.Add(dr);
                        Session["Cart"] = dt;
                    }

                    Response.Redirect("SanPham.aspx");
                }
            }
        }
예제 #2
0
        protected void grv_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            try
            {
                string str = grv_GioHang.DataKeys[e.RowIndex].Values[0].ToString();

                TextBox soluong = (TextBox)grv_GioHang.Rows[e.RowIndex].FindControl("txtSoLuong");

                DataTable dt = new DataTable();
                dt = (DataTable)Session["Cart"];
                XulyLayTen_GiaSanPham name_cost = new XulyLayTen_GiaSanPham();
                name_cost.Thongtinsanpham.MaSanPham = int.Parse(str);
                name_cost.Thucthi();
                string name = name_cost.LaytenSP();
                if (dt.Rows.Count != 0)
                {
                    foreach (DataRow dr in dt.Rows)
                    {
                        if (int.Parse(dr[0].ToString()) == int.Parse(str))
                        {
                            dr[3] = int.Parse(soluong.Text);
                            dr[4] = Convert.ToInt32(dr[2]) * Convert.ToInt32(dr[3]);
                        }
                    }
                }
                Session["Cart"] = dt;
                grv_GioHang.EditIndex = -1;
                this.Load_gridview();
                Total();
            }
            catch { multiview1.ActiveViewIndex = 3; }
        }