136 lines
3.7 KiB
C#
136 lines
3.7 KiB
C#
using System;
|
|
using System.IO.Ports;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using System.Windows;
|
|
using System.Windows.Controls;
|
|
using System.Windows.Threading;
|
|
using ProductionUiCordonelLegacy.Event;
|
|
using ProductionUiCordonelLegacy.Model;
|
|
|
|
namespace ProductionUiCordonelLegacy
|
|
{
|
|
/// <summary>
|
|
/// Interaktionslogik für MultiModeChild.xaml
|
|
/// </summary>
|
|
public partial class MultiModeChild : Window, IDisposable
|
|
{
|
|
public IMultiModeChildViewModel ViewModel;
|
|
|
|
public Boolean UseDefaultPos { get; internal set; } = true;
|
|
public event EventHandler PosChanged;
|
|
|
|
|
|
public MultiModeChild(IMultiModeChildViewModel viewModel)
|
|
{
|
|
InitializeComponent();
|
|
ViewModel = viewModel;
|
|
DataContext = ViewModel;
|
|
if (ViewModel is PressureMultiModeViewModel pressureModel)
|
|
{
|
|
PressureControl.setViewModel(pressureModel);
|
|
|
|
Left = 0;
|
|
Top = 250;
|
|
Height = SystemParameters.PrimaryScreenHeight - 300;
|
|
Width = SystemParameters.PrimaryScreenWidth / 2;
|
|
}
|
|
if (ViewModel is PickingMultiModeViewModel pickingModel)
|
|
{
|
|
PickingControl.setViewModel(pickingModel);
|
|
|
|
Left = SystemParameters.VirtualScreenLeft;
|
|
Top = SystemParameters.VirtualScreenTop;
|
|
Height = SystemParameters.VirtualScreenHeight;
|
|
Width = SystemParameters.VirtualScreenWidth - SystemParameters.PrimaryScreenWidth;
|
|
}
|
|
if (ViewModel is MarriageMultiModeViewModel marriageModel)
|
|
{
|
|
MarriageControl.setViewModel(marriageModel);
|
|
|
|
Left = SystemParameters.PrimaryScreenWidth / 2;
|
|
Top = 250;
|
|
Height = SystemParameters.PrimaryScreenHeight - 300;
|
|
Width = SystemParameters.PrimaryScreenWidth / 2;
|
|
|
|
}
|
|
|
|
}
|
|
internal void StartTextInputListener(String port, CancellationToken cancellation)
|
|
{
|
|
if (port == null)
|
|
{
|
|
return;
|
|
}
|
|
var task = new Task(() =>
|
|
{
|
|
var a = new SerialPort(port);
|
|
a.Open();
|
|
a.NewLine = "\r";
|
|
while (true)
|
|
{
|
|
if (cancellation.IsCancellationRequested)
|
|
{
|
|
break;
|
|
}
|
|
|
|
var resText = a.ReadLine();
|
|
Dispatcher.Invoke(DispatcherPriority.Normal,
|
|
new Action(() =>
|
|
{
|
|
ViewModel.InputText(resText);
|
|
}
|
|
));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
}, cancellation);
|
|
task.Start();
|
|
|
|
|
|
}
|
|
|
|
internal void InputText(String text)
|
|
{
|
|
ViewModel.InputText(text);
|
|
}
|
|
|
|
private void BtnPresueFailed_Click(Object sender, RoutedEventArgs e)
|
|
{
|
|
|
|
}
|
|
|
|
private void TxtPresurePcbId_TextChanged(Object sender, TextChangedEventArgs e)
|
|
{
|
|
|
|
}
|
|
|
|
private void PressureControl_OnBarcodeInput(Object sender, StringArgs e)
|
|
{
|
|
InputText(e.Content);
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
ViewModel.Dispose();
|
|
|
|
}
|
|
|
|
private void Button_Click(Object sender, RoutedEventArgs e)
|
|
{
|
|
if (sender is Button btn)
|
|
{
|
|
btn.Content = $"POS L{Left},T{Top },H{Height},W{Width}";
|
|
}
|
|
}
|
|
|
|
private void Button_Click_1(Object sender, RoutedEventArgs e)
|
|
{
|
|
PosChanged?.Invoke(this, EventArgs.Empty);
|
|
}
|
|
}
|
|
}
|