using System; using System.Windows; using System.Windows.Media; using System.Windows.Threading; namespace eDosStation { /// /// Interaction logic for MainWindow.xaml /// public partial class MainWindow : Window { const string className = "MainWindow"; public DataInterface dataInterface; public Station thisStation; DispatcherTimer bgTimer; private bool Offline = true; #if SimulateEPD public SimulateData simulData = new SimulateData(); #endif public MainWindow() { InitializeComponent(); } private void Button_Click(object sender, RoutedEventArgs e) { string ers = string.Empty; if (thisStation.RestartCom && thisStation.RestartComFirst ) { thisStation.DeviceRestart(); } var w = new ShowEPDDose(thisStation); w.ShowDialog(); if (thisStation.RestartCom && !thisStation.RestartComFirst ) { thisStation.DeviceRestart(); } thisStation.splunkLog?.WriteSplunkLog("Show Dose done", LSWLib.CLog.iseverity.info); } private void BEntry_Click(object sender, RoutedEventArgs e) { const string module = "BEntry_Click"; string ers = string.Empty; thisStation.splunkLog?.WriteSplunkLog(module, LSWLib.CLog.iseverity.info); string step = "DeviceRestart"; try { if (thisStation.RestartCom && thisStation.RestartComFirst) { thisStation.DeviceRestart(); } } catch (System.Exception ex) { thisStation.splunkLog?.WriteException(module, step, ex); } step = "EntryBadge"; try { var w = new EntryBadge(thisStation); w.ShowDialog(); #if SimulateEPD simulData = w.simulData; #endif w = null; } catch (System.Exception ex) { thisStation.splunkLog?.WriteException(module, step, ex); } step = "DeviceReset2"; try { if (thisStation.RestartCom && !thisStation.RestartComFirst) { thisStation.DeviceRestart(); } } catch (System.Exception ex) { thisStation.splunkLog.WriteException(module, step, ex); } thisStation.splunkLog?.WriteSplunkLog("Entry done", LSWLib.CLog.iseverity.info); } private void BExit_Click(object sender, RoutedEventArgs e) { const string module = "BExit_Click"; string ers = string.Empty; thisStation.splunkLog?.WriteSplunkLog(module, LSWLib.CLog.iseverity.info); if (thisStation.RestartCom && thisStation.RestartComFirst) { ers = thisStation.DeviceRestart(); } var w = new EpdExit(thisStation); #if SimulateEPD w.simulData = simulData; #endif w.ShowDialog(); w = null; if (thisStation.RestartCom && !thisStation.RestartComFirst) { ers = thisStation.DeviceRestart(); } thisStation.splunkLog?.WriteSplunkLog("Exit Done", LSWLib.CLog.iseverity.info); } private void MenuItem_Click(object sender, RoutedEventArgs e) { const string module = "MenuSettings"; try { var s = new Settings(thisStation); s.ShowDialog(); } catch (System.Exception ex) { thisStation?.splunkLog?.WriteException(className, module, ex); } } private void setLocalStatus() { if (!dataInterface.isOnline()) { Status.Content = "*** Offline ***"; if (!Offline) thisStation.splunkLog?.WriteSplunkLog("Went Offline", LSWLib.CLog.iseverity.warning); Offline = true; } else { Status.Content = "--- Online ---"; if (Offline) thisStation.splunkLog?.WriteSplunkLog("Back online", LSWLib.CLog.iseverity.info); Offline = false; } } private void setErrorStatus(string errMsg) { thisStation.splunkLog?.WriteSplunkLog("Errorstatus", LSWLib.CLog.iseverity.err, null, errMsg); Status.Content = $"*** Error {errMsg} ***"; Status.Foreground = Brushes.Yellow; Status.Background = Brushes.Red; } private void Window_Loaded(object sender, RoutedEventArgs e) { bool ok = true; string errMsg = string.Empty; tVersion.Text = "HPH eDos " + System.Reflection.Assembly.GetExecutingAssembly().GetName().Version; bgTimer = new DispatcherTimer(DispatcherPriority.Background); bgTimer.Interval = TimeSpan.FromSeconds(60); bgTimer.Tick += BgTimer_Tick; bgTimer.IsEnabled = true; try { dataInterface = new DataInterface(); thisStation = new Station(dataInterface, string.Empty); dataInterface.splunkLog = thisStation.splunkLog; } catch (System.Exception ex) { errMsg = $"Startup error {ex.Message} "; MessageBox.Show(errMsg); ok = false; dataInterface.stationLog?.WriteLine($"Window_Loaded {ex.Message}"); } if (ok && thisStation.Error > 0) { errMsg = $"Startup error {thisStation.ErrorMessage} "; MessageBox.Show(errMsg); ok = false; } // 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); // //ep.SetFeedbackSound(thisStation.useBeep); // } // catch (System.Exception ex) // { // errMsg = $"Edp software error {ex.Message}"; // MessageBox.Show(errMsg); // ok = false; // thisStation.splunkLog.WriteException("mainWindow", "Epd", ex); // dataInterface.stationLog?.WriteLine($"Window_Loaded {ex.Message}"); // } 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.Collapsed; } else setErrorStatus(errMsg); BgTimer_Tick(null, null); bgTimer.Start(); } private void BgTimer_Tick(object sender, EventArgs e) { setLocalStatus(); tbTime.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm"); } private void MEnc_Click(object sender, RoutedEventArgs e) { //string cfg = System.IO.Path.Combine(Environment.CurrentDirectory, System.AppDomain.CurrentDomain.FriendlyName ); //Config.ToggleConfigEncryption(cfg); } private void Window_GotFocus(object sender, RoutedEventArgs e) { bgTimer.Start(); } private void Window_LostFocus(object sender, RoutedEventArgs e) { bgTimer.Stop(); } private void mAbout_Click(object sender, RoutedEventArgs e) { About x = new About(thisStation); x.ShowDialog(); } private void mExit_Click(object sender, RoutedEventArgs e) { bgTimer?.Stop(); dataInterface.stationLog?.Close(); thisStation.splunkLog.KvClear(); thisStation.splunkLog?.CloseSplunkLog(); Application.Current.Shutdown(); Environment.Exit(0); } private void mReverseSync_Click(object sender, RoutedEventArgs e) { bool ok = dataInterface.ReverseSync(); if (ok) MessageBox.Show("Success", null, MessageBoxButton.OK, MessageBoxImage.Information); else MessageBox.Show("Fout", null, MessageBoxButton.OK, MessageBoxImage.Error); } } }