Пример #1
0
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            try
            {
                db.Configuration.LazyLoadingEnabled = false;
                CN_HopDong cN_HopDong = db.CN_HopDong.Find(id);
                if (cN_HopDong == null)
                {
                    return(HttpNotFound());
                }
                ViewBag.IDLoai = DanhSachLoaiHopDongPhanQuyen(cN_HopDong.IDLoai);
                //Cong trinh
                ViewBag.IDCT = DanhSachCongTrinh(cN_HopDong.IDCT);
                //Don vi thuc hien
                ViewBag.IDDV = DanhSachDonViThucHien(cN_HopDong.IDDV);
                //Hinh thuc hop dong
                ViewBag.IDHT = DanhSachHinhThucHopDong(cN_HopDong.IDHT);
                //
                ViewBag.NguoiTao = DanhSachNguoiTao(cN_HopDong.NguoiTao.GetValueOrDefault(Guid.Empty).ToString());

                return(View(cN_HopDong));
            }
            catch (Exception ex)
            {
                string cauBaoLoi = "Không lấy được dữ liệu.<br/>Lý do: " + ex.Message;
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest, cauBaoLoi));
            }
        }
Пример #2
0
        public ActionResult Delete(int id)
        {
            CN_HopDong cN_HopDong = db.CN_HopDong.Find(id);

            db.CN_HopDong.Remove(cN_HopDong);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Пример #3
0
        public ActionResult Edit_XuPhatTranhChap(int?Id)
        {
            if (Id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            db.Configuration.LazyLoadingEnabled = false;
            CN_HopDong cN_HopDong = db.CN_HopDong.Find(Id);

            if (cN_HopDong == null)
            {
                return(HttpNotFound());
            }
            return(View(cN_HopDong));
        }
Пример #4
0
        public ActionResult Edit_XuPhatTranhChap(CN_HopDong cN_HopDong)
        {
            try
            {
                ModelState.Clear();
                if (cN_HopDong.GiaTriPhat.GetValueOrDefault(0) < 1000)
                {
                    ModelState.AddModelError("GiaTriPhat", "Số tiền phải lớn hơn 1,000VND");
                }
                if (string.IsNullOrWhiteSpace(cN_HopDong.XuLyTranhChap))
                {
                    ModelState.AddModelError("GiaTriPhat", "Nhập nội dung xử lý tranh chấp");
                }
                if (string.IsNullOrWhiteSpace(cN_HopDong.XuLyViPham))
                {
                    ModelState.AddModelError("XuLyViPham", "Nhập nội dung xử lý vi phạm");
                }
                if (ModelState.IsValid)
                {
                    var cN_HopDongUpdate = db.CN_HopDong.Find(cN_HopDong.IDHD);
                    TryUpdateModel(cN_HopDongUpdate, new string[] {
                        "GiaTriPhat", "XuLyTranhChap", "XuLyViPham"
                    });
                    db.SaveChanges();
                    TempData["err"] = "<div class='alert alert-success' role='alert'><span class='glyphicon glyphicon-exclamation - sign' aria-hidden='true'></span><span class='sr - only'></span>Cập nhật thành công</div> ";
                    // luu lich su
                    HT_LichSuHoatDong ls = new HT_LichSuHoatDong(
                        ChucNang
                        , "UPDATE"
                        , DateTime.Now, Session["username"]?.ToString()
                        , $" Cập nhật - xử phat tranh chấp - Hợp đồng {cN_HopDong.SoHopDong} ");
                    db.HT_LichSuHoatDong.Add(ls);
                    db.SaveChanges();
                    return(View(cN_HopDong));
                }

                return(View(cN_HopDong));
            }
            catch (Exception ex)
            {
                string cauBaoLoi = "Không lấy được dữ liệu.<br/>Lý do: " + ex.Message;
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest, cauBaoLoi));
            }
        }
