307 lines
11 KiB
C#
307 lines
11 KiB
C#
///
|
|
/// 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 Oracle.DataAccess.Client;
|
|
//using Oracle.DataAccess.Types;
|
|
using SharedDatabase;
|
|
using SharedDatabase.Entities;
|
|
|
|
namespace Workplace.CheckItems
|
|
{
|
|
public partial class BarcodeAndOraDBQuery : UserControl, IDoubleCheckItem
|
|
{
|
|
public override string ToString()
|
|
{
|
|
return string.Format("Barcode+DBquery: {0} {1}", IxPolozky, Part.Name);
|
|
}
|
|
|
|
WorkplaceDlg parent;
|
|
//OracleConnection oraConn;
|
|
|
|
public Part Part { get; set; }
|
|
public Part Part2 { get; set; }
|
|
public int IxPolozky { get; set; }
|
|
|
|
public IList<string> BlackListedCodes
|
|
{
|
|
get { return blackListedCodes; }
|
|
set
|
|
{
|
|
blackListedCodes = value;
|
|
blackListLabel.Visible = (blackListedCodes != null) && (blackListedCodes.Count > 0);
|
|
}
|
|
}
|
|
IList<string> blackListedCodes;
|
|
|
|
public string ScannedCode
|
|
{
|
|
get { return part1CodeTextBox.Text; }
|
|
set { part1CodeTextBox.Text = value; }
|
|
}
|
|
|
|
public string ScannedCode2
|
|
{
|
|
get { return part2CodeTextBox.Text; }
|
|
set { part2CodeTextBox.Text = value; }
|
|
}
|
|
|
|
BarcodeAndOraDBQuery()
|
|
{
|
|
InitializeComponent();
|
|
blackListedCodes = new List<string>();
|
|
}
|
|
|
|
public BarcodeAndOraDBQuery(WorkplaceDlg parent, Part part1, Part part2 /*, OracleConnection oraConn*/)
|
|
: this()
|
|
{
|
|
this.parent = parent;
|
|
this.Part = part1;
|
|
this.Part2 = part2;
|
|
//this.oraConn = oraConn;
|
|
|
|
part1CodeTextBox.Text = (part1.DefaultCode != null) ? part1.DefaultCode : string.Empty;
|
|
part2CodeTextBox.Text = (part2.DefaultCode != null) ? part2.DefaultCode : string.Empty;
|
|
part1NameLabel.Text = part1.Name;
|
|
part2NameLabel.Text = part2.Name;
|
|
part1DescriptionLabel.Text = part1.Description;
|
|
part2DescriptionLabel.Text = part2.Description;
|
|
|
|
if (part1.CodeForm == (sbyte)CodeForm.Barcode)
|
|
{
|
|
try
|
|
{
|
|
Stream imageStream = Assembly.GetExecutingAssembly().GetManifestResourceStream("Workplace.Barcode.png");
|
|
pictureBox1.Image = new Bitmap(imageStream);
|
|
}
|
|
catch {}
|
|
}
|
|
}
|
|
|
|
public void ClearCode()
|
|
{
|
|
part1CodeTextBox.Text = (Part.DefaultCode != null) ? Part.DefaultCode : string.Empty;
|
|
part2CodeTextBox.Text = (Part2.DefaultCode != null) ? Part2.DefaultCode : string.Empty;
|
|
}
|
|
|
|
public void SubmitCode(string code)
|
|
{
|
|
part2CodeTextBox.Text = code;
|
|
part2CodeTextBox_KeyPress(null, new KeyPressEventArgs('\r'));
|
|
}
|
|
|
|
public void ResetFocus()
|
|
{
|
|
setFocusButton.Text = "";
|
|
}
|
|
|
|
public void SetFocus()
|
|
{
|
|
ClearCode();
|
|
setFocusButton.Text = ">";
|
|
part2CodeTextBox.Focus();
|
|
}
|
|
|
|
private void setFocusButton_Click(object sender, EventArgs e)
|
|
{
|
|
setFocusButton.Text = ">";
|
|
parent.OnFocusPressed(this, new FocusPressedEventArgs(IxPolozky, Part.CodeLocation));
|
|
}
|
|
|
|
private void part2CodeTextBox_KeyPress(object sender, KeyPressEventArgs e)
|
|
{
|
|
if (e.KeyChar != '\r') return;
|
|
|
|
// Ahoj,
|
|
// Predpokladam, ze ten kod snimas z krabice/etikety. Tam okrem serioveho cisla moze byt aj radioadresa.
|
|
// A dalsi problem moze byt, ze ak nejake seriove cislo nahradia inym vodomerom, tak v Z_NR_KOMPLETT to priradene
|
|
// seriove cislo zostava aj tomu vymazanemu vodomeru a bude ho mat aj novy vodomer => bude existovat viac zaznamov
|
|
// s rovnakym cislom v Z_NR_KOMPLETT ale s roznymi cislami PCB.
|
|
// Pouzi tento skript a do serialNumber vloz zosnimany kod:
|
|
//
|
|
// string sqlScript = $@"
|
|
// select *
|
|
// from VT_ZAEHLER_PD
|
|
// where (VT_ZAEHLER_PD.Z_NR_KOMPLETT = '{serialNumber}' OR VT_ZAEHLER_PD.VT_MODUL_SNR = '{serialNumber}'
|
|
// OR
|
|
// ((VT_ZAEHLER_PD.Z_NR_KOMPLETT like substr('{serialNumber}',1,length('{serialNumber}') - 2) || '%')
|
|
// and
|
|
// (VT_ZAEHLER_PD.Z_NR_KOMPLETT || trim(VT_ZAEHLER_PD.SUFFIX) = '{serialNumber}')
|
|
// )) AND ZAEHLERNUMMER > 0
|
|
// ";
|
|
// Pouzivam ho uz roky a funguje bez chyb. Je vyladeny aj vzhladom na databazove indexy, aby to bolo co najrychlejsie.
|
|
// S pozdravom/Mit freundlichen Grüssen/Best regards
|
|
// Jan Augustin
|
|
///
|
|
/// Read PCB number from the database
|
|
///
|
|
string pcbNr = string.Empty;
|
|
int suffixLen = 0;
|
|
int.TryParse(suffixLenTextBox.Text, out suffixLen);
|
|
try
|
|
{
|
|
// oraConn.Open();
|
|
// OracleCommand cmd;
|
|
// if (suffixLen > 0)
|
|
// {
|
|
// cmd = new OracleCommand("SELECT vt_fernum FROM vt_zaehler_pd WHERE z_nr_komplett = :1 AND anbid = 4 AND zaehlernummer > 0", oraConn);
|
|
// int suffixStart = Math.Max(0, ScannedCode2.Length - suffixLen);
|
|
// string zNrComplet = ScannedCode2.Substring(0, suffixStart);
|
|
// string suffix = ScannedCode2.Substring(suffixStart);
|
|
// cmd.Parameters.Add(new OracleParameter { OracleDbType = OracleDbType.Varchar2, Value = zNrComplet, }); /// :1 z_nr_komplett
|
|
//// cmd.Parameters.Add(new OracleParameter { OracleDbType = OracleDbType.Varchar2, Value = suffix, }); /// :2 suffix
|
|
// }
|
|
// else
|
|
// {
|
|
// cmd = new OracleCommand("SELECT vt_fernum FROM vt_zaehler_pd WHERE anbid = 4 AND z_nr_komplett = :1 AND zaehlernummer > 0", oraConn);
|
|
// cmd.Parameters.Add(new OracleParameter { OracleDbType = OracleDbType.Varchar2, Value = ScannedCode2 }); /// :1 z_nr_komplett
|
|
// }
|
|
|
|
// OracleDataReader dr = cmd.ExecuteReader();
|
|
// if (dr.Read())
|
|
// {
|
|
// pcbNr = dr.GetString(0);
|
|
// }
|
|
// dr.Close();
|
|
// oraConn.Close();
|
|
}
|
|
catch (Exception)
|
|
{
|
|
//oraConn.Close();
|
|
pcbNr = string.Empty;
|
|
}
|
|
|
|
part1CodeTextBox.Text = pcbNr;
|
|
|
|
PartError error = PartError.None;
|
|
if (string.IsNullOrEmpty(part1CodeTextBox.Text))
|
|
{
|
|
error = PartError.FieldEmpty;
|
|
}
|
|
else
|
|
{
|
|
switch ((CodeType)Part.CodeType)
|
|
{
|
|
case CodeType.FlowtubeNr:
|
|
if ((part1CodeTextBox.Text.Length < 3) || !part1CodeTextBox.Text.Substring(0, 3).Equals(Part.Name.Substring(Part.Name.Length - 3)))
|
|
{
|
|
error = PartError.WrongPart;
|
|
}
|
|
break;
|
|
|
|
case CodeType.FlowtubeNrLU:
|
|
if ((part1CodeTextBox.Text.Length < Part.Name.Length ||
|
|
!part1CodeTextBox.Text.Substring(0, Part.Name.Length).Equals(Part.Name)))
|
|
{
|
|
error = PartError.WrongPart;
|
|
}
|
|
break;
|
|
|
|
case CodeType.BatchNrContainingPartName:
|
|
if (!part1CodeTextBox.Text.Contains(Part.Name))
|
|
{
|
|
error = PartError.WrongPart;
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
|
|
parent.OnBarcodeReceived(this, new BarcodeReceivedEventArgs(part1CodeTextBox.Text, IxPolozky, Part.CodeLocation, error));
|
|
}
|
|
|
|
private void Polozka_MouseClick(object sender, MouseEventArgs e)
|
|
{
|
|
if (e.Button != MouseButtons.Right) return;
|
|
|
|
LocalSettingsFormForPolozka dlg = new LocalSettingsFormForPolozka();
|
|
if (dlg.ShowDialog() != DialogResult.OK) return;
|
|
|
|
if (string.IsNullOrEmpty(dlg.BlackListFileName))
|
|
{
|
|
if (this.IxPolozky == Program.LocalSettings.BlackListIx1)
|
|
{
|
|
Program.LocalSettings.BlackListIx1 = 0;
|
|
Program.LocalSettings.BlackListFile1 = string.Empty;
|
|
}
|
|
|
|
if (this.IxPolozky == Program.LocalSettings.BlackListIx2)
|
|
{
|
|
Program.LocalSettings.BlackListIx2 = 0;
|
|
Program.LocalSettings.BlackListFile2 = string.Empty;
|
|
}
|
|
|
|
if (this.IxPolozky == Program.LocalSettings.BlackListIx3)
|
|
{
|
|
Program.LocalSettings.BlackListIx3 = 0;
|
|
Program.LocalSettings.BlackListFile3 = string.Empty;
|
|
}
|
|
}
|
|
else if (Program.LocalSettings.BlackListIx1 == this.IxPolozky)
|
|
{
|
|
Program.LocalSettings.BlackListIx1 = this.IxPolozky;
|
|
Program.LocalSettings.BlackListFile1 = dlg.BlackListFileName;
|
|
}
|
|
else if (Program.LocalSettings.BlackListIx2 == this.IxPolozky)
|
|
{
|
|
Program.LocalSettings.BlackListIx2 = this.IxPolozky;
|
|
Program.LocalSettings.BlackListFile2 = dlg.BlackListFileName;
|
|
}
|
|
else if (Program.LocalSettings.BlackListIx3 == this.IxPolozky)
|
|
{
|
|
Program.LocalSettings.BlackListIx3 = this.IxPolozky;
|
|
Program.LocalSettings.BlackListFile3 = dlg.BlackListFileName;
|
|
}
|
|
else if (Program.LocalSettings.BlackListIx1 == 0)
|
|
{
|
|
Program.LocalSettings.BlackListIx1 = this.IxPolozky;
|
|
Program.LocalSettings.BlackListFile1 = dlg.BlackListFileName;
|
|
}
|
|
else if (Program.LocalSettings.BlackListIx2 == 0)
|
|
{
|
|
Program.LocalSettings.BlackListIx2 = this.IxPolozky;
|
|
Program.LocalSettings.BlackListFile2 = dlg.BlackListFileName;
|
|
}
|
|
else if (Program.LocalSettings.BlackListIx3 == 0)
|
|
{
|
|
Program.LocalSettings.BlackListIx3 = this.IxPolozky;
|
|
Program.LocalSettings.BlackListFile3 = dlg.BlackListFileName;
|
|
}
|
|
else
|
|
{
|
|
MessageBox.Show("Too many black lists, the black list was not saved !");
|
|
return;
|
|
}
|
|
|
|
BlackListedCodes = !string.IsNullOrEmpty(dlg.BlackListFileName) ? Workplace.BlackList.FromFile(dlg.BlackListFileName).Codes : null;
|
|
Program.LocalSettings.Save();
|
|
}
|
|
|
|
private void BarcodeAndOraDBQuery_Load(object sender, EventArgs e)
|
|
{
|
|
|
|
}
|
|
|
|
private void suffixLenUpButton_Click(object sender, EventArgs e)
|
|
{
|
|
int suffixLen = 0;
|
|
int.TryParse(suffixLenTextBox.Text, out suffixLen);
|
|
suffixLen++;
|
|
suffixLenTextBox.Text = suffixLen.ToString();
|
|
}
|
|
|
|
private void suffixLenDownButton_Click(object sender, EventArgs e)
|
|
{
|
|
int suffixLen = 0;
|
|
int.TryParse(suffixLenTextBox.Text, out suffixLen);
|
|
if (suffixLen > 0) suffixLen--;
|
|
suffixLenTextBox.Text = suffixLen.ToString();
|
|
}
|
|
}
|
|
}
|