From c3dc4a340e0e0dd1eb3daa45933d1a0e69f85586 Mon Sep 17 00:00:00 2001 From: Luc Vandenbroucke Date: Wed, 27 Apr 2022 16:12:21 +0200 Subject: [PATCH] diverse --- eDosLocal/UpdateLocal.sql | 36 +++++++++++++++ eDosStation/DataInterface.cs | 38 ++++++++++++--- eDosStation/EpdExit.xaml.cs | 8 ++++ eDosStation/Settings.xaml.cs | 90 ++++++++++++++++++++++++++++++++++-- syncEdosLocal/Program.cs | 26 ++++++++++- 5 files changed, 186 insertions(+), 12 deletions(-) diff --git a/eDosLocal/UpdateLocal.sql b/eDosLocal/UpdateLocal.sql index 2d5251a..9d8f051 100644 --- a/eDosLocal/UpdateLocal.sql +++ b/eDosLocal/UpdateLocal.sql @@ -327,3 +327,39 @@ ELSE [AllowMultipleEPD]=@AllowMultipleEPD WHERE [PCNr] = HOST_NAME(); go + + +CREATE OR ALTER PROCEDURE [dbo].[VisitInfo] @EPDVisitID INT = 51905, + @hasExited BIT = 0 OUT, + @isManualExit BIT = 0 OUT +AS +--DECLARE @EPDVisitID INT= 51905 +BEGIN + SET NOCOUNT ON; + + DECLARE + @ID_Visit INT, + @ID_Station INT; + + SET @ID_Station = @EPDVisitID % 100; + SET @ID_Visit = @EPDVisitID / 100; + SET @hasExited = 0; + SET @isManualExit = 0; + + SELECT + @hasExited = CONVERT(BIT, CASE WHEN [ReturnTime] IS NOT NULL OR [isManualExit] = 1 THEN 1 ELSE 0 END), + @isManualExit = ISNULL([isManualExit], 0) + FROM [dbo].[Visit] + WHERE [ID_Visit] = @ID_Visit + AND [ID_Station] = @ID_Station; + + SET NOCOUNT OFF; + + SELECT [hasExited] = @hasExited; + + RETURN CASE WHEN ISNULL(@hasExited, 0) = 1 THEN 1 ELSE 0 END + CASE WHEN ISNULL(@isManualExit, 0) = 1 THEN 2 ELSE 0 END; +END; +GO + +GRANT EXECUTE ON [dbo].[VisitInfo] TO [eDosStation]; +GO \ No newline at end of file diff --git a/eDosStation/DataInterface.cs b/eDosStation/DataInterface.cs index 21fbb22..b12d2ae 100644 --- a/eDosStation/DataInterface.cs +++ b/eDosStation/DataInterface.cs @@ -15,7 +15,7 @@ namespace eDosStation public SqlConnection localConnection, centralConnection; internal CLog splunkLog; - public System.Data.SqlClient.SqlCommand VisitInitCommand; + public System.Data.SqlClient.SqlCommand VisitInitCommand, VisitInfoCommand; public static SqlCommand VisitExitCommand; public static SqlCommand NextIDCommand; public static SqlCommand LastIDCommand; @@ -262,6 +262,14 @@ namespace eDosStation , 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) + }); + ReverseSyncCommand = new System.Data.SqlClient.SqlCommand("syncLoc.UpdateRemoteReturns", localConnection) { CommandType = System.Data.CommandType.StoredProcedure }; SqlCommandBuilder.DeriveParameters(ReverseSyncCommand); @@ -273,6 +281,27 @@ namespace eDosStation if (oldState == ConnectionState.Closed) localConnection.Close(); } + public int VisitInfo(int EpdVisitID) + { + int? rv = 0; + const string taskName = "VisitInfo"; + try + { + VisitInfoCommand.Parameters["EPDVisitID"].Value = EpdVisitID; + checkCon(true); + VisitInfoCommand.Connection = localConnection; + VisitInfoCommand.ExecuteScalar(); + rv = (int?)VisitInfoCommand.Parameters["RETURN_VALUE"].Value; + bool? hasExited = (bool?)VisitInfoCommand.Parameters["hasExited"].Value; + bool? isManualExit = (bool?)VisitInfoCommand.Parameters["isManualExit"].Value; + } + 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"; @@ -339,13 +368,8 @@ namespace eDosStation VisitExitCommand.SetBoolParam("isAlarm", ep.hasAlarm); VisitExitCommand.SetBoolParam("isFault", ep.eDosHasFault); - - checkCon(true); VisitExitCommand.Connection = localConnection; - - - VisitExitCommand.ExecuteNonQuery(); } catch (System.Exception ex) @@ -419,7 +443,7 @@ namespace eDosStation else u.hasEPD = false; u.activeVisit = dr.IntOrNull("activeVisit"); u.isAgent = dr.BoolOrFalse("isAgent"); - u.AllOk = (!CheckUser || (u.AccessAllow == true && u.VisitIDLocked == 0)); + u.AllOk = !CheckUser && u.VisitIDLocked==0 && u.AccessAllow == true ; } else { diff --git a/eDosStation/EpdExit.xaml.cs b/eDosStation/EpdExit.xaml.cs index b5b2050..65d1618 100644 --- a/eDosStation/EpdExit.xaml.cs +++ b/eDosStation/EpdExit.xaml.cs @@ -108,6 +108,14 @@ namespace eDosStation return; } + //Check id EPD is manual exit + int Exited = dataInterface.VisitInfo(EpdVisitID); + if (Exited>0) + { + endWithMessage($"This EPD was already returned or had a manual exit (ID:{EpdVisitID % 100})"); + return; + } + //bool NoTimeout = false; diff --git a/eDosStation/Settings.xaml.cs b/eDosStation/Settings.xaml.cs index f196ab6..78527e5 100644 --- a/eDosStation/Settings.xaml.cs +++ b/eDosStation/Settings.xaml.cs @@ -1,6 +1,8 @@ -using System.Collections.ObjectModel; +using System; +using System.Collections.ObjectModel; using System.Text; using System.Windows; +using System.Windows.Threading; namespace eDosStation { @@ -28,6 +30,9 @@ namespace eDosStation public partial class Settings : Window { + public LSWDesfirePublic.CCard dfReader = null; + private System.Threading.Tasks.Task ReaderTask = null; + User _User; Station thisStation; ObservableCollection beepValues = new ObservableCollection(); ObservableCollection readerValues = new ObservableCollection(); @@ -80,6 +85,7 @@ namespace eDosStation private void Window_Loaded(object sender, RoutedEventArgs e) { + string eDosCom = devcon.FindEdosCom(); try { @@ -171,7 +177,6 @@ namespace eDosStation { MessageBox.Show($"SerINstallations err {ex.Message}"); } - try { tBeep.SelectedValue = thisStation.useBeep; @@ -189,13 +194,90 @@ namespace eDosStation } try { - bool rv = thisStation.dataInterface.checkCon(false); + bool rv = thisStation.dataInterface.checkCon(false); } catch (System.Exception ex) { MessageBox.Show($"Interface check {ex.Message}"); } - + //StartReader(); } + + #region BadgeReader + public void StartReader() + { + if (dfReader == null) + { + dfReader = new LSWDesfirePublic.CCard(); + dfReader.GetReaderList(); + if (dfReader.readersList.Contains(thisStation.Reader)) + { + dfReader.SetReader(thisStation.Reader); + dfReader.Badged += DFReader_Badged; + dfReader.BadgeTO += DfReader_BadgeTO; + dfReader.BadgeError += DfReader_BadgeError; + ReaderTask = dfReader.Wait(5000, 10); + } + else + { + StringBuilder er = new StringBuilder($"Badgelezer \"{thisStation.Reader}\" niet gevonden!.\nDeze lezers zijn beschikbaar:\n"); + dfReader.GetReaderList(); + foreach (string r in dfReader.readersList) er.AppendLine($"-> {r}"); + MessageBox.Show(er.ToString(), "Badge Lezer", MessageBoxButton.OK, MessageBoxImage.Exclamation); + dfReader.Dispose(); dfReader = null; + } + } + } + void CheckBadge() + { + thisStation.splunkLog?.KvSet(LSWLib.CLog.skeys.persID, _User.PersID); + thisStation.splunkLog?.WriteSplunkLog("CheckBadge", LSWLib.CLog.iseverity.info, _User.PersID.ToString(), null); + //Dispatcher.InvokeAsync(() => { ShowUserInfo(); }); + } + public void showBadge(int persID, string csn) + { + //CSN.Text = csn; + //Site.Text = string.Empty; + //Code.Text = persID.ToString(); + _User = thisStation.dataInterface.GetUser(null, persID.ToString(), true); + Dispatcher.InvokeAsync(CheckBadge, DispatcherPriority.Normal); + } + private void DfReader_BadgeError(LSWDesfirePublic.CCard Sender, LSWDesfirePublic.BadgeErrorEventArgs e) + { + // endPage(); + } + private void DfReader_BadgeTO(LSWDesfirePublic.CCard Sender, EventArgs e) + { + //this.Dispatcher.InvokeAsync(new Action(() => endPage()), DispatcherPriority.Normal); + } + private void DFReader_Badged(LSWDesfirePublic.CCard Sender, LSWDesfirePublic.BadgeEventArgs e) + { + if (e.PersID > 0) + this.Dispatcher.InvokeAsync(new Action(() => showBadge(e.PersID, e.UID)), DispatcherPriority.Background); + else + { + string msg = $"No PersID found on badge {e.UID}"; + MessageBox.Show(msg, "Error", MessageBoxButton.OK); + thisStation.splunkLog?.WriteSplunkLog("Badged", LSWLib.CLog.iseverity.warning, null, msg); + } + } + private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e) + { + //try + //{ + // if (dfReader != null ) + // { + // dfReader.WaitEnd(); + // System.Threading.Thread.Sleep(2000); + // dfReader.Dispose(); + // dfReader = null; + // } + //} + //catch (System.Exception ex) + //{ + // System.Diagnostics.Debug.WriteLine(ex.Message); + //} + } + #endregion } } diff --git a/syncEdosLocal/Program.cs b/syncEdosLocal/Program.cs index f433674..cb8bbdb 100644 --- a/syncEdosLocal/Program.cs +++ b/syncEdosLocal/Program.cs @@ -1,4 +1,5 @@ -using LSWLib; +using System.Runtime.InteropServices; +using LSWLib; using System; using System.Data; using System.Data.SqlClient; @@ -8,6 +9,7 @@ using spl = LSWLib.CLog; namespace syncEdosLocal { + class cResult { @@ -94,6 +96,12 @@ namespace syncEdosLocal class Program { + [DllImport("kernel32.dll")] static extern IntPtr GetConsoleWindow(); + [DllImport("user32.dll")] static extern bool ShowWindow(IntPtr hWnd, int nCmdShow); + + const int SW_HIDE = 0; + const int SW_SHOW = 5; + const string moduleName = "syncEdosLocal"; public static string pcName; public static int Verbose; @@ -322,9 +330,19 @@ namespace syncEdosLocal } } if (Verbose > 0) + { + var handle = GetConsoleWindow(); + ShowWindow(handle, SW_SHOW); oStream = new System.IO.StreamWriter(System.Console.OpenStandardOutput()); + } else + { oStream = null; // new System.IO.StreamWriter( System.IO.Stream.Null); + var handle = GetConsoleWindow(); + ShowWindow(handle, SW_HIDE); + //// Show + //ShowWindow(handle, SW_SHOW); + } pcName = System.Environment.MachineName; @@ -536,5 +554,11 @@ namespace syncEdosLocal { spLog.Connection_InfoMessageLog(e, ref messages); } + + static Program() + { + var handle = GetConsoleWindow(); + ShowWindow(handle, SW_HIDE); + } } }