Пример #5
0
 public ActionResult Edit([Bind(Include = "IDTL, IDHD, IsHoanThanh, NgayThanhLy, GiaTriThanhLy, GiaTriQuyetToan, NgayTongNghiemThu, NguoiTao, NgayTao, NguoiCapNhat, NgayCapNhat")] CN_ThanhLy cN_ThanhLy, FormCollection fCollection)
 {
     try
     {
         db.Configuration.LazyLoadingEnabled = false;
         CN_HopDong hopDong = db.CN_HopDong.Find(cN_ThanhLy.IDHD);
         if (cN_ThanhLy.NgayThanhLy < hopDong.NgayHetHan)
         {
             ModelState.AddModelError("NgayThanhLy", $"Ngày thanh lý hợp đổng nhỏ hơn Ngày hết hạn {hopDong.NgayHetHan}");
         }
         if (ModelState.IsValid)
         {
             List <SelectListItem> list = _common.getThongTinBang();
             cN_ThanhLy.NguoiCapNhat    = list.Where(o => o.Value == "NguoiCapNhat").SingleOrDefault().Text;
             cN_ThanhLy.NgayCapNhat     = DateTime.Parse(list.Where(o => o.Value == "NgayCapNhat").SingleOrDefault().Text);
             db.Entry(cN_ThanhLy).State = EntityState.Modified;
             db.SaveChanges();
             //TempData["err"] = "<div class='alert alert-success' role='alert'><span class='glyphicon glyphicon-exclamation - sign' aria-hidden='true'></span><span class='sr - only'></span>Cập nhật thành công</div> ";
             #region luu lich su
             // luu lich su
             HT_LichSuHoatDong ls = new HT_LichSuHoatDong(
                 ChucNang
                 , "UPDATE"
                 , DateTime.Now, Session["username"]?.ToString()
                 , $"Cập nhật - Thanh lý - số hợp đồng { hopDong?.SoHopDong }");
             db.HT_LichSuHoatDong.Add(ls);
             db.SaveChanges();
             #endregion
             return(RedirectToAction("Index"));
         }
         TempData["err"] = "<div class='alert alert-danger' role='alert'><span class='glyphicon glyphicon-exclamation - sign' aria-hidden='true'></span><span class='sr - only'></span>Có lỗi xảy ra</div> ";
         ViewBag.IDHD    = DanhSachHopDong(cN_ThanhLy.IDHD.Value);
         return(View(cN_ThanhLy));
     }
     catch (Exception ex)
     {
         string cauBaoLoi = "Không ghi được dữ liệu.<br/>Lý do: " + ex.Message;
         return(new HttpStatusCodeResult(HttpStatusCode.BadRequest, cauBaoLoi));
     }
 }
Пример #6
0
        public ActionResult Delete(int id)
        {
            CN_DieuChinh cN_DieuChinh = db.CN_DieuChinh.Find(id);
            CN_HopDong   hopDong      = db.CN_HopDong.Find(cN_DieuChinh.IDHD);
            //db.CN_DieuChinh.Remove(cN_DieuChinh);
            //db.SaveChanges();
            SqlParameter sParameter = new SqlParameter();

            sParameter.ParameterName = "@IDDC";
            sParameter.Value         = id;
            sParameter.SqlDbType     = SqlDbType.Int;
            db.Database.ExecuteSqlCommand("Delete_CN_DieuChinh_HopDong @IDDC", sParameter);
            #region luu lich su
            // luu lich su
            HT_LichSuHoatDong ls = new HT_LichSuHoatDong(
                ChucNang
                , "DELETE"
                , DateTime.Now, Session["username"]?.ToString()
                , $" Xóa điều chỉnh - Số HD {hopDong?.SoHopDong} - lần điều chỉnh {cN_DieuChinh.DotDieuChinh}"); db.HT_LichSuHoatDong.Add(ls);
            db.SaveChanges();
            #endregion
            return(RedirectToAction("Index"));
        }
