init
This commit is contained in:
@@ -0,0 +1,238 @@
|
||||
using System;
|
||||
using System.Data;
|
||||
using System.Data.SqlClient;
|
||||
|
||||
namespace DatabaseImport.ISO
|
||||
{
|
||||
[Serializable()]
|
||||
public class LabratoryDetails //: ISerializableFile
|
||||
{
|
||||
private enum Fields
|
||||
{
|
||||
Name,
|
||||
LaboratoryName,
|
||||
LaboratoryContactName,
|
||||
LaboratoryContactPhone,
|
||||
LaboratoryContactFax,
|
||||
LaboratoryContactEmail,
|
||||
LaboratoryTestRefNumber,
|
||||
LaboratoryProjectRefNumber,
|
||||
LastModified,
|
||||
LastModifiedBy,
|
||||
LocalOnly,
|
||||
Version
|
||||
};
|
||||
private string _labratoryName = string.Empty;
|
||||
|
||||
public string LabratoryName
|
||||
{
|
||||
get => _labratoryName;
|
||||
set => _labratoryName = value;
|
||||
}
|
||||
|
||||
private string _labratoryContactName = string.Empty;
|
||||
|
||||
public string LabratoryContactName
|
||||
{
|
||||
get => _labratoryContactName;
|
||||
set => _labratoryContactName = value;
|
||||
}
|
||||
|
||||
private string _labratoryContactPhone = "NOVALUE";
|
||||
|
||||
public string LabratoryContactPhone
|
||||
{
|
||||
get => _labratoryContactPhone;
|
||||
set
|
||||
{
|
||||
if (value != string.Empty)
|
||||
{
|
||||
_labratoryContactPhone = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private string _labratoryContactFax = "NOVALUE";
|
||||
|
||||
public string LabratoryContactFax
|
||||
{
|
||||
get => _labratoryContactFax;
|
||||
set
|
||||
{
|
||||
if (value != string.Empty)
|
||||
{
|
||||
_labratoryContactFax = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private string _labratoryContactEmail = "NOVALUE";
|
||||
|
||||
public string LabratoryContactEmail
|
||||
{
|
||||
get => _labratoryContactEmail;
|
||||
set
|
||||
{
|
||||
if (value != string.Empty)
|
||||
{
|
||||
_labratoryContactEmail = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private string _labratoryTestRefNumber = string.Empty;
|
||||
|
||||
public string LabratoryTestRefNumber
|
||||
{
|
||||
get => _labratoryTestRefNumber;
|
||||
set => _labratoryTestRefNumber = value;
|
||||
}
|
||||
|
||||
private string _labratoryProjectRefNumber = string.Empty;
|
||||
|
||||
public string LabratoryProjectRefNumber
|
||||
{
|
||||
get => _labratoryProjectRefNumber;
|
||||
set => _labratoryProjectRefNumber = value;
|
||||
}
|
||||
|
||||
private string _name = "";
|
||||
|
||||
public string Name
|
||||
{
|
||||
get => _name;
|
||||
set => _name = value;
|
||||
}
|
||||
|
||||
private bool _localOnly;
|
||||
|
||||
public bool LocalOnly
|
||||
{
|
||||
get => _localOnly;
|
||||
set => _localOnly = value;
|
||||
}
|
||||
|
||||
private DateTime _lastModified;
|
||||
|
||||
public DateTime LastModified
|
||||
{
|
||||
get => _lastModified;
|
||||
set => _lastModified = value;
|
||||
}
|
||||
|
||||
private string _lastModifiedBy;
|
||||
|
||||
public string LastModifiedBy
|
||||
{
|
||||
get => _lastModifiedBy;
|
||||
set => _lastModifiedBy = value;
|
||||
}
|
||||
|
||||
private int _version = 1;
|
||||
|
||||
public int Version
|
||||
{
|
||||
get => _version;
|
||||
set => _version = value;
|
||||
}
|
||||
public static LabratoryDetails ReadXML(System.Xml.XmlElement root)
|
||||
{
|
||||
var l = new LabratoryDetails();
|
||||
foreach (var node in root.ChildNodes)
|
||||
{
|
||||
if (node is System.Xml.XmlElement)
|
||||
{
|
||||
ProcessXMLElement(node as System.Xml.XmlElement, ref l);
|
||||
}
|
||||
}
|
||||
return l;
|
||||
}
|
||||
|
||||
private static void ProcessXMLElement(System.Xml.XmlElement node, ref LabratoryDetails lab)
|
||||
{
|
||||
if (Enum.TryParse(node.Name, out Fields field))
|
||||
{
|
||||
switch (field)
|
||||
{
|
||||
case Fields.Version:
|
||||
lab.Version = int.Parse(node.InnerText, System.Globalization.CultureInfo.InvariantCulture);
|
||||
break;
|
||||
case Fields.Name:
|
||||
lab.Name = node.InnerText;
|
||||
break;
|
||||
case Fields.LocalOnly:
|
||||
lab.LocalOnly = Convert.ToBoolean(node.InnerText);
|
||||
break;
|
||||
case Fields.LastModifiedBy:
|
||||
lab.LastModifiedBy = node.InnerText;
|
||||
break;
|
||||
case Fields.LastModified:
|
||||
lab.LastModified = DateTime.Parse(node.InnerText,
|
||||
System.Globalization.CultureInfo.InvariantCulture);
|
||||
break;
|
||||
case Fields.LaboratoryTestRefNumber:
|
||||
lab.LabratoryTestRefNumber = node.InnerText;
|
||||
break;
|
||||
case Fields.LaboratoryProjectRefNumber:
|
||||
lab.LabratoryProjectRefNumber = node.InnerText;
|
||||
break;
|
||||
case Fields.LaboratoryName:
|
||||
lab.LabratoryName = node.InnerText;
|
||||
break;
|
||||
case Fields.LaboratoryContactPhone:
|
||||
lab.LabratoryContactPhone = node.InnerText;
|
||||
break;
|
||||
case Fields.LaboratoryContactName:
|
||||
lab.LabratoryContactName = node.InnerText;
|
||||
break;
|
||||
case Fields.LaboratoryContactFax:
|
||||
lab.LabratoryContactFax = node.InnerText;
|
||||
break;
|
||||
case Fields.LaboratoryContactEmail:
|
||||
lab.LabratoryContactEmail = node.InnerText;
|
||||
break;
|
||||
default:
|
||||
throw new NotSupportedException("LabratoryDetails::ProcessXMLElement unsupported field: " +
|
||||
field.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void DeleteLabratoryDetails()
|
||||
{
|
||||
try
|
||||
{
|
||||
var errorNumber = DTS.Common.Storage.DbOperations.LabratoryDetailsDelete(null, out string errorMessage);
|
||||
|
||||
if (errorNumber != 0)
|
||||
{
|
||||
//APILogger.Log("Failed to delete labratory details", errorMessage);
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
//APILogger.Log("Failed to delete laboratory details", ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public LabratoryDetails()
|
||||
{
|
||||
}
|
||||
public LabratoryDetails(DataRow dr)
|
||||
{
|
||||
_name = (string)dr["Name"];
|
||||
LabratoryName = (string)dr["LabratoryName"];
|
||||
LabratoryContactName = (string)dr["LabratoryContactName"];
|
||||
LabratoryContactPhone = (string)dr["LabratoryContactPhone"];
|
||||
LabratoryContactFax = (string)dr["LabratoryContactFax"];
|
||||
LabratoryContactEmail = (string)dr["LabratoryContactEmail"];
|
||||
LabratoryTestRefNumber = (string)dr["LabratoryTestRefNumber"];
|
||||
LabratoryProjectRefNumber = (string)dr["LabratoryProjectRefNumber"];
|
||||
_lastModified = Convert.ToDateTime(dr["LastModified"]);
|
||||
_lastModifiedBy = (string)dr["LastModifiedBy"];
|
||||
_localOnly = Convert.ToBoolean(dr["LocalOnly"]);
|
||||
_version = Convert.ToInt32(dr["Version"]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,137 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Data.SqlClient;
|
||||
using System.Linq;
|
||||
|
||||
namespace DatabaseImport
|
||||
{
|
||||
public class SensorCalibrationList
|
||||
{
|
||||
private static List<SensorCalibration> _cachedCalibrations = null;
|
||||
protected SensorCalibrationList()
|
||||
{
|
||||
//removed code that appeared it would never work? (wrong parameters to sql sp)
|
||||
}
|
||||
private readonly Dictionary<string, List<SensorCalibration>> _calibrations;
|
||||
private static readonly object LOCK = new object();
|
||||
|
||||
private static SensorCalibrationList _calibrationList;
|
||||
public static void Reload()
|
||||
{
|
||||
lock (LOCK)
|
||||
{
|
||||
_calibrationList = new SensorCalibrationList();
|
||||
}
|
||||
}
|
||||
public static SensorCalibration GetLatestCalibrationBySerialNumberAndExcitation(SensorData sd, ExcitationVoltageOptions.ExcitationVoltageOption exc)
|
||||
{
|
||||
if (null == sd) { return null; }
|
||||
if (sd.IsDigitalInput() || sd.IsSquib() || sd.IsDigitalOutput()) { return SensorCalibration.NewDigitalSC(); }
|
||||
if (null != _cachedCalibrations)
|
||||
{
|
||||
var matches = from sc in _cachedCalibrations where sc.SerialNumber == sd.SerialNumber select sc;
|
||||
var sensorCalibrations = matches as SensorCalibration[] ?? matches.ToArray();
|
||||
if (sensorCalibrations.Any())
|
||||
{
|
||||
SensorCalibration cal = null;
|
||||
|
||||
foreach (var sc in sensorCalibrations)
|
||||
{
|
||||
if (sc.IsProportional)
|
||||
{
|
||||
var bOk = Array.Exists(sc.Records.Records, record => record.Excitation == exc);
|
||||
|
||||
if (!bOk) { continue; }
|
||||
}
|
||||
if (null == cal) { cal = sc; }
|
||||
else if (sc.CalibrationDate > cal.CalibrationDate) { cal = sc; }
|
||||
else if (sc.CalibrationDate == cal.CalibrationDate && sc.ModifyDate > cal.ModifyDate)
|
||||
{
|
||||
cal = sc;
|
||||
}
|
||||
}
|
||||
if (null != cal) { return cal; }
|
||||
}
|
||||
}
|
||||
lock (LOCK)
|
||||
{
|
||||
if (null == _calibrationList)
|
||||
{
|
||||
_calibrationList = new SensorCalibrationList();
|
||||
}
|
||||
if (!_calibrationList._calibrations.ContainsKey(sd.SerialNumber) || _calibrationList._calibrations[sd.SerialNumber].Count <= 0) return null;
|
||||
try
|
||||
{
|
||||
var list = _calibrationList._calibrations[sd.SerialNumber];
|
||||
list.Sort();
|
||||
foreach (var sc in list)
|
||||
{
|
||||
if (!sc.IsProportional) { return new SensorCalibration(sc); }
|
||||
if (Array.Exists(sc.Records.Records, record => record.Excitation == exc))
|
||||
{
|
||||
return new SensorCalibration(sc);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception) {/* APILogger.Log(ex);*/ }
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
// /// <summary>
|
||||
// /// deletes all calibration data
|
||||
// /// originally created so TDM imports could clear all tables except DAS tables
|
||||
// /// </summary>
|
||||
public static void DeleteAll()
|
||||
{
|
||||
try
|
||||
{
|
||||
using (var cmd = DbOperations.GetSQLCommand(true))
|
||||
{
|
||||
try
|
||||
{
|
||||
cmd.CommandType = CommandType.StoredProcedure;
|
||||
cmd.CommandText = DbOperationsEnum.StoredProcedure.sp_SensorCalibrationsDelete.ToString();
|
||||
|
||||
#region params
|
||||
|
||||
cmd.Parameters.Add(new SqlParameter("@SensorSerialNumber", SqlDbType.Int) { Value = null });
|
||||
cmd.Parameters.Add(new SqlParameter("@CalibrationDate", SqlDbType.DateTime) { Value = null });
|
||||
cmd.Parameters.Add(new SqlParameter("@ModifiedDate", SqlDbType.DateTime) { Value = null });
|
||||
var errorNumberParam =
|
||||
new SqlParameter("@errorNumber", SqlDbType.Int) { Direction = ParameterDirection.Output };
|
||||
cmd.Parameters.Add(errorNumberParam);
|
||||
var errorMessageParam =
|
||||
new SqlParameter("@errorMessage", SqlDbType.NVarChar, 250)
|
||||
{
|
||||
Direction = ParameterDirection.Output
|
||||
};
|
||||
cmd.Parameters.Add(errorMessageParam);
|
||||
|
||||
#endregion params
|
||||
|
||||
cmd.ExecuteNonQuery();
|
||||
if (int.Parse(errorNumberParam.Value.ToString()) != 0)
|
||||
{
|
||||
//errorMessageParam.Value
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
cmd.Connection.Dispose();
|
||||
}
|
||||
}
|
||||
lock (LOCK)
|
||||
{
|
||||
if (null == _calibrationList)
|
||||
{
|
||||
_calibrationList = new SensorCalibrationList();
|
||||
}
|
||||
_calibrationList._calibrations.Clear();
|
||||
}
|
||||
}
|
||||
catch (Exception) {/* APILogger.Log("Failed to delete sensor calibrations ", ex); */}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user