public ActionResult QuanLyBanVe(string id) { if (CheckUser()) { if (id != null) { ThongTinHoaDon thongTin = new ThongTinHoaDon(); thongTin.HoaDon = _context.Ves.Find(id).HoaDon; thongTin.CacVe = thongTin.HoaDon.Ves.ToList(); thongTin.KhachHang = thongTin.HoaDon.KhachHang; thongTin.NhanVien = thongTin.HoaDon.NhanVien; return(View("~/Views/Admin/ChiTietVe.cshtml", thongTin)); } QuanLyVeViewModel quanLyVeViewModel = new QuanLyVeViewModel(); quanLyVeViewModel.DanhSachThongTinVe = _context.Ves.Join(_context.Tours, ve => ve.MaTour, tour => tour.MaTour, (ve, tour) => new { Ve = ve, DiaDiemDen = tour.DiaDiemDen, DiaDiemDi = tour.DiaDiemDi }).Join(_context.LoaiVes, c => c.Ve.MaLoaiVe, loaiVe => loaiVe.MaLoaiVe, (c, loaiVe) => new ThongTinVeExpanded() { Ve = c.Ve, GiaTien = loaiVe.GiaTien, DiaDiemDen = c.DiaDiemDen, DiaDiemDi = c.DiaDiemDi }).ToList(); return(View(quanLyVeViewModel)); } return(HttpNotFound("Hãy Đăng Nhập")); }
// // Xem tt hoa don // private void Btn_ThongTinHoaDon_Click(object sender, EventArgs e) { ThongTinHoaDon a = new ThongTinHoaDon( MyResources.MyRapPhim.GetTTHoaDonTheoNgay(DateTime_Ngay.Value), DateTime_Ngay.Value); a.Show(); a.Activate(); }
public IHttpActionResult PostHoaDon(ThongTinHoaDon thongTinHoaDon) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } //them vao bang? hoa don HoaDon hoaDon = new HoaDon() { //MaHoaDon = thongTinHoaDon.MaHoaDon, MaKhachHang = thongTinHoaDon.MaKhachHang, MaNhanVien = thongTinHoaDon.MaNhanVien, NgayTao = thongTinHoaDon.NgayTao, MoTa = thongTinHoaDon.MoTa, }; //them bang? hoa don chi tiet' List <HoaDonChiTiet> hoaDonChiTiet = new List <HoaDonChiTiet>(); thongTinHoaDon.LuaChon.ToList().ForEach(v => { HoaDonChiTiet tmp = new HoaDonChiTiet() { //MaHoaDon = thongTinHoaDon.MaHoaDon, MaHoaDon = hoaDon.MaHoaDon, MaLuaChon = v.Key, SoLuong = v.Value }; hoaDonChiTiet.Add(tmp); }); db.HoaDons.Add(hoaDon); db.HoaDonChiTiets.AddRange(hoaDonChiTiet); db.SaveChanges(); // them bang? giam? gia' // lay ra list khuyen mai dang duoc ap dung. var khuyenMaiApDung = db.KhuyenMais.Where(v => v.NgayBatDau.Value <= DateTime.Now && v.NgayKetThuc >= DateTime.Now).ToList(); if (khuyenMaiApDung != null) { //GiamGiaViewModel giamGia khuyenMaiApDung.ForEach(v => { db.PostGiamGia(v.MaKhuyenMai, hoaDon.MaHoaDon); }); } return(Ok()); }
/// <summary> /// post thong tin len bang hoa don va hoa don chi tiet' /// </summary> /// <param name="thongTinHoaDon"></param> /// <returns></returns> public bool PostHoaDon(ThongTinHoaDon thongTinHoaDon) { using (var client = new HttpClient()) { client.BaseAddress = new Uri("http://localhost:49365/api/"); //HTTP POST var responseTask = client.PostAsJsonAsync("HoaDons", thongTinHoaDon); responseTask.Wait(); var result = responseTask.Result; if (result.IsSuccessStatusCode) { return(true); } else { return(false); } } }
public ActionResult saveOrder(FormCollection fc) { List <Item> cart = (List <Item>)Session["cart"]; //Lưu đơn đặt hàng HoaDon hd = new HoaDon(); hd.NgayThanhToan = DateTime.Now; hd.HoTen = fc["UserName"]; hd.DiaChi = fc["DiaChi"]; hd.SoDienThoai = fc["SoDienThoai"]; hd.TongTien = fc["TongTien"]; hd.TenHoaDon = "Đơn hàng mới"; hd.MaKH = Convert.ToInt32(Session["UserID"]); de.HoaDons.Add(hd); de.SaveChanges(); foreach (Item Item in cart) { ThongTinHoaDon tthd = new ThongTinHoaDon(); tthd.ID_HoaDon = hd.ID_HoaDon; tthd.ID_SanPham = Item.Pr.ID_SanPham; tthd.DonGia = Item.Pr.DonGia; tthd.Quantity = Item.Quantity; //Update số lượng foreach (SanPham product in de.SanPhams.Where(x => x.ID_SanPham == Item.Pr.ID_SanPham)) { product.SoLuong = Item.Pr.SoLuong - tthd.Quantity; if (product.SoLuong < 0) { ViewBag.DuplicateMessage = "Vượt quá số lượng trong kho"; return(View("Cart")); } } de.ThongTinHoaDons.Add(tthd); de.SaveChanges(); } //Xóa tất cả giỏ hàng khi thanh toán Session.Remove("cart"); return(View("Thanks")); }
private void btngiaohang_Click(object sender, EventArgs e) { int rowindex = dgvHoaDon.CurrentRow.Index; if (dgvHoaDon.CurrentCell.ColumnIndex == 6) { if (dgvHoaDon.CurrentCell.Value.ToString() == "Chưa Giao Hàng") { dgvHoaDon.CurrentCell.Value = "Đang Giao Hàng"; int idhd = int.Parse(dgvHoaDon.Rows[rowindex].Cells[0].Value.ToString()); DataTable dt = ThongTinHDDAO.Instance.GetTableforKho(idhd); List <ThongTinHoaDon> listtthd = new List <ThongTinHoaDon>(); foreach (DataRow item in dt.Rows) { ThongTinHoaDon tthd = new ThongTinHoaDon(item); listtthd.Add(tthd); } // Lấy ra các id sp và update for (int i = 0; i < listtthd.Count; i++) { SanPhamDAO.Instance.Updatekhohang(listtthd[i].Idsp, listtthd[i].Soluong); } //Cập nhật lại dgvsanpham } else { dgvHoaDon.CurrentCell.Value = "Đã Giao Hàng"; } } int id = int.Parse(dgvHoaDon.Rows[rowindex].Cells[0].Value.ToString()); HoaDonDAO.Instance.xacnhangiaohang(dgvHoaDon.CurrentCell.Value.ToString(), id); }
public void LoadTTHDtoCSDL(ThongTinHoaDon tthd) { string query = "EXEC dbo.USB_LoadTTHD @idhd , @idsp , @soluong "; DataProvider.Instance.ExecureNonQuery(query, new object[] { tthd.Idhd, tthd.Idsp, tthd.Soluong }); }
private void btnThanhToan_Click(object sender, EventArgs e) { if (lbltongcong.Text == "") { MessageBox.Show("Bạn chưa bấm Tổng Cộng", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { bool check = KhachHangDAO.Instance.checkKHCSDL(txbsdt.Text); // Check xem Kh da ton tai trong csdl chua if (check == false) { //Tạo khách hàng, và thêm khách hàng vào CSDL KhachHang kh = new KhachHang(txbName.Text, txbdiachi.Text, txbsdt.Text, txblinkfacebook.Text); KhachHangDAO.Instance.LoadKHLenCSDL(kh); //Tạo hóa đơn và lấy id hóa đơn, để gán vào thông tin hóa đơn, thêm hóa đơn vào CSDL Hoadon hd = new Hoadon(0, DateTime.Now, txbsdt.Text, "Chưa Giao Hàng", double.Parse(lbltongcong.Text)); HoaDonDAO.Instance.LoadHoaDonLenCSDL(hd); //Xử lý thêm thông tin hóa đơn foreach (ListViewItem item in lsvhoadon.Items) { // Bước 1: Lấy id sản phẩm int idhd1 = HoaDonDAO.Instance.GetidhdbySDTanddate(txbsdt.Text, DateTime.Now); int idsp = SanPhamDAO.Instance.getIdbyNameAndColor(item.SubItems[3].Text, item.SubItems[4].Text); ThongTinHoaDon tthd = new ThongTinHoaDon(idhd1, idsp, int.Parse(item.SubItems[5].Text)); ThongTinHDDAO.Instance.LoadTTHDtoCSDL(tthd); } MessageBox.Show("Thanh toán thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { // Tạo hóa đơn và lấy id hóa đơn, để gán vào thông tin hóa đơn, thêm hóa đơn vào CSDL Hoadon hd = new Hoadon(0, DateTime.Now, txbsdt.Text, "Chưa Giao Hàng", double.Parse(lbltongcong.Text)); HoaDonDAO.Instance.LoadHoaDonLenCSDL(hd); // Xử lý thêm thông tin hóa đơn foreach (ListViewItem item in lsvhoadon.Items) { // Bước 1: Lấy id sản phẩm int idhd1 = HoaDonDAO.Instance.GetidhdbySDTanddate(txbsdt.Text, DateTime.Now); int idsp = SanPhamDAO.Instance.getIdbyNameAndColor(item.SubItems[3].Text, item.SubItems[4].Text); ThongTinHoaDon tthd = new ThongTinHoaDon(idhd1, idsp, int.Parse(item.SubItems[5].Text)); ThongTinHDDAO.Instance.LoadTTHDtoCSDL(tthd); } // Cuối cùng, xóa hết dữ liệu, để nhập dữ liệu mới MessageBox.Show("Thanh toán thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); } txbName.Clear(); txbdiachi.Clear(); txbsdt.Clear(); nmtongtien.Value = 0; txbName.Focus(); cbbsanpham.SelectedIndex = 0; nmsanpham.Value = 1; lbltongcong.Text = ""; lsvhoadon.Items.Clear(); } }
private void btnThemHoaDon_Click(object sender, EventArgs e) { if (gioHangList.Count > 0) { var luaChonList = new List <LuaChonViewModel>(); gioHangList.ForEach(v => { if (v.MaTopping.Count == 1) { luaChonList.Add(new LuaChonViewModel(-1, v.MaSanPham, v.MaTopping.Last())); } else { v.MaTopping.ForEach(n => { luaChonList.Add(new LuaChonViewModel(-1, v.MaSanPham, n)); }); } }); // ma lua chon. var listId = requestData.PostLuaChon(luaChonList).ToList(); // call ham get lua chon tu` server de? lay' du lieu. loc theo ma lua chon. var _luaChonList = requestData.GetListLuaChon(); var luaChonListItem = new List <LuaChonViewModel>(); listId.ForEach(v => { luaChonListItem.AddRange(_luaChonList.Where(n => n.MaLuaChon == v)); }); if (listId != null) { //tao dictionary luu thong tin lua. chon var thongTinLuaChonList = new Dictionary <int, int>(); // so sanh voi gio hang de lay thong tin cua san pham de? them vao` hoa' don gioHangList.ForEach(v => { listId.ForEach(n => { if (luaChonListItem.Where(m => m.MaLuaChon == n && m.MaSanPham == v.MaSanPham).Count() == v.MaTopping.Count()) { thongTinLuaChonList.Add(n, v.SoLuong); } }); }); // tao bien thong tin hoa don de? thao tac ham` them vao hoa don ThongTinHoaDon thongTinHoaDon = new ThongTinHoaDon(thongTinLuaChonList, taiKhoan.Id, DateTime.Now, txtMoTa.Text); bool check = requestData.PostHoaDon(thongTinHoaDon); if (check == true) { MessageBox.Show("Tạo hóa đơn thành công!", "OK!!!", MessageBoxButtons.OK, MessageBoxIcon.Information); gioHangList.Clear(); this.Dispose(); } else { MessageBox.Show("Tạo hóa đơn thất bại!", "ERROR!!!", MessageBoxButtons.OK, MessageBoxIcon.Error); gioHangList.Clear(); this.Dispose(); } } else { MessageBox.Show("Thêm lựa chọn thất bại!"); } //listId.ForEach(v => //{ // MessageBox.Show(v.ToString()); //}); } else { MessageBox.Show("Chưa chọn sản phẩm để tạo hóa đơn!", "EEROR!!!", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public ActionResult OrderNow(CartModel cart1) { WEBEntities1 db = new WEBEntities1(); HoaDon HD = new HoaDon(); ThongTinHoaDon TTHD = new ThongTinHoaDon(); String b; b = Session["LogedMaND"].ToString(); long a; a = Convert.ToInt64(b); HD.NgayLap = DateTime.Now; HD.MaND = a; HD.DiaChi = cart1.DiaChi; String a1; String a2; String a3; String aMaHD = "0"; a1 = HD.NgayLap.ToString(); a2 = HD.MaND.ToString(); a3 = HD.DiaChi.ToString(); string studentName; if (ModelState.IsValid) { db.HoaDons.Add(HD); db.SaveChanges(); //using (var ctx = new WEBEntities1()) //{ // //Get student name of string type // studentName = ctx.Database.SqlQuery<string>("Select MaHD from HoaDon where MaND = "+a2+",NgayLap ='"+a1+"'").FirstOrDefault<string>(); // } HoaDon a5; using (var ctx = new WEBEntities1()) { List <HoaDon> listHD = (from hd in db.HoaDons select hd).ToList <HoaDon>(); a5 = listHD.Last(); } foreach (Item item in (List <Item>)Session["cart"]) { TTHD.MaSP = item.Sanpham.MaSP; TTHD.SoLuong = item.Quantity; TTHD.Gia = item.Sanpham.Gia; TTHD.MaHD = a5.MaHD; if (ModelState.IsValid) { db.ThongTinHoaDons.Add(TTHD); db.SaveChanges(); } } return(RedirectToAction("Index", "Home")); } else { return(View("Fail", "User")); } }