2022-04-14 15:09:25 +02:00
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 ;
2022-04-15 16:00:35 +02:00
public System . IO . StreamWriter stationLog ;
2022-04-14 15:09:25 +02:00
public SqlConnection localConnection , centralConnection ;
internal CLog splunkLog ;
public System . Data . SqlClient . SqlCommand VisitInitCommand ;
public static SqlCommand VisitExitCommand ;
public static SqlCommand NextIDCommand ;
public static SqlCommand LastIDCommand ;
public static SqlCommand CheckStatus ;
2022-04-19 14:58:36 +02:00
public static SqlCommand GetPersonInfo ;
2022-04-14 15:09:25 +02:00
public DataSet1 . CommentOnEventDataTable dtCOE ;
2022-04-15 16:00:35 +02:00
private bool CheckUser , AllowMultipleEPD ;
2022-04-14 15:09:25 +02:00
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? ;
2022-04-15 16:00:35 +02:00
return nxtValue ;
2022-04-14 15:09:25 +02:00
}
public static int? LastID ( )
{
int? lastValue = null ;
if ( NextIDCommand . Connection . State = = ConnectionState . Closed ) LastIDCommand . Connection . Open ( ) ;
lastValue = LastIDCommand . ExecuteScalar ( ) as int? ;
return lastValue ;
}
/// <summary>
/// Check connenction. If closed then open oand optianly leave open.
/// </summary>
/// <param name="leaveOpen">If opened leave it open</param>
/// <returns>true if connection ok</returns>
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 ;
2022-04-15 16:00:35 +02:00
2022-04-14 15:09:25 +02:00
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 ;
}
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 ;
2022-04-19 14:58:36 +02:00
bool rv = checkCon ( true ) ;
2022-04-14 15:09:25 +02:00
MakeCommands ( ) ;
2022-04-19 14:58:36 +02:00
if ( localConnection . State = = ConnectionState . Open ) localConnection . Close ( ) ;
2022-04-15 16:00:35 +02:00
}
catch ( Exception ex )
2022-04-14 15:09:25 +02:00
{
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()}" ) ;
}
2022-04-15 16:00:35 +02:00
public DataInterface ( )
2022-04-14 15:09:25 +02:00
{
init ( ) ;
}
2022-04-15 16:00:35 +02:00
2022-04-14 15:09:25 +02:00
// 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 )
{
2022-04-15 16:00:35 +02:00
checkCon ( LeaveOpen ) ;
return localConnection ;
2022-04-14 15:09:25 +02:00
}
public System . Data . SqlClient . SqlConnection getConCentral ( bool LeaveOpen )
{
checkConCentral ( LeaveOpen ) ;
return centralConnection ;
}
void MakeCommands ( )
{
2022-04-19 14:58:36 +02:00
var oldState = localConnection . State ;
if ( oldState = = ConnectionState . Closed ) localConnection . Open ( ) ;
2022-04-14 15:09:25 +02:00
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 ) ;
2022-04-15 16:00:35 +02:00
2022-04-14 15:09:25 +02:00
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 )
} ) ;
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 )
} ) ;
ReverseSyncCommand = new System . Data . SqlClient . SqlCommand ( "syncLoc.UpdateRemoteReturns" , localConnection ) { CommandType = System . Data . CommandType . StoredProcedure } ;
2022-04-19 14:58:36 +02:00
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 ) ;
2022-04-14 15:09:25 +02:00
2022-04-19 14:58:36 +02:00
if ( oldState = = ConnectionState . Closed ) localConnection . Close ( ) ;
2022-04-14 15:09:25 +02:00
}
2022-04-15 16:00:35 +02:00
public void VisitExit ( int EpdVisitID , EpdBaseClr . Epd2 ep )
2022-04-14 15:09:25 +02:00
{
const string taskName = "VisitExit" ;
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 ;
2022-04-15 16:00:35 +02:00
//ep.hasAlarm
VisitExitCommand . SetBoolParam ( "eDosBatteryWarning" , ep . eDosBatteryWarning ) ;
2022-04-14 15:09:25 +02:00
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 ) ;
checkCon ( true ) ;
VisitExitCommand . Connection = localConnection ;
try
{
VisitExitCommand . ExecuteNonQuery ( ) ;
2022-04-15 16:00:35 +02:00
}
catch ( System . Exception ex )
2022-04-14 15:09:25 +02:00
{
splunkLog ? . WriteException ( moduleName , taskName , ex ) ;
}
localConnection . Close ( ) ;
}
2022-04-15 16:00:35 +02:00
public void FillComment ( )
2022-04-14 15:09:25 +02:00
{
2022-04-15 16:00:35 +02:00
if ( dtCOE = = null ) dtCOE = new DataSet1 . CommentOnEventDataTable ( ) ;
2022-04-14 15:09:25 +02:00
using ( var dt = new DataSet1TableAdapters . CommentOnEventTableAdapter ( ) )
{
dt . Fill ( dtCOE ) ;
}
}
2022-04-15 16:00:35 +02:00
public DataSet1 . CommentOnEventRow GetCommentOnEventRow ( int id )
2022-04-14 15:09:25 +02:00
{
return dtCOE . FindByID_CommnentOnEvent ( id ) ;
}
2022-04-15 16:00:35 +02:00
public void FillTaskInfo ( User _User , DataSet1 dataSet1 )
2022-04-14 15:09:25 +02:00
{
const string taskName = "FillTaskInfo" ;
try
{
using ( var dataSet1GetTaskInfoTableAdapter = new DataSet1TableAdapters . GetTaskInfoTableAdapter ( ) ) // new eDosStation.DataSet1TableAdapters.GetTaskInfoTableAdapter())
{
dataSet1GetTaskInfoTableAdapter . Fill ( dataSet1 . GetTaskInfo , null , _User . Margin ) ;
}
}
2022-04-15 16:00:35 +02:00
catch ( System . Exception ex )
{
2022-04-14 15:09:25 +02:00
splunkLog ? . WriteException ( moduleName , taskName , ex ) ;
}
}
2022-04-15 16:00:35 +02:00
public User GetUser ( string CSN , string Code , bool isEntry )
2022-04-14 15:09:25 +02:00
{
const string taskName = "GetUser" ;
User u = new User ( ) ;
//object[] Values = null;
try
{
2022-04-19 14:58:36 +02:00
GetPersonInfo . SetIntParam ( "@PersID" , Code ) ;
GetPersonInfo . SetStringParam ( "@CSN" , CSN ) ;
GetPersonInfo . SetBoolParam ( "@AllowMultipleEPD" , AllowMultipleEPD ) ;
checkCon ( true ) ;
var rs = GetPersonInfo . ExecuteReader ( System . Data . CommandBehavior . SingleRow ) ;
using ( var tb = new DataTable ( ) )
2022-04-14 15:09:25 +02:00
{
2022-04-19 14:58:36 +02:00
tb . Load ( rs ) ;
if ( tb . Rows . Count > 0 )
2022-04-14 15:09:25 +02:00
{
2022-04-19 14:58:36 +02:00
DataRow dr = tb . Rows [ 0 ] ;
//Values = new object[rs.FieldCount];
//int rv = rs.GetValues(Values);
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 = dr [ "AccessAllow" ] as bool? ;
decimal? m = dr [ "Margin" ] as decimal? ;
if ( m . HasValue ) u . Margin = ( double ) m . Value ; else u . Margin = null ;
//u.Margin = (double ?)Values[rs.GetOrdinal("Margin")] ;
u . VisitIDLocked = dr [ "VisitIDLocked" ] as int? ;
u . ReasonNoAccess = dr [ "ReasonNoAccess" ] . ToString ( ) . Replace ( "\\n" , "\n" ) ;
u . UserComment = dr [ "Comment" ] . ToString ( ) ;
2022-04-14 15:09:25 +02:00
2022-04-19 14:58:36 +02:00
if ( isEntry & & ! AllowMultipleEPD & & tb . Columns . Contains ( "hasEPD" ) )
2022-04-14 15:09:25 +02:00
{
2022-04-19 14:58:36 +02:00
u . hasEPD = ( bool ) dr [ "hasEPD" ] ;
if ( u . hasEPD ) u . ReasonNoAccess = "You have an EPD in use" ; //!!! not for return !!!!
2022-04-14 15:09:25 +02:00
}
2022-04-19 14:58:36 +02:00
else u . hasEPD = false ;
u . activeVisit = dr [ "activeVisit" ] as int? ;
u . AllOk = ( ! CheckUser | | ( u . AccessAllow = = true & & u . VisitIDLocked = = 0 ) ) ;
}
else
{
// Not found
u . PersID = 0 ;
u . LastName = "Not Found" ;
u . FirstName = "Not Found" ;
//u.conCode = "A1";
u . Language = "N" ;
u . AccessAllow = false ;
u . Margin = 0 ;
u . VisitIDLocked = 0 ;
u . ReasonNoAccess = "Not found" ;
u . UserComment = string . Empty ;
u . hasEPD = false ;
u . AllOk = ! CheckUser | | ( u . AccessAllow = = true & & u . VisitIDLocked = = 0 ) ;
2022-04-14 15:09:25 +02:00
}
2022-04-19 14:58:36 +02:00
rs . Close ( ) ;
2022-04-14 15:09:25 +02:00
}
}
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
{
2022-04-19 14:58:36 +02:00
splunkLog . KvClear ( ) ;
splunkLog . KvAddCommand ( CLog . skeys . sqlQuery , ReverseSyncCommand ) ;
2022-04-14 15:09:25 +02:00
ReverseSyncCommand . ExecuteNonQuery ( ) ;
2022-04-19 14:58:36 +02:00
splunkLog . WriteSplunkLog ( taskName , CLog . iseverity . info ) ;
2022-04-14 15:09:25 +02:00
rv = true ;
}
catch ( System . Exception ex )
{
splunkLog ? . WriteException ( moduleName , taskName , ex ) ;
}
localConnection . Close ( ) ;
return rv ;
}
}
}