From 461ea83d4afd62a18fa7ddaef6fcce5187a6feab Mon Sep 17 00:00:00 2001 From: Luc Vandenbroucke Date: Tue, 20 Apr 2021 15:04:43 +0200 Subject: [PATCH] sync ok --- eDosStation/App.Debug.config | 1 - eDosStation/App.config | 6 - .../{LocalRemote.cs => DataInterface.cs} | 152 +++++++----------- eDosStation/DataSet1.Designer.cs | 46 +----- eDosStation/DataSet1.xsd | 19 +-- eDosStation/EntryBadge.xaml.cs | 49 +++--- eDosStation/EpdExit.xaml.cs | 6 +- eDosStation/MainWindow.xaml.cs | 115 +++++++------ eDosStation/Properties/Settings.Designer.cs | 22 --- eDosStation/Properties/Settings.settings | 16 -- eDosStation/Settings.xaml.cs | 7 +- eDosStation/Station.cs | 18 ++- eDosStation/eDosStation.csproj | 2 +- syncEdosLocal/Program.cs | 6 +- 14 files changed, 181 insertions(+), 284 deletions(-) rename eDosStation/{LocalRemote.cs => DataInterface.cs} (73%) diff --git a/eDosStation/App.Debug.config b/eDosStation/App.Debug.config index 325a7d6..c8aecc1 100644 --- a/eDosStation/App.Debug.config +++ b/eDosStation/App.Debug.config @@ -2,7 +2,6 @@ - diff --git a/eDosStation/App.config b/eDosStation/App.config index 8b46286..9ba3bdf 100644 --- a/eDosStation/App.config +++ b/eDosStation/App.config @@ -6,12 +6,6 @@ - - diff --git a/eDosStation/LocalRemote.cs b/eDosStation/DataInterface.cs similarity index 73% rename from eDosStation/LocalRemote.cs rename to eDosStation/DataInterface.cs index 62c4124..df36aac 100644 --- a/eDosStation/LocalRemote.cs +++ b/eDosStation/DataInterface.cs @@ -9,21 +9,17 @@ using System.Windows.Navigation; namespace eDosStation { - public static class LocalRemote + public class DataInterface { - static public int ID_Station; - static public bool isLocal = false; - static public string serverConstr; - static public string serverTestConstr; - static public string localConstr; - static public string currentConStr; - static public System.Data.SqlClient.SqlConnection Connection; - static public System.Data.SqlClient.SqlConnection SequenceConnection; - static public System.Data.SqlClient.SqlCommand VisitInitCommand; + public int ID_Station; + public bool isLocal = false; + private string currentConStr; + public System.Data.SqlClient.SqlConnection localConnection; + public System.Data.SqlClient.SqlCommand VisitInitCommand; public static SqlCommand VisitExitCommand; public static SqlCommand NextIDCommand; - public static SqlCommand LastLocalIDCommand; - static public DataSet1.CommentOnEventDataTable dtCOE; + public static SqlCommand LastIDCommand; + public DataSet1.CommentOnEventDataTable dtCOE; public static int? NextID() { @@ -36,62 +32,44 @@ namespace eDosStation public static int? LastID() { int? lastValue = null; - if (NextIDCommand.Connection.State == ConnectionState.Closed) LastLocalIDCommand.Connection.Open(); - lastValue = LastLocalIDCommand.ExecuteScalar() as int?; + if (NextIDCommand.Connection.State == ConnectionState.Closed) LastIDCommand.Connection.Open(); + lastValue = LastIDCommand.ExecuteScalar() as int?; return lastValue; } - static public bool checkCon(bool leaveOpen = false) + /// + /// 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) { - if (Connection != null && Connection.State == System.Data.ConnectionState.Open) return true; - bool rv = false; - var cs = new System.Data.SqlClient.SqlConnectionStringBuilder(serverTestConstr); -#if DEBUG - cs.ConnectTimeout = 10; -#endif - isLocal = false; - Connection = new System.Data.SqlClient.SqlConnection(cs.ConnectionString); + if (localConnection != null && localConnection.State == System.Data.ConnectionState.Open) return true; try { - Connection.Open(); - } - catch { } - if (Connection.State != System.Data.ConnectionState.Open) - { - switchLocal(true); //wijzigt currentConStr als isLocal niet al gezet is. - } - else - { - currentConStr = serverConstr; - isLocal = false; + if (localConnection == null || string.IsNullOrEmpty(localConnection.ConnectionString)) localConnection = new SqlConnection(currentConStr); + + localConnection.Open(); rv = true; } - if (!rv) - try - { - Connection.ConnectionString = currentConStr; - Connection.Open(); - rv = true; - } - catch - { - Connection.Dispose(); - Connection = null; - } - if (rv && !leaveOpen) Connection?.Close(); + catch (System.Exception ex) + { + System.Windows.MessageBox.Show($"Opening '{currentConStr}' error :{ex.Message}"); + } + if (rv && !leaveOpen) localConnection?.Close(); return rv; } - internal static void SetStation(int curIDStation) + internal void SetStation(int curIDStation) { ID_Station = curIDStation; - LastLocalIDCommand.Parameters["ID_Station"].Value = curIDStation; + LastIDCommand.Parameters["ID_Station"].Value = curIDStation; VisitInitCommand.Parameters["ID_Station"].Value = curIDStation; } static public void first() { - var cb = new System.Data.SqlClient.SqlConnectionStringBuilder(Properties.Settings.Default.eDosConnectionString); + var cb = new System.Data.SqlClient.SqlConnectionStringBuilder(Properties.Settings.Default.localConnectionString); if (string.IsNullOrEmpty(cb.Password)) { var f = new AskPwd(); @@ -103,71 +81,56 @@ namespace eDosStation } } - static public void init() + private void init() { first(); - localConstr = System.Configuration.ConfigurationManager.ConnectionStrings["eDosStation.Properties.Settings.localConnectionString"].ConnectionString; - SequenceConnection = new SqlConnection(localConstr); - NextIDCommand = new SqlCommand("SELECT NEXT VALUE FOR VisitSequence as VisitID", SequenceConnection); - serverConstr = System.Configuration.ConfigurationManager.ConnectionStrings["eDosStation.Properties.Settings.eDosConnectionString"].ConnectionString; - var cb = new System.Data.SqlClient.SqlConnectionStringBuilder(serverConstr); - cb.ConnectTimeout = 5; - serverTestConstr = cb.ConnectionString; - checkCon(false); + currentConStr = System.Configuration.ConfigurationManager.ConnectionStrings["eDosStation.Properties.Settings.localConnectionString"].ConnectionString; + localConnection = new SqlConnection(currentConStr); + NextIDCommand = new SqlCommand("SELECT NEXT VALUE FOR VisitSequence as VisitID", localConnection); + isLocal = true; MakeCommands(); + bool rv= checkCon(false); } - static void switchLocal(bool force=false) + public DataInterface() { - if (force || !isLocal) - { - isLocal = true; - currentConStr = localConstr; - } + init(); } - static void switchServer() - { - if (isLocal) - { - isLocal = false; - currentConStr = System.Configuration.ConfigurationManager.ConnectionStrings["eDosStation.Properties.Settings.eDosConnectionString"].ConnectionString; - } - } - - static DataSet1TableAdapters.GetTaskInfoTableAdapter TaskInfoTa() + + DataSet1TableAdapters.GetTaskInfoTableAdapter TaskInfoTa() { var ta = new DataSet1TableAdapters.GetTaskInfoTableAdapter(); ta.Connection.ConnectionString = currentConStr; return ta; } - static DataSet1TableAdapters.GetTaskListTableAdapter TaskListTA() + DataSet1TableAdapters.GetTaskListTableAdapter TaskListTA() { var ta = new DataSet1TableAdapters.GetTaskListTableAdapter(); ta.Connection.ConnectionString = currentConStr; return ta; } - static DataSet1TableAdapters.CommentOnEventTableAdapter CommentTA() + DataSet1TableAdapters.CommentOnEventTableAdapter CommentTA() { var ta = new DataSet1TableAdapters.CommentOnEventTableAdapter(); ta.Connection.ConnectionString = currentConStr; return ta; } - static public System.Data.SqlClient.SqlConnection getCon(bool LeaveOpen) + public System.Data.SqlClient.SqlConnection getCon(bool LeaveOpen) { checkCon(LeaveOpen); - return Connection; + return localConnection; } - static void MakeCommands() + void MakeCommands() { - LastLocalIDCommand = new SqlCommand("VisitIDLast", SequenceConnection); - LastLocalIDCommand.CommandType = CommandType.StoredProcedure; - var pa = new System.Data.SqlClient.SqlParameter("ID_Station", SqlDbType.Int, 4); LastLocalIDCommand.Parameters.Add(pa); + 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); - VisitInitCommand = new System.Data.SqlClient.SqlCommand("VisitInit", Connection); + VisitInitCommand = new System.Data.SqlClient.SqlCommand("VisitInit", localConnection); VisitInitCommand.CommandType = System.Data.CommandType.StoredProcedure; pa = new System.Data.SqlClient.SqlParameter("ID_Station", SqlDbType.Int, 4); VisitInitCommand.Parameters.Add(pa); pa = new System.Data.SqlClient.SqlParameter("ID_Visit", SqlDbType.Int, 4); pa.Direction = ParameterDirection.Input; VisitInitCommand.Parameters.Add(pa); @@ -179,7 +142,7 @@ namespace eDosStation pa = new System.Data.SqlClient.SqlParameter("ENTRY_EPD_CLOCK", SqlDbType.Int, 4); VisitInitCommand.Parameters.Add(pa); pa = new System.Data.SqlClient.SqlParameter("EPDVisitID", SqlDbType.Int, 4); pa.Direction = ParameterDirection.Output; VisitInitCommand.Parameters.Add(pa); - VisitExitCommand = new SqlCommand("VisitExit", Connection); + VisitExitCommand = new SqlCommand("VisitExit", localConnection); VisitExitCommand.CommandType = CommandType.StoredProcedure; pa = new System.Data.SqlClient.SqlParameter("EPDVisitID", SqlDbType.Int, 4); VisitExitCommand.Parameters.Add(pa); pa = new System.Data.SqlClient.SqlParameter("HP07", SqlDbType.Float); VisitExitCommand.Parameters.Add(pa); @@ -210,10 +173,9 @@ namespace eDosStation pa = new System.Data.SqlClient.SqlParameter("errorStatus", SqlDbType.Int); VisitExitCommand.Parameters.Add(pa); pa = new System.Data.SqlClient.SqlParameter("operatingStatus", SqlDbType.Int); VisitExitCommand.Parameters.Add(pa); pa = new System.Data.SqlClient.SqlParameter("EXIT_EPD_CLOCK", SqlDbType.Int, 4); VisitExitCommand.Parameters.Add(pa); - } - static public void VisitExit(int EpdVisitID, EpdBaseClr.Epd2 ep) + public void VisitExit(int EpdVisitID, EpdBaseClr.Epd2 ep) { VisitExitCommand.Parameters["EPDVisitID"].Value = EpdVisitID; VisitExitCommand.Parameters["HP07"].Value = ep.Hp07; @@ -258,12 +220,12 @@ namespace eDosStation VisitExitCommand.Parameters["EXIT_EPD_CLOCK"].Value = ep.CountsClock; checkCon(true); - VisitExitCommand.Connection = Connection; + VisitExitCommand.Connection = localConnection; VisitExitCommand.ExecuteNonQuery(); - Connection.Close(); + localConnection.Close(); } - static public void FillComment() + public void FillComment() { if (dtCOE == null) dtCOE = new DataSet1.CommentOnEventDataTable(); using (var dt = new DataSet1TableAdapters.CommentOnEventTableAdapter()) @@ -273,12 +235,12 @@ namespace eDosStation } } - static public DataSet1.CommentOnEventRow GetCommentOnEventRow(int id) + public DataSet1.CommentOnEventRow GetCommentOnEventRow(int id) { return dtCOE.FindByID_CommnentOnEvent(id); } - static public void FillTaskInfo(User _User, DataSet1 dataSet1) + public void FillTaskInfo(User _User, DataSet1 dataSet1) { using (var dataSet1GetTaskInfoTableAdapter = new eDosStation.DataSet1TableAdapters.GetTaskInfoTableAdapter()) { @@ -287,19 +249,19 @@ namespace eDosStation } } - static public User GetUser( string CSN, string Code) + public User GetUser( string CSN, string Code) { User u = new User(); object[] Values = null; if (int.TryParse(Code,out int PersID)) - using (var cmd = new SqlCommand("GetPersonInfo", Connection)) + using (var cmd = new SqlCommand("GetPersonInfo", localConnection)) { cmd.CommandType = System.Data.CommandType.StoredProcedure; cmd.Parameters.AddWithValue("csn", CSN); cmd.Parameters.AddWithValue("PersID", PersID); //if (!string.IsNullOrWhiteSpace(Code)) cmd.Parameters.AddWithValue("Badge", Code); checkCon(true); - cmd.Connection = Connection; + cmd.Connection = localConnection; var rs = cmd.ExecuteReader(System.Data.CommandBehavior.SingleRow); if (rs.HasRows && rs.Read()) { diff --git a/eDosStation/DataSet1.Designer.cs b/eDosStation/DataSet1.Designer.cs index 2289ed9..f957b55 100644 --- a/eDosStation/DataSet1.Designer.cs +++ b/eDosStation/DataSet1.Designer.cs @@ -854,6 +854,7 @@ namespace eDosStation { this.columnID_Task.ReadOnly = true; this.columnID_Task.Unique = true; this.columnTask_Name.MaxLength = 2147483647; + this.columnTaskDescription.AllowDBNull = false; this.columnTaskDescription.ReadOnly = true; this.columnTaskDescription.MaxLength = 50; this.columnEPDRad.AllowDBNull = false; @@ -1194,6 +1195,7 @@ namespace eDosStation { this.columnID_Task.ReadOnly = true; this.columnID_Task.Unique = true; this.columnTask_Name.MaxLength = 2147483647; + this.columnTaskDescription.AllowDBNull = false; this.columnTaskDescription.ReadOnly = true; this.columnTaskDescription.MaxLength = 50; this.columnEPDRad.AllowDBNull = false; @@ -1752,12 +1754,7 @@ namespace eDosStation { [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Data.Design.TypedDataSetGenerator", "16.0.0.0")] public string TaskDescription { get { - try { - return ((string)(this[this.tableGetTaskInfo.TaskDescriptionColumn])); - } - catch (global::System.InvalidCastException e) { - throw new global::System.Data.StrongTypingException("The value for column \'TaskDescription\' in table \'GetTaskInfo\' is DBNull.", e); - } + return ((string)(this[this.tableGetTaskInfo.TaskDescriptionColumn])); } set { this[this.tableGetTaskInfo.TaskDescriptionColumn] = value; @@ -2131,18 +2128,6 @@ namespace eDosStation { this[this.tableGetTaskInfo.Task_NameColumn] = global::System.Convert.DBNull; } - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Data.Design.TypedDataSetGenerator", "16.0.0.0")] - public bool IsTaskDescriptionNull() { - return this.IsNull(this.tableGetTaskInfo.TaskDescriptionColumn); - } - - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Data.Design.TypedDataSetGenerator", "16.0.0.0")] - public void SetTaskDescriptionNull() { - this[this.tableGetTaskInfo.TaskDescriptionColumn] = global::System.Convert.DBNull; - } - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Data.Design.TypedDataSetGenerator", "16.0.0.0")] public bool IsID_AlarmEPDNull() { @@ -2461,12 +2446,7 @@ namespace eDosStation { [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Data.Design.TypedDataSetGenerator", "16.0.0.0")] public string TaskDescription { get { - try { - return ((string)(this[this.tableGetTaskList.TaskDescriptionColumn])); - } - catch (global::System.InvalidCastException e) { - throw new global::System.Data.StrongTypingException("The value for column \'TaskDescription\' in table \'GetTaskList\' is DBNull.", e); - } + return ((string)(this[this.tableGetTaskList.TaskDescriptionColumn])); } set { this[this.tableGetTaskList.TaskDescriptionColumn] = value; @@ -2519,18 +2499,6 @@ namespace eDosStation { public void SetTask_NameNull() { this[this.tableGetTaskList.Task_NameColumn] = global::System.Convert.DBNull; } - - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Data.Design.TypedDataSetGenerator", "16.0.0.0")] - public bool IsTaskDescriptionNull() { - return this.IsNull(this.tableGetTaskList.TaskDescriptionColumn); - } - - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Data.Design.TypedDataSetGenerator", "16.0.0.0")] - public void SetTaskDescriptionNull() { - this[this.tableGetTaskList.TaskDescriptionColumn] = global::System.Convert.DBNull; - } } /// @@ -2987,7 +2955,7 @@ namespace eDosStation.DataSet1TableAdapters { [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Data.Design.TypedDataSetGenerator", "16.0.0.0")] private void InitConnection() { this._connection = new global::System.Data.SqlClient.SqlConnection(); - this._connection.ConnectionString = global::eDosStation.Properties.Settings.Default.eDosConnectionString; + this._connection.ConnectionString = global::eDosStation.Properties.Settings.Default.localConnectionString; } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -3186,7 +3154,7 @@ namespace eDosStation.DataSet1TableAdapters { [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Data.Design.TypedDataSetGenerator", "16.0.0.0")] private void InitConnection() { this._connection = new global::System.Data.SqlClient.SqlConnection(); - this._connection.ConnectionString = global::eDosStation.Properties.Settings.Default.eDosConnectionString; + this._connection.ConnectionString = global::eDosStation.Properties.Settings.Default.localConnectionString; } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -3360,7 +3328,7 @@ namespace eDosStation.DataSet1TableAdapters { [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Data.Design.TypedDataSetGenerator", "16.0.0.0")] private void InitConnection() { this._connection = new global::System.Data.SqlClient.SqlConnection(); - this._connection.ConnectionString = global::eDosStation.Properties.Settings.Default.eDosConnectionString; + this._connection.ConnectionString = global::eDosStation.Properties.Settings.Default.localConnectionString; } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] diff --git a/eDosStation/DataSet1.xsd b/eDosStation/DataSet1.xsd index c588db9..49735bb 100644 --- a/eDosStation/DataSet1.xsd +++ b/eDosStation/DataSet1.xsd @@ -2,14 +2,15 @@ - + + - + dbo.GetTaskInfo @@ -54,7 +55,7 @@ - + dbo.GetTaskList @@ -77,7 +78,7 @@ - + dbo.CommentOnEventSelect @@ -107,7 +108,7 @@ - + @@ -120,7 +121,7 @@ - + @@ -169,7 +170,7 @@ - + @@ -182,7 +183,7 @@ - + @@ -199,7 +200,7 @@ - + diff --git a/eDosStation/EntryBadge.xaml.cs b/eDosStation/EntryBadge.xaml.cs index d107791..d145c86 100644 --- a/eDosStation/EntryBadge.xaml.cs +++ b/eDosStation/EntryBadge.xaml.cs @@ -22,6 +22,8 @@ namespace eDosStation int Search, UserSeconds; Boolean Inst1 = false, Inst2 = false; + private DataInterface dataInterface; + public static LSWDesfirePublic.CCard dfReader; //System.Threading.Thread t; //bool nextCSN = false; @@ -41,6 +43,7 @@ namespace eDosStation public EntryBadge(EpdBaseClr.Epd2 curEP, Station curStation) { + dataInterface = curStation.dataInterface; ep=curEP; thisStation = curStation; InitializeComponent(); @@ -126,34 +129,34 @@ namespace eDosStation private void DoEPD() { int? StationVisitID = null; - int? ID_Visit= LocalRemote.NextID(); + int? ID_Visit= DataInterface.NextID(); if (ID_Visit.HasValue && LoadDoses()) { bool isBG = (ep.epdType != 3); //3 = zwarte 0=grijs - var co = LocalRemote.getCon(true); - LocalRemote.VisitInitCommand.Connection = co; - LocalRemote.VisitInitCommand.Parameters["ID_Station"].Value = thisStation.ID_Station; - LocalRemote.VisitInitCommand.Parameters["ID_Visit"].Value = ID_Visit; - LocalRemote.VisitInitCommand.Parameters["PersID"].Value = _User.PersID; - LocalRemote.VisitInitCommand.Parameters["ID_Task"].Value = CurTaskRow.ID_Task; - LocalRemote.VisitInitCommand.Parameters["Inst_CODE"].Value = CurTaskRow.Inst_CODE; - LocalRemote.VisitInitCommand.Parameters["EPD_InternalID"].Value = (int)ep.EpdID; - LocalRemote.VisitInitCommand.Parameters["isBG"].Value = isBG; - LocalRemote.VisitInitCommand.Parameters["ENTRY_EPD_CLOCK"].Value = ep.CountsClock; + var co = dataInterface.getCon(true); + dataInterface.VisitInitCommand.Connection = co; + dataInterface.VisitInitCommand.Parameters["ID_Station"].Value = thisStation.ID_Station; + dataInterface.VisitInitCommand.Parameters["ID_Visit"].Value = ID_Visit; + dataInterface.VisitInitCommand.Parameters["PersID"].Value = _User.PersID; + dataInterface.VisitInitCommand.Parameters["ID_Task"].Value = CurTaskRow.ID_Task; + dataInterface.VisitInitCommand.Parameters["Inst_CODE"].Value = CurTaskRow.Inst_CODE; + dataInterface.VisitInitCommand.Parameters["EPD_InternalID"].Value = (int)ep.EpdID; + dataInterface.VisitInitCommand.Parameters["isBG"].Value = isBG; + dataInterface.VisitInitCommand.Parameters["ENTRY_EPD_CLOCK"].Value = ep.CountsClock; using (var l = new SqlLog()) try { - LocalRemote.VisitInitCommand.ExecuteNonQuery(); - l.LogCommand(LocalRemote.VisitInitCommand); + dataInterface.VisitInitCommand.ExecuteNonQuery(); + l.LogCommand(dataInterface.VisitInitCommand); } catch (System.Exception ex) { l.LogCommand(ex.Message); MessageBox.Show(ex.Message); } - StationVisitID = (int?)LocalRemote.VisitInitCommand.Parameters["EPDVisitID"].Value; + StationVisitID = (int?)dataInterface.VisitInitCommand.Parameters["EPDVisitID"].Value; co.Close(); int rv = ep.PrepareForIssue(); @@ -266,7 +269,7 @@ namespace eDosStation public string getCommentUnknown() { StringBuilder res = new StringBuilder(); - var r = LocalRemote.GetCommentOnEventRow(3); + var r = dataInterface.GetCommentOnEventRow(3); res.AppendLine(r.Comment_NL).Replace("\\n", "\n"); res.AppendLine("---"); res.AppendLine(r.Comment_FR).Replace("\\n", "\n"); @@ -280,7 +283,7 @@ namespace eDosStation { string res=string.Empty; if (!string.IsNullOrWhiteSpace(prefix)) res = prefix + "\n"; - var r = LocalRemote.GetCommentOnEventRow(id); + var r = dataInterface.GetCommentOnEventRow(id); string l = _User?.Language ?? "E"; if (r!=null) switch (l) @@ -356,14 +359,14 @@ namespace eDosStation { Naam.Text = _User.FirstName + " " + _User.LastName; eDosStation.DataSet1 dataSet1 = ((eDosStation.DataSet1)(this.FindResource("dataSet1"))); - LocalRemote.FillTaskInfo(_User, dataSet1); + dataInterface.FillTaskInfo(_User, dataSet1); tbTask.IsSelected = true; bool isAlara = (cbAlara.IsChecked == true); SetFilter(isAlara); } void CheckBadge() { - _User = LocalRemote.GetUser(CSN.Text, Code.Text); + _User = dataInterface.GetUser(CSN.Text, Code.Text); ShowUserInfo(); //AskTask(); } public void showBadge(int persID, string csn) @@ -492,7 +495,7 @@ namespace eDosStation private void BTestPerson_Click(object sender, RoutedEventArgs e) { Button b = sender as Button; - _User = LocalRemote.GetUser("TP"+b.Tag.ToString().ToUpper(), ""); + _User = dataInterface.GetUser("TP"+b.Tag.ToString().ToUpper(), ""); ShowUserInfo(); //AskTask(); } @@ -530,7 +533,7 @@ namespace eDosStation } private void Window_Loaded(object sender, RoutedEventArgs e) { - LocalRemote.checkCon(); + dataInterface.checkCon(); EpdFound = false; initialising = true; tbEntry.IsSelected = true; @@ -548,7 +551,7 @@ namespace eDosStation cbInst2.IsChecked = Inst2; } - LocalRemote.FillComment(); + dataInterface.FillComment(); //string TestCSN = null; // thisStation.TestCSN; initialising = false; @@ -568,9 +571,9 @@ namespace eDosStation } else { - StringBuilder er = new StringBuilder($"Badgelezer \"{thisStation.Reader}\" niet gevonden!.\nDeze zijn beschikbaar:\n"); + 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); + foreach (string r in dfReader.readersList) er.AppendLine($"-> {r}"); MessageBox.Show(er.ToString(), "Badge Lezer", MessageBoxButton.OK, MessageBoxImage.Exclamation); dfReader.Dispose(); dfReader = null; } diff --git a/eDosStation/EpdExit.xaml.cs b/eDosStation/EpdExit.xaml.cs index bf3d076..e035e55 100644 --- a/eDosStation/EpdExit.xaml.cs +++ b/eDosStation/EpdExit.xaml.cs @@ -22,6 +22,7 @@ namespace eDosStation /// public partial class EpdExit: Window { + DataInterface dataInterface; Station thisStation; EpdBaseClr.Epd2 ep; bool EpdFound = false; @@ -38,6 +39,7 @@ namespace eDosStation InitializeComponent(); ep = curEP; thisStation = curStation; + dataInterface = curStation.dataInterface; } private void ShowAlarm() @@ -142,8 +144,8 @@ namespace eDosStation var l = new SqlLog(); try { - LocalRemote.VisitExit(EpdVisitID, ep); - l.LogCommand(LocalRemote.VisitExitCommand); + dataInterface.VisitExit(EpdVisitID, ep); + l.LogCommand(DataInterface.VisitExitCommand); } catch (System.Exception ex) { diff --git a/eDosStation/MainWindow.xaml.cs b/eDosStation/MainWindow.xaml.cs index fdfb991..c1f1ac2 100644 --- a/eDosStation/MainWindow.xaml.cs +++ b/eDosStation/MainWindow.xaml.cs @@ -20,8 +20,9 @@ namespace eDosStation /// public partial class MainWindow : Window { - public Station thisStation ; - public EpdBaseClr.Epd2 ep=null; + public DataInterface dataInterface; + public Station thisStation; + public EpdBaseClr.Epd2 ep = null; #if SimulateEPD public SimulateData simulData = new SimulateData(); @@ -59,14 +60,14 @@ namespace eDosStation private void MenuItem_Click(object sender, RoutedEventArgs e) { - Settings s = new Settings(); + Settings s = new Settings( thisStation); s.ShowDialog(); } private void setLocalStatus() { - if (LocalRemote.isLocal) + if (dataInterface.isLocal) { Status.Content = "*** Offline ***"; Status.Foreground = Brushes.Yellow; @@ -79,75 +80,73 @@ namespace eDosStation Status.Background = Brushes.White; } } + + private void setErrorStatus(string errMsg) + { + Status.Content = $"*** Error {errMsg} ***"; + Status.Foreground = Brushes.Yellow; + Status.Background = Brushes.Red; + } + private void Window_Loaded(object sender, RoutedEventArgs e) { - var cb = new System.Data.SqlClient.SqlConnectionStringBuilder(Properties.Settings.Default.eDosConnectionString); - if (string.IsNullOrEmpty(cb.Password)) + bool ok = true; + string errMsg = string.Empty; + + dataInterface = new DataInterface(); + try { - 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); - Close(); + thisStation = new Station(dataInterface, string.Empty); } - else + catch (System.Exception ex) { - bool ok = true; - LocalRemote.init(); - + errMsg = $"Startup error {ex.Message} "; + MessageBox.Show(errMsg); + ok = false; + } + if (ok && thisStation.Error > 0) + { + errMsg = $"Startup error {thisStation.ErrorMessage} "; + MessageBox.Show(errMsg); + ok = false; + } + + if (ok) try { - thisStation = new Station(string.Empty); - LocalRemote.SetStation(thisStation.ID_Station); + //var sp = new System.IO.Ports.SerialPort($"com{thisStation.ComPort}"); + //sp.BaudRate = 9600; + //sp.Parity = System.IO.Ports.Parity.None; + //sp.StopBits = System.IO.Ports.StopBits.One; + //sp.Open(); + //sp.DiscardInBuffer(); + //sp.Close(); +#if SimulateEPD + thisStation.ComPort = 0; +#endif + ep = new EpdBaseClr.Epd2(thisStation.ComPort); } catch (System.Exception ex) { - MessageBox.Show($"Startup error {ex.Message} "); + errMsg = $"Edp software error {ex.Message}"; + MessageBox.Show(errMsg); ok = false; } - if (ok && thisStation.Error > 0) + if (ok) + { + if (thisStation.insComments.Length > 2) { - MessageBox.Show($"Startup error {thisStation.ErrorMessage} "); - ok = false; + InstMessage w = new InstMessage(thisStation.tbComments); + w.ShowDialog(); + ibComment.Child = thisStation.tbComments; + ibComment.Visibility = Visibility.Visible; } - - if (ok) - try - { - //var sp = new System.IO.Ports.SerialPort($"com{thisStation.ComPort}"); - //sp.BaudRate = 9600; - //sp.Parity = System.IO.Ports.Parity.None; - //sp.StopBits = System.IO.Ports.StopBits.One; - //sp.Open(); - //sp.DiscardInBuffer(); - //sp.Close(); -#if SimulateEPD - thisStation.ComPort = 0; -#endif - ep = new EpdBaseClr.Epd2(thisStation.ComPort); - } - catch (System.Exception ex) - { - MessageBox.Show($"Edp software error {ex.Message}"); - ok = false; - } - if (ok) - { - if (thisStation.insComments.Length > 2) - { - InstMessage w = new InstMessage(thisStation.tbComments); - w.ShowDialog(); - ibComment.Child = thisStation.tbComments; - ibComment.Visibility = Visibility.Visible; - } - else - ibComment.Visibility = Visibility.Hidden; - } - // nog niet in db - + else + ibComment.Visibility = Visibility.Hidden; + setLocalStatus(); } - setLocalStatus(); + else + setErrorStatus(errMsg); } private void MEnc_Click(object sender, RoutedEventArgs e) diff --git a/eDosStation/Properties/Settings.Designer.cs b/eDosStation/Properties/Settings.Designer.cs index 7a74263..ea4182d 100644 --- a/eDosStation/Properties/Settings.Designer.cs +++ b/eDosStation/Properties/Settings.Designer.cs @@ -107,28 +107,6 @@ namespace eDosStation.Properties { } } - [global::System.Configuration.ApplicationScopedSettingAttribute()] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Configuration.SpecialSettingAttribute(global::System.Configuration.SpecialSetting.ConnectionString)] - [global::System.Configuration.DefaultSettingValueAttribute("Data Source=scksrv23;Initial Catalog=master;Integrated Security=True;TrustServerC" + - "ertificate=True;Application Name=eDosStation")] - public string masterConnectionString { - get { - return ((string)(this["masterConnectionString"])); - } - } - - [global::System.Configuration.ApplicationScopedSettingAttribute()] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Configuration.SpecialSettingAttribute(global::System.Configuration.SpecialSetting.ConnectionString)] - [global::System.Configuration.DefaultSettingValueAttribute("Data Source=HPHDB;Initial Catalog=eDosx;User ID=eDosStation;Password=Infopla+8;Tr" + - "ustServerCertificate=True;Application Name=eDosStation")] - public string eDosConnectionString { - get { - return ((string)(this["eDosConnectionString"])); - } - } - [global::System.Configuration.ApplicationScopedSettingAttribute()] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Configuration.SpecialSettingAttribute(global::System.Configuration.SpecialSetting.ConnectionString)] diff --git a/eDosStation/Properties/Settings.settings b/eDosStation/Properties/Settings.settings index a37eb7b..28f030a 100644 --- a/eDosStation/Properties/Settings.settings +++ b/eDosStation/Properties/Settings.settings @@ -23,22 +23,6 @@ True - - <?xml version="1.0" encoding="utf-16"?> -<SerializableConnectionString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> - <ConnectionString>Data Source=scksrv23;Initial Catalog=master;Integrated Security=True;TrustServerCertificate=True;Application Name=eDosStation</ConnectionString> - <ProviderName>System.Data.SqlClient</ProviderName> -</SerializableConnectionString> - Data Source=scksrv23;Initial Catalog=master;Integrated Security=True;TrustServerCertificate=True;Application Name=eDosStation - - - <?xml version="1.0" encoding="utf-16"?> -<SerializableConnectionString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> - <ConnectionString>Data Source=HPHDB;Initial Catalog=eDosx;User ID=eDosStation;Password=Infopla+8;TrustServerCertificate=True;Application Name=eDosStation</ConnectionString> - <ProviderName>System.Data.SqlClient</ProviderName> -</SerializableConnectionString> - Data Source=HPHDB;Initial Catalog=eDosx;User ID=eDosStation;Password=Infopla+8;TrustServerCertificate=True;Application Name=eDosStation - <?xml version="1.0" encoding="utf-16"?> <SerializableConnectionString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> diff --git a/eDosStation/Settings.xaml.cs b/eDosStation/Settings.xaml.cs index 58dc8ef..9cd634d 100644 --- a/eDosStation/Settings.xaml.cs +++ b/eDosStation/Settings.xaml.cs @@ -20,8 +20,9 @@ namespace eDosStation public partial class Settings : Window { Station thisStation; - public Settings() + public Settings( Station tStation) { + thisStation = tStation; InitializeComponent(); } @@ -33,7 +34,7 @@ namespace eDosStation thisStation.Inst_Name1= tInsName1.Text; thisStation.Inst_Name2 = tInsName2.Text; thisStation.TestCSN = tTestCSN.Text; - thisStation.Reader = cbReaders.Text; + thisStation.Reader = cbReaders.Text; thisStation.Update(); this.Close(); if (thisStation.Error>0) @@ -49,7 +50,6 @@ namespace eDosStation private void Window_Loaded(object sender, RoutedEventArgs e) { - thisStation = new Station(string.Empty); tComPort.Text = thisStation.ComPort.ToString(); tInsCode1.Text = thisStation.Inst_CODE1.ToString(); tInsCode2.Text = thisStation.Inst_CODE2.ToString(); @@ -57,6 +57,7 @@ namespace eDosStation tInsName2.Text = thisStation.Inst_Name2.ToString(); tTestCSN.Text = thisStation.TestCSN; + bool rv = thisStation.dataInterface.checkCon(false); var a = new LSWDesfirePublic.CCard(); a.GetReaderList(); cbReaders.Items.Clear(); diff --git a/eDosStation/Station.cs b/eDosStation/Station.cs index be0696b..b039828 100644 --- a/eDosStation/Station.cs +++ b/eDosStation/Station.cs @@ -11,7 +11,6 @@ namespace eDosStation { public class Station { - public int ID_Station { get; set; } public int ComPort { get; set; } public int Inst_CODE1 { get; set; } @@ -27,9 +26,11 @@ namespace eDosStation public string ErrorMessage; public StringBuilder insComments; public TextBlock tbComments; + public DataInterface dataInterface; - public Station(string Station) + public Station(DataInterface mDataInterface, string Station) { + dataInterface = mDataInterface; Error = 0; ErrorMessage = string.Empty; ComPort = 0; @@ -45,7 +46,7 @@ namespace eDosStation tbComments.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch; tbComments.TextAlignment = System.Windows.TextAlignment.Center; - using (var co = LocalRemote.getCon(true)) + var co = dataInterface.getCon(true); // No dispose { using (var cmd = new SqlCommand("StationSettingsSelect", co)) { @@ -87,6 +88,7 @@ namespace eDosStation } } + dataInterface.SetStation(ID_Station); if (Error == 0) using (var cmd2 = new SqlCommand("GetInstallationsComments", co)) { @@ -119,20 +121,19 @@ namespace eDosStation ErrorMessage = ex.Message; } } - co.Close(); + co?.Close(); } } public void Update() { - using (var co = new SqlConnection(Properties.Settings.Default.eDosConnectionString)) + var co = dataInterface.getCon(true); { using (var cmd = new SqlCommand("StationSettingsUpdate", co)) { cmd.CommandType = System.Data.CommandType.StoredProcedure; - co.Open(); cmd.Parameters.AddWithValue("ComPort", ComPort); - + if (!string.IsNullOrEmpty(Inst_Name1) && Inst_CODE1 > 0) { cmd.Parameters.AddWithValue("Inst_CODE1", Inst_CODE1); @@ -147,6 +148,9 @@ namespace eDosStation if (!string.IsNullOrEmpty(TestCSN)) cmd.Parameters.AddWithValue("TestCSN", TestCSN); + if (!string.IsNullOrEmpty(Reader)) + cmd.Parameters.AddWithValue("@Reader", Reader); + try { cmd.ExecuteNonQuery(); diff --git a/eDosStation/eDosStation.csproj b/eDosStation/eDosStation.csproj index d06adb3..5ccb0a3 100644 --- a/eDosStation/eDosStation.csproj +++ b/eDosStation/eDosStation.csproj @@ -158,7 +158,7 @@ InstMessage.xaml - + Settings.xaml diff --git a/syncEdosLocal/Program.cs b/syncEdosLocal/Program.cs index 0b294fc..e398cc2 100644 --- a/syncEdosLocal/Program.cs +++ b/syncEdosLocal/Program.cs @@ -96,7 +96,8 @@ namespace syncEdosLocal foreach (DataRow rtr in dtTables.Rows) { ucmd.Parameters["OBJECT_ID"].Value = (int)rtr[0]; - dest = rtr[1].ToString(); + string src=rtr[1].ToString(); + dest = rtr[2].ToString(); var x = rtr.GetChildRows(dtActions.ParentRelations[0]); Task = $"Table {dest}"; System.Console.WriteLine($"*** Step {rtr[1].ToString()}"); @@ -139,7 +140,7 @@ namespace syncEdosLocal } int cnt = 0; - qry = LSWLib.SqlCommands.getColumnsQry(fromConnection, dest); + qry = LSWLib.SqlCommands.getColumnsQry(fromConnection, src); SqlConnection[] curDests = new SqlConnection[] { toConnection }; cnt = Bulker.Execute(Task, fromConnection, curDests, qry, CommandType.Text, dest, 0, ref error, ref messages); ucmd.Parameters["lastRecords"].Value = cnt; @@ -178,6 +179,7 @@ namespace syncEdosLocal } static void Main(string[] args) { + //Sync need both var SourceCoStr = System.Configuration.ConfigurationManager.ConnectionStrings["eDosConnectionString"].ConnectionString; var LocalCoStr = System.Configuration.ConfigurationManager.ConnectionStrings["LocalConnectionString"].ConnectionString; spLog = new spl("SynceDosLocal");