294 lines
12 KiB
C#
294 lines
12 KiB
C#
///
|
|
/// Copyright (c) 2019 Sensus Slovensko a.s.
|
|
///
|
|
using System;
|
|
using System.Globalization;
|
|
using System.IO;
|
|
using System.Xml;
|
|
using Gma.QrCodeNet.Encoding;
|
|
using log4net;
|
|
using Oracle.DataAccess.Client;
|
|
|
|
namespace RecordProcessing.Records
|
|
{
|
|
public class RFTestRecord : IRecord
|
|
{
|
|
static readonly ILog log = LogManager.GetLogger(typeof(RFTestRecord));
|
|
|
|
public const string RFTestStationName = "STAWL001";
|
|
|
|
public static string Path;
|
|
|
|
public string FileName { get { return fileName; } }
|
|
public string SN { get { return sn; } set { sn = value; } }
|
|
public DateTime TimeStamp { get { return timeStamp; } }
|
|
public Status Status { get { return status; } }
|
|
public string ResultStr { get { return string.Format("({0} {1})", string.IsNullOrEmpty(RFPower_Value) ? "" : RFPower_Value, string.IsNullOrEmpty(RFPower_Unit) ? "" : RFPower_Unit); } }
|
|
public string Remark { get { return string.IsNullOrEmpty(remark) ? string.Empty : remark; } }
|
|
|
|
string fileName;
|
|
string sn;
|
|
DateTime timeStamp;
|
|
Status status;
|
|
string remark;
|
|
|
|
|
|
public string BattSapPartNr; /// Battery SAP part number
|
|
public int BattBatchNr; /// Batch number (purchase order)
|
|
public string BattMMYY; /// Production date
|
|
public string BattSupplier; /// Supplier
|
|
public string FlowtubeSapPartNr; /// Flowtube SAP part number
|
|
public bool IsPorexFlowtube; ///
|
|
public string PrintedInfo; /// 'T', 'Vi', '-', 'T/P', 'Vi/P' or '-/P'
|
|
|
|
public string ProductName;
|
|
public double TestTime; /// [s]
|
|
public string RFPower_Value;
|
|
public string RFPower_LoLim;
|
|
public string RFPower_HiLim;
|
|
public string RFPower_Unit;
|
|
public int ReferenceRecordsCount;
|
|
public string FrequencyInfo;
|
|
|
|
bool complete { get { return (sn != null) && (BattSapPartNr != null) && (BattBatchNr != 0) && (BattMMYY != null) && (BattSupplier != null); } }
|
|
|
|
|
|
static QrEncoder encoder = new QrEncoder();
|
|
|
|
|
|
public RFTestRecord()
|
|
{
|
|
sn = null; /// Initially there is no PCB number
|
|
}
|
|
|
|
/// <summary>
|
|
/// Load a record from an xml-file
|
|
/// </summary>
|
|
/// <param name="fileName">xml-filename</param>
|
|
/// <returns>Record or null</returns>
|
|
public static RFTestRecord FromFile(string fileName)
|
|
{
|
|
try
|
|
{
|
|
string bareFileName = System.IO.Path.GetFileName(fileName).Replace(".xml", "");
|
|
using (Stream inputStream = File.OpenRead(fileName))
|
|
{
|
|
return FromFile(inputStream, bareFileName);
|
|
}
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
log.ErrorFormat("Cannot open file {0}: {1}", fileName, exc.Message);
|
|
return null;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Load a record from a file stream (XML file format)
|
|
/// </summary>
|
|
/// <param name="inputStream">Input stream</param>
|
|
/// <param name="bareFileName">Filename for doc. purpose only</param>
|
|
/// <returns>Record</returns>
|
|
public static RFTestRecord FromFile(Stream inputStream, string bareFileName)
|
|
{
|
|
RFTestRecord record = new RFTestRecord();
|
|
|
|
record.fileName = bareFileName;
|
|
|
|
try
|
|
{
|
|
string[] fields = record.fileName.Split(new char[] { '_' });
|
|
string dateTimeEtc = fields[(fields.Length == 2) ? 1 : fields.Length - 2];
|
|
int yyyy = int.Parse(dateTimeEtc.Substring(0, 4));
|
|
int mo = int.Parse(dateTimeEtc.Substring(4, 2));
|
|
int dd = int.Parse(dateTimeEtc.Substring(6, 2));
|
|
int hh = int.Parse(dateTimeEtc.Substring(8, 2));
|
|
int mi = int.Parse(dateTimeEtc.Substring(10, 2));
|
|
int ss = int.Parse(dateTimeEtc.Substring(12, 2));
|
|
record.timeStamp = new DateTime(yyyy, mo, dd, hh, mi, ss);
|
|
|
|
XmlDocument xDoc = new XmlDocument();
|
|
xDoc.Load(inputStream);
|
|
bool testResultFound = false;
|
|
foreach (XmlNode node in xDoc.DocumentElement.ChildNodes)
|
|
{
|
|
if (node.Name == "PRODUCT")
|
|
{
|
|
record.ProductName = node.Attributes["NAME"].Value;
|
|
}
|
|
else if (node.Name == "REFS")
|
|
{
|
|
record.remark = node.Attributes["SEQ_REF"].Value;
|
|
}
|
|
else if (node.Name == "PANEL")
|
|
{
|
|
foreach (XmlNode sNode in node.ChildNodes)
|
|
{
|
|
if (sNode.Name != "DUT") continue;
|
|
|
|
record.sn = sNode.Attributes["ID"].Value;
|
|
|
|
string statusStr = sNode.Attributes["STATUS"].Value;
|
|
if (statusStr.ToLower().Equals("passed"))
|
|
{
|
|
record.status = Status.Passed;
|
|
}
|
|
else if (statusStr.ToLower().Equals("failed"))
|
|
{
|
|
record.status = Status.Failed;
|
|
}
|
|
else
|
|
{
|
|
record.status = Status.Interrupted;
|
|
}
|
|
|
|
record.TestTime = double.Parse(sNode.Attributes["TESTTIME"].Value, NumberStyles.AllowDecimalPoint | NumberStyles.AllowLeadingSign, CultureInfo.InvariantCulture);
|
|
|
|
if (testResultFound) continue;
|
|
|
|
///
|
|
/// Search for RF_Power test result
|
|
///
|
|
foreach (XmlNode ssNode in sNode.ChildNodes)
|
|
{
|
|
if (ssNode.Name != "GROUP") continue;
|
|
foreach (XmlNode sssNode in ssNode.ChildNodes)
|
|
{
|
|
if (sssNode.Name != "GROUP" || !sssNode.HasChildNodes) continue;
|
|
|
|
foreach (XmlNode ssssNode in sssNode.ChildNodes)
|
|
{
|
|
if ((ssssNode.Name == "TEST") && (ssssNode.Attributes["NAME"].Value == "RF_Power") &&
|
|
!string.IsNullOrEmpty(ssssNode.Attributes["UNIT"].Value) &&
|
|
!string.IsNullOrEmpty(ssssNode.Attributes["VALUE"].Value) &&
|
|
!string.IsNullOrEmpty(ssssNode.Attributes["LOLIM"].Value) &&
|
|
!string.IsNullOrEmpty(ssssNode.Attributes["HILIM"].Value))
|
|
{
|
|
record.RFPower_Unit = ssssNode.Attributes["UNIT"].Value;
|
|
record.RFPower_Value = ssssNode.Attributes["VALUE"].Value;
|
|
record.RFPower_LoLim = ssssNode.Attributes["LOLIM"].Value;
|
|
record.RFPower_HiLim = ssssNode.Attributes["HILIM"].Value;
|
|
testResultFound = true;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
if (testResultFound) break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
log.ErrorFormat("Cannot parse file {0}: {1}", record.fileName, exc.Message);
|
|
return null;
|
|
}
|
|
|
|
return record;
|
|
}
|
|
|
|
|
|
public string GetFrequencyInfo()
|
|
{
|
|
if (!string.IsNullOrEmpty(ProductName))
|
|
{
|
|
string[] fields = ProductName.Split(new char[] { ' ', '_' });
|
|
foreach (var s in fields)
|
|
{
|
|
if (s.Contains("MHz")) return s;
|
|
}
|
|
}
|
|
|
|
return "---";
|
|
}
|
|
|
|
|
|
public bool CanSaveRecordToOracle() { return true; }
|
|
|
|
/// <summary>
|
|
/// Save RF_Power measurement result into Oracle DB
|
|
/// </summary>
|
|
/// <param name="oraConn">Oracle DB connection</param>
|
|
/// <returns>true = Record was successfully saved to DB</returns>
|
|
public bool SaveRecordToOracle(OracleConnection oraConn)
|
|
{
|
|
OracleTransaction transaction = null;
|
|
try
|
|
{
|
|
oraConn.Open();
|
|
transaction = oraConn.BeginTransaction();
|
|
|
|
bool exists = false; /// true = Record with the same PcbNumber already exist, use 'update' instead of 'insert'
|
|
|
|
OracleCommand cmd1 = new OracleCommand("select * from IP_ENDTEST_PD where PCBNUMBER = :1", oraConn);
|
|
OracleParameter param = new OracleParameter("PCBNUMBER", OracleDbType.Varchar2);
|
|
param.Value = SN;
|
|
cmd1.Parameters.Add(param);
|
|
OracleDataReader dr1 = cmd1.ExecuteReader();
|
|
if (dr1.Read()) { exists = true; }
|
|
dr1.Close();
|
|
|
|
OracleCommand cmd;
|
|
if (exists)
|
|
{
|
|
cmd = new OracleCommand("update IP_ENDTEST_PD set ET_RF_POWER_VALUE = :2, ET_RF_POWER_LOLIM = :3, ET_RF_POWER_HILIM = :4, ET_RF_POWER_UNIT = :5, DUT_TIMESTAMP = :6, TESTSTATIONNAME = :7 where PCBNUMBER = :1", oraConn);
|
|
}
|
|
else
|
|
{
|
|
cmd = new OracleCommand("insert into IP_ENDTEST_PD(PCBNUMBER, ET_RF_POWER_VALUE, ET_RF_POWER_LOLIM, ET_RF_POWER_HILIM, ET_RF_POWER_UNIT, DUT_TIMESTAMP, TESTSTATIONNAME) values (:1, :2, :3, :4, :5, :6, :7)", oraConn);
|
|
}
|
|
OracleParameter parm;
|
|
parm = new OracleParameter("PCBNUMBER", OracleDbType.Varchar2); parm.Value = SN; cmd.Parameters.Add(parm);
|
|
parm = new OracleParameter("ET_RF_POWER_VALUE", OracleDbType.Varchar2); parm.Value = RFPower_Value; cmd.Parameters.Add(parm);
|
|
parm = new OracleParameter("ET_RF_POWER_LOLIM", OracleDbType.Varchar2); parm.Value = RFPower_LoLim; cmd.Parameters.Add(parm);
|
|
parm = new OracleParameter("ET_RF_POWER_HILIM", OracleDbType.Varchar2); parm.Value = RFPower_HiLim; cmd.Parameters.Add(parm);
|
|
parm = new OracleParameter("ET_RF_POWER_UNIT", OracleDbType.Varchar2); parm.Value = RFPower_Unit; cmd.Parameters.Add(parm);
|
|
parm = new OracleParameter("DUT_TIMESTAMP", OracleDbType.TimeStamp); parm.Value = TimeStamp; cmd.Parameters.Add(parm);
|
|
parm = new OracleParameter("TESTSTATIONNAME", OracleDbType.Varchar2); parm.Value = RFTestStationName; cmd.Parameters.Add(parm);
|
|
cmd.ExecuteNonQuery();
|
|
|
|
transaction.Commit();
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
if (transaction != null) transaction.Rollback();
|
|
oraConn.Close();
|
|
|
|
log.ErrorFormat("RF_Power test result of PcbNumber={0} was not written into ORACLE database: {1}", SN, exc.Message);
|
|
return false;
|
|
}
|
|
|
|
oraConn.Close();
|
|
return true;
|
|
}
|
|
|
|
public bool CanPrintRecord() { return true; }
|
|
|
|
public bool PrintRecord()
|
|
{
|
|
try
|
|
{
|
|
new RFTestPrintDocument(this, encoder.Encode(SN), false).Print();
|
|
return true;
|
|
}
|
|
catch (Exception)
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
|
|
public override string ToString()
|
|
{
|
|
return string.Format("File={0} PcbNr={1}({2}), Rslt={3}, RF_Power={4} {5}",
|
|
fileName,
|
|
sn,
|
|
ReferenceRecordsCount,
|
|
status,
|
|
RFPower_Value,
|
|
RFPower_Unit);
|
|
}
|
|
}
|
|
}
|