public static Result CheckTenSieuAmExist(string loaiSieuAmGUID, string tenSieuAm) { Result result = new Result(); MMOverride db = null; try { db = new MMOverride(); LoaiSieuAm loaiSieuAm = null; if (loaiSieuAmGUID == null || loaiSieuAmGUID == string.Empty) { loaiSieuAm = db.LoaiSieuAms.FirstOrDefault <LoaiSieuAm>(s => s.TenSieuAm.ToLower() == tenSieuAm.ToLower()); } else { loaiSieuAm = db.LoaiSieuAms.FirstOrDefault <LoaiSieuAm>(s => s.TenSieuAm.ToLower() == tenSieuAm.ToLower() && s.LoaiSieuAmGUID.ToString() != loaiSieuAmGUID); } if (loaiSieuAm == null) { result.Error.Code = ErrorCode.NOT_EXIST; } else { result.Error.Code = ErrorCode.EXIST; } } catch (System.Data.SqlClient.SqlException se) { result.Error.Code = (se.Message.IndexOf("Timeout expired") >= 0) ? ErrorCode.SQL_QUERY_TIMEOUT : ErrorCode.INVALID_SQL_STATEMENT; result.Error.Description = se.ToString(); } catch (Exception e) { result.Error.Code = ErrorCode.UNKNOWN_ERROR; result.Error.Description = e.ToString(); } finally { if (db != null) { db.Dispose(); db = null; } } return(result); }
private void OnEdit() { _isNew = false; if (_drLoaiSieuAm == null) { MsgBox.Show(Application.ProductName, "Vui lòng chọn loại siêu âm cần cập nhật.", IconType.Information); return; } if (!CheckInfo()) { return; } LoaiSieuAm loaiSieuAm = new LoaiSieuAm(); loaiSieuAm.LoaiSieuAmGUID = Guid.Parse(_drLoaiSieuAm["LoaiSieuAmGUID"].ToString()); loaiSieuAm.UpdatedBy = Guid.Parse(Global.UserGUID); loaiSieuAm.UpdatedDate = DateTime.Now; loaiSieuAm.TenSieuAm = txtTenSieuAm.Text.Trim(); loaiSieuAm.ThuTu = (int)numThuTu.Value; loaiSieuAm.InTrang2 = chkInTrang2.Checked; loaiSieuAm.Status = (byte)Status.Actived; List <MauBaoCao> mauBaoCaoList = new List <MauBaoCao>(); byte[] buff = null; _textControl1.Save(out buff, TXTextControl.BinaryStreamType.MSWord); MauBaoCao mauBaoCao = new MauBaoCao(); mauBaoCao.Template = new System.Data.Linq.Binary(buff); mauBaoCao.DoiTuong = (int)DoiTuong.Chung; if (raNamNu.Checked) { if (chkNam.Checked) { mauBaoCao.DoiTuong = (int)DoiTuong.Nam; mauBaoCaoList.Add(mauBaoCao); } if (chkNu.Checked) { buff = null; _textControl2.Save(out buff, TXTextControl.BinaryStreamType.MSWord); mauBaoCao = new MauBaoCao(); mauBaoCao.Template = new System.Data.Linq.Binary(buff); mauBaoCao.DoiTuong = (int)DoiTuong.Nu; mauBaoCaoList.Add(mauBaoCao); } } else { mauBaoCaoList.Add(mauBaoCao); } Result result = SieuAmBus.InsertLoaiSieuAm(loaiSieuAm, mauBaoCaoList); if (result.IsOK) { _flag = true; OnDisplayLoaiSieuList(); _flag = false; SetCurrentLoaiSieuAm(loaiSieuAm.LoaiSieuAmGUID.ToString()); } else { MsgBox.Show(Application.ProductName, result.GetErrorAsString("SieuAmBus.InsertLoaiSieuAm"), IconType.Error); Utility.WriteToTraceLog(result.GetErrorAsString("SieuAmBus.InsertLoaiSieuAm")); } }
public static Result InsertLoaiSieuAm(LoaiSieuAm loaiSieuAm, List <MauBaoCao> mauBaoCaoList) { Result result = new Result(); MMOverride db = null; try { db = new MMOverride(); string desc = string.Empty; using (TransactionScope t = new TransactionScope(TransactionScopeOption.RequiresNew)) { //Insert if (loaiSieuAm.LoaiSieuAmGUID == null || loaiSieuAm.LoaiSieuAmGUID == Guid.Empty) { loaiSieuAm.LoaiSieuAmGUID = Guid.NewGuid(); db.LoaiSieuAms.InsertOnSubmit(loaiSieuAm); db.SubmitChanges(); foreach (var mauBaoCao in mauBaoCaoList) { mauBaoCao.MauBaoCaoGUID = Guid.NewGuid(); mauBaoCao.LoaiSieuAmGUID = loaiSieuAm.LoaiSieuAmGUID; mauBaoCao.CreatedDate = DateTime.Now; mauBaoCao.CreatedBy = Guid.Parse(Global.UserGUID); db.MauBaoCaos.InsertOnSubmit(mauBaoCao); } //Tracking desc += string.Format("- GUID: '{0}', Tên siêu âm: '{1}', Thứ tự: '{2}', In trang 2: '{3}'", loaiSieuAm.LoaiSieuAmGUID.ToString(), loaiSieuAm.TenSieuAm, loaiSieuAm.ThuTu, loaiSieuAm.InTrang2); Tracking tk = new Tracking(); tk.TrackingGUID = Guid.NewGuid(); tk.TrackingDate = DateTime.Now; tk.DocStaffGUID = Guid.Parse(Global.UserGUID); tk.ActionType = (byte)ActionType.Add; tk.Action = "Thêm thông tin loại siêu âm"; tk.Description = desc; tk.TrackingType = (byte)TrackingType.None; tk.ComputerName = Utility.GetDNSHostName(); db.Trackings.InsertOnSubmit(tk); db.SubmitChanges(); } else //Update { LoaiSieuAm lsa = db.LoaiSieuAms.SingleOrDefault <LoaiSieuAm>(s => s.LoaiSieuAmGUID.ToString() == loaiSieuAm.LoaiSieuAmGUID.ToString()); if (lsa != null) { lsa.TenSieuAm = loaiSieuAm.TenSieuAm; lsa.ThuTu = loaiSieuAm.ThuTu; lsa.InTrang2 = loaiSieuAm.InTrang2; lsa.Path = loaiSieuAm.Path; lsa.UpdatedDate = loaiSieuAm.UpdatedDate; lsa.UpdatedBy = loaiSieuAm.UpdatedBy; lsa.Status = loaiSieuAm.Status; //Delete mẫu báo cáo var mbcs = lsa.MauBaoCaos; foreach (var mbc in mbcs) { mbc.UpdatedBy = Guid.Parse(Global.UserGUID); mbc.UpdatedDate = DateTime.Now; mbc.Status = (byte)Status.Deactived; } //Update mẫu báo cáo foreach (var mbc in mauBaoCaoList) { MauBaoCao mauBaoCao = lsa.MauBaoCaos.Where(m => m.DoiTuong == mbc.DoiTuong).FirstOrDefault(); if (mauBaoCao == null) { mbc.MauBaoCaoGUID = Guid.NewGuid(); mbc.LoaiSieuAmGUID = loaiSieuAm.LoaiSieuAmGUID; mbc.CreatedDate = DateTime.Now; mbc.CreatedBy = Guid.Parse(Global.UserGUID); db.MauBaoCaos.InsertOnSubmit(mbc); } else { mauBaoCao.UpdatedBy = Guid.Parse(Global.UserGUID); mauBaoCao.UpdatedDate = DateTime.Now; mauBaoCao.Template = mbc.Template; mauBaoCao.Status = (byte)Status.Actived; } } //Tracking desc += string.Format("- GUID: '{0}', Tên siêu âm: '{1}', Thứ tự: '{2}', In trang 2: '{3}'", lsa.LoaiSieuAmGUID.ToString(), lsa.TenSieuAm, lsa.ThuTu, lsa.InTrang2); Tracking tk = new Tracking(); tk.TrackingGUID = Guid.NewGuid(); tk.TrackingDate = DateTime.Now; tk.DocStaffGUID = Guid.Parse(Global.UserGUID); tk.ActionType = (byte)ActionType.Edit; tk.Action = "Sửa thông tin loại siêu âm"; tk.Description = desc; tk.TrackingType = (byte)TrackingType.None; tk.ComputerName = Utility.GetDNSHostName(); db.Trackings.InsertOnSubmit(tk); db.SubmitChanges(); } } t.Complete(); } } catch (System.Data.SqlClient.SqlException se) { result.Error.Code = (se.Message.IndexOf("Timeout expired") >= 0) ? ErrorCode.SQL_QUERY_TIMEOUT : ErrorCode.INVALID_SQL_STATEMENT; result.Error.Description = se.ToString(); } catch (Exception e) { result.Error.Code = ErrorCode.UNKNOWN_ERROR; result.Error.Description = e.ToString(); } finally { if (db != null) { db.Dispose(); db = null; } } return(result); }
public static Result DeleteLoaiSieuAm(List <string> keys) { Result result = new Result(); MMOverride db = null; try { db = new MMOverride(); using (TransactionScope t = new TransactionScope(TransactionScopeOption.RequiresNew)) { string desc = string.Empty; foreach (string key in keys) { LoaiSieuAm l = db.LoaiSieuAms.SingleOrDefault <LoaiSieuAm>(ss => ss.LoaiSieuAmGUID.ToString() == key); if (l != null) { l.DeletedDate = DateTime.Now; l.DeletedBy = Guid.Parse(Global.UserGUID); l.Status = (byte)Status.Deactived; desc += string.Format("- GUID: '{0}', Tên siêu âm: '{1}', Thứ tự: '{2}', In trang 2: '{3}'\n", l.LoaiSieuAmGUID.ToString(), l.TenSieuAm, l.ThuTu, l.InTrang2); } } //Tracking desc = desc.Substring(0, desc.Length - 1); Tracking tk = new Tracking(); tk.TrackingGUID = Guid.NewGuid(); tk.TrackingDate = DateTime.Now; tk.DocStaffGUID = Guid.Parse(Global.UserGUID); tk.ActionType = (byte)ActionType.Delete; tk.Action = "Xóa thông tin loại siêu âm"; tk.Description = desc; tk.TrackingType = (byte)TrackingType.None; tk.ComputerName = Utility.GetDNSHostName(); db.Trackings.InsertOnSubmit(tk); db.SubmitChanges(); t.Complete(); } } catch (System.Data.SqlClient.SqlException se) { result.Error.Code = (se.Message.IndexOf("Timeout expired") >= 0) ? ErrorCode.SQL_QUERY_TIMEOUT : ErrorCode.INVALID_SQL_STATEMENT; result.Error.Description = se.ToString(); } catch (Exception e) { result.Error.Code = ErrorCode.UNKNOWN_ERROR; result.Error.Description = e.ToString(); } finally { if (db != null) { db.Dispose(); db = null; } } return(result); }