Exemplo n.º 1
0
 public ChiTietDonHangDTO(ChiTietDonHang ct)
 {
     SOLUONGMUA = ct.SOLUONGMUA;
     TRANGTHAIGIAOHANG = ct.TRANGTHAIGIAOHANG;
     TRANGTHAISUDUNG = ct.TRANGTHAISUDUNG;
     LANGIAOHANGTHU = ct.LANGIAOHANGTHU;
     NGAYGIAOHANG = ct.NGAYGIAOHANG;
     MADH = ct.MADH;
     VOUCHERDH = ct.VOUCHERDH;
 }
        public ActionResult Create([Bind(Include = "SoHieuDonHang,MaDonHang,MaSanPham,SoLuongSanPham,GiaSanPham,GhiChu")] ChiTietDonHang chiTietDonHang)
        {
            if (ModelState.IsValid)
            {
                db.ChiTietDonHangs.Add(chiTietDonHang);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.MaDonHang = new SelectList(db.DonHangs, "MaDonHang", "MaNhanVien", chiTietDonHang.MaDonHang);
            ViewBag.MaSanPham = new SelectList(db.SanPhams, "MaSanPham", "MaDMSP", chiTietDonHang.MaSanPham);
            return(View(chiTietDonHang));
        }
Exemplo n.º 3
0
        public ActionResult Create([Bind(Include = "MaDonHang,MaSP,SoLuong")] ChiTietDonHang chiTietDonHang)
        {
            if (ModelState.IsValid)
            {
                db.ChiTietDonHangs.Add(chiTietDonHang);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.MaDonHang = new SelectList(db.DonHangs, "MaDonHang", "Email", chiTietDonHang.MaDonHang);
            ViewBag.MaSP      = new SelectList(db.SanPhams, "MaSP", "TenSP", chiTietDonHang.MaSP);
            return(View(chiTietDonHang));
        }
 public bool Insert(ChiTietDonHang orderDetail)
 {
     try
     {
         db.ChiTietDonHangs.Add(orderDetail);
         db.SaveChanges();
         return(true);
     }
     catch
     {
         return(false);
     }
 }
Exemplo n.º 5
0
 public bool Insert(ChiTietDonHang cthd)
 {
     try
     {
         db.ChiTietDonHangs.Add(cthd);
         db.SaveChanges();
         return(true);
     }
     catch
     {
         return(false);
     }
 }
        public ActionResult XacNhanXoa(int madonhang, string maSP)
        {
            ChiTietDonHang ct = db.ChiTietDonHang.Find(madonhang, maSP);

            if (ct == null)
            {
                Response.StatusCode = 404;
                return(null);
            }
            db.ChiTietDonHang.Remove(ct);
            db.SaveChanges();
            return(RedirectToAction("Index", "QuanLyChiTietDonHang", new { @madonhang = madonhang }));
        }
Exemplo n.º 7
0
 public ActionResult Edit([Bind(Include = "MaCTDH,MaDH,MaSP,SoLuong")] ChiTietDonHang chiTietDonHang)
 {
     ValidateProduct(chiTietDonHang);
     if (ModelState.IsValid)
     {
         db.Entry(chiTietDonHang).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.MaDH  = new SelectList(db.DonHangs, "MaDH", "Email", chiTietDonHang.MaDH);
     ViewBag.TenSP = new SelectList(db.SanPhams, "MaSP", "TenSP", chiTietDonHang.SanPham.TenSP);
     return(View(chiTietDonHang));
 }
Exemplo n.º 8
0
        //Hiển thị sản phẩm
        public ActionResult HienThi(int MaDonHang)
        {
            //Lấy ra đối tượng sách theo mã
            ChiTietDonHang chitietdonhang = db.ChiTietDonHangs.SingleOrDefault(n => n.MaDonHang == MaDonHang);

            if (chitietdonhang == null)
            {
                Response.StatusCode = 404;
                return(null);
            }

            return(View(chitietdonhang));
        }
Exemplo n.º 9
0
        public ActionResult Edit([Bind(Include = "MaDH,MaSP,SoLuong,DonGia")] ChiTietDonHang chiTietDonHang)
        {
            if (ModelState.IsValid)
            {
                db.Entry(chiTietDonHang).State = EntityState.Modified;
                db.SaveChanges();
                Url.Action("TongTienDH", "DonHang", new { maDH = chiTietDonHang.MaDH });
                return(RedirectToAction("Details", "DonHang", new { id = chiTietDonHang.MaDH }));
            }
            ViewBag.MaDH = new SelectList(db.DonHang, "MaDH", "LuuY", chiTietDonHang.MaDH);
            ViewBag.MaSP = new SelectList(db.SanPham, "MaSP", "TenSP", chiTietDonHang.MaSP);

            return(View(chiTietDonHang));
        }
Exemplo n.º 10
0
        public IEnumerable <ChiTietDonHang> Get(ChiTietDonHang chitiet)
        {
            List <ChiTietDonHang> chitietdonhang = new List <ChiTietDonHang>();
            List <ChiTietDonHang> dbchitiet      = dbContext.ChiTietDonHangs.ToList();

            foreach (ChiTietDonHang item in dbchitiet)
            {
                if (item.ID_DonHang == chitiet.ID_DonHang)
                {
                    chitietdonhang.Add(item);
                }
            }
            return(chitietdonhang);
        }
Exemplo n.º 11
0
        public ActionResult XacNhanXoa(int MaDonHang)
        {
            DonHang        donhang        = db.DonHangs.SingleOrDefault(n => n.MaDonHang == MaDonHang);
            ChiTietDonHang chitietdonhang = db.ChiTietDonHangs.SingleOrDefault(n => n.MaDonHang == MaDonHang);

            if (donhang == null || chitietdonhang != null)
            {
                Response.StatusCode = 404;
                return(null);
            }
            db.DonHangs.Remove(donhang);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Exemplo n.º 12
0
        // GET: Admin/CTDH/Details/5
        public ActionResult Details(int?idDH, int?idSP)
        {
            if (idDH == null || idSP == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            ChiTietDonHang chiTietDonHang = db.ChiTietDonHang.Where(x => x.MaDH == idDH && x.MaSP == idSP).SingleOrDefault();

            if (chiTietDonHang == null)
            {
                return(HttpNotFound());
            }
            return(View(chiTietDonHang));
        }
 public bool Insert(ChiTietDonHang chitiet)
 {
     try
     {
         db.ChiTietDonHangs.Add(chitiet);
         db.SaveChanges();
         return(true);
     }
     catch (Exception ex)
     {
         Console.WriteLine("Error here" + ex.Message);
         return(false);
     }
 }
Exemplo n.º 14
0
        public ActionResult XacNhanXoa(int MaDonHang, int MaSach)
        {
            ChiTietDonHang ctdh = db.ChiTietDonHangs.Where(n => n.MaDH == MaDonHang && n.MaSach == MaSach).FirstOrDefault();
            DonHang        dh   = db.DonHangs.FirstOrDefault(n => n.MaDH == MaDonHang);

            if (ctdh == null && dh == null)
            {
                Response.StatusCode = 404;
                return(null);
            }
            db.ChiTietDonHangs.Remove(ctdh);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Exemplo n.º 15
0
        public IHttpActionResult DeleteChiTietDonHang(int id)
        {
            ChiTietDonHang chiTietDonHang = db.ChiTietDonHangs.Find(id);

            if (chiTietDonHang == null)
            {
                return(NotFound());
            }

            db.ChiTietDonHangs.Remove(chiTietDonHang);
            db.SaveChanges();

            return(Ok(chiTietDonHang));
        }
Exemplo n.º 16
0
        // GET: ChiTietDonHang/Details/5
        public ActionResult Details(string id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            ChiTietDonHang chiTietDonHang = db.ChiTietDonHangs.Find(id);

            if (chiTietDonHang == null)
            {
                return(HttpNotFound());
            }
            return(View(chiTietDonHang));
        }
        public ActionResult DatHang(NguoiDung ng)
        {
            var gioHang = Session["GioHang"] as Cart;

            if (gioHang == null || gioHang.TongSanPham == 0)
            {
                return(RedirectToAction("Index", "Home"));
            }
            int soHDTonTai   = db.DonHangs.Count();
            int soCTDHTonTai = db.ChiTietDonHangs.Count();
            int soNgDung     = db.NguoiDungs.Count();

            try
            {
                ng.IdNguoiDung     = soNgDung++;
                ng.IdKieuNguoiDung = 1;
                ng.TenDangNhap     = "nguoiDung";
                ng.MatKhau         = "matkhau";
                db.NguoiDungs.Add(ng);
                DonHang dh = new DonHang();
                dh.IdDonHang          = soHDTonTai + 1;
                dh.IdNguoiDung        = ng.IdNguoiDung;
                dh.IdTinhTrangDonHang = 1;
                dh.NgayTaoDonHang     = DateTime.Now;
                dh.NgayXuLyDonHang    = DateTime.Now;
                dh.TrackingNumber     = (soHDTonTai + 1).ToString();
                dh.IdGiaoDich         = dh.TrackingNumber;
                db.DonHangs.Add(dh);

                for (int i = 0; i < gioHang.getLsCart.Count; i++)
                {
                    ChiTietDonHang ct = new ChiTietDonHang();
                    ct.IdChiTietDonHang = soCTDHTonTai + i;
                    ct.IdSanPham        = gioHang.getLsCart[i].sanPham.IdSanPham;
                    ct.IdDonHang        = dh.IdDonHang;
                    ct.SoLuongSanPham   = gioHang.getLsCart[i].soLuong;
                    db.ChiTietDonHangs.Add(ct);
                }

                db.SaveChanges();
                gioHang.clear();
                return(RedirectToAction("Index", "Home"));
            }
            catch (Exception ex)
            {
                string a = "Error" + ex;
                return(RedirectToAction("Index"));
            }
        }
Exemplo n.º 18
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (textBoxCustomerID.Text == "" || textBoxCustomerID.Text == null)
            {
                MessageBox.Show("Hãy nhập thông tin khách hàng !");
            }
            else
            {
                GioHangDao dao = new GioHangDao();
                // thêm id khách hàng vào trong bảng GioHang
                dao.addIdCustomerToAllRecord(int.Parse(textBoxCustomerID.Text));

                // Tạo Record trong bảng DonHang
                DonHang d = new DonHang();
                d.MaKH     = int.Parse(dao.getIdCustomer());
                d.TongTien = dao.netAmount();
                DonHangDao donhangDao = new DonHangDao();
                var        idDonHang  = donhangDao.insertDonHang(d);

                // Tạo Record trong bảng ChiTietDonHang
                foreach (var item in dao.listGioHang())
                {
                    var     tensach = item.BookTitle;
                    var     soluong = item.Qty;
                    var     dongia  = item.Price;
                    SachDao sachDao = new SachDao();
                    // Tạo 1 ChiTietDonHang và thêm các thuộc tính vào
                    ChiTietDonHang ctdh = new ChiTietDonHang();
                    ctdh.MaDH    = int.Parse(idDonHang);
                    ctdh.MaSach  = sachDao.getIdBookByName(tensach);
                    ctdh.SoLuong = soluong;
                    ctdh.DonGia  = dongia;

                    // Insert record vào ChiTietDonHang
                    ChiTietDonHangDao ctdhDao = new ChiTietDonHangDao();
                    ctdhDao.insertChiTietDonHang(ctdh);

                    // Update lại số lượng tồn của Sach
                    sachDao.updateStock(ctdh.MaSach, (int)ctdh.SoLuong);
                }
                // Clear all
                clearAll();


                // Xóa hết bảng GioHang
                dao.deleteAllCartRecord();
                MessageBox.Show("Thành công !");
            }
        }
Exemplo n.º 19
0
        // GET: ChiTietDonHang/Edit/5
        public ActionResult Edit(string id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            ChiTietDonHang chiTietDonHang = db.ChiTietDonHangs.Find(id);

            if (chiTietDonHang == null)
            {
                return(HttpNotFound());
            }
            ViewBag.Ma_PDH = new SelectList(db.PhieuDonHangs, "Ma_PDH", "MaHoaDon", chiTietDonHang.Ma_PDH);
            return(View(chiTietDonHang));
        }
Exemplo n.º 20
0
 private void Luuchitietdonhang(Giohang giohang, MainContext db, int maDH)
 {
     foreach (var temp in giohang.getGiohang())
     {
         var chiTiet = new ChiTietDonHang()
         {
             DonHangId = maDH,
             SanPhamId = temp.sanPham.Id,
             SoLuong   = temp.Soluong,
             ThanhTien = (decimal)temp.Thanhtien
         };
         db.ChiTietDonHangs.Add(chiTiet);
     }
     db.SaveChanges();
 }
Exemplo n.º 21
0
 private void luuChiTietDonHang(int maDH)
 {
     foreach (var item in (List <Cart>)Session["Cart"])
     {
         ChiTietDonHang chiTietDon = new ChiTietDonHang()
         {
             MaSP      = item.SanPham.MaSP,
             MaDonHang = maDH,
             SoLuong   = item.Quantity,
             TongTien  = item.Quantity * item.SanPham.GiaSP
         };
         db.ChiTietDonHangs.Add(chiTietDon);
         db.SaveChanges();
     }
 }
Exemplo n.º 22
0
        public ActionResult Create(string TenNguoiNhan, string SDTNguoiNhan, string Email, string DiaChiNhan, string GhiChu)
        {
            var     dao        = new DonHangDao();
            var     productDao = new ProductDao();
            var     chitietDao = new ChiTietDonHangDao();
            DonHang don        = new DonHang();

            var user = (UserLogin)Session[Common.CommonConstants.USER_SESSION];

            don.IdUser       = user.UserID;
            don.NgayDat      = DateTime.Now;
            don.TrangThai    = 0;
            don.TenNguoiNhan = TenNguoiNhan;
            don.SDTNguoiNhan = SDTNguoiNhan;
            don.Email        = Email;
            don.DiaChiNhan   = DiaChiNhan;
            don.GhiChu       = GhiChu;
            don.TongTien     = 0;
            var list = (List <CartItem>)Session[Common.CommonConstants.CartSession];


            var maDonHang = dao.insert(don);

            if (maDonHang >= 0)
            {
                long tongtien = 0;
                foreach (var item in list)
                {
                    ChiTietDonHang entity = new ChiTietDonHang();
                    entity.MaDonHang = maDonHang;
                    entity.MaSach    = item.SanPham.MaSach;
                    entity.SoLuong   = item.SoLuong;
                    entity.DonGia    = (int)item.SanPham.DonGia;
                    entity.ThanhTien = entity.SoLuong * entity.DonGia;
                    chitietDao.insert(entity);
                    productDao.UpdateSoLuong(item.SoLuong, entity.MaSach);
                    tongtien += (long)entity.ThanhTien;
                }
                dao.UpdateTongTien(tongtien, maDonHang);
                Session[Common.CommonConstants.CartSession] = null;

                string        s        = "Bạn đã đặt hàng thành công. Vui lòng xem chi tiết trong tài khoản cá nhân ";
                List <string> overList = new List <string>();
                overList.Add(s);
                Session[Common.CommonConstants.OverSoLuong] = overList;
            }
            return(RedirectToAction("Index", "Cart"));
        }
Exemplo n.º 23
0
        public ActionResult DatHang(FormCollection f)
        {
            string ten = "";
            int    gia = 0;
            int    sl  = 0;

            DonDatHang     ddh = new DonDatHang();
            KhachHang      kh  = (KhachHang)Session["Taikhoan"];
            List <GioHang> gh  = layGioHang();

            ddh.MaKH    = kh.MaKH;
            ddh.NgayDat = DateTime.Now;
            var ngaygiao = String.Format("{0:MM/dd/yyyy}", f["NgayGiao"].ToString());

            ddh.NgayGiao          = DateTime.Parse(ngaygiao);
            ddh.TinhTrangGiaoHang = false;
            ddh.DaThanhToan       = false;
            db.DonDatHangs.InsertOnSubmit(ddh);
            db.SubmitChanges();

            foreach (var item in gh)
            {
                ChiTietDonHang ctdh = new ChiTietDonHang();
                ctdh.MaDonHang = ddh.MaDonHang;
                ctdh.MaHang    = item.maHang;
                ctdh.Soluong   = item.soLuong;
                ctdh.DonGia    = (decimal)item.donGia;
                db.ChiTietDonHangs.InsertOnSubmit(ctdh);

                foreach (MatHang g in db.MatHangs.ToList())
                {
                    if (g.MaHang == ctdh.MaHang)
                    {
                        ten += g.TenHang + ",";
                    }
                }
            }
            db.SubmitChanges();
            foreach (ChiTietDonHang a in db.ChiTietDonHangs.Where(n => n.MaDonHang == ddh.MaDonHang).ToList())
            {
                sl  += (int)a.Soluong;
                gia += (int)(a.DonGia * a.Soluong);
            }
            string url = "https://www.baokim.vn/payment/product/[email protected]&id=&order_description=ABC" + "&product_name=" + ten.Substring(0, (ten.Length - 1)) + "&product_price=" + gia + "&product_quantity=" + sl + "&total_amount=" + gia + "&url_cancel=&url_detail=&url_success=" + Url.Action("XacNhanDonHang", "GioHang", new { idDH = ddh.MaDonHang, kt = 1 });

            Session["GioHang"] = null;
            return(Redirect(url));
        }
        public bool Update(ChiTietDonHang entity)
        {
            try
            {
                var bill = db.ChiTietDonHangs.Find(entity.MaDH);
                bill.SoLuong = entity.SoLuong;
                bill.DonGia  = entity.DonGia;

                db.SaveChanges();
                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
Exemplo n.º 25
0
        // GET: ChiTietDonHangs/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            ChiTietDonHang chiTietDonHang = db.ChiTietDonHang.Find(id);

            if (chiTietDonHang == null)
            {
                return(HttpNotFound());
            }
            ViewBag.SerialNumber = new SelectList(db.SanPham, "SerialNumber", "MaLoaiSP", chiTietDonHang.SerialNumber);
            ViewBag.MaDonHang    = new SelectList(db.DonHang, "MaDonHang", "MaDonHang", chiTietDonHang.MaDonHang);
            return(View(chiTietDonHang));
        }
        public ActionResult LuuDiemDanhGia(int id, int diem)
        {
            ChiTietDonHang chiTietDonHang = db.ChiTietDonHangs.Find(id);
            Album          album          = db.Albums.Find(chiTietDonHang.AlbumID);
            DiemDanhGia    diemDanhGia    = new DiemDanhGia();

            diemDanhGia.Diem             = diem;
            diemDanhGia.ChiTietDonHangID = id;
            Decimal diemTB = Convert.ToDecimal((album.DiemDanhGia + diem) / 2);

            album.DiemDanhGia     = diemTB;
            db.Entry(album).State = EntityState.Modified;
            db.DiemDanhGias.Add(diemDanhGia);
            db.SaveChanges();
            return(RedirectToAction("ThongTinDonHang", new { id = chiTietDonHang.DonHangID }));
        }
Exemplo n.º 27
0
        // GET: Admin/CTDH/Edit/5
        public ActionResult Edit(int?idDH, int?idSP)
        {
            if (idDH == null || idSP == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            ChiTietDonHang chiTietDonHang = db.ChiTietDonHang.Where(x => x.MaDH == idDH && x.MaSP == idSP).SingleOrDefault();

            if (chiTietDonHang == null)
            {
                return(HttpNotFound());
            }
            ViewBag.MaDH = new SelectList(db.DonHang, "MaDH", "LuuY", chiTietDonHang.MaDH);
            ViewBag.MaSP = new SelectList(db.SanPham, "MaSP", "TenSP", chiTietDonHang.MaSP);
            return(View(chiTietDonHang));
        }
Exemplo n.º 28
0
        // GET: Admin/ChiTietDonHangs/Edit/5
        public ActionResult Edit(string id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            ChiTietDonHang chiTietDonHang = db.ChiTietDonHangs.Find(id);

            if (chiTietDonHang == null)
            {
                return(HttpNotFound());
            }
            ViewBag.MaDonHang = new SelectList(db.DonHangs, "MaDonHang", "Email", chiTietDonHang.MaDonHang);
            ViewBag.MaSP      = new SelectList(db.SanPhams, "MaSP", "TenSP", chiTietDonHang.MaSP);
            return(View(chiTietDonHang));
        }
        public ActionResult ChinhSua(int?madonhang, string maSP)
        {
            if (madonhang == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            ChiTietDonHang ct = db.ChiTietDonHang.Find(madonhang, maSP);

            if (ct == null)
            {
                Response.StatusCode = 404;
                return(null);
            }
            ViewBag.maSP = new SelectList(db.SanPham.ToList().OrderBy(n => n.tenSP), "maSP", "tenSP");
            return(View(ct));
        }
Exemplo n.º 30
0
        public ActionResult DatHangTaiCuaHang()
        {
            //Kiểm tra đăng nhập
            if ((Session["TaiKhoan"] == null) || (Session["TaiKhoan"].ToString() == ""))
            {
                return(RedirectToAction("DangNhap", "NguoiDung"));
            }
            //Kiểm tra giỏ hàng
            if (Session["GioHang"] == null)
            {
                RedirectToAction("Index", "Home");
            }
            //thêm đơn hàng
            DonHang        dh = new DonHang();
            KhachHang      kh = (KhachHang)Session["TaiKhoan"];
            List <GioHang> gh = LayGioHang();

            dh.MaKH              = kh.MaKH;
            dh.HoTen             = kh.HoTen;
            dh.TaiKhoan          = kh.TaiKhoan;
            dh.DaThanhToan       = Convert.ToInt32(TongTien());
            dh.TinhTrangGiaoHang = 0;
            dh.DuyetDonHang      = 0;
            dh.NgayDat           = DateTime.Now;
            dh.NgayGiao          = DateTime.Now;
            db.DonHangs.Add(dh);
            db.SaveChanges();
            //Thêm chi tiết đơn hàng
            foreach (var item in gh)
            {
                ChiTietDonHang ctdh = new ChiTietDonHang();
                ctdh.MaDonHang   = dh.MaDonHang;
                ctdh.MaDienThoai = item._MaDienThoai;
                ctdh.SoLuong     = item._SoLuong;
                ctdh.DonGia      = item._DonGia.ToString();


                DienThoai dienthoai = db.DienThoais.SingleOrDefault(n => n.MaDienThoai == item._MaDienThoai);
                dienthoai.SoLuongTon -= item._SoLuong;
                db.ChiTietDonHangs.Add(ctdh);
                db.SaveChanges();
                Session["GioHang"] = null;
            }
            db.SaveChanges();
            Session["GioHang"] = null;
            return(RedirectToAction("Camonquykhach", "GioHang"));
        }
Exemplo n.º 31
0
        public ActionResult AddOrEditCTDH(ChiTietDonHang ct)
        {
            using (DBNoiThat db = new DBNoiThat())
            {
                if (ct.IDCT == 0)
                {
                    if (db.ChiTietDonHangs.Where(p => p.IDSanPham == ct.IDSanPham && p.IDDonHang == ct.IDDonHang).FirstOrDefault() != null)
                    {
                        return(Json(new { success = false, message = "Sản phẩm đã tồn tại trong đơn hàng!" }, JsonRequestBehavior.AllowGet));
                    }

                    ct.DonGia = db.SanPhams.Where(p => p.ID == ct.IDSanPham).FirstOrDefault().Gia;

                    ct.ThanhTien = ct.SoLuong * ct.DonGia;
                    db.ChiTietDonHangs.Add(ct);

                    DonHang dh = db.DonHangs.Where(p => p.ID == ct.IDDonHang).FirstOrDefault();
                    dh.TongTien = dh.TongTien + ct.ThanhTien - dh.DaGiamGia;

                    db.SaveChanges();
                    return(Json(new { success = true, message = "Thêm mới thành công!" }, JsonRequestBehavior.AllowGet));
                }
                else
                {
                    try
                    {
                        ChiTietDonHang ct2 = db.ChiTietDonHangs.Where(p => p.IDCT == ct.IDCT).FirstOrDefault();
                        DonHang        dh  = db.DonHangs.Where(p => p.ID == ct.IDDonHang).FirstOrDefault();

                        dh.TongTien = dh.TongTien - ct2.ThanhTien;

                        ct2.IDSanPham = ct.IDSanPham;
                        ct2.SoLuong   = ct.SoLuong;
                        ct2.ThanhTien = ct2.SoLuong * ct2.DonGia;

                        dh.TongTien = dh.TongTien + ct2.ThanhTien - dh.DaGiamGia;

                        db.SaveChanges();
                        return(Json(new { success = true, message = "Cập nhật thành công!" }, JsonRequestBehavior.AllowGet));
                    }
                    catch
                    {
                        return(Json(new { success = false, message = "Cập nhật thất bại!" }, JsonRequestBehavior.AllowGet));
                    }
                }
            }
        }
Exemplo n.º 32
0
        public static int ThemChiTietDonHang(ChiTietDonHang ct)
        {
            string query = String.Format("INSERT INTO ChiTietDonHang(MaDH, MaSP, SoLuong, DonGia, ThanhTien) VALUES (" + ct.MaDH + ", '" + ct.MaSP + "', " + ct.SoLuong + ", " + ct.DonGia + ", " + ct.ThanhTien + ")");

            try
            {
                conn.Open();
                command.CommandText = query;
                return command.ExecuteNonQuery();

            }
            catch (Exception ex)
            {

            }
            finally
            {
                conn.Close();
            }
            return 0;
        }
Exemplo n.º 33
0
    private void AddDonHangToDB(DataRowView dr, int dhid, int chid, string tench)
    {
        ChiTietDonHang ctdh = new ChiTietDonHang();

        ctdh.InsertFields(dhid, int.Parse(dr["SanPhamID"].ToString()), dr["TenSanPham"].ToString(),
                          decimal.Parse(dr["GiaSanPham"].ToString()),
                          int.Parse(dr["SoSanPham"].ToString()), decimal.Parse(dr["TongTien"].ToString()), chid, tench);
    }