using LSWLib; using System; using System.Data; using System.Data.SqlClient; namespace eDosStation { public class DataInterface { const string moduleName = "DataInterface"; public int ID_Station; public bool isLocal = false; private string currentConStr, ConCentralStr; public System.IO.StreamWriter stationLog; public SqlConnection localConnection, centralConnection; internal CLog splunkLog; public System.Data.SqlClient.SqlCommand VisitInitCommand, VisitInfoCommand, VisitInitConfirmCommand; public static SqlCommand VisitExitCommand; public static SqlCommand NextIDCommand; public static SqlCommand LastIDCommand; public static SqlCommand CheckStatus; public static SqlCommand GetPersonInfo; public DataSet1.CommentOnEventDataTable dtCOE; private bool CheckUser, AllowMultipleEPD; private SqlCommand ReverseSyncCommand; public static string tnow() { return DateTime.Now.ToString("HH:mm:ss.fff"); } public static int? NextID() { int? nxtValue = null; if (NextIDCommand.Connection.State == ConnectionState.Closed) NextIDCommand.Connection.Open(); nxtValue = NextIDCommand.ExecuteScalar() as int?; return nxtValue; } public static int? LastID() { int? lastValue = null; if (NextIDCommand.Connection.State == ConnectionState.Closed) LastIDCommand.Connection.Open(); lastValue = LastIDCommand.ExecuteScalar() as int?; return lastValue; } /// /// Check connenction. If closed then open oand optianly leave open. /// /// If opened leave it open /// true if connection ok public bool checkCon(bool leaveOpen = false) { bool rv = false; if (localConnection != null && localConnection.State == System.Data.ConnectionState.Open) return true; try { if (localConnection == null || string.IsNullOrEmpty(localConnection.ConnectionString)) localConnection = new SqlConnection(currentConStr); localConnection.Open(); rv = true; } catch (System.Exception ex) { System.Windows.MessageBox.Show($"Opening '{currentConStr}' error :{ex.Message}"); } if (rv && !leaveOpen) localConnection?.Close(); return rv; } public bool checkConCentral(bool leaveOpen = false) { bool rv = false; if (centralConnection != null && centralConnection.State == System.Data.ConnectionState.Open) return true; try { if (centralConnection == null || string.IsNullOrEmpty(centralConnection.ConnectionString)) centralConnection = new SqlConnection(ConCentralStr); centralConnection.Open(); rv = true; } catch (System.Exception ex) { System.Windows.MessageBox.Show($"Opening '{ConCentralStr}' error :{ex.Message}"); } if (rv && !leaveOpen) centralConnection?.Close(); return rv; } internal void SetStation(int curIDStation) { ID_Station = curIDStation; LastIDCommand.Parameters["ID_Station"].Value = curIDStation; VisitInitCommand.Parameters["ID_Station"].Value = curIDStation; CheckStatus.Parameters["ID_Station"].Value = curIDStation; VisitInitConfirmCommand.Parameters["ID_Station"].Value = curIDStation; } public bool isOnline() { bool? online = false; if (checkCon(true)) { online = CheckStatus.ExecuteScalar() as bool?; if (!online.HasValue) online = false; } isLocal = !online.Value; return online.Value; } static public void first() { var cb = new System.Data.SqlClient.SqlConnectionStringBuilder(Properties.Settings.Default.localConnectionString); if (string.IsNullOrEmpty(cb.Password)) { var f = new AskPwd(); f.ShowDialog(); string pwd = f.ResponseText; string cfg = System.IO.Path.Combine(Environment.CurrentDirectory, System.AppDomain.CurrentDomain.FriendlyName); Config.ToggleConfigEncryption(cfg, pwd); System.Windows.Application.Current.Shutdown(); } } private void init() { const string taskName = "init"; stationLog?.WriteLine($"{moduleName}.{taskName } start {tnow()}"); try { var flog = System.Configuration.ConfigurationManager.AppSettings["sqlLogFolder"]; if (System.IO.Directory.Exists(flog)) { string fn = System.IO.Path.Combine(flog, "station.log"); if (System.IO.File.Exists(fn)) { stationLog = new System.IO.StreamWriter(fn, false, System.Text.Encoding.UTF8); } } first(); currentConStr = System.Configuration.ConfigurationManager.ConnectionStrings["eDosStation.Properties.Settings.localConnectionString"].ConnectionString; ConCentralStr = System.Configuration.ConfigurationManager.ConnectionStrings["eDosConnectionString"].ConnectionString; localConnection = new SqlConnection(currentConStr); NextIDCommand = new SqlCommand("SELECT NEXT VALUE FOR VisitSequence as VisitID", localConnection); isLocal = true; bool rv = checkCon(true); MakeCommands(); if (localConnection.State == ConnectionState.Open)localConnection.Close(); } catch (Exception ex) { splunkLog?.WriteException(moduleName, taskName, ex); System.Windows.MessageBox.Show($"Init error {ex.Message} con={currentConStr}"); stationLog.WriteLine($"Init error {ex.Message} con={currentConStr}"); } stationLog?.WriteLine($"Datainterface.Init end {tnow()}"); } public DataInterface() { init(); } // DataSet1TableAdapters.GetTaskInfoTableAdapter TaskInfoTa() //{ // return new DataSet1TableAdapters.GetTaskInfoTableAdapter(); // //var ta = DataSet1TableAdapters.GetTaskInfoTableAdapter(); // //if (ta.Connection.ConnectionString!= currentConStr) ta.Connection.ConnectionString = currentConStr; // //return //} // DataSet1TableAdapters.GetTaskListTableAdapter TaskListTA() //{ // return new DataSet1TableAdapters.GetTaskListTableAdapter(); // //ta.Connection.ConnectionString = currentConStr; // //return ta; //} internal void SetCheckUser(bool pCheckUser) { this.CheckUser = pCheckUser; } internal void SetAllowMultipleEPD(bool pAllowMultipleEPD) { this.AllowMultipleEPD = pAllowMultipleEPD; } //DataSet1TableAdapters.CommentOnEventTableAdapter CommentTA() //{ // var ta = new DataSet1TableAdapters.CommentOnEventTableAdapter(); // ta.Connection.ConnectionString = currentConStr; // return ta; //} public System.Data.SqlClient.SqlConnection getCon(bool LeaveOpen) { checkCon(LeaveOpen); return localConnection; } public System.Data.SqlClient.SqlConnection getConCentral(bool LeaveOpen) { checkConCentral(LeaveOpen); return centralConnection; } void MakeCommands() { var oldState = localConnection.State; if (oldState == ConnectionState.Closed) localConnection.Open(); LastIDCommand = new SqlCommand("VisitIDLast", localConnection); LastIDCommand.CommandType = CommandType.StoredProcedure; var pa = new System.Data.SqlClient.SqlParameter("ID_Station", SqlDbType.Int, 4); LastIDCommand.Parameters.Add(pa); CheckStatus = new SqlCommand("[syncLoc].[SyncStatusIsOK]", localConnection); CheckStatus.CommandType = CommandType.StoredProcedure; pa = new System.Data.SqlClient.SqlParameter("ID_Station", SqlDbType.Int, 4); CheckStatus.Parameters.Add(pa); VisitInitCommand = new System.Data.SqlClient.SqlCommand("[dbo].[VisitInit]", localConnection) { CommandType = System.Data.CommandType.StoredProcedure }; VisitInitCommand.Parameters.AddRange(new System.Data.SqlClient.SqlParameter[] { new System.Data.SqlClient.SqlParameter("PersID",SqlDbType.Int,0,System.Data.ParameterDirection.Input,false,0,0,null,System.Data.DataRowVersion.Default,null) , new System.Data.SqlClient.SqlParameter("ID_Task",SqlDbType.Int,0,System.Data.ParameterDirection.Input,false,0,0,null,System.Data.DataRowVersion.Default,null) , new System.Data.SqlClient.SqlParameter("Inst_CODE",SqlDbType.Int,0,System.Data.ParameterDirection.Input,false,0,0,null,System.Data.DataRowVersion.Default,null) , new System.Data.SqlClient.SqlParameter("EPD_InternalID",SqlDbType.Int,0,System.Data.ParameterDirection.Input,false,0,0,null,System.Data.DataRowVersion.Default,null) , new System.Data.SqlClient.SqlParameter("isBG",SqlDbType.Bit,0,System.Data.ParameterDirection.Input,false,0,0,null,System.Data.DataRowVersion.Default,null) , new System.Data.SqlClient.SqlParameter("EPDVisitID",SqlDbType.Int,0,System.Data.ParameterDirection.Output,false,0,0,null,System.Data.DataRowVersion.Default,null) , new System.Data.SqlClient.SqlParameter("ID_Station",SqlDbType.Int,0,System.Data.ParameterDirection.Input,false,0,0,null,System.Data.DataRowVersion.Default,null) , new System.Data.SqlClient.SqlParameter("ID_Visit",SqlDbType.Int,0,System.Data.ParameterDirection.Input,false,0,0,null,System.Data.DataRowVersion.Default,null) , new System.Data.SqlClient.SqlParameter("ENTRY_EPD_CLOCK",SqlDbType.Decimal,0,System.Data.ParameterDirection.Input,false,10,0,null,System.Data.DataRowVersion.Default,null) , new System.Data.SqlClient.SqlParameter("epdType",SqlDbType.TinyInt,0,System.Data.ParameterDirection.Input,false,0,0,null,System.Data.DataRowVersion.Default,null) , new System.Data.SqlClient.SqlParameter("InitError",SqlDbType.Int,0,System.Data.ParameterDirection.Input,false,0,0,null,System.Data.DataRowVersion.Default,null) }); VisitInitConfirmCommand = new System.Data.SqlClient.SqlCommand("[dbo].[VisitInitConfirm]", localConnection) { CommandType = System.Data.CommandType.StoredProcedure }; VisitInitConfirmCommand.Parameters.AddRange(new System.Data.SqlClient.SqlParameter[] { new System.Data.SqlClient.SqlParameter("ID_Station",SqlDbType.Int,0,System.Data.ParameterDirection.Input,false,0,0,null,System.Data.DataRowVersion.Default,null) , new System.Data.SqlClient.SqlParameter("ID_Visit",SqlDbType.Int,0,System.Data.ParameterDirection.Input,false,0,0,null,System.Data.DataRowVersion.Default,null) , new System.Data.SqlClient.SqlParameter("InitError",SqlDbType.Int,0,System.Data.ParameterDirection.Input,false,0,0,null,System.Data.DataRowVersion.Default,null) }); VisitExitCommand = new System.Data.SqlClient.SqlCommand("[dbo].[VisitExit]", localConnection) { CommandType = System.Data.CommandType.StoredProcedure }; VisitExitCommand.Parameters.AddRange(new System.Data.SqlClient.SqlParameter[] { new System.Data.SqlClient.SqlParameter("EPDVisitID",SqlDbType.Int,0,System.Data.ParameterDirection.Input,false,0,0,null,System.Data.DataRowVersion.Default,null) , new System.Data.SqlClient.SqlParameter("HP07",SqlDbType.Float,0,System.Data.ParameterDirection.Input,false,0,0,null,System.Data.DataRowVersion.Default,null) , new System.Data.SqlClient.SqlParameter("HP10",SqlDbType.Float,0,System.Data.ParameterDirection.Input,false,0,0,null,System.Data.DataRowVersion.Default,null) , new System.Data.SqlClient.SqlParameter("HP07Peak",SqlDbType.Float,0,System.Data.ParameterDirection.Input,false,0,0,null,System.Data.DataRowVersion.Default,null) , new System.Data.SqlClient.SqlParameter("HP10Peak",SqlDbType.Float,0,System.Data.ParameterDirection.Input,false,0,0,null,System.Data.DataRowVersion.Default,null) , new System.Data.SqlClient.SqlParameter("HP07PeakTime",SqlDbType.DateTime,0,System.Data.ParameterDirection.Input,false,0,0,null,System.Data.DataRowVersion.Default,null) , new System.Data.SqlClient.SqlParameter("HP10PeakTime",SqlDbType.DateTime,0,System.Data.ParameterDirection.Input,false,0,0,null,System.Data.DataRowVersion.Default,null) , new System.Data.SqlClient.SqlParameter("HP07Total",SqlDbType.Float,0,System.Data.ParameterDirection.Input,false,0,0,null,System.Data.DataRowVersion.Default,null) , new System.Data.SqlClient.SqlParameter("HP10Total",SqlDbType.Float,0,System.Data.ParameterDirection.Input,false,0,0,null,System.Data.DataRowVersion.Default,null) , new System.Data.SqlClient.SqlParameter("K1",SqlDbType.Int,0,System.Data.ParameterDirection.Input,false,0,0,null,System.Data.DataRowVersion.Default,null) , new System.Data.SqlClient.SqlParameter("K2",SqlDbType.Int,0,System.Data.ParameterDirection.Input,false,0,0,null,System.Data.DataRowVersion.Default,null) , new System.Data.SqlClient.SqlParameter("K3",SqlDbType.Int,0,System.Data.ParameterDirection.Input,false,0,0,null,System.Data.DataRowVersion.Default,null) , new System.Data.SqlClient.SqlParameter("K4",SqlDbType.Int,0,System.Data.ParameterDirection.Input,false,0,0,null,System.Data.DataRowVersion.Default,null) , new System.Data.SqlClient.SqlParameter("K5",SqlDbType.Int,0,System.Data.ParameterDirection.Input,false,0,0,null,System.Data.DataRowVersion.Default,null) , new System.Data.SqlClient.SqlParameter("K6",SqlDbType.Int,0,System.Data.ParameterDirection.Input,false,0,0,null,System.Data.DataRowVersion.Default,null) , new System.Data.SqlClient.SqlParameter("SG",SqlDbType.Int,0,System.Data.ParameterDirection.Input,false,0,0,null,System.Data.DataRowVersion.Default,null) , new System.Data.SqlClient.SqlParameter("BC",SqlDbType.Int,0,System.Data.ParameterDirection.Input,false,0,0,null,System.Data.DataRowVersion.Default,null) , new System.Data.SqlClient.SqlParameter("FB",SqlDbType.Int,0,System.Data.ParameterDirection.Input,false,0,0,null,System.Data.DataRowVersion.Default,null) , new System.Data.SqlClient.SqlParameter("HG",SqlDbType.Int,0,System.Data.ParameterDirection.Input,false,0,0,null,System.Data.DataRowVersion.Default,null) , new System.Data.SqlClient.SqlParameter("QualityData",SqlDbType.Int,0,System.Data.ParameterDirection.Input,false,0,0,null,System.Data.DataRowVersion.Default,null) , new System.Data.SqlClient.SqlParameter("alarmStatus",SqlDbType.Int,0,System.Data.ParameterDirection.Input,false,0,0,null,System.Data.DataRowVersion.Default,null) , new System.Data.SqlClient.SqlParameter("otherAlarms",SqlDbType.Int,0,System.Data.ParameterDirection.Input,false,0,0,null,System.Data.DataRowVersion.Default,null) , new System.Data.SqlClient.SqlParameter("errorStatus",SqlDbType.Int,0,System.Data.ParameterDirection.Input,false,0,0,null,System.Data.DataRowVersion.Default,null) , new System.Data.SqlClient.SqlParameter("operatingStatus",SqlDbType.Int,0,System.Data.ParameterDirection.Input,false,0,0,null,System.Data.DataRowVersion.Default,null) , new System.Data.SqlClient.SqlParameter("ENTRY_EPD_CLOCK",SqlDbType.Decimal,0,System.Data.ParameterDirection.Input,false,10,0,null,System.Data.DataRowVersion.Default,null) , new System.Data.SqlClient.SqlParameter("EXIT_EPD_CLOCK",SqlDbType.Decimal,0,System.Data.ParameterDirection.Input,false,10,0,null,System.Data.DataRowVersion.Default,null) , new System.Data.SqlClient.SqlParameter("PersID",SqlDbType.Int,0,System.Data.ParameterDirection.Input,false,0,0,null,System.Data.DataRowVersion.Default,null) , new System.Data.SqlClient.SqlParameter("eDosBatteryWarning",SqlDbType.Bit,0,System.Data.ParameterDirection.Input,false,0,0,null,System.Data.DataRowVersion.Default,null) , new System.Data.SqlClient.SqlParameter("eDosDose07Warning",SqlDbType.Bit,0,System.Data.ParameterDirection.Input,false,0,0,null,System.Data.DataRowVersion.Default,null) , new System.Data.SqlClient.SqlParameter("eDosDose07Alarm",SqlDbType.Bit,0,System.Data.ParameterDirection.Input,false,0,0,null,System.Data.DataRowVersion.Default,null) , new System.Data.SqlClient.SqlParameter("eDosRate07Warning",SqlDbType.Bit,0,System.Data.ParameterDirection.Input,false,0,0,null,System.Data.DataRowVersion.Default,null) , new System.Data.SqlClient.SqlParameter("eDosRate07Alarm",SqlDbType.Bit,0,System.Data.ParameterDirection.Input,false,0,0,null,System.Data.DataRowVersion.Default,null) , new System.Data.SqlClient.SqlParameter("eDosDose10Warning",SqlDbType.Bit,0,System.Data.ParameterDirection.Input,false,0,0,null,System.Data.DataRowVersion.Default,null) , new System.Data.SqlClient.SqlParameter("eDosDose10Alarm",SqlDbType.Bit,0,System.Data.ParameterDirection.Input,false,0,0,null,System.Data.DataRowVersion.Default,null) , new System.Data.SqlClient.SqlParameter("eDosRate10Warning",SqlDbType.Bit,0,System.Data.ParameterDirection.Input,false,0,0,null,System.Data.DataRowVersion.Default,null) , new System.Data.SqlClient.SqlParameter("eDosRate10Alarm",SqlDbType.Bit,0,System.Data.ParameterDirection.Input,false,0,0,null,System.Data.DataRowVersion.Default,null) , new System.Data.SqlClient.SqlParameter("isAlarm",SqlDbType.Bit,0,System.Data.ParameterDirection.Input,true,0,0,null,System.Data.DataRowVersion.Default,null) , new System.Data.SqlClient.SqlParameter("isFault",SqlDbType.Bit,0,System.Data.ParameterDirection.Input,true,0,0,null,System.Data.DataRowVersion.Default,null) }); VisitInfoCommand = new System.Data.SqlClient.SqlCommand("[dbo].[VisitInfo]", localConnection) { CommandType = System.Data.CommandType.StoredProcedure }; VisitInfoCommand.Parameters.AddRange(new System.Data.SqlClient.SqlParameter[] { new System.Data.SqlClient.SqlParameter("RETURN_VALUE",SqlDbType.Int,0,System.Data.ParameterDirection.ReturnValue,false,0,0,null,System.Data.DataRowVersion.Default,null) ,new System.Data.SqlClient.SqlParameter("EPDVisitID",SqlDbType.Int,0,System.Data.ParameterDirection.Input,false,0,0,null,System.Data.DataRowVersion.Default,null) ,new System.Data.SqlClient.SqlParameter("hasExited",SqlDbType.Bit,0,System.Data.ParameterDirection.Output,false,0,0,null,System.Data.DataRowVersion.Default,null) ,new System.Data.SqlClient.SqlParameter("isManualExit",SqlDbType.Bit,0,System.Data.ParameterDirection.Output,false,0,0,null,System.Data.DataRowVersion.Default,null) ,new System.Data.SqlClient.SqlParameter("name",SqlDbType.VarChar,100,System.Data.ParameterDirection.Output,true,0,0,null,System.Data.DataRowVersion.Default,null) }); ReverseSyncCommand = new System.Data.SqlClient.SqlCommand("syncLoc.UpdateRemoteReturns", localConnection) { CommandType = System.Data.CommandType.StoredProcedure }; SqlCommandBuilder.DeriveParameters(ReverseSyncCommand); ReverseSyncCommand.Parameters["@ID_LocalStation"].Value = DBNull.Value; ReverseSyncCommand.SetStringParam("@pcnr", Environment.MachineName); GetPersonInfo = new System.Data.SqlClient.SqlCommand("[dbo].[GetPersonInfo]", localConnection) { CommandType = System.Data.CommandType.StoredProcedure }; SqlCommandBuilder.DeriveParameters(GetPersonInfo); if (oldState == ConnectionState.Closed) localConnection.Close(); } public int? ParaIntValue(SqlCommand cmd, string name) { int? rv = null; if (cmd.Parameters.Contains(name) && cmd.Parameters[name].Value != DBNull.Value) rv = (int?)cmd.Parameters[name].Value; return rv; } public bool? ParaBoolValue(SqlCommand cmd, string name) { bool? rv = null; if (cmd.Parameters.Contains(name) && cmd.Parameters[name].Value != DBNull.Value) rv = (bool?)cmd.Parameters[name].Value; return rv; } public string ParaStringValue(SqlCommand cmd, string name) { string rv = null; if (cmd.Parameters.Contains(name) && cmd.Parameters[name].Value != DBNull.Value) rv = (string)cmd.Parameters[name].Value; return rv; } public int VisitInfo(int EpdVisitID, out string name) { int? rv = 0; const string taskName = "VisitInfo"; name = string.Empty; try { VisitInfoCommand.Parameters["EPDVisitID"].Value = EpdVisitID; checkCon(true); VisitInfoCommand.Connection = localConnection; VisitInfoCommand.ExecuteScalar(); rv = ParaIntValue(VisitInfoCommand, "RETURN_VALUE"); bool? hasExited = ParaBoolValue(VisitInfoCommand, "hasExited"); bool? isManualExit = ParaBoolValue(VisitInfoCommand, "isManualExit"); name = ParaStringValue(VisitInfoCommand, "name"); } catch (System.Exception ex) { splunkLog?.WriteException(moduleName, taskName, ex); } if (rv == null) rv = 0; return rv.Value; } public void VisitExit(int EpdVisitID, EpdBaseClr.Epd2 ep) { const string taskName = "VisitExit"; try { VisitExitCommand.Parameters["EPDVisitID"].Value = EpdVisitID; VisitExitCommand.Parameters["HP07"].Value = ep.Hp07; VisitExitCommand.Parameters["HP10"].Value = ep.Hp10; VisitExitCommand.Parameters["Hp07Total"].Value = ep.Hp07Total; VisitExitCommand.Parameters["Hp10Total"].Value = ep.Hp10Total; VisitExitCommand.Parameters["Hp07Peak"].Value = ep.Hp07Peak; VisitExitCommand.Parameters["Hp10Peak"].Value = ep.Hp10Peak; if (ep.Hp07PeakTime != null) VisitExitCommand.Parameters["HP07PeakTime"].Value = ep.Hp07PeakTime; else VisitExitCommand.Parameters["HP07PeakTime"].Value = DBNull.Value; if (ep.Hp10PeakTime != null) VisitExitCommand.Parameters["Hp10PeakTime"].Value = ep.Hp07PeakTime; else VisitExitCommand.Parameters["Hp10PeakTime"].Value = DBNull.Value; VisitExitCommand.Parameters["K1"].Value = ep.K1; VisitExitCommand.Parameters["K2"].Value = ep.K2; VisitExitCommand.Parameters["K3"].Value = ep.K3; VisitExitCommand.Parameters["K4"].Value = ep.K4; VisitExitCommand.Parameters["K5"].Value = ep.K5; VisitExitCommand.Parameters["K6"].Value = ep.K6; VisitExitCommand.Parameters["SG"].Value = ep.SG; VisitExitCommand.Parameters["BC"].Value = ep.BC; VisitExitCommand.Parameters["FB"].Value = ep.FB; VisitExitCommand.Parameters["HG"].Value = ep.HG; VisitExitCommand.Parameters["QualityData"].Value = ep.QualityData; //VisitExitCommand.Parameters["D1"].Value = ep.D1; //VisitExitCommand.Parameters["D2"].Value = ep.D2; //VisitExitCommand.Parameters["D3"].Value = ep.D3; //VisitExitCommand.Parameters["D4"].Value = ep.D4; VisitExitCommand.Parameters["alarmStatus"].Value = ep.alarmStatus; VisitExitCommand.Parameters["otherAlarms"].Value = ep.otherAlarms; VisitExitCommand.Parameters["errorStatus"].Value = ep.errorStatus; VisitExitCommand.Parameters["operatingStatus"].Value = ep.operatingStatus; VisitExitCommand.Parameters["ENTRY_EPD_CLOCK"].Value = ep.CountsClockBase; VisitExitCommand.Parameters["EXIT_EPD_CLOCK"].Value = ep.CountsClock; if (int.TryParse(ep.WearerName, out int WearerPersID)) VisitExitCommand.Parameters["PersID"].Value = WearerPersID; else VisitExitCommand.Parameters["PersID"].Value = DBNull.Value; //ep.hasAlarm VisitExitCommand.SetBoolParam("eDosBatteryWarning", ep.eDosBatteryWarning); VisitExitCommand.SetBoolParam("eDosDose07Warning", ep.eDosDose07Warning); VisitExitCommand.SetBoolParam("eDosDose07Alarm", ep.eDosDose07Alarm); VisitExitCommand.SetBoolParam("eDosRate07Warning", ep.eDosRate07Warning); VisitExitCommand.SetBoolParam("eDosRate07Alarm", ep.eDosRate07Alarm); VisitExitCommand.SetBoolParam("eDosDose10Warning", ep.eDosDose10Warning); VisitExitCommand.SetBoolParam("eDosDose10Alarm", ep.eDosDose10Alarm); VisitExitCommand.SetBoolParam("eDosRate10Warning", ep.eDosRate10Warning); VisitExitCommand.SetBoolParam("eDosRate10Alarm", ep.eDosRate10Alarm); VisitExitCommand.SetBoolParam("isAlarm", ep.eDoshasAlarm, splunkLog); VisitExitCommand.SetBoolParam("isFault", ep.eDosHasFault, splunkLog); checkCon(true); VisitExitCommand.Connection = localConnection; VisitExitCommand.ExecuteNonQuery(); } catch (System.Exception ex) { splunkLog?.WriteException(moduleName, taskName, ex); } localConnection.Close(); } public void FillComment() { if (dtCOE == null) dtCOE = new DataSet1.CommentOnEventDataTable(); using (var dt = new DataSet1TableAdapters.CommentOnEventTableAdapter()) { dt.Fill(dtCOE); } } public DataSet1.CommentOnEventRow GetCommentOnEventRow(int id) { return dtCOE.FindByID_CommnentOnEvent(id); } public void FillTaskInfo(User _User, DataSet1 dataSet1) { const string taskName = "FillTaskInfo"; try { using (var dataSet1GetTaskInfoTableAdapter = new DataSet1TableAdapters.GetTaskInfoTableAdapter()) // new eDosStation.DataSet1TableAdapters.GetTaskInfoTableAdapter()) { dataSet1GetTaskInfoTableAdapter.Fill(dataSet1.GetTaskInfo, null, _User.Margin); } } catch (System.Exception ex) { splunkLog?.WriteException(moduleName, taskName, ex); } } public User GetUser(string CSN, string Code, bool isEntry) { const string taskName = "GetUser"; User u = new User(); //object[] Values = null; try { GetPersonInfo.SetIntParam("@PersID", Code); GetPersonInfo.SetStringParam("@CSN", CSN); GetPersonInfo.SetBoolParam("@AllowMultipleEPD", AllowMultipleEPD); GetPersonInfo.SetBoolParam("@CheckUser", CheckUser); checkCon(true); var rs = GetPersonInfo.ExecuteReader(System.Data.CommandBehavior.SingleRow); using (var tb = new DataTable()) { tb.Load(rs); if (tb.Rows.Count > 0) { DataRow dr = tb.Rows[0]; u.PersID = (int) dr["PersID"]; u.LastName = dr["LastName"].ToString(); u.FirstName = dr["FirstName"].ToString(); //u.conCode = Values[rs.GetOrdinal("conCode")].ToString(); u.Language = dr["Language"].ToString(); u.AccessAllow = !CheckUser || dr.BoolOrFalse("AccessAllow"); u.Margin = dr.DoubleOrNull("Margin") ; u.VisitIDLocked = dr.IntOrDefault("VisitIDLocked",0); u.ReasonNoAccess = dr["ReasonNoAccess"].ToString().Replace("\\n", "\n"); u.UserComment = dr["Comment"].ToString(); if (isEntry && !AllowMultipleEPD && tb.Columns.Contains("hasEPD")) { u.hasEPD = dr.BoolOrFalse("hasEPD"); if (u.hasEPD) u.ReasonNoAccess = "You have an EPD in use"; //!!! not for return !!!! } else u.hasEPD = false; u.activeVisit = dr.IntOrNull("activeVisit"); u.isAgent = dr.BoolOrFalse("isAgent"); u.AllOk = u.VisitIDLocked==0 && u.AccessAllow.Value ; } else { // Not found u.SetNotFound(); u.AllOk = !CheckUser || (u.AccessAllow == true && u.VisitIDLocked == 0); } rs.Close(); } } catch (System.Exception ex) { splunkLog?.WriteException(moduleName, taskName, ex); if (stationLog != null) stationLog.WriteLine($"{taskName} error {ex.Message} {System.DateTime.Now.ToString("HH:mm:ss:nnn")}"); } return u; } public bool ReverseSync() { const string taskName = "ReverseSync"; bool rv = false; checkCon(true); VisitExitCommand.Connection = localConnection; try { splunkLog.KvClear(); splunkLog.KvAddCommand(CLog.skeys.sqlQuery, ReverseSyncCommand); ReverseSyncCommand.ExecuteNonQuery(); splunkLog.WriteSplunkLog(taskName , CLog.iseverity.info ); rv = true; } catch (System.Exception ex) { splunkLog?.WriteException(moduleName, taskName, ex); } localConnection.Close(); splunkLog.KvClear(); return rv; } } }