From 1c5bf76bb306a6c242a2d89136735334920ba053 Mon Sep 17 00:00:00 2001 From: Milan Hanajik Date: Mon, 11 Sep 2023 14:12:25 +0200 Subject: [PATCH] Changes for nanjing : iPerl.CycleBeginningForm and S640CommForm bug fixes. --- TBF/Rig/DataEntry/iPerl/CycleBeginningForm.cs | 46 +++--- .../Output/DB/ProductionTracing/Tracing.cs | 140 ++++++------------ TBF/Rig/Sequences/MainSeq.cs | 86 +++++------ .../S640Communication/S640CommForm.cs | 130 ++++++++++++---- TBF/UI/MainWnd.cs | 84 +++++++---- 5 files changed, 272 insertions(+), 214 deletions(-) diff --git a/TBF/Rig/DataEntry/iPerl/CycleBeginningForm.cs b/TBF/Rig/DataEntry/iPerl/CycleBeginningForm.cs index 7877208c0..c93de56d2 100644 --- a/TBF/Rig/DataEntry/iPerl/CycleBeginningForm.cs +++ b/TBF/Rig/DataEntry/iPerl/CycleBeginningForm.cs @@ -1,5 +1,5 @@ /// -/// Copyright (c) 2015-2021 Sensus Slovensko a.s. +/// Copyright (c) 2015-2023 Sensus Slovensko a.s. /// using System; using System.Collections.Generic; @@ -72,18 +72,23 @@ namespace TBF.Rig.DataEntry.iPerl listOfOrders = new List(); - if ((cfg.Orders == Orders.FromOracle || cfg.Orders == Orders.CombinedAndFromOracle) && ProcessData.OracleDB != null) + if ((cfg.Orders == Orders.FromOracle || cfg.Orders == Orders.CombinedAndFromOracle) + && ProcessData.OracleDB != null) { - var list = ProcessData.OracleDB.ReadOrders(); - foreach (var o in list) listOfOrders.Add(o); + foreach (var o in ProcessData.OracleDB.ReadOrders()) + { + listOfOrders.Add(o); + } } - if ((cfg.Orders == Orders.FromTracingDB || cfg.Orders == Orders.CombinedAndFromTracingDB) && - ProcessData.TracingDB != null && - ProcessData.TracingDB.DebugLevel == DebugMode.Normal) + if ((cfg.Orders == Orders.FromTracingDB || cfg.Orders == Orders.CombinedAndFromTracingDB) + && ProcessData.TracingDB != null + && ProcessData.TracingDB.DebugLevel == DebugMode.Normal) { - var list = ProcessData.TracingDB.ReadOrders(); - foreach (var o in list) listOfOrders.Add(o); + foreach (var o in ProcessData.TracingDB.ReadOrders()) + { + listOfOrders.Add(o); + } } string insertFirst = null; @@ -236,21 +241,22 @@ namespace TBF.Rig.DataEntry.iPerl { try { - ISession session = ProcessData.TracingDB.SessionFactory.OpenSession(); - string poName = 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; - string workflow = (list.Count == 1) ? list[0].Workflow : null; - ProcessData.WorkflowSummary = SharedDatabase.WorkflowSummary.ReadFromDB(workflow, "test", session); - session.Close(); + using (var session = ProcessData.TracingDB.SessionFactory.OpenSession()) + { + var list = session.QueryOver() + .Where(x => (x.POName == Program.MainWnd.SelectedProcedure.OrderInfo.POName)) + .List(); + ProcessData.OrderInfo = (list.Count == 1) ? list[0] : null; + string workflow = (list.Count == 1) ? list[0].Workflow : null; + ProcessData.WorkflowSummary = SharedDatabase.WorkflowSummary.ReadFromDB(workflow, "test", session); + session.Close(); + } } - catch (Exception exc) + catch (Exception ex) { + log.ErrorFormat("Unable to load an order, workflow or workstep: {0}", ex); ProcessData.OrderInfo = null; ProcessData.WorkflowSummary = null; - log.ErrorFormat("Unable to load order, workflow or workstep: {0}", exc.Message); } } diff --git a/TBF/Rig/Output/DB/ProductionTracing/Tracing.cs b/TBF/Rig/Output/DB/ProductionTracing/Tracing.cs index e6d8263dc..a846aa0d1 100644 --- a/TBF/Rig/Output/DB/ProductionTracing/Tracing.cs +++ b/TBF/Rig/Output/DB/ProductionTracing/Tracing.cs @@ -1,5 +1,5 @@ /// -/// Copyright (c) 2018-2019 Sensus Slovensko a.s. +/// Copyright (c) 2018-2023 Sensus Slovensko a.s. /// using System; using System.Collections.Generic; @@ -7,9 +7,7 @@ using System.Linq; using System.Net; using log4net; using NHibernate; -using NHibernate.Criterion; using Common; -using Config.Entities; using SharedDatabase; using SharedDatabase.Entities; using TBF.Rig.Sequences; @@ -112,39 +110,47 @@ namespace TBF.Rig.Output.DB.ProductionTracing /// /// Session factory is used to create database sessions /// - SessionFactory = FluentNHibernate.Cfg.Fluently.Configure() - .Database(FluentNHibernate.Cfg.Db.MySQLConfiguration.Standard.ConnectionString(tracingCfg.ConnStr)) - .Mappings(m => m.FluentMappings.AddFromAssemblyOf()) - .ExposeConfiguration(SharedDatabase.TracingDB.BuildSchema) - .BuildSessionFactory(); + SharedDatabase.TracingDB.SessionFactory = this.SessionFactory = + FluentNHibernate.Cfg.Fluently.Configure() + .Database(FluentNHibernate.Cfg.Db.MySQLConfiguration.Standard.ConnectionString(tracingCfg.ConnStr)) + .Mappings(m => m.FluentMappings.AddFromAssemblyOf()) + .ExposeConfiguration(SharedDatabase.TracingDB.BuildSchema) + .BuildSessionFactory(); - ISession session = SessionFactory.OpenSession(); - - /// - /// Initialize DefaultOrder - /// - var dfltOrders = session.QueryOver() - .Where(x => x.POName == "0000001") - .And(x => (x.POState == (sbyte)OrderState.New || x.POState == (sbyte)OrderState.Active)) - .List(); - if (dfltOrders.Count > 0) DefaultOrder = dfltOrders[0]; + try + { + using (var session = SessionFactory.OpenSession()) + { + /// + /// Initialize DefaultOrder + /// + var dfltOrders = session.QueryOver() + .Where(x => x.POName == "0000001") + .And(x => (x.POState == (sbyte)OrderState.New || x.POState == (sbyte)OrderState.Active)) + .List(); + if (dfltOrders.Count > 0) DefaultOrder = dfltOrders[0]; #if !DEBUG - /// - /// Register this test bench in the tracing DB for approx. 2 weeks (RELEASE version only) - /// - SharedDatabase.TracingDB.RegisterWorkplaceObsolete(session, - workplace, - CurrentUser.UserName(), - GetIPAddress(), - "", - WorkstepName, - DateTime.Now + new TimeSpan(15, 0, 0, 0)); + /// + /// Register this test bench in the tracing DB for approx. 2 weeks (RELEASE version only) + /// + SharedDatabase.TracingDB.RegisterWorkplaceObsolete(session, + workplace, + CurrentUser.UserName(), + GetIPAddress(), + "", + WorkstepName, + DateTime.Now + new TimeSpan(15, 0, 0, 0)); + session.Flush(); #endif - session.Flush(); - session.Close(); - SharedDatabase.TracingDB.SessionFactory = SessionFactory; - if (session != null) session.Dispose(); + session.Close(); + } + } + catch (Exception ex) + { + log.ErrorFormat("Cannot load a default order from a database or regster this workplace: {0}", ex); + DefaultOrder = null; + } } /// string GetIPAddress() @@ -167,53 +173,26 @@ namespace TBF.Rig.Output.DB.ProductionTracing } public void StopDevice2() {} - public IList ReadOrders(ISession session = null) + public IList ReadOrders() { - bool openAndCloseSession = (session == null) || !session.IsOpen; - try { - if (openAndCloseSession) session = SessionFactory.OpenSession(); - - var result = session.QueryOver() - .Where(x => (x.POState == (sbyte)OrderState.New || x.POState == (sbyte)OrderState.Active)) - .List(); - - if (openAndCloseSession) session.Close(); - - return result; + using (var session = SessionFactory.OpenSession()) + { + var result = session.QueryOver() + .Where(x => (x.POState == (sbyte)OrderState.New || x.POState == (sbyte)OrderState.Active)) + .List(); + session.Close(); + return result; + } } - catch (Exception exc) + catch (Exception ex) { - log.ErrorFormat("Cannot read orders from the tracing DB: {0}", exc.Message); + log.ErrorFormat("ReadOrders() failed: {0}", ex.Message); return new List(); } } - public OrderInfo ReadOrder(string poName, ISession session = null) - { - bool openAndCloseSession = (session == null) || !session.IsOpen; - - try - { - if (openAndCloseSession) session = SessionFactory.OpenSession(); - - var list = session.QueryOver() - .Where(x => (x.POName == poName)) - .List(); - - if (openAndCloseSession) session.Close(); - - return (list.Count == 1) ? list[0] : null; - } - catch (Exception exc) - { - log.ErrorFormat("Cannot read order {0} from the tracing DB: {1}", poName, exc.Message); - return null; - } - } - - /// /// Read reference records belonging to a specified order. /// Used when retrieving housing S/N-s belonging to obtained eRegister numbers. @@ -488,27 +467,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) diff --git a/TBF/Rig/Sequences/MainSeq.cs b/TBF/Rig/Sequences/MainSeq.cs index ecc4b9ea9..46168973e 100644 --- a/TBF/Rig/Sequences/MainSeq.cs +++ b/TBF/Rig/Sequences/MainSeq.cs @@ -1,5 +1,5 @@ /// -/// Copyright (c) 2013-2022 Sensus Slovensko a.s. +/// Copyright (c) 2013-2023 Sensus Slovensko a.s. /// using System; using System.Collections.Generic; @@ -9,10 +9,8 @@ using log4net; using NHibernate; using Common; using Config.Entities; -using Results.Entities; using TBF.Rig.Operations; using TBF.Rig.GenericDevices; -using TBF.Boxes; using TBF.Resources; using TBF.UiBridge; @@ -122,7 +120,7 @@ namespace TBF.Rig.Sequences /// void CloseCommunicationForm() { - UiBridge.Bridge.OnCloseModelessForm(this, null); + Bridge.OnCloseModelessForm(this, null); modelessDlg = null; } @@ -226,20 +224,22 @@ namespace TBF.Rig.Sequences { try { - ISession session = ProcessData.TracingDB.SessionFactory.OpenSession(); - var list = session.QueryOver() - .Where(x => (x.POName == ProcessData.SelectedProcedure.OrderInfo.POName)) - .List(); - ProcessData.OrderInfo = (list.Count == 1) ? list[0] : null; - string workflow = (list.Count == 1) ? list[0].Workflow : null; - ProcessData.WorkflowSummary = SharedDatabase.WorkflowSummary.ReadFromDB(workflow, "test", session); - session.Close(); + using (var session = ProcessData.TracingDB.SessionFactory.OpenSession()) + { + var list = session.QueryOver() + .Where(x => (x.POName == ProcessData.SelectedProcedure.OrderInfo.POName)) + .List(); + ProcessData.OrderInfo = (list.Count == 1) ? list[0] : null; + string workflow = (list.Count == 1) ? list[0].Workflow : null; + ProcessData.WorkflowSummary = SharedDatabase.WorkflowSummary.ReadFromDB(workflow, "test", session); + session.Close(); + } } - catch (Exception exc) + catch (Exception ex) { + log.ErrorFormat("Unable to load order, workflow or workstep: {0}", ex); ProcessData.OrderInfo = null; ProcessData.WorkflowSummary = null; - log.ErrorFormat("Unable to load order, workflow or workstep: {0}", exc.Message); } } @@ -270,19 +270,19 @@ namespace TBF.Rig.Sequences if (!processDataHeaderOK) { - UiBridge.Bridge.OnError(this, "Invalid process data"); + Bridge.OnError(this, "Invalid process data"); continue; } else if (version != Program.Version) { /// Program version does not match the one stored in process data - UiBridge.Bridge.OnError(this, Strings.Program_version_does_not_match); + Bridge.OnError(this, Strings.Program_version_does_not_match); continue; } else if (batchNr != Program.LocalSettings.BatchNr) { /// Program version does not match the one stored in process data - UiBridge.Bridge.OnError(this, Strings.Invalid_batch_number); + Bridge.OnError(this, Strings.Invalid_batch_number); continue; } @@ -386,7 +386,7 @@ namespace TBF.Rig.Sequences Debug.WriteLine(string.Format("Procedure.Tests[0].MoreParams {0}", NHibernateUtil.IsInitialized(StateMachine.Procedure.Tests[0].MoreParams) ? "initialized" : "NOT initialized")); } - UiBridge.Bridge.OnError(this, string.Empty); /// Clear an error message (if any) + Bridge.OnError(this, string.Empty); /// Clear an error message (if any) if (selection == Selection.RestoreInterruptedSession) @@ -394,7 +394,7 @@ namespace TBF.Rig.Sequences if (!LoadProcessData()) { /// Restorig interrupted session failed - UiBridge.Bridge.OnError(this, "Restorig interrupted session failed"); + Bridge.OnError(this, "Restorig interrupted session failed"); goto stop; } } @@ -420,7 +420,7 @@ namespace TBF.Rig.Sequences if (selection == Selection.RestoreBatch) { BatchRslts = CreateNewBatchResults(newBatchNr, StateMachine.Procedure); - RestoreBatchResults(TBF.UiBridge.Bridge.BatchNr, ref BatchRslts); /// pass the original batch number of the batch to be restored + RestoreBatchResults(Bridge.BatchNr, ref BatchRslts); /// pass the original batch number of the batch to be restored } else if (selection == Selection.RestoreAndFixBatch) { @@ -428,11 +428,11 @@ namespace TBF.Rig.Sequences /// Restore and fix a batch - part 1 (fix "Previous workstep is missing" error) /// BatchRslts = CreateNewBatchResults(newBatchNr, StateMachine.Procedure); - RestoreBatchResults(TBF.UiBridge.Bridge.BatchNr, ref BatchRslts); /// pass the original batch number of the batch to be restored + RestoreBatchResults(Bridge.BatchNr, ref BatchRslts); /// pass the original batch number of the batch to be restored for (int i = 0; i < BatchRslts.Batch.WaterMeters.Count; i++) { - WaterMeter wm = BatchRslts.Batch.WaterMeters[i]; + var wm = BatchRslts.Batch.WaterMeters[i]; if (wm != null && !wm.Disabled) { if (wm.Passed) @@ -661,7 +661,7 @@ namespace TBF.Rig.Sequences /// Restore and fix a batch - part 2 for (int i = 0; i < BatchRslts.Batch.WaterMeters.Count; i++) { - WaterMeter wm = BatchRslts.Batch.WaterMeters[i]; + var wm = BatchRslts.Batch.WaterMeters[i]; if (wm != null && !wm.Disabled) { /// Water meter did not pass @@ -743,7 +743,7 @@ namespace TBF.Rig.Sequences break; } /// - UiBridge.Bridge.OnError(this, string.Empty); /// Clear an error message (if any) + Bridge.OnError(this, string.Empty); /// Clear an error message (if any) /// if (selection == Selection.PurgeBegin) goto fill_the_bench; if (selection == Selection.PurgeEnd) @@ -770,7 +770,7 @@ namespace TBF.Rig.Sequences cycle_or_test_selected: - UiBridge.Bridge.OnError(this, string.Empty); /// Clear an error message (if any) + Bridge.OnError(this, string.Empty); /// Clear an error message (if any) if (UIFlowControl.Stop == WaitBeginFormClosed()) { @@ -824,7 +824,7 @@ namespace TBF.Rig.Sequences (selsctedTestIx >= StateMachine.TestInstances.Length - simultWithEvacuationCount)) { /// Invalid test selection - UiBridge.Bridge.OnError(this, string.Format("No test specified")); + Bridge.OnError(this, string.Format("No test specified")); goto select_cycle_or_test; } } @@ -854,7 +854,7 @@ namespace TBF.Rig.Sequences out transitionBefore, out transitionBetween, out transitionAfter, out errorMsg)) { - UiBridge.Bridge.OnError(this, errorMsg); + Bridge.OnError(this, errorMsg); goto select_cycle_or_test; } } @@ -895,7 +895,7 @@ namespace TBF.Rig.Sequences out nextTransitionBefore, out dummy2, out dummy3, out errorMsg2)) { - UiBridge.Bridge.OnError(this, errorMsg2); + Bridge.OnError(this, errorMsg2); goto select_cycle_or_test; } @@ -926,7 +926,7 @@ namespace TBF.Rig.Sequences out transitionBefore, out transitionBetween, out transitionAfter, out errorMsg)) { - UiBridge.Bridge.OnError(this, errorMsg); + Bridge.OnError(this, errorMsg); goto select_cycle_or_test; } @@ -946,7 +946,7 @@ namespace TBF.Rig.Sequences string errMsg; if (!testMethod.CheckDeviceCaps(testInst.Test, outPath, out errMsg)) { - UiBridge.Bridge.OnError(this, errMsg); + Bridge.OnError(this, errMsg); goto select_cycle_or_test; } StateMachine.ControlBoard.Devices = outPath; @@ -1048,7 +1048,7 @@ namespace TBF.Rig.Sequences } else { - UiBridge.Bridge.OnError(this, string.Format(Strings.Method_0_cannot_be_used, testInst.Test.Method)); + Bridge.OnError(this, string.Format(Strings.Method_0_cannot_be_used, testInst.Test.Method)); goto select_cycle_or_test; } @@ -1106,7 +1106,7 @@ namespace TBF.Rig.Sequences if (testIx < 0) { /// Invalid test selection - UiBridge.Bridge.OnError(this, string.Format("No test specified")); + Bridge.OnError(this, string.Format("No test specified")); goto select_cycle_or_test; } @@ -1124,7 +1124,7 @@ namespace TBF.Rig.Sequences out transitionBefore, out transitionBetween, out transitionAfter, out errorMsg)) { - UiBridge.Bridge.OnError(this, errorMsg); + Bridge.OnError(this, errorMsg); goto select_cycle_or_test; } @@ -1139,7 +1139,7 @@ namespace TBF.Rig.Sequences string errMsg; if (!testMethod.CheckDeviceCaps(test, outPath, out errMsg)) { - UiBridge.Bridge.OnError(this, errMsg); + Bridge.OnError(this, errMsg); goto select_cycle_or_test; } StateMachine.ControlBoard.Devices = outPath; @@ -1201,7 +1201,7 @@ namespace TBF.Rig.Sequences } else { - UiBridge.Bridge.OnError(this, string.Format("{0} cannot be used", test.Method)); + Bridge.OnError(this, string.Format("{0} cannot be used", test.Method)); goto select_cycle_or_test; } } @@ -1212,7 +1212,7 @@ namespace TBF.Rig.Sequences save_results: - UiBridge.Bridge.OnError(this, string.Empty); /// Clear an error message (if any) + Bridge.OnError(this, string.Empty); /// Clear an error message (if any) Bridge.Bench2UI(ButtonsEtc.StopBtnEn); /// Hide most of buttons if (State.LastEvents.Contains(Event.ModelessFormIsOpen)) @@ -1273,7 +1273,7 @@ namespace TBF.Rig.Sequences { for (int j = wm.MeterTestRslts.Count - 1; j >= 0; j--) { - MeterTestRslt mtr = wm.MeterTestRslts[j]; + var mtr = wm.MeterTestRslts[j]; if ((mtr.Publish() == Publish.Never || mtr.Publish() == Publish.Internal) && !mtr.Evaluate()) { wm.MeterTestRslts.RemoveAt(j); @@ -1281,7 +1281,7 @@ namespace TBF.Rig.Sequences } } - TestRslt tr = BatchRslts.Batch.TestRslts[i]; + var tr = BatchRslts.Batch.TestRslts[i]; if ((tr.Publish() == Publish.Never || tr.Publish() == Publish.Internal) && !tr.Evaluate()) { BatchRslts.Batch.TestRslts.RemoveAt(i); @@ -1289,13 +1289,13 @@ namespace TBF.Rig.Sequences } /// (1) Set boolean WaterMeter.Passed variable, (2) Remove disabled water meters - for (int wmNr0 = ProcessData.BatchRslts.Batch.WaterMeters.Count - 1; wmNr0 >= 0; wmNr0--) + for (int wmNr0 = BatchRslts.Batch.WaterMeters.Count - 1; wmNr0 >= 0; wmNr0--) { - WaterMeter wm = ProcessData.BatchRslts.Batch.WaterMeters[wmNr0]; + var wm = BatchRslts.Batch.WaterMeters[wmNr0]; if (wm.Disabled) { /// Do not save disabled watermeters to DB, remove them from the list - ProcessData.BatchRslts.Batch.WaterMeters.RemoveAt(wmNr0); + BatchRslts.Batch.WaterMeters.RemoveAt(wmNr0); } else { @@ -1310,8 +1310,8 @@ namespace TBF.Rig.Sequences //------------------------------------------------------ /// Save results to 'Results' MySQL DB with RsltsSent = 0 before saving and printing elswhere - ProcessData.BatchRslts.Batch.RsltsSent = false; - Results.DB.SaveNewBatch(ProcessData.BatchRslts.Batch); + BatchRslts.Batch.RsltsSent = false; + Results.DB.SaveNewBatch(BatchRslts.Batch); string[] writers = (StateMachine.Procedure.ResultsWriter != null) ? StateMachine.Procedure.ResultsWriter.Split(new char[] { '~' }) : new string[0]; string[] printers = (StateMachine.Procedure.ResultsPrinter != null) ? StateMachine.Procedure.ResultsPrinter.Split(new char[] { '~' }) : new string[0]; diff --git a/TBF/Rig/TestMethods/S640Communication/S640CommForm.cs b/TBF/Rig/TestMethods/S640Communication/S640CommForm.cs index 53730d720..231c84057 100644 --- a/TBF/Rig/TestMethods/S640Communication/S640CommForm.cs +++ b/TBF/Rig/TestMethods/S640Communication/S640CommForm.cs @@ -235,16 +235,16 @@ namespace TBF.Rig.TestMethods.S640Communication throw new Exception("Something strange: activities.Count != tests.Count"); } - if (activities.Count > 0) - { - ProcessData.RegisterReaders = StateMachine.GetMetersPath(tests[0]).RegisterReaders; - } - - if (ProcessData.RegisterReaders.Length != waterMeters.Count) + if (ProcessData.RegisterReaders.Length != ProcessData.BatchRslts.Batch.WaterMeters.Count) { throw new Exception("Something strange: RegisterReaders.Length != WaterMeters.Count"); } + if (activities.Count > 0) + { + ProcessData.RegisterReaders = StateMachine.GetMetersPath(tests[0]).RegisterReaders; + } + optoHeads = new RegisterReaders.S640Stream.S640Stream[ProcessData.RegisterReaders.Length]; /// for (int wmPos = 0; wmPos < ProcessData.RegisterReaders.Length; wmPos++) @@ -450,8 +450,8 @@ namespace TBF.Rig.TestMethods.S640Communication progressBar1.Value = 0; } - TBF.UiBridge.TestProgressEventArgs.SetEstimatedTimes(new int[] { 0, 0, 10, 0, 140, 0, 0, 0 }); - TBF.UiBridge.Bridge.OnTestProgress(null, new TBF.UiBridge.TestProgressEventArgs(tests[acIx], Progress.JustStarted)); + UiBridge.TestProgressEventArgs.SetEstimatedTimes(new int[] { 0, 0, 10, 0, 140, 0, 0, 0 }); + UiBridge.Bridge.OnTestProgress(null, new TBF.UiBridge.TestProgressEventArgs(tests[acIx], Progress.JustStarted)); sirtDataLogger.InfoFormat(""); /// Makes the log more readable when there is a lot of data sirtDataLogger.WarnFormat("Activity = {0}", activities[acIx]); @@ -739,6 +739,48 @@ namespace TBF.Rig.TestMethods.S640Communication { activityLabel.Text = "SIRT communication in progress"; + if (ProcessData.OrderInfo is OrderInfo && ProcessData.TracingDB != null) + { + var order = ProcessData.OrderInfo as OrderInfo; + ISession session = null; + try + { + session = ProcessData.TracingDB.SessionFactory.OpenSession(); + var orders = session.QueryOver() + .Where(x => x.POName == order.POName) + .List(); + if (orders.Count == 1) + { + orders[0].CurrentPcsCount = ProcessData.OrderInfo.CurrentPcsCount; + orders[0].CurrentSN = ProcessData.OrderInfo.CurrentSN; + orders[0].CurrentRA = ProcessData.OrderInfo.CurrentRA; + session.SaveOrUpdate(orders[0]); + session.Flush(); + + log.WarnFormat("Order={0} CurrentPcsCount={1} CurrentSN={2} CurrentRA={3}", + ProcessData.OrderInfo.POName, ProcessData.OrderInfo.CurrentPcsCount, + ProcessData.OrderInfo.CurrentSN, ProcessData.OrderInfo.CurrentRA); + } + else + { + log.Error("Failed to update OrderInfo.CurrentSN..."); + } + } + catch (Exception ex) + { + log.ErrorFormat("Failed to update OrderInfo.CurrentSN... : {0}", ex.Message); + } + finally + { + if (session != null && session.IsOpen) session.Close(); + } + } + else if (ProcessData.OrderInfo is Output.DB.SensusOracle.OrderDetails && ProcessData.OracleDB != null) + { + int updatedCount = ProcessData.OracleDB + .UpdateOrderDetails(ProcessData.OrderInfo as Output.DB.SensusOracle.OrderDetails); + } + log.DebugFormat("Saving '{0}' file", EndFileName); if (debugLevel == DebugMode.Normal) { @@ -925,31 +967,56 @@ namespace TBF.Rig.TestMethods.S640Communication /// true = s/n-s are assigned, false = missing order information or DB connection bool AssignNewSNsAndRadioAddresses(IList waterMeters, RegisterReaders.S640Stream.S640Stream[] optoHeads) { - var order = ProcessData.OrderInfo; - if (order == null) return false; - - var oraOrder = order as TBF.Rig.Output.DB.SensusOracle.OrderDetails; /// - if (oraOrder != null && (ProcessData.OracleDB == null || !ProcessData.OracleDB.ReadOrderDetails(ref oraOrder))) + /// Reload the order refered by ProcessData.OrderInfo + /// + if (ProcessData.OrderInfo is OrderInfo && ProcessData.TracingDB != null) { + string orderName = Program.MainWnd.SelectedProcedure.OrderInfo.POName; + try + { + using (var session = ProcessData.TracingDB.SessionFactory.OpenSession()) + { + var list = session.QueryOver() + .Where(x => (x.POName == orderName)) + .List(); + + if (list.Count == 1) + { + ProcessData.OrderInfo = list[0]; + + log.WarnFormat("Order={0} CurrentPcsCount={1} CurrentSN={2} CurrentRA={3}", + orderName, ProcessData.OrderInfo.CurrentPcsCount, + ProcessData.OrderInfo.CurrentSN, ProcessData.OrderInfo.CurrentRA); + } + else + { + log.ErrorFormat("Unable to reload order {0}", orderName); + } + + session.Close(); + } + } + catch (Exception exc) + { + log.ErrorFormat("Unable to reload order {0}: {1}", orderName, exc.Message); + } + } + else if (ProcessData.OrderInfo is Output.DB.SensusOracle.OrderDetails && ProcessData.OracleDB != null) + { + var oraOrder = ProcessData.OrderInfo as Output.DB.SensusOracle.OrderDetails; + if (!ProcessData.OracleDB.ReadOrderDetails(ref oraOrder)) return false; + } + else + { + /// Either order is missing or a required component (TracingDB or SensusOracle) is missing return false; } - if (order.CurrentSN < order.SNFirst) - { - order.CurrentSN = order.SNFirst - 1; - } + var order = ProcessData.OrderInfo; for (int i = 0; i < optoHeads.Length; i++) { - int currentSerialNr = (order.CurrentSN < order.SNFirst) - ? order.SNFirst - : order.CurrentSN + 1; - - int currentRadioAddress = (order.CurrentRA < order.RAFirst) - ? order.RAFirst - : order.CurrentRA + 1; - Results.Entities.WaterMeter wm = ProcessData.BatchRslts.Batch.WaterMeters[i]; if (optoHeads[i] != null && optoHeads[i].PcbNumber != 0 && wm != null && !wm.Disabled) { @@ -980,28 +1047,31 @@ namespace TBF.Rig.TestMethods.S640Communication else { /// Assign numbers - wm.AssignedSerialNr = currentSerialNr; + wm.AssignedSerialNr = (order.CurrentSN < order.SNFirst) ? order.SNFirst : order.CurrentSN + 1; wm.Prefix = order.SNPrefix; wm.Suffix = order.SNSuffix; wm.CompleteSerialNr = string.Format("{0}{1}{2}", - order.SNPrefix, - currentSerialNr.ToString(string.Format("D{0}", order.SNDigitsCount)), - order.SNSuffix); + wm.Prefix, + wm.AssignedSerialNr.ToString(string.Format("D{0}", order.SNDigitsCount)), + wm.Suffix); assignedSNs[i].Text = wm.CompleteSerialNr; + int currentRadioAddress = (order.CurrentRA < order.RAFirst) ? order.RAFirst : order.CurrentRA + 1; wm.RadioAddress = string.Format("{0}{1}{2}", order.RAPrefix, currentRadioAddress.ToString(SharedDatabase.Const.RAFormat), order.RASuffix); assignedRadioAddresses[i].Text = wm.RadioAddress; - order.CurrentSN = currentSerialNr; + order.CurrentSN = wm.AssignedSerialNr; order.CurrentRA = currentRadioAddress; order.CurrentPcsCount++; } } } + UiBridge.Bridge.OnTestCompleted(this, new UiBridge.TestCompletedEventArgs(string.Empty, null)); + areNewSNsAndRadioAddressesAssigned = true; return true; } diff --git a/TBF/UI/MainWnd.cs b/TBF/UI/MainWnd.cs index 82df766ae..8b3e86e49 100644 --- a/TBF/UI/MainWnd.cs +++ b/TBF/UI/MainWnd.cs @@ -1,5 +1,5 @@ /// -/// Copyright (c) 2013-2022 Sensus Slovensko a.s. +/// Copyright (c) 2013-2023 Sensus Slovensko a.s. /// using System; using System.Collections.Generic; @@ -767,28 +767,49 @@ namespace TBF.UI if (src == ProcedureSelection.FromLocalDB) { - localProcedures = TBF.DB.CreateSession(DBKind.Config) - .QueryOver() - .Where(x => (x.ProcedureState == ProcedureState.Active)) - .OrderBy(x => x.ItemNr).Asc - .List(); - - foreach (var proc in localProcedures) + try { - procedureInfos.Add(new ProcedureInfo(src, itemNr++, proc.Name, signature, proc.Watermeters)); + using (var session = TBF.DB.CreateSession(DBKind.Config)) + { + localProcedures = session.QueryOver() + .Where(x => (x.ProcedureState == ProcedureState.Active)) + .OrderBy(x => x.ItemNr).Asc + .List(); + + foreach (var proc in localProcedures) + { + procedureInfos.Add(new ProcedureInfo(src, itemNr++, proc.Name, signature, proc.Watermeters)); + } + } + } + catch (Exception ex) + { + log.ErrorFormat("Cannot load procedures from a local database: {0}", ex); + localProcedures = new List(); } } else if (src == ProcedureSelection.FromSharedDB) { - remoteProcedures = TBF.DB.CreateSession(DBKind.RemoteConfig) - .QueryOver() - .Where(x => (x.ProcedureState == ProcedureState.Active)) - .OrderBy(x => x.ItemNr).Asc - .List(); - - foreach (var proc in remoteProcedures) + try { - procedureInfos.Add(new ProcedureInfo(src, itemNr++, proc.Name, signature, proc.Watermeters)); + using (var session = TBF.DB.CreateSession(DBKind.RemoteConfig)) + { + remoteProcedures = session.QueryOver() + .Where(x => (x.ProcedureState == ProcedureState.Active)) + .OrderBy(x => x.ItemNr).Asc + .List(); + session.Close(); + } + + foreach (var proc in remoteProcedures) + { + procedureInfos.Add(new ProcedureInfo(src, itemNr++, proc.Name, signature, proc.Watermeters)); + } + } + catch (Exception ex) + { + log.ErrorFormat("Cannot load procedures from a remote database: {0}", ex); + remoteProcedures = new List(); } } else if (src == ProcedureSelection.OrderFromOracleDB) @@ -804,21 +825,24 @@ namespace TBF.UI { try { - var session = TBF.Rig.Sequences.ProcessData.TracingDB.SessionFactory.OpenSession(); - tracingDBOrders = session.QueryOver() - .Where(x => x.POState != (sbyte)SharedDatabase.Entities.OrderState.Finished) - .List(); - session.Close(); - } - catch - { - tracingDBOrders = new List(); - } + using (var session = Rig.Sequences.ProcessData.TracingDB.SessionFactory.OpenSession()) + { + tracingDBOrders = session.QueryOver() + .Where(x => x.POState != (sbyte)SharedDatabase.Entities.OrderState.Finished) + .List(); + session.Close(); + } - foreach (var order in tracingDBOrders) + foreach (var order in tracingDBOrders) + { + procedureInfos.Add(new ProcedureInfo(src, 0, order.POName, signature, order.VariantCode, order, + order.Workflow, order.LaserMarking)); + } + } + catch (Exception ex) { - procedureInfos.Add(new ProcedureInfo(src, 0, order.POName, signature, order.VariantCode, order, - order.Workflow, order.LaserMarking)); + log.ErrorFormat("Cannot load orders from the production tracing DB: {0}", ex); + tracingDBOrders = new List(); } } }