diff --git a/Common/Production/ProductionUiCordonel/App.xaml.cs b/Common/Production/ProductionUiCordonel/App.xaml.cs index d2e9d9e7..5909ed80 100644 --- a/Common/Production/ProductionUiCordonel/App.xaml.cs +++ b/Common/Production/ProductionUiCordonel/App.xaml.cs @@ -1,6 +1,8 @@ using System; using System.Configuration; using System.Windows; +using Xylem.Common.Production.ProductionUiCordonel.ProductionProcesses.EolProcesses; +using Xylem.Common.Production.ProductionUiCordonel.ProductionProcesses.PickingProcesses; namespace Xylem.Common.Production.ProductionUiCordonel { @@ -11,24 +13,27 @@ namespace Xylem.Common.Production.ProductionUiCordonel { private void Application_Startup(Object sender, StartupEventArgs e) { - switch (ConfigurationManager.AppSettings[$"Mode"]) + switch (ConfigurationManager.AppSettings["Mode"]) { case "1": - - var mainWindow = new FinalTest(); - mainWindow.Show(); + var ProductionWindow = new ProductionWindow( + ProductionUiCordonel.Properties.Resources.StrEolSoftwareNameVersion, + "ProductionUiCordonel", new EolProcessStateDef()); + ProductionWindow.Show(); break; case "2": - var Picking = new Picking(); - Picking.Show(); + ProductionWindow = new ProductionWindow( + ProductionUiCordonel.Properties.Resources.StrPickingSoftwareNameVersion, + "PickingUiCordonel", new PickingProcessStateDef()); + ProductionWindow.Show(); break; default: - var mainWindowDef = new FinalTest(); - mainWindowDef.Show(); + ProductionWindow = new ProductionWindow( + ProductionUiCordonel.Properties.Resources.StrEolSoftwareNameVersion, + "ProductionUiCordonel", new EolProcessStateDef()); + ProductionWindow.Show(); break; } - - } } } diff --git a/Common/Production/ProductionUiCordonel/MainWindow.xaml b/Common/Production/ProductionUiCordonel/MainWindow.xaml deleted file mode 100644 index e878071f..00000000 --- a/Common/Production/ProductionUiCordonel/MainWindow.xaml +++ /dev/null @@ -1,78 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/Common/Production/ProductionUiCordonel/MainWindow.xaml.cs b/Common/Production/ProductionUiCordonel/MainWindow.xaml.cs deleted file mode 100644 index a96dcba9..00000000 --- a/Common/Production/ProductionUiCordonel/MainWindow.xaml.cs +++ /dev/null @@ -1,451 +0,0 @@ -using System; -using System.ComponentModel; -using System.IO; -using System.Linq; -using System.Net; -using System.Threading.Tasks; -using System.Timers; -using System.Windows; -using System.Windows.Controls; -using System.Windows.Threading; -using Newtonsoft.Json; -using Xylem.Common.CommonCore.Configuration; -using Xylem.Common.CommonCore.Consts; -using Xylem.Common.Hardware.Interfaces.Ports.PortCore; -using Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore; -using Xylem.Common.Hardware.WaterMeter.WaterMeterCore; -using Xylem.Common.Logic.SoftwareAccessHelper; -using Xylem.Common.Production.ProductionUiCordonel.Model; - -namespace Xylem.Common.Production.ProductionUiCordonel -{ - //public class QuantityToBackgroundConverter : IValueConverter - //{ - // public object Convert(object value, Type targetType, object parameter, CultureInfo culture) - // { - // var dc = DisplayCodes.None; - - // if (DisplayCodes.TryParse(value.ToString(), out dc)) - // { - // string hex = ""; - // int intValue; - // if (int.TryParse(value.ToString(), out intValue)) - // { - // hex = intValue.ToString("X"); - // } - // return $"{dc} ({hex})"; - // } - // else - // { - // return "?"; - // } - - - // } - - // public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) - // { - // throw new NotImplementedException(); - // } - //} - - /// - /// Interaction logic for MainWindow.xaml - /// - public partial class MainWindow - { - private Timer tmrAutoDetect; - - public EventHandler OnPcbIdDetect; - - private Int32 intervalWithoutDetect = 1000; - private Int32 intervalWithDetect = 10000; - private String _currentPcbID; - - - public PickingViewModel PickingData = new PickingViewModel(); - - public String CurrentPcbID - { - set - { - if (_currentPcbID != value && !(string.IsNullOrEmpty(_currentPcbID) && value == null)) - { - - if (_currentPcbID != value) - { - - if (!string.IsNullOrEmpty(_currentPcbID) && string.IsNullOrEmpty(value)) - { - _currentPcbID = value; - updateUi(lblPcbID, _currentPcbID); - - - } - else - { - _currentPcbID = value; - updateUi(lblPcbID, _currentPcbID); - - if (!string.IsNullOrEmpty(_currentPcbID)) - { - GetPcbMapping(_currentPcbID); - } - } - } - OnPcbIdDetect?.Invoke(CurrentPcbID, EventArgs.Empty); - } - - } - get => _currentPcbID; - } - - public enum uiState - { - not_connected, - connected - } - - private uiState _currentState; - public uiState CurrentState - { - set - { - _currentState = value; - updateUi(lblState, _currentState.ToString()); - } - get => _currentState; - } - - private String _lastMsg; - public String LastMsg - { - set - { - _lastMsg = value; - updateUi(lblMessage, _lastMsg); - } - get => _lastMsg; - } - - public MainWindow() - { - try - { - if (true) - { - - } - InitializeComponent(); - - } - catch (Exception ex) - { - - MessageBox.Show(ex.Message + Environment.NewLine + ex.StackTrace); - } - - } - public ApplicationSettings Settings { get; set; } - private void Window_Initialized(Object sender, EventArgs e) - { - var configfile = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), - nameof(Hardware.WaterMeter.Genesis), ProgramConfig.SerialConfigFileName); - - if (!File.Exists(configfile)) - { - throw new ApplicationException($"Configuration file {configfile} not found "); - } - var tr = new StreamReader(configfile); - var meterConfigList = JsonConvert.DeserializeObject(tr.ReadToEnd()); - - cbxSlotBox.Items.Clear(); - foreach (var item in meterConfigList.OrderBy(s => s.Slot)) - { - cbxSlotBox.Items.Add(item.Slot); - } - - cbxSlotBox.SelectedIndex = 0; - tmrAutoDetect = new Timer(intervalWithoutDetect); - tmrAutoDetect.Elapsed += TmrAutoDetect_Elapsed; - tmrAutoDetect.Enabled = false; - - - Settings = new ApplicationSettings("ProductionUiConfig.json"); - - - useSetting(true); - } - - private void TmrAutoDetect_Elapsed(Object sender, ElapsedEventArgs e) - { - tmrAutoDetect.Enabled = false; - var hasDetect = Detect(true, 1); - if (hasDetect) - { - tmrAutoDetect.Interval = intervalWithDetect; - } - else - { - tmrAutoDetect.Interval = intervalWithoutDetect; - } - tmrAutoDetect.Enabled = Settings.AutoDetect; - } - - - private void BtnConnect_Click(Object sender, RoutedEventArgs e) - { - var hasDetect = Detect(false, (Int32)cbxSlotBox.SelectedValue); - - Settings.Slot = (Int32)cbxSlotBox.SelectedValue; - storeSetting(); - } - - private void updateUi(ContentControl c, String content) - { - c.Dispatcher.Invoke(DispatcherPriority.Normal, - new Action(() => { c.Content = content; })); - } - private void updateUi(TextBox c, String content) - { - c.Dispatcher.Invoke(DispatcherPriority.Normal, - new Action(() => { c.Text = content; })); - } - private void updateUi(TextBlock c, String content) - { - c.Dispatcher.Invoke(DispatcherPriority.Normal, - new Action(() => { c.Text = content; })); - } - - private MeterBatch CurrentBatch; - private IGenesisMeter _currentMeter; - private Boolean detectIsLocked; - - private IGenesisMeter CurrentMeter - { - get => _currentMeter; - set - { - _currentMeter = value; - if (ucFinalRadioTest != null) - { - if (_currentMeter?.PcbId != null) - { - // ucFinalRadioTest.GenesisMeter = value; - } - else - { - // ucFinalRadioTest.GenesisMeter = null; - } - - } - } - } - - private Boolean Detect(Boolean ignoreErrors, Int32 slot) - { - if (!detectIsLocked) - { - LastMsg = "Start Detect"; - Boolean hasDetect = false; - if (string.IsNullOrEmpty(CurrentPcbID) || CurrentMeter == null) - { - var mb = new MeterBatch(); - var tryMeter = new GenesisMeter(); - try - { - tryMeter.SetupFromConfigFile(slot); - mb.AddMeter(tryMeter); - tryMeter.Logout(); - LastMsg = "Try to get PcbID"; - CurrentPcbID = tryMeter.GetPcbId(); - - hasDetect = !string.IsNullOrEmpty(CurrentPcbID); - CurrentBatch = mb; - CurrentMeter = tryMeter; - if (hasDetect) - { - LastMsg = $"New PcbID detected {CurrentPcbID}"; - - CurrentMeter.Login(); - } - else - { - LastMsg = "No Meter found"; - DisposeAllConnections(); - } - - } - catch (Exception e) - { - if (!ignoreErrors) - { - MessageBox.Show($"Error occur.{ Environment.NewLine} {e.Message}"); - } - - } - - } - else - { - LastMsg = "Check if Meter is still connected"; - var ret = CurrentMeter.GetPcbId(); - if (string.IsNullOrEmpty(ret) || ret != CurrentPcbID) - { - LastMsg = "Meter connection lost"; - hasDetect = false; - DisposeAllConnections(); - - CurrentPcbID = ""; - } - else - { - LastMsg = "Meter is still connected"; - hasDetect = true; - } - } - return hasDetect; - } - - LastMsg = "Meter is still connected (locked)"; - return true; - } - - - - private void Window_Closing(Object sender, CancelEventArgs e) - { - DisposeAllConnections(); - } - - private void DisposeAllConnections() - { - - if (CurrentBatch != null) - { - CurrentBatch.RemoveAllMeters(); - if (CurrentMeter != null) - { - CurrentMeter.Dispose(); - } - CurrentBatch.Dispose(); - } - PickingData.Empty(); - - } - - - - - private void GetPcbMapping(String pcbID) - { - if (string.IsNullOrEmpty(pcbID)) - { - return; - } - var url = $"{ServiceUrls.MarriageServiceUrl()}GetSerialNumberAndOrderNumber?PcbId={pcbID}&withRadioAdress=true"; - - Task.Run(() => - { - try - { - var responseJson = LocalWebRequest.GetRequest(url); - var a = JsonConvert.DeserializeObject(responseJson); - - - if (ucFinalRadioTest != null) - { - var tmpInt = 0; - int.TryParse(a[1], out tmpInt); - // ucFinalRadioTest.OrderNumber = tmpInt; - - tmpInt = 0; - if (a.Length > 2) - { - int.TryParse(a[2], out tmpInt); - - } - - //ucFinalRadioTest.RadioAddress = tmpInt; - // ucFinalRadioTest.SerialNumber = a[0] + "/" + a[3]; - - } - - - } - catch (Exception ex) - { - if (ex is WebException) - { - MessageBox.Show($"Error on Store: {Environment.NewLine} { ((WebException)ex).Message}"); - } - - MessageBox.Show(ex.Message); - } - }); - } - - - - - - - - private void Button_Click(Object sender, RoutedEventArgs e) - { - - } - - private void UcFinalRadioTest_OnLockMeter(Object sender, EventArgs e) - { - detectIsLocked = true; - - } - - private void UcFinalRadioTestOnOnReleaseMeter(Object sender, EventArgs e) - { - detectIsLocked = false; - //ucFinalRadioTest.SetUpBlank(false); - } - - - private void BtnSwitchAutoDetect_Click(Object sender, RoutedEventArgs e) - { - Settings.AutoDetect = !Settings.AutoDetect; - storeSetting(); - useSetting(); - } - - private void CbxSlotBox_SelectionChanged(Object sender, SelectionChangedEventArgs e) - { - - } - private void storeSetting() - { - Settings.Update("ProductionUiConfig.json"); - } - - - - private void useSetting(Boolean setSlot = false) - { - tmrAutoDetect.Enabled = Settings.AutoDetect; - tblkAutodetectState.Text = "Off"; - if (Settings.AutoDetect) - { - tblkAutodetectState.Text = "On"; - } - if (setSlot) - { - cbxSlotBox.SelectedValue = Settings.Slot; - } - } - - private void StackPanel_SizeChanged(Object sender, SizeChangedEventArgs e) - { - ucFinalRadioTest.Height = e.NewSize.Height; - - } - - } -} diff --git a/Common/Production/ProductionUiCordonel/MultiMode.xaml b/Common/Production/ProductionUiCordonel/MultiMode.xaml deleted file mode 100644 index 3e3fd0a6..00000000 --- a/Common/Production/ProductionUiCordonel/MultiMode.xaml +++ /dev/null @@ -1,152 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - diff --git a/Common/Production/ProductionUiCordonel/MultiMode.xaml.cs b/Common/Production/ProductionUiCordonel/MultiMode.xaml.cs deleted file mode 100644 index 8a7b6e0d..00000000 --- a/Common/Production/ProductionUiCordonel/MultiMode.xaml.cs +++ /dev/null @@ -1,206 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Threading; -using System.Windows; -using System.Windows.Controls; -using System.Windows.Input; -using Xylem.Common.Production.ProductionUiCordonel.Model; - -namespace Xylem.Common.Production.ProductionUiCordonel -{ - /// - /// Interaktionslogik für MultiMode.xaml - /// - public partial class MultiMode : Window - { - //#region Raw Input API - - //[DllImport("User32.dll")] - //extern static uint GetRawInputDeviceList(IntPtr pRawInputDeviceList, ref uint uiNumDevices, uint cbSize); - - //[DllImport("User32.dll")] - //extern static uint GetRawInputDeviceInfo(IntPtr hDevice, uint uiCommand, IntPtr pData, ref uint pcbSize); - - //[DllImport("User32.dll")] - //extern static bool RegisterRawInputDevices(RAWINPUTDEVICE[] pRawInputDevice, uint uiNumDevices, uint cbSize); - - //[DllImport("User32.dll")] - //extern static uint GetRawInputData(IntPtr hRawInput, uint uiCommand, IntPtr pData, ref uint pcbSize, uint cbSizeHeader); - - //#endregion - - MultiModeMasterViewModel multiModeMasterViewModel = new MultiModeMasterViewModel(); - - private List Childs = new List(); - - public ApplicationSettings AppSettings { get; private set; } - //class RawInputDevice : InputDevice - //{ - // public override IInputElement Target => throw new NotImplementedException(); - - // public override PresentationSource ActiveSource => throw new NotImplementedException(); - //} - public MultiMode() - { - - DataContext = multiModeMasterViewModel; - - InitializeComponent(); - Topmost = false; - } - private void keyUp(Object sender, KeyEventArgs e) - { - - } - public void SetBaseFocus() - { - //foreach (var item in Childs) - //{ - // item.Key.Activate(); - //} - //this.Activate(); - //txtBarcodeInput.Focus(); - - } - - - private MultiModeChild addChild(IMultiModeChildViewModel model) - { - var a = new MultiModeChild(model); - - a.Show(); - return a; - } - CancellationTokenSource cts; - - private void Window_Loaded(Object sender, RoutedEventArgs e) - { - cts = new CancellationTokenSource(); - AppSettings = new ApplicationSettings("MultiProductionUiConfig.json"); - multiModeMasterViewModel.StartPicking(cts); - //var trigger = new List(); - - //if (AppSettings.ChildForms == null || !AppSettings.ChildForms.Any()) - //{ - // AppSettings.ChildForms = new List(); - - // AppSettings.ChildForms.Add(new ApplicationSettings.MultiFormChilds() { Name = "Picking", Slot = 1, ViewModelType = typeof(PickingMultiModeViewModel), StartPos = null, Visisble = true, TextPort = "COM11" }); - // AppSettings.ChildForms.Add(new ApplicationSettings.MultiFormChilds() { Name = "PressureHE", Slot = 3, ViewModelType = typeof(PressureMultiModeViewModel), StartPos = null, Visisble = true, TextPort = null }); - // AppSettings.ChildForms.Add(new ApplicationSettings.MultiFormChilds() { Name = "PressureHY", Slot = 1, ViewModelType = typeof(PressureMultiModeViewModel), StartPos = null, Visisble = true, TextPort = null }); - // AppSettings.ChildForms.Add(new ApplicationSettings.MultiFormChilds() { Name = "Marriage", Slot = 4, ViewModelType = typeof(MarriageMultiModeViewModel), StartPos = null, Visisble = true, TextPort = "COM1" }); - // AppSettings.Update("MultiProductionUiConfig.json"); - //} - - - ////AppSettings.ChildForms.ForEach(c => trigger.Add(c.TextPort.ToString())); - - //cts = new CancellationTokenSource(); - - //foreach (var item in AppSettings.ChildForms) - //{ - // if (item.Visisble) - // { - - - // IMultiModeChildViewModel mdl = null; - // if (item.ViewModelType == typeof(PickingMultiModeViewModel)) - // { - // mdl = new PickingMultiModeViewModel(item.Name, item.Slot, trigger, AppSettings.StationId); - // } - // else if (item.ViewModelType == typeof(PressureMultiModeViewModel)) - // { - // mdl = new PressureMultiModeViewModel(item.Name, item.Slot, trigger, AppSettings.StationId); - // } - // else if (item.ViewModelType == typeof(MarriageMultiModeViewModel)) - // { - // mdl = new MarriageMultiModeViewModel(item.Name, item.Slot, trigger, AppSettings.StationId); - // } - // if (mdl == null) - // { - // throw new ApplicationException("Bad configuration or old software"); - // } - // var child = addChild(mdl); - - // child.StartTextInputListener(item.TextPort, cts.Token); - - // if (item.StartPos != null) - // { - // child.WindowStartupLocation = WindowStartupLocation.Manual; - // child.Top = item.StartPos.Top; - // child.Left = item.StartPos.Left; - // child.Height = item.StartPos.Height; - // child.Width = item.StartPos.Width; - // child.UseDefaultPos = false; - // } - // child.PosChanged += delegate (object val, EventArgs a) - // { - // if (val is MultiModeChild mmc) - // { - // if (mmc.ViewModel is BaseMultiModeChildViewModel baseChild) - // { - // var aasd = AppSettings.ChildForms.FirstOrDefault(c => c.Name == baseChild.ChildName); - // aasd.StartPos = new ApplicationSettings.Pos() { Height = mmc.Height, Left = mmc.Left, Top = mmc.Top, Width = mmc.Width }; - - // AppSettings.Update("MultiProductionUiConfig.json"); - // } - // } - - // }; - - - // child.Show(); - - // Childs.Add(child); - - // } - - //} - - - - //SetBaseFocus(); - } - - private void delegeChild_PosChange(Object sender, EventArgs e) - { - throw new NotImplementedException(); - } - - private void TxtBarcodeInput_TextChanged(Object sender, TextChangedEventArgs e) - { - //if (sender is TextBox text) - //{ - // if (text.Text.ToLower().Contains("clear")) - // { - // text.Text = string.Empty; - // } - // else if (text.Text.Contains(System.Environment.NewLine)) - // { - // foreach (var dispatchChild in Childs.Where(x => x.Value == text.Text[0])) - // { - // dispatchChild.Key.InputText(text.Text.Substring(1, text.Text.Length - 1).Trim()); - // } - - // text.Text = ""; - // SetBaseFocus(); - // } - - //} - - } - - private void Window_Closed(Object sender, EventArgs e) - { - - cts.Cancel(); - - - foreach (var item in Childs) - { - item.Dispose(); - - item.Close(); - } - } - } -} diff --git a/Common/Production/ProductionUiCordonel/MultiModeChild.xaml b/Common/Production/ProductionUiCordonel/MultiModeChild.xaml deleted file mode 100644 index 5b560b2f..00000000 --- a/Common/Production/ProductionUiCordonel/MultiModeChild.xaml +++ /dev/null @@ -1,84 +0,0 @@ - - - - - - - - - - - - - - - -