tbf/TBF/BenchControl/DataEntry/S620/CheckItems/OkNok.cs

133 lines
3.3 KiB
C#

///
/// Copyright (c) 2020 Sensus Slovensko a.s.
///
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using TracingDB.Entities;
namespace TBF.BenchControl.DataEntry.S620.CheckItems
{
public partial class OkNok : UserControl, ICheckItem
{
public override string ToString()
{
return string.Format("Ok/Nok: {0} {1}({2})", IxPolozky, Part.Name, string.IsNullOrEmpty(Part.OraDBType) ? string.Empty : Part.OraDBType);
}
FormForMechanicalMetersWithTracing parent;
public Part Part { get { return part; } }
Part part;
public int IxPolozky
{
get { return ixPolozky; }
set { ixPolozky = value; }
}
int ixPolozky;
public string ScannedCode
{
get { return checkBox1.Checked ? "OK" : "NOK"; }
set
{
if (string.IsNullOrEmpty(value))
{
checkBox1.Checked = false;
checkBox2.Checked = false;
}
else if (value.ToLower().Equals("ok"))
{
checkBox1.Checked = true;
checkBox2.Checked = false;
}
else if (value.ToLower().Equals("nok"))
{
checkBox1.Checked = false;
checkBox2.Checked = true;
}
else
{
checkBox1.Checked = false;
checkBox2.Checked = false;
}
}
}
OkNok()
{
InitializeComponent();
}
public OkNok(FormForMechanicalMetersWithTracing parent, TracingDB.Entities.Part part)
: this()
{
this.parent = parent;
this.part = part;
kodMaterialuLabel.Text = part.Name;
descriptionMaterialuLabel.Text = part.Description;
}
public void ClearCode()
{
checkBox1.Checked = false;
checkBox2.Checked = false;
}
public void SubmitCode(string code)
{
ScannedCode = code;
scannedCodeTextBox_KeyPress(null, new KeyPressEventArgs('\r'));
}
public void ResetFocus()
{
setFocusButton.Text = "";
}
public void SetFocus()
{
setFocusButton.Text = ">";
checkBox1.Checked = false;
checkBox2.Checked = false;
checkBox1.Focus();
}
private void setFocusButton_Click(object sender, EventArgs e)
{
setFocusButton.Text = ">";
parent.OnFocusPressed(this, new FocusPressedEventArgs(IxPolozky, Part.CodeLocation));
}
private void scannedCodeTextBox_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar != '\r') return;
parent.OnBarcodeReceived(this, new BarcodeReceivedEventArgs(ScannedCode, IxPolozky, Part.CodeLocation));
return;
}
private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
if (checkBox1.Checked)
{
checkBox2.Checked = false;
parent.OnBarcodeReceived(this, new BarcodeReceivedEventArgs(ScannedCode, IxPolozky, Part.CodeLocation));
}
return;
}
private void checkBox2_CheckedChanged(object sender, EventArgs e)
{
if (checkBox2.Checked)
{
checkBox1.Checked = false;
parent.OnBarcodeReceived(this, new BarcodeReceivedEventArgs(ScannedCode, IxPolozky, Part.CodeLocation));
}
return;
}
}
}