2020-12-07 13:36:21 +00:00
///
2021-02-02 11:30:27 +00:00
/// Copyright (c) 2020-2021 Sensus Slovensko a.s.
2020-12-07 13:36:21 +00:00
///
using System ;
using System.Collections.Generic ;
using System.Windows.Forms ;
using log4net ;
using TBF.BenchControl.Sequences ;
using TBF.Resources ;
using Oracle.DataAccess.Client ;
using TracingDB.Entities ;
using NHibernate ;
using TracingDB ;
2021-02-02 11:30:27 +00:00
using System.Drawing ;
2020-12-07 13:36:21 +00:00
namespace TBF.BenchControl.DataEntry.S620
{
2021-02-02 11:30:27 +00:00
public partial class FormForMechanicalMetersWithTracing : Form , ICycleBeginOrEndForm , GenericDevices . IHasCompleted
2020-12-07 13:36:21 +00:00
{
private static readonly ILog log = LogManager . GetLogger ( typeof ( FormForMechanicalMetersWithTracing ) ) ;
/// <summary> Number of water meters </summary>
IList < Results . Entities . WaterMeter > waterMeters ;
readonly int wmsCount ;
2021-02-02 11:30:27 +00:00
readonly int maxWMsCount ;
readonly char closeButton ;
readonly bool atTheEnd ;
2020-12-07 13:36:21 +00:00
/// To be retrieved after the form is closed
2021-02-02 11:30:27 +00:00
string purchaseOrder ;
public string PurchaseOrder { get { return purchaseOrder ; } set { purchaseOrder = value ; } }
string [ ] bodyNrText ;
public string [ ] BodyNrText { get { return bodyNrText ; } set { bodyNrText = value ; } }
int [ ] assignedSerialNr ;
public int [ ] AssignedSerialNr { get { return assignedSerialNr ; } set { assignedSerialNr = value ; } }
string [ ] completeSerialNr ;
public string [ ] CompleteSerialNr { get { return completeSerialNr ; } set { completeSerialNr = value ; } }
bool [ ] disabled ;
public bool [ ] Disabled { get { return disabled ; } set { disabled = value ; } }
string prefix ; /// S/N prefix - Loaded from Oracle DB table VT_AUFTRAG_PD
public string Prefix { get { return prefix ; } set { prefix = value ; } }
2020-12-07 13:36:21 +00:00
2021-02-02 11:30:27 +00:00
string suffix ; /// S/N suffix - Loaded from Oracle DB table VT_AUFTRAG_PD
public string Suffix { get { return suffix ; } set { suffix = value ; } }
///
/// Production order related
///
2020-12-07 13:36:21 +00:00
/// Loaded from Oracle DB table VT_AUFTRAG_PD
int firstSN ; /// First serial number
int snDigits ; /// Number of digits of the middle part of the serial number
int pcsCount ; /// Pieces count
IList < BodySerNrResult > foundMeters ;
2021-02-02 11:30:27 +00:00
IList < int > foundSNs ;
2020-12-07 13:36:21 +00:00
IList < int > assignedSNs ;
/// Entered manually
int snRangeFirst ; /// 0 = invalid
int snRangeLast ; /// 0 = invalid
///
2021-02-02 11:30:27 +00:00
/// Production tracing - part that persists between different forms (production cycles)
2020-12-07 13:36:21 +00:00
///
2021-02-02 11:30:27 +00:00
static IList < Process > workflows ; /// Workflows from the database
static Process currentWorkflow ; /// Currently used workflow
static Workstep currentWStep ; /// Currently used workflow step
static IList < Workstep > stepsOfTheCurrentWorkflow ;
static IList < Part > uniqueCodeParts ;
static IList < ICheckItem > palety ;
static FormForMechanicalMetersWithTracing ( )
{
workflows = new List < Process > ( ) ;
currentWorkflow = null ;
currentWStep = null ;
stepsOfTheCurrentWorkflow = new List < Workstep > ( ) ;
uniqueCodeParts = new List < Part > ( ) ;
palety = new List < ICheckItem > ( ) ;
}
2020-12-07 13:36:21 +00:00
2021-02-02 11:30:27 +00:00
///
/// Production tracing
///
ISession dbSession ;
2020-12-07 13:36:21 +00:00
/// Previous workstep verification
Workstep verifiedWorkstep ;
2021-02-02 11:30:27 +00:00
Part verifiedPart ; /// Applicable when verifyReferencePart == false
2020-12-07 13:36:21 +00:00
bool verifyReferencePart ;
2021-02-02 11:30:27 +00:00
///
/// UI
///
Color oriBackColor ;
Rectangle rect ;
int textBoxesCount ; /// Number of text boxes for serial numbers
2020-12-07 13:36:21 +00:00
Label [ ] labels ;
2021-02-02 11:30:27 +00:00
TextBox [ ] bodyNrBoxes ;
2020-12-07 13:36:21 +00:00
TextBox [ ] serialNrBoxes ;
CheckBox [ ] checkBoxes ;
2021-02-02 11:30:27 +00:00
int nextWaterMeterIx ;
bool loadedOnce ; /// Set when this form loads for the first time
public bool Completed { get { return completed ; } }
bool completed ; /// Set when this form closes
2020-12-07 13:36:21 +00:00
/// <summary> Parameterless constructor for common functionality </summary>
public FormForMechanicalMetersWithTracing ( )
{
InitializeComponent ( ) ;
ControlBox = false ;
2021-02-02 11:30:27 +00:00
oriBackColor = BackColor ;
2020-12-07 13:36:21 +00:00
ManageCheckGroupBox ( batchesCheckBox , batchesGroupBox ) ;
2021-02-02 11:30:27 +00:00
ManageCheckGroupBox ( orderCheckBox , orderGroupBox ) ;
2020-12-07 13:36:21 +00:00
firstSN = 0 ;
snDigits = 0 ;
pcsCount = 0 ;
2021-02-02 11:30:27 +00:00
prefix = null ;
suffix = null ;
2020-12-07 13:36:21 +00:00
foundMeters = new List < BodySerNrResult > ( ) ;
2021-02-02 11:30:27 +00:00
foundSNs = new List < int > ( ) ;
2020-12-07 13:36:21 +00:00
assignedSNs = new List < int > ( ) ;
snRangeFirst = 0 ;
snRangeLast = 0 ;
textBoxesCount = 40 ;
labels = new Label [ ]
{
label1 , label2 , label3 , label4 , label5 , label6 , label7 , label8 , label9 , label10 ,
label11 , label12 , label13 , label14 , label15 , label16 , label17 , label18 , label19 , label20 ,
label21 , label22 , label23 , label24 , label25 , label26 , label27 , label28 , label29 , label30 ,
label31 , label32 , label33 , label34 , label35 , label36 , label37 , label38 , label39 , label40 ,
} ;
2021-02-02 11:30:27 +00:00
bodyNrBoxes = new TextBox [ ]
2020-12-07 13:36:21 +00:00
{
textBox1 , textBox2 , textBox3 , textBox4 , textBox5 , textBox6 , textBox7 , textBox8 , textBox9 , textBox10 ,
textBox11 , textBox12 , textBox13 , textBox14 , textBox15 , textBox16 , textBox17 , textBox18 , textBox19 , textBox20 ,
textBox21 , textBox22 , textBox23 , textBox24 , textBox25 , textBox26 , textBox27 , textBox28 , textBox29 , textBox30 ,
textBox31 , textBox32 , textBox33 , textBox34 , textBox35 , textBox36 , textBox37 , textBox38 , textBox39 , textBox40 ,
} ;
2021-01-12 10:40:29 +00:00
serialNrBoxes = new TextBox [ ]
2020-12-07 13:36:21 +00:00
{
textBox41 , textBox42 , textBox43 , textBox44 , textBox45 , textBox46 , textBox47 , textBox48 , textBox49 , textBox50 ,
textBox51 , textBox52 , textBox53 , textBox54 , textBox55 , textBox56 , textBox57 , textBox58 , textBox59 , textBox60 ,
textBox61 , textBox62 , textBox63 , textBox64 , textBox65 , textBox66 , textBox67 , textBox68 , textBox69 , textBox70 ,
textBox71 , textBox72 , textBox73 , textBox74 , textBox75 , textBox76 , textBox77 , textBox78 , textBox79 , textBox80 ,
} ;
checkBoxes = new CheckBox [ ]
{
checkBox1 , checkBox2 , checkBox3 , checkBox4 , checkBox5 , checkBox6 , checkBox7 , checkBox8 , checkBox9 , checkBox10 ,
checkBox11 , checkBox12 , checkBox13 , checkBox14 , checkBox15 , checkBox16 , checkBox17 , checkBox18 , checkBox19 , checkBox20 ,
checkBox21 , checkBox22 , checkBox23 , checkBox24 , checkBox25 , checkBox26 , checkBox27 , checkBox28 , checkBox29 , checkBox30 ,
checkBox31 , checkBox32 , checkBox33 , checkBox34 , checkBox35 , checkBox36 , checkBox37 , checkBox38 , checkBox39 , checkBox40 ,
} ;
2021-02-02 11:30:27 +00:00
System . Diagnostics . Debug . Assert ( labels . Length = = textBoxesCount ) ;
System . Diagnostics . Debug . Assert ( bodyNrBoxes . Length = = textBoxesCount ) ;
System . Diagnostics . Debug . Assert ( serialNrBoxes . Length = = textBoxesCount ) ;
System . Diagnostics . Debug . Assert ( checkBoxes . Length = = textBoxesCount ) ;
2020-12-07 13:36:21 +00:00
2021-02-02 11:30:27 +00:00
rect = new Rectangle ( orderGroupBox . Left , orderGroupBox . Top + orderGroupBox . Height + 10 , orderGroupBox . Width , 30 ) ;
2020-12-07 13:36:21 +00:00
2021-02-02 11:30:27 +00:00
nextWaterMeterIx = 0 ;
loadedOnce = false ;
2020-12-07 13:36:21 +00:00
completed = false ;
2021-02-02 11:30:27 +00:00
ColorFlashHandler + = delegate ( object sender , ColorFlashEventArgs args )
{
if ( InvokeRequired ) { Invoke ( new EventHandler < ColorFlashEventArgs > ( OnColorFlash ) , sender , args ) ; }
else OnColorFlash ( sender , args ) ;
} ;
2020-12-07 13:36:21 +00:00
StartForceCloseHandler ( ) ;
}
#region Forced close handling
public void StartForceCloseHandler ( )
{
UiBridge . Bridge . CloseModelessFormHandler + = delegate ( object sender , EventArgs args )
{
if ( InvokeRequired ) { Invoke ( new EventHandler < EventArgs > ( OnForceClose ) , sender , args ) ; }
else OnForceClose ( sender , args ) ;
} ;
}
private void OnForceClose ( object sender , EventArgs args )
{
DialogResult = DialogResult . Cancel ;
Close ( ) ;
}
#endregion
/// <summary>
/// Constructor
/// </summary>
/// <param name="waterMetersCount">Number of text boxes for serial numbers</param>
2021-02-02 11:30:27 +00:00
public FormForMechanicalMetersWithTracing ( IList < Results . Entities . WaterMeter > waterMeters , int maxWMsCount , char closeButton , bool atTheEnd )
2020-12-07 13:36:21 +00:00
: this ( )
{
this . waterMeters = waterMeters ;
2021-02-02 11:30:27 +00:00
this . maxWMsCount = maxWMsCount ;
this . wmsCount = Math . Min ( waterMeters . Count , maxWMsCount ) ;
this . closeButton = closeButton ;
this . atTheEnd = atTheEnd ;
bodyNrText = new string [ waterMeters . Count ] ;
assignedSerialNr = new int [ waterMeters . Count ] ;
completeSerialNr = new string [ waterMeters . Count ] ;
disabled = new bool [ waterMeters . Count ] ;
/// Disable controls that exceed the number of water meters in case textBoxesCount > wmsCount
for ( int i = wmsCount ; i < textBoxesCount ; i + + )
{
labels [ i ] . Visible = bodyNrBoxes [ i ] . Visible = serialNrBoxes [ i ] . Visible = checkBoxes [ i ] . Visible = false ;
}
/// Disable water meters that exceed the maximum number of water meters
for ( int i = wmsCount ; i < waterMeters . Count ; i + + )
{
if ( waterMeters [ i ] ! = null ) disabled [ i ] = true ;
}
2020-12-07 13:36:21 +00:00
2021-02-02 11:30:27 +00:00
textBoxesCount = Math . Min ( textBoxesCount , wmsCount ) ;
2020-12-07 13:36:21 +00:00
if ( TracingDB . DB . SessionFactory ! = null )
{
try
{
dbSession = TracingDB . DB . SessionFactory . OpenSession ( ) ;
}
catch ( Exception exc )
{
DialogResult rslt = MessageBox . Show ( Strings . Opening_production_tracing_DB_failed +
Environment . NewLine + Environment . NewLine + exc . Message ,
Strings . Error ,
MessageBoxButtons . OK ,
MessageBoxIcon . Exclamation ) ;
}
2021-02-02 11:30:27 +00:00
if ( workflows . Count = = 0 & & dbSession ! = null )
2020-12-07 13:36:21 +00:00
{
2021-02-02 11:30:27 +00:00
workflows = ReadReleasedActiveProcesses ( dbSession ) ;
if ( workflows = = null )
2020-12-07 13:36:21 +00:00
{
MessageBox . Show ( Strings . Reading_from_the_production_tracing_DB_failed ,
Strings . Error ,
MessageBoxButtons . OK ,
MessageBoxIcon . Exclamation ) ;
2021-02-02 11:30:27 +00:00
workflows = new List < Process > ( ) ;
2020-12-07 13:36:21 +00:00
}
}
}
BarcodeReceivedHandler + = delegate ( object sndr , BarcodeReceivedEventArgs args )
{
if ( InvokeRequired ) { Invoke ( new EventHandler < BarcodeReceivedEventArgs > ( BarcodeReceived ) , sndr , args ) ; }
else { BarcodeReceived ( sndr , args ) ; }
} ;
FocusPressedHandler + = delegate ( object sndr , FocusPressedEventArgs args )
{
if ( InvokeRequired ) { Invoke ( new EventHandler < FocusPressedEventArgs > ( FocusPressed ) , sndr , args ) ; }
else { FocusPressed ( sndr , args ) ; }
} ;
}
private void CycleBeginningForm_Load ( object sender , EventArgs e )
{
Localize ( ) ;
2021-02-02 11:30:27 +00:00
/// Production tracing
UpdateWorkflowCombo ( workflows , ( currentWorkflow ! = null ) ? currentWorkflow . Name : Program . LocalSettings . LastWorkflow ) ;
currentWorkflow = Process . GetProcessFromName ( workflows , workflowComboBox . Text ) ;
stepsOfTheCurrentWorkflow = ( currentWorkflow ! = null ) ? currentWorkflow . Worksteps : new List < Workstep > ( ) ;
currentWStep = UpdateWStepCombo ( currentWorkflow , ( currentWStep ! = null ) ? currentWStep . Name : Program . LocalSettings . LastWStep ) ;
UpdateItems ( currentWorkflow , currentWStep ) ;
RedrawItems ( ) ;
if ( currentWorkflow ! = null ) LoadCodesFromDictionary ( currentWorkflow . Name , palety ) ;
2020-12-07 13:36:21 +00:00
2021-02-02 11:30:27 +00:00
/// P/O and serial number assignment
PrepareOrderAndSNRangeCombos ( ) ;
2020-12-07 13:36:21 +00:00
2021-02-02 11:30:27 +00:00
/// TextBox-es
for ( int i = 0 ; i < textBoxesCount ; i + + )
{
if ( waterMeters [ i ] . Disabled )
2020-12-07 13:36:21 +00:00
{
2021-02-02 11:30:27 +00:00
bodyNrBoxes [ i ] . Enabled = serialNrBoxes [ i ] . Enabled = checkBoxes [ i ] . Enabled = false ;
disabled [ i ] = true ;
checkBoxes [ i ] . Checked = false ;
2020-12-07 13:36:21 +00:00
}
2021-02-02 11:30:27 +00:00
else if ( atTheEnd )
2020-12-07 13:36:21 +00:00
{
2021-02-02 11:30:27 +00:00
/// At the end
disabled [ i ] = false ;
bodyNrBoxes [ i ] . Text = bodyNrText [ i ] = waterMeters [ i ] . SerialNr ;
checkBoxes [ i ] . Checked = true ;
bodyNrBoxes [ i ] . Enabled = false ; /// Do not allow body number change
serialNrBoxes [ i ] . Enabled = false ; /// Do not allow serial number change from UI
checkBoxes [ i ] . Enabled = true ; /// Allow 'disabled' check box change
2020-12-07 13:36:21 +00:00
2021-02-02 11:30:27 +00:00
/// Highlight failed water meters
if ( ! waterMeters [ i ] . PassedFromTests ( ) )
{
bodyNrBoxes [ i ] . BackColor = System . Drawing . Color . Pink ;
serialNrBoxes [ i ] . BackColor = System . Drawing . Color . Pink ;
}
}
else
2020-12-07 13:36:21 +00:00
{
2021-02-02 11:30:27 +00:00
/// At the beginning
bodyNrBoxes [ i ] . Enabled = true ;
serialNrBoxes [ i ] . Enabled = false ;
checkBoxes [ i ] . Checked = false ;
2020-12-07 13:36:21 +00:00
}
}
2021-02-02 11:30:27 +00:00
#if DEBUG
reloadButton . Enabled = true ;
#else
2020-12-07 13:36:21 +00:00
if ( ProcessData . OracleDB ! = null & & ProcessData . OracleDB . SelectedDB ! = null )
{
reloadButton . Enabled = true ;
}
#endif
2021-02-02 11:30:27 +00:00
if ( atTheEnd )
{
ProcessPO ( ) ;
UpdateSNFromTo ( ) ;
AssignSerialNumbers ( ) ;
}
loadedOnce = true ;
2020-12-07 13:36:21 +00:00
}
void Localize ( )
{
Text = Strings . Data ;
2021-02-02 11:30:27 +00:00
workflowGroupBox . Text = "Pracovný postup" ;
workstepGroupBox . Text = "Krok prac. postupu" ;
orderCheckBox . Text = "Výrobná zakázka a sériové čísla" ;
2020-12-07 13:36:21 +00:00
firstSNLabel . Text = "prvé s/n" ;
snDigitsLabel . Text = "číslic" ;
piecesCountLabel . Text = "kusov" ;
2021-02-02 11:30:27 +00:00
reloadButton . Text = "@" ;
2020-12-07 13:36:21 +00:00
fromLabel . Text = "od" ;
toLabel . Text = "do" ;
serialNumbersGroupBox . Text = "Sériové čísla" ;
bodyLabel . Text = bodyLabel2 . Text = "Číslo púzdra" ;
snLabel . Text = snLabel2 . Text = "Sériové číslo" ;
2021-02-02 11:30:27 +00:00
batchesCheckBox . Text = "Šarže" ;
okButton . Text = Strings . OkBtnText ;
//clearButton.Text = Strings.ClearBtnText;
}
void AssignSerialNumbers ( )
{
assignedSNs . Clear ( ) ;
2020-12-07 13:36:21 +00:00
for ( int i = 0 ; i < textBoxesCount ; i + + )
{
2021-02-02 11:30:27 +00:00
if ( waterMeters [ i ] . PassedFromTests ( ) & & ! string . IsNullOrEmpty ( bodyNrBoxes [ i ] . Text ) & & checkBoxes [ i ] . Checked )
{
int nextSN = GetNextSerialNr ( ) ;
serialNrBoxes [ i ] . Text = ( nextSN > 0 ) ? nextSN . ToString ( ) : string . Empty ;
}
else
{
serialNrBoxes [ i ] . Text = string . Empty ;
}
2020-12-07 13:36:21 +00:00
}
2021-02-02 11:30:27 +00:00
Invalidate ( rect ) ;
}
private void FormForMechanicalMetersWithTracing_Shown ( object sender , EventArgs e )
{
nextWaterMeterIx = 0 ;
FocusToNextField ( ) ;
}
void FocusToNextField ( )
{
( atTheEnd ? serialNrBoxes [ nextWaterMeterIx ] : bodyNrBoxes [ nextWaterMeterIx ] ) . Focus ( ) ;
2020-12-07 13:36:21 +00:00
}
2021-02-02 11:30:27 +00:00
/// <summary>
/// Redraw workflows in workflow combo box. Try to keep Program.LocalSettings.LastProcess selected.
/// In case of a change in ReleaseActive processes in the DB it may not be possible to keep this selection.
/// In such case function returns null.
/// When process selection changes, 'processComboBox_SelectedIndexChanged' is invoked.
/// </summary>
/// <returns>true = list of processes changed</returns>
bool UpdateWorkflowCombo ( IList < Process > workflows , string oriWorkflowName )
{
bool anyDifference = ( workflows . Count ! = workflowComboBox . Items . Count ) ;
if ( ! anyDifference )
{
for ( int i = 0 ; i < workflows . Count ; i + + )
{
if ( workflowComboBox . Items . Count < = i | | workflowComboBox . Items [ i ] . ToString ( ) ! = workflows [ i ] . Name )
{
anyDifference = true ;
break ;
}
}
}
if ( ! anyDifference ) return false ;
int selectedIndex = - 1 ;
workflowComboBox . Items . Clear ( ) ;
for ( int i = 0 ; i < workflows . Count ; i + + )
{
workflowComboBox . Items . Add ( workflows [ i ] . Name ) ;
if ( ! string . IsNullOrEmpty ( oriWorkflowName ) & & ( workflows [ i ] . Name = = oriWorkflowName ) )
{
selectedIndex = i ;
}
}
workflowComboBox . SelectedIndex = selectedIndex ;
return true ;
}
private void workflowComboBox_SelectedIndexChanged ( object sender , EventArgs e )
{
if ( ! loadedOnce ) return ;
Process process = Process . GetProcessFromName ( workflows , workflowComboBox . Text ) ;
Workstep workstep = UpdateWStepCombo ( process , workstepComboBox . Text ) ;
if ( UpdateItems ( process , workstep ) )
{
ClearCodesOfBatches ( ) ;
}
FocusToNextField ( ) ;
}
private void reloadWorkflowsButton_Click ( object sender , EventArgs e )
{
workflows = ReadReleasedActiveProcesses ( dbSession ) ;
if ( workflows = = null )
{
MessageBox . Show ( Strings . Reading_from_the_production_tracing_DB_failed ,
Strings . Error ,
MessageBoxButtons . OK ,
MessageBoxIcon . Exclamation ) ;
workflows = new List < Process > ( ) ;
}
UpdateWorkflowCombo ( workflows , workflowComboBox . Text ) ;
}
/// <summary>
/// Updates workstep selection combo items and text. Clear it only if process == null.
/// If there is a valid 'oriWorkstepName', the combo box text is set and the selected workstep is returned.
/// Otherwise this function returns null.
/// </summary>
/// <param name="workflow">Process with worksteps to be used</param>
/// <param name="oriWStepName">Originally selected workstep name</param>
/// <returns>New selected workstep or null</returns>
private Workstep UpdateWStepCombo ( Process workflow , string oriWStepName )
{
Workstep selectedWStep = null ;
workstepComboBox . Items . Clear ( ) ;
if ( workflow ! = null )
{
foreach ( var ws in workflow . Worksteps )
{
workstepComboBox . Items . Add ( ws ) ;
if ( ! string . IsNullOrEmpty ( oriWStepName ) & & ( ws . Name = = oriWStepName ) )
{
/// If one of new worksteps matches the original one, set the combo box text
/// and later (after completing the loop) return the new workstep.
selectedWStep = ws ;
}
}
}
workstepComboBox . Text = ( selectedWStep ! = null ) ? selectedWStep . Name : string . Empty ;
return selectedWStep ;
}
private void workstepComboBox_SelectedIndexChanged ( object sender , EventArgs e )
{
if ( ! loadedOnce ) return ;
/// Update 'currentWorkstep'
Workstep workstep = null ;
foreach ( var w in currentWorkflow . Worksteps )
{
if ( w . ToString ( ) = = workstepComboBox . Text )
{
workstep = w ;
Program . LocalSettings . LastWStep = w . Name ;
Program . LocalSettings . Save ( ) ;
break ;
}
}
if ( UpdateItems ( currentWorkflow , workstep ) )
{
ClearCodesOfBatches ( ) ;
}
FocusToNextField ( ) ;
}
/// <summary>
/// Updates screen items (polozky) and currentProcess, currentWorkstep variables.
/// If either process or workstep is null, the screen is icleared.
/// </summary>
/// <param name="workflow">Process to be used (drawn)</param>
/// <param name="workstep">Workstep to be used (drawn)</param>
/// <returns>true = process or workstep changed, false = no change</returns>
bool UpdateItems ( Process workflow , Workstep workstep )
{
if ( ( workflow ! = currentWorkflow ) | | ( workstep ! = currentWStep ) )
{
currentWorkflow = workflow ;
stepsOfTheCurrentWorkflow = workflow . Worksteps ;
currentWStep = workstep ;
verifiedWorkstep = null ; /// Disable any verification
RedrawItems ( ) ;
if ( currentWorkflow ! = null )
{
LoadCodesFromDictionary ( currentWorkflow . Name , palety ) ;
}
ScanVerificationInfo info ;
if ( ( info = TracingDB . DB . AnalyzeProcess ( dbSession , currentWorkflow , currentWStep ) ) ! = null )
{
verifiedWorkstep = info . Workstep ;
verifiedPart = info . Part ;
verifyReferencePart = info . VerifyReferencePart ;
}
//wplaceRegistration.UpdateRegistration(dbSession,
// ProcessData.BenchInfo.TestBenchName,
// Users.GlobalData.CurrentUser.UserName,
// "1.2.3.4",
// (currentProcess != null) ? currentProcess.Name : string.Empty,
// (currentWorkstep != null) ? currentWorkstep.Name : string.Empty,
// DateTime.Now + new TimeSpan(8, 0, 0));
return true ;
}
else
{
return false ;
}
}
/// <summary>
/// Redraw items (polozky) of the currentProcess and currentWorkstep
/// or clear them if there is no current process or workstep.
/// </summary>
void RedrawItems ( )
{
///
/// Remove existing items (polozky)
///
palety . Clear ( ) ;
flowLayoutPanel2 . Controls . Clear ( ) ;
if ( currentWorkflow = = null | | currentWStep = = null ) return ;
ICheckItem polozka ;
/// Reference part
if ( currentWStep . ReferencePart ! = null )
{
uniqueCodeParts . Add ( currentWStep . ReferencePart ) ;
}
/// All other parts
foreach ( var p in currentWStep . Parts )
{
if ( p . CodeLocation = = CodeLocation . OnPart )
{
uniqueCodeParts . Add ( p ) ;
}
else if ( p . CodeLocation = = CodeLocation . OnPallet )
{
switch ( p . CodeForm )
{
case CodeForm . OkNok :
polozka = new CheckItems . OkNok ( this , p ) ;
break ;
case CodeForm . Keyboard :
case CodeForm . Scale :
polozka = new CheckItems . Keyboard ( this , p ) ;
break ;
case CodeForm . Barcode :
case CodeForm . QRCode :
default :
polozka = new CheckItems . Barcode ( this , p ) ;
break ;
}
polozka . IxPolozky = palety . Count + 100 ;
palety . Add ( polozka ) ;
flowLayoutPanel2 . Controls . Add ( polozka as UserControl ) ;
}
}
}
void ClearAllTextBoxes ( )
{
foreach ( var tb in bodyNrBoxes ) { tb . Text = string . Empty ; }
foreach ( var tb in serialNrBoxes ) { tb . Text = string . Empty ; }
nextWaterMeterIx = 0 ;
FocusToNextField ( ) ;
}
void ClearCodesOfBatches ( )
{
if ( loadedOnce )
{
foreach ( var p in palety )
{
p . ClearCode ( ) ;
}
}
}
2020-12-07 13:36:21 +00:00
/// <summary>
/// Load Purchase order combo box items from the LocalSettings PurchaseOrderHistory array
/// </summary>
/// <param name="orderComboBox">Puchase order ComboBox</param>
void PrepareOrderAndSNRangeCombos ( )
{
2021-02-02 11:30:27 +00:00
LocalSettings LS = Program . LocalSettings ;
2020-12-07 13:36:21 +00:00
/// Purchase order
2021-02-02 11:30:27 +00:00
for ( int i = 0 ; i < LS . PurchaseOrderHistoryCount ; i + + )
orderCB . Items . Add ( LS . PurchaseOrderHistory [ i ] ) ;
if ( orderCB . Items . Count > 0 )
orderCB . Text = orderCB . Items [ 0 ] . ToString ( ) ;
2020-12-07 13:36:21 +00:00
/// First S/N in selected range
2021-02-02 11:30:27 +00:00
for ( int i = 0 ; i < LS . FirstSNHistoryCount ; i + + )
firstSNRangeCB . Items . Add ( LS . FirstSNHistory [ i ] ) ;
if ( firstSNRangeCB . Items . Count > 0 )
firstSNRangeCB . Text = firstSNRangeCB . Items [ 0 ] . ToString ( ) ;
2020-12-07 13:36:21 +00:00
/// Last S/N in selected range
2021-02-02 11:30:27 +00:00
for ( int i = 0 ; i < LS . LastSNHistoryCount ; i + + )
lastSNRangeCB . Items . Add ( LS . LastSNHistory [ i ] ) ;
if ( lastSNRangeCB . Items . Count > 0 )
lastSNRangeCB . Text = lastSNRangeCB . Items [ 0 ] . ToString ( ) ;
2020-12-07 13:36:21 +00:00
}
private void okButton_Click ( object sender , EventArgs e )
{
2021-02-02 11:30:27 +00:00
if ( CheckForNonUniqueness ( atTheEnd ? serialNrBoxes : bodyNrBoxes , textBoxesCount ) )
{
return ;
}
2020-12-07 13:36:21 +00:00
2021-02-02 11:30:27 +00:00
/// Read UI data and store them to 'interface' variables
2020-12-07 13:36:21 +00:00
int itmp ;
2021-02-02 11:30:27 +00:00
for ( int i = 0 ; i < textBoxesCount ; i + + )
{
bodyNrText [ i ] = bodyNrBoxes [ i ] . Text ;
assignedSerialNr [ i ] = int . TryParse ( serialNrBoxes [ i ] . Text , out itmp ) ? itmp : 0 ;
completeSerialNr [ i ] = string . Format ( "{0}{1}{2}" ,
( prefix ! = null ) ? prefix : string . Empty ,
assignedSerialNr [ i ] . ToString ( string . Format ( "D{0}" , Math . Max ( snDigits , 1 ) ) ) ,
( suffix ! = null ) ? suffix : string . Empty ) ;
disabled [ i ] = ! checkBoxes [ i ] . Checked ;
}
purchaseOrder = orderCB . Text ;
SaveProductionTracingRecords ( ) ;
2020-12-07 13:36:21 +00:00
completed = true ;
Close ( ) ;
}
2021-02-02 11:30:27 +00:00
private void SaveProductionTracingRecords ( )
{
if ( atTheEnd )
{
///
/// Save records to MySQL
///
string workplace = TBF . BenchControl . Sequences . ProcessData . BenchInfo . TestBenchName ;
ITransaction mysqlTransaction = dbSession . BeginTransaction ( ) ;
try
{
for ( int wmNr0 = 0 ; wmNr0 < textBoxesCount ; wmNr0 + + )
{
bool passed = waterMeters [ wmNr0 ] . Passed ;
if ( passed & & ! string . IsNullOrEmpty ( bodyNrBoxes [ wmNr0 ] . Text ) & & ! string . IsNullOrEmpty ( serialNrBoxes [ wmNr0 ] . Text ) )
{
///
/// Prepare records
///
ReferenceRecord refRecord = new ReferenceRecord ( currentWorkflow ,
currentWStep ,
bodyNrBoxes [ wmNr0 ] . Text ,
Users . GlobalData . GetCurrentUserName ( ) ,
workplace ,
passed ? 1 : 0 ) ;
if ( uniqueCodeParts . Count > = 2 )
{
refRecord . Records . Add ( new Record ( uniqueCodeParts [ 1 ] , refRecord , serialNrBoxes [ wmNr0 ] . Text ) ) ;
}
for ( int i = 0 ; i < palety . Count ; i + + )
{
refRecord . Records . Add ( new Record ( palety [ i ] . Part , refRecord , palety [ i ] . ScannedCode ) ) ;
}
DB . SaveRecords ( dbSession , refRecord ) ;
}
}
mysqlTransaction . Commit ( ) ;
}
catch ( Exception exc )
{
log . ErrorFormat ( "MySQL database transaction rolled back, data not comitted: {0}" , exc . Message ) ;
mysqlTransaction . Rollback ( ) ;
}
}
}
/// <summary>
/// Check for uniqueness of test in an array of TextBox-es
/// </summary>
/// <param name="textBoxes">Array of TextBox-es</param>
/// <param name="count">Number of text boxes at the beginning of the array to check</param>
/// <returns>true when there are at leas two equal non-empty tests</returns>
bool CheckForNonUniqueness ( TextBox [ ] textBoxes , int count )
{
for ( int ix2 = 1 ; ix2 < count ; ix2 + + )
{
for ( int ix1 = 0 ; ix1 < ix2 ; ix1 + + )
{
if ( ! string . IsNullOrEmpty ( textBoxes [ ix2 ] . Text ) & & ( textBoxes [ ix2 ] . Text = = textBoxes [ ix1 ] . Text ) )
{
/// Two non-empty codes are equal
Color oriBackColor1 = textBoxes [ ix1 ] . BackColor ;
Color oriBackColor2 = textBoxes [ ix2 ] . BackColor ;
textBoxes [ ix1 ] . BackColor = Color . Yellow ;
textBoxes [ ix2 ] . BackColor = Color . Yellow ;
MessageBox . Show ( "Našli sa dva rovnaké kódy." ) ;
textBoxes [ ix1 ] . BackColor = oriBackColor1 ;
textBoxes [ ix2 ] . BackColor = oriBackColor2 ;
return true ;
}
}
}
return false ;
}
2020-12-07 13:36:21 +00:00
private void clearButton_Click ( object sender , EventArgs e )
{
if ( MessageBox . Show ( "Naozaj chcete všetky kódy vymazať?" , "Upozonenie" , MessageBoxButtons . YesNo , MessageBoxIcon . Exclamation ) = = DialogResult . Yes )
{
for ( int i = 0 ; i < Math . Min ( wmsCount , textBoxesCount ) ; i + + )
{
bodyNrBoxes [ i ] . Text = string . Empty ;
serialNrBoxes [ i ] . Text = string . Empty ;
2021-02-02 11:30:27 +00:00
serialNrBoxes [ i ] . Text = string . Empty ;
2020-12-07 13:36:21 +00:00
checkBoxes [ i ] . Checked = false ;
}
assignedSNs . Clear ( ) ;
}
}
2021-02-02 11:30:27 +00:00
private void textBox1_KeyPress ( object s , KeyPressEventArgs e ) { BodyNoTextBoxKeyPress ( s , e , 0 ) ; }
private void textBox2_KeyPress ( object s , KeyPressEventArgs e ) { BodyNoTextBoxKeyPress ( s , e , 1 ) ; }
private void textBox3_KeyPress ( object s , KeyPressEventArgs e ) { BodyNoTextBoxKeyPress ( s , e , 2 ) ; }
private void textBox4_KeyPress ( object s , KeyPressEventArgs e ) { BodyNoTextBoxKeyPress ( s , e , 3 ) ; }
private void textBox5_KeyPress ( object s , KeyPressEventArgs e ) { BodyNoTextBoxKeyPress ( s , e , 4 ) ; }
private void textBox6_KeyPress ( object s , KeyPressEventArgs e ) { BodyNoTextBoxKeyPress ( s , e , 5 ) ; }
private void textBox7_KeyPress ( object s , KeyPressEventArgs e ) { BodyNoTextBoxKeyPress ( s , e , 6 ) ; }
private void textBox8_KeyPress ( object s , KeyPressEventArgs e ) { BodyNoTextBoxKeyPress ( s , e , 7 ) ; }
private void textBox9_KeyPress ( object s , KeyPressEventArgs e ) { BodyNoTextBoxKeyPress ( s , e , 8 ) ; }
private void textBox10_KeyPress ( object s , KeyPressEventArgs e ) { BodyNoTextBoxKeyPress ( s , e , 9 ) ; }
private void textBox11_KeyPress ( object s , KeyPressEventArgs e ) { BodyNoTextBoxKeyPress ( s , e , 10 ) ; }
private void textBox12_KeyPress ( object s , KeyPressEventArgs e ) { BodyNoTextBoxKeyPress ( s , e , 11 ) ; }
private void textBox13_KeyPress ( object s , KeyPressEventArgs e ) { BodyNoTextBoxKeyPress ( s , e , 12 ) ; }
private void textBox14_KeyPress ( object s , KeyPressEventArgs e ) { BodyNoTextBoxKeyPress ( s , e , 13 ) ; }
private void textBox15_KeyPress ( object s , KeyPressEventArgs e ) { BodyNoTextBoxKeyPress ( s , e , 14 ) ; }
private void textBox16_KeyPress ( object s , KeyPressEventArgs e ) { BodyNoTextBoxKeyPress ( s , e , 15 ) ; }
private void textBox17_KeyPress ( object s , KeyPressEventArgs e ) { BodyNoTextBoxKeyPress ( s , e , 16 ) ; }
private void textBox18_KeyPress ( object s , KeyPressEventArgs e ) { BodyNoTextBoxKeyPress ( s , e , 17 ) ; }
private void textBox19_KeyPress ( object s , KeyPressEventArgs e ) { BodyNoTextBoxKeyPress ( s , e , 18 ) ; }
private void textBox20_KeyPress ( object s , KeyPressEventArgs e ) { BodyNoTextBoxKeyPress ( s , e , 19 ) ; }
private void textBox21_KeyPress ( object s , KeyPressEventArgs e ) { BodyNoTextBoxKeyPress ( s , e , 20 ) ; }
private void textBox22_KeyPress ( object s , KeyPressEventArgs e ) { BodyNoTextBoxKeyPress ( s , e , 21 ) ; }
private void textBox23_KeyPress ( object s , KeyPressEventArgs e ) { BodyNoTextBoxKeyPress ( s , e , 22 ) ; }
private void textBox24_KeyPress ( object s , KeyPressEventArgs e ) { BodyNoTextBoxKeyPress ( s , e , 23 ) ; }
private void textBox25_KeyPress ( object s , KeyPressEventArgs e ) { BodyNoTextBoxKeyPress ( s , e , 24 ) ; }
private void textBox26_KeyPress ( object s , KeyPressEventArgs e ) { BodyNoTextBoxKeyPress ( s , e , 25 ) ; }
private void textBox27_KeyPress ( object s , KeyPressEventArgs e ) { BodyNoTextBoxKeyPress ( s , e , 26 ) ; }
private void textBox28_KeyPress ( object s , KeyPressEventArgs e ) { BodyNoTextBoxKeyPress ( s , e , 27 ) ; }
private void textBox29_KeyPress ( object s , KeyPressEventArgs e ) { BodyNoTextBoxKeyPress ( s , e , 28 ) ; }
private void textBox30_KeyPress ( object s , KeyPressEventArgs e ) { BodyNoTextBoxKeyPress ( s , e , 29 ) ; }
private void textBox31_KeyPress ( object s , KeyPressEventArgs e ) { BodyNoTextBoxKeyPress ( s , e , 30 ) ; }
private void textBox32_KeyPress ( object s , KeyPressEventArgs e ) { BodyNoTextBoxKeyPress ( s , e , 31 ) ; }
private void textBox33_KeyPress ( object s , KeyPressEventArgs e ) { BodyNoTextBoxKeyPress ( s , e , 32 ) ; }
private void textBox34_KeyPress ( object s , KeyPressEventArgs e ) { BodyNoTextBoxKeyPress ( s , e , 33 ) ; }
private void textBox35_KeyPress ( object s , KeyPressEventArgs e ) { BodyNoTextBoxKeyPress ( s , e , 34 ) ; }
private void textBox36_KeyPress ( object s , KeyPressEventArgs e ) { BodyNoTextBoxKeyPress ( s , e , 35 ) ; }
private void textBox37_KeyPress ( object s , KeyPressEventArgs e ) { BodyNoTextBoxKeyPress ( s , e , 36 ) ; }
private void textBox38_KeyPress ( object s , KeyPressEventArgs e ) { BodyNoTextBoxKeyPress ( s , e , 37 ) ; }
private void textBox39_KeyPress ( object s , KeyPressEventArgs e ) { BodyNoTextBoxKeyPress ( s , e , 38 ) ; }
private void textBox40_KeyPress ( object s , KeyPressEventArgs e ) { BodyNoTextBoxKeyPress ( s , e , 39 ) ; }
2020-12-07 13:36:21 +00:00
/// <summary>
/// Process a key press within any enabled combo boxe
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
/// <param name="currentFocusOwner">TextBox control which received the event</param>
2021-02-02 11:30:27 +00:00
private void BodyNoTextBoxKeyPress ( object sender , KeyPressEventArgs e , int wmNr0 )
{
if ( closeButton ! = '\0' & & e . KeyChar = = closeButton )
2020-12-07 13:36:21 +00:00
{
/// Process '+' key ..... Form completed
okButton_Click ( sender , e ) ;
}
2021-02-02 11:30:27 +00:00
else if ( e . KeyChar = = '\r' )
{
/// Process <enter> key ..... Go to the next text field
nextWaterMeterIx = ( wmNr0 + 1 ) % textBoxesCount ;
bodyNrBoxes [ nextWaterMeterIx ] . Focus ( ) ;
2020-12-07 13:36:21 +00:00
2021-02-02 11:30:27 +00:00
ColorFlashAndBeep ( this , new ColorFlashEventArgs ( 600 , Color . Green , 700 , 500 ) ) ;
}
else
{
checkBoxes [ wmNr0 ] . Checked = true ;
disabled [ wmNr0 ] = false ;
}
2020-12-07 13:36:21 +00:00
}
2021-02-02 11:30:27 +00:00
private void textBox41_KeyPress ( object s , KeyPressEventArgs e ) { SnTextBoxKeyPress ( s , e , 0 ) ; }
private void textBox42_KeyPress ( object s , KeyPressEventArgs e ) { SnTextBoxKeyPress ( s , e , 1 ) ; }
private void textBox43_KeyPress ( object s , KeyPressEventArgs e ) { SnTextBoxKeyPress ( s , e , 2 ) ; }
private void textBox44_KeyPress ( object s , KeyPressEventArgs e ) { SnTextBoxKeyPress ( s , e , 3 ) ; }
private void textBox45_KeyPress ( object s , KeyPressEventArgs e ) { SnTextBoxKeyPress ( s , e , 4 ) ; }
private void textBox46_KeyPress ( object s , KeyPressEventArgs e ) { SnTextBoxKeyPress ( s , e , 5 ) ; }
private void textBox47_KeyPress ( object s , KeyPressEventArgs e ) { SnTextBoxKeyPress ( s , e , 6 ) ; }
private void textBox48_KeyPress ( object s , KeyPressEventArgs e ) { SnTextBoxKeyPress ( s , e , 7 ) ; }
private void textBox49_KeyPress ( object s , KeyPressEventArgs e ) { SnTextBoxKeyPress ( s , e , 8 ) ; }
private void textBox50_KeyPress ( object s , KeyPressEventArgs e ) { SnTextBoxKeyPress ( s , e , 9 ) ; }
private void textBox51_KeyPress ( object s , KeyPressEventArgs e ) { SnTextBoxKeyPress ( s , e , 10 ) ; }
private void textBox52_KeyPress ( object s , KeyPressEventArgs e ) { SnTextBoxKeyPress ( s , e , 11 ) ; }
private void textBox53_KeyPress ( object s , KeyPressEventArgs e ) { SnTextBoxKeyPress ( s , e , 12 ) ; }
private void textBox54_KeyPress ( object s , KeyPressEventArgs e ) { SnTextBoxKeyPress ( s , e , 13 ) ; }
private void textBox55_KeyPress ( object s , KeyPressEventArgs e ) { SnTextBoxKeyPress ( s , e , 14 ) ; }
private void textBox56_KeyPress ( object s , KeyPressEventArgs e ) { SnTextBoxKeyPress ( s , e , 15 ) ; }
private void textBox57_KeyPress ( object s , KeyPressEventArgs e ) { SnTextBoxKeyPress ( s , e , 16 ) ; }
private void textBox58_KeyPress ( object s , KeyPressEventArgs e ) { SnTextBoxKeyPress ( s , e , 17 ) ; }
private void textBox59_KeyPress ( object s , KeyPressEventArgs e ) { SnTextBoxKeyPress ( s , e , 18 ) ; }
private void textBox60_KeyPress ( object s , KeyPressEventArgs e ) { SnTextBoxKeyPress ( s , e , 19 ) ; }
private void textBox61_KeyPress ( object s , KeyPressEventArgs e ) { SnTextBoxKeyPress ( s , e , 20 ) ; }
private void textBox62_KeyPress ( object s , KeyPressEventArgs e ) { SnTextBoxKeyPress ( s , e , 21 ) ; }
private void textBox63_KeyPress ( object s , KeyPressEventArgs e ) { SnTextBoxKeyPress ( s , e , 22 ) ; }
private void textBox64_KeyPress ( object s , KeyPressEventArgs e ) { SnTextBoxKeyPress ( s , e , 23 ) ; }
private void textBox65_KeyPress ( object s , KeyPressEventArgs e ) { SnTextBoxKeyPress ( s , e , 24 ) ; }
private void textBox66_KeyPress ( object s , KeyPressEventArgs e ) { SnTextBoxKeyPress ( s , e , 25 ) ; }
private void textBox67_KeyPress ( object s , KeyPressEventArgs e ) { SnTextBoxKeyPress ( s , e , 26 ) ; }
private void textBox68_KeyPress ( object s , KeyPressEventArgs e ) { SnTextBoxKeyPress ( s , e , 27 ) ; }
private void textBox69_KeyPress ( object s , KeyPressEventArgs e ) { SnTextBoxKeyPress ( s , e , 28 ) ; }
private void textBox70_KeyPress ( object s , KeyPressEventArgs e ) { SnTextBoxKeyPress ( s , e , 29 ) ; }
private void textBox71_KeyPress ( object s , KeyPressEventArgs e ) { SnTextBoxKeyPress ( s , e , 30 ) ; }
private void textBox72_KeyPress ( object s , KeyPressEventArgs e ) { SnTextBoxKeyPress ( s , e , 31 ) ; }
private void textBox73_KeyPress ( object s , KeyPressEventArgs e ) { SnTextBoxKeyPress ( s , e , 32 ) ; }
private void textBox74_KeyPress ( object s , KeyPressEventArgs e ) { SnTextBoxKeyPress ( s , e , 33 ) ; }
private void textBox75_KeyPress ( object s , KeyPressEventArgs e ) { SnTextBoxKeyPress ( s , e , 34 ) ; }
private void textBox76_KeyPress ( object s , KeyPressEventArgs e ) { SnTextBoxKeyPress ( s , e , 35 ) ; }
private void textBox77_KeyPress ( object s , KeyPressEventArgs e ) { SnTextBoxKeyPress ( s , e , 36 ) ; }
private void textBox78_KeyPress ( object s , KeyPressEventArgs e ) { SnTextBoxKeyPress ( s , e , 37 ) ; }
private void textBox79_KeyPress ( object s , KeyPressEventArgs e ) { SnTextBoxKeyPress ( s , e , 38 ) ; }
private void textBox80_KeyPress ( object s , KeyPressEventArgs e ) { SnTextBoxKeyPress ( s , e , 39 ) ; }
2020-12-07 13:36:21 +00:00
/// <summary>
/// Process a key press within any enabled combo boxe
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
/// <param name="currentFocusOwner">TextBox control which received the event</param>
2021-02-02 11:30:27 +00:00
private void SnTextBoxKeyPress ( object sender , KeyPressEventArgs e , int wmNr0 )
2020-12-07 13:36:21 +00:00
{
2021-02-02 11:30:27 +00:00
if ( closeButton ! = '\0' & & e . KeyChar = = closeButton )
2020-12-07 13:36:21 +00:00
{
/// Process '+' key ..... Form completed
okButton_Click ( sender , e ) ;
}
2021-02-02 11:30:27 +00:00
else if ( e . KeyChar = = '\r' )
2020-12-07 13:36:21 +00:00
{
/// Process <enter> key ..... Next text field
2021-02-02 11:30:27 +00:00
nextWaterMeterIx = ( wmNr0 + 1 ) % textBoxesCount ;
serialNrBoxes [ nextWaterMeterIx ] . Focus ( ) ;
}
}
private void checkBox1_CheckedChanged ( object s , EventArgs e ) { ProcessCheckBoxChecked ( s , e , 0 ) ; }
private void checkBox2_CheckedChanged ( object s , EventArgs e ) { ProcessCheckBoxChecked ( s , e , 1 ) ; }
private void checkBox3_CheckedChanged ( object s , EventArgs e ) { ProcessCheckBoxChecked ( s , e , 2 ) ; }
private void checkBox4_CheckedChanged ( object s , EventArgs e ) { ProcessCheckBoxChecked ( s , e , 3 ) ; }
private void checkBox5_CheckedChanged ( object s , EventArgs e ) { ProcessCheckBoxChecked ( s , e , 4 ) ; }
private void checkBox6_CheckedChanged ( object s , EventArgs e ) { ProcessCheckBoxChecked ( s , e , 5 ) ; }
private void checkBox7_CheckedChanged ( object s , EventArgs e ) { ProcessCheckBoxChecked ( s , e , 6 ) ; }
private void checkBox8_CheckedChanged ( object s , EventArgs e ) { ProcessCheckBoxChecked ( s , e , 7 ) ; }
private void checkBox9_CheckedChanged ( object s , EventArgs e ) { ProcessCheckBoxChecked ( s , e , 8 ) ; }
private void checkBox10_CheckedChanged ( object s , EventArgs e ) { ProcessCheckBoxChecked ( s , e , 9 ) ; }
private void checkBox11_CheckedChanged ( object s , EventArgs e ) { ProcessCheckBoxChecked ( s , e , 10 ) ; }
private void checkBox12_CheckedChanged ( object s , EventArgs e ) { ProcessCheckBoxChecked ( s , e , 11 ) ; }
private void checkBox13_CheckedChanged ( object s , EventArgs e ) { ProcessCheckBoxChecked ( s , e , 12 ) ; }
private void checkBox14_CheckedChanged ( object s , EventArgs e ) { ProcessCheckBoxChecked ( s , e , 13 ) ; }
private void checkBox15_CheckedChanged ( object s , EventArgs e ) { ProcessCheckBoxChecked ( s , e , 14 ) ; }
private void checkBox16_CheckedChanged ( object s , EventArgs e ) { ProcessCheckBoxChecked ( s , e , 15 ) ; }
private void checkBox17_CheckedChanged ( object s , EventArgs e ) { ProcessCheckBoxChecked ( s , e , 16 ) ; }
private void checkBox18_CheckedChanged ( object s , EventArgs e ) { ProcessCheckBoxChecked ( s , e , 17 ) ; }
private void checkBox19_CheckedChanged ( object s , EventArgs e ) { ProcessCheckBoxChecked ( s , e , 18 ) ; }
private void checkBox20_CheckedChanged ( object s , EventArgs e ) { ProcessCheckBoxChecked ( s , e , 19 ) ; }
private void checkBox21_CheckedChanged ( object s , EventArgs e ) { ProcessCheckBoxChecked ( s , e , 20 ) ; }
private void checkBox22_CheckedChanged ( object s , EventArgs e ) { ProcessCheckBoxChecked ( s , e , 21 ) ; }
private void checkBox23_CheckedChanged ( object s , EventArgs e ) { ProcessCheckBoxChecked ( s , e , 22 ) ; }
private void checkBox24_CheckedChanged ( object s , EventArgs e ) { ProcessCheckBoxChecked ( s , e , 23 ) ; }
private void checkBox25_CheckedChanged ( object s , EventArgs e ) { ProcessCheckBoxChecked ( s , e , 24 ) ; }
private void checkBox26_CheckedChanged ( object s , EventArgs e ) { ProcessCheckBoxChecked ( s , e , 25 ) ; }
private void checkBox27_CheckedChanged ( object s , EventArgs e ) { ProcessCheckBoxChecked ( s , e , 26 ) ; }
private void checkBox28_CheckedChanged ( object s , EventArgs e ) { ProcessCheckBoxChecked ( s , e , 27 ) ; }
private void checkBox29_CheckedChanged ( object s , EventArgs e ) { ProcessCheckBoxChecked ( s , e , 28 ) ; }
private void checkBox30_CheckedChanged ( object s , EventArgs e ) { ProcessCheckBoxChecked ( s , e , 29 ) ; }
private void checkBox31_CheckedChanged ( object s , EventArgs e ) { ProcessCheckBoxChecked ( s , e , 30 ) ; }
private void checkBox32_CheckedChanged ( object s , EventArgs e ) { ProcessCheckBoxChecked ( s , e , 31 ) ; }
private void checkBox33_CheckedChanged ( object s , EventArgs e ) { ProcessCheckBoxChecked ( s , e , 32 ) ; }
private void checkBox34_CheckedChanged ( object s , EventArgs e ) { ProcessCheckBoxChecked ( s , e , 33 ) ; }
private void checkBox35_CheckedChanged ( object s , EventArgs e ) { ProcessCheckBoxChecked ( s , e , 34 ) ; }
private void checkBox36_CheckedChanged ( object s , EventArgs e ) { ProcessCheckBoxChecked ( s , e , 35 ) ; }
private void checkBox37_CheckedChanged ( object s , EventArgs e ) { ProcessCheckBoxChecked ( s , e , 36 ) ; }
private void checkBox38_CheckedChanged ( object s , EventArgs e ) { ProcessCheckBoxChecked ( s , e , 37 ) ; }
private void checkBox39_CheckedChanged ( object s , EventArgs e ) { ProcessCheckBoxChecked ( s , e , 38 ) ; }
private void checkBox40_CheckedChanged ( object s , EventArgs e ) { ProcessCheckBoxChecked ( s , e , 39 ) ; }
///
void ProcessCheckBoxChecked ( object sender , EventArgs e , int wmNr0 )
{
if ( atTheEnd )
{
AssignSerialNumbers ( ) ;
}
}
/// <summary>
/// Update the dictionary of scanned codes of palettes and save it.
/// Dictionary contains pairs (process.Name, '~'-separated strings of scanned codes).
/// Update codes of parts with CodeType == CodeType.Silicon and shared between workflows as well.
/// </summary>
/// <param name="processName">Current workflow name</param>
/// <param name="palety">A list of palettes</param>
/// <returns>true = LocalSettings updated and saved</returns>
bool UpdateAndSaveStoredCodesDictionary ( Process process , IList < ICheckItem > palety )
{
if ( process = = null | | string . IsNullOrEmpty ( process . Name ) | | palety = = null | | palety . Count = = 0 )
{
return false ;
}
if ( Program . LocalSettings . LastData = = null )
{
Program . LocalSettings . LastData = new SerializableDictionary < string , string > ( ) ;
}
/// Dictionary key
string key = process . Name ;
/// Dictionary value
System . Text . StringBuilder sb = new System . Text . StringBuilder ( ) ;
bool first = true ;
foreach ( var p in palety )
{
if ( ! first ) sb . Append ( "~" ) ;
first = false ;
sb . Append ( p . ScannedCode ) ;
}
string value = sb . ToString ( ) ;
/// Store or update key/value pair
string storedValue ;
if ( ! Program . LocalSettings . LastData . TryGetValue ( key , out storedValue ) )
{
Program . LocalSettings . LastData . Add ( key , value ) ;
Program . LocalSettings . Save ( ) ;
return true ;
}
else if ( storedValue ! = value )
{
Program . LocalSettings . LastData [ key ] = value ;
Program . LocalSettings . Save ( ) ;
return true ;
}
/// Key/value pair was up to date
return false ;
}
/// <summary>
/// Load codes of palettes from the dictionary.
/// Dictionary contains pairs (process.Name, '~'-separated strings of scanned codes).
/// </summary>
/// <param name="processName">Current process name</param>
/// <param name="palety">A list of palettes</param>
void LoadCodesFromDictionary ( string processName , IList < ICheckItem > palety )
{
if ( string . IsNullOrEmpty ( processName ) | | palety = = null ) return ;
string [ ] loadedCodes = new string [ 0 ] ;
string value ;
if ( Program . LocalSettings . LastData ! = null & &
Program . LocalSettings . LastData . TryGetValue ( processName , out value ) )
{
loadedCodes = value . Split ( new char [ ] { '~' } ) ;
}
2020-12-07 13:36:21 +00:00
2021-02-02 11:30:27 +00:00
int ix = 0 ;
for ( int i = 0 ; i < palety . Count ; i + + )
{
if ( ! string . IsNullOrEmpty ( palety [ i ] . Part . DefaultCode ) )
2020-12-07 13:36:21 +00:00
{
2021-02-02 11:30:27 +00:00
palety [ i ] . ScannedCode = palety [ i ] . Part . DefaultCode ;
ix + + ;
}
else if ( ix < loadedCodes . Length )
{
palety [ i ] . ScannedCode = loadedCodes [ ix + + ] ;
}
else
{
palety [ i ] . ClearCode ( ) ;
2020-12-07 13:36:21 +00:00
}
}
}
private void orderCB_SelectedIndexChanged ( object sender , EventArgs e )
{
2021-02-02 11:30:27 +00:00
if ( ! loadedOnce ) return ;
2020-12-07 13:36:21 +00:00
ProcessPO ( ) ;
2021-02-02 11:30:27 +00:00
FocusToNextField ( ) ;
2020-12-07 13:36:21 +00:00
}
private void reloadButton_Click ( object sender , EventArgs e )
{
ProcessPO ( ) ;
2021-02-02 11:30:27 +00:00
FocusToNextField ( ) ;
2020-12-07 13:36:21 +00:00
}
void ProcessPO ( )
{
2021-02-02 11:30:27 +00:00
if ( ReadPurchaseOrderParamsFromDB ( ProcessData . OracleDB . SelectedDB , orderCB . Text , out firstSN , out snDigits , out pcsCount , out prefix , out suffix ) )
2020-12-07 13:36:21 +00:00
{
2021-02-02 11:30:27 +00:00
prefixTextBox . Text = ( prefix ! = null ) ? prefix : string . Empty ;
suffixTextBox . Text = ( suffix ! = null ) ? suffix : string . Empty ;
2020-12-07 13:36:21 +00:00
snDigitsTextBox . Text = snDigits . ToString ( ) ;
firstSNTextBox . Text = firstSN . ToString ( string . Format ( "D{0}" , snDigits ) ) ;
pcsCountTextBox . Text = pcsCount . ToString ( ) ;
exclamationPOLabel . Visible = false ;
}
else
{
prefixTextBox . Text = suffixTextBox . Text = string . Empty ;
firstSNTextBox . Text = snDigitsTextBox . Text = pcsCountTextBox . Text = string . Empty ;
exclamationPOLabel . Visible = true ;
}
2021-02-02 11:30:27 +00:00
if ( UpdateSNFromTo ( ) )
{
AssignSerialNumbers ( ) ;
}
else
{
Invalidate ( rect ) ;
}
2020-12-07 13:36:21 +00:00
}
bool ReadPurchaseOrderParamsFromDB ( OracleConnection connection , string orderNr , out int firstSN , out int snDigits , out int piecesCount , out string prefix , out string suffix )
{
firstSN = 0 ;
piecesCount = 0 ;
snDigits = 0 ;
prefix = null ;
suffix = null ;
2021-02-02 11:30:27 +00:00
#if DEBUG
firstSN = 101 ;
piecesCount = 100 ;
snDigits = 4 ;
prefix = "M789" ;
suffix = null ;
foundMeters . Clear ( ) ;
foundSNs . Clear ( ) ;
for ( int sn = firstSN ; sn < = 125 ; sn + + )
{
foundMeters . Add ( new BodySerNrResult ( string . Format ( "681172554VQ200034{0:D3}" , sn ) , sn , 96 ) ) ;
foundSNs . Add ( sn ) ;
}
return true ;
#endif
2020-12-07 13:36:21 +00:00
if ( connection = = null | | string . IsNullOrEmpty ( orderNr ) ) return false ;
try
{
connection . Open ( ) ;
foreach ( var status in new string [ ] { "NEU" , "AKTIV" } )
{
/// STATUS='NEU'
2021-02-02 11:30:27 +00:00
OracleCommand cmd = new OracleCommand ( "SELECT sollstueck, erste_zaehlernr, prefix, suffix, znrlaenge FROM vt_auftrag_pd" +
" WHERE produktion_anbid=:1 AND status=:2 AND produktion_usestate=:3 AND auftragsnummer=:4" , connection ) ;
2020-12-07 13:36:21 +00:00
2021-08-19 09:02:46 +00:00
cmd . Parameters . Add ( new OracleParameter { OracleDbType = OracleDbType . Int32 , Value = ProcessData . OracleDB . Anbid_Producer } ) ; ///:1
cmd . Parameters . Add ( new OracleParameter { OracleDbType = OracleDbType . Varchar2 , Value = status } ) ; ///:2
cmd . Parameters . Add ( new OracleParameter { OracleDbType = OracleDbType . Int32 , Value = 0 } ) ; ///:3
cmd . Parameters . Add ( new OracleParameter { OracleDbType = OracleDbType . Varchar2 , Value = orderNr } ) ; ///:4
2020-12-07 13:36:21 +00:00
OracleDataReader dr = cmd . ExecuteReader ( ) ;
while ( dr . Read ( ) )
{
piecesCount = dr . GetInt32 ( 0 ) ;
firstSN = dr . GetInt32 ( 1 ) ;
try { prefix = dr . GetString ( 2 ) ; } catch { prefix = null ; }
try { suffix = dr . GetString ( 3 ) ; } catch { suffix = null ; }
snDigits = dr . GetInt32 ( 4 ) ;
}
dr . Close ( ) ;
}
if ( firstSN = = 0 & & piecesCount = = 0 )
{
2021-02-02 11:30:27 +00:00
string msg2 = string . Format ( "No PO={0} found in Oracle DB" , orderNr ) ;
2020-12-07 13:36:21 +00:00
log . Warn ( msg2 ) ;
System . Diagnostics . Debug . WriteLine ( msg2 ) ;
connection . Close ( ) ;
return false ;
}
foundMeters . Clear ( ) ;
2021-02-02 11:30:27 +00:00
OracleCommand cmd2 = new OracleCommand ( "SELECT vt_fernum, zaehlernummer, hydr_pruefung FROM vt_zaehler_pd" +
" WHERE anbid=:1 AND auftragsnummer=:2 ORDER BY zaehlernummer ASC" , connection ) ;
2020-12-07 13:36:21 +00:00
2021-08-19 09:02:46 +00:00
cmd2 . Parameters . Add ( new OracleParameter { OracleDbType = OracleDbType . Int32 , Value = ProcessData . OracleDB . Anbid_Producer } ) ; ///:1
cmd2 . Parameters . Add ( new OracleParameter { OracleDbType = OracleDbType . Varchar2 , Value = orderNr } ) ; ///:2
2020-12-07 13:36:21 +00:00
OracleDataReader dr2 = cmd2 . ExecuteReader ( ) ;
while ( dr2 . Read ( ) )
{
string bodyNr = dr2 . GetString ( 0 ) ; /// Body number
int serialNr = dr2 . GetInt32 ( 1 ) ; /// Assigned serial number when OK, 0 when NOK
int result = dr2 . GetInt32 ( 2 ) ; /// HYDR_PRUEFUNG: 96=OK, 224=OK after a repetition, 97=NOK
2021-02-02 11:30:27 +00:00
if ( serialNr > 0 & & result ! = 97 )
2020-12-07 13:36:21 +00:00
{
foundMeters . Add ( new BodySerNrResult ( bodyNr , serialNr , result ) ) ;
}
}
dr2 . Close ( ) ;
2021-02-02 11:30:27 +00:00
string msg = string . Format ( "PO={0} found in Oracle DB: first S/N={1}, total pieces count={2}, pieces produced so far={3}" , orderNr , firstSN , piecesCount , foundMeters . Count ) ;
2020-12-07 13:36:21 +00:00
log . Warn ( msg ) ;
System . Diagnostics . Debug . WriteLine ( msg ) ;
connection . Close ( ) ;
2021-02-02 11:30:27 +00:00
foundSNs . Clear ( ) ;
foreach ( var mtr in foundMeters )
{
if ( mtr . SerialNr > 0 ) foundSNs . Add ( mtr . SerialNr ) ;
}
2020-12-07 13:36:21 +00:00
return true ;
}
catch ( Exception exc )
{
string msg = string . Format ( "ERROR: ORACLE DB query select AUFTRAGSNUMMER, SOLLSTUECK from VT_AUFTRAG_PD where ... failed: {0}" , exc . Message ) ;
log . Error ( msg ) ;
System . Diagnostics . Debug . WriteLine ( msg ) ;
firstSN = 0 ;
piecesCount = 0 ;
connection . Close ( ) ;
return false ;
}
}
2021-02-02 11:30:27 +00:00
private void firstSNRangeCB_TextChanged ( object s , EventArgs e )
{
if ( ! loadedOnce ) return ;
if ( UpdateSNFromTo ( ) )
AssignSerialNumbers ( ) ;
else
Invalidate ( rect ) ;
}
private void lastSNRangeCB_TextChanged ( object s , EventArgs e )
{
if ( ! loadedOnce ) return ;
if ( UpdateSNFromTo ( ) )
AssignSerialNumbers ( ) ;
else
Invalidate ( rect ) ;
}
private void firstSNRangeCB_SelectedIndexChanged ( object s , EventArgs e )
{
if ( ! loadedOnce ) return ;
if ( UpdateSNFromTo ( ) )
AssignSerialNumbers ( ) ;
else
Invalidate ( rect ) ;
FocusToNextField ( ) ;
}
private void lastSNRangeCB_SelectedIndexChanged ( object s , EventArgs e )
{
if ( ! loadedOnce ) return ;
if ( UpdateSNFromTo ( ) )
AssignSerialNumbers ( ) ;
else
Invalidate ( rect ) ;
FocusToNextField ( ) ;
}
2020-12-07 13:36:21 +00:00
2021-02-02 11:30:27 +00:00
/// <summary>
///
/// </summary>
/// <returns>true when the range of serial numbers is valid</returns>
bool UpdateSNFromTo ( )
2020-12-07 13:36:21 +00:00
{
bool anyError = false ;
int _snRangeFirst ;
if ( int . TryParse ( firstSNRangeCB . Text , out _snRangeFirst ) & & ( _snRangeFirst > = firstSN )
2021-02-02 11:30:27 +00:00
& & ( _snRangeFirst < firstSN + pcsCount ) )
2020-12-07 13:36:21 +00:00
{
snRangeFirst = _snRangeFirst ;
exclamationFromLabel . Visible = false ;
}
else
{
snRangeFirst = 0 ;
exclamationFromLabel . Visible = true ;
anyError = true ;
}
int _snRangeLast ;
if ( int . TryParse ( lastSNRangeCB . Text , out _snRangeLast ) & & ( _snRangeLast > = firstSN )
2021-02-02 11:30:27 +00:00
& & ( _snRangeLast < firstSN + pcsCount ) )
2020-12-07 13:36:21 +00:00
{
snRangeLast = _snRangeLast ;
exclamationToLabel . Visible = false ;
}
else
{
snRangeLast = 0 ;
exclamationToLabel . Visible = true ;
anyError = true ;
}
if ( snRangeFirst > 0 & & snRangeLast > 0 & & snRangeFirst > snRangeLast )
{
snRangeFirst = snRangeLast = 0 ;
exclamationFromLabel . Visible = exclamationToLabel . Visible = true ;
anyError = true ;
}
2021-02-02 11:30:27 +00:00
return ! anyError ;
2020-12-07 13:36:21 +00:00
}
/// <summary>
/// Returns next free serial number within specified range or 0 if no appropriate s/n is available
/// </summary>
/// <returns>Serial number or 0</returns>
int GetNextSerialNr ( )
{
for ( int sn = snRangeFirst ; sn < = snRangeLast ; sn + + )
{
2021-02-02 11:30:27 +00:00
if ( ! foundSNs . Contains ( sn ) & & ! assignedSNs . Contains ( sn ) )
2020-12-07 13:36:21 +00:00
{
/// A free serial number within specified range found
assignedSNs . Add ( sn ) ;
return sn ;
}
}
return 0 ; /// No free serial number found
}
/// <summary>
/// Read released-active processes from the database.
/// </summary>
/// <param name="session">Production tracing DB session</param>
/// <returns>A list of processes (success) or null (failure)</returns>
2021-02-02 11:30:27 +00:00
private static IList < Process > ReadReleasedActiveProcesses ( ISession session )
2020-12-07 13:36:21 +00:00
{
try
{
return session . QueryOver < Process > ( )
. Where ( x = > ( x . ReleaseStatus = = ReleaseStatus . ReleasedActive | | x . ReleaseStatus = = ReleaseStatus . ToBeApproved ) )
. OrderBy ( x = > x . Name ) . Asc
. List ( ) ;
}
catch ( Exception exc )
{
log . ErrorFormat ( Strings . Reading_from_the_production_tracing_DB_failed , exc . Message ) ;
return null ;
}
}
public void OnFocusPressed ( object sender , FocusPressedEventArgs data )
{
if ( FocusPressedHandler = = null ) return ;
try
{
FocusPressedHandler ( sender , data ) ;
}
catch ( Exception )
{
// log.Error("FocusPressedHandler(...) failed", e);
}
}
public event EventHandler < FocusPressedEventArgs > FocusPressedHandler ;
///
public void FocusPressed ( object sender , FocusPressedEventArgs data )
{
foreach ( var p in palety ) p . ResetFocus ( ) ;
2021-02-02 11:30:27 +00:00
if ( ( data . IxPolozky > = 100 ) & & ( data . IxPolozky - 100 < palety . Count ) )
2020-12-07 13:36:21 +00:00
{
palety [ data . IxPolozky - 100 ] . SetFocus ( ) ;
}
}
public void OnBarcodeReceived ( object sender , BarcodeReceivedEventArgs data )
{
if ( BarcodeReceivedHandler = = null ) return ;
try
{
BarcodeReceivedHandler ( sender , data ) ;
}
catch ( Exception exc )
{
string msg = exc . Message ;
// log.Error("BarcodeReceivedHandler(...) failed", e);
}
}
public event EventHandler < BarcodeReceivedEventArgs > BarcodeReceivedHandler ;
///
public void BarcodeReceived ( object sender , BarcodeReceivedEventArgs data )
{
foreach ( var p in palety ) p . ResetFocus ( ) ;
/// TODO
}
private void ManageCheckGroupBox ( CheckBox chk , GroupBox grp )
{
/// Make sure the CheckBox isn't in the GroupBox. This will only happen the first time.
if ( chk . Parent = = grp )
{
grp . Parent . Controls . Add ( chk ) ; /// Reparent the CheckBox so it's not in the GroupBox.
chk . Location = new System . Drawing . Point ( chk . Left + grp . Left , chk . Top + grp . Top ) ; /// Adjust the CheckBox's location.
chk . BringToFront ( ) ; /// Move the CheckBox to the top of the stacking order.
}
/// Enable or disable the GroupBox.
grp . Enabled = chk . Checked ;
}
private void batchesCheckBox_CheckStateChanged ( object sender , EventArgs e )
{
ManageCheckGroupBox ( batchesCheckBox , batchesGroupBox ) ;
2021-02-02 11:30:27 +00:00
if ( ! batchesCheckBox . Checked )
{
FocusToNextField ( ) ;
}
}
private void orderCheckBox_CheckedChanged ( object sender , EventArgs e )
{
ManageCheckGroupBox ( orderCheckBox , orderGroupBox ) ;
if ( ! orderCheckBox . Checked )
{
if ( atTheEnd )
{
AssignSerialNumbers ( ) ;
}
else
{
FocusToNextField ( ) ;
Invalidate ( rect ) ;
}
}
}
private void FormForMechanicalMetersWithTracing_FormClosing ( object sender , FormClosingEventArgs e )
{
Program . LocalSettings . UpdateHistory ( orderCB . Text , ref Program . LocalSettings . PurchaseOrderHistory ) ;
Program . LocalSettings . UpdateHistory ( firstSNRangeCB . Text , ref Program . LocalSettings . FirstSNHistory ) ;
Program . LocalSettings . UpdateHistory ( lastSNRangeCB . Text , ref Program . LocalSettings . LastSNHistory ) ;
Program . LocalSettings . LastSNTexts = bodyNrText ;
UpdateAndSaveStoredCodesDictionary ( currentWorkflow , palety ) ;
if ( ( currentWorkflow ! = null ) & & ( Program . LocalSettings . LastWorkflow ! = currentWorkflow . Name ) )
{
Program . LocalSettings . LastWorkflow = currentWorkflow . Name ;
}
if ( ( currentWStep ! = null ) & & ( Program . LocalSettings . LastWStep ! = currentWStep . Name ) )
{
Program . LocalSettings . LastWStep = currentWStep . Name ;
}
Program . LocalSettings . Save ( ) ;
//wplaceRegistration.UnregisterWorkplace(dbSession);
}
#region Color flash and beep
/// <summary>
/// Called from the state machine when an operation forces a modeless dialog close.
/// </summary>
public void ColorFlashAndBeep ( object sender , ColorFlashEventArgs args )
{
Common . BackgroundBeep . Beep ( ) ;
if ( ColorFlashHandler ! = null )
{
try { ColorFlashHandler ( sender , args ) ; }
catch ( Exception ) { }
}
}
public event EventHandler < ColorFlashEventArgs > ColorFlashHandler ;
private System . Windows . Forms . Timer colorFlashDurationTimer ;
void OnColorFlash ( object sender , ColorFlashEventArgs args )
{
// start timer here
if ( colorFlashDurationTimer = = null )
{
colorFlashDurationTimer = new System . Windows . Forms . Timer ( ) ;
colorFlashDurationTimer . Tick + = ( s , e ) = > { ColorFlashAction ( ) ; } ;
}
BackColor = args . FlashColor ;
colorFlashDurationTimer . Interval = args . FlashTime ;
colorFlashDurationTimer . Start ( ) ;
}
// Specify what you want to happen when the Elapsed event is
// raised.
private void ColorFlashAction ( )
{
BackColor = oriBackColor ;
colorFlashDurationTimer . Stop ( ) ;
colorFlashDurationTimer . Enabled = false ;
}
#endregion
private void FormForMechanicalMetersWithTracing_Paint ( object sender , PaintEventArgs e )
{
var g = this . CreateGraphics ( ) ;
PaintRect ( g , rect , firstSN , pcsCount , snRangeFirst , snRangeLast , foundSNs , assignedSNs ) ;
}
void PaintRect ( System . Drawing . Graphics g , Rectangle r , int first , int count , int rngFrom , int rngTo , IList < int > foundSNs , IList < int > assignedSNs )
{
SolidBrush greenBrush = new SolidBrush ( Color . SeaGreen ) ;
SolidBrush yellowBrush = new SolidBrush ( Color . Yellow ) ;
SolidBrush whiteBrush = new SolidBrush ( Color . White ) ;
SolidBrush fadedGreenBrush = new SolidBrush ( Color . DarkSeaGreen ) ;
SolidBrush fadedWhiteBrush = new SolidBrush ( Color . Silver ) ;
if ( 0 < first & & first < = rngFrom & & rngFrom < = rngTo & & rngTo < firstSN + count )
{
float left = Convert . ToSingle ( r . Left ) ;
float top = Convert . ToSingle ( r . Top ) ;
float height = Convert . ToSingle ( r . Height ) ;
float elWidth = Convert . ToSingle ( r . Width ) / Convert . ToSingle ( count ) ;
for ( int sn = first ; sn < first + count ; sn + + )
{
float x = left + ( sn - first ) * elWidth ;
if ( foundSNs ! = null & & foundSNs . Contains ( sn ) )
{
if ( rngFrom < = sn & & sn < = rngTo )
g . FillRectangle ( greenBrush , x , top , elWidth , height ) ;
else
g . FillRectangle ( fadedGreenBrush , x , top , elWidth , height ) ;
}
else if ( assignedSNs ! = null & & assignedSNs . Contains ( sn ) )
{
g . FillRectangle ( yellowBrush , x , top , elWidth , height ) ;
}
else
{
if ( rngFrom < = sn & & sn < = rngTo )
g . FillRectangle ( whiteBrush , x , top , elWidth , height ) ;
else
g . FillRectangle ( fadedWhiteBrush , x , top , elWidth , height ) ;
}
}
}
else
{
g . FillRectangle ( fadedWhiteBrush , r ) ;
}
2020-12-07 13:36:21 +00:00
}
}
}