Пример #7
0
        public ActionResult Edit(CN_HopDong cN_HopDong)
        {
            try
            {
                db.Configuration.LazyLoadingEnabled = false;
                int dHopDong = db.CN_HopDong.Where(p => !string.IsNullOrEmpty(cN_HopDong.SoHopDong) && p.IDHD != cN_HopDong.IDHD && string.Compare(p.SoHopDong.Trim().Replace("\n", "").Replace("\r", ""), cN_HopDong.SoHopDong.Trim()) == 0).Count();
                if (dHopDong > 0)
                {
                    ModelState.AddModelError("SoHopDong", "Số hợp đồng đã tồn tại.");
                }
                if (cN_HopDong.IDLoai.GetValueOrDefault(-1) == -1)
                {
                    ModelState.AddModelError("IDLoai", "Chọn loại hợp đồng.");
                }
                if (cN_HopDong.IDCT.GetValueOrDefault(-1) == -1)
                {
                    ModelState.AddModelError("IDCT", "Chọn công trình.");
                }
                if (cN_HopDong.IDHT.GetValueOrDefault(-1) == -1)
                {
                    ModelState.AddModelError("IDHT", "Chọn hình thức hợp đồng.");
                }
                // giá trị hợp đông nhỏ hơn giá trị gói thầu
                if (cN_HopDong.GiaTriHopDong.GetValueOrDefault(-1) > cN_HopDong.GiaTriGoiThau.GetValueOrDefault(-1))
                {
                    ModelState.AddModelError("GiaTriHopDong", "Giá trị hợp đồng < Giá trị gói thầu.");
                }
                //số ngày thi công nhỏ hơn số ngày thực hiện
                if (cN_HopDong.SoNgayThiCong.GetValueOrDefault(-1) > cN_HopDong.SoNgayThucHien.GetValueOrDefault(-1))
                {
                    ModelState.AddModelError("SoNgayThiCong", "Số ngày thi công < Số ngày thực hiện.");
                }
                if (cN_HopDong.IDDV == -1)
                {
                    cN_HopDong.IDDV = null;
                }
                if (cN_HopDong.NgayHetHan < cN_HopDong.NgayKy)
                {
                    ModelState.AddModelError("NgayHetHan", "Ngày hết hạn HĐ phải lớn hơn ngày ký HĐ");
                }
                DateTime cNgayHetHan = cN_HopDong.NgayKy.Value;
                if (cN_HopDong.NgayHetHan < cNgayHetHan.AddDays(cN_HopDong.SoNgayThucHien.GetValueOrDefault(0)))
                {
                    ModelState.AddModelError("NgayHetHan", "Ngày hết hạn HĐ phải lớn hơn ngày ký HĐ + Số ngày thực hiện");
                }
                if (ModelState.IsValid)
                {
                    ModelState.Clear();
                    List <SelectListItem> list = _common.getThongTinBang();
                    cN_HopDong.NguoiCapNhat = list.Where(o => o.Value == "NguoiTao").SingleOrDefault().Text;
                    cN_HopDong.NgayCapNhat  = DateTime.Parse(list.Where(o => o.Value == "NgayTao").SingleOrDefault().Text);
                    CN_HopDong cN_HopDongUpdate = new CN_HopDong();
                    cN_HopDongUpdate = db.CN_HopDong.Find(cN_HopDong.IDHD);

                    //var cN_HopDongUpdate = db.CN_HopDong.Find(cN_HopDong.IDHD);

                    TryUpdateModel(cN_HopDongUpdate, new string[] {
                        "IDLoai", "SoHopDong", "NgayKy", "NoiDung", "IDCT", "IDDV", "IDHT", "NamGiaoA", "GiaTriHopDong", "GiaTriGoiThau",
                        "SoNgayThiCong", "SoNgayThucHien", "NgayHetHan", "NguoiCapNhat", "NgayCapNhat"
                    });
                    if (ModelState.IsValid == false)
                    {
                        string Errors = "";
                        foreach (ModelState item in ModelState.Values)
                        {
                            if (item.Errors.Count > 0)
                            {
                                Errors += $"tring error: {item.Errors[0].ErrorMessage} AttemptedValue: {item.Value.AttemptedValue} <br>";
                            }
                        }
                        throw new Exception(Errors);
                    }
                    db.SaveChanges();
                    TempData["err"] = "<div class='alert alert-success' role='alert'><span class='glyphicon glyphicon-exclamation - sign' aria-hidden='true'></span><span class='sr - only'></span> Cập nhật thành công</div> ";
                    // luu lich su
                    HT_LichSuHoatDong ls = new HT_LichSuHoatDong(
                        ChucNang
                        , "UPDATE"
                        , DateTime.Now, Session["username"]?.ToString()
                        , $" Cập nhật - Tên hợp đồng {cN_HopDong.SoHopDong} ");
                    db.HT_LichSuHoatDong.Add(ls);
                    db.SaveChanges();
                    return(RedirectToAction("Index"));
                }
                ViewBag.IDLoai = DanhSachLoaiHopDongPhanQuyen(cN_HopDong.IDLoai);
                //Cong trinh
                ViewBag.IDCT = DanhSachCongTrinh(cN_HopDong.IDCT);
                //Don vi thuc hien
                ViewBag.IDDV = DanhSachDonViThucHien(cN_HopDong.IDDV);
                //Hinh thuc hop dong
                ViewBag.IDHT = DanhSachHinhThucHopDong(cN_HopDong.IDHT);
                //nguoi tao
                ViewBag.NguoiTao = DanhSachNguoiTao(cN_HopDong.NguoiTao.GetValueOrDefault(Guid.Empty).ToString());
                return(View(cN_HopDong));
            }
            catch (Exception ex)
            {
                string cauBaoLoi = "Không lấy được dữ liệu.<br/>Lý do: " + ex.Message;
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest, cauBaoLoi));
            }
        }
