//Lưu đơn đặt hàng (Lấy từ Session[kh]) public ActionResult LuuDDH() { List <GioHang> lstGiohang = Laygiohang(); DONHANG dh = new DONHANG(); KHACHHANG kh = (KHACHHANG)Session["kh"]; dh.MADH = Capma_tudong("DH"); dh.NGAYLAP = DateTime.Now; dh.TONGTIEN = (int)TongTien(); dh.TINHTRANG = false; dh.MAKH = kh.MAKH; data.DONHANGs.InsertOnSubmit(dh); data.SubmitChanges(); foreach (var item in lstGiohang) { CTDH ct = new CTDH(); ct.MADH = Capma_tudong("DH"); ct.MASP = item.masp; ct.SOLUONG = item.soluong; data.CTDHs.InsertOnSubmit(ct); data.SubmitChanges(); } Update_ma("DH"); Session["GioHang"] = null; return(RedirectToAction("DatThanhCong", "_Home")); }
public ActionResult Dathang(FormCollection collection) { DonHang dh = new DonHang(); KhachHang kh = (KhachHang)Session["KH"]; List <Giohang> gh = Laygiohang(); CTDH ctdh = new CTDH(); //dh.MaKH = kh.MaKH; dh.MaKH = kh.MaKH; dh.NgayDat = DateTime.Now; dh.TinhTrangGiaoHang = false; data.DonHangs.InsertOnSubmit(dh); data.SubmitChanges(); foreach (var item in gh) { ctdh.MaDH = dh.MaDH; ctdh.MaSP = item.iMaSP; ctdh.SoLuong = item.iSoluong; ctdh.Dongia = (decimal)item.dDongia; data.CTDHs.InsertOnSubmit(ctdh); } data.SubmitChanges(); Session["Giohang"] = null; return(RedirectToAction("Xacnhandonhang", "Giohang")); }
public ActionResult DatHang(FormCollection collection) { DATHANG dh = new DATHANG(); KHACHHANG kh = (KHACHHANG)Session["Taikhoan"]; List <Giohang> gh = Laygiohang(); try { dh.NGAYLAP = DateTime.Now; dh.MAKH = kh.MAKH; dblayer.add_dh(dh); foreach (var item in gh) { CTDH ctdh = new CTDH(); ctdh.MADH = "1"; ctdh.MAHANGHOA = item.iMAHANGHOA; ctdh.SOLUONG = item.iSOLUONG; ctdh.DONGIA = (decimal)item.dDONGIABAN; ctdh.THANHTIEN = (decimal)item.dTHANHTIEN; dblayer.add_ctdh(ctdh); } } catch (Exception ex) { @ViewBag.Error = ex.Message; return(this.DatHang()); } Session["Giohang"] = null; return(RedirectToAction("Xacnhandonhang", "Giohang")); }
public ActionResult DatHang() { if (Session["TaiKhoan"] == null || Session["TaiKhoan"] == "") { return(RedirectToAction("DangNhap", "NguoiDung")); } if (Session["GioHang"] == null) { RedirectToAction("Index", "Home"); } DonHang dh = new DonHang(); KhachHang kh = (KhachHang)Session["TaiKhoan"]; List <GioHang> lstGioHang = LayGioHang(); dh.MaKH = kh.MaKH; dh.NgayDat = DateTime.Now; db.DonHangs.Add(dh); db.SaveChanges(); foreach (var item in lstGioHang) { CTDH ctDonHang = new CTDH(); ctDonHang.MaDonHang = dh.MaDonHang; ctDonHang.MaSach = item.iMaSach; ctDonHang.SoLuong = item.iSoLuong; ctDonHang.DonGia = (decimal)item.dDonGia; db.CTDHs.Add(ctDonHang); } db.SaveChanges(); return(RedirectToAction("Index", "Home")); }
public ActionResult DeleteConfirmed(string id) { CTDH cTDH = db.CTDHs.Find(id); db.CTDHs.Remove(cTDH); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult DatHang(KhachHang kh) { if (Session["GioHang"] == null) { return(RedirectToAction("Index", "Home")); } KhachHang Khach = new KhachHang(); if (Session["TaiKhoan"] == null) { //khach chua dang ky Khach = kh; dt.KhachHang.Add(Khach); dt.SaveChanges(); } else { // khach da dang ky la thanh vien ThanhVien tv = Session["TaiKhoan"] as ThanhVien; Khach.HoTenKH = tv.HoTen; Khach.SdtKH = tv.Sdt; Khach.EmailKH = tv.Email; Khach.DiaChiKH = tv.DiaChi; Khach.MaTV = tv.MaTV; dt.KhachHang.Add(Khach); dt.SaveChanges(); } //Them Don Hang DonDatHang ddh = new DonDatHang(); ddh.MaKH = Khach.MaKH; ddh.NgayDat = DateTime.Now; ddh.NgayGiao = DateTime.Now.AddDays(1); ddh.TinhTrangGiaoHang = false; ddh.UuDai = 0; ddh.Dagiao = false; ddh.DaThanhToan = false; dt.DonDatHang.Add(ddh); dt.SaveChanges(); //chi tiet List <ItemGioHang> lstGioHang = LayGioHang(); foreach (var item in lstGioHang) { CTDH ctdh = new CTDH(); ctdh.MaDDH = ddh.MaDDH; ctdh.MaSP = item.MaSP; ctdh.TenSP = item.TenSP; ctdh.Soluong = item.SoLuong; ctdh.Dongia = item.DonGia; dt.CTDH.Add(ctdh); } dt.SaveChanges(); Session["GioHang"] = null; return(RedirectToAction("XemGioHang")); }
public void luudonhang(DONHANG dh, List <CTDH> ctdh) { DONHANG donhang = new DONHANG { MACUSTOMER = dh.MACUSTOMER, NGAYMUA = dh.NGAYMUA, DIACHI = dh.DIACHI, SDT = dh.SDT, TONGTIEN = dh.TONGTIEN, GHICHU = dh.GHICHU }; db.DONHANGs.Add(donhang); db.SaveChanges(); int iddonhang = donhang.MADH; List <CTDH> listct = new List <CTDH>(); listct = ctdh; var listrating = new List <RATING>(); foreach (var item in listct) { CTDH ct = new CTDH(); ct.MADH = iddonhang; ct.MASP = item.MASP; ct.MAMERCHANT = item.MAMERCHANT; ct.SOLUONG = item.SOLUONG; ct.THANHTIEN = item.THANHTIEN; ct.TINHTRANG = item.TINHTRANG; ct.MAKICHCO = item.MAKICHCO; ct.GIAGIAM = item.GIAGIAM; db.CTDHs.Add(ct); db.SaveChanges(); if (listrating.Exists(x => x.MADH == item.MADH) && listrating.Exists(x => x.MASP == item.MASP)) { } else { listrating.Add(new RATING() { MADH = item.MADH, MASP = item.MASP }); RATING rating = new RATING(); rating.MADH = iddonhang; rating.MASP = item.MASP; rating.MAMERCHANT = item.MAMERCHANT; rating.MACUSTOMER = dh.MACUSTOMER; rating.RATING_M = null; rating.RATING_C = null; rating.NGAYRATING = null; rating.TRANGTHAI = 0; RATINGDAL ratingdal = new RATINGDAL(); ratingdal.addrating(rating); db.SaveChanges(); } } }
public static void them(CTDH dh) { var x = db.DONDATHANGs.AsNoTracking().OrderByDescending(s => s.ID).FirstOrDefault(); dh.ID = x.ID; dh.SANPHAM = null; db.CTDHs.Add(dh); db.SaveChanges(); }
public ActionResult Edit([Bind(Include = "SODH,MASP,SL,THANHTIEN")] CTDH cTDH) { if (ModelState.IsValid) { db.Entry(cTDH).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.MASP = new SelectList(db.SANPHAMs, "MASP", "TENSP", cTDH.MASP); ViewBag.SODH = new SelectList(db.DONHANGs, "SODH", "USER_ID", cTDH.SODH); return(View(cTDH)); }
public void add_ctdh(CTDH ctdh) { SqlCommand com = new SqlCommand("sp_ThemCTDH", con); com.CommandType = CommandType.StoredProcedure; com.Parameters.AddWithValue("@MADH", ctdh.MADH); com.Parameters.AddWithValue("@MAHANGHOA", ctdh.MAHANGHOA); com.Parameters.AddWithValue("@SOLUONG", ctdh.SOLUONG); con.Open(); com.ExecuteNonQuery(); con.Close(); }
public ActionResult Xoadh(int[] dsxoa) { foreach (int Id in dsxoa) { DonHang x = db.DonHangs.SingleOrDefault(n => n.MaDH == Id); CTDH c = db.CTDHs.SingleOrDefault(n => n.MaDH == Id); db.DonHangs.DeleteOnSubmit(x); db.CTDHs.DeleteOnSubmit(c); } db.SubmitChanges(); return(RedirectToAction("DonHang")); }
private void xoasp_Click(object sender, EventArgs e) { CTDH cttemp = new CTDH(); cttemp.ID = ct.ID; cttemp.IDSP = int.Parse(comboBox1.SelectedValue.ToString()); cttemp.SANPHAM = sp.Where(s => s.ID == cttemp.IDSP).FirstOrDefault(); cttemp.SL = int.Parse(textBox5.Text); cttemp.DONGIA = int.Parse(textBox6.Text); cttemp.GHICHU = richTextBox1.Text; dsct.Remove(cttemp); gridControl2.DataSource = dsct; }
public static int sua(CTDH ct) { try { DAO.QLNHAP.sua(ct); return(1); } catch (Exception ex) { Console.WriteLine(ex.Message); return(0); } }
// GET: Admin/CTDH/Details/5 public ActionResult Details(string id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } CTDH cTDH = db.CTDHs.Find(id); if (cTDH == null) { return(HttpNotFound()); } return(View(cTDH)); }
public ActionResult Order() { //Kiểm tra đăng nhập người dùng if (Session["TaiKhoan"] == null || Session["TaiKhoan"].ToString() == "") { return(RedirectToAction("Login", "Home")); } //Kiểm tra giỏ hàng if (Session["GioHang"] == null) { return(RedirectToAction("Index", "Home")); } //Lỗi //var id = (from d in db.DONHANGs select d).Max(x => x.SODH);k //id = "DH" + (int.Parse(id.Substring(2)) + 1).ToString(); var don = (from n in db.DONHANGs where n.NGAYDAT == null select n).Single(); //Thêm đơn hàng USER kh = (USER)Session["TaiKhoan"]; List <GIOHANG> gh = LayGioHang(); don.USER_ID = kh.USER_ID; don.NGAYDAT = DateTime.Now; db.Entry(don).State = EntityState.Modified; string id = don.SODH; int num = int.Parse(id.Substring(2)) + 1; string DHnext = "DH" + num.ToString(); DONHANG DHmoi = new DONHANG(); DHmoi.SODH = DHnext; //Thêm đơn hàng vào csdl db.DONHANGs.Add(DHmoi); db.SaveChanges(); //Thêm chi tiết đơn hàng foreach (var item in gh) { CTDH ctdh = new CTDH(); ctdh.SODH = don.SODH; ctdh.MASP = item.gMASP; ctdh.SL = item.gSL; ctdh.THANHTIEN = item.gTHANHTIEN; db.CTDHs.Add(ctdh); } db.SaveChanges(); ViewBag.Message = "Your order was successfull!"; return(RedirectToAction("Index", "Home")); }
// GET: Admin/CTDH/Edit/5 public ActionResult Edit(string id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } CTDH cTDH = db.CTDHs.Find(id); if (cTDH == null) { return(HttpNotFound()); } ViewBag.MASP = new SelectList(db.SANPHAMs, "MASP", "TENSP", cTDH.MASP); ViewBag.SODH = new SelectList(db.DONHANGs, "SODH", "USER_ID", cTDH.SODH); return(View(cTDH)); }
public ActionResult ChitietDH(int id) { if (Session["TaikhoanAdmin"] != null) { CTDH ctdh = db.CTDHs.SingleOrDefault(n => n.MaDH == id); ViewBag.MaDH = ctdh.MaDH; var tkh = db.DonHangs.Where(a => a.MaDH == ctdh.MaDH).FirstOrDefault(); ViewBag.TenKH = db.KhachHangs.Where(a => a.MaKH == tkh.MaKH).FirstOrDefault(); ViewBag.Sp = db.SanPhams.Where(a => a.MaSP == ctdh.MaSP).ToList(); if (ctdh == null) { Response.StatusCode = 404; return(null); } return(View(ctdh)); } return(RedirectToAction("Login", "Nguoidung")); }
public string editChiTietDonHang(decimal madonhang, decimal masach, decimal soluong) { bool done; try { CTDH ct = db.CTDHs.First(x => (x.MaDH == madonhang && x.MaSach == masach)); ct.SoLuong = soluong; db.CTDHs.InsertOnSubmit(ct); db.SubmitChanges(); done = true; } catch (Exception) { done = false; } return(new JavaScriptSerializer().Serialize(done)); }
public ActionResult luudonhang(int macustomer, string diachi, string sdt, string ghichu, double tongtien) { if (Session[ssgiohang] != null) { DONHANG dh = new DONHANG(); dh.MACUSTOMER = macustomer; dh.NGAYMUA = DateTime.Today; dh.TONGTIEN = tongtien; dh.GHICHU = ghichu == ""?"N/A":ghichu; dh.SDT = sdt; dh.DIACHI = diachi; List <ITEMGIOHANGViewModel> listitem = new List <ITEMGIOHANGViewModel>(); listitem = (List <ITEMGIOHANGViewModel>)Session[ssgiohang]; List <CTDH> listctdh = new List <CTDH>(); foreach (var item in listitem) { CTDH ctdh = new CTDH(); ctdh.MASP = item.SANPHAM.MASP; ctdh.MAMERCHANT = item.SANPHAM.MAMERCHANT; ctdh.SOLUONG = item.SOLUONG; ctdh.THANHTIEN = item.THANHTIENITEM - item.TIENGIAM; ctdh.TINHTRANG = 1; ctdh.MAKICHCO = item.KICHCO.MAKICHCO; ctdh.GIAGIAM = item.SANPHAM.GIAGIAM; listctdh.Add(ctdh); CUNGSANPHAMDAL csp = new CUNGSANPHAMDAL(); csp.capnhatsoluong(ctdh.MASP, ctdh.MAKICHCO, ctdh.SOLUONG); } DONGHANGDAL dal = new DONGHANGDAL(); dal.luudonhang(dh, listctdh); Session[ssgiohang] = null; //Session["tongsoluong"] = null; //Session["tongthanhtoan"] = null; } else { return(Json(-1, JsonRequestBehavior.AllowGet)); } return(RedirectToAction("listsanphamtronggiohang")); }
public void ThemDH(int MaKH, string MaDH, int thanhtien, DataGridView g, string diachi, string TinhThanh, string QuanHuyen) { DonHang D = new DonHang(); D.MaDonHang = MaDH; D.MaKhachHang = MaKH; D.ThanhTienDonHang = thanhtien; D.NgayMuaHang = DateTime.Today; D.DiaChiGiaoHang = diachi; D.Tinh_ThanhPho = TinhThanh; D.Quan_Huyen = QuanHuyen; da.ThemDH(D); for (int i = 0; i < g.Rows.Count; i++) { CTDH CT = new CTDH(); CT.MaDonHang = MaDH; string a = (g.Rows[i].Cells[0].Value.ToString()); int Masp = da.TimMaSanPham(a); CT.MaSanPham = Masp; CT.Gia = int.Parse(g.Rows[i].Cells[1].Value.ToString()); CT.SoLuong = int.Parse(g.Rows[i].Cells[2].Value.ToString()); da.THEMCTDH(CT); } }
public void THEMCTDH(CTDH CT) { db.CTDHs.InsertOnSubmit(CT); db.SubmitChanges(); }
public static void sua(CTDH dh) { db.Entry(dh).State = EntityState.Modified; db.SaveChanges(); }