protected void rptSanPham_ItemCommand(object source, RepeaterCommandEventArgs e) { if (e.CommandName == "ThemGH") { HttpCookie cookie = Request.Cookies["TenTK"]; if (cookie != null) { DTO_GioHang gioHang = new DTO_GioHang(); gioHang.TenTaiKhoan = cookie.Value; gioHang.MaSP = e.CommandArgument.ToString(); gioHang.SoLuong = 1; if (BUS_GioHang.ThemGioHang(gioHang)) { Response.Write("<script>alert('Thêm sản phẩm thành công')</script>"); } else { Response.Write("<script>alert('Thêm sản phẩm thành công')</script>"); } } else { Response.Redirect("Login.aspx"); } } }
public static bool KTGH(DTO_GioHang gioHang) { string query = "SELECT COUNT(*) FROM GioHang WHERE TenTaiKhoan = @TenTaiKhoan AND MaSP = @MaSP"; SqlParameter[] param = new SqlParameter[2]; param[0] = new SqlParameter("@TenTaiKhoan", gioHang.TenTaiKhoan); param[1] = new SqlParameter("@MaSP", gioHang.MaSP); return(Convert.ToInt32(DataProvider.ExecuteSelectQuery(query, param).Rows[0][0]) == 1); }
public static DTO_GioHang ConvertToDTO(DataRow dr) { DTO_GioHang gh = new DTO_GioHang(); gh.MaSP = dr["MaSP"].ToString(); gh.TenTaiKhoan = dr["TenTaiKhoan"].ToString(); gh.SoLuong = Convert.ToInt32(dr["SoLuong"].ToString()); return(gh); }
public static bool SuaGH(DTO_GioHang gioHang) { string query = "UPDATE GioHang SET SoLuong = SoLuong + @SoLuong WHERE TenTaiKhoan = @TenTaiKhoan AND MaSP = @MaSP"; SqlParameter[] param = new SqlParameter[3]; param[0] = new SqlParameter("@TenTaiKhoan", gioHang.TenTaiKhoan); param[1] = new SqlParameter("@MaSP", gioHang.MaSP); param[2] = new SqlParameter("@SoLuong", gioHang.SoLuong); return(DataProvider.ExecuteUpdateQuery(query, param) == 1); }
public static bool ThemGH(DTO_GioHang gioHang) { string query = "INSERT INTO GioHang (TenTaiKhoan, MaSP, SoLuong) VALUES (@TenTaiKhoan, @MaSP, @SoLuong)"; SqlParameter[] param = new SqlParameter[3]; param[0] = new SqlParameter("@TenTaiKhoan", gioHang.TenTaiKhoan); param[1] = new SqlParameter("@MaSP", gioHang.MaSP); param[2] = new SqlParameter("@SoLuong", gioHang.SoLuong); return(DataProvider.ExecuteInsertQuery(query, param) == 1); }
public static bool ThemGioHang(DTO_GioHang gioHang) { if (DAO_GioHang.KTGH(gioHang)) { return(DAO_GioHang.SuaGH(gioHang)); } else { return(DAO_GioHang.ThemGH(gioHang)); } }
protected void rptGiohang_ItemCommand(object source, RepeaterCommandEventArgs e) { DTO_GioHang gh = new DTO_GioHang(); if (e.CommandName == "CapNhatGH") { gh.MaSP = e.CommandArgument.ToString(); gh.TenTaiKhoan = Request.Cookies["TenTK"].Value; gh.SoLuong = Convert.ToInt32((e.Item.FindControl("txtSoLuong") as TextBox).Text); if (BUS_GioHang.ThemGioHang(gh) == true) { Response.Write("<script>alert('Cập nhật thành công')</script>"); Response.Redirect("Cart.aspx"); } } if (e.CommandName == "XoaGH") { string maSP = e.CommandArgument.ToString(); BUS_GioHang.XoaGioHang(maSP); Response.Redirect("Cart.aspx"); } }