/// <summary> /// Cập nhật kiểm định /// </summary> /// <param name="id"></param> /// <returns></returns> public ActionResult Edit(int?id) { Kiemdinh kiemDinh = db.Kiemdinhs.FirstOrDefault(p => p.KiemdinhID == id); Hoadonnuoc hoaDonNuoc = db.Hoadonnuocs.Find(kiemDinh.HoaDonId); int kiemDinhKHID = kiemDinh.KhachhangID.Value; ViewData["kiemDinh"] = kiemDinh; ViewData["khachHang"] = db.Khachhangs.Find(kiemDinh.KhachhangID); ViewBag.chiSoThangTruoc = ChiSo.getChiSoThang(hoaDonNuoc.ThangHoaDon.Value.ToString(), hoaDonNuoc.NamHoaDon.Value.ToString(), hoaDonNuoc.KhachhangID.Value); ViewBag.id = id; return(View(kiemDinh)); }
public ActionResult Create(FormCollection form) { #region FormRequest String maKhachHang = String.IsNullOrEmpty(form["maKhachHang"]) ? "0" : form["maKhachHang"]; String thangKiemDinh = String.IsNullOrEmpty(form["thang"]) ? DateTime.Now.Month.ToString() : form["thang"]; String namKiemDinh = String.IsNullOrEmpty(form["nam"]) ? DateTime.Now.Year.ToString() : form["nam"]; int quanHuyenID = Convert.ToInt32(form["quan"]); ViewBag.Thang = thangKiemDinh; ViewBag.Nam = namKiemDinh; #endregion Kiemdinh kD = new Kiemdinh(); var khachHang = (from i in db.Khachhangs join r in db.Hoadonnuocs on i.KhachhangID equals r.KhachhangID where i.MaKhachHang == maKhachHang && r.ThangHoaDon.ToString() == thangKiemDinh && r.NamHoaDon.ToString() == namKiemDinh select new KhachHangModel { MaKH = i.MaKhachHang, KHID = i.KhachhangID, tenKhachHang = i.Ten, QuanhuyenID = i.QuanhuyenID == null ? 0 : i.QuanhuyenID.Value, PhuongxaID = i.PhuongxaID == null ? 0 : i.PhuongxaID.Value, CumdancuID = i.CumdancuID == null ? 0 : i.CumdancuID.Value, TuyenKHID = i.TuyenKHID == null ? 0 : i.TuyenKHID.Value, }).FirstOrDefault(); if (khachHang != null) { maKhachHang = khachHang.MaKH; var hoaDonNuoc = db.Hoadonnuocs.FirstOrDefault(p => p.KhachhangID == khachHang.KHID && p.ThangHoaDon.ToString() == thangKiemDinh && p.NamHoaDon.ToString() == namKiemDinh); var kiemDinhHoaDonNuocID = 0; if (hoaDonNuoc != null) { kiemDinhHoaDonNuocID = hoaDonNuoc.HoadonnuocID; } var isKiemDinhExist = db.Kiemdinhs.FirstOrDefault(p => p.HoaDonId == kiemDinhHoaDonNuocID); if (isKiemDinhExist == null) { #region ViewBag ViewBag.message = null; ViewBag.khachHang = khachHang; ViewBag.maKH = maKhachHang; ViewBag.khachHangID = khachHang.KHID; ViewBag.chiSoThangTruoc = ChiSo.getChiSoThang(thangKiemDinh, namKiemDinh, khachHang.KHID); ViewBag.result = true; ViewBag.HoaDonID = kiemDinhHoaDonNuocID; #endregion } else { ViewBag.message = "Thông tin kiểm định đã tồn tại"; ViewBag.result = false; ViewBag.maKH = maKhachHang; return(View()); } return(View(kD)); } else { ViewBag.message = "Không tìm thấy hóa đơn có mã khách hàng "; ViewBag.result = false; ViewBag.maKH = maKhachHang; } return(View()); }