Changes for nanjing : iPerl.CycleBeginningForm and S640CommForm bug fixes.
This commit is contained in:
@@ -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<Process>())
|
||||
.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<Process>())
|
||||
.ExposeConfiguration(SharedDatabase.TracingDB.BuildSchema)
|
||||
.BuildSessionFactory();
|
||||
|
||||
ISession session = SessionFactory.OpenSession();
|
||||
|
||||
///
|
||||
/// Initialize DefaultOrder
|
||||
///
|
||||
var dfltOrders = session.QueryOver<OrderInfo>()
|
||||
.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<OrderInfo>()
|
||||
.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(),
|
||||
"<multiple>",
|
||||
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(),
|
||||
"<multiple>",
|
||||
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<OrderInfo> ReadOrders(ISession session = null)
|
||||
public IList<OrderInfo> ReadOrders()
|
||||
{
|
||||
bool openAndCloseSession = (session == null) || !session.IsOpen;
|
||||
|
||||
try
|
||||
{
|
||||
if (openAndCloseSession) session = SessionFactory.OpenSession();
|
||||
|
||||
var result = session.QueryOver<OrderInfo>()
|
||||
.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<OrderInfo>()
|
||||
.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<OrderInfo>();
|
||||
}
|
||||
}
|
||||
|
||||
public OrderInfo ReadOrder(string poName, ISession session = null)
|
||||
{
|
||||
bool openAndCloseSession = (session == null) || !session.IsOpen;
|
||||
|
||||
try
|
||||
{
|
||||
if (openAndCloseSession) session = SessionFactory.OpenSession();
|
||||
|
||||
var list = session.QueryOver<OrderInfo>()
|
||||
.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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 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<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)
|
||||
|
||||
Reference in New Issue
Block a user