public static Result UpdateXetNghiem(XetNghiem_CellDyn3200 xetNghiem) { Result result = new Result(); MMOverride db = null; try { db = new MMOverride(); string desc = string.Empty; using (TransactionScope t = new TransactionScope(TransactionScopeOption.RequiresNew)) { XetNghiem_CellDyn3200 xn = db.XetNghiem_CellDyn3200s.SingleOrDefault <XetNghiem_CellDyn3200>(x => x.XetNghiemGUID == xetNghiem.XetNghiemGUID); if (xn != null) { xn.UpdatedDate = xetNghiem.UpdatedDate; xn.UpdatedBy = xetNghiem.UpdatedBy; xn.FromValue = xetNghiem.FromValue; xn.ToValue = xetNghiem.ToValue; xn.FromPercent = xetNghiem.FromPercent; xn.ToPercent = xetNghiem.ToPercent; xn.Status = (byte)Status.Actived; desc += string.Format("- GUID: '{0}', Tên xét nghiệm: '{1}'", xn.XetNghiemGUID.ToString(), xn.FullName); //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.Edit; tk.Action = "Cập nhật xét nghiệm CellDyn3200"; 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); }
private void OnSaveInfo() { try { XetNghiem_CellDyn3200 xetNghiem = new XetNghiem_CellDyn3200(); xetNghiem.XetNghiemGUID = Guid.Parse(_row["XetNghiemGUID"].ToString()); xetNghiem.UpdatedDate = DateTime.Now; xetNghiem.UpdatedBy = Guid.Parse(Global.UserGUID); MethodInvoker method = delegate { xetNghiem.TenXetNghiem = _tenXetNghiem; xetNghiem.FullName = _tenXetNghiem; if (chkFromValue_Normal.Checked) { xetNghiem.FromValue = (double)numFromValue_Normal.Value; } if (chkToValue_Normal.Checked) { xetNghiem.ToValue = (double)numToValue_Normal.Value; } //if (chkFromValue_NormalPercent.Enabled && chkFromValue_NormalPercent.Checked) // xetNghiem.FromPercent = (double)numFromValue_NormalPercent.Value; //if (chkToValue_NormalPercent.Enabled && chkToValue_NormalPercent.Checked) // xetNghiem.ToPercent = (double)numToValue_NormalPercent.Value; Result result = XetNghiem_CellDyn3200Bus.UpdateXetNghiem(xetNghiem); if (!result.IsOK) { MsgBox.Show(Application.ProductName, result.GetErrorAsString("XetNghiem_CellDyn3200Bus.UpdateXetNghiem"), IconType.Error); Utility.WriteToTraceLog(result.GetErrorAsString("XetNghiem_CellDyn3200Bus.UpdateXetNghiem")); } else { DataRow row = GetDataRow(xetNghiem.XetNghiemGUID.ToString()); if (row != null) { if (chkFromValue_Normal.Checked) { row["FromValue"] = xetNghiem.FromValue.Value; } else { row["FromValue"] = DBNull.Value; } if (chkToValue_Normal.Checked) { row["ToValue"] = xetNghiem.ToValue.Value; } else { row["ToValue"] = DBNull.Value; } //if (chkFromValue_NormalPercent.Enabled && chkFromValue_NormalPercent.Checked) // row["FromPercent"] = xetNghiem.FromPercent.Value; //else // row["FromPercent"] = DBNull.Value; //if (chkToValue_NormalPercent.Enabled && chkToValue_NormalPercent.Checked) // row["ToPercent"] = xetNghiem.ToPercent.Value; //else // row["ToPercent"] = DBNull.Value; MsgBox.Show(Application.ProductName, "Lưu chỉ số xét nghiệm thành công.", IconType.Information); } } }; if (InvokeRequired) { BeginInvoke(method); } else { method.Invoke(); } } catch (Exception e) { MsgBox.Show(Application.ProductName, e.Message, IconType.Error); Utility.WriteToTraceLog(e.Message); } }
public static Result GetChiTietKetQuaXetNghiem(string ketQuaXetNghiemGUID) { Result result = new Result(); try { string query = string.Format("SELECT CAST(0 AS Bit) AS Checked, *, CAST('' AS nvarchar(50)) AS BinhThuong FROM ChiTietKetQuaXetNghiem_CellDyn3200View WITH(NOLOCK) WHERE KQXN_CellDyn3200GUID = '{0}' AND Status = {1} ORDER BY GroupID, [Order]", ketQuaXetNghiemGUID, (byte)Status.Actived); result = ExcuteQuery(query); if (!result.IsOK) { return(result); } MMOverride db = new MMOverride(); DataTable dt = result.QueryResult as DataTable; foreach (DataRow row in dt.Rows) { double?fromValue = null; double?toValue = null; //double? fromPercent = null; //double? toPercent = null; string donVi = string.Empty; if ((row["FromValue2"] != null && row["FromValue2"] != DBNull.Value) || (row["ToValue2"] != null && row["ToValue2"] != DBNull.Value)) { if (row["FromValue2"] != null && row["FromValue2"] != DBNull.Value) { fromValue = Convert.ToDouble(row["FromValue2"]); } if (row["ToValue2"] != null && row["ToValue2"] != DBNull.Value) { toValue = Convert.ToDouble(row["ToValue2"]); } //if (row["FromPercent2"] != null && row["FromPercent2"] != DBNull.Value) // fromPercent = Convert.ToDouble(row["FromPercent2"]); //if (row["ToPercent2"] != null && row["ToPercent2"] != DBNull.Value) // toPercent = Convert.ToDouble(row["ToPercent2"]); if (row["DonVi2"] != null && row["DonVi2"] != DBNull.Value) { donVi = row["DonVi2"].ToString().Trim(); } } else { string tenXetNghiem = row["Fullname"].ToString(); XetNghiem_CellDyn3200 xn = db.XetNghiem_CellDyn3200s.SingleOrDefault <XetNghiem_CellDyn3200>(x => x.TenXetNghiem == tenXetNghiem); if (xn == null) { continue; } if (xn.FromValue.HasValue) { fromValue = xn.FromValue.Value; } if (xn.ToValue.HasValue) { toValue = xn.ToValue.Value; } //if (xn.FromPercent.HasValue) // fromPercent = xn.FromPercent.Value; //if (xn.ToPercent.HasValue) // toPercent = xn.ToPercent.Value; if (xn.DonVi != null && xn.DonVi != string.Empty) { donVi = xn.DonVi; } } double testResult = Convert.ToDouble(row["TestResult"]); TinhTrang tinhTrang = TinhTrang.BinhThuong; if (fromValue != null && toValue != null) { //if (fromPercent != null || toPercent != null) // row["BinhThuong"] = string.Format("({0:F2} - {1:F2})", fromValue.Value, toValue.Value); //else if (donVi != string.Empty) { row["BinhThuong"] = string.Format("({0:F2}-{1:F2} {2})", fromValue.Value, toValue.Value, donVi); } else { row["BinhThuong"] = string.Format("({0:F2}-{1:F2})", fromValue.Value, toValue.Value); } if (testResult < fromValue.Value || testResult > toValue.Value) { tinhTrang = TinhTrang.BatThuong; } } else if (fromValue != null) { //if (fromPercent != null || toPercent != null) // row["BinhThuong"] = string.Format("(> {0:F2})", fromValue.Value); //else if (donVi != string.Empty) { row["BinhThuong"] = string.Format("(>{0:F2} {1})", fromValue.Value, donVi); } else { row["BinhThuong"] = string.Format("(>{0:F2})", fromValue.Value); } if (testResult <= fromValue.Value) { tinhTrang = TinhTrang.BatThuong; } } else { //if (fromPercent != null || toPercent != null) // row["BinhThuong"] = string.Format("(< {0:F2})", toValue.Value); //else if (donVi != string.Empty) { row["BinhThuong"] = string.Format("(<{0:F2} {1})", toValue.Value, donVi); } else { row["BinhThuong"] = string.Format("(<{0:F2})", toValue.Value); } if (testResult >= toValue.Value) { tinhTrang = TinhTrang.BatThuong; } } //if (fromPercent != null && toPercent != null) //{ // double testPercent = Convert.ToDouble(row["TestPercent"]); // row["Percent"] = string.Format("{0:F2}% ({1:F2} - {2:F2} {3})", testPercent, fromPercent.Value, toPercent.Value, donVi); // if (tinhTrang == TinhTrang.BinhThuong) // { // if (testPercent < fromPercent.Value || testPercent > toPercent.Value) // tinhTrang = TinhTrang.BatThuong; // } //} //else if (fromPercent != null) //{ // double testPercent = Convert.ToDouble(row["TestPercent"]); // row["Percent"] = string.Format("{0:F2}% (> {1:F2} {2})", testPercent, fromPercent.Value, donVi); // if (tinhTrang == TinhTrang.BinhThuong) // { // if (testPercent <= fromPercent.Value) // tinhTrang = TinhTrang.BatThuong; // } //} //else if (toPercent != null) //{ // double testPercent = Convert.ToDouble(row["TestPercent"]); // row["Percent"] = string.Format("{0:F2}% (< {1:F2} {2})", testPercent, toPercent.Value, donVi); // if (tinhTrang == TinhTrang.BinhThuong) // { // if (testPercent >= toPercent.Value) // tinhTrang = TinhTrang.BatThuong; // } //} row["TinhTrang"] = (byte)tinhTrang; ChiTietKetQuaXetNghiem_CellDyn3200 ctkqxn = db.ChiTietKetQuaXetNghiem_CellDyn3200s.SingleOrDefault <ChiTietKetQuaXetNghiem_CellDyn3200>(c => c.ChiTietKQXN_CellDyn3200GUID.ToString() == row["ChiTietKQXN_CellDyn3200GUID"].ToString()); if (ctkqxn != null) { ctkqxn.FromValue = fromValue; ctkqxn.ToValue = toValue; //ctkqxn.FromPercent = fromPercent; //ctkqxn.ToPercent = toPercent; ctkqxn.DonVi = donVi; if (ctkqxn.FromValue != null && ctkqxn.FromValue.HasValue) { row["FromValue"] = ctkqxn.FromValue.Value; } if (ctkqxn.ToValue != null && ctkqxn.ToValue.HasValue) { row["ToValue"] = ctkqxn.ToValue.Value; } //if (ctkqxn.FromPercent != null && ctkqxn.FromValue.HasValue) // row["FromPercent"] = ctkqxn.FromPercent.Value; //if (ctkqxn.ToPercent != null && ctkqxn.ToValue.HasValue) // row["ToPercent"] = ctkqxn.ToPercent.Value; //row["DoiTuong"] = ctkqxn.DoiTuong; row["DonVi"] = ctkqxn.DonVi; } } db.SubmitChanges(); db.Dispose(); } 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(); } return(result); }