172 lines
4.9 KiB
C#
172 lines
4.9 KiB
C#
using System;
|
|
using System.IO;
|
|
using System.Net;
|
|
using System.Windows.Controls;
|
|
using Newtonsoft.Json;
|
|
using ProductionUiCordonelLegacy.ProductionProcesses.Enum;
|
|
using ProductionUiCordonelLegacy.UserControls.FinalTest;
|
|
using Xylem.Common.CommonCore.Configuration;
|
|
|
|
namespace ProductionUiCordonelLegacy.ProductionProcesses.Actions
|
|
{
|
|
public class ProductionProcessCheckOrderNumber : BaseProductionProcess
|
|
{
|
|
public event EventHandler isDone;
|
|
private UcBarcodeInput UserControl;
|
|
public DialogResult Result = DialogResult.None;
|
|
public enum DialogResult
|
|
{
|
|
None,
|
|
Retry,
|
|
Print,
|
|
Abort
|
|
}
|
|
public Boolean DialogIsDone { get; }
|
|
public Int32 SerialNumber { get; private set; }
|
|
public Int32 Ordernumber { get; private set; }
|
|
|
|
private Int32? OldOrderNumber { get; }
|
|
|
|
public ProductionProcessCheckOrderNumber(Int32? oldOrderNumber = null)
|
|
|
|
{
|
|
OldOrderNumber = oldOrderNumber;
|
|
|
|
DialogIsDone = false;
|
|
name = "Überprüfe Auftrag";
|
|
currentProcessState = ProductionProcessState.Waiting;
|
|
}
|
|
public override void InitUserControl()
|
|
{
|
|
UserControl = new UcBarcodeInput();
|
|
}
|
|
|
|
public override UserControl GetControl()
|
|
{
|
|
if (UserControl == null)
|
|
{
|
|
throw new Exception($"UserControl {GetType()} not Ready");
|
|
}
|
|
return UserControl;
|
|
}
|
|
|
|
|
|
public override void ProcessDone()
|
|
{
|
|
//clear
|
|
}
|
|
|
|
private void StepDone()
|
|
{
|
|
currentProcessState = ProductionProcessState.Done;
|
|
isDone?.Invoke(this, EventArgs.Empty);
|
|
}
|
|
|
|
private void StepMismatch(String msg)
|
|
{
|
|
|
|
UserControl.SetDesc(msg);
|
|
UserControl.SetFocusMe();
|
|
//UserControl.Focus();
|
|
NewStatus(msg);
|
|
UserControl.BarcodeInput += UserControl_KeyDown;
|
|
|
|
|
|
}
|
|
|
|
private void UserControl_KeyDown(Object sender, String input)
|
|
{
|
|
var a = input;
|
|
|
|
UserControl.txtHiddenInput.Text = "";
|
|
if (OldOrderNumber.HasValue && a == Ordernumber.ToString())
|
|
{
|
|
StepDone();
|
|
}
|
|
else
|
|
{
|
|
StepMismatch($"Falscher oder fehlender Auftrag!{Environment.NewLine}Dieser Zähler ({SerialNumber}) ist teil des Auftrags {Ordernumber}.{Environment.NewLine}Bitte den Auftrag scannen.");
|
|
|
|
}
|
|
|
|
|
|
//StepDone();
|
|
}
|
|
|
|
public override void StartProcess()
|
|
{
|
|
|
|
//get order number
|
|
GetPcbMapping(Meter.PcbId);
|
|
|
|
if (OldOrderNumber.HasValue && OldOrderNumber.Value == Ordernumber)
|
|
{
|
|
StepDone();
|
|
}
|
|
|
|
StepMismatch($"Falscher oder fehlender Auftrag!{Environment.NewLine}Dieser Zähler ({SerialNumber}) ist teil des Auftrags {Ordernumber}.{Environment.NewLine}Bitte den Auftrag scannen.");
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
private void GetPcbMapping(String pcbID)
|
|
{
|
|
if (string.IsNullOrEmpty(pcbID))
|
|
{
|
|
return;
|
|
}
|
|
var url = $"{ServiceUrls.MarriageServiceUrl()}GetSerialNumberAndOrderNumber?PcbId={pcbID}";
|
|
|
|
|
|
try
|
|
{
|
|
var http = (HttpWebRequest)WebRequest.Create(url);
|
|
HttpWebResponse response;
|
|
try
|
|
{
|
|
response = (HttpWebResponse)http.GetResponse();
|
|
}
|
|
catch (WebException exception)
|
|
{
|
|
response = (HttpWebResponse)exception.Response;
|
|
}
|
|
|
|
if (response != null && response.StatusCode == HttpStatusCode.OK)
|
|
{
|
|
var responseStream = response.GetResponseStream();
|
|
if (responseStream != null)
|
|
using (var sr = new StreamReader(responseStream))
|
|
{
|
|
var responseJson = sr.ReadToEnd();
|
|
var a = JsonConvert.DeserializeObject<String[]>(responseJson);
|
|
SerialNumber = Convert.ToInt32(a[0]);
|
|
Ordernumber = Convert.ToInt32(a[1]);
|
|
|
|
Meter.SerialNumber = SerialNumber.ToString();
|
|
}
|
|
}
|
|
else
|
|
{
|
|
throw new InvalidOperationException();
|
|
}
|
|
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
if (ex is WebException)
|
|
{
|
|
//MessageBox.Show($"Error on Store: {Environment.NewLine} { ((WebException)ex).Message}");
|
|
}
|
|
|
|
//MessageBox.Show(ex.Message);
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
}
|