public ActionResult UpdateDichVu(COCAUGIA_DICHVU21 model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var data = _ICOCAUGIA_DICHVU21Service.Getbykey(model.ID);
                    if (data != null)
                    {
                        data.TEN_DICHVU21 = model.TEN_DICHVU21;

                        _ICOCAUGIA_DICHVU21Service.Save(data);
                        _ICOCAUGIA_DICHVU21Service.CommitChanges();

                        return(_GridViewDanhSachDichVuPartial());
                    }
                    else
                    {
                        ViewData["EditError"] = "Nhóm dịch vụ không tồn tại hoặc đã bị xoá.";
                    }
                }
                else
                {
                    ViewData["EditError"] = "Dữ liệu bạn vừa nhập không chính xác.";
                }
            }
            catch (Exception e)
            {
                ViewData["EditError"] = "Đã xảy ra lỗi vui lòng thử lại sau.";
                log.ErrorFormat("Update - message: {0}{1} - {2}", e.Message, Environment.NewLine, e.StackTrace);
            }
            return(_GridViewDanhSachDichVuPartial());
        }
Exemplo n.º 2
0
        public COCAUGIA_THUCTE AddCoCauThucTe(string maCskcb, string maThe, DateTime ngayVao, DateTime ngayRa, string maDichVu)
        {
            var entity = GetCoCauThucTe(maCskcb, maThe, ngayVao, ngayRa, maDichVu);

            if (entity == null)
            {
                COCAUGIA_DICHVU21 dichvu21 = _ICOCAUGIA_DICHVU21Service.Query.Where(x => x.MA_DICHVU21.EndsWith(maDichVu.Right(4))).FirstOrDefault();
                DM_COSOKCB        cskcb    = _IDMCOSOKCBService.Query.Where(x => x.MA.Equals(maCskcb)).FirstOrDefault();

                COCAUGIA_THUCTE thucte = new COCAUGIA_THUCTE
                {
                    DICHVU21 = dichvu21,
                    COSOKCB  = cskcb,
                    MA_THE   = maThe,
                    NGAY_VAO = ngayVao,
                    NGAY_RA  = ngayRa
                };
                var result = _ICOCAUGIA_THUCTEService.Save(thucte);
                _ICOCAUGIA_THUCTEService.CommitChanges();
                return(result);
            }
            else
            {
                return(null);
            }
        }
        public ActionResult _GridViewChiTietDichVuFilter(string maNhomdv, string tenNhomdv)
        {
            try
            {
                var data = _ICOCAUGIA_DICHVU21Service.Query.Where(item => item.MA_DICHVU21 == maNhomdv);

                if (data.Count <COCAUGIA_DICHVU21>() == 0)
                {
                    var newData = new COCAUGIA_DICHVU21();

                    newData.MA_DICHVU21  = maNhomdv;
                    newData.TEN_DICHVU21 = tenNhomdv;
                    newData.TRANGTHAI    = 0;

                    _ICOCAUGIA_DICHVU21Service.Save(newData);
                    _ICOCAUGIA_DICHVU21Service.CommitChanges();
                }

                Session["_GridViewChiTietDichVuPartial"] = _ICOCAUGIA_CHITIETService.getByFilter(maNhomdv);
                return(PartialView("_GridViewChiTietDichVuPartial", Session["_GridViewChiTietDichVuPartial"]));
            }
            catch (Exception e)
            {
                log.ErrorFormat("_GridViewChiTietDichVuPartial - message: {0}{1} - {2}", e.Message, Environment.NewLine, e.StackTrace);
            }
            return(PartialView("_GridViewChiTietDichVuPartial", new List <COCAUGIA_CHITIET>().AsQueryable()));
        }
        public ActionResult BatchEditingUpdateModel(MVCxGridViewBatchUpdateValues <COCAUGIA_THUCTE_CT, int> updateValues)
        {
            /*
             * foreach (var item in updateValues.Update)
             * {
             *  var data = new COCAUGIA_PHATSINH();
             *
             *  data.CHITIET_ID = Convert.ToInt32(item.ID);
             *  data.COSOKCB_ID = Convert.ToInt32(Session["cskcbId"]);
             *  data.SP_HSBA = Convert.ToString(Session["spHsba"]);
             *  data.DONGIA_PS = item.DONGIA_CC;
             *  data.SOLUONG_PS = item.SOLUONG_CC;
             *  data.THANHTIEN_PS = data.SOLUONG_PS * data.DONGIA_PS;
             *
             *  _ICOCAUGIA_PHATSINHService.Save(data);
             * }*/

            long?idThucTe = Session["idThucTe"] as long?;

            // Lấy danh sách các COCAUGIA_THUCTE_CT trong session (được clone từ COCAUGIA_CHITIET)
            var thucTeCts = Session["_GridViewChiTietDichVuPartial"] as List <COCAUGIA_THUCTE_CT>;

            // Tạo dữ liệu mới
            if (idThucTe == null)
            {
                long?idDichVu = Session["idDichVu"] as long?;
                if (idDichVu != null)
                {
                    // Lấy dịch vụ
                    COCAUGIA_DICHVU21 dichvu21 = _ICOCAUGIA_DICHVU21Service.getById(idDichVu.Value).FirstOrDefault();

                    // Lấy cơ sở KCB
                    DM_COSOKCB cskcb = _IDMCOSOKCBService.GetByMa(Session["maCskcb"] as string).FirstOrDefault();

                    // Tạo một bản ghi vào COCAUGIA_THUCTE
                    COCAUGIA_THUCTE thucTe = new COCAUGIA_THUCTE
                    {
                        DICHVU21   = dichvu21,
                        COSOKCB    = cskcb,
                        MA_THE     = Session["maThe"] as string,
                        NGAY_VAO   = DateTime.Parse(Session["ngayVao"] as string),
                        NGAY_RA    = DateTime.Parse(Session["ngayRa"] as string),
                        THUCTE_CTs = new List <COCAUGIA_THUCTE_CT>()
                    };

                    // Ghi đè các phần tử đã được update trong form
                    foreach (var item in updateValues.Update)
                    {
                        int index = thucTeCts.FindIndex(x => x.ID == item.ID);
                        thucTeCts[index].SO_LUONG_NEW  = item.SO_LUONG_NEW;
                        thucTeCts[index].DONGIA_NEW    = item.DONGIA_NEW;
                        thucTeCts[index].TEN_COCAU_NEW = item.TEN_COCAU_NEW;
                    }

                    // Reset lại id và gán thực tế để insert vào DB
                    foreach (var item in thucTeCts)
                    {
                        item.ID = 0;
                        thucTe.THUCTE_CTs.Add(item);
                        item.THUCTE = thucTe;
                    }

                    _ICOCAUGIA_THUCTEService.Save(thucTe);
                    _ICOCAUGIA_THUCTEService.CommitChanges();
                }
            }
            else // Update lại dữ liệu
            {
                foreach (var item in updateValues.Update)
                {
                    int index = thucTeCts.FindIndex(x => x.ID == item.ID);
                    thucTeCts[index].SO_LUONG_NEW  = item.SO_LUONG_NEW;
                    thucTeCts[index].DONGIA_NEW    = item.DONGIA_NEW;
                    thucTeCts[index].TEN_COCAU_NEW = item.TEN_COCAU_NEW;

                    _ICOCAUGIA_THUCTE_CTService.Save(thucTeCts[index]);
                }

                _ICOCAUGIA_THUCTE_CTService.CommitChanges();
            }

            return(_GridViewChiTietDichVuFilter(
                       Session["maCskcb"] as string,
                       Session["maThe"] as string,
                       Session["ngayVao"] as string,
                       Session["ngayRa"] as string,
                       Session["maDichVu"] as string));
        }