Пример #8
0
 public ActionResult Create([Bind(Include = "IDHD,IDLoai,MaCT,NoiDung,MaDD,NamGiaoA,IDDV,GiaTriGoiThau,IDHT,SoHopDong,NgayKy,GiaTriHopDong,SoNgayThucHien,SoNgayThiCong,NgayTongNghiemThu,XuLyViPham,GiaTriPhat,XuLyTranhChap,IsHoanThanh,NguoiTao,NgayTao,NguoiCapNhat,NgayCapNhat,NgayHetHan,IDCT")] CN_HopDong cN_HopDong)
 {
     try
     {
         db.Configuration.LazyLoadingEnabled = false;
         int dHopDong = db.CN_HopDong.Where(p => !string.IsNullOrEmpty(cN_HopDong.SoHopDong) && string.Compare(p.SoHopDong.Trim().Replace("\n", "").Replace("\r", ""), cN_HopDong.SoHopDong.Trim()) == 0).Count();
         if (dHopDong > 0)
         {
             ModelState.AddModelError("SoHopDong", "Số hợp đồng đã tồn tại.");
         }
         if (cN_HopDong.IDLoai.GetValueOrDefault(-1) == -1)
         {
             ModelState.AddModelError("IDLoai", "Chọn loại hợp đồng.");
         }
         if (cN_HopDong.IDCT.GetValueOrDefault(-1) == -1)
         {
             ModelState.AddModelError("IDCT", "Chọn công trình.");
         }
         if (cN_HopDong.IDHT.GetValueOrDefault(-1) == -1)
         {
             ModelState.AddModelError("IDHT", "Chọn hình thức hợp đồng.");
         }
         // giá trị hợp đông nhỏ hơn giá trị gói thầu
         if (cN_HopDong.GiaTriHopDong.GetValueOrDefault(-1) > cN_HopDong.GiaTriGoiThau.GetValueOrDefault(-1))
         {
             ModelState.AddModelError("GiaTriHopDong", "Giá trị hợp đồng < Giá trị gói thầu.");
         }
         //số ngày thi công nhỏ hơn số ngày thực hiện
         if (cN_HopDong.SoNgayThiCong.GetValueOrDefault(-1) > cN_HopDong.SoNgayThucHien.GetValueOrDefault(-1))
         {
             ModelState.AddModelError("SoNgayThiCong", "Số ngày thi công < Số ngày thực hiện.");
         }
         if (cN_HopDong.IDDV == -1)
         {
             cN_HopDong.IDDV = null;
         }
         if (cN_HopDong.NgayHetHan < cN_HopDong.NgayKy)
         {
             ModelState.AddModelError("NgayHetHan", "Ngày hết hạn HĐ phải lớn hơn ngày ký HĐ");
         }
         DateTime cNgayHetHan = cN_HopDong.NgayKy.Value;
         if (cN_HopDong.NgayHetHan < cNgayHetHan.AddDays(cN_HopDong.SoNgayThucHien.GetValueOrDefault(0)))
         {
             ModelState.AddModelError("NgayHetHan", "Ngày hết hạn HĐ phải lớn hơn ngày ký HĐ + Số ngày thực hiện");
         }
         if (ModelState.IsValid)
         {
             //
             List <SelectListItem> list = _common.getThongTinBang();
             cN_HopDong.NguoiTao = Guid.Parse(list.Where(o => o.Value == "NguoiTao").SingleOrDefault().Text);
             cN_HopDong.NgayTao  = DateTime.Parse(list.Where(o => o.Value == "NgayTao").SingleOrDefault().Text);
             db.CN_HopDong.Add(cN_HopDong);
             db.SaveChanges();
             // luu lich su
             HT_LichSuHoatDong ls = new HT_LichSuHoatDong(
                 ChucNang
                 , "CREATE"
                 , DateTime.Now, Session["username"]?.ToString()
                 , $" Thêm mới - Số hợp đồng {cN_HopDong.SoHopDong} ");
             db.HT_LichSuHoatDong.Add(ls);
             db.SaveChanges();
             return(RedirectToAction("Index"));
         }
         ViewBag.IDCT     = DanhSachCongTrinh(cN_HopDong.IDCT);
         ViewBag.IDDV     = DanhSachDonViThucHien(cN_HopDong.IDDV);
         ViewBag.IDHT     = DanhSachHinhThucHopDong(cN_HopDong.IDHT);
         ViewBag.NguoiTao = DanhSachNguoiTao(cN_HopDong.NguoiTao?.ToString());
         ViewBag.IDLoai   = DanhSachLoaiHopDong(cN_HopDong.IDLoai);
         return(View(cN_HopDong));
     }
     catch (Exception ex)
     {
         string cauBaoLoi = "Không ghi được dữ liệu.<br/>Lý do: " + ex.Message;
         return(new HttpStatusCodeResult(HttpStatusCode.BadRequest, cauBaoLoi));
     }
 }
