eDosStationFull/eDosStation_Backup_2025.02.04_07.47.06/Settings.xaml.cs
2026-08-18 12:15:26 +02:00

414 lines
17 KiB
C#

using System;
using System.Collections.ObjectModel;
using System.Text;
using System.Windows;
using System.Windows.Threading;
namespace eDosStation
{
/// <summary>
/// Interaction logic for Settings.xaml
/// </summary>
public class beepclass
{
public string Text { get; set; }
public byte Value { get; set; }
public beepclass(string txt, byte val)
{
Text = txt; Value = val;
}
}
public class readerclass
{
public string Text { get; set; }
public readerclass(string txt)
{
Text = txt;
}
}
public partial class Settings : Window
{
const string className = "Settings";
//private System.Threading.Tasks.Task ReaderTask;
//User _User;
Station thisStation;
ObservableCollection<beepclass> beepValues;
ObservableCollection<readerclass> readerValues;
public Settings(Station tStation)
{
try
{
//_User = null;
thisStation = null;
//dfReader = null; ReaderTask = null;
beepValues = new ObservableCollection<beepclass>();
readerValues = new ObservableCollection<readerclass>();
InitializeComponent();
if (tStation != null) thisStation = tStation;
if (tStation != null) tStation.splunkLog?.WriteSplunkLog(className, null, LSWLib.CLog.iseverity.info, lresultMessage: "created");
}
catch (System.Exception ex)
{
if (tStation != null) tStation.splunkLog?.WriteException(className, className, ex);
}
}
private void BOK_Click(object sender, RoutedEventArgs e)
{
const string module = "BOK_Click";
string step="init";
try
{
step = "comport";
string thiscom = cComPort.SelectedItem.ToString().Replace("COM", string.Empty);
thisStation.ComPort = int.Parse(thiscom);
DataSet1.InstallationRow ir;
step = "code1";
ir = CIns1.SelectedItem as DataSet1.InstallationRow;
if (ir != null)
{
thisStation.Inst_CODE1 = ir.Inst_CODE;
thisStation.Inst_Name1 = ir.InstallationName;
} else
{
thisStation.Inst_CODE1 = 0;
thisStation.Inst_Name1 = string.Empty;
}
step = "code2";
ir = CIns2.SelectedItem as DataSet1.InstallationRow;
if (ir != null)
{
thisStation.Inst_CODE2 = ir.Inst_CODE;
thisStation.Inst_Name2 = ir.InstallationName;
}
else
{
thisStation.Inst_CODE2 = 0;
thisStation.Inst_Name2 = string.Empty;
}
step = "usebeep";
if (tBeep.HasItems && tBeep.SelectedIndex != -1) {
thisStation.useBeep = (byte)tBeep.SelectedValue;
} else
thisStation.useBeep = (byte)0b00011110;
step = "validation++";
if (cbValidation.IsChecked == null) cbValidation.IsChecked = false;
thisStation.useTestButtons = cbValidation.IsChecked.Value;
step = "Reader";
thisStation.Reader = (string)cbReaders.SelectedValue;
step = "checkUser";
thisStation.checkUser = cbCheckUsers.IsChecked != null ? cbCheckUsers.IsChecked.Value : false;
thisStation.RestartCom = cbRestartCom.IsChecked != null ? cbRestartCom.IsChecked.Value : false;
step = "EPDTimeOut";
thisStation.EPDTimeOut = int.Parse(tEPDTimeout.Text);
step = "OnlyMK2";
thisStation.OnlyMK2 = cbOnlyMK2.IsChecked != null ? cbOnlyMK2.IsChecked.Value : false;
step = "RestartComFirst";
thisStation.RestartComFirst = cbRestartComFirst.IsChecked != null ? cbRestartComFirst.IsChecked.Value : false;
step = "AllowMultipleEPD";
thisStation.AllowMultipleEPD = cbAllowMultipleEPD.IsChecked != null ? cbAllowMultipleEPD.IsChecked.Value : false;
//thisStation.WriteConfig32 = cbWriteConfig32.IsChecked != null ? cbWriteConfig32.IsChecked.Value : false;
thisStation.LogAll = cbLogAll.IsChecked != null ? cbLogAll.IsChecked.Value : false;
thisStation.ElatecPort = eComPort.SelectedValue.ToString().Trim();
step = "Update";
thisStation.Update();
if (thisStation.Error > 0)
{
thisStation?.splunkLog?.WriteSplunkLog(module, null, LSWLib.CLog.iseverity.err, lresultMessage: thisStation.ErrorMessage);
MessageBox.Show($"Error {thisStation.ErrorMessage}");
}
}
catch (System.Exception ex)
{
thisStation?.splunkLog?.WriteException(module, step, ex);
}
thisStation?.splunkLog?.WriteSplunkLog(module, null, LSWLib.CLog.iseverity.info, lresultMessage: "done");
this.Close();
}
private void BCancel_Click(object sender, RoutedEventArgs e)
{
const string module = "BCancel_Click";
thisStation?.splunkLog?.WriteSplunkLog(module, null, LSWLib.CLog.iseverity.info, lresultMessage: "saved");
this.Close();
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
const string module = "Window_Loaded";
string step = "devcon";
string eDosCom = null;
try
{
eDosCom = thisStation?.find();
thisStation.splunkLog?.WriteSplunkLog(module,step, LSWLib.CLog.iseverity.info, lresultMessage: eDosCom);
}
catch (System.Exception ex)
{
thisStation?.splunkLog?.WriteException(module, step, ex);
}
step = "GetReaderList";
try
{
using (var a = new LSWDesfirePublic.CCard())
{
a.GetReaderList();
foreach (string s in a.readersList) { readerValues.Add(new readerclass(s)); }
}
cbReaders.ItemsSource = readerValues;
cbReaders.SelectedValue = thisStation.Reader;
thisStation.splunkLog?.WriteSplunkLog(module, step, LSWLib.CLog.iseverity.info);
}
catch (System.Exception ex)
{
thisStation?.splunkLog?.WriteException(module, step, ex);
MessageBox.Show($"Readers err {ex.Message}");
}
step = "GetPortNames";
try
{
foreach (string cn in System.IO.Ports.SerialPort.GetPortNames())
{
cComPort.Items.Add(cn);
eComPort.Items.Add(cn);
}
thisStation.splunkLog?.WriteSplunkLog(module,step, LSWLib.CLog.iseverity.info);
}
catch (System.Exception ex)
{
thisStation?.splunkLog?.WriteException(module, step, ex);
MessageBox.Show($"Serial err {ex.Message}");
}
step = "BeepValues";
try
{
beepValues.Add(new beepclass("Loud High freq Beep", 0b00010111));
beepValues.Add(new beepclass("Loud Low freq Beep", 0b00011111));
beepValues.Add(new beepclass("Normal High freq Beep", 0b00010110));
beepValues.Add(new beepclass("Normal Low freq Beep", 0b00011110));
beepValues.Add(new beepclass("No Beep (only led)", 0b00011010));
tBeep.ItemsSource = beepValues;
thisStation.splunkLog?.WriteSplunkLog(module, step, LSWLib.CLog.iseverity.info);
}
catch (System.Exception ex)
{
thisStation?.splunkLog?.WriteException(module, step, ex);
MessageBox.Show($"Serial err {ex.Message}");
}
// 7 6 5 4 3210
// 1 0 0 1 1 1 0 0 1 1 1 0 0001
// 1 0 0 1 1 1 0 0 1 1 0 0 0001
// 1 0 0 1 1 1 0 0 1 0 1 0 0001
// 1 0 0 1 1 1 0 0 1 0 0 0 0001
// 1 0 0 1 1 1 0 0 0 0 0 0 0000
//MK3
//Bits 0-3 = Graphic Wearer Name, displayed in EPD Assignment menu
//0000 : Off(no sounder)
//0001 : Continuous Single Tone
//0010 : Continuous Dual Tone Slow
//0011 : Continuous Dual Tone Fast
//0100 : Intermittent Single Slow
//0101 : Intermittent Single Fast
//0110 : Intermittent Double Slow
//0111 : Intermittent Double Fast
//1110 : Mirion Style Dose
//1111 : Mirion Style Rate
//Bit 4 = Not used
//Bit 5 = Tone 2kHz = 0, 4kHz = 1
//Bit 6 = Volume Loud = 1, Normal = 0
//Bit 7 = Sound Enabled = 1
//Bit 8, 9 = Not used
//Bit 10 = LED Brightness Bright = 1, Normal = 0
//Bit 11 = LED Enabled = 1
//Bit 12 = Mutable User can mute = 1
//Bit 13, 14 = Not Used
//Bit 15 = Vibe Enabled = 1
//beepValues.Add(new beepclass("Beep", 22));
//beepValues.Add(new beepclass("No Beep", 18));
step = "Select com";
try
{
string thisComport = $"COM{thisStation.ComPort}";
if (!string.IsNullOrEmpty(eDosCom)) thisComport = eDosCom;
if (!cComPort.Items.Contains(thisComport)) cComPort.Items.Add(thisComport);
cComPort.SelectedItem = thisComport;
thisStation.splunkLog?.WriteSplunkLog(module,step, LSWLib.CLog.iseverity.info);
}
catch (System.Exception ex)
{
thisStation?.splunkLog?.WriteException(module, step, ex);
MessageBox.Show($"Serial err {ex.Message}");
}
step = "Select ecom";
try
{
string thisComport = thisStation.ElatecPort;
if (!eComPort.Items.Contains(thisComport)) eComPort.Items.Add(thisComport);
eComPort.SelectedItem = thisComport;
thisStation.splunkLog?.WriteSplunkLog(module, step, LSWLib.CLog.iseverity.info);
}
catch (System.Exception ex)
{
thisStation?.splunkLog?.WriteException(module, step, ex);
MessageBox.Show($"Serial err {ex.Message}");
}
step = "tbInstallations";
try
{
DataSet1.InstallationDataTable tbInstallations;
using (var ta = new DataSet1TableAdapters.InstallationTableAdapter())
tbInstallations = ta.GetData();
tbInstallations.AddInstallationRow(0, "-");
foreach (DataSet1.InstallationRow r in tbInstallations.Rows)
{
CIns1.Items.Add(r);
CIns2.Items.Add(r);
}
CIns1.SelectedValue = thisStation.Inst_CODE1;
CIns2.SelectedValue = thisStation.Inst_CODE2;
thisStation.splunkLog?.WriteSplunkLog(module, step, LSWLib.CLog.iseverity.info);
}
catch (System.Exception ex)
{
thisStation?.splunkLog?.WriteException(module, step, ex);
MessageBox.Show($"SetINstallations err {ex.Message}");
}
step = "setCheckBoxes";
try
{
tBeep.SelectedValue = thisStation.useBeep;
cbValidation.IsChecked = thisStation.useTestButtons;
cbCheckUsers.IsChecked = thisStation.checkUser;
cbRestartCom.IsChecked = thisStation.RestartCom;
tEPDTimeout.Text = thisStation.EPDTimeOut.ToString();
cbRestartComFirst.IsChecked = thisStation.RestartComFirst;
cbOnlyMK2.IsChecked = thisStation.OnlyMK2;
cbAllowMultipleEPD.IsChecked = thisStation.AllowMultipleEPD;
cbWriteConfig32.IsChecked = thisStation.WriteConfig32;
cbLogAll.IsChecked = thisStation.LogAll;
thisStation.splunkLog?.WriteSplunkLog(module, step, LSWLib.CLog.iseverity.info);
}
catch (System.Exception ex)
{
thisStation?.splunkLog?.WriteException(module, step, ex);
MessageBox.Show($"Settings err {ex.Message}");
}
step = "CheckCon";
try
{
bool rv = thisStation.dataInterface.checkCon(false);
thisStation.splunkLog?.WriteSplunkLog(module, step, LSWLib.CLog.iseverity.info);
}
catch (System.Exception ex)
{
thisStation?.splunkLog?.WriteException(module, step, ex);
MessageBox.Show($"Interface check {ex.Message}");
}
step = "endLoaded";
thisStation?.splunkLog?.WriteSplunkLog(module, step, LSWLib.CLog.iseverity.info);
}
#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
}
}