Changes for 620 meters, OrderInfo is updated in DataEntry.S620 form session.

This commit is contained in:
Milan Hanajik
2023-06-25 22:47:40 +02:00
parent 4aa7c22014
commit fb6e6f5a5e
3 changed files with 125 additions and 118 deletions
+2 -41
View File
@@ -132,49 +132,12 @@ namespace TBF.Rig.DataEntry.S620
delegate void EntryFormDlgt(EntryForm myRef);
///
void UpdateOrderWorkflow(out string order, out string workflow)
{
if (ProcessData.OrderInfo is SharedDatabase.Entities.OrderInfo && ProcessData.TracingDB != null)
{
try
{
ISession session = ProcessData.TracingDB.SessionFactory.OpenSession();
order = Program.MainWnd.SelectedProcedure.OrderInfo.POName;
var list = session.QueryOver<SharedDatabase.Entities.OrderInfo>()
.Where(x => (x.POName == Program.MainWnd.SelectedProcedure.OrderInfo.POName))
.List();
ProcessData.OrderInfo = (list.Count == 1) ? list[0] : null;
workflow = (list.Count == 1) ? list[0].Workflow : null;
ProcessData.WorkflowSummary = SharedDatabase.WorkflowSummary.ReadFromDB(workflow, "test", session);
session.Close();
}
catch (Exception exc)
{
order = string.Empty;
workflow = string.Empty;
ProcessData.OrderInfo = null;
ProcessData.WorkflowSummary = null;
log.ErrorFormat("Unable to load order, workflow or workstep: {0}", exc.Message);
}
}
else
{
order = string.Empty;
workflow = string.Empty;
ProcessData.OrderInfo = null;
ProcessData.WorkflowSummary = null;
}
}
///
void OnCycleStart(EntryForm myRef)
{
if (entryFormCfg.ProductionTracing)
{
string order, workflow;
UpdateOrderWorkflow(out order, out workflow);
myRef.modelessDlg = new FormForMechanicalMetersWithTracing(waterMeters, entryFormCfg.MaxWMsCount, entryFormCfg.CloseButton, false,
true, entryFormCfg.OrdersFromProdTracing, order, workflow);
true, entryFormCfg.OrdersFromProdTracing);
}
else
{
@@ -189,10 +152,8 @@ namespace TBF.Rig.DataEntry.S620
{
if (entryFormCfg.ProductionTracing)
{
string order, workflow;
UpdateOrderWorkflow(out order, out workflow);
myRef.modelessDlg = new FormForMechanicalMetersWithTracing(waterMeters, entryFormCfg.MaxWMsCount, entryFormCfg.CloseButton, true,
true, entryFormCfg.OrdersFromProdTracing, order, workflow);
true, entryFormCfg.OrdersFromProdTracing);
}
else
{
@@ -17,6 +17,8 @@ using SharedDatabase;
using SharedDatabase.Entities;
using TBF.Rig.Sequences;
using TBF.Resources;
using NHibernate.Criterion;
using Renci.SshNet;
namespace TBF.Rig.DataEntry.S620
{
@@ -226,7 +228,7 @@ namespace TBF.Rig.DataEntry.S620
/// Constructor
/// </summary>
/// <param name="waterMetersCount">Number of text boxes for serial numbers</param>
public FormForMechanicalMetersWithTracing(IList<Results.Entities.WaterMeter> waterMeters, int maxWMsCount, char closeButton, bool atTheEnd, bool withProductionTracing = true, bool ordersFromProdTracing = false, string purchaseOrder = null, string workflow = null)
public FormForMechanicalMetersWithTracing(IList<Results.Entities.WaterMeter> waterMeters, int maxWMsCount, char closeButton, bool atTheEnd, bool withProductionTracing = true, bool ordersFromProdTracing = false)
: this()
{
this.waterMeters = waterMeters;
@@ -236,8 +238,6 @@ namespace TBF.Rig.DataEntry.S620
this.atTheEnd = atTheEnd;
this.withProductionTracing = withProductionTracing;
this.ordersFromProdTracing = ordersFromProdTracing;
this.preSelectedPurchaseOrder = purchaseOrder;
this.preSelectedWorkflow = workflow;
bodyNrText = new string[waterMeters.Count];
assignedSerialNr = new int[waterMeters.Count];
@@ -257,11 +257,11 @@ namespace TBF.Rig.DataEntry.S620
textBoxesCount = Math.Min(textBoxesCount, wmsCount);
if (SharedDatabase.TracingDB.SessionFactory != null)
if (TracingDB.SessionFactory != null)
{
try
{
dbSession = SharedDatabase.TracingDB.SessionFactory.OpenSession();
dbSession = TracingDB.SessionFactory.OpenSession();
}
catch (Exception exc)
{
@@ -270,9 +270,14 @@ namespace TBF.Rig.DataEntry.S620
Strings.Error,
MessageBoxButtons.OK,
MessageBoxIcon.Exclamation);
dbSession = null;
}
if (workflows.Count == 0 && dbSession != null)
if (dbSession != null)
{
UpdateOrderWorkflow(dbSession, out preSelectedPurchaseOrder, out preSelectedWorkflow);
if (withProductionTracing && workflows.Count == 0)
{
workflows = ReadReleasedActiveProcesses(dbSession);
if (workflows == null)
@@ -285,6 +290,7 @@ namespace TBF.Rig.DataEntry.S620
}
}
}
}
BarcodeReceivedHandler += delegate(object sndr, BarcodeReceivedEventArgs args)
{
@@ -412,6 +418,43 @@ namespace TBF.Rig.DataEntry.S620
//clearButton.Text = Strings.ClearBtnText;
}
void UpdateOrderWorkflow(ISession session, out string orderName, out string workflowName)
{
if (ProcessData.OrderInfo is OrderInfo && ProcessData.TracingDB != null)
{
try
{
orderName = Program.MainWnd.SelectedProcedure.OrderInfo.POName;
var list = session.QueryOver<OrderInfo>()
.Where(x => (x.POName == Program.MainWnd.SelectedProcedure.OrderInfo.POName))
.List();
ProcessData.OrderInfo = (list.Count == 1) ? list[0] : null;
workflowName = (list.Count == 1) ? list[0].Workflow : null;
ProcessData.WorkflowSummary = WorkflowSummary.ReadFromDB(workflowName, "test", session);
log.WarnFormat("Pre-selected order={0}, pre-selected workflow={1}",
(ProcessData.OrderInfo != null) ? ProcessData.OrderInfo.POName : "<none>",
!string.IsNullOrEmpty(workflowName) ? workflowName : "<none>");
}
catch (Exception exc)
{
orderName = string.Empty;
workflowName = string.Empty;
ProcessData.OrderInfo = null;
ProcessData.WorkflowSummary = null;
log.ErrorFormat("Unable to load order, workflow or workstep: {0}", exc.Message);
}
}
else
{
orderName = string.Empty;
workflowName = string.Empty;
ProcessData.OrderInfo = null;
ProcessData.WorkflowSummary = null;
}
}
/// <summary>
/// Assign serial numbers
/// </summary>assigned, false = no order information or DB connection</returns>
@@ -812,10 +855,36 @@ namespace TBF.Rig.DataEntry.S620
{
ProcessData.OrderInfo.CurrentPcsCount = lastProducedPcsCount;
ProcessData.OrderInfo.CurrentSN = lastAssignedSN;
if (ProcessData.OrderInfo is OrderInfo)
{
try
{
dbSession.SaveOrUpdate(ProcessData.OrderInfo as OrderInfo);
dbSession.Flush();
log.WarnFormat("Order={0} CurrentPcsCount={1} CurrentSN={2} CurrentRA={3}",
ProcessData.OrderInfo.POName, ProcessData.OrderInfo.CurrentPcsCount,
ProcessData.OrderInfo.CurrentSN, ProcessData.OrderInfo.CurrentRA);
}
catch (Exception ex)
{
log.ErrorFormat("Failed to update OrderInfo.CurrentSN... : {0}", ex.Message);
}
}
else if (ProcessData.OrderInfo is Output.DB.SensusOracle.OrderDetails)
{
// TODO
}
}
if (atTheEnd && withProductionTracing)
{
//SaveProductionTracingRecords(); /// TODO
//dbSession.Flush();
}
if (atTheEnd) UiBridge.Bridge.OnTestCompleted(this, new UiBridge.TestCompletedEventArgs(string.Empty, null));
completed = true;
Close();
@@ -825,8 +894,6 @@ namespace TBF.Rig.DataEntry.S620
/// Not used now
/// </summary>
private void SaveProductionTracingRecords()
{
if (atTheEnd)
{
///
/// Save records to MySQL
@@ -873,7 +940,6 @@ namespace TBF.Rig.DataEntry.S620
mysqlTransaction.Rollback();
}
}
}
/// <summary>
/// Check for uniqueness of test in an array of TextBox-es
@@ -1657,9 +1723,10 @@ namespace TBF.Rig.DataEntry.S620
Program.LocalSettings.LastWStep = currentWStep.Name;
}
Program.LocalSettings.Save();
//wplaceRegistration.UnregisterWorkplace(dbSession);
if (dbSession != null && dbSession.IsOpen)
{
dbSession.Close();
}
}
#region Color flash and beep
@@ -488,27 +488,6 @@ namespace TBF.Rig.Output.DB.ProductionTracing
session = SessionFactory.OpenSession();
transaction = session.BeginTransaction();
var reloadedOrder = session.QueryOver<OrderInfo>()
.Where(x => x.POName == order.POName)
.List();
if (reloadedOrder.Count == 1)
{
reloadedOrder[0].CurrentPcsCount = order.CurrentPcsCount;
reloadedOrder[0].CurrentSN = order.CurrentSN;
reloadedOrder[0].CurrentRA = order.CurrentRA;
if (order.CurrentPcsCount > 0)
{
reloadedOrder[0].POState = (sbyte)OrderState.Active;
}
session.SaveOrUpdate(reloadedOrder[0]);
log.WarnFormat("Order={0} CurrentPcsCount={1} CurrentSN={2} CurrentRA={3}",
order.POName, order.CurrentPcsCount, order.CurrentSN, order.CurrentRA);
}
else
{
log.ErrorFormat("Unexpected reloadedOrder.Count == {0} in SaveTracingRecords()", reloadedOrder.Count);
}
string workplace = (ProcessData.BenchInfo != null) ? ProcessData.BenchInfo.TestBenchName : "TestBench";
int writtenRecordsCount = 0;
foreach (var wm in batch.WaterMeters)