2018-08-01 06:44:16 +00:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using log4net;
|
2018-08-28 07:28:58 +00:00
|
|
|
|
using TracingDB.Entities;
|
2018-08-01 06:44:16 +00:00
|
|
|
|
|
2018-08-28 07:28:58 +00:00
|
|
|
|
namespace TracingDB
|
2018-08-01 06:44:16 +00:00
|
|
|
|
{
|
2019-03-01 13:16:04 +00:00
|
|
|
|
public class BatteryAndFlowtubeInfo
|
2018-08-01 06:44:16 +00:00
|
|
|
|
{
|
2019-03-01 13:16:04 +00:00
|
|
|
|
static readonly ILog log = LogManager.GetLogger(typeof(BatteryAndFlowtubeInfo));
|
2018-08-01 06:44:16 +00:00
|
|
|
|
|
|
|
|
|
|
/// 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
|
2019-03-01 13:16:04 +00:00
|
|
|
|
public string FlowtubeSapPartNr; /// Flowtube SAP part number
|
|
|
|
|
|
public bool IsPorexFlowtube; ///
|
|
|
|
|
|
public string PrintedInfo; /// 'T', 'Vi', '-', 'T/P', 'Vi/P' or '-/P'
|
2018-08-01 06:44:16 +00:00
|
|
|
|
public DateTime TimeStamp; /// Record creation time
|
|
|
|
|
|
|
|
|
|
|
|
bool complete { get { return (PcbNumber != null) && (BattSapPartNr != null) && (BattBatchNr != 0) && (BattMMYY != null) && (BattSupplier != null); } }
|
|
|
|
|
|
|
|
|
|
|
|
|
2019-03-01 13:16:04 +00:00
|
|
|
|
public BatteryAndFlowtubeInfo()
|
2018-08-01 06:44:16 +00:00
|
|
|
|
{
|
|
|
|
|
|
TimeStamp = DateTime.Now;
|
2019-03-01 13:16:04 +00:00
|
|
|
|
PrintedInfo = "-";
|
2018-08-01 06:44:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Search MySQL DB and get battery info, add it into the record.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <returns>true when successful</returns>
|
2019-03-01 13:16:04 +00:00
|
|
|
|
public static BatteryAndFlowtubeInfo GetBatteryAndFlowtubeInfo(string pcbNumber, IList<WMPart> parts, string porexSapNumbers)
|
2018-08-01 06:44:16 +00:00
|
|
|
|
{
|
|
|
|
|
|
if (string.IsNullOrEmpty(pcbNumber))
|
|
|
|
|
|
{
|
|
|
|
|
|
log.ErrorFormat("Invalid PcbBr, no battery info.");
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-03-01 13:16:04 +00:00
|
|
|
|
BatteryAndFlowtubeInfo info = new BatteryAndFlowtubeInfo() { PcbNumber = pcbNumber };
|
2018-08-01 06:44:16 +00:00
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
bool error = false;
|
|
|
|
|
|
|
2019-03-01 13:16:04 +00:00
|
|
|
|
foreach (var part in parts)
|
2018-08-01 06:44:16 +00:00
|
|
|
|
{
|
2019-03-01 13:16:04 +00:00
|
|
|
|
if (part.CodeLocation == CodeLocation.OnPart)
|
2018-08-01 06:44:16 +00:00
|
|
|
|
{
|
2019-03-01 13:16:04 +00:00
|
|
|
|
if (porexSapNumbers.Contains(part.Name))
|
2018-08-01 06:44:16 +00:00
|
|
|
|
{
|
2019-03-01 13:16:04 +00:00
|
|
|
|
info.IsPorexFlowtube = true;
|
|
|
|
|
|
info.FlowtubeSapPartNr = part.Name;
|
2018-08-01 06:44:16 +00:00
|
|
|
|
}
|
2019-03-01 13:16:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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"))
|
2018-08-01 06:44:16 +00:00
|
|
|
|
{
|
|
|
|
|
|
if (info.BattSapPartNr != null) { error = true; break; }
|
2019-03-01 13:16:04 +00:00
|
|
|
|
info.BattSapPartNr = part.Name;
|
2018-08-01 06:44:16 +00:00
|
|
|
|
int battBatchNr;
|
2019-03-01 13:16:04 +00:00
|
|
|
|
info.BattBatchNr = int.TryParse(part.Code, out battBatchNr) ? battBatchNr : 1;
|
|
|
|
|
|
info.BattSupplier = oraDescr; /// Should be "TADIRAN" or "VITZROCELL"
|
2018-08-01 06:44:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-03-01 13:16:04 +00:00
|
|
|
|
if (part.CodeType == CodeType.DateMMYY)
|
2018-08-01 06:44:16 +00:00
|
|
|
|
{
|
|
|
|
|
|
if (info.BattMMYY != null) { error = true; break; }
|
2019-03-01 13:16:04 +00:00
|
|
|
|
info.BattMMYY = part.Code;
|
2018-08-01 06:44:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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")
|
|
|
|
|
|
{
|
2019-03-01 13:16:04 +00:00
|
|
|
|
info.PrintedInfo = "Vi";
|
2018-08-01 06:44:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
else if (info.BattSupplier == "TADIRAN")
|
|
|
|
|
|
{
|
2019-03-01 13:16:04 +00:00
|
|
|
|
info.PrintedInfo = "T";
|
2018-08-01 06:44:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-03-01 13:16:04 +00:00
|
|
|
|
///
|
|
|
|
|
|
/// Append Porex flowtube info in case of a Porex flowtube
|
|
|
|
|
|
///
|
|
|
|
|
|
if (info.IsPorexFlowtube) { info.PrintedInfo += "/P"; }
|
|
|
|
|
|
|
2018-08-01 06:44:16 +00:00
|
|
|
|
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()
|
|
|
|
|
|
{
|
2019-03-01 13:16:04 +00:00
|
|
|
|
return string.Format("PcbNr={0}, Battery={1}/{2}/{3} {4}, Time={5}", PcbNumber, BattBatchNr, BattMMYY, BattSupplier, (IsPorexFlowtube ? "porex" : ""), TimeStamp);
|
2018-08-01 06:44:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|