Beispiel #1
0
        public ActionResult Edit(int?id, FormCollection form)
        {
            Kiemdinh kD           = db.Kiemdinhs.Find(id);
            DateTime ngayKiemDinh = Convert.ToDateTime(form["ngayKiemDinh"]);

            if (ngayKiemDinh != null)
            {
                //lấy danh sách attributes của khách hàng
                int    khachHangID         = int.Parse(form["khachHangID"].ToString());
                String ghiChu              = form["ghiChu"];
                int    chiSoLucKiemDinh    = Convert.ToInt32(form["chiSoTruocKiemDinh"]);
                int    chiSoSauKhiKiemDinh = Convert.ToInt32(form["chiSoSauKhiKiemDinh"]);
                //thêm object kiểm định mới

                kD.KhachhangID      = khachHangID;
                kD.Ngaykiemdinh     = ngayKiemDinh;
                kD.Ghichu           = ghiChu;
                kD.Chisoluckiemdinh = chiSoLucKiemDinh;
                kD.Chisosaukiemdinh = chiSoSauKhiKiemDinh;
                db.Entry(kD).State  = System.Data.Entity.EntityState.Modified;
                //lưu vào db
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            else
            {
                return(View("Edit", kD));
            }
        }
Beispiel #2
0
 /// <summary>
 /// Thêm mới kiểm định cho khách hàng nào đó.
 /// </summary>
 /// <param name="form"></param>
 /// <returns></returns>
 public ActionResult AddKiemDinh([Bind()] Kiemdinh kD, FormCollection form)
 {
     #region formRequest
     DateTime ngayKiemDinh        = Convert.ToDateTime(form["ngayKiemDinh"]);
     String   ghiChu              = form["ghiChu"];
     int      chiSoLucKiemDinh    = Convert.ToInt32(form["chiSoTruocKiemDinh"]);
     int      chiSoSauKhiKiemDinh = Convert.ToInt32(form["chiSoSauKhiKiemDinh"]);
     int      khachHangID         = int.Parse(form["khachHangID"].ToString());
     int      hoaDonID            = int.Parse(form["hoaDonID"]);
     #endregion
     if (ngayKiemDinh != null)
     {
         //thêm object kiểm định mới
         kD                  = new Kiemdinh();
         kD.KhachhangID      = khachHangID;
         kD.Ngaykiemdinh     = ngayKiemDinh;
         kD.Ghichu           = ghiChu;
         kD.Chisoluckiemdinh = chiSoLucKiemDinh;
         kD.Chisosaukiemdinh = chiSoSauKhiKiemDinh;
         kD.HoaDonId         = hoaDonID;
         db.Kiemdinhs.Add(kD);
         //lưu vào db
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     else
     {
         return(View("Create", kD));
     }
 }
Beispiel #3
0
        /// <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));
        }
Beispiel #4
0
        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());
        }