271 lines
9.3 KiB
C#
271 lines
9.3 KiB
C#
using System;
|
|
using System.Windows;
|
|
using System.Windows.Media;
|
|
using System.Windows.Threading;
|
|
|
|
namespace eDosStation
|
|
{
|
|
/// <summary>
|
|
/// Interaction logic for MainWindow.xaml
|
|
/// </summary>
|
|
public partial class MainWindow : Window
|
|
{
|
|
|
|
const string className = "MainWindow";
|
|
public DataInterface dataInterface;
|
|
public Station thisStation;
|
|
DispatcherTimer bgTimer;
|
|
private bool Offline = true;
|
|
private App curApp;
|
|
|
|
#if SimulateEPD
|
|
public SimulateData simulData = new SimulateData();
|
|
#endif
|
|
public MainWindow()
|
|
{
|
|
InitializeComponent();
|
|
curApp = Application.Current as App;
|
|
}
|
|
|
|
public void loadsvg()
|
|
{
|
|
var m_imageSource = new SvgImageSource(new Uri("mySvgImage.svg"));
|
|
}
|
|
|
|
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(null, "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, null, 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(module, "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, null,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(module,"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()
|
|
{
|
|
const string module = "setLocalStatus";
|
|
if (!dataInterface.isOnline())
|
|
{
|
|
Status.Content = "*** Offline ***";
|
|
if (!Offline) thisStation.splunkLog?.WriteSplunkLog(module, "Went Offline", LSWLib.CLog.iseverity.warning);
|
|
Offline = true;
|
|
}
|
|
else
|
|
{
|
|
Status.Content = "--- Online ---";
|
|
if (Offline) thisStation.splunkLog?.WriteSplunkLog(module, "Back online", LSWLib.CLog.iseverity.info);
|
|
Offline = false;
|
|
}
|
|
}
|
|
private void setErrorStatus(string errMsg)
|
|
{
|
|
const string module = "setErrorStatus";
|
|
thisStation.splunkLog?.WriteSplunkLog(module, null, LSWLib.CLog.iseverity.err, lresultMessage: errMsg);
|
|
Status.Content = $"*** Error {errMsg} ***";
|
|
Status.Foreground = Brushes.Yellow;
|
|
Status.Background = Brushes.Red;
|
|
}
|
|
|
|
private void showBadge(int persid)
|
|
{
|
|
UserInfo UI = new UserInfo(persid);
|
|
UI.ShowDialog();
|
|
|
|
}
|
|
private void Pelatec_DataReceived(int PersID)
|
|
{
|
|
this.Dispatcher.InvokeAsync(new Action(() => showBadge(PersID)), DispatcherPriority.Background);
|
|
}
|
|
|
|
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, curApp);
|
|
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)
|
|
{
|
|
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);
|
|
|
|
|
|
TruDose.Content = $"TruDose: {thisStation.sComPort}";
|
|
BadgeReader.Content = thisStation.ReaderName;
|
|
BgTimer_Tick(null, null);
|
|
bgTimer.Start();
|
|
thisStation.ReceivedPersid = Pelatec_DataReceived;
|
|
|
|
}
|
|
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();
|
|
try
|
|
{
|
|
Environment.Exit(0);
|
|
}
|
|
catch { }
|
|
}
|
|
|
|
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);
|
|
}
|
|
}
|
|
}
|