diff --git a/TBF/Rig/DataEntry/S620/EntryForm.cs b/TBF/Rig/DataEntry/S620/EntryForm.cs index 7fd06bf80..66f501368 100644 --- a/TBF/Rig/DataEntry/S620/EntryForm.cs +++ b/TBF/Rig/DataEntry/S620/EntryForm.cs @@ -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() - .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 { diff --git a/TBF/Rig/DataEntry/S620/FormForMechanicalMetersWithTracing.cs b/TBF/Rig/DataEntry/S620/FormForMechanicalMetersWithTracing.cs index 0cc3804f8..41ff9d1bc 100644 --- a/TBF/Rig/DataEntry/S620/FormForMechanicalMetersWithTracing.cs +++ b/TBF/Rig/DataEntry/S620/FormForMechanicalMetersWithTracing.cs @@ -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 /// /// Number of text boxes for serial numbers - public FormForMechanicalMetersWithTracing(IList waterMeters, int maxWMsCount, char closeButton, bool atTheEnd, bool withProductionTracing = true, bool ordersFromProdTracing = false, string purchaseOrder = null, string workflow = null) + public FormForMechanicalMetersWithTracing(IList 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,18 +270,24 @@ namespace TBF.Rig.DataEntry.S620 Strings.Error, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); + dbSession = null; } - if (workflows.Count == 0 && dbSession != null) + if (dbSession != null) { - workflows = ReadReleasedActiveProcesses(dbSession); - if (workflows == null) + UpdateOrderWorkflow(dbSession, out preSelectedPurchaseOrder, out preSelectedWorkflow); + + if (withProductionTracing && workflows.Count == 0) { - MessageBox.Show(Strings.Reading_from_the_production_tracing_DB_failed, - Strings.Error, - MessageBoxButtons.OK, - MessageBoxIcon.Exclamation); - workflows = new List(); + 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(); + } } } } @@ -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() + .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 : "", + !string.IsNullOrEmpty(workflowName) ? workflowName : ""); + } + 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; + } + } + /// /// Assign serial numbers /// assigned, false = no order information or DB connection @@ -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(); + } - //SaveProductionTracingRecords(); /// TODO + if (atTheEnd) UiBridge.Bridge.OnTestCompleted(this, new UiBridge.TestCompletedEventArgs(string.Empty, null)); completed = true; Close(); @@ -826,52 +895,49 @@ namespace TBF.Rig.DataEntry.S620 /// private void SaveProductionTracingRecords() { - if (atTheEnd) + /// + /// Save records to MySQL + /// + string workplace = TBF.Rig.Sequences.ProcessData.BenchInfo.TestBenchName; + ITransaction mysqlTransaction = dbSession.BeginTransaction(); + try { - /// - /// Save records to MySQL - /// - string workplace = TBF.Rig.Sequences.ProcessData.BenchInfo.TestBenchName; - ITransaction mysqlTransaction = dbSession.BeginTransaction(); - try + for (int wmNr0 = 0; wmNr0 < textBoxesCount; wmNr0++) { - for (int wmNr0 = 0; wmNr0 < textBoxesCount; wmNr0++) + bool passed = waterMeters[wmNr0].Passed; + + if (passed && !string.IsNullOrEmpty(bodyNrBoxes[wmNr0].Text) && !string.IsNullOrEmpty(serialNrBoxes[wmNr0].Text)) { - bool passed = waterMeters[wmNr0].Passed; + ///// + ///// 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)); + //} - 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)); - //} + //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); } + } - mysqlTransaction.Commit(); - } - catch (Exception exc) - { - log.ErrorFormat("MySQL database transaction rolled back, data not comitted: {0}", exc.Message); - mysqlTransaction.Rollback(); - } + mysqlTransaction.Commit(); + } + catch (Exception exc) + { + log.ErrorFormat("MySQL database transaction rolled back, data not comitted: {0}", exc.Message); + mysqlTransaction.Rollback(); } } @@ -1656,10 +1722,11 @@ 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 diff --git a/TBF/Rig/Output/DB/ProductionTracing/Tracing.cs b/TBF/Rig/Output/DB/ProductionTracing/Tracing.cs index d688e5e19..0603b9d49 100644 --- a/TBF/Rig/Output/DB/ProductionTracing/Tracing.cs +++ b/TBF/Rig/Output/DB/ProductionTracing/Tracing.cs @@ -488,27 +488,6 @@ namespace TBF.Rig.Output.DB.ProductionTracing session = SessionFactory.OpenSession(); transaction = session.BeginTransaction(); - var reloadedOrder = session.QueryOver() - .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)