SharedDatabase entities/mappings changes, StepRecord added, RR.Code1,2,3,4, etc. Workplace ver. 3.1.14

This commit is contained in:
Milan Hanajik
2022-01-10 07:27:18 +01:00
parent c75e3d08d3
commit a6ba6e26b2
30 changed files with 446 additions and 1424 deletions
+4 -4
View File
@@ -810,8 +810,8 @@ namespace GenericTest
/// A valid serial number is available => proceed
///
ITransaction transaction = null;
Process proc = null;
OrderInfo order = null;
string proc = null;
string order = null;
bool readingFromTracingDBFailed = false; /// Reading form tracing DB failed (equipment error)
bool savingToTracingDBFailed = false; /// Writing to tracoing DB failed (equipment error)
bool verificationFailed = false; /// Reading/writing from/to tracing DB OK, but verification failed (product error)
@@ -824,7 +824,7 @@ namespace GenericTest
transaction = dbSession.BeginTransaction();
/// Get a process of the last reference record with this PCB number
proc = TracingDB.GetWorkflow(dbSession, testerRecord.SN, out order);
proc = TracingDB.GetWorkflow(dbSession, testerRecord.SN, 1, out order);
/// Check if a record from the previous workplace exists
if (proc == null)
@@ -863,7 +863,7 @@ namespace GenericTest
{
/// Fetch all GOOD reference records with given code
IList<ReferenceRecord> refRecords = dbSession.QueryOver<ReferenceRecord>()
.Where(rr => ((rr.Code == testerRecord.SN) && (rr.Result == 0)))
.Where(rr => ((rr.Code1 == testerRecord.SN) && (rr.Result == 0)))
.And(rr => (rr.Workstep == verInfo.Workstep))
.JoinQueryOver<Workstep>(rr => rr.Workstep)
.Where(ws => (ws.ReferencePart.Id == verInfo.Part.Id))
+2 -24
View File
@@ -236,31 +236,9 @@ namespace Results.Forms
using (ISession session = SharedDatabase.TracingDB.SessionFactory.OpenSession())
{
IList<ReferenceRecord> refRecords = session.QueryOver<ReferenceRecord>()
.Where(x => (x.Code == wm.SerialNr))
.OrderBy(x => x.TimeStamp).Desc
.Where(x => (x.Code1 == wm.SerialNr))
.OrderBy(x => x.Timestamp).Desc
.List();
for (int i = 0; i < refRecords.Count; i++)
{
ReferenceRecord refR = refRecords[i];
if ((refR.Records != null) && (refR.Records.Count > 0))
{
/// Reference record has additional records/parts (i.e. it is PCB assembly workflow step)
///
foreach (var rec in refR.Records)
{
if (rec.Part.OraDBType.ToLower().Contains("flowtube"))
{
/// rec.Part is a flowtube
///
IList<ReferenceRecord> flowtubeRRs = session.QueryOver<ReferenceRecord>()
.Where(x => (x.Code == rec.Code))
.OrderBy(x => x.TimeStamp).Desc
.List();
foreach (var rr in flowtubeRRs) refRecords.Add(rr);
}
}
}
}
new Results.Forms.MoreWMResultsDlg(wm, refRecords).ShowDialog();
}
+24 -46
View File
@@ -122,65 +122,43 @@ namespace Results.Forms
/// <param name="refRecords">ReferenceRecord-s from tracing DB</param>
void ShowTracingResults(Results.Entities.WaterMeter wm, IList<ReferenceRecord> refRecords)
{
tracingResultsListView.Columns.Add(Strings.Date_and_time, 110);
tracingResultsListView.Columns.Add(Strings.Step, 100);
tracingResultsListView.Columns.Add(Strings.Workplace, 100);
tracingResultsListView.Columns.Add(Strings.Name, 100);
tracingResultsListView.Columns.Add(Strings.Result, 70);
tracingResultsListView.Columns.Add(Strings.Part, 90);
tracingResultsListView.Columns.Add(Strings.Code, 150);
tracingResultsListView.Columns.Add(Strings.Result, 70);
tracingResultsListView.Columns.Add(Strings.Note, 100);
tracingResultsListView.Columns.Add(Strings.Date_and_time, 110);
tracingResultsListView.Columns.Add(Strings.Workstep, 100);
tracingResultsListView.Columns.Add(Strings.Workplace, 100);
tracingResultsListView.Columns.Add(Strings.User, 100);
tracingResultsListView.Columns.Add(Strings.Order, 90);
tracingResultsListView.Columns.Add(Strings.Workflow, 450);
if (refRecords == null || refRecords.Count == 0)
{
messageLabel.Text = "V sledovaní výroby nie sú žiadne záznamy";
messageLabel.Text = Strings.No_records_in_production_tracing_DB;
}
else
{
Process proc = refRecords[0].Workflow;
bool[] isMissing = new bool[proc.Worksteps.Count];
for (int i = 0; i < isMissing.Length; i++) isMissing[i] = true;
ReferenceRecord rr = refRecords[0];
string workflow = rr.Workflow;
foreach (var rr in refRecords)
foreach (var rcrd in rr.Records)
{
tracingResultsListView.Items.Add(new ListViewItem(new string[]
string[] oneRow = new string[]
{
rr.TimeStamp.ToString("dd.MM.yyyy HH:mm"),
(rr.Workstep != null) ? rr.Workstep.Name : string.Empty,
rr.Workplace,
rr.UserName,
rr.Result == 0 ? "OK" : "NOK",
(rr.Workstep != null && rr.Workstep.ReferencePart != null) ? rr.Workstep.ReferencePart.Name : string.Empty,
rr.Code,
(rr.Workflow != null) ? rr.Workflow.Name : string.Empty,
}));
(rcrd.Name != null) ? rcrd.Name : "<none>",
(rcrd.Code != null) ? rcrd.Code : "<none>",
rcrd.Result.ToString(),
(rcrd.Note != null) ? rcrd.Note : "<none>",
(rcrd.StepRecord != null) ? rcrd.StepRecord.Timestamp.ToString("dd.MM.yyyy HH:mm:ss") : string.Empty,
(rcrd.StepRecord != null && rcrd.StepRecord.Workstep != null) ? rcrd.StepRecord.Workstep : "<none>",
(rcrd.StepRecord != null && rcrd.StepRecord.Workplace != null) ? rcrd.StepRecord.Workplace : "<none>",
(rcrd.StepRecord != null && rcrd.StepRecord.User != null) ? rcrd.StepRecord.User : "<none>",
(rr.POName != null) ? rr.POName : "<none>",
(rr.Workflow != null) ? rr.Workflow : "<none>",
};
for (int i = 0; i < isMissing.Length; i++)
{
if (proc.Worksteps[i] == rr.Workstep) isMissing[i] = false;
}
}
string missingWorkplace = null;
for (int i = 0; i < isMissing.Length; i++)
{
if (isMissing[i])
{
if (missingWorkplace == null)
{
missingWorkplace = proc.Worksteps[i].Name;
messageLabel.Text = string.Format("Chýba záznam z pracoviska {0}", missingWorkplace);
}
else
{
messageLabel.Text = string.Format("Chýba záznam z pracoviska {0} aj z nasledujúcich pracovísk", missingWorkplace);
}
}
}
if (missingWorkplace == null)
{
messageLabel.Text = "Všetko je OK";
tracingResultsListView.Items.Add(new ListViewItem(oneRow));
}
}
}
-65
View File
@@ -1,65 +0,0 @@
namespace Results.Forms
{
partial class TracingResultsDlg
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.tracingResultsListView = new System.Windows.Forms.ListView();
this.SuspendLayout();
//
// tracingResultsListView
//
this.tracingResultsListView.Dock = System.Windows.Forms.DockStyle.Fill;
this.tracingResultsListView.GridLines = true;
this.tracingResultsListView.Location = new System.Drawing.Point(0, 0);
this.tracingResultsListView.Name = "tracingResultsListView";
this.tracingResultsListView.Size = new System.Drawing.Size(1228, 178);
this.tracingResultsListView.TabIndex = 0;
this.tracingResultsListView.UseCompatibleStateImageBehavior = false;
this.tracingResultsListView.View = System.Windows.Forms.View.Details;
//
// TracingResultsDlg
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(1228, 178);
this.Controls.Add(this.tracingResultsListView);
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "TracingResultsDlg";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
this.Text = "TracingResultsDlg";
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.ListView tracingResultsListView;
}
}
-44
View File
@@ -1,44 +0,0 @@
///
/// Copyright (c) 2019 Sensus Slovensko a.s.
///
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using SharedDatabase.Entities;
using Results.Resources;
namespace Results.Forms
{
public partial class TracingResultsDlg : Form
{
public TracingResultsDlg(IList<ReferenceRecord> rRecords)
{
InitializeComponent();
Text = Strings.Production_tracing_results;
tracingResultsListView.Columns.Add(Strings.Date_and_time, 110);
tracingResultsListView.Columns.Add(Strings.Step, 100);
tracingResultsListView.Columns.Add(Strings.Workplace, 100);
tracingResultsListView.Columns.Add(Strings.Name, 100);
tracingResultsListView.Columns.Add(Strings.Result, 70);
tracingResultsListView.Columns.Add(Strings.Part, 90);
tracingResultsListView.Columns.Add(Strings.Code, 150);
tracingResultsListView.Columns.Add(Strings.Workflow, 450);
foreach (var rr in rRecords)
{
tracingResultsListView.Items.Add(new ListViewItem(new string[] {
rr.TimeStamp.ToString("dd.MM.yyyy HH:mm"),
rr.Workstep.Name,
rr.Workplace,
rr.UserName,
rr.Result == 0 ? "OK" : "NOK",
rr.Workstep.ReferencePart.Name,
rr.Code,
rr.Workflow.Name,
}));
}
}
}
}
-120
View File
@@ -1,120 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>
+36
View File
@@ -609,6 +609,15 @@ namespace Results.Resources {
}
}
/// <summary>
/// Looks up a localized string similar to No records in production tracing DB.
/// </summary>
internal static string No_records_in_production_tracing_DB {
get {
return ResourceManager.GetString("No_records_in_production_tracing_DB", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to No water meter.
/// </summary>
@@ -618,6 +627,15 @@ namespace Results.Resources {
}
}
/// <summary>
/// Looks up a localized string similar to Note.
/// </summary>
internal static string Note {
get {
return ResourceManager.GetString("Note", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to OK.
/// </summary>
@@ -627,6 +645,15 @@ namespace Results.Resources {
}
}
/// <summary>
/// Looks up a localized string similar to Order.
/// </summary>
internal static string Order {
get {
return ResourceManager.GetString("Order", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to P amb.
/// </summary>
@@ -2193,6 +2220,15 @@ namespace Results.Resources {
}
}
/// <summary>
/// Looks up a localized string similar to Workstep.
/// </summary>
internal static string Workstep {
get {
return ResourceManager.GetString("Workstep", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Wrong iPerl counting direction.
/// </summary>
+12
View File
@@ -336,4 +336,16 @@
<data name="This_position_is_disabled" xml:space="preserve">
<value>Taro pozice je vypnuta</value>
</data>
<data name="Order" xml:space="preserve">
<value>Zakázka</value>
</data>
<data name="No_records_in_production_tracing_DB" xml:space="preserve">
<value>Žádné záznamy v databázi pro sledování výroby</value>
</data>
<data name="Note" xml:space="preserve">
<value>Poznámka</value>
</data>
<data name="Workstep" xml:space="preserve">
<value>Krok</value>
</data>
</root>
+12
View File
@@ -837,4 +837,16 @@
<data name="Tooltip_RA" xml:space="preserve">
<value>Radio address of the meter</value>
</data>
<data name="Order" xml:space="preserve">
<value>Order</value>
</data>
<data name="No_records_in_production_tracing_DB" xml:space="preserve">
<value>No records in production tracing DB</value>
</data>
<data name="Note" xml:space="preserve">
<value>Note</value>
</data>
<data name="Workstep" xml:space="preserve">
<value>Workstep</value>
</data>
</root>
-9
View File
@@ -124,12 +124,6 @@
<Compile Include="Forms\ResultsConfigDlg.designer.cs">
<DependentUpon>ResultsConfigDlg.cs</DependentUpon>
</Compile>
<Compile Include="Forms\TracingResultsDlg.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="Forms\TracingResultsDlg.Designer.cs">
<DependentUpon>TracingResultsDlg.cs</DependentUpon>
</Compile>
<Compile Include="Forms\WaterMeterEventArgs.cs" />
<Compile Include="ItemID.cs" />
<Compile Include="ManualEntryItemSpec.cs" />
@@ -230,9 +224,6 @@
<EmbeddedResource Include="Forms\ResultsConfigDlg.resx">
<DependentUpon>ResultsConfigDlg.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Forms\TracingResultsDlg.resx">
<DependentUpon>TracingResultsDlg.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
-127
View File
@@ -1,127 +0,0 @@
using System;
using System.Collections.Generic;
using log4net;
using SharedDatabase.Entities;
namespace SharedDatabase
{
public class BatteryAndFlowtubeInfo
{
static readonly ILog log = LogManager.GetLogger(typeof(BatteryAndFlowtubeInfo));
/// Constants
public const string VitzrocellBatteryPartNr = "68118221";
public const string TadiranBatteryPartNr = "68117469";
public string PcbNumber; /// Unique PCB number of the water meter
public string BattSapPartNr; /// Battery SAP part number
public int BattBatchNr; /// Batch number (purchase order)
public string BattMMYY; /// Production date
public string BattSupplier; /// Supplier
public string FlowtubeSapPartNr; /// Flowtube SAP part number
public bool IsPorexFlowtube; ///
public string PrintedInfo; /// 'T', 'Vi', '-', 'T/P', 'Vi/P' or '-/P'
public DateTime TimeStamp; /// Record creation time
bool complete { get { return (PcbNumber != null) && (BattSapPartNr != null) && (BattBatchNr != 0) && (BattMMYY != null) && (BattSupplier != null); } }
public BatteryAndFlowtubeInfo()
{
TimeStamp = DateTime.Now;
PrintedInfo = "-";
}
/// <summary>
/// Search MySQL DB and get battery info, add it into the record.
/// </summary>
/// <returns>true when successful</returns>
public static BatteryAndFlowtubeInfo GetBatteryAndFlowtubeInfo(string pcbNumber, IList<WMPart> parts, string porexSapNumbers)
{
if (string.IsNullOrEmpty(pcbNumber))
{
log.ErrorFormat("Invalid PcbBr, no battery info.");
return null;
}
BatteryAndFlowtubeInfo info = new BatteryAndFlowtubeInfo() { PcbNumber = pcbNumber };
try
{
bool error = false;
foreach (var part in parts)
{
if (part.CodeLocation == CodeLocation.OnPart)
{
if (porexSapNumbers.Contains(part.Name))
{
info.IsPorexFlowtube = true;
info.FlowtubeSapPartNr = part.Name;
}
}
if (!string.IsNullOrEmpty(part.OraDBType))
{
string[] oraItems = part.OraDBType.Split(new char[] { ' ' });
string oraType = oraItems[0];
string oraDescr = (oraItems.Length > 1) ? oraItems[1] : string.Empty;
if ((oraType == "Batt") || (oraType == "Batt1") || (oraType == "Batt2"))
{
if (info.BattSapPartNr != null) { error = true; break; }
info.BattSapPartNr = part.Name;
int battBatchNr;
info.BattBatchNr = int.TryParse(part.Code, out battBatchNr) ? battBatchNr : 1;
info.BattSupplier = oraDescr; /// Should be "TADIRAN" or "VITZROCELL"
}
}
if (part.CodeType == (sbyte)CodeType.DateMMYY)
{
if (info.BattMMYY != null) { error = true; break; }
info.BattMMYY = part.Code;
}
}
if (error || !info.complete)
{
log.ErrorFormat("Battery info. for PcbNr={0} wasn't found in MySQL database", info.PcbNumber);
return null;
}
///
/// Set battery information printed on labels
///
if (info.BattSupplier == "VITZROCELL")
{
info.PrintedInfo = "Vi";
}
else if (info.BattSupplier == "TADIRAN")
{
info.PrintedInfo = "T";
}
///
/// Append Porex flowtube info in case of a Porex flowtube
///
if (info.IsPorexFlowtube) { info.PrintedInfo += "/P"; }
return info;
}
catch (Exception exc)
{
log.ErrorFormat("Battery info. for PcbNr={0} wasn't found in MySQL database: {1}",
info.PcbNumber, exc.Message);
return null;
}
}
public override string ToString()
{
return string.Format("PcbNr={0}, Battery={1}/{2}/{3} {4}, Time={5}", PcbNumber, BattBatchNr, BattMMYY, BattSupplier, (IsPorexFlowtube ? "porex" : ""), TimeStamp);
}
}
}
+26 -45
View File
@@ -6,60 +6,41 @@ namespace SharedDatabase.Entities
public class Record
{
public virtual int Id { get; protected set; }
public virtual string Code { get; set; }
public virtual DateTime TimeStamp { get; set; }
public virtual string Name { get; set; } /// Part name (e.g. SAP number)
public virtual string Code { get; set; } /// Serial number or batch number
public virtual int Result { get; set; } /// Operation result: 0=OK, otherwise a non-zero error code
public virtual string Note { get; set; } /// Arbitrary additional information (e.g. Oracle settings)
public virtual StepRecord StepRecord { get; set; } /// Step record with timestamp/workstep/workplace/user info, many-to-one relationship
public virtual ReferenceRecord ReferenceRecord { get; set; } /// Reference record with info identifying the product, many-to-one relationship
public virtual Part Part { get; set; }
public virtual ReferenceRecord ReferenceRecord { get; set; }
protected Record()
{
}
/// <summary>
/// Constructor used when a part barcode is scanned
/// </summary>
/// <param name="partId">Part</param>
/// <param name="referenceRecordId">Reference record</param>
/// <param name="code">Scanned barcode</param>
public Record(Part part, ReferenceRecord referenceRecord, string code)
{
Part = part;
ReferenceRecord = referenceRecord;
Code = code;
TimeStamp = DateTime.Now;
}
protected Record() { }
/// <summary>
/// Create a copy of a process with a new name
/// Constructor used when a part barcode is scanned
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public virtual Record Clone(Process newProcess, ReferenceRecord newRR)
/// <param name="name">Part name (SAP nr.)</param>
/// <param name="code">Scanned barcode: S/N or a batch nr.</param>
/// <param name="result">0=OK, otherwise a non-zero error code</param>
/// <param name="stepRecord">Step record</param>
/// <param name="referenceRecord">Reference record</param>
/// <param name="note">true = record with workstep info, false = record with part info</param>
public Record(ReferenceRecord referenceRecord, StepRecord stepRecord, string name, string code, int result = 0, string note = null)
{
Part newPart = null;
foreach (var pt in newProcess.Parts)
{
if (Part.Name == pt.Name)
{
newPart = pt;
break;
}
}
Record rslt = new Record(newPart, newRR, Code);
rslt.TimeStamp = TimeStamp;
return rslt;
ReferenceRecord = referenceRecord;
StepRecord = stepRecord;
Name = name;
Code = code;
Result = Result;
Note = note;
}
public override string ToString()
{
return string.Format("code={0} part={1}{2} description={3}",
Code,
Part.Name,
string.IsNullOrEmpty(Part.OraDBType) ? string.Empty : string.Format(" ORACLE='{0}'", Part.OraDBType),
Part.Description);
return string.Format("name={0} code={1} rslt={2} note={3}",
Name != null ? Name : "<none>",
Code != null ? Code : "<none>",
Result,
Note != null ? Note : "<none>");
}
}
}
+32 -63
View File
@@ -1,20 +1,21 @@
using System;
using System.Collections.Generic;
using FluentNHibernate.Mapping;
namespace SharedDatabase.Entities
{
public class ReferenceRecord
{
public virtual int Id { get; protected set; }
public virtual string Code { get; set; }
public virtual DateTime TimeStamp { get; set; }
public virtual string UserName { get; set; }
public virtual string Workplace { get; set; }
public virtual int Result { get; set; } /// 0 = No error (OK), >0 = Error code
public virtual OrderInfo POrder { get; set; }
public virtual Process Workflow { get; set; }
public virtual Workstep Workstep { get; set; }
public virtual IList<Record> Records { get; set; }
public virtual string Code1 { get; set; }
public virtual string Code2 { get; set; }
public virtual string Code3 { get; set; }
public virtual string Code4 { get; set; }
public virtual string POName { get; set; }
public virtual string Workflow { get; set; }
public virtual DateTime Timestamp { get; set; } /// Time stamp of the last added step record
public virtual IList<Record> Records { get; set; }
public virtual IList<StepRecord> StepRecords { get; set; }
/// <summary>
@@ -23,69 +24,37 @@ namespace SharedDatabase.Entities
protected ReferenceRecord()
{
Records = new List<Record>();
}
/// <summary>
/// Constructor used when reference barcode is scanned
/// </summary>
/// <param name="porder">Production order</param>
/// <param name="workflow">Process</param>
/// <param name="workstep">Workstep</param>
/// <param name="code">Scanned barcode</param>
public ReferenceRecord(OrderInfo porder, Process workflow, Workstep workstep, string code,
string userName, string workplace, int result)
: this()
{
POrder = porder;
Workflow = workflow;
Workstep = workstep;
Code = code;
TimeStamp = DateTime.Now;
UserName = userName;
Workplace = workplace;
Result = result;
StepRecords = new List<StepRecord>();
}
/// <summary>
/// Create a copy of a reference record with a new name
/// Constructor used when reference barcode is scanned
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public virtual ReferenceRecord Clone(Process newProcess)
/// <param name="porder">Production order</param>
/// <param name="workflow">Process</param>
/// <param name="workstep">Workstep</param>
/// <param name="code">Scanned barcode</param>
public ReferenceRecord(string porder, string workflow, string code1, string code2 = null, string code3 = null, string code4 = null)
: this()
{
Workstep newWorkstep = null;
foreach (var ws in newProcess.Worksteps)
{
if (Workstep.Name == ws.Name)
{
newWorkstep = ws;
break;
}
}
ReferenceRecord rslt = new ReferenceRecord(POrder, newProcess, newWorkstep,
Code, UserName, Workplace, Result);
rslt.TimeStamp = TimeStamp;
rslt.Records = new List<Record>();
foreach (var record in Records)
{
rslt.Records.Add(record.Clone(newProcess, rslt));
}
return rslt;
Code1 = code1;
Code2 = code2;
Code3 = code3;
Code4 = code4;
POName = porder;
Workflow = workflow;
Timestamp = DateTime.Now;
}
public override string ToString()
{
return string.Format("code={0} part={1} description='{2}' step='{3}' workplace='{4}' user={5} time={6:dd.MM.yyyy HH:mm:ss}",
(Code != null) ? Code : "<none>",
(Workstep != null) ? Workstep.ReferencePart.Name : string.Empty,
(Workstep != null) ? Workstep.ReferencePart.Description : string.Empty,
(Workstep != null) ? Workstep.Name : string.Empty,
Workplace,
UserName,
TimeStamp);
return string.Format("sn1={0} sn2={1} sn3={2} sn4={3} order={4} workflow={5}",
(Code1 != null) ? Code1 : "<none>",
(Code2 != null) ? Code2 : "<none>",
(Code3 != null) ? Code3 : "<none>",
(Code4 != null) ? Code4 : "<none>",
(POName != null) ? POName : "<none>",
(Workflow != null) ? Workflow : "<none>");
}
}
}
+47
View File
@@ -0,0 +1,47 @@
using System;
using System.Collections.Generic;
namespace SharedDatabase.Entities
{
public class StepRecord
{
public virtual int Id { get; protected set; }
public virtual DateTime Timestamp { get; set; } /// Timestamp
public virtual string Workstep { get; set; } /// Workstep name
public virtual string Workplace { get; set; } /// Workplace
public virtual string User { get; set; } /// User name
public virtual int Result { get; set; } /// 0=OK, otherwise a non-zero error code
public virtual ReferenceRecord ReferenceRecord { get; set; } /// Many-to-one relationship
public virtual IList<Record> Records { get; set; }
protected StepRecord() { }
/// <summary>
/// Constructor used when a part barcode is scanned
/// </summary>
/// <param name="referenceRecord">Reference record</param>
/// <param name="workstep">Workstep name</param>
/// <param name="workplace">Worklace</param>
/// <param name="user">User name</param>
/// <param name="result">0=OK, otherwise a non-zero error code</param>
public StepRecord(ReferenceRecord referenceRecord, string workstep, string workplace, string user, int result = 0)
{
Timestamp = DateTime.Now;
ReferenceRecord = referenceRecord;
Workstep = workstep;
Workplace = workplace;
User = user;
Result = result;
}
public override string ToString()
{
return string.Format("time={0:yyyy/MM/dd HH:mm:ss} workstep={1} workplace={2} user={3}{4}",
Timestamp,
Workstep != null ? Workstep : "<none>",
Workplace != null ? Workplace : "<none>",
User != null ? User : "<none>",
Result != 0 ? string.Format(" error={0}", Result) : string.Empty);
}
}
}
-48
View File
@@ -77,54 +77,6 @@ namespace SharedDatabase
Count,
}
public enum LoginLevel
{
None,
TeamLeader,
Administrator,
MH,
Count,
}
public enum ItemSpecID
{
RefRecordID = 0,
TimeStamp,
Workstep,
Workplace,
UserName,
Barcode,
RefPartName,
PartBarcode,
PartName,
TimeStamp2,
Workstep2,
Workplace2,
UserName2,
Barcode2,
PartBarcode2,
SerialNr,
PurchaseOrder,
TestResult,
MaxPruefindex,
MaxTestindexEx,
TestBenchId,
Process,
Result,
}
public enum ItemSpecCaps
{
None = 0,
ReferenceRecord = 1,
AssociatedRecord = 2,
OracleQuery = 4,
}
public enum VerifState
{
Undefined = 0, /// Undefined (only used in OnActivity(..) when start/stop info message is issued)
-350
View File
@@ -1,350 +0,0 @@
///
/// Copyright (c) 2016-2021 Sensus Slovensko a.s.
///
using System;
using System.Collections.Generic;
using SharedDatabase.Entities;
using SharedDatabase.Resources;
using NHibernate;
using NHibernate.Criterion;
namespace SharedDatabase
{
public class ItemSpec
{
///
/// Function delegate to pick a reference record and convert it to a string
///
public delegate string PrintDlgt(object x, string format, string precision, int width);
///
/// Public fields
///
public readonly ItemSpecID Uid; /// Unique Uid used to distinguish items
public readonly string Name; /// Name that can be localized to identify the item in a list
public readonly PrintDlgt PrintFn; /// Function used to convert the result to a text
public string Caption; /// User defined text printed in the column header
public string Format; /// Specifies the text generation
public string Precision; /// Specifies the text generation
public int Width; /// Specifies the text generation
readonly ItemSpecCaps itemSpecCaps;
/// <summary> Public parameterless constructor </summary>
public ItemSpec()
{
}
/// <summary> Constructor to specify all items </summary>
public ItemSpec(ItemSpecID uid, string name, PrintDlgt printFn, ItemSpecCaps itemSpecCaps)
{
Uid = uid;
Name = name;
PrintFn = printFn;
this.itemSpecCaps = itemSpecCaps;
///
Caption = name;
Format = "{0}";
Precision = string.Empty;
Width = 0;
}
public override string ToString()
{
return string.Format("uid={0}, name={1}, caption={2}", Uid, Name, Caption);
}
/// <summary> Copy constructor </summary>
public ItemSpec Clone()
{
ItemSpec newItem = new ItemSpec(Uid, Name, PrintFn, itemSpecCaps);
newItem.Caption = Caption;
newItem.Format = Format;
newItem.Precision = Precision;
newItem.Width = Width;
return newItem;
}
/// <summary> Safe wrapper which replaces null-s by empty strings </summary>
public string Print(object x)
{
string str = PrintFn(x, Format, Precision, Width);
return (str == null) ? string.Empty : str;
}
/// <summary> Similar to Print(), in addition embeds text into "" </summary>
public string Export(object x)
{
string str = PrintFn(x, Format, Precision, Width);
if (str == null) str = string.Empty;
if (Uid == ItemSpecID.Barcode || Uid == ItemSpecID.PartBarcode || Uid == ItemSpecID.SerialNr || Uid == ItemSpecID.PurchaseOrder)
{
return string.Format("=\"{0}\"", str);
}
return str;
}
/// Static list of all available items
public static readonly IList<ItemSpec> AllItems;
///
/// Static constructor that initializes the list of all items
///
static ItemSpec()
{
AllItems = new List<ItemSpec>();
AllItems.Add(new ItemSpec(ItemSpecID.RefRecordID, Strings.RefRecordID, (x, f, p, w) => ((int)x).ToString(), ItemSpecCaps.ReferenceRecord));
AllItems.Add(new ItemSpec(ItemSpecID.TimeStamp, Strings.Time_stamp, (x, f, p, w) => string.IsNullOrEmpty(f) ? ((DateTime)x).ToString() : string.Format(f, (DateTime)x), ItemSpecCaps.ReferenceRecord));
AllItems.Add(new ItemSpec(ItemSpecID.Workstep, Strings.Workstep, (x, f, p, w) => FormatStr(f, x is Workstep ? (x as Workstep).Name : "<null>"), ItemSpecCaps.ReferenceRecord));
AllItems.Add(new ItemSpec(ItemSpecID.Workplace, Strings.Workplace, (x, f, p, w) => FormatStr(f, x), ItemSpecCaps.ReferenceRecord));
AllItems.Add(new ItemSpec(ItemSpecID.UserName, Strings.User_name, (x, f, p, w) => FormatStr(f, x), ItemSpecCaps.ReferenceRecord));
AllItems.Add(new ItemSpec(ItemSpecID.Barcode, Strings.Ref_part_barcode, (x, f, p, w) => FormatStr(f, x), ItemSpecCaps.ReferenceRecord));
AllItems.Add(new ItemSpec(ItemSpecID.RefPartName, Strings.Ref_part_name, (x, f, p, w) => FormatStr(f, ((Workstep)x).ReferencePart.Name), ItemSpecCaps.ReferenceRecord));
AllItems.Add(new ItemSpec(ItemSpecID.PartBarcode, Strings.Part_barcode, (x, f, p, w) => FormatStr(f, x), ItemSpecCaps.ReferenceRecord | ItemSpecCaps.AssociatedRecord));
AllItems.Add(new ItemSpec(ItemSpecID.PartName, Strings.Part_name, (x, f, p, w) => FormatStr(f, ((Part)x).Name), ItemSpecCaps.ReferenceRecord | ItemSpecCaps.AssociatedRecord));
AllItems.Add(new ItemSpec(ItemSpecID.TimeStamp2, Strings.Time_stamp+"2", (x, f, p, w) => string.IsNullOrEmpty(f) ? ((DateTime)x).ToString() : string.Format(f, (DateTime)x), ItemSpecCaps.ReferenceRecord));
AllItems.Add(new ItemSpec(ItemSpecID.Workstep2, Strings.Workstep + "2", (x, f, p, w) => FormatStr(f, ((Workstep)x).Name), ItemSpecCaps.ReferenceRecord));
AllItems.Add(new ItemSpec(ItemSpecID.Workplace2, Strings.Workplace + "2", (x, f, p, w) => FormatStr(f, x), ItemSpecCaps.ReferenceRecord));
AllItems.Add(new ItemSpec(ItemSpecID.UserName2, Strings.User_name + "2", (x, f, p, w) => FormatStr(f, x), ItemSpecCaps.ReferenceRecord));
AllItems.Add(new ItemSpec(ItemSpecID.Barcode2, Strings.Barcode + "2", (x, f, p, w) => FormatStr(f, x), ItemSpecCaps.ReferenceRecord));
AllItems.Add(new ItemSpec(ItemSpecID.PartBarcode2, Strings.Part_barcode+"2", (x, f, p, w) => FormatStr(f, x), ItemSpecCaps.ReferenceRecord | ItemSpecCaps.AssociatedRecord));
AllItems.Add(new ItemSpec(ItemSpecID.SerialNr, Strings.Serial_nr, (x, f, p, w) => x as string, ItemSpecCaps.ReferenceRecord | ItemSpecCaps.OracleQuery));
AllItems.Add(new ItemSpec(ItemSpecID.PurchaseOrder, Strings.Purchase_order, (x, f, p, w) => x as string, ItemSpecCaps.ReferenceRecord | ItemSpecCaps.OracleQuery));
AllItems.Add(new ItemSpec(ItemSpecID.TestResult, Strings.Test_result, (x, f, p, w) => x as string, ItemSpecCaps.ReferenceRecord | ItemSpecCaps.OracleQuery));
AllItems.Add(new ItemSpec(ItemSpecID.MaxPruefindex, Strings.Tests_count, (x, f, p, w) => x as string, ItemSpecCaps.ReferenceRecord | ItemSpecCaps.OracleQuery));
AllItems.Add(new ItemSpec(ItemSpecID.MaxTestindexEx,Strings.Tests_count_and_rslt, (x, f, p, w) => x as string, ItemSpecCaps.ReferenceRecord | ItemSpecCaps.OracleQuery));
AllItems.Add(new ItemSpec(ItemSpecID.TestBenchId, Strings.Test_bench_Id, (x, f, p, w) => x as string, ItemSpecCaps.ReferenceRecord | ItemSpecCaps.OracleQuery));
AllItems.Add(new ItemSpec(ItemSpecID.Process, Strings.Workflow, (x, f, p, w) => FormatStr(f, x is Process ? (x as Process).Name : "<null>"), ItemSpecCaps.ReferenceRecord));
AllItems.Add(new ItemSpec(ItemSpecID.Result, Strings.Result, (x, f, p, w) => FormatStr(f, ((int)x).ToString()), ItemSpecCaps.ReferenceRecord));
}
public static string FormatStr(string format, object value)
{
int len;
if (string.IsNullOrEmpty(format))
{
return (string)value;
}
else if (int.TryParse(format, out len) && len > 0)
{
if (((string)value).Length >= len)
{
return ((string)value).Substring(0, len);
}
else
{
return (string)value;
}
}
else
{
return string.Format(format, value);
}
}
public PropertyProjection GetProperty(ReferenceRecord refRecord, Record record)
{
switch (Uid)
{
case ItemSpecID.RefRecordID: return Projections.Property(() => refRecord.Id);
case ItemSpecID.TimeStamp: return Projections.Property(() => refRecord.TimeStamp);
case ItemSpecID.Workstep: return Projections.Property(() => refRecord.Workstep);
case ItemSpecID.Workplace: return Projections.Property(() => refRecord.Workplace);
case ItemSpecID.UserName: return Projections.Property(() => refRecord.UserName);
case ItemSpecID.Barcode: return Projections.Property(() => refRecord.Code);
case ItemSpecID.RefPartName: return Projections.Property(() => refRecord.Workstep);
case ItemSpecID.PartBarcode: return Projections.Property(() => record.Code);
case ItemSpecID.PartName: return Projections.Property(() => record.Part);
case ItemSpecID.TimeStamp2: return null;
case ItemSpecID.Workstep2: return null;
case ItemSpecID.Workplace2: return null;
case ItemSpecID.UserName2: return null;
case ItemSpecID.Barcode2: return null;
case ItemSpecID.PartBarcode2: return null;
case ItemSpecID.SerialNr: return null;
case ItemSpecID.PurchaseOrder: return null;
case ItemSpecID.TestResult: return null;
case ItemSpecID.MaxPruefindex: return null;
case ItemSpecID.MaxTestindexEx: return null;
case ItemSpecID.TestBenchId: return null;
case ItemSpecID.Process: return Projections.Property(() => refRecord.Workflow);
case ItemSpecID.Result: return Projections.Property(() => refRecord.Result);
default: return null;
}
}
public PropertyProjection GetProperty2(ReferenceRecord refRecord2, Record record2)
{
switch (Uid)
{
case ItemSpecID.RefRecordID: return null;
case ItemSpecID.TimeStamp: return null;
case ItemSpecID.Workstep: return null;
case ItemSpecID.Workplace: return null;
case ItemSpecID.UserName: return null;
case ItemSpecID.Barcode: return null;
case ItemSpecID.PartBarcode: return null;
case ItemSpecID.TimeStamp2: return Projections.Property(() => refRecord2.TimeStamp);
case ItemSpecID.Workstep2: return Projections.Property(() => refRecord2.Workstep);
case ItemSpecID.Workplace2: return Projections.Property(() => refRecord2.Workplace);
case ItemSpecID.UserName2: return Projections.Property(() => refRecord2.UserName);
case ItemSpecID.Barcode2: return Projections.Property(() => refRecord2.Code);
case ItemSpecID.PartBarcode2: return Projections.Property(() => record2.Code);
case ItemSpecID.SerialNr: return null;
case ItemSpecID.PurchaseOrder: return null;
case ItemSpecID.TestResult: return null;
case ItemSpecID.MaxPruefindex: return null;
case ItemSpecID.MaxTestindexEx: return null;
case ItemSpecID.TestBenchId: return null;
case ItemSpecID.Process: return Projections.Property(() => refRecord2.Workflow);
case ItemSpecID.Result: return Projections.Property(() => refRecord2.Result);
default: return null;
}
}
public ItemSpecCaps GetCaps()
{
return itemSpecCaps;
}
public static ItemSpec GetItem(ItemSpecID id)
{
foreach (var item in AllItems)
if (item.Uid == id)
return item.Clone();
return null;
}
public static ItemSpec GetItem(string uidName)
{
foreach (var item in AllItems)
if (item.Uid.ToString() == uidName)
return item.Clone();
return null;
}
public static ProjectionList GetProjections(IList<ItemSpec> items, ReferenceRecord refRecord, Record record)
{
ProjectionList projections = Projections.ProjectionList();
foreach (var item in items)
{
PropertyProjection projection = item.GetProperty(refRecord, record);
if (projection != null)
projections.Add(projection);
}
return projections;
}
public static IList<object[]> Expand(IList<object[]> data, IList<ItemSpec> items)
{
if (data.Count == 0) return data;
int iSize = data[0].Length;
int oSize = items.Count;
for (int i = 0; i < data.Count; i++)
{
object[] inArr = data[i];
object[] outArr = new object[oSize];
int srcIx = 0;
for (int dstIx = 0; dstIx < oSize; dstIx++)
{
outArr[dstIx] = ((items[dstIx].GetCaps() & ItemSpecCaps.OracleQuery) == ItemSpecCaps.OracleQuery) ? string.Empty : inArr[srcIx++];
}
data[i] = outArr;
}
return data;
}
//static string GetPartCode(ReferenceRecord refRecord, string partName)
//{
// if (refRecord != null && refRecord.Records != null)
// {
// foreach (var record in refRecord.Records)
// {
// if (record.Part.Name.Equals(partName))
// {
// return record.Code;
// }
// }
// }
// return string.Empty;
//}
public static string[] ToStrArray(IList<ItemSpec> items)
{
int count = (items != null) ? items.Count : 0;
string[] result = new string[count];
for (int i = 0; i < count; i++)
{
result[i] = string.Format("{0}~{1}~{2}~{3}~{4}",
items[i].Uid,
items[i].Caption,
items[i].Format,
items[i].Precision,
items[i].Width);
}
return result;
}
public static IList<ItemSpec> FromStrArray(string[] strArray)
{
IList<ItemSpec> result = new List<ItemSpec>();
if (strArray != null)
{
for (int i = 0; i < strArray.Length; i++)
{
string[] field = strArray[i].Split(new char[] { '~' });
try
{
ItemSpec item = GetItem(field[0]);
item.Caption = field[1];
item.Format = field[2];
item.Precision = field[3];
item.Width = int.Parse(field[4]);
result.Add(item);
}
catch
{
ItemSpec item = GetItem(ItemSpecID.RefRecordID);
item.Format = string.Format("Parse error: {0}", strArray[i]);
result.Add(item);
}
}
}
return result;
}
}
}
+6 -5
View File
@@ -7,11 +7,12 @@ namespace SharedDatabase.Mappings
public RecordMap()
{
Id(x => x.Id);
Map(x => x.Code);
Map(x => x.TimeStamp);
References(x => x.Part);
References(x => x.ReferenceRecord);
Map(x => x.Name);
Map(x => x.Code);
Map(x => x.Result);
Map(x => x.Note);
References(x => x.StepRecord);
References(x => x.ReferenceRecord);
}
}
}
+10 -13
View File
@@ -7,18 +7,15 @@ namespace SharedDatabase.Mappings
public ReferenceRecordMap()
{
Id(x => x.Id);
Map(x => x.Code);
Map(x => x.TimeStamp);
Map(x => x.UserName);
Map(x => x.Workplace);
Map(x => x.Result);
References(x => x.POrder);
References(x => x.Workflow)
.Column("Process_id");
References(x => x.Workstep);
HasMany(x => x.Records)
.Cascade.All();
}
Map(x => x.Code1);
Map(x => x.Code2);
Map(x => x.Code3);
Map(x => x.Code4);
Map(x => x.POName);
Map(x => x.Workflow);
Map(x => x.Timestamp);
HasMany(x => x.Records).Cascade.All();
HasMany(x => x.StepRecords).Cascade.All();
}
}
}
+19
View File
@@ -0,0 +1,19 @@
using FluentNHibernate.Mapping;
namespace SharedDatabase.Mappings
{
class StepRecordMap : ClassMap<Entities.StepRecord>
{
public StepRecordMap()
{
Id(x => x.Id);
Map(x => x.Timestamp);
Map(x => x.Workstep);
Map(x => x.Workplace);
Map(x => x.User);
Map(x => x.Result);
References(x => x.ReferenceRecord);
HasMany(x => x.Records).Cascade.All();
}
}
}
+2 -3
View File
@@ -57,7 +57,6 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="BatteryAndFlowtubeInfo.cs" />
<Compile Include="Entities\Batch.cs" />
<Compile Include="Entities\Components.cs" />
<Compile Include="Entities\Event.cs" />
@@ -68,6 +67,7 @@
<Compile Include="Entities\Process.cs" />
<Compile Include="Entities\Record.cs" />
<Compile Include="Entities\ReferenceRecord.cs" />
<Compile Include="Entities\StepRecord.cs" />
<Compile Include="Entities\Subscriber.cs" />
<Compile Include="Entities\TestData.cs" />
<Compile Include="Entities\TestRslt.cs" />
@@ -115,7 +115,6 @@
<DependentUpon>UserManagementDlg.cs</DependentUpon>
</Compile>
<Compile Include="ItemID.cs" />
<Compile Include="ItemSpec.cs" />
<Compile Include="Mappings\BatchMap.cs" />
<Compile Include="Mappings\ComponentsMap.cs" />
<Compile Include="Mappings\EventMap.cs" />
@@ -126,6 +125,7 @@
<Compile Include="Mappings\ProcessMap.cs" />
<Compile Include="Mappings\RecordMap.cs" />
<Compile Include="Mappings\ReferenceRecordMap.cs" />
<Compile Include="Mappings\StepRecordMap.cs" />
<Compile Include="Mappings\SubscriberMap.cs" />
<Compile Include="Mappings\TestDataMap.cs" />
<Compile Include="Mappings\TestRsltMap.cs" />
@@ -157,7 +157,6 @@
<Compile Include="UsersDB.cs" />
<Compile Include="Utils.cs" />
<Compile Include="WMeterRsltItemSpec.cs" />
<Compile Include="WMPart.cs" />
<Compile Include="WPlaceRegistrationMgmt.cs" />
</ItemGroup>
<ItemGroup>
+19 -10
View File
@@ -168,28 +168,37 @@ namespace SharedDatabase
/// <summary>
/// Get process of the last good record with the reference part code equal to 'serialNumber'
/// </summary>
/// Find a reference record of product specified by one of unique S/N-s (code)
/// and get it's workflow and the current order.
/// </summa
/// <param name="session">DB session</param>
/// <param name="serialNumber">Serial number</param>
/// <param name="code">One of unique serial numbers identifying the product</param>
/// <param name="codeIx">1,2,3 or 4</param>
/// <returns>Workflow of the specified part</returns>
public static Process GetWorkflow(ISession session, string serialNumber, out OrderInfo order)
public static string GetWorkflow(ISession session, string code, int codeIx, out string order)
{
order = null;
if (string.IsNullOrEmpty(serialNumber)) return null;
if (string.IsNullOrEmpty(code)) return null;
try
{
/// Read all already existing reference records with Code==pcbNumber, referenceRecords[0] will be the most recent one
var referenceRecords = session.QueryOver<ReferenceRecord>()
.Where(rr => ((rr.Code == serialNumber) && (rr.Result == 0)))
.OrderBy(rr => rr.TimeStamp).Desc
.List();
IQueryOver<ReferenceRecord,ReferenceRecord> query = session.QueryOver<ReferenceRecord>();
switch (codeIx)
{
default:
case 1: query = query.Where(rr => rr.Code1 == code); break;
case 2: query = query.Where(rr => rr.Code2 == code); break;
case 3: query = query.Where(rr => rr.Code3 == code); break;
case 4: query = query.Where(rr => rr.Code4 == code); break;
}
var referenceRecords = query.OrderBy(rr => rr.Timestamp).Desc.List();
if (referenceRecords.Count == 0) return null; /// Returns an empty list if no such ref. record found
order = referenceRecords[0].POrder;
order = referenceRecords[0].POName;
return referenceRecords[0].Workflow;
}
catch
-53
View File
@@ -1,53 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SharedDatabase.Entities;
namespace SharedDatabase
{
public class WMPart
{
public string Name;
public Process Process;
public string OraDBType;
public string Description;
public string Code;
public DateTime TimeStamp;
public sbyte CodeType;
public sbyte CodeForm;
public CodeLocation CodeLocation;
public string UserName;
public string Workplace;
public WMPart(ReferenceRecord rr)
{
Name = rr.Workstep.ReferencePart.Name;
Process = rr.Workflow;
OraDBType = rr.Workstep.ReferencePart.OraDBType;
Description = rr.Workstep.ReferencePart.Description;
Code = rr.Code;
TimeStamp = rr.TimeStamp;
CodeType = rr.Workstep.ReferencePart.CodeType;
CodeForm = rr.Workstep.ReferencePart.CodeForm;
CodeLocation = rr.Workstep.ReferencePart.CodeLocation;
UserName = rr.UserName;
Workplace = rr.Workplace;
}
public WMPart(Record r)
{
Name = r.Part.Name;
Process = r.Part.Workflow;
OraDBType = r.Part.OraDBType;
Description = r.Part.Description;
Code = r.Code;
TimeStamp = r.TimeStamp;
CodeType = r.Part.CodeType;
CodeForm = r.Part.CodeForm;
CodeLocation = r.Part.CodeLocation;
UserName = r.ReferenceRecord.UserName;
Workplace = r.ReferenceRecord.Workplace;
}
}
}
@@ -833,27 +833,27 @@ namespace TBF.Rig.DataEntry.S620
if (passed && !string.IsNullOrEmpty(bodyNrBoxes[wmNr0].Text) && !string.IsNullOrEmpty(serialNrBoxes[wmNr0].Text))
{
///
/// Prepare records
///
ReferenceRecord refRecord = new ReferenceRecord(currentOrder,
currentWorkflow,
currentWStep,
bodyNrBoxes[wmNr0].Text,
GlobalData.GetCurrentUserName(),
workplace,
passed ? 1 : 0);
if (uniqueCodeParts.Count >= 2)
{
refRecord.Records.Add(new Record(uniqueCodeParts[1], refRecord, serialNrBoxes[wmNr0].Text));
}
/////
///// Prepare records
/////
//ReferenceRecord refRecord = new ReferenceRecord(currentOrder,
// currentWorkflow,
// currentWStep,
// bodyNrBoxes[wmNr0].Text,
// 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));
}
//for (int i = 0; i < palety.Count; i++)
//{
// refRecord.Records.Add(new Record(palety[i].Part, refRecord, palety[i].ScannedCode));
//}
TracingDB.SaveRecords(dbSession, refRecord);
//TracingDB.SaveRecords(dbSession, refRecord);
}
}
+24 -118
View File
@@ -298,15 +298,15 @@ namespace TBF.Rig.Output.DB.ProductionTracing
try
{
var refRecords = session.QueryOver<ReferenceRecord>()
.Where(x => (x.POrder == order))
.Where(x => (x.POName == order.POName))
.List();
refRecords.Reverse();
if (dfltOrder != null && dfltWFlow != null)
{
var moreRecords = session.QueryOver<ReferenceRecord>()
.Where(x => (x.POrder == dfltOrder))
.And(x => (x.Workflow == dfltWFlow))
.Where(x => (x.POName == dfltOrder.POName))
.And(x => (x.Workflow == dfltWFlow.Name))
.List();
for (int i = moreRecords.Count - 1; i >= 0; i--) refRecords.Add(moreRecords[i]);
}
@@ -333,7 +333,7 @@ namespace TBF.Rig.Output.DB.ProductionTracing
{
var records = session.QueryOver<Record>()
.JoinQueryOver<ReferenceRecord>(rec => rec.ReferenceRecord)
.Where(rr => rr.POrder.Id == order.Id)
.Where(rr => rr.POName == order.POName)
.List();
records.Reverse();
@@ -341,8 +341,8 @@ namespace TBF.Rig.Output.DB.ProductionTracing
{
var moreRecords = session.QueryOver<Record>()
.JoinQueryOver<ReferenceRecord>(rec => rec.ReferenceRecord)
.Where(rr => (rr.POrder.Id == dfltOrder.Id))
.And(rr => (rr.Workflow.Id == dfltWFlow.Id))
.Where(rr => (rr.POName == dfltOrder.POName))
.And(rr => (rr.Workflow == dfltWFlow.Name))
.List();
for (int i = moreRecords.Count - 1; i >= 0; i--) records.Add(moreRecords[i]);
}
@@ -488,33 +488,16 @@ namespace TBF.Rig.Output.DB.ProductionTracing
bool isAtLeastOneNOK = false;
using (ISession session = SessionFactory.OpenSession())
{
var cOrders = session.QueryOver<OrderInfo>()
.Where(x => x.POName == sampleWM.PurchaseOrder)
.And(x => (x.POState == (sbyte)OrderState.New || x.POState == (sbyte)OrderState.Active))
.List();
if (cOrders.Count < 1)
for (int i = 0; i < waterMeters.Count; i++)
{
cOrders = session.QueryOver<OrderInfo>()
.Where(x => x.POName == "0000001")
.List();
}
Results.Entities.WaterMeter wm = waterMeters[i];
if (cOrders.Count == 1)
{
currentOrder = cOrders[0];
for (int i = 0; i < waterMeters.Count; i++)
if ((wm != null) && !wm.Disabled)
{
Results.Entities.WaterMeter wm = waterMeters[i];
if ((wm != null) && !wm.Disabled)
CheckPreviousRecordOfSingleWM(session, wm);
if (wm.LastRecordIsNok)
{
CheckPreviousRecordOfSingleWM(session, wm, 1);
if (wm.LastRecordIsNok)
{
isAtLeastOneNOK = true;
}
isAtLeastOneNOK = true;
}
}
}
@@ -526,7 +509,7 @@ namespace TBF.Rig.Output.DB.ProductionTracing
return retVal;
}
Retv CheckPreviousRecordOfSingleWM(ISession session, Results.Entities.WaterMeter wm, int sessionId)
Retv CheckPreviousRecordOfSingleWM(ISession session, Results.Entities.WaterMeter wm)
{
if (string.IsNullOrEmpty(wm.SerialNr))
{
@@ -536,100 +519,23 @@ namespace TBF.Rig.Output.DB.ProductionTracing
return Retv.OK;
}
///
/// Get all already existing reference records with Code == wm.SerialNr, refRecords[0] will be the most recent one
///
ReferenceRecord refRecord = null;
Workstep workstep = null;
ProjectionList projections = Projections.ProjectionList();
projections.Add(Projections.Property(() => refRecord.Id)); /// rslt[0] = reference record ID
projections.Add(Projections.Property(() => workstep.Id)); /// rslt[1] = workstep ID
projections.Add(Projections.Property(() => refRecord.Workflow.Id)); /// rslt[2] = process ID
projections.Add(Projections.Property(() => refRecord.TimeStamp)); /// rslt[3] = reference record time stamp
///
/// Get all reference records with Code == SerialNr from all worksteps different from 'Test_bench'
///
IList<object[]> results = session.QueryOver<ReferenceRecord>(() => refRecord)
.Where(rr => (rr.Code == wm.SerialNr))
.JoinQueryOver<Workstep>(rr => rr.Workstep, () => workstep)
.And(ws => (ws.Name != WorkstepName))
.Select(projections)
.List<object[]>();
var refRecords = session.QueryOver<ReferenceRecord>()
.Where(rr => (rr.Code1 == wm.SerialNr))
.List();
if (results.Count == 0)
if (refRecords.Count == 0)
{
/// No records found
wm.ProcessId = 0;
wm.LastRecordIsNok = true; /// NOK
///
return Retv.OK;
}
///
/// Get processId of the last record
///
int processId = 0;
DateTime lastTimeStamp = DateTime.MinValue;
foreach (var rslt in results)
{
if (DateTime.Compare((DateTime)rslt[3], lastTimeStamp) > 0)
{
lastTimeStamp = (DateTime)rslt[3];
processId = (int)rslt[2];
}
}
if (processId == 0) return Retv.Error; /// This should never happen
if ((currentWorkflow == null) || (currentWorkflow.Id != processId))
{
///
/// Process changed ==> update currentProcess / currentWorkstep / verifiedWorkstep / verifiedPart / verifyReferencePart
///
var processes = session.QueryOver<Process>()
.Where(p => (p.Id == processId))
.List();
if (processes.Count != 1) return Retv.Error;
IList<Workstep> worksteps = session.QueryOver<Workstep>()
.Where(ws => (ws.Workflow == processes[0]))
.And( ws => (ws.Name == WorkstepName))
.List();
if (worksteps.Count != 1) return Retv.Error;
SharedDatabase.ScanVerificationInfo info;
///
if (null == (info = SharedDatabase.TracingDB.AnalyzeProcess(session, processes[0], worksteps[0])))
{
return Retv.Error; /// Unable to
}
///
currentWorkflow = processes[0];
currentWorkstep = worksteps[0];
verifiedWorkstep = info.Workstep;
verifiedPart = info.Part;
verifyReferencePart = info.VerifyReferencePart;
}
wm.ProcessId = currentWorkflow.Id;
wm.LastRecordIsNok = true; /// NOK (=default if no matching record found)
foreach (var rslt in results)
{
if ((verifiedWorkstep.Id == (int)rslt[1]) && (processId == (int)rslt[2]))
{
/// This record fits verification requirements
wm.LastRecordIsNok = false; /// OK
break;
}
}
wm.ProcessId = 0;
wm.LastRecordIsNok = false; /// NOK (=default if no matching record found)
return Retv.OK;
}
@@ -724,11 +630,11 @@ namespace TBF.Rig.Output.DB.ProductionTracing
/// <param name="wm">Watermeter entity</param>
void SaveSingleWM2DB(ISession session, OrderInfo order, Results.Entities.WaterMeter wm, Process workflow, Workstep workstep)
{
session.SaveOrUpdate(new ReferenceRecord(order, workflow, workstep,
wm.SerialNr,
GlobalData.CurrentUser.UserName,
workplace,
wm.Passed ? 0 : 1));
//session.SaveOrUpdate(new ReferenceRecord(order, workflow, workstep,
// wm.SerialNr,
// GlobalData.CurrentUser.UserName,
// workplace,
// wm.Passed ? 0 : 1));
}
}
}
@@ -525,7 +525,7 @@ namespace TBF.Rig.TestMethods.S640Communication
if ((rec = records.FirstOrDefault(x => x.Code == pcbNumber)) != null &&
(refRec = refRecords.FirstOrDefault(x => x.Id == rec.ReferenceRecord.Id)) != null)
{
serialNumbers[i].Text = refRec.Code;
serialNumbers[i].Text = refRec.Code1;
}
else
{
+2 -25
View File
@@ -559,32 +559,9 @@ namespace TBF.UI.ResultsMI
using (ISession session = SharedDatabase.TracingDB.SessionFactory.OpenSession())
{
IList<ReferenceRecord> refRecords = session.QueryOver<ReferenceRecord>()
.Where(x => (x.Code == wm.SerialNr))
.OrderBy(x => x.TimeStamp).Desc
.Where(x => (x.Code1 == wm.SerialNr))
.OrderBy(x => x.Timestamp).Desc
.List();
for (int i = 0; i < refRecords.Count; i++)
{
ReferenceRecord refR = refRecords[i];
if ((refR.Records != null) && (refR.Records.Count > 0))
{
/// Reference record has additional records/parts (i.e. it is PCB assembly workflow step)
///
foreach (var rec in refR.Records)
{
if (!string.IsNullOrEmpty(rec.Part.OraDBType) && rec.Part.OraDBType.ToLower().Contains("flowtube"))
{
/// rec.Part is a flowtube
///
IList<ReferenceRecord> flowtubeRRs = session.QueryOver<ReferenceRecord>()
.Where(x => (x.Code == rec.Code))
.OrderBy(x => x.TimeStamp).Desc
.List();
foreach (var rr in flowtubeRRs) refRecords.Add(rr);
break;
}
}
}
}
new MoreWMResultsDlg(wm, refRecords).ShowDialog();
}
+13 -7
View File
@@ -19,16 +19,22 @@ namespace WorkflowConfigurator.Forms
Text = string.Format(Strings._0_records, refRecords.Count);
recordsListView.Columns.Add("Time", 120);
recordsListView.Columns.Add("Workplace", 100);
recordsListView.Columns.Add("Part", 80);
recordsListView.Columns.Add("Code", 200);
recordsListView.Columns.Add("Code1", 100);
recordsListView.Columns.Add("Code2", 100);
recordsListView.Columns.Add("Code3", 100);
recordsListView.Columns.Add("Code4", 100);
recordsListView.Columns.Add("Order", 70);
recordsListView.Columns.Add("Workflow", 200);
foreach (var rr in refRecords)
{
recordsListView.Items.Add(new ListViewItem(new string[] { string.Format("{0:dd.MM.yyyy HH:mm:ss}", rr.TimeStamp),
rr.Workplace,
rr.Workstep.ReferencePart.Name,
rr.Code }));
recordsListView.Items.Add(new ListViewItem(new string[] { string.Format("{0:dd.MM.yyyy HH:mm:ss}", rr.Timestamp),
(rr.Code1 != null) ? rr.Code1 : "<none>",
(rr.Code2 != null) ? rr.Code2 : "<none>",
(rr.Code3 != null) ? rr.Code3 : "<none>",
(rr.Code4 != null) ? rr.Code4 : "<none>",
(rr.POName != null) ? rr.POName : "<none>",
(rr.Workflow != null) ? rr.Workflow : "<none>"}));
}
}
}
@@ -579,7 +579,6 @@ namespace WorkflowConfigurator.UserControls
{
case Reason.PrepareBtn:
if (!GetAccessToStateChange(false)) return; /// Login if unsufficient access right
if (!DeleteTestRecords(true)) return; /// Always delete records created while testing
UpdateLockState(unlocked, unlocked);
Process.ReleaseStatus = ReleaseStatus.In_preparation;
break;
@@ -592,7 +591,6 @@ namespace WorkflowConfigurator.UserControls
case Reason.ReleaseBtn:
if (!GetAccessToStateChange(true)) return; /// Obligatory login when releasing a process to production
if (!DeleteTestRecords(false)) return; /// Optionally delete records created while testing
UpdateLockState(false, false);
Process.ReleaseStatus = ReleaseStatus.Released;
Process.ApprovedBy = GlobalData.GetCurrentUserName();
@@ -635,58 +633,6 @@ namespace WorkflowConfigurator.UserControls
}
}
/// <summary>
/// Delete records created while testing when swithing either to 'InPreparation' or 'Released' state.
/// </summary>
/// <param name="deleteObligatory">true = bypassing deletion is not possible</param>
/// <returns>true when successful, false when failed or aborted by user</returns>
bool DeleteTestRecords(bool deleteObligatory)
{
if (SharedDatabase.TracingDB.Session == null)
{
MessageBox.Show(Strings.Deleting_records_failed, Strings.Error, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
return false;
}
DialogResult dr = deleteObligatory
? MessageBox.Show(Strings.Records_created_while_testing_will_be_deleted, Strings.Warning, MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation)
: MessageBox.Show(Strings.Do_you_want_to_delete_records_created_while_testing_QM, Strings.Warning, MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (dr == DialogResult.No)
{
return true; /// User decided not to delete records => OK, continue
}
else if (dr == DialogResult.OK || dr == DialogResult.Yes)
{
new Thread(() => Application.Run(new ModelessForm(Strings.Deleting_records))).Start();
ITransaction transaction = SharedDatabase.TracingDB.Session.BeginTransaction();
try
{
IList<ReferenceRecord> refRecords = SharedDatabase.TracingDB.Session.QueryOver<ReferenceRecord>()
.Where(x => (x.Workflow == Process))
.List();
foreach (var rr in refRecords) SharedDatabase.TracingDB.Session.Delete(rr);
transaction.Commit();
ModelessForm.CloseForm();
return true; /// Records successfully deleted
}
catch (Exception)
{
transaction.Rollback();
ModelessForm.CloseForm();
MessageBox.Show(Strings.Deleting_records_failed, Strings.Error, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
return false; /// Deleting records failed
}
}
else
{
return false; /// Obligatory deletion was cancelled
}
}
public void ImportParts()
{
partsCtrl.ImportParts();
@@ -781,7 +727,7 @@ namespace WorkflowConfigurator.UserControls
{
if (SharedDatabase.TracingDB.Session != null)
{
IList<ReferenceRecord> refRecords = SharedDatabase.TracingDB.Session.QueryOver<ReferenceRecord>().Where(x => (x.Workflow == Process)).List();
IList<ReferenceRecord> refRecords = SharedDatabase.TracingDB.Session.QueryOver<ReferenceRecord>().Where(x => (x.Workflow == Process.Name)).List();
new Forms.ShowRecordsForm(refRecords).ShowDialog();
}
}
+2 -2
View File
@@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("3.0.13.0")]
[assembly: AssemblyFileVersion("3.0.13.0")]
[assembly: AssemblyVersion("3.1.14.0")]
[assembly: AssemblyFileVersion("3.1.14.0")]
+133 -168
View File
@@ -371,23 +371,14 @@ namespace Workplace
try
{
var pieces = dbSession.QueryOver<ReferenceRecord>()
.Where(x => x.POrder == CurrentOrder)
.And(x => x.Workflow == CurrentWorkflow)
.And(x => x.Workstep == CurrentWorkstep)
.And(x => x.Result == 0)
.OrderBy(x => x.Code).Asc
.Where(x => x.POName == CurrentOrder.POName)
.And(x => x.Workflow == CurrentWorkflow.Name)
.List<ReferenceRecord>();
int piecesCountWithUniqueCode = Math.Min(1, pieces.Count);
for (int i = 1; i < pieces.Count; i++)
{
if (pieces[i].Code != pieces[i - 1].Code) piecesCountWithUniqueCode++;
}
completedGroupBox.Visible = true;
completedLabel.Text = piecesCountWithUniqueCode.ToString();
completedLabel.Text = pieces.Count.ToString();
bool targetReached = piecesCountWithUniqueCode >= CurrentOrder.PiecesCount;
bool targetReached = pieces.Count >= CurrentOrder.PiecesCount;
completedGroupBox.BackColor = targetReached ? Color.Green : SystemColors.Control;
completedGroupBox.ForeColor = targetReached ? Color.White : SystemColors.ControlText;
return targetReached;
@@ -1050,109 +1041,34 @@ namespace Workplace
}
}
bool verificationPassed = false;
int codeIx = 1;
if (Program.LocalSettings.SearchOtherProcessFlowtube && verifyReferencePart)
///
/// Find reference records with s/n of the part to be verified
///
IQueryOver<ReferenceRecord, ReferenceRecord> query = dbSession.QueryOver<ReferenceRecord>();
switch (codeIx)
{
///
/// Find reference records with s/n of the part to be verified (mostly a flowtube)
///
IList<ReferenceRecord> refRecords = dbSession.QueryOver<ReferenceRecord>()
.Where(rr => ((rr.Code == verifiedCode) && (rr.Result == 0)))
.OrderBy(rr => rr.TimeStamp).Desc
.List();
ReferenceRecord oriRefRecord = null;
foreach (var rr in refRecords)
default:
case 1: query = query.Where(rr => (rr.Code1 == verifiedCode)); break;
case 2: query = query.Where(rr => (rr.Code2 == verifiedCode)); break;
case 3: query = query.Where(rr => (rr.Code3 == verifiedCode)); break;
case 4: query = query.Where(rr => (rr.Code4 == verifiedCode)); break;
}
var refRecords = query.OrderBy(rr => rr.Timestamp).Desc.List();
bool verificationPassed = false;
if (refRecords.Count > 0 && refRecords[0].StepRecords != null)
{
foreach (var r in refRecords[0].StepRecords)
{
if (rr.Workstep.Name == verifiedWorkstep.Name)
if (r.Workstep == verifiedWorkstep.Name)
{
/// This is the last good record from a verified workstep
oriRefRecord = rr;
verificationPassed = true;
break;
}
}
if (oriRefRecord != null)
{
verificationPassed = true;
/// Create new records corresponding to refRecords with process==oriRefRecord.Process
ITransaction transaction = dbSession.BeginTransaction();
try
{
/// Create new records
foreach (var cpws in workstepsOfTheCurrentWorkflow)
{
if (cpws == CurrentWorkstep) break; /// Quit when reaching currentWorkstep, create only records for previous worksteps
foreach (var rr in refRecords)
{
if ((rr.Workflow == oriRefRecord.Workflow) && (rr.Workstep.Name == cpws.Name))
{
/// Create a new ref.record
ReferenceRecord newRefRecord = new ReferenceRecord(CurrentOrder, CurrentWorkflow, cpws, verifiedCode, rr.UserName, rr.Workplace, rr.Result);
newRefRecord.TimeStamp = rr.TimeStamp;
foreach (var part in cpws.Parts)
{
int sapNr = -1;
int.TryParse(part.Name, out sapNr);
string foundCode = string.Empty;
foreach (var rec in rr.Records)
{
int oriSapNr;
if (rec.Part.Name == part.Name || (int.TryParse(rec.Part.Name, out oriSapNr) && oriSapNr == sapNr))
{
/// SAP number is the same => use the scanned code
foundCode = rec.Code;
}
}
newRefRecord.Records.Add(new Record(part, newRefRecord, foundCode));
}
///
/// Save and delete records to/from MySQL DB
///
if (!(CurrentWorkflow.ReleaseStatus == ReleaseStatus.ToBeApproved))
{
/// Not in testing mode => delete original records being inherited
TracingDB.DeleteRecords(dbSession, rr);
}
/// Save new inherited records
TracingDB.SaveRecords(dbSession, newRefRecord);
}
}
}
transaction.Commit();
}
catch (Exception exc)
{
log.ErrorFormat("MySQL database transaction rolled back, data not comitted: {0}", exc.Message);
transaction.Rollback();
}
}
}
else if (verifyReferencePart)
{
IQueryOver<ReferenceRecord, Workstep> query = dbSession.QueryOver<ReferenceRecord>()
.Where(rr => ((rr.Code == verifiedCode) && (rr.Result == 0)))
.And(rr => rr.Workstep == verifiedWorkstep)
.JoinQueryOver<Workstep>(rr => rr.Workstep)
.Where(ws => ws.ReferencePart.Id == verifiedPart.Id);
IList<ReferenceRecord> refRecords = query.List();
if (refRecords.Count > 0) verificationPassed = true;
}
else
{
IList<Record> records = dbSession.QueryOver<Record>()
.Where(rec => rec.Code == verifiedCode)
.And(rec => rec.Part == verifiedPart)
.List();
if (records.Count > 0) verificationPassed = true;
}
if (!verificationPassed)
@@ -1206,90 +1122,105 @@ namespace Workplace
return;
}
///
/// Prepare records
///
ReferenceRecord refRecord = new ReferenceRecord(CurrentOrder,
CurrentWorkflow,
CurrentWorkstep,
(CurrentWorkstep.ReferencePart != null) ? komponenty[0].ScannedCode : null,
workerTextBox.Text,
workplaceTextBox.Text,
failedCheckBox.Checked ? 1 : 0);
int firstNoRefCompIx = (CurrentWorkstep.ReferencePart != null) ? 1 : 0;
if (komponenty[0] is IDoubleCheckItem)
{
refRecord.Records.Add(new Record((komponenty[0] as IDoubleCheckItem).Part2, refRecord,
(komponenty[0] as IDoubleCheckItem).ScannedCode2));
}
for (int i = firstNoRefCompIx; i < komponenty.Count; i++)
{
refRecord.Records.Add(new Record(komponenty[i].Part, refRecord,
komponenty[i].ScannedCode));
if (komponenty[i] is IDoubleCheckItem)
{
refRecord.Records.Add(new Record((komponenty[i] as IDoubleCheckItem).Part2, refRecord,
(komponenty[i] as IDoubleCheckItem).ScannedCode2));
}
}
for (int i = 0; i < palety.Count; i++)
{
refRecord.Records.Add(new Record(palety[i].Part, refRecord, palety[i].ScannedCode));
}
bool wasAlreadyTested = false;
bool componentsSaved = true;
///
/// Save records to MySQL
///
int result = 0; /// OK (default)
bool wasAlreadyTested = false;
bool componentsSaved = true;
bool successfullySaved = false;
///
ITransaction transaction = dbSession.BeginTransaction();
OrderInfo oi = new OrderInfo();
try
{
var snGenerator = komponenty[0] as CheckItems.SNGeneratorPrinter;
CheckItems.SNGeneratorPrinter snGenerator = (komponenty[0] as CheckItems.SNGeneratorPrinter); /// null when there is no S/N generator
///
/// Handle serial number generators
///
if (snGenerator != null && komponenty[0].Part.CodeForm == (sbyte)CodeForm.SNGenerator)
{
string generatedCode;
OrderProgress orderInfoState;
///
if (CurrentOrder != null)
if (CurrentOrder == null)
{
orderInfoState = snGenerator.NegotiateSerialNr(CurrentOrder, CurrentWorkflow, CurrentWorkstep,
out generatedCode, true, dbSession);
}
else
{
komponenty[0].ScannedCode = generatedCode = "ERROR";
/// The 1st item is a S/N generator but no order is selected ==> Error
komponenty[0].ScannedCode = "ERROR";
throw new Exception("No order selected");
}
if (orderInfoState == OrderProgress.InProgress)
///
/// Negotiate and update the generated serial number
///
string generatedCode;
var orderInfoState = snGenerator.NegotiateSerialNr(CurrentOrder, CurrentWorkflow, CurrentWorkstep,
out generatedCode, true, dbSession);
if (orderInfoState == OrderProgress.InProgress || orderInfoState == OrderProgress.Overproduction)
{
refRecord.Code = komponenty[0].ScannedCode = generatedCode;
}
else if (orderInfoState == OrderProgress.Overproduction)
{
refRecord.Code = komponenty[0].ScannedCode = generatedCode;
komponenty[0].ScannedCode = generatedCode;
}
else if (orderInfoState == OrderProgress.Completed)
{
komponenty[0].ScannedCode = "END";
throw new Exception("END");
}
else
else //if (orderInfoState == OrderProgress.Error)
{
/// Do nothing, possibly no order is selected
/// An unexpected error
throw new Exception("No order selected");
}
}
TracingDB.SaveRecords(dbSession, refRecord);
///
/// Select or create a reference record
///
var refRecords = dbSession.QueryOver<ReferenceRecord>()
.Where(x => x.Code1 == komponenty[0].ScannedCode)
.List();
/// Handle or prevent reference record duplicity
if (refRecords.Count > 1) throw new Exception("Unexpected error: two identical codes in the database");
else if (snGenerator != null && refRecords.Count == 1) throw new Exception("A duplicit code was generated");
ReferenceRecord refRecord = (refRecords.Count == 1) ? refRecords[0]
: new ReferenceRecord(CurrentOrder.POName, CurrentWorkflow.Name, komponenty[0].ScannedCode);
/// Handle case of a double check item - update refRecord.Code2
if (komponenty[0] is IDoubleCheckItem)
{
refRecord.Code2 = (komponenty[0] as IDoubleCheckItem).ScannedCode2;
}
/// Prepare new records
var records = new List<Record>();
var stepRecord = PrepareRecords(refRecord, result, records);
/// De-referene existing recors with the same part name, a more recent record exists now
foreach (var oriRecord in refRecord.Records)
{
var overridingRecord = records.FirstOrDefault(x => x.Name == oriRecord.Name);
if (overridingRecord != null)
{
oriRecord.ReferenceRecord = null;
dbSession.SaveOrUpdate(oriRecord);
}
}
/// Update the reference record
refRecord.StepRecords.Add(stepRecord);
foreach (var rcrd in records) refRecord.Records.Add(rcrd);
if (stepRecord.Timestamp > refRecord.Timestamp) refRecord.Timestamp = stepRecord.Timestamp;
dbSession.SaveOrUpdate(refRecord);
log.InfoFormat(" ReferenceRecord : {0}", refRecord);
/// Save new records
dbSession.SaveOrUpdate(stepRecord);
log.InfoFormat(" StepRecord : {0}", stepRecord);
foreach (var rcrd in records)
{
dbSession.SaveOrUpdate(rcrd);
log.InfoFormat(" Record : {0}", rcrd);
}
transaction.Commit();
successfullySaved = true;
}
@@ -1370,6 +1301,41 @@ namespace Workplace
}
}
/// <summary>
/// Prepare records and a step record with scanned/generated/collected information
/// </summary>
/// <param name="refRecord">Reference record</param>
/// <param name="result">Result: 0=OK, otherwise a non-zero error code</param>
/// <param name="records">List of records to be updated (initially an empty list)</param>
/// <returns>Step record</returns>
StepRecord PrepareRecords(ReferenceRecord refRecord, int result, IList<Record> records)
{
var stepRecord = new StepRecord(refRecord, CurrentWorkstep.Name, workplaceTextBox.Text, workerTextBox.Text, result);
int firstNoRefCompIx = (CurrentWorkstep.ReferencePart == null) ? 0 : (komponenty[0] is IDoubleCheckItem) ? 2 : 1;
for (int i = firstNoRefCompIx; i < komponenty.Count; i++)
{
if (komponenty[i] is CheckItems.S640Stream)
{
/// eRegister number from data stream ... update refRecord.Code2
refRecord.Code2 = komponenty[i].ScannedCode;
}
else
{
records.Add(new Record(refRecord, stepRecord, komponenty[i].Part.Name, komponenty[i].ScannedCode,
result, komponenty[i].Part.OraDBType));
}
}
for (int i = 0; i < palety.Count; i++)
{
records.Add(new Record(refRecord, stepRecord, palety[i].Part.Name, palety[i].ScannedCode,
result, komponenty[i].Part.OraDBType));
}
return stepRecord;
}
void SetErrorFlag(PartError errorCode, Color backColor)
{
if (errorFlag == PartError.None)
@@ -1400,7 +1366,6 @@ namespace Workplace
ResetErrorFlag();
}
public void OnFocusPressed(object sender, FocusPressedEventArgs data)
{
ResetIdleTime();