/// /// Copyright (c) 2020 Sensus Slovensko a.s. /// using System; using System.Collections.Generic; using System.Drawing; using System.IO; using System.Linq; using System.Reflection; using System.Windows.Forms; using TracingDB; using TracingDB.Entities; namespace TBF.BenchControl.DataEntry.S620.CheckItems { public partial class Barcode : UserControl, ICheckItem { public override string ToString() { return string.Format(": {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 scannedCodeTextBox.Text; } set { scannedCodeTextBox.Text = value; } } Barcode() { InitializeComponent(); } public Barcode(FormForMechanicalMetersWithTracing parent, Part part) : this() { this.parent = parent; this.part = part; scannedCodeTextBox.Text = (part.DefaultCode != null) ? part.DefaultCode : string.Empty; kodMaterialuLabel.Text = part.Name; descriptionMaterialuLabel.Text = part.Description; if (part.CodeForm == CodeForm.Barcode) { try { Stream imageStream = Assembly.GetExecutingAssembly().GetManifestResourceStream("Pracovisko.Barcode.png"); pictureBox1.Image = new Bitmap(imageStream); } catch {} } } public void ClearCode() { if (part.CodeType != CodeType.Silicon) { scannedCodeTextBox.Text = (part.DefaultCode != null) ? part.DefaultCode : string.Empty; } } public void SubmitCode(string code) { scannedCodeTextBox.Text = code; scannedCodeTextBox_KeyPress(null, new KeyPressEventArgs('\r')); } public void ResetFocus() { setFocusButton.Text = ""; } public void SetFocus() { ClearCode(); setFocusButton.Text = ">"; scannedCodeTextBox.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; PartError error = PartError.None; if (string.IsNullOrEmpty(scannedCodeTextBox.Text)) { error = PartError.FieldEmpty; } else { switch (part.CodeType) { case CodeType.FlowtubeNr: if ((scannedCodeTextBox.Text.Length < 3) || !scannedCodeTextBox.Text.Substring(0, 3).Equals(part.Name.Substring(part.Name.Length - 3))) { error = PartError.WrongPart; } break; case CodeType.FlowtubeNrLU: if ((scannedCodeTextBox.Text.Length < part.Name.Length || !scannedCodeTextBox.Text.Substring(0, part.Name.Length).Equals(part.Name))) { error = PartError.WrongPart; } break; case CodeType.BatchNrContainingPartName: if (!scannedCodeTextBox.Text.Contains(part.Name)) { error = PartError.WrongPart; } break; case CodeType.DateMMYY: break; } } parent.OnBarcodeReceived(this, new BarcodeReceivedEventArgs(scannedCodeTextBox.Text, IxPolozky, Part.CodeLocation, error)); } } }