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 Index() { //Session["idThucTe"] = 13; if (Session["idThucTe"] != null) { COCAUGIA_THUCTE thucte = _NhapCoCauGiaThucTeProvider._CoCauGiaThucTe.GetCoCauThucTeByID(Convert.ToInt32(Session["idThucTe"])); ViewData["thucte"] = thucte; } return(View()); }
public ActionResult AddThucTeChiTiet(CoCauThucTeChiTietItem item) { COCAUGIA_THUCTE thucte = _NhapCoCauGiaThucTeProvider._CoCauGiaThucTe.GetCoCauThucTeByID(Convert.ToInt64(Session["idThucTe"])); COCAUGIA_LOAI loai = _NhapCoCauGiaThucTeProvider._CoCauGiaLoai.GetCoCauGiaLoaiByID(item.IDLoai); COCAUGIA_THUCTE_CT thucte_ct = new COCAUGIA_THUCTE_CT { THUCTE = thucte, LOAI = loai, MA_COCAU = item.MaCoCau, TEN_COCAU_OLD = item.TenCoCauOld, DONGIA_OLD = item.DonGiaOld, SO_LUONG_OLD = item.SoLuongOld, TEN_COCAU_NEW = item.TenCoCauNew, DONGIA_NEW = item.DonGiaNew, SO_LUONG_NEW = item.SoLuongNew }; _NhapCoCauGiaThucTeProvider._CoCauGiaThucTeChiTiet.AddCoCauThucTeChiTiet(thucte_ct); return(GridViewThucTeChiTietByIDThucTe(Convert.ToInt64(Session["idThucTe"]))); }
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)); }