Пример #9
0
        public ActionResult Edit([Bind(Include = "IDDC,IDHD,NgayDieuChinh,GiaTriDieuChinh,SoNgayGiaHanTienDo,LyDoDieuChinh,NguoiTao,NgayTao,NguoiCapNhat,NgayCapNhat,DotDieuChinh,NgayHetHanDC,IDLoaiDieuChinh,ChenhLech")] CN_DieuChinh cN_DieuChinh, FormCollection _FormCollection)
        {
            CN_HopDong hopDong = db.CN_HopDong.Find(cN_DieuChinh.IDHD);

            if (ModelState.IsValid)
            {
                string FlagCreate = _FormCollection["FlagCreate"]; //0: cap nhat 1: them moi
                List <SelectListItem> lThongTin = _common.getThongTinBang();

                string err = "";
                if (cN_DieuChinh.NgayDieuChinh.HasValue == false)
                {
                    TempData["err"] = "< div class='alert alert-danger' role='alert'><span class='glyphicon glyphicon-exclamation - sign' aria-hidden='true'></span><span class='sr - only'></span>Vui lòng chọn ngày điều chỉnh</div> ";
                }
                var iTienDoSauDC = db.GetTienDo_SauDieuChinh(cN_DieuChinh.IDHD, cN_DieuChinh.DotDieuChinh, cN_DieuChinh.SoNgayGiaHanTienDo).SingleOrDefault();
                if (iTienDoSauDC.SoNgayThiCong > iTienDoSauDC.SoNgayThucHien)
                {
                    TempData["err"]          = "<div class='alert alert-danger' role='alert'><span class='glyphicon glyphicon-exclamation - sign' aria-hidden='true'></span><span class='sr - only'></span>“Tiến độ thi công” không được lớn hơn “Thời gian thực hiện hợp đồng”</div> ";
                    ViewBag.DotDieuChinhNew  = cN_DieuChinh.DotDieuChinh + 1;
                    ViewBag.IDHD             = new SelectList(db.CN_HopDong.Where(o => o.IDHD == cN_DieuChinh.IDHD), "IDHD", "SoHopDong", cN_DieuChinh.IDHD);
                    ViewBag.DotDieuChinh     = cN_DieuChinh.DotDieuChinh;
                    ViewBag.ListDotDieuChinh = db.CN_DieuChinh.Where(o => o.IDHD == cN_DieuChinh.IDHD).OrderByDescending(o => o.IDDC).ToList();
                    ViewBag.HopDongDC        = db.CN_HopDong.Where(o => o.IDHD == cN_DieuChinh.IDHD).FirstOrDefault();
                    ViewBag.IDLoaiDieuChinh  = new SelectList(db.DM_LoaiDieuChinh.Where(x => x.Khoa != false).Select(x => new SelectListItem {
                        Value = x.IDLoaiDieuChinh.ToString(), Text = x.TenLoaiDieuChinh
                    }), "Value", "Text");
                    ViewBag.DSHD = db.CN_HopDong.Where(o => o.IDHD == cN_DieuChinh.IDHD).Select(s => new HopDongDC
                    {
                        IDHD         = s.IDHD.ToString(),
                        GiaTriThucTe = s.GiaTriThucTe.HasValue == true ? s.GiaTriThucTe.ToString() : s.GiaTriHopDong.ToString(),
                        ngayKy       = s.NgayKy.ToString()
                    }).FirstOrDefault();
                    return(View(cN_DieuChinh));
                }
                #region
                //if (FlagCreate == "1")
                //{
                //    CN_DieuChinh oNew = new CN_DieuChinh();
                //    oNew.DotDieuChinh = cN_DieuChinh.DotDieuChinh;
                //    oNew.GiaTriDieuChinh = cN_DieuChinh.GiaTriDieuChinh;
                //    oNew.IDHD = cN_DieuChinh.IDHD;
                //    oNew.LyDoDieuChinh = cN_DieuChinh.LyDoDieuChinh;
                //    oNew.NgayDieuChinh = cN_DieuChinh.NgayDieuChinh;
                //    oNew.NgayTao = DateTime.Parse(lThongTin.Where(o => o.Value == "NgayTao").SingleOrDefault().Text);
                //    oNew.NguoiTao = lThongTin.Where(o => o.Value == "NguoiTao").SingleOrDefault().Text;
                //    oNew.SoNgayGiaHanTienDo = cN_DieuChinh.SoNgayGiaHanTienDo;
                //    oNew.NgayHetHanDC = cN_DieuChinh.NgayHetHanDC;
                //    oNew.IDLoaiDieuChinh = cN_DieuChinh.IDLoaiDieuChinh;
                //    oNew.ChenhLech = cN_DieuChinh.ChenhLech;
                //    db.CN_DieuChinh.Add(oNew);
                //    db.SaveChanges();

                //}
                //else
                //{
                //    List<SelectListItem> list = _common.getThongTinBang();
                //    cN_DieuChinh.NguoiCapNhat = list.Where(o => o.Value == "NguoiCapNhat").SingleOrDefault().Text;
                //    cN_DieuChinh.NgayCapNhat = DateTime.Parse(list.Where(o => o.Value == "NgayCapNhat").SingleOrDefault().Text);
                //    db.Entry(cN_DieuChinh).State = EntityState.Modified;
                //    db.SaveChanges();
                //}
                #endregion
                #region tham số
                SqlParameter[] AParameter =
                {
                    new SqlParameter
                    {
                        ParameterName = "@IDDC",
                        Value         = cN_DieuChinh.IDDC,
                        DbType        = DbType.Int32
                    },
                    new SqlParameter
                    {
                        ParameterName = "@IDHD",
                        Value         = cN_DieuChinh.IDHD,
                        DbType        = DbType.Int32
                    },
                    new SqlParameter
                    {
                        ParameterName = "@NgayDieuChinh",
                        Value         = cN_DieuChinh.NgayDieuChinh,
                        DbType        = DbType.Date
                    },
                    new SqlParameter
                    {
                        ParameterName = "@GiaTriDieuChinh",
                        Value         = cN_DieuChinh.GiaTriDieuChinh,
                        DbType        = DbType.Decimal,
                        Precision     = 18,
                        Scale         = 3,
                        IsNullable    = true
                    },
                    new SqlParameter
                    {
                        ParameterName = "@ChenhLech",
                        Value         = cN_DieuChinh.ChenhLech,
                        DbType        = DbType.Decimal,
                        Precision     = 18,
                        Scale         = 3
                    },
                    new SqlParameter
                    {
                        ParameterName = "@SoNgayGiaHanTienDo",
                        Value         = cN_DieuChinh.SoNgayGiaHanTienDo,
                        DbType        = DbType.Int32,
                    },
                    new SqlParameter
                    {
                        ParameterName = "@LyDoDieuChinh",
                        Value         = cN_DieuChinh.LyDoDieuChinh ?? string.Empty,
                        //DbType = DbType.String,
                        IsNullable = true,
                        SqlDbType  = SqlDbType.NVarChar,
                        Size       = 255
                    },
                    new SqlParameter
                    {
                        ParameterName = "@NguoiTao",
                        Value         = lThongTin.Where(o => o.Value == "NguoiTao").SingleOrDefault().Text,
                        DbType        = DbType.String
                    },
                    new SqlParameter
                    {
                        ParameterName = "@NgayTao",
                        Value         = DateTime.Parse(lThongTin.Where(o => o.Value == "NgayTao").SingleOrDefault().Text),
                        DbType        = DbType.Date
                    },
                    new SqlParameter
                    {
                        ParameterName = "@NguoiCapNhat",
                        Value         = lThongTin.Where(o => o.Value == "NguoiCapNhat").SingleOrDefault().Text,
                        DbType        = DbType.String
                    },
                    new SqlParameter
                    {
                        ParameterName = "@NgayCapNhat",
                        Value         = DateTime.Parse(lThongTin.Where(o => o.Value == "NgayCapNhat").SingleOrDefault().Text),
                        DbType        = DbType.Date
                    },
                    new SqlParameter
                    {
                        ParameterName = "@DotDieuChinh",
                        Value         = cN_DieuChinh.DotDieuChinh,
                        DbType        = DbType.Int32
                    },
                    new SqlParameter
                    {
                        ParameterName = "@NgayHetHanDC",
                        Value         = cN_DieuChinh.NgayHetHanDC,
                        DbType        = DbType.Date
                    },
                    new SqlParameter
                    {
                        ParameterName = "@IDLoaiDieuChinh",
                        Value         = cN_DieuChinh.IDLoaiDieuChinh,
                        DbType        = DbType.Int32
                    },
                    new SqlParameter
                    {
                        ParameterName = "@FlagCreate",
                        Value         = FlagCreate,
                        DbType        = DbType.String
                    }
                };
                #endregion

                db.Database.ExecuteSqlCommand("Insert_CN_DieuChinh_HopDong  @IDDC, @IDHD, @NgayDieuChinh, @GiaTriDieuChinh, @ChenhLech, @SoNgayGiaHanTienDo, @LyDoDieuChinh, @NguoiTao,@NgayTao, @NguoiCapNhat, @NgayCapNhat, @DotDieuChinh, @NgayHetHanDC, @IDLoaiDieuChinh, @FlagCreate", AParameter);
                #region luu lich su
                // luu lich su
                HT_LichSuHoatDong ls = new HT_LichSuHoatDong(
                    ChucNang
                    , "UPDATE"
                    , DateTime.Now, Session["username"]?.ToString()
                    , $"Cập nhật điều chỉnh - Số HD {hopDong?.SoHopDong} - lần điều chỉnh {cN_DieuChinh.DotDieuChinh}");
                db.HT_LichSuHoatDong.Add(ls);
                db.SaveChanges();
                #endregion
                return(RedirectToAction("Edit", cN_DieuChinh.IDDC));
            }
            return(RedirectToAction("Edit", cN_DieuChinh.IDDC));
        }
