public bool ThoaiDuyetListTheoID(List <int> listID) { bool kq = true; Entities entities = ContextFactory.GetInstance(); try { using (TransactionScope trans = new TransactionScope()) { foreach (int id in listID) { HT_NHNSD obj = new HT_NHNSD(); obj = entities.HT_NHNSD.FirstOrDefault(e => e.ID == id); obj.TTHAI_NVU = BusinessConstant.TrangThaiNghiepVu.THOAI_DUYET.layGiaTri(); entities.SaveChanges(); } trans.Complete(); } } catch (System.Exception ex) { kq = false; LLogging.WriteLog(ex.TargetSite.Name, LLogging.LogType.ERR, ex); } finally { entities = null; } return(kq); }
public HT_NHNSD Sua(HT_NHNSD obj) { HT_NHNSD kq = null; Entities entities = ContextFactory.GetInstance(); EntityKey key = null; object original = null; try { key = entities.CreateEntityKey(ENTITY_SET_NAME, obj); if (entities.TryGetObjectByKey(key, out original)) { entities.ApplyCurrentValues(key.EntitySetName, obj); } entities.SaveChanges(); kq = obj; } catch (System.Exception ex) { kq = null; LLogging.WriteLog(ex.TargetSite.Name, LLogging.LogType.ERR, ex); throw ex; } finally { entities = null; } return(kq); }
public bool XoaListTheoID(List <int> listID) { bool kq = true; Entities entities = ContextFactory.GetInstance(); try { using (TransactionScope trans = new TransactionScope()) { foreach (int id in listID) { HT_NHNSD obj = new HT_NHNSD(); obj = entities.HT_NHNSD.FirstOrDefault(e => e.ID == id); entities.DeleteObject(obj); entities.SaveChanges(); } trans.Complete(); } } catch (System.Exception ex) { kq = false; LLogging.WriteLog(ex.TargetSite.Name, LLogging.LogType.ERR, ex); } finally { entities = null; } return(kq); }
public void OnSave(ref string msg, HT_NHNSD obj) { try { if (Validate(ref msg, obj)) { QuanTriHeThongProcess process = new QuanTriHeThongProcess(); List <string> lstStrIdNSD = new List <string>(); //(from row in dt.AsEnumerable() select row.Field<string>("ID")).Distinct().ToList(); List <int> lstIdNSD = lstStrIdNSD.Select(i => i.StringToInt32()).ToList(); ApplicationConstant.ResponseStatus ret = ApplicationConstant.ResponseStatus.KHONG_THANH_CONG; var lstTruyCap = new List <HT_TRUY_CAP>(); string responseMessage = null; // Nếu là thêm mới if (obj.ID == 0) { ret = process.ThemNHNSD(ref obj, lstIdNSD, lstTruyCap, ref responseMessage); afterAddNew(ref msg, ret, obj, responseMessage); } else { ret = process.SuaNHNSD(ref obj, lstIdNSD, lstTruyCap, ref responseMessage); afterModify(ref msg, ret, obj, responseMessage); } } } catch (Exception ex) { msg = LanguageNode.GetValueMessageLanguage(ex.Message); LLogging.WriteLog(System.Reflection.MethodInfo.GetCurrentMethod().ToString(), LLogging.LogType.ERR, ex); } }
public HT_NHNSD GetByMa(string ma) { HT_NHNSD kq = null; Entities entities = ContextFactory.GetInstance(); try { kq = entities.HT_NHNSD.FirstOrDefault(e => e.MA_NHNSD == ma); return(kq); } catch (System.Exception ex) { kq = null; LLogging.WriteLog(ex.TargetSite.Name, LLogging.LogType.ERR, ex); } finally { entities = null; } return(kq); }
public bool Xoa(HT_NHNSD obj) { bool kq = true; Entities entities = ContextFactory.GetInstance(); try { entities.HT_NHNSD.Attach(obj); entities.HT_NHNSD.DeleteObject(obj); entities.SaveChanges(); } catch (System.Exception ex) { kq = false; LLogging.WriteLog(ex.TargetSite.Name, LLogging.LogType.ERR, ex); } finally { entities = null; } return(kq); }
private bool Validate(ref string msg, HT_NHNSD obj) { if (obj.MA_DVI_QLY.IsNullOrEmpty()) { msg = "Chưa chọn Đơn vị"; return(false); } if (obj.MA_NHNSD.IsNullOrEmptyOrSpace()) { msg = "Chưa nhập Mã"; return(false); } if (obj.TEN_NHNSD.IsNullOrEmptyOrSpace()) { msg = "Chưa nhập Tên"; return(false); } return(true); }
public HT_NHNSD Them(HT_NHNSD obj) { HT_NHNSD kq = null; Entities entities = ContextFactory.GetInstance(); try { entities.HT_NHNSD.AddObject(obj); entities.SaveChanges(); kq = obj; } catch (System.Exception ex) { kq = null; LLogging.WriteLog(ex.TargetSite.Name, LLogging.LogType.ERR, ex); throw ex; } finally { entities = null; } return(kq); }
/// <summary> /// Sau khi sửa /// </summary> /// <param name="ret"></param> private void afterModify(ApplicationConstant.ResponseStatus ret, HT_NHNSD obj, string responseMessage) { if (ret == ApplicationConstant.ResponseStatus.THANH_CONG) { LMessage.ShowMessage("M.DungChung.CapNhatThanhCong", LMessage.MessageBoxType.Information); id = obj.ID; TthaiNvu = obj.TTHAI_NVU; lblTrangThai.Content = BusinessConstant.layNgonNguSuDung(obj.TTHAI_BGHI); txtTrangThai.Text = BusinessConstant.layNgonNguSuDung(obj.TTHAI_BGHI); raddtNgayNhap.Value = LDateTime.StringToDate(obj.NGAY_NHAP, "yyyyMMdd"); txtNguoiLap.Text = obj.NGUOI_NHAP; raddtNgayCNhat.Value = LDateTime.StringToDate(obj.NGAY_CNHAT, "yyyyMMdd"); txtNguoiCapNhat.Text = obj.NGUOI_CNHAT; CommonFunction.RefreshButton(Toolbar, DatabaseConstant.Action.XEM, tthaiNvu, mnuMain, DatabaseConstant.Function.HT_NHNSD); formCase = "XEM"; HideControl(); } else { LMessage.ShowMessage(responseMessage, LMessage.MessageBoxType.Error); } // Yêu cầu Unlock bản ghi cần sửa UtilitiesProcess process = new UtilitiesProcess(); List <int> listLockId = new List <int>(); listLockId.Add(id); bool retUnlockData = process.UnlockData(DatabaseConstant.Module.QTHT, DatabaseConstant.Function.HT_NHNSD, DatabaseConstant.Table.HT_NHNSD, DatabaseConstant.Action.SUA, listLockId); }
/// <summary> /// Sau khi thêm mới /// </summary> /// <param name="ret"></param> private void afterAddNew(ApplicationConstant.ResponseStatus ret, HT_NHNSD obj, string responseMessage) { if (ret == ApplicationConstant.ResponseStatus.THANH_CONG) { LMessage.ShowMessage("M.DungChung.ThemThanhCong", LMessage.MessageBoxType.Information); if (cbMultiAdd.IsChecked == true) { ResetForm(); } else if (!DatabaseConstant.CLOSE_DETAIL_FORM) { id = obj.ID; TthaiNvu = obj.TTHAI_NVU; lblLabelTrangThai.Content = BusinessConstant.layNgonNguSuDung(obj.TTHAI_BGHI); txtTrangThai.Text = BusinessConstant.layNgonNguSuDung(obj.TTHAI_BGHI); raddtNgayNhap.Value = LDateTime.StringToDate(obj.NGAY_NHAP, "yyyyMMdd"); txtNguoiLap.Text = obj.NGUOI_NHAP; raddtNgayCNhat.Value = LDateTime.StringToDate(obj.NGAY_CNHAT, "yyyyMMdd"); txtNguoiCapNhat.Text = obj.NGUOI_CNHAT; CommonFunction.RefreshButton(Toolbar, DatabaseConstant.Action.XEM, tthaiNvu, mnuMain, DatabaseConstant.Function.HT_NHNSD); formCase = "XEM"; HideControl(); } else { onClose(); } } else { LMessage.ShowMessage(responseMessage, LMessage.MessageBoxType.Error); } }
public void getObject(DatabaseConstant.Action action) { Mouse.OverrideCursor = Cursors.Wait; try { if (obj == null) { obj = new HT_NHNSD(); } //obj.MA_DVI_QLY = txtMaDonVi.Text; obj.MA_DVI_QLY = lstSourceDonVi.ElementAt(cmbDonVi.SelectedIndex).KeywordStrings.First(); obj.MA_DVI_TAO = ClientInformation.MaDonVi; obj.MA_NHNSD = txtMaNhom.Text; obj.MO_TA = txtMoTa.Text; if (chkHoatDong.IsChecked == true) { obj.HAN_CHE_TRUY_CAP = BusinessConstant.CoKhong.CO.layGiaTri(); } else { obj.HAN_CHE_TRUY_CAP = BusinessConstant.CoKhong.KHONG.layGiaTri(); } obj.NGAY_CNHAT = (DateTime.Today).ToString("yyyyMMdd"); if (obj.ID == 0) { obj.NGAY_NHAP = (DateTime.Today).ToString("yyyyMMdd"); } obj.NGUOI_CNHAT = ClientInformation.TenDangNhap; if (obj.ID == 0) { obj.NGUOI_NHAP = ClientInformation.TenDangNhap; } obj.TEN_NHNSD = txtTenNhom.Text; string strTTNV = string.Empty; if (obj.ID == 0) { obj.NGUON_TAO_DL = "NSD"; obj.PVI_KTHAC = "K"; strTTNV = obj.TTHAI_NVU; } obj.TTHAI_NVU = CommonFunction.LayTrangThaiBanGhi(action, BusinessConstant.layTrangThaiNghiepVu(strTTNV)); obj.TTHAI_BGHI = BusinessConstant.TrangThaiBanGhi.SU_DUNG.layGiaTri(); // Luôn là đã duyệt (???) obj.TTHAI_NVU = BusinessConstant.TrangThaiNghiepVu.DA_DUYET.layGiaTri(); //Lấy thông tin hạn chế truy cập MAC or IP lstTruyCap = new List <HT_TRUY_CAP>(); foreach (DataRow dr in dtTruyCap.Rows) { if (!dr["STT"].ToString().IsNullOrEmptyOrSpace()) { HT_TRUY_CAP objTruyCap = new HT_TRUY_CAP(); objTruyCap.ID_DTUONG = obj.ID; objTruyCap.MA_DTUONG = obj.MA_NHNSD; objTruyCap.LOAI_DTUONG = BusinessConstant.LoaiDoiTuong.NHOM_NGUOI_SDUNG.layGiaTri(); if (Convert.ToBoolean(dr["KICH_HOAT"]) == true) { objTruyCap.KICH_HOAT = BusinessConstant.CoKhong.CO.layGiaTri(); } else { objTruyCap.KICH_HOAT = BusinessConstant.CoKhong.KHONG.layGiaTri(); } objTruyCap.DIA_CHI = dr["DIA_CHI"].ToString().ToUpper(); objTruyCap.LOAI_DIA_CHI = dr["LOAI_DIA_CHI"].ToString(); lstTruyCap.Add(objTruyCap); } } } catch (System.Exception ex) { CommonFunction.ThongBaoLoi(ex); LLogging.WriteLog(System.Reflection.MethodInfo.GetCurrentMethod().ToString(), LLogging.LogType.ERR, ex); } Mouse.OverrideCursor = Cursors.Arrow; }
/// <summary> /// Sau khi sửa /// </summary> /// <param name="ret"></param> private void afterModify(ref string msg, ApplicationConstant.ResponseStatus ret, HT_NHNSD obj, string responseMessage) { if (ret == ApplicationConstant.ResponseStatus.THANH_CONG) { msg = "S#" + LanguageNode.GetValueMessageLanguage("M.DungChung.CapNhatThanhCong"); // Bind lại giao diện } else { msg = "E#" + LanguageNode.GetValueMessageLanguage(responseMessage); } // Yêu cầu Unlock bản ghi cần sửa UtilitiesProcess process = new UtilitiesProcess(); List <int> listLockId = new List <int>(); listLockId.Add(obj.ID); bool retUnlockData = process.UnlockData(DatabaseConstant.Module.QTHT, DatabaseConstant.Function.HT_NHNSD, DatabaseConstant.Table.HT_NHNSD, DatabaseConstant.Action.SUA, listLockId); }
/// <summary> /// Sau khi thêm mới /// </summary> /// <param name="ret"></param> private void afterAddNew(ref string msg, ApplicationConstant.ResponseStatus ret, HT_NHNSD obj, string responseMessage, bool multiAdd = false) { if (ret == ApplicationConstant.ResponseStatus.THANH_CONG) { msg = "S#" + LanguageNode.GetValueMessageLanguage("M.DungChung.ThemThanhCong"); if (multiAdd) { } else if (!DatabaseConstant.CLOSE_DETAIL_FORM) { } else { } } else { msg = "E#" + LanguageNode.GetValueMessageLanguage(responseMessage); } }