Exemplo n.º 1
0
        public ActionResult Themvaogio(int?maGiay)
        {
            if (Session["giohang"] == null)
            {
                Session["giohang"] = new List <GioHangs>();
                Session["slgh"]    = "Trống";
            }

            List <GioHangs> giohang = Session["giohang"] as List <GioHangs>;

            if (giohang.FirstOrDefault(t => t.maGiay == maGiay) == null)
            {
                Giay giay = db.Giays.Find(maGiay);
                if (Session["slgh"].ToString() == "Trống")
                {
                    Session["slgh"] = 0;
                }
                Session["slgh"] = Int32.Parse(Session["slgh"].ToString()) + 1;
                GioHangs newItem = new GioHangs()
                {
                    maGiay  = giay.MaGiay,
                    tenGiay = giay.TenGiay,
                    soLuong = 1,
                    hinhAnh = giay.HinhAnhGiay,
                    donGia  = (decimal)giay.GiaTien
                };
                giohang.Add(newItem);
            }
            else
            {
                GioHangs giohg = giohang.FirstOrDefault(t => t.maGiay == maGiay);
                giohg.soLuong++;
            }
            return(Redirect(Request.UrlReferrer.ToString()));
        }
    protected void dl2_ItemCommand(object source, DataListCommandEventArgs e)
    {
        LinkButton lable         = (LinkButton)e.Item.FindControl("TenSPLabel");
        SanPhams   sanpham       = db.SanPhams.SingleOrDefault(p => p.TenSP == lable.Text);
        string     clickdangnhap = Request.QueryString["ClickDangNhap"];

        if (clickdangnhap == null)
        {
            Response.Redirect("~/TrangDangNhap.aspx?MaSanPham=" + sanpham.MaSanPham);
        }
        else
        {
            string   makh    = Request.QueryString["MaKhachHang"];
            GioHangs giohang = db.GioHangs.SingleOrDefault(p => p.MaKhachHang.ToString() == makh && p.MaSanPham == sanpham.MaSanPham);
            if (giohang != null)
            {
                giohang.SoLuong = giohang.SoLuong + 1;
                db.SubmitChanges();
            }
            else
            {
                giohang             = new GioHangs();
                giohang.SoLuong     = 1;
                giohang.MaSanPham   = Convert.ToInt32(sanpham.MaSanPham);
                giohang.MaKhachHang = Convert.ToInt32(makh);
                db.GioHangs.InsertOnSubmit(giohang);
                db.SubmitChanges();
            }
            Response.Redirect("~/GioHang.aspx?MaKhachHang=" + makh);
        }
    }
 public List <GioHangs> DeleteGioHang(User admin, GioHangs gh)
 {
     if (admin.chucNang == "admin")
     {
         model.GioHangs.Remove(GetGioHang(gh.username));
         model.SaveChanges();
     }
     return(GetListGioHang());
 }
 public List <GioHangs> AddGioHang(User admin, GioHangs lk)
 {
     if (admin.chucNang == "admin")
     {
         model.GioHangs.Add(GetGioHang(lk.username));
         model.SaveChanges();
     }
     return(GetListGioHang());
 }
 public List <GioHangs> EditGioHang(User admin, GioHangs gh)
 {
     if (admin.chucNang == "admin")
     {
         //var gioiHang = GetGioHang(gh.maGioHang);
         //gioiHang.thongtin = gh.thongtin;
         //model.SaveChanges();
     }
     return(GetListGioHang());
 }
Exemplo n.º 6
0
    protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
    {
        string   MaKhachHang1 = Request.QueryString["MaKhachHang"];
        int      MaKhachHang  = Convert.ToInt32(MaKhachHang1);
        GioHangs giohang      = db.GioHangs.SingleOrDefault(p => p.MaSanPham.ToString() == GridView1.Rows[GridView1.SelectedIndex].Cells[0].Text && p.MaKhachHang == MaKhachHang);

        if (giohang != null)
        {
            db.GioHangs.DeleteOnSubmit(giohang);
            db.SubmitChanges();
            load();
        }
    }
Exemplo n.º 7
0
    protected void bntDangNhap_Click(object sender, EventArgs e)
    {
        var dskhachanh = from p in db.KhachHangs select p;

        foreach (KhachHang khachhang in dskhachanh)
        {
            if (khachhang.TenDangNhap == txtUser.Text && khachhang.MatKhau == txtPass.Text)
            {
                string masp = Request.QueryString["MaSanPham"];
                if (masp != null)
                {
                    GioHangs giohang = db.GioHangs.SingleOrDefault(p => p.MaKhachHang == khachhang.MaKhachHang && p.MaSanPham.ToString() == masp);
                    if (giohang != null)
                    {
                        giohang.SoLuong = giohang.SoLuong + 1;
                        db.SubmitChanges();
                    }
                    else
                    {
                        giohang             = new GioHangs();
                        giohang.SoLuong     = 1;
                        giohang.MaSanPham   = Convert.ToInt32(masp);
                        giohang.MaKhachHang = khachhang.MaKhachHang;
                        db.GioHangs.InsertOnSubmit(giohang);
                        db.SubmitChanges();
                    }
                }
                string clickdangnhap = Request.QueryString["ClickDangNhap"];
                if (clickdangnhap == null)
                {
                    Response.Redirect("~/GioHang.aspx?MaKhachHang=" + khachhang.MaKhachHang);
                }
                else
                {
                    Response.Redirect("~/Default3.aspx?ClickDangNhap=true+&MaKhachHang=" + khachhang.MaKhachHang);
                }
            }

            else
            {
                CustomValidator1.ErrorMessage = "Tên đăng nhập hoặc mật khẩu không đúng";
                CustomValidator1.IsValid      = false;
            }
        }
    }