Пример #10
0
        //public ActionResult Create([Bind(Include = "IDDC,IDHD,NgayDieuChinh,GiaTriDieuChinh,SoNgayGiaHanTienDo,LyDoDieuChinh,NguoiTao,NgayTao,NguoiCapNhat,NgayCapNhat,NgayHetHanDC,IDLoaiDieuChinh,ChenhLech")] CN_DieuChinh cN_DieuChinh)
        public ActionResult Create(CN_DieuChinh cN_DieuChinh)
        {
            //ViewBag.IDHD = new SelectList(db.CN_HopDong, "IDHD", "SoHopDong", cN_DieuChinh.IDHD);
            //var itemIds = db.CN_DieuChinh.Select(x => x.IDHD).ToArray();
            //ViewBag.DotDieuChinhNew = cN_DieuChinh.DotDieuChinh + 1;
            //ViewBag.IDHD = new SelectList(db.CN_HopDong.Where(o => o.IDHD == cN_DieuChinh.IDHD), "IDHD", "SoHopDong", cN_DieuChinh.IDHD);
            //ViewBag.DotDieuChinh = cN_DieuChinh.DotDieuChinh;
            //ViewBag.ListDotDieuChinh = db.CN_DieuChinh.Where(o => o.IDHD == cN_DieuChinh.IDHD).OrderByDescending(o => o.IDDC).ToList();
            //ViewBag.HopDongDC = db.CN_HopDong.Where(o => o.IDHD == cN_DieuChinh.IDHD).FirstOrDefault();
            //ViewBag.IDLoaiDieuChinh = new SelectList(db.DM_LoaiDieuChinh.Where(x => x.Khoa != false).Select(x => new SelectListItem { Value = x.IDLoaiDieuChinh.ToString(), Text = x.TenLoaiDieuChinh }), "Value", "Text");
            //ViewBag.NgayKyHD = new SelectList(db.CN_HopDong.Where(x => !itemIds.Contains(x.IDHD)).Select(s => new SelectListItem { Value = s.IDHD.ToString(), Text = s.NgayHetHan.ToString() }));
            //ViewBag.DSHD = db.CN_HopDong.Where(x => !itemIds.Contains(x.IDHD)).Select(s => new HopDongDC{
            //                                                          IDHD = s.IDHD.ToString(),
            //                                                          GiaTriThucTe = s.GiaTriThucTe.HasValue == true ? s.GiaTriThucTe.ToString() : s.GiaTriHopDong.ToString(),
            //                                                          ngayKy = s.NgayKy.ToString()
            //                                                      }).ToList();
            try
            {
                db.Configuration.LazyLoadingEnabled = false;
                CN_HopDong hopDong      = db.CN_HopDong.Find(cN_DieuChinh.IDHD);
                var        iTienDoSauDC = db.GetTienDo_SauDieuChinh(cN_DieuChinh.IDHD, cN_DieuChinh.DotDieuChinh, cN_DieuChinh.SoNgayGiaHanTienDo).SingleOrDefault();
                if (iTienDoSauDC.SoNgayThiCong > iTienDoSauDC.SoNgayThucHien)
                {
                    ModelState.AddModelError("SoNgayThiCong", $"Tiến độ thi công” không được lớn hơn “Thời gian thực hiện hợp đồng { iTienDoSauDC.SoNgayThucHien?.ToString("0:##0")}");
                }
                if (ModelState.IsValid)
                {
                    List <SelectListItem> lThongTin = _common.getThongTinBang();
                    #region tham số
                    SqlParameter[] AParameter =
                    {
                        new SqlParameter
                        {
                            ParameterName = "@IDDC",
                            Value         = cN_DieuChinh.IDDC,
                            DbType        = DbType.Int32
                        },
                        new SqlParameter
                        {
                            ParameterName = "@IDHD",
                            Value         = cN_DieuChinh.IDHD,
                            DbType        = DbType.Int32
                        },
                        new SqlParameter
                        {
                            ParameterName = "@NgayDieuChinh",
                            Value         = cN_DieuChinh.NgayDieuChinh,
                            DbType        = DbType.Date
                        },
                        new SqlParameter
                        {
                            ParameterName = "@GiaTriDieuChinh",
                            Value         = cN_DieuChinh.GiaTriDieuChinh,
                            DbType        = DbType.Decimal,
                            Precision     = 18,
                            Scale         = 3
                        },
                        new SqlParameter
                        {
                            ParameterName = "@ChenhLech",
                            Value         = cN_DieuChinh.ChenhLech,
                            DbType        = DbType.Decimal,
                            Precision     = 18,
                            Scale         = 3
                        },
                        new SqlParameter
                        {
                            ParameterName = "@SoNgayGiaHanTienDo",
                            Value         = cN_DieuChinh.SoNgayGiaHanTienDo,
                            DbType        = DbType.Int32,
                        },
                        new SqlParameter
                        {
                            ParameterName = "@LyDoDieuChinh",
                            Value         = cN_DieuChinh.LyDoDieuChinh,
                            DbType        = DbType.String
                        },
                        new SqlParameter
                        {
                            ParameterName = "@NguoiTao",
                            Value         = lThongTin.Where(o => o.Value == "NguoiTao").SingleOrDefault().Text,
                            DbType        = DbType.String
                        },
                        new SqlParameter
                        {
                            ParameterName = "@NgayTao",
                            Value         = DateTime.Parse(lThongTin.Where(o => o.Value == "NgayTao").SingleOrDefault().Text),
                            DbType        = DbType.Date
                        },
                        new SqlParameter
                        {
                            ParameterName = "@NguoiCapNhat",
                            Value         = lThongTin.Where(o => o.Value == "NguoiCapNhat").SingleOrDefault().Text,
                            DbType        = DbType.String
                        },
                        new SqlParameter
                        {
                            ParameterName = "@NgayCapNhat",
                            Value         = DateTime.Parse(lThongTin.Where(o => o.Value == "NgayCapNhat").SingleOrDefault().Text),
                            DbType        = DbType.Date
                        },
                        new SqlParameter
                        {
                            ParameterName = "@DotDieuChinh",
                            Value         = 1,
                            DbType        = DbType.Int32
                        },
                        new SqlParameter
                        {
                            ParameterName = "@NgayHetHanDC",
                            Value         = cN_DieuChinh.NgayHetHanDC,
                            DbType        = DbType.Date
                        },
                        new SqlParameter
                        {
                            ParameterName = "@IDLoaiDieuChinh",
                            Value         = cN_DieuChinh.IDLoaiDieuChinh,
                            DbType        = DbType.Int32
                        },
                        new SqlParameter
                        {
                            ParameterName = "@FlagCreate",
                            Value         = "1",
                            DbType        = DbType.String
                        }
                    };
                    #endregion

                    db.Database.ExecuteSqlCommand("Insert_CN_DieuChinh_HopDong  @IDDC, @IDHD, @NgayDieuChinh, @GiaTriDieuChinh, @ChenhLech, @SoNgayGiaHanTienDo, @LyDoDieuChinh, @NguoiTao,@NgayTao, @NguoiCapNhat, @NgayCapNhat, @DotDieuChinh, @NgayHetHanDC, @IDLoaiDieuChinh, @FlagCreate", AParameter);
                    #region luu lich su
                    // luu lich su
                    HT_LichSuHoatDong ls = new HT_LichSuHoatDong(
                        ChucNang
                        , "CREATE"
                        , DateTime.Now, Session["username"]?.ToString()
                        , $" Thêm mới điều chỉnh - Số HD {hopDong.SoHopDong} - lần điều chỉnh {cN_DieuChinh.DotDieuChinh}");
                    db.HT_LichSuHoatDong.Add(ls);
                    db.SaveChanges();
                    #endregion
                    return(RedirectToAction("Index"));
                }
                ViewBag.IDLoaiDieuChinh = DanhSachLoaiDieuChinh(cN_DieuChinh.IDLoaiDieuChinh);
                ViewBag.IDHD            = DanhSachHopDongDieuChinh(cN_DieuChinh.IDHD);
                return(View(cN_DieuChinh));
            }
            catch (Exception ex)
            {
                string cauBaoLoi = "Không ghi được dữ liệu.<br/>Lý do: " + ex.Message;
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest, cauBaoLoi));
            }
        }