Ejemplo n.º 1
0
        public JsonResult XoaSpGioHang(string Id)
        {
            Guid IDGioHang = Guid.Parse(Id);

            bool kq = new GioHangController().XoaSPGioHang(IDGioHang);

            if (kq == true)
            {
                return(Json(true, JsonRequestBehavior.AllowGet));
            }

            return(Json(false, JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 2
0
        public ActionResult SPSach()
        {
            taikhoan tk = (taikhoan)Session[CommonConstants.SESSION_ACCOUNT];

            DonHangValue Dh = new GioHangController().KiemTraTkTrongDonHang(tk.id);

            List <ThongTinGioHang> DanhsachSP = new GioHangController().DanhSachSpTrongGio(Dh.IdDonHang);

            decimal?TongTien = new GioHangController().TongTien(Dh.IdDonHang);

            ViewBag.TongTien = TongTien;

            return(View(DanhsachSP));
        }
Ejemplo n.º 3
0
        public void testTC1_ThemGioHangDong()
        {
            GioHangController gc = new GioHangController();
            List <GioHang>    ds = new List <GioHang>();

            for (int i = 0; i < 5; i++)
            {
                Random  r = new Random();
                int     a = r.Next(1, 10);
                GioHang g = new GioHang("SP" + a);

                gc.ThemGioHang("SP" + a, "http://localhost:12742/");
                ds.Add(g);
            }
            Assert.AreEqual(5, ds.Count);
            Assert.AreEqual(ds.Count, gc.TongSl());
        }
Ejemplo n.º 4
0
        public ActionResult ThayDoiSoL(string SL, string IDGioHang, string GiaTam, string IDDonHang)
        {
            Guid         IDGioHangs = Guid.Parse(IDGioHang);
            Guid         IDDonHangs = Guid.Parse(IDDonHang);
            int          soluong    = int.Parse(SL);
            decimal      giatam     = decimal.Parse(GiaTam);
            GioHangValue Gh         = new GioHangValue()
            {
                IdGioHang = IDGioHangs,
                Soluong   = soluong,
                Tamtinh   = giatam
            };



            bool kq = new GioHangController().UpdateGiohang(Gh);

            decimal?TongGia = new GioHangController().TongTien(IDDonHangs);

            DonHangValue Donh = new DonHangValue()
            {
                IdDonHang = IDDonHangs,
                TongTien  = TongGia
            };


            bool updae = new GioHangController().CapNhatDonHang(Donh);



            if (kq == false)
            {
                return(Json(false, JsonRequestBehavior.AllowGet));
            }


            return(Json(true, JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 5
0
        protected void btn_muahang_Click(object sender, EventArgs e)
        {
            string idgio   = "";
            int    slg     = 0;
            string ngaylap = System.DateTime.Now.Day.ToString() + "/" + System.DateTime.Now.Month.ToString() + "/" + System.DateTime.Now.Year.ToString();

            //int idg = 4;
            gh = new GioHangController();
            DataTable tb;

            if (Session["GioHang"] == null)
            {
                tb    = gh.SetTable();
                idgio = DateTime.Now.Day.ToString() + "" + System.DateTime.Now.Month.ToString() + "" + System.DateTime.Now.Year.ToString() + "" + DateTime.Now.Hour.ToString() + "" + DateTime.Now.Minute.ToString() + "" + DateTime.Now.Second.ToString();
            }
            else

            {
                tb = (DataTable)Session["GioHang"];
                foreach (DataRow gr in tb.Rows)
                {
                    idgio = gr["idgio"].ToString();
                    slg   = int.Parse(gr["SoLuong"].ToString());
                }
            }
            //
            int  idsp = int.Parse(Request.QueryString.Get("idsp"));
            bool kt   = gh.Check_SPTrongGio(idsp, idgio);

            if (kt)
            {
                int      sl   = int.Parse(Session["sl"].ToString());
                Validate va   = new Validate();
                string   sql1 = "SELECT SUM(SoLuong) AS Tong FROM dbo.GioHang WHERE IDSanPham=" + idsp + " AND IDGioHang='" + idgio + "'";
                va.dr = va.getData(sql1);
                if (va.dr.Read())
                {
                    int soLuong = int.Parse(va.dr["Tong"].ToString());
                    if ((sl - soLuong) <= 0)
                    {
                        Lbtb.Text = "<script>alert('Bạn đã thêm sản phẩm tối đa.!')</script>";
                        va.dr.Close();
                    }
                    else
                    {
                        va.dr.Close();
                        string         sql = "SELECT * FROM dbo.tbSANPHAM WHERE IDSanPham='" + Request.QueryString.Get("idsp") + "'";
                        SqlDataAdapter da  = new SqlDataAdapter(sql, SqlDataConnect.connet);
                        DataTable      dt  = new DataTable();
                        da.Fill(dt);
                        foreach (DataRow dr in dt.Rows)
                        {
                            tb = gh.dienVaoBang(tb, dr["HinhAnh1"].ToString(), dr["TenSP"].ToString(), 1, Convert.ToDouble(dr["Gia"]), Convert.ToInt16(dr["IDSanPham"]), Convert.ToInt16(dr["SoLuong"]), idgio.ToString());
                            gh.GioHang_UpDateSl(slg + 1, idsp, idgio);
                            Session["GioHang"] = tb;
                            Response.Redirect("GioHang.aspx");
                        }
                    }
                }
            }
            else
            {
                string         sql = "SELECT * FROM dbo.tbSANPHAM WHERE IDSanPham='" + Request.QueryString.Get("idsp") + "'";
                SqlDataAdapter da  = new SqlDataAdapter(sql, SqlDataConnect.connet);
                DataTable      dt  = new DataTable();
                da.Fill(dt);
                foreach (DataRow dr in dt.Rows)
                {
                    tb = gh.dienVaoBang(tb, dr["HinhAnh1"].ToString(), dr["TenSP"].ToString(), 1, Convert.ToDouble(dr["Gia"]), Convert.ToInt16(dr["IDSanPham"]), Convert.ToInt16(dr["SoLuong"]), idgio.ToString());
                    Session["GioHang"] = tb;
                    GioHangInfo info = new GioHangInfo
                    {
                        IDDonHang   = idgio,
                        IDDienThoai = int.Parse(dr["IDSanPham"].ToString()),
                        SoLuongMua  = 1,
                        Gia         = int.Parse(dr["Gia"].ToString()),
                        NgayLap     = ngaylap
                    };
                    GioHangController giohang = new GioHangController();
                    giohang.GioHang_Insert(info);
                    Response.Redirect("GioHang.aspx");
                }
            }
        }
Ejemplo n.º 6
0
        public JsonResult MuaSach(string ID, string Gia)
        {
            taikhoan tk = (taikhoan)Session[CommonConstants.SESSION_ACCOUNT];

            if (tk == null)
            {
                return(Json(false, JsonRequestBehavior.AllowGet));
            }

            DonHangValue DonHang = new GioHangController().KiemTraTkTrongDonHang(tk.id);

            if (DonHang != null)
            {
                GioHangValue GioHang = new GioHangValue()
                {
                    IdDonHang = DonHang.IdDonHang,
                    IdGioHang = Guid.NewGuid(),
                    IdSach    = Guid.Parse(ID),
                    Soluong   = 1,
                    Tamtinh   = decimal.Parse(Gia)
                };

                bool    ThemGh   = new GioHangController().ThemGioHang(GioHang);
                decimal?tongiten = new GioHangController().TongTien(DonHang.IdDonHang);
                DonHang.TongTien = tongiten;

                new GioHangController().CapNhatDonHang(DonHang);


                if (ThemGh == true)
                {
                    return(Json(true, JsonRequestBehavior.AllowGet));
                }
            }
            else
            {
                DonHangValue DHMoi = new DonHangValue()
                {
                    IdDonHang   = Guid.NewGuid(),
                    IdNguoiMua  = tk.id,
                    NgayDatHang = DateTime.Now.Date,
                    TongTien    = 0
                };

                bool ThemDonHang = new GioHangController().ThemDonHang(DHMoi);
                if (ThemDonHang == true)
                {
                    GioHangValue Ghmoi = new GioHangValue()
                    {
                        IdDonHang = DHMoi.IdDonHang,
                        IdGioHang = Guid.NewGuid(),
                        IdSach    = Guid.Parse(ID),
                        Soluong   = 1,
                        Tamtinh   = Decimal.Parse(Gia)
                    };

                    bool ThemGioHangM = new GioHangController().ThemGioHang(Ghmoi);

                    decimal?tongtien = new GioHangController().TongTien(DHMoi.IdDonHang);
                    DHMoi.TongTien = tongtien;



                    bool CapNhatDonH = new GioHangController().CapNhatDonHang(DHMoi);
                    if (ThemDonHang == true)
                    {
                        return(Json(true, JsonRequestBehavior.DenyGet));
                    }
                }
            }


            return(Json(true, JsonRequestBehavior.DenyGet));
        }
Ejemplo n.º 7
0
 public void TC_CapNhatGioHangDong()
 {
     Random            r = new Random();
     int               a = r.Next(1, 10);
     GioHangController g = new GioHangController();
 }