init
This commit is contained in:
@@ -0,0 +1,98 @@
|
||||
/* Copyright 2017 Diversified Technical Systems
|
||||
*/
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace DatabaseImport
|
||||
{
|
||||
/// <summary>
|
||||
/// this class will probably become an abstract base class in the future but for now since we only have
|
||||
/// summed realtime channels, we can be a little less formal
|
||||
/// </summary>
|
||||
public class CalculatedValueClass
|
||||
{
|
||||
public CalculatedValueClass(System.Data.DataRow dr)
|
||||
{
|
||||
var fields = Enum.GetValues(typeof(DbOperations.CalculatedChannels.Fields))
|
||||
.Cast<DbOperations.CalculatedChannels.Fields>().ToArray();
|
||||
|
||||
foreach (var field in fields)
|
||||
{
|
||||
var o = dr[field.ToString()];
|
||||
if (DBNull.Value.Equals(o)) { continue; }
|
||||
switch (field)
|
||||
{
|
||||
case DbOperations.CalculatedChannels.Fields.TestSetupName:
|
||||
TestSetupName = Convert.ToString(o);
|
||||
break;
|
||||
case DbOperations.CalculatedChannels.Fields.Operation:
|
||||
Operation = (Operations)Convert.ToInt32(o);
|
||||
break;
|
||||
case DbOperations.CalculatedChannels.Fields.InputChannelIds:
|
||||
InputChannelIdsBlob = (byte[])o;
|
||||
break;
|
||||
case DbOperations.CalculatedChannels.Fields.Id:
|
||||
Id = Convert.ToInt32(o);
|
||||
break;
|
||||
case DbOperations.CalculatedChannels.Fields.CFCForOutput:
|
||||
ChannelFilterClassForOutput = Convert.ToString(o);
|
||||
break;
|
||||
case DbOperations.CalculatedChannels.Fields.CFCForInputChannels:
|
||||
CFCForInputChannels = Convert.ToString(o);
|
||||
break;
|
||||
case DbOperations.CalculatedChannels.Fields.CCName:
|
||||
Name = Convert.ToString(o);
|
||||
break;
|
||||
case DbOperations.CalculatedChannels.Fields.CalculatedChannelValueCode:
|
||||
CalculatedValueCode = Convert.ToString(o);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int Id { get; set; } = -1;
|
||||
|
||||
public enum Operations
|
||||
{
|
||||
SUM = 1,
|
||||
AVERAGE = 2,
|
||||
IRTRACC3D = 3,
|
||||
IRTRACC3D_ABDOMEN = 4,
|
||||
IRTRACC3D_LOWERTHORAX = 5
|
||||
}
|
||||
|
||||
public Operations Operation { get; set; } = Operations.SUM;
|
||||
|
||||
public string CalculatedValueCode { get; set; } = "???????????????X";
|
||||
|
||||
private List<string> _inputChannelIds = new List<string>();
|
||||
public string[] InputChannelIds
|
||||
{
|
||||
get => _inputChannelIds.ToArray();
|
||||
set => _inputChannelIds = new List<string>(value);
|
||||
}
|
||||
public byte[] InputChannelIdsBlob
|
||||
{
|
||||
get
|
||||
{
|
||||
var text = string.Join(System.Globalization.CultureInfo.InvariantCulture.TextInfo.ListSeparator, InputChannelIds);
|
||||
return System.Text.Encoding.UTF8.GetBytes(text);
|
||||
}
|
||||
set
|
||||
{
|
||||
_inputChannelIds.Clear();
|
||||
var text = System.Text.Encoding.UTF8.GetString(value);
|
||||
InputChannelIds = text.Split(new[] { System.Globalization.CultureInfo.InvariantCulture.TextInfo.ListSeparator }, StringSplitOptions.None);
|
||||
}
|
||||
}
|
||||
|
||||
public string CFCForInputChannels { get; set; } = "";
|
||||
|
||||
public string ChannelFilterClassForOutput { get; set; } = "";
|
||||
|
||||
public string TestSetupName { get; set; }
|
||||
|
||||
public string Name { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,186 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Data;
|
||||
using System.Data.SqlClient;
|
||||
|
||||
namespace DatabaseImport.ISO
|
||||
{
|
||||
[Serializable]
|
||||
public class CustomerDetails //: ISerializableFile
|
||||
{
|
||||
// #region properties
|
||||
public string CustomerName { get; set; } = string.Empty;
|
||||
public string CustomerTestRefNumber { get; set; } = string.Empty;
|
||||
|
||||
private string _projectRefNumber = "NOVALUE";
|
||||
public string ProjectRefNumber
|
||||
{
|
||||
get => _projectRefNumber;
|
||||
set
|
||||
{
|
||||
if (value != string.Empty)
|
||||
{
|
||||
_projectRefNumber = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private string _customerOrderNumber = "NOVALUE";
|
||||
public string CustomerOrderNumber
|
||||
{
|
||||
get => _customerOrderNumber;
|
||||
set
|
||||
{
|
||||
if (value != string.Empty)
|
||||
{
|
||||
_customerOrderNumber = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private string _customerCostUnit = "NOVALUE";
|
||||
public string CustomerCostUnit
|
||||
{
|
||||
get => _customerCostUnit;
|
||||
set
|
||||
{
|
||||
if (value != string.Empty)
|
||||
{
|
||||
_customerCostUnit = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
public bool LocalOnly { get; set; } = false;
|
||||
public string Name { get; set; } = "";
|
||||
public DateTime LastModified { get; set; }
|
||||
public string LastModifiedBy { get; set; }
|
||||
public int Version { get; set; } = 1;
|
||||
|
||||
// #endregion properties
|
||||
// #region constructor
|
||||
public CustomerDetails()
|
||||
{
|
||||
}
|
||||
|
||||
// public CustomerDetails(string name, bool localOnly) { Name = name; LocalOnly = localOnly; }
|
||||
|
||||
public CustomerDetails(DataRow dr)
|
||||
{
|
||||
Name = (string)dr["Name"];
|
||||
CustomerName = (string)dr["CustomerName"];
|
||||
CustomerTestRefNumber = (string)dr["CustomerTestRefNumber"];
|
||||
ProjectRefNumber = (string)dr["ProjectRefNumber"];
|
||||
CustomerOrderNumber = (string)dr["CustomerOrderNumber"];
|
||||
CustomerCostUnit = (string)dr["CustomerCostUnit"];
|
||||
LocalOnly = Convert.ToBoolean(dr["LocalOnly"]);
|
||||
LastModified = Convert.ToDateTime(dr["LastModified"]);
|
||||
LastModifiedBy = (string)dr["LastModifiedBy"];
|
||||
Version = Convert.ToInt32(dr["Version"]);
|
||||
}
|
||||
public CustomerDetails(CustomerDetails copy)
|
||||
{
|
||||
Name = copy.Name;
|
||||
CustomerName = copy.CustomerName;
|
||||
CustomerTestRefNumber = copy.CustomerTestRefNumber;
|
||||
ProjectRefNumber = copy.ProjectRefNumber;
|
||||
CustomerOrderNumber = copy.CustomerOrderNumber;
|
||||
CustomerCostUnit = copy.CustomerCostUnit;
|
||||
LocalOnly = copy.LocalOnly;
|
||||
LastModified = copy.LastModified;
|
||||
LastModifiedBy = copy.LastModifiedBy;
|
||||
Version = copy.Version;
|
||||
}
|
||||
// #endregion constructor
|
||||
private enum Fields
|
||||
{
|
||||
Name,
|
||||
CustomerName,
|
||||
CustomerTestRefNumber,
|
||||
ProjectRefNumber,
|
||||
CustomerOrderNumber,
|
||||
CustomerCostUnit,
|
||||
LocalOnly,
|
||||
LastModified,
|
||||
LastModifiedBy,
|
||||
Version
|
||||
}
|
||||
public static CustomerDetails ReadXML(System.Xml.XmlElement root)
|
||||
{
|
||||
var c = new CustomerDetails();
|
||||
|
||||
foreach (var node in root.ChildNodes)
|
||||
{
|
||||
if (node is System.Xml.XmlElement)
|
||||
{
|
||||
ProcessXMLElement(node as System.Xml.XmlElement, ref c);
|
||||
}
|
||||
}
|
||||
return c;
|
||||
}
|
||||
private static void ProcessXMLElement(System.Xml.XmlElement node, ref CustomerDetails c)
|
||||
{
|
||||
if (!Enum.TryParse(node.Name, out Fields field)) return;
|
||||
switch (field)
|
||||
{
|
||||
case Fields.CustomerCostUnit: c.CustomerCostUnit = node.InnerText; break;
|
||||
case Fields.CustomerName: c.CustomerName = node.InnerText; break;
|
||||
case Fields.CustomerOrderNumber: c.CustomerOrderNumber = node.InnerText; break;
|
||||
case Fields.CustomerTestRefNumber: c.CustomerTestRefNumber = node.InnerText; break;
|
||||
case Fields.LastModified: c.LastModified = DateTime.Parse(node.InnerText, System.Globalization.CultureInfo.InvariantCulture); break;
|
||||
case Fields.LastModifiedBy: c.LastModifiedBy = node.InnerText; break;
|
||||
case Fields.LocalOnly: c.LocalOnly = bool.Parse(node.InnerText); break;
|
||||
case Fields.Name: c.Name = node.InnerText; break;
|
||||
case Fields.ProjectRefNumber: c.ProjectRefNumber = node.InnerText; break;
|
||||
case Fields.Version: c.Version = int.Parse(node.InnerText, System.Globalization.CultureInfo.InvariantCulture); break;
|
||||
default: throw new NotSupportedException("ISODll.CustomerDetails::ProcessXMLElement unsupported field: " + field.ToString());
|
||||
}
|
||||
}
|
||||
public void WriteXML(ref System.Xml.XmlWriter writer)
|
||||
{
|
||||
writer.WriteStartElement("CustomerDetail");
|
||||
|
||||
var fields = Enum.GetValues(typeof(Fields)).Cast<Fields>().ToArray();
|
||||
|
||||
foreach (var field in fields)
|
||||
{
|
||||
writer.WriteStartElement(field.ToString());
|
||||
|
||||
switch (field)
|
||||
{
|
||||
case Fields.CustomerCostUnit: writer.WriteString(CustomerCostUnit); break;
|
||||
case Fields.CustomerName: writer.WriteString(CustomerName); break;
|
||||
case Fields.CustomerOrderNumber: writer.WriteString(CustomerOrderNumber); break;
|
||||
case Fields.CustomerTestRefNumber: writer.WriteString(CustomerTestRefNumber); break;
|
||||
case Fields.LastModified: writer.WriteString(LastModified.ToString(System.Globalization.CultureInfo.InvariantCulture)); break;
|
||||
case Fields.LastModifiedBy: writer.WriteString(LastModifiedBy); break;
|
||||
case Fields.LocalOnly: writer.WriteString(LocalOnly.ToString()); break;
|
||||
case Fields.Name: writer.WriteString(Name); break;
|
||||
case Fields.ProjectRefNumber: writer.WriteString(ProjectRefNumber); break;
|
||||
case Fields.Version: writer.WriteString(Version.ToString(System.Globalization.CultureInfo.InvariantCulture)); break;
|
||||
default: throw new NotSupportedException("CustomerDetails::WriteXML unsupported field " + field.ToString());
|
||||
}
|
||||
|
||||
writer.WriteEndElement();
|
||||
}
|
||||
|
||||
writer.WriteEndElement();
|
||||
}
|
||||
|
||||
public static void DeleteCustomerDetails(string name = null)
|
||||
{
|
||||
try
|
||||
{
|
||||
var errorNumber = DTS.Common.Storage.DbOperations.CustomerDetailsDelete(name, out string errorMessage);
|
||||
|
||||
if (errorNumber != 0)
|
||||
{
|
||||
//APILogger.Log("Failed to delete customer details", errorMessage);
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
//APILogger.Log("Failed to delete customer details", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
588
DataPRO/Modules/DatabaseImporter/DatabaseImport/ISO/Hardware.cs
Normal file
588
DataPRO/Modules/DatabaseImporter/DatabaseImport/ISO/Hardware.cs
Normal file
@@ -0,0 +1,588 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Data;
|
||||
using System.ComponentModel;
|
||||
using System.Data.SqlClient;
|
||||
|
||||
namespace DatabaseImport
|
||||
{
|
||||
public class Hardware : INotifyPropertyChanged, IISOHardware
|
||||
{
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
|
||||
protected bool SetProperty<T>(ref T storage, T value, string propertyName = null)
|
||||
{
|
||||
if (Equals(storage, value)) return false;
|
||||
|
||||
storage = value;
|
||||
OnPropertyChanged(propertyName);
|
||||
return true;
|
||||
}
|
||||
|
||||
protected void OnPropertyChanged(string propertyName = null)
|
||||
{
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
||||
}
|
||||
|
||||
public enum ChannelType
|
||||
{
|
||||
Analog,
|
||||
IEPE,
|
||||
Squib,
|
||||
DigitalOutput
|
||||
}
|
||||
|
||||
public static DateTime INVALIDDATE => new DateTime(1970, 1, 1);
|
||||
private string _serialNumber = "";
|
||||
|
||||
public string SerialNumber
|
||||
{
|
||||
get => _serialNumber;
|
||||
set => _serialNumber = value;
|
||||
}
|
||||
|
||||
private int _calInterval = 365;
|
||||
|
||||
public int CalInterval
|
||||
{
|
||||
get => _calInterval;
|
||||
set => _calInterval = value;
|
||||
}
|
||||
|
||||
private int _dasType;
|
||||
|
||||
public int DASType
|
||||
{
|
||||
get => _dasType;
|
||||
set => SetProperty(ref _dasType, value, "DASType");
|
||||
}
|
||||
|
||||
private int _maxModules;
|
||||
|
||||
public int MaxModules
|
||||
{
|
||||
get => _maxModules;
|
||||
set => SetProperty(ref _maxModules, value, "MaxModules");
|
||||
}
|
||||
|
||||
private long _maxMemory;
|
||||
|
||||
public long MaxMemory
|
||||
{
|
||||
get => _maxMemory;
|
||||
set => SetProperty(ref _maxMemory, value, "MaxMemory");
|
||||
}
|
||||
|
||||
private double _minSampleRate;
|
||||
|
||||
public double MinSampleRate
|
||||
{
|
||||
get => _minSampleRate;
|
||||
set => SetProperty(ref _minSampleRate, value, "MinSampleRate");
|
||||
}
|
||||
|
||||
private double _maxSampleRate = 1000000;
|
||||
|
||||
public double MaxSampleRate
|
||||
{
|
||||
get => _maxSampleRate;
|
||||
set => SetProperty(ref _maxSampleRate, value, "MaxSampleRate");
|
||||
}
|
||||
|
||||
private double _maxAAFRate = 200000;
|
||||
|
||||
public double MaxAAFRate
|
||||
{
|
||||
get => _maxAAFRate;
|
||||
set => SetProperty(ref _maxAAFRate, value, "MaxAAFRate");
|
||||
}
|
||||
|
||||
private string _firmwareVersion = "";
|
||||
|
||||
public string FirmwareVersion
|
||||
{
|
||||
get => _firmwareVersion;
|
||||
set => SetProperty(ref _firmwareVersion, value, "FirmwareVersion");
|
||||
}
|
||||
|
||||
private DateTime _calDate = INVALIDDATE;
|
||||
|
||||
public DateTime CalDate
|
||||
{
|
||||
get => _calDate < INVALIDDATE ? INVALIDDATE : _calDate;
|
||||
set => SetProperty(ref _calDate, value, "CalDate");
|
||||
}
|
||||
|
||||
private int _protocolVerison;
|
||||
|
||||
public int ProtocolVersion
|
||||
{
|
||||
get => _protocolVerison;
|
||||
set => SetProperty(ref _protocolVerison, value, "ProtocolVersion");
|
||||
}
|
||||
|
||||
private DateTime _lastModified = DateTime.Now;
|
||||
|
||||
public DateTime LastModified
|
||||
{
|
||||
get => _lastModified;
|
||||
set => SetProperty(ref _lastModified, value, "LastModified");
|
||||
}
|
||||
|
||||
private string _lastModifiedBy = "";
|
||||
|
||||
public string LastModifiedBy
|
||||
{
|
||||
get => _lastModifiedBy;
|
||||
set => SetProperty(ref _lastModifiedBy, value, "LastModifiedBy");
|
||||
}
|
||||
|
||||
private int _version = 1;
|
||||
|
||||
public int Version
|
||||
{
|
||||
get => _version;
|
||||
set => SetProperty(ref _version, value, "Version");
|
||||
}
|
||||
|
||||
private bool _bLocalOnly;
|
||||
|
||||
public bool LocalOnly
|
||||
{
|
||||
get => _bLocalOnly;
|
||||
set => SetProperty(ref _bLocalOnly, value, "LocalOnly");
|
||||
}
|
||||
|
||||
private DateTime _lastUsed = INVALIDDATE;
|
||||
|
||||
public DateTime LastUsed
|
||||
{
|
||||
get => _lastUsed;
|
||||
set => SetProperty(ref _lastUsed, value, "LastUsed");
|
||||
}
|
||||
|
||||
private string _lastUsedBy = "";
|
||||
|
||||
public string LastUsedBy
|
||||
{
|
||||
get => _lastUsedBy;
|
||||
set => SetProperty(ref _lastUsedBy, value, "LastUsedBy");
|
||||
}
|
||||
|
||||
private string _ipAddress = "";
|
||||
|
||||
public string IPAddress
|
||||
{
|
||||
get => _ipAddress;
|
||||
set => SetProperty(ref _ipAddress, value, "IPAddress");
|
||||
}
|
||||
|
||||
private int _channels;
|
||||
|
||||
public int Channels
|
||||
{
|
||||
get => _channels;
|
||||
set => SetProperty(ref _channels, value, "Channels");
|
||||
}
|
||||
|
||||
private string _position = "";
|
||||
|
||||
public string Position
|
||||
{
|
||||
get => _position;
|
||||
set => SetProperty(ref _position, value, "Position");
|
||||
}
|
||||
|
||||
private bool _isProgrammable;
|
||||
|
||||
public bool IsProgrammable
|
||||
{
|
||||
get => _isProgrammable;
|
||||
set => SetProperty(ref _isProgrammable, value, "IsProgrammable");
|
||||
}
|
||||
|
||||
private bool _isModule;
|
||||
|
||||
public bool IsModule
|
||||
{
|
||||
get => _isModule;
|
||||
set => SetProperty(ref _isModule, value, "IsModule");
|
||||
}
|
||||
|
||||
private bool _isReconfigurable;
|
||||
|
||||
public bool IsReconfigurable
|
||||
{
|
||||
get => _isReconfigurable;
|
||||
set => SetProperty(ref _isReconfigurable, value, "IsReconfigurable");
|
||||
}
|
||||
|
||||
private int[] _channelTypes;
|
||||
|
||||
public int[] ChannelTypes
|
||||
{
|
||||
get => _channelTypes ?? (_channelTypes = new int[0]);
|
||||
set => SetProperty(ref _channelTypes, value, "ChannelTypes");
|
||||
}
|
||||
|
||||
public string ParentDAS { get; set; } = "";
|
||||
|
||||
public int Port { get; set; }
|
||||
public int PositionOnChain { get; set; }
|
||||
public int PositionOnDistributor { get; set; }
|
||||
|
||||
public Hardware()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public Hardware(Hardware copy)
|
||||
{
|
||||
Version = copy.Version;
|
||||
SerialNumber = copy.SerialNumber;
|
||||
ProtocolVersion = copy.ProtocolVersion;
|
||||
Position = copy.Position;
|
||||
MinSampleRate = copy.MinSampleRate;
|
||||
MaxSampleRate = copy.MaxSampleRate;
|
||||
MaxModules = copy.MaxModules;
|
||||
MaxMemory = copy.MaxMemory;
|
||||
LocalOnly = copy.LocalOnly;
|
||||
LastUsedBy = copy.LastUsedBy;
|
||||
LastUsed = copy.LastUsed;
|
||||
LastModifiedBy = copy.LastModifiedBy;
|
||||
LastModified = copy.LastModified;
|
||||
IsReconfigurable = copy.IsReconfigurable;
|
||||
IsProgrammable = copy.IsProgrammable;
|
||||
ISOChannels = copy.ISOChannels.Select(c => new ISO.HardwareChannel(c, this)).ToArray();
|
||||
IPAddress = copy.IPAddress;
|
||||
FirmwareVersion = copy.FirmwareVersion;
|
||||
DASType = copy.DASType;
|
||||
var channeltypes = new int[copy.ChannelTypes.Length];
|
||||
Array.Copy(copy.ChannelTypes, channeltypes, copy.ChannelTypes.Length);
|
||||
ChannelTypes = channeltypes;
|
||||
Channels = copy.Channels;
|
||||
CalInterval = copy.CalInterval;
|
||||
CalDate = copy.CalDate;
|
||||
IsModule = copy.IsModule;
|
||||
ParentDAS = copy.ParentDAS;
|
||||
PositionOnChain = copy.PositionOnChain;
|
||||
PositionOnDistributor = copy.PositionOnDistributor;
|
||||
Port = copy.Port;
|
||||
}
|
||||
|
||||
public Hardware(IDataRecord reader)
|
||||
{
|
||||
|
||||
CalDate = Convert.ToDateTime(reader[DbOperations.DAS.Fields.CalDate.ToString()]);
|
||||
Channels = Convert.ToInt32(reader[DbOperations.DAS.Fields.Channels.ToString()]);
|
||||
IPAddress = Convert.ToString(reader[DbOperations.DAS.Fields.Connection.ToString()]);
|
||||
FirmwareVersion = Convert.ToString(reader[DbOperations.DAS.Fields.FirmwareVersion.ToString()]);
|
||||
LastModified = Convert.ToDateTime(reader[DbOperations.DAS.Fields.LastModified.ToString()]);
|
||||
LastModifiedBy = Convert.ToString(reader[DbOperations.DAS.Fields.LastModifiedBy.ToString()]);
|
||||
LastUsed = Convert.ToDateTime(reader[DbOperations.DAS.Fields.LastUsed.ToString()]);
|
||||
LastUsedBy = Convert.ToString(reader[DbOperations.DAS.Fields.LastUsedBy.ToString()]);
|
||||
LocalOnly = Convert.ToBoolean(reader[DbOperations.DAS.Fields.LocalOnly.ToString()]);
|
||||
MaxMemory = Convert.ToInt64(reader[DbOperations.DAS.Fields.MaxMemory.ToString()]);
|
||||
MaxModules = Convert.ToInt32(reader[DbOperations.DAS.Fields.MaxModules.ToString()]);
|
||||
MaxSampleRate = Convert.ToDouble(reader[DbOperations.DAS.Fields.MaxSampleRate.ToString()]);
|
||||
MinSampleRate = Convert.ToDouble(reader[DbOperations.DAS.Fields.MinSampleRate.ToString()]);
|
||||
Position = Convert.ToString(reader[DbOperations.DAS.Fields.Position.ToString()]);
|
||||
IsReconfigurable = Convert.ToBoolean(reader[DbOperations.DAS.Fields.Reconfigurable.ToString()]);
|
||||
IsModule = Convert.ToBoolean(reader[DbOperations.DAS.Fields.IsModule.ToString()]);
|
||||
IsProgrammable = Convert.ToBoolean(reader[DbOperations.DAS.Fields.Reprogramable.ToString()]);
|
||||
ProtocolVersion = Convert.ToInt32(reader[DbOperations.DAS.Fields.ProtocolVersion.ToString()]);
|
||||
SerialNumber = Convert.ToString(reader[DbOperations.DAS.Fields.SerialNumber.ToString()]);
|
||||
DASType = Convert.ToInt32(reader[DbOperations.DAS.Fields.Type.ToString()]);
|
||||
|
||||
if (reader[DbOperations.DAS.Fields.ChannelTypes.ToString()] != null)
|
||||
{
|
||||
var tokens =
|
||||
(reader[DbOperations.DAS.Fields.ChannelTypes.ToString()] as string).Split(',');
|
||||
var itemp = 0;
|
||||
ChannelTypes = (from token in tokens where int.TryParse(token, out itemp) select itemp).ToArray();
|
||||
}
|
||||
Version = Convert.ToInt32(reader[DbOperations.DAS.Fields.Version.ToString()]);
|
||||
ParentDAS = Convert.ToString(reader[DbOperations.DAS.Fields.ParentDAS.ToString()]);
|
||||
|
||||
Port = reader[DbOperations.DAS.Fields.Port.ToString()] is DBNull
|
||||
? 0
|
||||
: Convert.ToInt32(reader[DbOperations.DAS.Fields.Port.ToString()]);
|
||||
|
||||
PositionOnChain = Convert.ToInt32(reader[DbOperations.DAS.Fields.PositionOnChain.ToString()]);
|
||||
PositionOnDistributor = Convert.ToInt32(reader[DbOperations.DAS.Fields.PositionOnDistributor.ToString()]);
|
||||
}
|
||||
|
||||
public static List<ISO.HardwareChannel> GetDASISOChannels(string hardwareId, Hardware das)
|
||||
{
|
||||
var channelList = new List<ISO.HardwareChannel>();
|
||||
|
||||
using (var cmd = DbOperations.GetSQLCommand(true))
|
||||
{
|
||||
try
|
||||
{
|
||||
cmd.CommandType = CommandType.StoredProcedure;
|
||||
cmd.CommandText = DbOperationsEnum.StoredProcedure.sp_DASChannelsGet.ToString();
|
||||
|
||||
#region params
|
||||
|
||||
cmd.Parameters.Add(new SqlParameter("@HardwareId", SqlDbType.NVarChar) { Value = hardwareId });
|
||||
|
||||
#endregion params
|
||||
|
||||
using (var readerISOChannels = cmd.ExecuteReader())
|
||||
{
|
||||
while (readerISOChannels.Read())
|
||||
{
|
||||
channelList.Add(new ISO.HardwareChannel(readerISOChannels, das));
|
||||
}
|
||||
readerISOChannels.Close();
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
cmd.Connection.Dispose();
|
||||
}
|
||||
}
|
||||
channelList.Sort(ISO.HardwareChannel.PhysicalCompare);
|
||||
return channelList;
|
||||
}
|
||||
|
||||
private static void GetAllDASISOChannels(Dictionary<string, Hardware> serialNumberToHardware)
|
||||
{
|
||||
var channelsByDASKey = new Dictionary<string, List<ISO.HardwareChannel>>();
|
||||
|
||||
using (var cmd = DbOperations.GetSQLCommand(true))
|
||||
{
|
||||
try
|
||||
{
|
||||
cmd.CommandType = CommandType.StoredProcedure;
|
||||
cmd.CommandText = DbOperationsEnum.StoredProcedure.sp_DASChannelsGet.ToString();
|
||||
|
||||
#region params
|
||||
|
||||
cmd.Parameters.Add(new SqlParameter("@HardwareId", SqlDbType.NVarChar) { Value = null });
|
||||
|
||||
#endregion params
|
||||
|
||||
using (var readerISOChannels = cmd.ExecuteReader())
|
||||
{
|
||||
while (readerISOChannels.Read())
|
||||
{
|
||||
var serialNumber = Convert.ToString(readerISOChannels["HardwareId"]);
|
||||
if (!serialNumberToHardware.ContainsKey(serialNumber))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
var hardware = serialNumberToHardware[serialNumber];
|
||||
var hc = new ISO.HardwareChannel(readerISOChannels, hardware);
|
||||
if (!channelsByDASKey.ContainsKey(serialNumber))
|
||||
{
|
||||
channelsByDASKey[serialNumber] = new List<ISO.HardwareChannel>();
|
||||
}
|
||||
channelsByDASKey[serialNumber].Add(hc);
|
||||
}
|
||||
readerISOChannels.Close();
|
||||
}
|
||||
using (var enumHardware = serialNumberToHardware.GetEnumerator())
|
||||
{
|
||||
while (enumHardware.MoveNext())
|
||||
{
|
||||
var hardware = enumHardware.Current.Value;
|
||||
if (!channelsByDASKey.ContainsKey(enumHardware.Current.Key))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
var list = channelsByDASKey[enumHardware.Current.Key];
|
||||
list.Sort(ISO.HardwareChannel.PhysicalCompare);
|
||||
hardware.ISOChannels = list.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
cmd.Connection.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private List<ISO.HardwareChannel> _isoChannels = new List<ISO.HardwareChannel>();
|
||||
|
||||
public ISO.HardwareChannel[] ISOChannels
|
||||
{
|
||||
get => _isoChannels.ToArray();
|
||||
set => SetProperty(ref _isoChannels, new List<ISO.HardwareChannel>(value), "ISOChannels");
|
||||
}
|
||||
|
||||
public static Hardware[] GetSingleDAS(string serialNumber, string position)
|
||||
{
|
||||
var list = new List<Hardware>();
|
||||
try
|
||||
{
|
||||
|
||||
using (var cmd = DbOperations.GetSQLCommand(true))
|
||||
{
|
||||
try
|
||||
{
|
||||
cmd.CommandType = CommandType.StoredProcedure;
|
||||
cmd.CommandText = DbOperationsEnum.StoredProcedure.sp_DASGet.ToString();
|
||||
|
||||
#region params
|
||||
|
||||
cmd.Parameters.Add(
|
||||
new SqlParameter("@SerialNumber", SqlDbType.NVarChar) { Value = serialNumber });
|
||||
cmd.Parameters.Add(new SqlParameter("@position", SqlDbType.NVarChar)
|
||||
{
|
||||
Value = string.IsNullOrEmpty(position) ? null : position
|
||||
});
|
||||
|
||||
#endregion params
|
||||
|
||||
using (var readerDAS = cmd.ExecuteReader())
|
||||
{
|
||||
while (readerDAS.Read())
|
||||
{
|
||||
list.Add(new Hardware(readerDAS));
|
||||
}
|
||||
readerDAS.Close();
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
cmd.Connection.Dispose();
|
||||
}
|
||||
}
|
||||
foreach (var das in list)
|
||||
{
|
||||
var channels = GetDASISOChannels(das.SerialNumber, das);
|
||||
channels.Sort(ISO.HardwareChannel.PhysicalCompare);
|
||||
das.ISOChannels = channels.ToArray();
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
/*APILogger.Log("failed to retrieve all das, ", ex); */
|
||||
}
|
||||
list.Sort(new HardwareCompare());
|
||||
return list.ToArray();
|
||||
}
|
||||
|
||||
public static Hardware[] GetAllDAS(string serialNumber, string position)
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(serialNumber))
|
||||
{
|
||||
return GetSingleDAS(serialNumber, position);
|
||||
}
|
||||
var list = new List<Hardware>();
|
||||
try
|
||||
{
|
||||
using (var cmd = DbOperations.GetSQLCommand(true))
|
||||
{
|
||||
try
|
||||
{
|
||||
cmd.CommandType = CommandType.StoredProcedure;
|
||||
cmd.CommandText = DbOperationsEnum.StoredProcedure.sp_DASGet.ToString();
|
||||
|
||||
#region params
|
||||
|
||||
cmd.Parameters.Add(new SqlParameter("@SerialNumber", SqlDbType.NVarChar)
|
||||
{
|
||||
Value = string.IsNullOrEmpty(serialNumber) ? null : serialNumber
|
||||
});
|
||||
cmd.Parameters.Add(new SqlParameter("@position", SqlDbType.NVarChar)
|
||||
{
|
||||
Value = string.IsNullOrEmpty(position) ? null : position
|
||||
});
|
||||
|
||||
#endregion params
|
||||
|
||||
using (var readerDAS = cmd.ExecuteReader())
|
||||
{
|
||||
while (readerDAS.Read())
|
||||
{
|
||||
list.Add(new Hardware(readerDAS));
|
||||
}
|
||||
readerDAS.Close();
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
cmd.Connection.Dispose();
|
||||
}
|
||||
}
|
||||
var serialNumberToDAS = new Dictionary<string, Hardware>();
|
||||
foreach (var das in list)
|
||||
{
|
||||
serialNumberToDAS[$"{das.SerialNumber}_{das.DASType}"] = das;
|
||||
}
|
||||
GetAllDASISOChannels(serialNumberToDAS);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
/*APILogger.Log("failed to retrieve all das, ", ex);*/
|
||||
}
|
||||
list.Sort(new HardwareCompare());
|
||||
return list.ToArray();
|
||||
}
|
||||
|
||||
public class HardwareCompare : Comparer<Hardware>
|
||||
{
|
||||
public override int Compare(Hardware x, Hardware y)
|
||||
{
|
||||
var ret = string.Compare(x.SerialNumber, y.SerialNumber, StringComparison.Ordinal);
|
||||
if (0 == ret)
|
||||
{
|
||||
ret = string.Compare(x.IPAddress, y.IPAddress, StringComparison.Ordinal);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
public void Delete()
|
||||
{
|
||||
using (var cmd = DbOperations.GetSQLCommand(true))
|
||||
{
|
||||
try
|
||||
{
|
||||
cmd.CommandType = CommandType.StoredProcedure;
|
||||
cmd.CommandText = DbOperationsEnum.StoredProcedure.sp_DASDelete.ToString();
|
||||
|
||||
#region params
|
||||
|
||||
cmd.Parameters.Add(new SqlParameter("@SerialNumber", SqlDbType.NVarChar) { Value = SerialNumber });
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public string GetId()
|
||||
{
|
||||
return GetId(SerialNumber, DASType.ToString(), IPAddress);
|
||||
}
|
||||
|
||||
public static string GetId(string sn, string dastype, string ip)
|
||||
{
|
||||
return $"{sn}_{dastype}";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,140 @@
|
||||
using System;
|
||||
using System.Data;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace DatabaseImport.ISO
|
||||
{
|
||||
public class HardwareChannel : INotifyPropertyChanged
|
||||
{
|
||||
#region IPropertyNotified
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
protected bool SetProperty<T>(ref T storage, T value, string propertyName = null)
|
||||
{
|
||||
if (Equals(storage, value)) return false;
|
||||
|
||||
storage = value;
|
||||
OnPropertyChanged(propertyName);
|
||||
return true;
|
||||
}
|
||||
protected void OnPropertyChanged(string propertyName = null)
|
||||
{
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
||||
}
|
||||
#endregion
|
||||
|
||||
private Hardware _parentHardware;
|
||||
public Hardware ParentDAS
|
||||
{
|
||||
get => _parentHardware;
|
||||
set => SetProperty(ref _parentHardware, value, "ParentDAS");
|
||||
}
|
||||
|
||||
private int _supportedBridges = 12;
|
||||
public int SupportedBridges
|
||||
{
|
||||
get => _supportedBridges;
|
||||
set => SetProperty(ref _supportedBridges, value, "SupportedBridges");
|
||||
}
|
||||
|
||||
private int _supportedSquibFireModes = 16;
|
||||
public int SupportedSquibFireModes
|
||||
{
|
||||
get => _supportedSquibFireModes;
|
||||
set => SetProperty(ref _supportedSquibFireModes, value, "SupportedSquibFireModes");
|
||||
}
|
||||
|
||||
private int _supporedExcitations = 16;
|
||||
public int SupportedExcitations
|
||||
{
|
||||
get => _supporedExcitations;
|
||||
set => SetProperty(ref _supporedExcitations, value, "SupportedExcitations");
|
||||
}
|
||||
|
||||
private int _supportedDigitalInputModes = 16;
|
||||
public int SupportedDigitalInputModes
|
||||
{
|
||||
get => _supportedDigitalInputModes;
|
||||
set => SetProperty(ref _supportedDigitalInputModes, value, "SupportedDigitalInputModes");
|
||||
}
|
||||
|
||||
private int _supportedDigitalOutputModes = 16;
|
||||
public int SupportedDigitalOutputModes
|
||||
{
|
||||
get => _supportedDigitalOutputModes;
|
||||
set => SetProperty(ref _supportedDigitalOutputModes, value, "SupportedDigitalOutputModes");
|
||||
}
|
||||
|
||||
private int _channelIdx;
|
||||
public int ChannelIdx
|
||||
{
|
||||
get => _channelIdx;
|
||||
set => SetProperty(ref _channelIdx, value, "ChannelIdx");
|
||||
}
|
||||
|
||||
private int _dasDisplayOrder;
|
||||
public int DASDisplayOrder
|
||||
{
|
||||
get => _dasDisplayOrder;
|
||||
set => _dasDisplayOrder = value;
|
||||
}
|
||||
|
||||
private string _moduleSerialNumber = "";
|
||||
public string ModuleSerialNumber
|
||||
{
|
||||
get => _moduleSerialNumber;
|
||||
set => SetProperty(ref _moduleSerialNumber, value, "ModuleSerialNumber");
|
||||
}
|
||||
|
||||
private int _moduleArrayIndex;
|
||||
public int ModuleArrayIndex
|
||||
{
|
||||
get => _moduleArrayIndex;
|
||||
set => _moduleArrayIndex = value;
|
||||
}
|
||||
|
||||
// public HardwareChannel() { }
|
||||
public HardwareChannel(HardwareChannel copy, Hardware h)
|
||||
{
|
||||
SupportedSquibFireModes = copy.SupportedSquibFireModes;
|
||||
SupportedExcitations = copy.SupportedExcitations;
|
||||
SupportedDigitalOutputModes = copy.SupportedDigitalOutputModes;
|
||||
SupportedDigitalInputModes = copy.SupportedDigitalInputModes;
|
||||
SupportedBridges = copy.SupportedBridges;
|
||||
ParentDAS = h;
|
||||
LocalOnly = copy.LocalOnly;
|
||||
DASDisplayOrder = copy.DASDisplayOrder;
|
||||
ChannelIdx = copy.ChannelIdx;
|
||||
ModuleArrayIndex = copy.ModuleArrayIndex;
|
||||
_moduleSerialNumber = copy.ModuleSerialNumber;
|
||||
}
|
||||
public HardwareChannel(IDataRecord reader, Hardware hardware)
|
||||
{
|
||||
ParentDAS = hardware;
|
||||
|
||||
ChannelIdx = Convert.ToInt32(reader[DbOperations.DAS.DASChannelFields.ChannelIdx.ToString()]);
|
||||
SupportedBridges = Convert.ToInt32(reader[DbOperations.DAS.DASChannelFields.SupportedBridges.ToString()]);
|
||||
SupportedExcitations = Convert.ToInt32(reader[DbOperations.DAS.DASChannelFields.SupportedExcitations.ToString()]);
|
||||
SupportedDigitalInputModes = Convert.ToInt32(reader[DbOperations.DAS.DASChannelFields.SupportedDigitalInputModes.ToString()]);
|
||||
SupportedDigitalOutputModes = Convert.ToInt32(reader[DbOperations.DAS.DASChannelFields.SupportedDigitalOutputModes.ToString()]);
|
||||
SupportedSquibFireModes = Convert.ToInt32(reader[DbOperations.DAS.DASChannelFields.SupportedSquibFireModes.ToString()]);
|
||||
DASDisplayOrder = Convert.ToInt32(reader[DbOperations.DAS.DASChannelFields.DASDisplayOrder.ToString()]);
|
||||
ModuleSerialNumber = reader[DbOperations.DAS.DASChannelFields.ModuleSerialNumber.ToString()] as string;
|
||||
LocalOnly = Convert.ToBoolean(reader[DbOperations.DAS.DASChannelFields.LocalOnly.ToString()]);
|
||||
ModuleArrayIndex = Convert.ToInt32(reader[DbOperations.DAS.DASChannelFields.ModuleArrayIndex.ToString()]);
|
||||
|
||||
}
|
||||
private bool _bLocalOnly;
|
||||
public bool LocalOnly
|
||||
{
|
||||
get => _bLocalOnly;
|
||||
set => SetProperty(ref _bLocalOnly, value, "LocalOnly");
|
||||
}
|
||||
|
||||
public static int PhysicalCompare(HardwareChannel left, HardwareChannel right)
|
||||
{
|
||||
if (left == right) { return 0; }
|
||||
if (null == left) { return -1; }
|
||||
return null == right ? 1 : left.ChannelIdx.CompareTo(right.ChannelIdx);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,423 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace DatabaseImport
|
||||
{
|
||||
/// <summary>
|
||||
/// this is a helper class wrapping access to the iso13499 access db
|
||||
/// it also now makes use of datapro database tables which mimic the access db
|
||||
/// </summary>
|
||||
public class ISO13499FileDb
|
||||
{
|
||||
public class ExpiredISOFieldException : Exception
|
||||
{
|
||||
public ExpiredISOFieldException(string remark) : base(remark) { }
|
||||
}
|
||||
/// <summary>
|
||||
/// list of directions, populated when first loaded
|
||||
/// </summary>
|
||||
private readonly Dictionary<string, MMEDirections> _directionsDictionary = new Dictionary<string, MMEDirections>();
|
||||
/// <summary>
|
||||
/// list of filter classes, populated when first loaded
|
||||
/// </summary>
|
||||
private readonly Dictionary<string, MMEFilterClasses> _filterClassesDictionary = new Dictionary<string, MMEFilterClasses>();
|
||||
/// <summary>
|
||||
/// list of figures, populated when first loaded
|
||||
/// </summary>
|
||||
private readonly List<MMEFigures> _figures = new List<MMEFigures>();
|
||||
/// <summary>
|
||||
/// list of all known fine 1 locations, populated when first loaded
|
||||
/// </summary>
|
||||
private readonly Dictionary<string, MMEFineLocations1> _fineLoc1Dictionary = new Dictionary<string, MMEFineLocations1>();
|
||||
/// <summary>
|
||||
/// list of all known fine 2 locations, populated when first loaded
|
||||
/// </summary>
|
||||
private readonly Dictionary<string, MMEFineLocations2> _fineLoc2Dictionary = new Dictionary<string, MMEFineLocations2>();
|
||||
/// <summary>
|
||||
/// list of all known fine 3 locations, populated when first loaded
|
||||
/// </summary>
|
||||
private readonly Dictionary<string, MMEFineLocations3> _fineLoc3Dictionary = new Dictionary<string, MMEFineLocations3>();
|
||||
/// <summary>
|
||||
/// list of all known physical dimensions, populated when first loaded
|
||||
/// </summary>
|
||||
private readonly Dictionary<string, MMEPhysicalDimensions> _physicalDimensionsDictionary = new Dictionary<string, MMEPhysicalDimensions>();
|
||||
/// <summary>
|
||||
/// list of all known positions, populated when first loaded
|
||||
/// </summary>
|
||||
private readonly Dictionary<string, MMEPositions> _positionsDictionary = new Dictionary<string, MMEPositions>();
|
||||
/// <summary>
|
||||
/// list of all known possible channels, populated when first loaded
|
||||
/// </summary>
|
||||
private readonly List<MMEPossibleChannels> _possibleChannels = new List<MMEPossibleChannels>();
|
||||
|
||||
private readonly Dictionary<string, List<MMEPossibleChannels>> _possibleChannelsByType =
|
||||
new Dictionary<string, List<MMEPossibleChannels>>();
|
||||
/// <summary>
|
||||
/// list of possible test objects, populated when first loaded
|
||||
/// </summary>
|
||||
private readonly Dictionary<string, MMETestObjects> _testObjectsDictionary = new Dictionary<string, MMETestObjects>();
|
||||
/// <summary>
|
||||
/// list of all possible transducer locations, populated when first loaded
|
||||
/// </summary>
|
||||
private readonly Dictionary<string, MMETransducerMainLocation> _transducerMainLoc = new Dictionary<string, MMETransducerMainLocation>();
|
||||
/// <summary>
|
||||
/// scans all possible channels for unique types, returns the list of unique types
|
||||
/// </summary>
|
||||
private List<string> _uniquePossibleChannelTypes = null;
|
||||
public string[] GetUniquePossibleChannelTypes()
|
||||
{
|
||||
RefreshIfNeeded();
|
||||
if (null != _uniquePossibleChannelTypes) return _uniquePossibleChannelTypes.ToArray();
|
||||
_uniquePossibleChannelTypes = new List<string>();
|
||||
var uniquetypes = (from pc in _possibleChannels where !pc.Expired orderby pc.Text_L1 select pc.Type).Distinct().ToArray();
|
||||
if (uniquetypes.Length > 0)
|
||||
{
|
||||
_uniquePossibleChannelTypes.AddRange(uniquetypes);
|
||||
_uniquePossibleChannelTypes.Sort();
|
||||
}
|
||||
return _uniquePossibleChannelTypes.ToArray();
|
||||
}
|
||||
public string[] GetUniquePossibleChannelTypes(string typeToRemove)
|
||||
{
|
||||
return GetUniquePossibleChannelTypes().Where(uniquePossibleChannelType => !uniquePossibleChannelType.StartsWith(typeToRemove)).ToArray();
|
||||
}
|
||||
private void RefreshIfNeeded()
|
||||
{
|
||||
lock (RefreshLock)
|
||||
{
|
||||
if (!_bLoaded) { RefreshAllData(); }
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// gets a list of all possible channels given a type
|
||||
/// </summary>
|
||||
/// <param name="type"></param>
|
||||
/// <returns></returns>
|
||||
public MMEPossibleChannels[] GetPossibleChannelsForType(string type)
|
||||
{
|
||||
RefreshIfNeeded();
|
||||
if (!_possibleChannelsByType.ContainsKey(type))
|
||||
{
|
||||
return new MMEPossibleChannels[0];
|
||||
}
|
||||
return _possibleChannelsByType[type].ToArray();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// gets the possible channels just from DataPRO exclusive (so excluding ISO13499 origined channels)
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public MMEPossibleChannels[] GetSQLPossibleChannels()
|
||||
{
|
||||
RefreshIfNeeded();
|
||||
var list = (from pc in _possibleChannels.AsParallel() where pc.MMEChannelType == (int)MMEPossibleChannels.MMEChannelTypes.SQL select pc).ToArray();
|
||||
|
||||
if (null != list && list.Any())
|
||||
{
|
||||
return list.Select(li => new MMEPossibleChannels(li)).ToArray();
|
||||
}
|
||||
return new MMEPossibleChannels[0];
|
||||
}
|
||||
public void DeleteSQL()
|
||||
{
|
||||
try
|
||||
{
|
||||
MMEDirections.DeleteDirections();
|
||||
MMEFigures.DeleteFigures();
|
||||
MMEFilterClasses.DeleteFilterClasses();
|
||||
MMEFineLocations1.DeleteFineLocations1();
|
||||
MMEFineLocations2.DeleteFineLocations2();
|
||||
MMEFineLocations3.DeleteFineLocations3();
|
||||
MMEPhysicalDimensions.DeletePhysicalDimensions();
|
||||
MMEPositions.DeletePositions();
|
||||
MMETestObjects.DeleteTestObjects();
|
||||
MMETransducerMainLocation.DeleteTransducerMainLocations();
|
||||
MMEPossibleChannels.DeletePossibleChannels();
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
//APILogger.Log("failure to load ISO tables", ex);
|
||||
}
|
||||
RefreshAllData();
|
||||
}
|
||||
/// <summary>
|
||||
/// gets the "type" field from all possible channels where the channel test object matchines the input string in to
|
||||
/// </summary>
|
||||
/// <param name="to"></param>
|
||||
/// <returns></returns>
|
||||
public string[] GetTestObjectTypeForTestObject(string to)
|
||||
{
|
||||
RefreshIfNeeded();
|
||||
return (from pc in _possibleChannels.AsParallel() where pc.Test_Object == to orderby pc.Type select pc.Type).Distinct().ToArray();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// dictionary of possible channels keyed by id, there's a separate dictionary for iso13499 origined channels
|
||||
/// and DataPRO origined channels
|
||||
/// </summary>
|
||||
private Dictionary<long, MMEPossibleChannels> _mmePossibleChannelsDict = null;
|
||||
private Dictionary<long, MMEPossibleChannels> _mmePossibleChannelsDictOurs = null;
|
||||
public MMEPossibleChannels GetPossibleChannel(long id, int channelType)
|
||||
{
|
||||
RefreshIfNeeded();
|
||||
if (1 == channelType)
|
||||
{
|
||||
if (null == _mmePossibleChannelsDictOurs)
|
||||
{
|
||||
_mmePossibleChannelsDictOurs = new Dictionary<long, MMEPossibleChannels>();
|
||||
foreach (var channel in _possibleChannels)
|
||||
{
|
||||
if (channel.MMEChannelType != channelType) { continue; }
|
||||
if (!_mmePossibleChannelsDictOurs.ContainsKey(channel.Id)) { _mmePossibleChannelsDictOurs.Add(channel.Id, channel); }
|
||||
}
|
||||
}
|
||||
return _mmePossibleChannelsDictOurs.ContainsKey(id) ? _mmePossibleChannelsDictOurs[id] : null;
|
||||
}
|
||||
if (null == _mmePossibleChannelsDict)
|
||||
{
|
||||
_mmePossibleChannelsDict = new Dictionary<long, MMEPossibleChannels>();
|
||||
foreach (var channel in _possibleChannels)
|
||||
{
|
||||
if (channel.MMEChannelType != channelType) { continue; }
|
||||
if (!_mmePossibleChannelsDict.ContainsKey(channel.Id)) { _mmePossibleChannelsDict.Add(channel.Id, channel); }
|
||||
}
|
||||
}
|
||||
return _mmePossibleChannelsDict.ContainsKey(id) ? _mmePossibleChannelsDict[id] : null;
|
||||
}
|
||||
/// <summary>
|
||||
/// gets all possible test objects from test object tables
|
||||
/// </summary>
|
||||
/// <param name="bIncludeExpired"></param>
|
||||
/// <returns></returns>
|
||||
public MMETestObjects[] GetTestObjects(bool bIncludeExpired)
|
||||
{
|
||||
RefreshIfNeeded();
|
||||
return bIncludeExpired ? _testObjectsDictionary.Values.ToArray() : (from to in _testObjectsDictionary.Values.ToArray().AsParallel() where !to.Expired select to).ToArray();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// writes a test object to DATAPro's list of test objects
|
||||
/// </summary>
|
||||
/// <param name="to"></param>
|
||||
public void Commit(MMETestObjects to)
|
||||
{
|
||||
RefreshIfNeeded();
|
||||
to.Commit();
|
||||
_testObjectsDictionary[to.Test_Object] = to;
|
||||
}
|
||||
/// <summary>
|
||||
/// returns any test objects which match test object test object iso code.
|
||||
/// returns null if not found
|
||||
/// </summary>
|
||||
/// <param name="iso"></param>
|
||||
/// <returns></returns>
|
||||
public MMETestObjects GetTestObjectByIso(string iso)
|
||||
{
|
||||
RefreshIfNeeded();
|
||||
return _testObjectsDictionary.ContainsKey(iso) ? _testObjectsDictionary[iso] : null;
|
||||
}
|
||||
/// <summary>
|
||||
/// returns a position if any that has a matching iso code position field
|
||||
/// returns null if not found
|
||||
/// </summary>
|
||||
/// <param name="key">position code to look for</param>
|
||||
/// <returns></returns>
|
||||
public MMEPositions GetPositionByISO(string key)
|
||||
{
|
||||
RefreshIfNeeded();
|
||||
return _positionsDictionary.ContainsKey(key) ? _positionsDictionary[key] : null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// returns the first position with a guid which matches the requested guid
|
||||
/// returns null if not found
|
||||
/// </summary>
|
||||
/// <param name="GUID">guid to look for</param>
|
||||
/// <returns></returns>
|
||||
public MMEPositions GetPosition(string GUID)
|
||||
{
|
||||
RefreshIfNeeded();
|
||||
var positions = (from p in _positionsDictionary.Values.ToArray().AsParallel() where p.S_GUID == GUID select p);
|
||||
if (positions.Any()) { return positions.First(); }
|
||||
return null;
|
||||
}
|
||||
/// <summary>
|
||||
/// returns filter class matching the iso code filter class field
|
||||
/// </summary>
|
||||
/// <param name="key"></param>
|
||||
/// <returns></returns>
|
||||
public MMEFilterClasses GetFilterClassByIso(string key)
|
||||
{
|
||||
RefreshIfNeeded();
|
||||
return _filterClassesDictionary.ContainsKey(key) ? _filterClassesDictionary[key] : null;
|
||||
}
|
||||
/// <summary>
|
||||
/// returns a direction given the isocode direction field
|
||||
/// </summary>
|
||||
/// <param name="key"></param>
|
||||
/// <returns></returns>
|
||||
public MMEDirections GetDirectionByIso(string key)
|
||||
{
|
||||
RefreshIfNeeded();
|
||||
return _directionsDictionary.ContainsKey(key) ? _directionsDictionary[key] : null;
|
||||
}
|
||||
/// <summary>
|
||||
/// returns a fine location 1, given a matching iso fine location field
|
||||
/// </summary>
|
||||
/// <param name="key"></param>
|
||||
/// <returns></returns>
|
||||
public MMEFineLocations1 GetFineLocation1ByIso(string key)
|
||||
{
|
||||
RefreshIfNeeded();
|
||||
return _fineLoc1Dictionary.ContainsKey(key) ? _fineLoc1Dictionary[key] : null;
|
||||
}
|
||||
/// <summary>
|
||||
/// returns a fine location 2 based on fine location 2 iso code field
|
||||
/// </summary>
|
||||
/// <param name="key"></param>
|
||||
/// <returns></returns>
|
||||
public MMEFineLocations2 GetFineLocation2ByIso(string key)
|
||||
{
|
||||
RefreshIfNeeded();
|
||||
return _fineLoc2Dictionary.ContainsKey(key) ? _fineLoc2Dictionary[key] : null;
|
||||
}
|
||||
/// <summary>
|
||||
/// gets fine location 3 based on fine location 3 isocode field
|
||||
/// </summary>
|
||||
/// <param name="key"></param>
|
||||
/// <returns></returns>
|
||||
public MMEFineLocations3 GetFineLocation3ByIso(string key)
|
||||
{
|
||||
RefreshIfNeeded();
|
||||
return _fineLoc3Dictionary.ContainsKey(key) ? _fineLoc3Dictionary[key] : null;
|
||||
}
|
||||
/// <summary>
|
||||
/// gets physical dimension by isocode physical dimension field
|
||||
/// </summary>
|
||||
/// <param name="key"></param>
|
||||
/// <returns></returns>
|
||||
public MMEPhysicalDimensions GetPhysicalDimensionByIso(string key)
|
||||
{
|
||||
RefreshIfNeeded();
|
||||
return _physicalDimensionsDictionary.ContainsKey(key) ? _physicalDimensionsDictionary[key] : null;
|
||||
}
|
||||
/// <summary>
|
||||
/// gets all possible positions
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public MMEPositions[] GetPositions()
|
||||
{
|
||||
RefreshIfNeeded();
|
||||
return _positionsDictionary.Values.ToArray();
|
||||
}
|
||||
readonly Dictionary<string, MMETransducerMainLocation> _expiredMainLocations = new Dictionary<string, MMETransducerMainLocation>();
|
||||
/// <summary>
|
||||
/// gets a main location given an isocode main location field
|
||||
/// </summary>
|
||||
/// <param name="key"></param>
|
||||
/// <returns></returns>
|
||||
public MMETransducerMainLocation GetMainLocationByIso(string key)
|
||||
{
|
||||
RefreshIfNeeded();
|
||||
if (_transducerMainLoc.ContainsKey(key)) { return _transducerMainLoc[key]; }
|
||||
if (_expiredMainLocations.ContainsKey(key)) { throw new ExpiredISOFieldException(_expiredMainLocations[key].Remarks); }
|
||||
return null;
|
||||
}
|
||||
private bool _bLoaded = false;
|
||||
private static readonly object RefreshLock = new object();
|
||||
|
||||
private void ProcessPossibleChannels()
|
||||
{
|
||||
foreach (var pc in _possibleChannels)
|
||||
{
|
||||
//Don't include 2535, the Thoracic Compression Criterion channel which contains an expired main location (TCCR), but isn't itself marked as expired (FB 9891).
|
||||
if (pc.Id == 2535 ||
|
||||
(pc.Direction == "R" && !pc.Text_L1.ToLower().Contains("seat") && !pc.Text_L1.ToLower().Contains("load")) ||
|
||||
pc.Expired || pc.Default_Filter_Class == "V") { continue; }
|
||||
|
||||
if (!_possibleChannelsByType.ContainsKey(pc.Type))
|
||||
{
|
||||
_possibleChannelsByType[pc.Type] = new List<MMEPossibleChannels>();
|
||||
}
|
||||
_possibleChannelsByType[pc.Type].Add(pc);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// loads all data from iso13499 and datapro databases
|
||||
/// </summary>
|
||||
public void RefreshAllData()
|
||||
{
|
||||
lock (RefreshLock)
|
||||
{
|
||||
try
|
||||
{
|
||||
_mmePossibleChannelsDict = new Dictionary<long, MMEPossibleChannels>();
|
||||
_mmePossibleChannelsDictOurs = new Dictionary<long, MMEPossibleChannels>();
|
||||
_uniquePossibleChannelTypes = null;
|
||||
_directionsDictionary.Clear();
|
||||
_figures.Clear();
|
||||
_filterClassesDictionary.Clear();
|
||||
_fineLoc1Dictionary.Clear();
|
||||
_fineLoc2Dictionary.Clear();
|
||||
_fineLoc3Dictionary.Clear();
|
||||
_possibleChannelsByType.Clear();
|
||||
_physicalDimensionsDictionary.Clear();
|
||||
_positionsDictionary.Clear();
|
||||
_possibleChannels.Clear();
|
||||
_testObjectsDictionary.Clear();
|
||||
_transducerMainLoc.Clear();
|
||||
_expiredMainLocations.Clear();
|
||||
|
||||
try
|
||||
{
|
||||
foreach (var dir in MMEDirections.GetDirections()) { if (!_directionsDictionary.ContainsKey(dir.Direction)) { _directionsDictionary.Add(dir.Direction, dir); } }
|
||||
|
||||
_figures.AddRange(MMEFigures.GetFigures());
|
||||
|
||||
foreach (var fc in MMEFilterClasses.GetFilterClasses()) { if (!_filterClassesDictionary.ContainsKey(fc.Filter_Class)) { _filterClassesDictionary.Add(fc.Filter_Class, fc); } }
|
||||
|
||||
foreach (var loc in MMEFineLocations1.GetFineLocations1()) { if (!_fineLoc1Dictionary.ContainsKey(loc.Fine_Loc_1)) { _fineLoc1Dictionary.Add(loc.Fine_Loc_1, loc); } }
|
||||
|
||||
foreach (var loc in MMEFineLocations2.GetFineLocations2()) { if (!_fineLoc2Dictionary.ContainsKey(loc.FINE_LOC_2)) { _fineLoc2Dictionary.Add(loc.FINE_LOC_2, loc); } }
|
||||
|
||||
foreach (var loc in MMEFineLocations3.GetFineLocations3()) { if (!_fineLoc3Dictionary.ContainsKey(loc.FINE_LOC_3)) { _fineLoc3Dictionary.Add(loc.FINE_LOC_3, loc); } }
|
||||
|
||||
foreach (var pd in MMEPhysicalDimensions.GetPhysicalDimensions()) { if (!_physicalDimensionsDictionary.ContainsKey(pd.Physical_Dimension)) { _physicalDimensionsDictionary.Add(pd.Physical_Dimension, pd); } }
|
||||
|
||||
foreach (var pos in MMEPositions.GetPositions()) { if (!_positionsDictionary.ContainsKey(pos.Position)) { _positionsDictionary.Add(pos.Position, pos); } }
|
||||
|
||||
_possibleChannels.AddRange(MMEPossibleChannels.GetPossibleChannels());
|
||||
|
||||
ProcessPossibleChannels();
|
||||
|
||||
foreach (var to in MMETestObjects.GetTestObjects()) { if (!_testObjectsDictionary.ContainsKey(to.Test_Object)) { _testObjectsDictionary.Add(to.Test_Object, to); } }
|
||||
|
||||
foreach (var mainloc in MMETransducerMainLocation.GetTransducerMainLocations())
|
||||
{
|
||||
if (mainloc.Expired) { if (!_expiredMainLocations.ContainsKey(mainloc.Trans_Main_Loc)) { _expiredMainLocations.Add(mainloc.Trans_Main_Loc, mainloc); } }
|
||||
else { if (!_transducerMainLoc.ContainsKey(mainloc.Trans_Main_Loc)) { _transducerMainLoc.Add(mainloc.Trans_Main_Loc, mainloc); } }
|
||||
}
|
||||
|
||||
|
||||
foreach (var pc in _possibleChannels)
|
||||
{
|
||||
if (pc.MMEChannelType == (int)MMEPossibleChannels.MMEChannelTypes.SQL) { _mmePossibleChannelsDictOurs[pc.Id] = pc; }
|
||||
else { _mmePossibleChannelsDict[pc.Id] = pc; }
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
//APILogger.Log("failure to load ISO tables", ex);
|
||||
}
|
||||
_bLoaded = true;
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
_bLoaded = false;
|
||||
//APILogger.Log(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
145
DataPRO/Modules/DatabaseImporter/DatabaseImport/ISO/IsoCode.cs
Normal file
145
DataPRO/Modules/DatabaseImporter/DatabaseImport/ISO/IsoCode.cs
Normal file
@@ -0,0 +1,145 @@
|
||||
using System.Text;
|
||||
|
||||
namespace DatabaseImport.ISO
|
||||
{
|
||||
public class IsoCode
|
||||
{
|
||||
private readonly char[] _isoCodeFull = { '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0' };
|
||||
|
||||
private char _testObject
|
||||
{
|
||||
get => _isoCodeFull[0];
|
||||
set => _isoCodeFull[0] = value;
|
||||
}
|
||||
private char _position
|
||||
{
|
||||
get => _isoCodeFull[1];
|
||||
set => _isoCodeFull[1] = value;
|
||||
}
|
||||
private char[] _mainLocation
|
||||
{
|
||||
get => new[] { _isoCodeFull[2], _isoCodeFull[3], _isoCodeFull[4], _isoCodeFull[5] };
|
||||
set
|
||||
{
|
||||
for (var i = 0; i < 4; i++)
|
||||
{
|
||||
if (value.Length <= i) { _isoCodeFull[i + 2] = '0'; }
|
||||
else { _isoCodeFull[i + 2] = value[i]; }
|
||||
}
|
||||
}
|
||||
}
|
||||
private char[] _fineLocation1
|
||||
{
|
||||
get => new[] { _isoCodeFull[6], _isoCodeFull[7] };
|
||||
set
|
||||
{
|
||||
for (var i = 0; i < 2; i++)
|
||||
{
|
||||
_isoCodeFull[i + 6] = value.Length < i ? '0' : value[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
private char[] _fineLocation2
|
||||
{
|
||||
get => new[] { _isoCodeFull[8], _isoCodeFull[9] };
|
||||
set
|
||||
{
|
||||
for (var i = 0; i < 2; i++)
|
||||
{
|
||||
if (value.Length < i) { _isoCodeFull[i + 8] = '0'; }
|
||||
else { _isoCodeFull[i + 8] = value[i]; }
|
||||
}
|
||||
}
|
||||
}
|
||||
private char[] _fineLocation3
|
||||
{
|
||||
get => new[] { _isoCodeFull[10], _isoCodeFull[11] };
|
||||
set
|
||||
{
|
||||
for (var i = 0; i < 2; i++)
|
||||
{
|
||||
if (value.Length < i) { _isoCodeFull[i + 10] = '0'; }
|
||||
else { _isoCodeFull[i + 10] = value[i]; }
|
||||
}
|
||||
}
|
||||
}
|
||||
private char[] _physicalDimension
|
||||
{
|
||||
get => new[] { _isoCodeFull[12], _isoCodeFull[13] };
|
||||
set
|
||||
{
|
||||
for (var i = 0; i < 2; i++)
|
||||
{
|
||||
if (value.Length < i) { _isoCodeFull[i + 12] = '0'; }
|
||||
else { _isoCodeFull[i + 12] = value[i]; }
|
||||
}
|
||||
}
|
||||
}
|
||||
private char _direction
|
||||
{
|
||||
get => _isoCodeFull[14];
|
||||
set => _isoCodeFull[14] = value;
|
||||
}
|
||||
private char _filterClass
|
||||
{
|
||||
get => _isoCodeFull[15];
|
||||
set => _isoCodeFull[15] = value;
|
||||
}
|
||||
public IsoCode(string isoCode)
|
||||
{
|
||||
if (null == isoCode) { isoCode = ""; }
|
||||
if (isoCode.Length > 16) { isoCode = isoCode.Substring(0, 16); }
|
||||
if (isoCode.Length < 16)
|
||||
{
|
||||
isoCode = isoCode.PadRight(16, '?');
|
||||
}
|
||||
for (var i = 0; i < 16; i++) { _isoCodeFull[i] = isoCode[i]; }
|
||||
}
|
||||
public string StringRepresentation
|
||||
{
|
||||
get
|
||||
{
|
||||
var sb = new StringBuilder();
|
||||
foreach (var c in _isoCodeFull) { sb.Append(c); }
|
||||
return sb.ToString();
|
||||
}
|
||||
set
|
||||
{
|
||||
for (var i = 0; i < 16; i++)
|
||||
{
|
||||
if (i >= value.Length) { _isoCodeFull[i] = '0'; }
|
||||
else { _isoCodeFull[i] = value[i]; }
|
||||
}
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// returns the isocode for a channel
|
||||
/// considers whether it should mask the test time fields in the isocode
|
||||
/// test time fields are test object, and filterclass
|
||||
/// returns isocode
|
||||
/// </summary>
|
||||
/// <param name="channel"></param>
|
||||
/// <param name="careAboutTestTimeFields"></param>
|
||||
/// <returns></returns>
|
||||
public static string GetString(MMEPossibleChannels channel, bool careAboutTestTimeFields)
|
||||
{
|
||||
var iso = new IsoCode("")
|
||||
{
|
||||
_direction = channel.Direction[0],
|
||||
_fineLocation1 = channel.Fine_Loc_1.ToCharArray(),
|
||||
_fineLocation2 = channel.Fine_Loc_2.ToCharArray(),
|
||||
_fineLocation3 = channel.Fine_Loc_3.ToCharArray(),
|
||||
_mainLocation = channel.Trans_Main_Loc.ToCharArray(),
|
||||
_physicalDimension = channel.Physical_Dimension.ToCharArray(),
|
||||
_position = channel.Position[0],
|
||||
_testObject = careAboutTestTimeFields ? channel.Test_Object[0] : '?',
|
||||
_filterClass = careAboutTestTimeFields ? channel.Default_Filter_Class[0] : '?'
|
||||
};
|
||||
return iso.StringRepresentation;
|
||||
}
|
||||
public static string GetString(string testObject, string position, string main, string floc1, string floc2, string floc3, string physdim, string dir, string fc)
|
||||
{
|
||||
return $"{testObject}{position}{main}{floc1}{floc2}{floc3}{physdim}{dir}{fc}";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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,82 @@
|
||||
using System;
|
||||
|
||||
namespace DatabaseImport
|
||||
{
|
||||
/// <summary>
|
||||
/// this is a class for storing directly in and out of the db
|
||||
/// it's simplified and doesn't know about sensors and is just a wrapper for a row in the db
|
||||
/// </summary>
|
||||
public class LevelTriggerChannel
|
||||
{
|
||||
public string TestSetupName { get; set; } = "";
|
||||
|
||||
public string GroupSerialNumber { get; set; } = "";
|
||||
|
||||
public string TestObjectChannelId { get; set; } = "";
|
||||
|
||||
public string HardwareChannelId { get; set; } = "";
|
||||
|
||||
public string SensorSerialNumber { get; set; } = "";
|
||||
|
||||
public bool GreaterThanEnabled { get; set; } = true;
|
||||
|
||||
public double GreaterThanThresholdEU { get; set; }
|
||||
|
||||
public bool LessThanEnabled { get; set; }
|
||||
|
||||
public bool TriggerBetweenBounds { get; set; }
|
||||
|
||||
public bool TriggerOutsideBounds { get; set; }
|
||||
|
||||
public double InsideUpperLevelEU { get; set; }
|
||||
|
||||
public double InsideLowerLevelEU { get; set; }
|
||||
|
||||
public double OutsideUpperLevelEU { get; set; }
|
||||
|
||||
public double OutsideLowerLevelEU { get; set; }
|
||||
|
||||
public double LessThanThresholdEU { get; set; }
|
||||
|
||||
public LevelTriggerChannel(LevelTriggerChannel copy)
|
||||
{
|
||||
TestSetupName = copy.TestSetupName;
|
||||
GroupSerialNumber = copy.GroupSerialNumber;
|
||||
TestObjectChannelId = copy.TestObjectChannelId;
|
||||
HardwareChannelId = copy.HardwareChannelId;
|
||||
SensorSerialNumber = copy.SensorSerialNumber;
|
||||
GreaterThanEnabled = copy.GreaterThanEnabled;
|
||||
GreaterThanThresholdEU = copy.GreaterThanThresholdEU;
|
||||
LessThanEnabled = copy.LessThanEnabled;
|
||||
LessThanThresholdEU = copy.LessThanThresholdEU;
|
||||
InsideUpperLevelEU = copy.InsideUpperLevelEU;
|
||||
InsideLowerLevelEU = copy.InsideLowerLevelEU;
|
||||
OutsideUpperLevelEU = copy.OutsideUpperLevelEU;
|
||||
OutsideLowerLevelEU = copy.OutsideLowerLevelEU;
|
||||
TriggerBetweenBounds = copy.TriggerBetweenBounds;
|
||||
TriggerOutsideBounds = copy.TriggerOutsideBounds;
|
||||
}
|
||||
public LevelTriggerChannel(System.Data.DataRow dr)
|
||||
{
|
||||
try
|
||||
{
|
||||
GreaterThanEnabled = Convert.ToBoolean(dr[DbOperations.LevelTriggers.Fields.GreaterThanEnabled.ToString()]);
|
||||
GreaterThanThresholdEU = Convert.ToDouble(dr[DbOperations.LevelTriggers.Fields.GreaterThanEU.ToString()]);
|
||||
GroupSerialNumber = Convert.ToString(dr[DbOperations.LevelTriggers.Fields.TestObjectName.ToString()]);
|
||||
HardwareChannelId = Convert.ToString(dr[DbOperations.LevelTriggers.Fields.HardwareChannelId.ToString()]);
|
||||
LessThanEnabled = Convert.ToBoolean(dr[DbOperations.LevelTriggers.Fields.LessThanEnabled.ToString()]);
|
||||
LessThanThresholdEU = Convert.ToDouble(dr[DbOperations.LevelTriggers.Fields.LessThanEU.ToString()]);
|
||||
SensorSerialNumber = Convert.ToString(dr[DbOperations.LevelTriggers.Fields.SensorSerialNumber.ToString()]);
|
||||
TestObjectChannelId = Convert.ToString(dr[DbOperations.LevelTriggers.Fields.TestObjectChannelId.ToString()]);
|
||||
TestSetupName = Convert.ToString(dr[DbOperations.LevelTriggers.Fields.TestSetupName.ToString()]);
|
||||
TriggerBetweenBounds = Convert.ToBoolean(dr[DbOperations.LevelTriggers.Fields.TriggerInside.ToString()]);
|
||||
TriggerOutsideBounds = Convert.ToBoolean(dr[DbOperations.LevelTriggers.Fields.TriggerOutside.ToString()]);
|
||||
OutsideUpperLevelEU = Convert.ToDouble(dr[DbOperations.LevelTriggers.Fields.OutsideUpperEU.ToString()]);
|
||||
OutsideLowerLevelEU = Convert.ToDouble(dr[DbOperations.LevelTriggers.Fields.OutsideLowerEU.ToString()]);
|
||||
InsideUpperLevelEU = Convert.ToDouble(dr[DbOperations.LevelTriggers.Fields.InsideUpperEU.ToString()]);
|
||||
InsideLowerLevelEU = Convert.ToDouble(dr[DbOperations.LevelTriggers.Fields.InsideLowerEU.ToString()]);
|
||||
}
|
||||
catch (Exception) { /*APILogger.Log(ex);*/ }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,237 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Data.SqlClient;
|
||||
|
||||
namespace DatabaseImport
|
||||
{
|
||||
public class MMEDirections //: AbstractOLEDbWrapper
|
||||
{
|
||||
public string S_GUID { get; }
|
||||
|
||||
public string Direction { get; }
|
||||
|
||||
public string Text_L1 { get; }
|
||||
|
||||
public string Text_L2 { get; }
|
||||
|
||||
public DateTime Date { get; }
|
||||
|
||||
public long Version { get; }
|
||||
|
||||
public bool Expired { get; }
|
||||
|
||||
public string Remarks { get; }
|
||||
|
||||
public DateTime Last_Change { get; }
|
||||
|
||||
public string Last_Change_Text { get; }
|
||||
|
||||
public string History { get; }
|
||||
|
||||
public string SortKey { get; }
|
||||
|
||||
public MMEPossibleChannels.MMEChannelTypes RecordType { get; }
|
||||
public MMEDirections(string sGuid, string direction, string textL1, string textL2, DateTime date, long version,
|
||||
bool bExpired, string remarks, DateTime lastChange, string lastChangeText, string history, string sortkey,
|
||||
MMEPossibleChannels.MMEChannelTypes type)
|
||||
{
|
||||
RecordType = type;
|
||||
S_GUID = sGuid;
|
||||
Direction = direction;
|
||||
Text_L1 = textL1;
|
||||
Text_L2 = textL2;
|
||||
Date = date;
|
||||
Version = version;
|
||||
Expired = bExpired;
|
||||
Remarks = remarks;
|
||||
Last_Change = lastChange;
|
||||
Last_Change_Text = lastChangeText;
|
||||
History = history;
|
||||
SortKey = sortkey;
|
||||
}
|
||||
|
||||
public static MMEDirections[] GetDirections()
|
||||
{
|
||||
var directions = new List<MMEDirections>();
|
||||
SqlDataReader reader = null;
|
||||
|
||||
try
|
||||
{
|
||||
using (var cmd = DbOperations.GetSQLCommand(true))
|
||||
{
|
||||
try
|
||||
{
|
||||
cmd.CommandType = CommandType.StoredProcedure;
|
||||
cmd.CommandText = DbOperationsEnum.StoredProcedure.sp_MMEDirectionsGet.ToString();
|
||||
cmd.Parameters.Add(new SqlParameter("@s_GUID", SqlDbType.UniqueIdentifier) { Value = null });
|
||||
|
||||
reader = cmd.ExecuteReader();
|
||||
while (reader.Read())
|
||||
{
|
||||
try
|
||||
{
|
||||
var version =
|
||||
Convert.ToInt32(
|
||||
reader[DbOperations.MMETables.MMEDirectionsFields.VERSION.ToString()]);
|
||||
var text2 = Convert.ToString(
|
||||
reader[DbOperations.MMETables.MMEDirectionsFields.TEXT_L2.ToString()]);
|
||||
var text1 = Convert.ToString(
|
||||
reader[DbOperations.MMETables.MMEDirectionsFields.TEXT_L1.ToString()]);
|
||||
var sortKey =
|
||||
Convert.ToString(
|
||||
reader[DbOperations.MMETables.MMEDirectionsFields.SORTKEY.ToString()]);
|
||||
var sGuid = Convert.ToString(
|
||||
reader[DbOperations.MMETables.MMEDirectionsFields.s_GUID.ToString()]);
|
||||
var remarks =
|
||||
Convert.ToString(
|
||||
reader[DbOperations.MMETables.MMEDirectionsFields.REMARKS.ToString()]);
|
||||
var lastChangeText =
|
||||
Convert.ToString(
|
||||
reader[DbOperations.MMETables.MMEDirectionsFields.LAST_CHANGE_TEXT.ToString()]);
|
||||
var lastChange =
|
||||
Convert.ToDateTime(
|
||||
reader[DbOperations.MMETables.MMEDirectionsFields.LAST_CHANGE.ToString()]);
|
||||
var history =
|
||||
Convert.ToString(
|
||||
reader[DbOperations.MMETables.MMEDirectionsFields.HISTORY.ToString()]);
|
||||
var expired =
|
||||
Convert.ToBoolean(
|
||||
reader[DbOperations.MMETables.MMEDirectionsFields.EXPIRED.ToString()]);
|
||||
var direction =
|
||||
Convert.ToString(
|
||||
reader[DbOperations.MMETables.MMEDirectionsFields.DIRECTION.ToString()]);
|
||||
var date = Convert.ToDateTime(
|
||||
reader[DbOperations.MMETables.MMEDirectionsFields.DATE.ToString()]);
|
||||
var mmedirection = new MMEDirections(sGuid, direction, text1, text2, date,
|
||||
Convert.ToInt64(version),
|
||||
expired, remarks, lastChange, lastChangeText, history, sortKey,
|
||||
MMEPossibleChannels.MMEChannelTypes.ISO13499_106);
|
||||
directions.Add(mmedirection);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
//APILogger.Log("failed to load direction", ex);
|
||||
}
|
||||
}
|
||||
reader.Close();
|
||||
}
|
||||
finally { cmd.Connection.Dispose(); }
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
//APILogger.Log("failed to load sql portion of iso.mmedirections, ", ex);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
using (var cmd = DbOperations.GetSQLCommand(true))
|
||||
{
|
||||
try
|
||||
{
|
||||
cmd.CommandType = CommandType.StoredProcedure;
|
||||
cmd.CommandText = DbOperationsEnum.StoredProcedure.sp_MMEDirectionsGetCustom.ToString();
|
||||
cmd.Parameters.Add(new SqlParameter("@s_GUID", SqlDbType.UniqueIdentifier) { Value = null });
|
||||
|
||||
reader = cmd.ExecuteReader();
|
||||
while (reader.Read())
|
||||
{
|
||||
try
|
||||
{
|
||||
var version =
|
||||
Convert.ToInt32(
|
||||
reader[DbOperations.MMETables.MMEDirectionsFields.VERSION.ToString()]);
|
||||
var text2 = Convert.ToString(
|
||||
reader[DbOperations.MMETables.MMEDirectionsFields.TEXT_L2.ToString()]);
|
||||
var text1 = Convert.ToString(
|
||||
reader[DbOperations.MMETables.MMEDirectionsFields.TEXT_L1.ToString()]);
|
||||
var sortKey =
|
||||
Convert.ToString(
|
||||
reader[DbOperations.MMETables.MMEDirectionsFields.SORTKEY.ToString()]);
|
||||
var sGuid = Convert.ToString(
|
||||
reader[DbOperations.MMETables.MMEDirectionsFields.s_GUID.ToString()]);
|
||||
var remarks =
|
||||
Convert.ToString(
|
||||
reader[DbOperations.MMETables.MMEDirectionsFields.REMARKS.ToString()]);
|
||||
var lastChangeText =
|
||||
Convert.ToString(
|
||||
reader[DbOperations.MMETables.MMEDirectionsFields.LAST_CHANGE_TEXT.ToString()]);
|
||||
var lastChange =
|
||||
Convert.ToDateTime(
|
||||
reader[DbOperations.MMETables.MMEDirectionsFields.LAST_CHANGE.ToString()]);
|
||||
var history =
|
||||
Convert.ToString(
|
||||
reader[DbOperations.MMETables.MMEDirectionsFields.HISTORY.ToString()]);
|
||||
var expired =
|
||||
Convert.ToBoolean(
|
||||
reader[DbOperations.MMETables.MMEDirectionsFields.EXPIRED.ToString()]);
|
||||
var direction =
|
||||
Convert.ToString(
|
||||
reader[DbOperations.MMETables.MMEDirectionsFields.DIRECTION.ToString()]);
|
||||
var date = Convert.ToDateTime(
|
||||
reader[DbOperations.MMETables.MMEDirectionsFields.DATE.ToString()]);
|
||||
var mmedirection = new MMEDirections(sGuid, direction, text1, text2, date,
|
||||
Convert.ToInt64(version),
|
||||
expired, remarks, lastChange, lastChangeText, history, sortKey,
|
||||
MMEPossibleChannels.MMEChannelTypes.SQL);
|
||||
directions.Add(mmedirection);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
//APILogger.Log("failed to load custom direction", ex);
|
||||
}
|
||||
}
|
||||
reader.Close();
|
||||
}
|
||||
finally { cmd.Connection.Dispose(); }
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
//APILogger.Log("failed to load sql portion of custom mmedirections, ", ex);
|
||||
}
|
||||
|
||||
finally
|
||||
{
|
||||
reader?.Close();
|
||||
}
|
||||
return directions.ToArray();
|
||||
}
|
||||
public static void DeleteDirections()
|
||||
{
|
||||
try
|
||||
{
|
||||
using (var cmd = DbOperations.GetSQLCommand(true))
|
||||
{
|
||||
try
|
||||
{
|
||||
cmd.CommandType = CommandType.StoredProcedure;
|
||||
cmd.CommandText = DbOperationsEnum.StoredProcedure.sp_MMEDirectionsDelete.ToString();
|
||||
cmd.Parameters.Add(new SqlParameter("@s_GUID", SqlDbType.UniqueIdentifier) { 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);
|
||||
|
||||
cmd.ExecuteNonQuery();
|
||||
if (int.Parse(errorNumberParam.Value.ToString()) != 0)
|
||||
{
|
||||
//errorMessageParam.Value
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
cmd.Connection.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception) { /*APILogger.Log("failed to delete sql portion of iso.mmedirections, ", ex); */}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,187 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Data.SqlClient;
|
||||
|
||||
namespace DatabaseImport
|
||||
{
|
||||
public class MMEFigures //: AbstractOLEDbWrapper
|
||||
{
|
||||
public long ID { get; }
|
||||
|
||||
public string TxtShortName { get; }
|
||||
|
||||
public string TxtDescription { get; }
|
||||
|
||||
public string TxtRemarks { get; }
|
||||
|
||||
public DateTime DatRevision { get; }
|
||||
|
||||
public long IntAuthor { get; }
|
||||
|
||||
public ushort IntPage { get; }
|
||||
|
||||
public ushort IntPages { get; }
|
||||
|
||||
public string TxtImageFile { get; }
|
||||
|
||||
public long IntVersion { get; }
|
||||
|
||||
public bool BolExpired { get; }
|
||||
|
||||
public string TxtSortKey { get; }
|
||||
|
||||
public bool BitStdPath { get; }
|
||||
|
||||
public long IntIDStdPath { get; }
|
||||
|
||||
public string TxtPath { get; }
|
||||
|
||||
public DateTime Last_Change { get; }
|
||||
|
||||
public string Last_Change_Text { get; }
|
||||
|
||||
public string History { get; }
|
||||
|
||||
public MMEFigures(long id, string txtShortName, string txtDescription, string txtRemarks, DateTime datRevision, long intAuthor,
|
||||
ushort intPage, ushort intPages, string txtImageFile, long version, bool bExpired, string txtSortKey,
|
||||
bool bitStdPath, long intIDStdPath, string txtPath, DateTime lastChange, string lastChangeText, string history)
|
||||
{
|
||||
ID = id;
|
||||
TxtShortName = txtShortName;
|
||||
TxtDescription = txtDescription;
|
||||
TxtRemarks = txtRemarks;
|
||||
DatRevision = datRevision;
|
||||
IntAuthor = intAuthor;
|
||||
IntPage = intPage;
|
||||
IntPages = intPages;
|
||||
TxtImageFile = txtImageFile;
|
||||
IntVersion = version;
|
||||
BolExpired = bExpired;
|
||||
TxtSortKey = txtSortKey;
|
||||
BitStdPath = bitStdPath;
|
||||
IntIDStdPath = intIDStdPath;
|
||||
TxtPath = txtPath;
|
||||
Last_Change = lastChange;
|
||||
Last_Change_Text = lastChangeText;
|
||||
History = history;
|
||||
}
|
||||
public static void DeleteFigures()
|
||||
{
|
||||
return;//nothing to do
|
||||
}
|
||||
public static MMEFigures[] GetFigures()
|
||||
{
|
||||
var figures = new List<MMEFigures>();
|
||||
|
||||
try
|
||||
{
|
||||
using (var cmd = DbOperations.GetSQLCommand(true))
|
||||
{
|
||||
try
|
||||
{
|
||||
cmd.CommandType = CommandType.StoredProcedure;
|
||||
cmd.CommandText = DbOperationsEnum.StoredProcedure.sp_MMEFiguresGet.ToString();
|
||||
cmd.Parameters.Add(new SqlParameter("@Id", SqlDbType.NVarChar) { Value = null });
|
||||
using (var reader = cmd.ExecuteReader())
|
||||
{
|
||||
while (reader.Read())
|
||||
{
|
||||
var id = Convert.ToInt64(reader["ID"]);
|
||||
var txtShortName = reader["txtShortName"].ToString();
|
||||
var txtDescription = reader["txtDescription"].ToString();
|
||||
var txtRemarks = reader["txtRemarks"].ToString();
|
||||
var datRevision = DateTime.MinValue;
|
||||
if (!DBNull.Value.Equals(reader["datRevision"]))
|
||||
{
|
||||
datRevision = (DateTime)reader["datRevision"];
|
||||
}
|
||||
var intAuthor = Convert.ToInt64(reader["intAuthor"]);
|
||||
var intPage = Convert.ToUInt16(reader["intPage"]);
|
||||
var intPages = Convert.ToUInt16(reader["intPages"]);
|
||||
var txtImageFile = reader["txtImageFile"].ToString();
|
||||
var version = Convert.ToInt64(reader["intVersion"]);
|
||||
var bExpired = (bool)reader["bolExpired"];
|
||||
var txtSortKey = reader["txtSortKey"].ToString();
|
||||
var bitStdPath = (bool)reader["bitStdPath"];
|
||||
var intIDStdPath = Convert.ToInt64(reader["IntIDStdPath"]);
|
||||
var txtPath = reader["txtPath"].ToString();
|
||||
var lastChange = DBNull.Value != reader["LAST_CHANGE"]
|
||||
? DateTime.MinValue
|
||||
: (DateTime)reader["LAST_CHANGE"];
|
||||
var lastChangeText = reader["LAST_CHANGE_TEXT"].ToString();
|
||||
var history = reader["HISTORY"].ToString();
|
||||
figures.Add(new MMEFigures(id, txtShortName, txtDescription, txtRemarks,
|
||||
datRevision, intAuthor, intPage,
|
||||
intPages, txtImageFile, version, bExpired, txtSortKey, bitStdPath, intIDStdPath,
|
||||
txtPath, lastChange, lastChangeText, history));
|
||||
}
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
cmd.Connection.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
//APILogger.Log("Problem loading figures - ", ex);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
using (var cmd = DbOperations.GetSQLCommand(true))
|
||||
{
|
||||
try
|
||||
{
|
||||
cmd.CommandType = CommandType.StoredProcedure;
|
||||
cmd.CommandText = DbOperationsEnum.StoredProcedure.sp_MMEFiguresGetCustom.ToString();
|
||||
cmd.Parameters.Add(new SqlParameter("@Id", SqlDbType.NVarChar) { Value = null });
|
||||
using (var reader = cmd.ExecuteReader())
|
||||
{
|
||||
while (reader.Read())
|
||||
{
|
||||
var id = Convert.ToInt64(reader["ID"]);
|
||||
var txtShortName = reader["txtShortName"].ToString();
|
||||
var txtDescription = reader["txtDescription"].ToString();
|
||||
var txtRemarks = reader["txtRemarks"].ToString();
|
||||
var datRevision = DateTime.MinValue;
|
||||
if (!DBNull.Value.Equals(reader["datRevision"]))
|
||||
{
|
||||
datRevision = (DateTime)reader["datRevision"];
|
||||
}
|
||||
var intAuthor = Convert.ToInt64(reader["intAuthor"]);
|
||||
var intPage = Convert.ToUInt16(reader["intPage"]);
|
||||
var intPages = Convert.ToUInt16(reader["intPages"]);
|
||||
var txtImageFile = reader["txtImageFile"].ToString();
|
||||
var version = Convert.ToInt64(reader["intVersion"]);
|
||||
var bExpired = (bool)reader["bolExpired"];
|
||||
var txtSortKey = reader["txtSortKey"].ToString();
|
||||
var bitStdPath = (bool)reader["bitStdPath"];
|
||||
var intIDStdPath = Convert.ToInt64(reader["IntIDStdPath"]);
|
||||
var txtPath = reader["txtPath"].ToString();
|
||||
var lastChange = DBNull.Value != reader["LAST_CHANGE"]
|
||||
? DateTime.MinValue
|
||||
: (DateTime)reader["LAST_CHANGE"];
|
||||
var lastChangeText = reader["LAST_CHANGE_TEXT"].ToString();
|
||||
var history = reader["HISTORY"].ToString();
|
||||
figures.Add(new MMEFigures(id, txtShortName, txtDescription, txtRemarks, datRevision,
|
||||
intAuthor, intPage,
|
||||
intPages, txtImageFile, version, bExpired, txtSortKey, bitStdPath, intIDStdPath,
|
||||
txtPath, lastChange, lastChangeText, history));
|
||||
}
|
||||
}
|
||||
}
|
||||
finally { cmd.Connection.Dispose(); }
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
//APILogger.Log("Problem loading custom figures - ", ex);
|
||||
}
|
||||
|
||||
return figures.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,221 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Data.SqlClient;
|
||||
|
||||
namespace DatabaseImport
|
||||
{
|
||||
public class MMEFilterClasses //: AbstractOLEDbWrapper
|
||||
{
|
||||
public string S_GUID { get; }
|
||||
|
||||
public string Filter_Class { get; }
|
||||
|
||||
public string Text_L1 { get; }
|
||||
|
||||
public string Text_L2 { get; }
|
||||
|
||||
public long Version { get; }
|
||||
|
||||
public DateTime Date { get; }
|
||||
|
||||
public string Remarks { get; }
|
||||
|
||||
public bool Expired { get; }
|
||||
|
||||
public string SortKey { get; }
|
||||
|
||||
public DateTime Last_Change { get; }
|
||||
|
||||
public string Last_Change_Text { get; }
|
||||
|
||||
public string History { get; }
|
||||
|
||||
public MMEPossibleChannels.MMEChannelTypes RecordType { get; } = MMEPossibleChannels.MMEChannelTypes.ISO13499_106;
|
||||
public MMEFilterClasses(string sGuid, string filterClass, string textL1, string textL2, long version,
|
||||
DateTime date, string remarks, bool bExpired, string sortKey, DateTime lastChange, string lastChangeText, string history,
|
||||
MMEPossibleChannels.MMEChannelTypes type)
|
||||
{
|
||||
RecordType = type;
|
||||
S_GUID = sGuid;
|
||||
Filter_Class = filterClass;
|
||||
Text_L1 = textL1;
|
||||
Text_L2 = textL2;
|
||||
Version = version;
|
||||
Date = date;
|
||||
Remarks = remarks;
|
||||
Expired = bExpired;
|
||||
SortKey = sortKey;
|
||||
Last_Change = lastChange;
|
||||
Last_Change_Text = lastChangeText;
|
||||
History = history;
|
||||
}
|
||||
public static void DeleteFilterClasses()
|
||||
{
|
||||
try
|
||||
{
|
||||
using (var cmd = DbOperations.GetSQLCommand(true))
|
||||
{
|
||||
try
|
||||
{
|
||||
cmd.CommandType = CommandType.StoredProcedure;
|
||||
cmd.CommandText = DbOperationsEnum.StoredProcedure.sp_MMEFilterClassesDelete.ToString();
|
||||
cmd.Parameters.Add(new SqlParameter("@s_GUID", SqlDbType.UniqueIdentifier) { 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);
|
||||
|
||||
cmd.ExecuteNonQuery();
|
||||
if (int.Parse(errorNumberParam.Value.ToString()) != 0)
|
||||
{
|
||||
//errorMessageParam.Value
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
cmd.Connection.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception) { /*APILogger.Log("failed to delete filters, ", ex); */}
|
||||
}
|
||||
|
||||
public static MMEFilterClasses[] GetFilterClasses()
|
||||
{
|
||||
var filterClasses = new List<MMEFilterClasses>();
|
||||
|
||||
try
|
||||
{
|
||||
using (var cmd = DbOperations.GetSQLCommand(true))
|
||||
{
|
||||
try
|
||||
{
|
||||
cmd.CommandType = CommandType.StoredProcedure;
|
||||
cmd.CommandText = DbOperationsEnum.StoredProcedure.sp_MMEFilterClassesGet.ToString();
|
||||
cmd.Parameters.Add(new SqlParameter("@s_GUID", SqlDbType.UniqueIdentifier) { Value = null });
|
||||
//cmd.ExecuteNonQuery();
|
||||
using (var ds = DbOperations.Connection.QueryDataSet(cmd))
|
||||
{
|
||||
if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
|
||||
{
|
||||
try
|
||||
{
|
||||
filterClasses.AddRange(from DataRow dr in ds.Tables[0].Rows
|
||||
let date = Convert.ToDateTime(
|
||||
dr[DbOperations.MMETables.MMEFilterClassesFields.DATE.ToString()])
|
||||
let expired = Convert.ToBoolean(
|
||||
dr[DbOperations.MMETables.MMEFilterClassesFields.EXPIRED.ToString()])
|
||||
let filterclass = Convert.ToString(dr[
|
||||
DbOperations.MMETables.MMEFilterClassesFields.FILTER_CLASS.ToString()])
|
||||
let history = Convert.ToString(
|
||||
dr[DbOperations.MMETables.MMEFilterClassesFields.HISTORY.ToString()])
|
||||
let lastChange = Convert.ToDateTime(dr[
|
||||
DbOperations.MMETables.MMEFilterClassesFields.LAST_CHANGE.ToString()])
|
||||
let lastChangeText = Convert.ToString(dr[
|
||||
DbOperations.MMETables.MMEFilterClassesFields.LAST_CHANGE_TEXT.ToString()])
|
||||
let remarks = Convert.ToString(
|
||||
dr[DbOperations.MMETables.MMEFilterClassesFields.REMARKS.ToString()])
|
||||
let sGuid = Convert.ToString(
|
||||
dr[DbOperations.MMETables.MMEFilterClassesFields.s_GUID.ToString()])
|
||||
let sortkey = Convert.ToString(
|
||||
dr[DbOperations.MMETables.MMEFilterClassesFields.SORTKEY.ToString()])
|
||||
let text1 = Convert.ToString(
|
||||
dr[DbOperations.MMETables.MMEFilterClassesFields.TEXT_L1.ToString()])
|
||||
let text2 = Convert.ToString(
|
||||
dr[DbOperations.MMETables.MMEFilterClassesFields.TEXT_L2.ToString()])
|
||||
let version = Convert.ToInt32(
|
||||
dr[DbOperations.MMETables.MMEFilterClassesFields.VERSION.ToString()])
|
||||
select new MMEFilterClasses(sGuid, filterclass, text1, text2,
|
||||
Convert.ToInt64(version), date, remarks, expired, sortkey, lastChange,
|
||||
lastChangeText, history, MMEPossibleChannels.MMEChannelTypes.ISO13499_106));
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
//APILogger.Log("Failed to process filter classes ", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
cmd.Connection.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
//APILogger.Log("failed to retrieve filters, ", ex);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
using (var cmd = DbOperations.GetSQLCommand(true))
|
||||
{
|
||||
try
|
||||
{
|
||||
cmd.CommandType = CommandType.StoredProcedure;
|
||||
cmd.CommandText = DbOperationsEnum.StoredProcedure.sp_MMEFilterClassesGetCustom.ToString();
|
||||
cmd.Parameters.Add(new SqlParameter("@s_GUID", SqlDbType.UniqueIdentifier) { Value = null });
|
||||
using (var ds = DbOperations.Connection.QueryDataSet(cmd))
|
||||
{
|
||||
if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
|
||||
{
|
||||
try
|
||||
{
|
||||
filterClasses.AddRange(from DataRow dr in ds.Tables[0].Rows
|
||||
let date = Convert.ToDateTime(
|
||||
dr[DbOperations.MMETables.MMEFilterClassesFields.DATE.ToString()])
|
||||
let expired = Convert.ToBoolean(
|
||||
dr[DbOperations.MMETables.MMEFilterClassesFields.EXPIRED.ToString()])
|
||||
let filterclass = Convert.ToString(dr[
|
||||
DbOperations.MMETables.MMEFilterClassesFields.FILTER_CLASS.ToString()])
|
||||
let history = Convert.ToString(
|
||||
dr[DbOperations.MMETables.MMEFilterClassesFields.HISTORY.ToString()])
|
||||
let lastChange = Convert.ToDateTime(dr[
|
||||
DbOperations.MMETables.MMEFilterClassesFields.LAST_CHANGE.ToString()])
|
||||
let lastChangeText = Convert.ToString(dr[
|
||||
DbOperations.MMETables.MMEFilterClassesFields.LAST_CHANGE_TEXT.ToString()])
|
||||
let remarks = Convert.ToString(
|
||||
dr[DbOperations.MMETables.MMEFilterClassesFields.REMARKS.ToString()])
|
||||
let sGuid = Convert.ToString(
|
||||
dr[DbOperations.MMETables.MMEFilterClassesFields.s_GUID.ToString()])
|
||||
let sortkey = Convert.ToString(
|
||||
dr[DbOperations.MMETables.MMEFilterClassesFields.SORTKEY.ToString()])
|
||||
let text1 = Convert.ToString(
|
||||
dr[DbOperations.MMETables.MMEFilterClassesFields.TEXT_L1.ToString()])
|
||||
let text2 = Convert.ToString(
|
||||
dr[DbOperations.MMETables.MMEFilterClassesFields.TEXT_L2.ToString()])
|
||||
let version = Convert.ToInt32(
|
||||
dr[DbOperations.MMETables.MMEFilterClassesFields.VERSION.ToString()])
|
||||
select new MMEFilterClasses(sGuid, filterclass, text1, text2,
|
||||
Convert.ToInt64(version), date, remarks, expired, sortkey, lastChange,
|
||||
lastChangeText, history, MMEPossibleChannels.MMEChannelTypes.SQL));
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
//APILogger.Log("Failed to process custom filter classes", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
cmd.Connection.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
//APILogger.Log("failed to retrieve custom filters, ", ex);
|
||||
}
|
||||
return filterClasses.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,215 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Data.SqlClient;
|
||||
|
||||
namespace DatabaseImport
|
||||
{
|
||||
public class MMEFineLocations1 //: AbstractOLEDbWrapper
|
||||
{
|
||||
public string S_GUID { get; }
|
||||
|
||||
public string Fine_Loc_1 { get; }
|
||||
|
||||
public string Text_L1 { get; }
|
||||
|
||||
public string Text_L2 { get; }
|
||||
|
||||
public long Version { get; }
|
||||
|
||||
public DateTime Date { get; }
|
||||
|
||||
public string Remarks { get; }
|
||||
|
||||
public bool Expired { get; }
|
||||
|
||||
public string SortKey { get; }
|
||||
|
||||
public DateTime Last_Change { get; }
|
||||
|
||||
public string Last_Change_Text { get; }
|
||||
|
||||
public string History { get; }
|
||||
|
||||
public MMEPossibleChannels.MMEChannelTypes RecordType { get; } = MMEPossibleChannels.MMEChannelTypes.ISO13499_106;
|
||||
public MMEFineLocations1(string sGuid, string fineLoc1, string textL1, string textL2, long version, DateTime date,
|
||||
string remarks, bool expired, string sortKey, DateTime lastChange, string lastChangeText, string history,
|
||||
MMEPossibleChannels.MMEChannelTypes type)
|
||||
{
|
||||
RecordType = type;
|
||||
S_GUID = sGuid;
|
||||
Fine_Loc_1 = fineLoc1;
|
||||
Text_L1 = textL1;
|
||||
Text_L2 = textL2;
|
||||
Version = version;
|
||||
Date = date;
|
||||
Remarks = remarks;
|
||||
Expired = expired;
|
||||
SortKey = sortKey;
|
||||
Last_Change = lastChange;
|
||||
Last_Change_Text = lastChangeText;
|
||||
History = history;
|
||||
}
|
||||
public static void DeleteFineLocations1()
|
||||
{
|
||||
try
|
||||
{
|
||||
using (var cmd = DbOperations.GetSQLCommand(true))
|
||||
{
|
||||
try
|
||||
{
|
||||
cmd.CommandType = CommandType.StoredProcedure;
|
||||
cmd.CommandText = DbOperationsEnum.StoredProcedure.sp_MMEFineLocations1Delete.ToString();
|
||||
cmd.Parameters.Add(new SqlParameter("@s_GUID", SqlDbType.UniqueIdentifier) { 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);
|
||||
|
||||
cmd.ExecuteNonQuery();
|
||||
if (int.Parse(errorNumberParam.Value.ToString()) != 0)
|
||||
{
|
||||
//errorMessageParam.Value
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
cmd.Connection.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
catch (Exception) { /*APILogger.Log("failed to delete fine locations1, ", ex); */}
|
||||
}
|
||||
public static MMEFineLocations1[] GetFineLocations1()
|
||||
{
|
||||
var fineLocations1 = new List<MMEFineLocations1>();
|
||||
|
||||
try
|
||||
{
|
||||
using (var cmd = DbOperations.GetSQLCommand(true))
|
||||
{
|
||||
try
|
||||
{
|
||||
cmd.CommandType = CommandType.StoredProcedure;
|
||||
cmd.CommandText = DbOperationsEnum.StoredProcedure.sp_MMEFineLocations1Get.ToString();
|
||||
cmd.Parameters.Add(new SqlParameter("@s_GUID", SqlDbType.NVarChar) { Value = null });
|
||||
using (var ds = DbOperations.Connection.QueryDataSet(cmd))
|
||||
{
|
||||
if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
|
||||
{
|
||||
try
|
||||
{
|
||||
fineLocations1.AddRange(from DataRow dr in ds.Tables[0].Rows
|
||||
let date = Convert.ToDateTime(
|
||||
dr[DbOperations.MMETables.MMEFineLocations1Fields.DATE.ToString()])
|
||||
let expired = Convert.ToBoolean(
|
||||
dr[DbOperations.MMETables.MMEFineLocations1Fields.EXPIRED.ToString()])
|
||||
let fineLoc1 = Convert.ToString(dr[
|
||||
DbOperations.MMETables.MMEFineLocations1Fields.FINE_LOC_1.ToString()])
|
||||
let history = Convert.ToString(
|
||||
dr[DbOperations.MMETables.MMEFineLocations1Fields.HISTORY.ToString()])
|
||||
let lastChange = Convert.ToDateTime(dr[
|
||||
DbOperations.MMETables.MMEFineLocations1Fields.LAST_CHANGE.ToString()])
|
||||
let lastChangeText = Convert.ToString(dr[
|
||||
DbOperations.MMETables.MMEFineLocations1Fields.LAST_CHANGE_TEXT.ToString()])
|
||||
let remarks = Convert.ToString(
|
||||
dr[DbOperations.MMETables.MMEFineLocations1Fields.REMARKS.ToString()])
|
||||
let sGuid = Convert.ToString(
|
||||
dr[DbOperations.MMETables.MMEFineLocations1Fields.s_GUID.ToString()])
|
||||
let sortKey = Convert.ToString(
|
||||
dr[DbOperations.MMETables.MMEFineLocations1Fields.SORTKEY.ToString()])
|
||||
let text1 = Convert.ToString(
|
||||
dr[DbOperations.MMETables.MMEFineLocations1Fields.TEXT_L1.ToString()])
|
||||
let text2 = Convert.ToString(
|
||||
dr[DbOperations.MMETables.MMEFineLocations1Fields.TEXT_L2.ToString()])
|
||||
let version = Convert.ToInt32(
|
||||
dr[DbOperations.MMETables.MMEFineLocations1Fields.VERSION.ToString()])
|
||||
select new MMEFineLocations1(sGuid, fineLoc1, text1, text2,
|
||||
Convert.ToInt64(version), date, remarks, expired, sortKey, lastChange,
|
||||
lastChangeText, history, MMEPossibleChannels.MMEChannelTypes.ISO13499_106));
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
//APILogger.Log("Failed to parse fine locations1:", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
cmd.Connection.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception) { /*APILogger.Log("failed to retrieve fine locations1, ", ex);*/ }
|
||||
|
||||
try
|
||||
{
|
||||
using (var cmd = DbOperations.GetSQLCommand(true))
|
||||
{
|
||||
try
|
||||
{
|
||||
cmd.CommandType = CommandType.StoredProcedure;
|
||||
cmd.CommandText = DbOperationsEnum.StoredProcedure.sp_MMEFineLocations1GetCustom.ToString();
|
||||
cmd.Parameters.Add(new SqlParameter("@s_GUID", SqlDbType.NVarChar) { Value = null });
|
||||
using (var ds = DbOperations.Connection.QueryDataSet(cmd))
|
||||
{
|
||||
if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
|
||||
{
|
||||
try
|
||||
{
|
||||
fineLocations1.AddRange(from DataRow dr in ds.Tables[0].Rows
|
||||
let date = Convert.ToDateTime(
|
||||
dr[DbOperations.MMETables.MMEFineLocations1Fields.DATE.ToString()])
|
||||
let expired = Convert.ToBoolean(
|
||||
dr[DbOperations.MMETables.MMEFineLocations1Fields.EXPIRED.ToString()])
|
||||
let fineLoc1 = Convert.ToString(dr[
|
||||
DbOperations.MMETables.MMEFineLocations1Fields.FINE_LOC_1.ToString()])
|
||||
let history = Convert.ToString(
|
||||
dr[DbOperations.MMETables.MMEFineLocations1Fields.HISTORY.ToString()])
|
||||
let lastChange = Convert.ToDateTime(dr[
|
||||
DbOperations.MMETables.MMEFineLocations1Fields.LAST_CHANGE.ToString()])
|
||||
let lastChangeText = Convert.ToString(dr[
|
||||
DbOperations.MMETables.MMEFineLocations1Fields.LAST_CHANGE_TEXT.ToString()])
|
||||
let remarks = Convert.ToString(
|
||||
dr[DbOperations.MMETables.MMEFineLocations1Fields.REMARKS.ToString()])
|
||||
let sGuid = Convert.ToString(
|
||||
dr[DbOperations.MMETables.MMEFineLocations1Fields.s_GUID.ToString()])
|
||||
let sortKey = Convert.ToString(
|
||||
dr[DbOperations.MMETables.MMEFineLocations1Fields.SORTKEY.ToString()])
|
||||
let text1 = Convert.ToString(
|
||||
dr[DbOperations.MMETables.MMEFineLocations1Fields.TEXT_L1.ToString()])
|
||||
let text2 = Convert.ToString(
|
||||
dr[DbOperations.MMETables.MMEFineLocations1Fields.TEXT_L2.ToString()])
|
||||
let version = Convert.ToInt32(
|
||||
dr[DbOperations.MMETables.MMEFineLocations1Fields.VERSION.ToString()])
|
||||
select new MMEFineLocations1(sGuid, fineLoc1, text1, text2,
|
||||
Convert.ToInt64(version), date, remarks, expired, sortKey, lastChange,
|
||||
lastChangeText, history, MMEPossibleChannels.MMEChannelTypes.SQL));
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
//APILogger.Log("Failed to parse custom fine locations1:", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
cmd.Connection.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception) { /*APILogger.Log("failed to retrieve custom fine locations1, ", ex);*/ }
|
||||
|
||||
return fineLocations1.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,215 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Data.SqlClient;
|
||||
|
||||
namespace DatabaseImport
|
||||
{
|
||||
public class MMEFineLocations2 //: AbstractOLEDbWrapper
|
||||
{
|
||||
public string S_GUID { get; }
|
||||
|
||||
public string FINE_LOC_2 { get; }
|
||||
|
||||
public string Text_L1 { get; }
|
||||
|
||||
public string Text_L2 { get; }
|
||||
|
||||
public long Version { get; }
|
||||
|
||||
public DateTime Date { get; }
|
||||
|
||||
public string Remarks { get; }
|
||||
|
||||
public bool Expired { get; }
|
||||
|
||||
public string SortKey { get; }
|
||||
|
||||
public DateTime Last_Change { get; }
|
||||
|
||||
public string Last_Change_Text { get; }
|
||||
|
||||
public string History { get; }
|
||||
|
||||
public MMEPossibleChannels.MMEChannelTypes RecordType { get; } = MMEPossibleChannels.MMEChannelTypes.ISO13499_106;
|
||||
public MMEFineLocations2(string sGuid, string fineLoc2, string textL1, string textL2, long version, DateTime date,
|
||||
string remarks, bool expired, string sortKey, DateTime lastChange, string lastChangeText, string history,
|
||||
MMEPossibleChannels.MMEChannelTypes type)
|
||||
{
|
||||
RecordType = type;
|
||||
S_GUID = sGuid;
|
||||
FINE_LOC_2 = fineLoc2;
|
||||
Text_L1 = textL1;
|
||||
Text_L2 = textL2;
|
||||
Version = version;
|
||||
Date = date;
|
||||
Remarks = remarks;
|
||||
Expired = expired;
|
||||
SortKey = sortKey;
|
||||
Last_Change = lastChange;
|
||||
Last_Change_Text = lastChangeText;
|
||||
History = history;
|
||||
}
|
||||
|
||||
public static void DeleteFineLocations2()
|
||||
{
|
||||
try
|
||||
{
|
||||
using (var cmd = DbOperations.GetSQLCommand(true))
|
||||
{
|
||||
try
|
||||
{
|
||||
cmd.CommandType = CommandType.StoredProcedure;
|
||||
cmd.CommandText = DbOperationsEnum.StoredProcedure.sp_MMEFineLocations2Delete.ToString();
|
||||
cmd.Parameters.Add(new SqlParameter("@s_GUID", SqlDbType.UniqueIdentifier) { 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);
|
||||
|
||||
cmd.ExecuteNonQuery();
|
||||
if (int.Parse(errorNumberParam.Value.ToString()) != 0)
|
||||
{
|
||||
//errorMessageParam.Value
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
cmd.Connection.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception) {/* APILogger.Log("failed to delete fine locations2, ", ex); */}
|
||||
}
|
||||
public static MMEFineLocations2[] GetFineLocations2()
|
||||
{
|
||||
var fineLocations2 = new List<MMEFineLocations2>();
|
||||
|
||||
try
|
||||
{
|
||||
using (var cmd = DbOperations.GetSQLCommand(true))
|
||||
{
|
||||
try
|
||||
{
|
||||
cmd.CommandType = CommandType.StoredProcedure;
|
||||
cmd.CommandText = DbOperationsEnum.StoredProcedure.sp_MMEFineLocations2Get.ToString();
|
||||
cmd.Parameters.Add(new SqlParameter("@s_GUID", SqlDbType.NVarChar) { Value = null });
|
||||
using (var ds = DbOperations.Connection.QueryDataSet(cmd))
|
||||
{
|
||||
if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
|
||||
{
|
||||
try
|
||||
{
|
||||
fineLocations2.AddRange(from DataRow dr in ds.Tables[0].Rows
|
||||
let date = Convert.ToDateTime(
|
||||
dr[DbOperations.MMETables.MMEFineLocations2Fields.DATE.ToString()])
|
||||
let expired = Convert.ToBoolean(
|
||||
dr[DbOperations.MMETables.MMEFineLocations2Fields.EXPIRED.ToString()])
|
||||
let fineLoc2 = Convert.ToString(dr[
|
||||
DbOperations.MMETables.MMEFineLocations2Fields.FINE_LOC_2.ToString()])
|
||||
let history = Convert.ToString(
|
||||
dr[DbOperations.MMETables.MMEFineLocations2Fields.HISTORY.ToString()])
|
||||
let lastChange = Convert.ToDateTime(dr[
|
||||
DbOperations.MMETables.MMEFineLocations2Fields.LAST_CHANGE.ToString()])
|
||||
let lastChangeText = Convert.ToString(dr[
|
||||
DbOperations.MMETables.MMEFineLocations2Fields.LAST_CHANGE_TEXT.ToString()])
|
||||
let remarks = Convert.ToString(
|
||||
dr[DbOperations.MMETables.MMEFineLocations2Fields.REMARKS.ToString()])
|
||||
let sGuid = Convert.ToString(
|
||||
dr[DbOperations.MMETables.MMEFineLocations2Fields.s_GUID.ToString()])
|
||||
let sortKey = Convert.ToString(
|
||||
dr[DbOperations.MMETables.MMEFineLocations2Fields.SORTKEY.ToString()])
|
||||
let text1 = Convert.ToString(
|
||||
dr[DbOperations.MMETables.MMEFineLocations2Fields.TEXT_L1.ToString()])
|
||||
let text2 = Convert.ToString(
|
||||
dr[DbOperations.MMETables.MMEFineLocations2Fields.TEXT_L2.ToString()])
|
||||
let version = Convert.ToInt32(
|
||||
dr[DbOperations.MMETables.MMEFineLocations2Fields.VERSION.ToString()])
|
||||
select new MMEFineLocations2(sGuid, fineLoc2, text1, text2,
|
||||
Convert.ToInt64(version), date, remarks, expired, sortKey, lastChange,
|
||||
lastChangeText, history, MMEPossibleChannels.MMEChannelTypes.ISO13499_106));
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
//APILogger.Log("Failed to parse fine locations2:", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
cmd.Connection.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception) { /*APILogger.Log("failed to retrieve fine locations2, ", ex); */}
|
||||
|
||||
try
|
||||
{
|
||||
using (var cmd = DbOperations.GetSQLCommand(true))
|
||||
{
|
||||
try
|
||||
{
|
||||
cmd.CommandType = CommandType.StoredProcedure;
|
||||
cmd.CommandText = DbOperationsEnum.StoredProcedure.sp_MMEFineLocations2GetCustom.ToString();
|
||||
cmd.Parameters.Add(new SqlParameter("@s_GUID", SqlDbType.NVarChar) { Value = null });
|
||||
using (var ds = DbOperations.Connection.QueryDataSet(cmd))
|
||||
{
|
||||
if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
|
||||
{
|
||||
try
|
||||
{
|
||||
fineLocations2.AddRange(from DataRow dr in ds.Tables[0].Rows
|
||||
let date = Convert.ToDateTime(
|
||||
dr[DbOperations.MMETables.MMEFineLocations2Fields.DATE.ToString()])
|
||||
let expired = Convert.ToBoolean(
|
||||
dr[DbOperations.MMETables.MMEFineLocations2Fields.EXPIRED.ToString()])
|
||||
let fineLoc2 = Convert.ToString(dr[
|
||||
DbOperations.MMETables.MMEFineLocations2Fields.FINE_LOC_2.ToString()])
|
||||
let history = Convert.ToString(
|
||||
dr[DbOperations.MMETables.MMEFineLocations2Fields.HISTORY.ToString()])
|
||||
let lastChange = Convert.ToDateTime(dr[
|
||||
DbOperations.MMETables.MMEFineLocations2Fields.LAST_CHANGE.ToString()])
|
||||
let lastChangeText = Convert.ToString(dr[
|
||||
DbOperations.MMETables.MMEFineLocations2Fields.LAST_CHANGE_TEXT.ToString()])
|
||||
let remarks = Convert.ToString(
|
||||
dr[DbOperations.MMETables.MMEFineLocations2Fields.REMARKS.ToString()])
|
||||
let sGuid = Convert.ToString(
|
||||
dr[DbOperations.MMETables.MMEFineLocations2Fields.s_GUID.ToString()])
|
||||
let sortKey = Convert.ToString(
|
||||
dr[DbOperations.MMETables.MMEFineLocations2Fields.SORTKEY.ToString()])
|
||||
let text1 = Convert.ToString(
|
||||
dr[DbOperations.MMETables.MMEFineLocations2Fields.TEXT_L1.ToString()])
|
||||
let text2 = Convert.ToString(
|
||||
dr[DbOperations.MMETables.MMEFineLocations2Fields.TEXT_L2.ToString()])
|
||||
let version = Convert.ToInt32(
|
||||
dr[DbOperations.MMETables.MMEFineLocations2Fields.VERSION.ToString()])
|
||||
select new MMEFineLocations2(sGuid, fineLoc2, text1, text2,
|
||||
Convert.ToInt64(version), date, remarks, expired, sortKey, lastChange,
|
||||
lastChangeText, history, MMEPossibleChannels.MMEChannelTypes.SQL));
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
//APILogger.Log("Failed to parse custom fine locations2:", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
cmd.Connection.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception) { /*APILogger.Log("failed to retrieve custom fine locations2, ", ex);*/ }
|
||||
|
||||
return fineLocations2.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,227 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Data.SqlClient;
|
||||
|
||||
namespace DatabaseImport
|
||||
{
|
||||
public class MMEFineLocations3 //: AbstractOLEDbWrapper
|
||||
{
|
||||
public string S_GUID { get; }
|
||||
|
||||
public string FINE_LOC_3 { get; }
|
||||
|
||||
public string Text_L1 { get; }
|
||||
|
||||
public string Text_L2 { get; }
|
||||
|
||||
public long Version { get; }
|
||||
|
||||
public DateTime Date { get; }
|
||||
|
||||
public string Remarks { get; }
|
||||
|
||||
public bool Expired { get; }
|
||||
|
||||
public string SortKey { get; }
|
||||
|
||||
public string Picture_ShortName { get; }
|
||||
|
||||
public DateTime Last_Change { get; }
|
||||
|
||||
public string Last_Change_Text { get; }
|
||||
|
||||
public string History { get; }
|
||||
|
||||
public MMEPossibleChannels.MMEChannelTypes RecordType { get; }
|
||||
public MMEFineLocations3(string sGuid, string fineLoc3, string textL1, string textL2, long version, DateTime date,
|
||||
string remarks, bool expired, string sortKey, DateTime lastChange, string lastChangeText, string history, string picturesShortName,
|
||||
MMEPossibleChannels.MMEChannelTypes type)
|
||||
{
|
||||
RecordType = type;
|
||||
S_GUID = sGuid;
|
||||
FINE_LOC_3 = fineLoc3;
|
||||
Text_L1 = textL1;
|
||||
Text_L2 = textL2;
|
||||
Version = version;
|
||||
Date = date;
|
||||
Remarks = remarks;
|
||||
Expired = expired;
|
||||
SortKey = sortKey;
|
||||
Last_Change = lastChange;
|
||||
Last_Change_Text = lastChangeText;
|
||||
History = history;
|
||||
Picture_ShortName = picturesShortName;
|
||||
}
|
||||
public static void DeleteFineLocations3()
|
||||
{
|
||||
try
|
||||
{
|
||||
using (var cmd = DbOperations.GetSQLCommand(true))
|
||||
{
|
||||
try
|
||||
{
|
||||
cmd.CommandType = CommandType.StoredProcedure;
|
||||
cmd.CommandText = DbOperationsEnum.StoredProcedure.sp_MMEFineLocations3Delete.ToString();
|
||||
cmd.Parameters.Add(new SqlParameter("@s_GUID", SqlDbType.UniqueIdentifier) { 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);
|
||||
|
||||
cmd.ExecuteNonQuery();
|
||||
if (int.Parse(errorNumberParam.Value.ToString()) != 0)
|
||||
{
|
||||
//errorMessageParam.Value
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
cmd.Connection.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception) {/* APILogger.Log("failed to delete fine locations3, ", ex); */}
|
||||
}
|
||||
public static MMEFineLocations3[] GetFineLocations3()
|
||||
{
|
||||
var fineLocations3 = new List<MMEFineLocations3>();
|
||||
try
|
||||
{
|
||||
using (var cmd = DbOperations.GetSQLCommand(true))
|
||||
{
|
||||
try
|
||||
{
|
||||
cmd.CommandType = CommandType.StoredProcedure;
|
||||
cmd.CommandText = DbOperationsEnum.StoredProcedure.sp_MMEFineLocations3Get.ToString();
|
||||
cmd.Parameters.Add(new SqlParameter("@s_GUID", SqlDbType.NVarChar) { Value = null });
|
||||
//cmd.ExecuteNonQuery();
|
||||
using (var ds = DbOperations.Connection.QueryDataSet(cmd))
|
||||
{
|
||||
|
||||
if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
|
||||
{
|
||||
try
|
||||
{
|
||||
fineLocations3.AddRange(from DataRow dr in ds.Tables[0].Rows
|
||||
let date = Convert.ToDateTime(
|
||||
dr[DbOperations.MMETables.MMEFineLocations3Fields.DATE.ToString()])
|
||||
let expired = Convert.ToBoolean(
|
||||
dr[DbOperations.MMETables.MMEFineLocations3Fields.EXPIRED.ToString()])
|
||||
let fineLoc3 = Convert.ToString(dr[
|
||||
DbOperations.MMETables.MMEFineLocations3Fields.FINE_LOC_3.ToString()])
|
||||
let history = Convert.ToString(
|
||||
dr[DbOperations.MMETables.MMEFineLocations3Fields.HISTORY.ToString()])
|
||||
let lastChange = Convert.ToDateTime(dr[
|
||||
DbOperations.MMETables.MMEFineLocations3Fields.LAST_CHANGE.ToString()])
|
||||
let lastChangeText = Convert.ToString(dr[
|
||||
DbOperations.MMETables.MMEFineLocations3Fields.LAST_CHANGE_TEXT.ToString()])
|
||||
let pictureShortName = Convert.ToString(dr[
|
||||
DbOperations.MMETables.MMEFineLocations3Fields.PICTURE_SHORTNAME
|
||||
.ToString()])
|
||||
let remarks = Convert.ToString(
|
||||
dr[DbOperations.MMETables.MMEFineLocations3Fields.REMARKS.ToString()])
|
||||
let sGuid = Convert.ToString(
|
||||
dr[DbOperations.MMETables.MMEFineLocations3Fields.s_GUID.ToString()])
|
||||
let sortKey = Convert.ToString(
|
||||
dr[DbOperations.MMETables.MMEFineLocations3Fields.SORTKEY.ToString()])
|
||||
let text1 = Convert.ToString(
|
||||
dr[DbOperations.MMETables.MMEFineLocations3Fields.TEXT_L1.ToString()])
|
||||
let text2 = Convert.ToString(
|
||||
dr[DbOperations.MMETables.MMEFineLocations3Fields.TEXT_L2.ToString()])
|
||||
let version = Convert.ToInt32(
|
||||
dr[DbOperations.MMETables.MMEFineLocations3Fields.VERSION.ToString()])
|
||||
select new MMEFineLocations3(sGuid, fineLoc3, text1, text2,
|
||||
Convert.ToInt64(version), date, remarks, expired, sortKey, lastChange,
|
||||
lastChangeText, history, pictureShortName,
|
||||
MMEPossibleChannels.MMEChannelTypes.ISO13499_106));
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
//APILogger.Log("Failed to process fine locations3: ", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
cmd.Connection.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception) { /*APILogger.Log("failed to load fine locations3, ", ex);*/ }
|
||||
|
||||
try
|
||||
{
|
||||
using (var cmd = DbOperations.GetSQLCommand(true))
|
||||
{
|
||||
try
|
||||
{
|
||||
cmd.CommandType = CommandType.StoredProcedure;
|
||||
cmd.CommandText = DbOperationsEnum.StoredProcedure.sp_MMEFineLocations3GetCustom.ToString();
|
||||
cmd.Parameters.Add(new SqlParameter("@s_GUID", SqlDbType.NVarChar) { Value = null });
|
||||
using (var ds = DbOperations.Connection.QueryDataSet(cmd))
|
||||
{
|
||||
|
||||
if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
|
||||
{
|
||||
try
|
||||
{
|
||||
fineLocations3.AddRange(from DataRow dr in ds.Tables[0].Rows
|
||||
let date = Convert.ToDateTime(
|
||||
dr[DbOperations.MMETables.MMEFineLocations3Fields.DATE.ToString()])
|
||||
let expired = Convert.ToBoolean(
|
||||
dr[DbOperations.MMETables.MMEFineLocations3Fields.EXPIRED.ToString()])
|
||||
let fineLoc3 = Convert.ToString(dr[
|
||||
DbOperations.MMETables.MMEFineLocations3Fields.FINE_LOC_3.ToString()])
|
||||
let history = Convert.ToString(
|
||||
dr[DbOperations.MMETables.MMEFineLocations3Fields.HISTORY.ToString()])
|
||||
let lastChange = Convert.ToDateTime(dr[
|
||||
DbOperations.MMETables.MMEFineLocations3Fields.LAST_CHANGE.ToString()])
|
||||
let lastChangeText = Convert.ToString(dr[
|
||||
DbOperations.MMETables.MMEFineLocations3Fields.LAST_CHANGE_TEXT.ToString()])
|
||||
let pictureShortName = Convert.ToString(dr[
|
||||
DbOperations.MMETables.MMEFineLocations3Fields.PICTURE_SHORTNAME
|
||||
.ToString()])
|
||||
let remarks = Convert.ToString(
|
||||
dr[DbOperations.MMETables.MMEFineLocations3Fields.REMARKS.ToString()])
|
||||
let sGuid = Convert.ToString(
|
||||
dr[DbOperations.MMETables.MMEFineLocations3Fields.s_GUID.ToString()])
|
||||
let sortKey = Convert.ToString(
|
||||
dr[DbOperations.MMETables.MMEFineLocations3Fields.SORTKEY.ToString()])
|
||||
let text1 = Convert.ToString(
|
||||
dr[DbOperations.MMETables.MMEFineLocations3Fields.TEXT_L1.ToString()])
|
||||
let text2 = Convert.ToString(
|
||||
dr[DbOperations.MMETables.MMEFineLocations3Fields.TEXT_L2.ToString()])
|
||||
let version = Convert.ToInt32(
|
||||
dr[DbOperations.MMETables.MMEFineLocations3Fields.VERSION.ToString()])
|
||||
select new MMEFineLocations3(sGuid, fineLoc3, text1, text2,
|
||||
Convert.ToInt64(version), date, remarks, expired, sortKey, lastChange,
|
||||
lastChangeText, history, pictureShortName,
|
||||
MMEPossibleChannels.MMEChannelTypes.SQL));
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
//APILogger.Log("Failed to process custom fine locations3: ", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
cmd.Connection.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception) {/* APILogger.Log("failed to load custom fine locations3, ", ex); */}
|
||||
|
||||
return fineLocations3.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,293 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Data.SqlClient;
|
||||
|
||||
namespace DatabaseImport
|
||||
{
|
||||
public class MMEPhysicalDimensions //: AbstractOLEDbWrapper
|
||||
{
|
||||
public string S_GUID { get; }
|
||||
|
||||
public string Physical_Dimension { get; }
|
||||
|
||||
public string Text_L1 { get; }
|
||||
|
||||
public string Text_L2 { get; }
|
||||
|
||||
public string Default_Unit { get; }
|
||||
|
||||
public long Length_EXP { get; }
|
||||
|
||||
public long Time_EXP { get; }
|
||||
|
||||
public long Mass_EXP { get; }
|
||||
|
||||
public long Electric_Current_EXP { get; }
|
||||
|
||||
public long Temperature_EXP { get; }
|
||||
|
||||
public long Luminous_Intensity_Exp { get; }
|
||||
|
||||
public long Amount_Of_Substance_EXP { get; }
|
||||
|
||||
public long Version { get; }
|
||||
|
||||
public DateTime Date { get; }
|
||||
|
||||
public string Remarks { get; }
|
||||
|
||||
public bool Expired { get; }
|
||||
|
||||
public string SortKey { get; }
|
||||
|
||||
public DateTime Last_Change { get; }
|
||||
|
||||
public string Last_Change_Text { get; }
|
||||
|
||||
public string History { get; }
|
||||
|
||||
public MMEPossibleChannels.MMEChannelTypes RecordType { get; } = MMEPossibleChannels.MMEChannelTypes.ISO13499_106;
|
||||
public MMEPhysicalDimensions(string sGUID, string physicalDimension, string textL1, string textL2, string defaultUnit,
|
||||
long lengthExp, long timeExp, long massExp, long currentExp, long temperatureExp, long luminiousExp, long amountExp,
|
||||
long version, DateTime date, string remarks, bool expired, string sortKey, DateTime lastChange, string lastChangeText,
|
||||
string history, MMEPossibleChannels.MMEChannelTypes type)
|
||||
{
|
||||
RecordType = type;
|
||||
S_GUID = sGUID;
|
||||
Physical_Dimension = physicalDimension;
|
||||
Text_L1 = textL1;
|
||||
Text_L2 = textL2;
|
||||
Default_Unit = defaultUnit;
|
||||
Length_EXP = lengthExp;
|
||||
Time_EXP = timeExp;
|
||||
Mass_EXP = massExp;
|
||||
Electric_Current_EXP = currentExp;
|
||||
Temperature_EXP = temperatureExp;
|
||||
Luminous_Intensity_Exp = luminiousExp;
|
||||
Amount_Of_Substance_EXP = amountExp;
|
||||
Version = version;
|
||||
Date = date;
|
||||
Remarks = remarks;
|
||||
Expired = expired;
|
||||
SortKey = sortKey;
|
||||
Last_Change = lastChange;
|
||||
Last_Change_Text = lastChangeText;
|
||||
History = history;
|
||||
}
|
||||
public static void DeletePhysicalDimensions()
|
||||
{
|
||||
try
|
||||
{
|
||||
using (var cmd = DbOperations.GetSQLCommand(true))
|
||||
{
|
||||
try
|
||||
{
|
||||
cmd.CommandType = CommandType.StoredProcedure;
|
||||
cmd.CommandText = DbOperationsEnum.StoredProcedure.sp_MMEPhysicalDimensionsDelete.ToString();
|
||||
cmd.Parameters.Add(new SqlParameter("@s_GUID", SqlDbType.UniqueIdentifier) { 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);
|
||||
|
||||
cmd.ExecuteNonQuery();
|
||||
if (int.Parse(errorNumberParam.Value.ToString()) != 0)
|
||||
{
|
||||
//errorMessageParam.Value
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
cmd.Connection.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception) {/* APILogger.Log("failed to delete physical dimensions", ex);*/ }
|
||||
}
|
||||
public static MMEPhysicalDimensions[] GetPhysicalDimensions()
|
||||
{
|
||||
var physicalDimensions = new List<MMEPhysicalDimensions>();
|
||||
|
||||
try
|
||||
{
|
||||
using (var cmd = DbOperations.GetSQLCommand(true))
|
||||
{
|
||||
try
|
||||
{
|
||||
cmd.CommandType = CommandType.StoredProcedure;
|
||||
cmd.CommandText = DbOperationsEnum.StoredProcedure.sp_MMEPhysicalDimensionsGet.ToString();
|
||||
cmd.Parameters.Add(new SqlParameter("@s_GUID", SqlDbType.NVarChar) { Value = null });
|
||||
using (var ds = DbOperations.Connection.QueryDataSet(cmd))
|
||||
{
|
||||
if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
|
||||
{
|
||||
try
|
||||
{
|
||||
physicalDimensions.AddRange(from DataRow dr in ds.Tables[0].Rows
|
||||
let amountOfSubstanceExp = Convert.ToInt32(
|
||||
dr[
|
||||
DbOperations.MMETables.MMEPhysicalDimensionFields.AMOUNT_OFSUBSTANCE_EXP
|
||||
.ToString()])
|
||||
let date = Convert.ToDateTime(
|
||||
dr[DbOperations.MMETables.MMEPhysicalDimensionFields.DATE.ToString()])
|
||||
let defaultUnit = Convert.ToString(dr[
|
||||
DbOperations.MMETables.MMEPhysicalDimensionFields.DEFAULT_UNIT.ToString()])
|
||||
let electricalExp = Convert.ToInt32(dr[
|
||||
DbOperations.MMETables.MMEPhysicalDimensionFields.ELECTRIC_CURRENT_EXP
|
||||
.ToString()])
|
||||
let expired = Convert.ToBoolean(dr[
|
||||
DbOperations.MMETables.MMEPhysicalDimensionFields.EXPIRED.ToString()])
|
||||
let history = Convert.ToString(dr[
|
||||
DbOperations.MMETables.MMEPhysicalDimensionFields.HISTORY.ToString()])
|
||||
let lastChange = Convert.ToDateTime(dr[
|
||||
DbOperations.MMETables.MMEPhysicalDimensionFields.LAST_CHANGE.ToString()])
|
||||
let lastChangeText = Convert.ToString(dr[
|
||||
DbOperations.MMETables.MMEPhysicalDimensionFields.LAST_CHANGE_TEXT
|
||||
.ToString()])
|
||||
let lengthExp = Convert.ToInt32(dr[
|
||||
DbOperations.MMETables.MMEPhysicalDimensionFields.LENGTH_EXP.ToString()])
|
||||
let lumIntExp = Convert.ToInt32(dr[
|
||||
DbOperations.MMETables.MMEPhysicalDimensionFields.LUMINOUS_INTENSITY_EXP
|
||||
.ToString()])
|
||||
let massExp = Convert.ToInt32(dr[
|
||||
DbOperations.MMETables.MMEPhysicalDimensionFields.MASS_EXP.ToString()])
|
||||
let physicalDimension = Convert.ToString(dr[
|
||||
DbOperations.MMETables.MMEPhysicalDimensionFields.PHYSICAL_DIMENSION
|
||||
.ToString()])
|
||||
let remarks = Convert.ToString(dr[
|
||||
DbOperations.MMETables.MMEPhysicalDimensionFields.REMARKS.ToString()])
|
||||
let sGuid = Convert.ToString(dr[
|
||||
DbOperations.MMETables.MMEPhysicalDimensionFields.s_GUID.ToString()])
|
||||
let sortKey = Convert.ToString(dr[
|
||||
DbOperations.MMETables.MMEPhysicalDimensionFields.SORTKEY.ToString()])
|
||||
let tempExp = Convert.ToInt32(dr[
|
||||
DbOperations.MMETables.MMEPhysicalDimensionFields.TEMPERATURE_EXP
|
||||
.ToString()])
|
||||
let text1 = Convert.ToString(dr[
|
||||
DbOperations.MMETables.MMEPhysicalDimensionFields.TEXT_L1.ToString()])
|
||||
let text2 = Convert.ToString(dr[
|
||||
DbOperations.MMETables.MMEPhysicalDimensionFields.TEXT_L2.ToString()])
|
||||
let timeExp = Convert.ToInt32(dr[
|
||||
DbOperations.MMETables.MMEPhysicalDimensionFields.TIME_EXP.ToString()])
|
||||
let version = Convert.ToInt32(dr[
|
||||
DbOperations.MMETables.MMEPhysicalDimensionFields.VERSION.ToString()])
|
||||
select new MMEPhysicalDimensions(sGuid, physicalDimension, text1, text2,
|
||||
defaultUnit, Convert.ToInt64(lengthExp), Convert.ToInt64(timeExp),
|
||||
Convert.ToInt64(massExp), Convert.ToInt64(electricalExp),
|
||||
Convert.ToInt64(tempExp), Convert.ToInt64(lumIntExp),
|
||||
Convert.ToInt64(amountOfSubstanceExp), Convert.ToInt64(version), date,
|
||||
remarks, expired, sortKey, lastChange, lastChangeText, history,
|
||||
MMEPossibleChannels.MMEChannelTypes.ISO13499_106));
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
//APILogger.Log("Failed to parse physical dimensions: ", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
cmd.Connection.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception) { /*APILogger.Log("failed to retrieve physical dimensions", ex);*/ }
|
||||
|
||||
try
|
||||
{
|
||||
using (var cmd = DbOperations.GetSQLCommand(true))
|
||||
{
|
||||
try
|
||||
{
|
||||
cmd.CommandType = CommandType.StoredProcedure;
|
||||
cmd.CommandText = DbOperationsEnum.StoredProcedure.sp_MMEPhysicalDimensionsGetCustom.ToString();
|
||||
cmd.Parameters.Add(new SqlParameter("@s_GUID", SqlDbType.NVarChar) { Value = null });
|
||||
using (var ds = DbOperations.Connection.QueryDataSet(cmd))
|
||||
{
|
||||
if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
|
||||
{
|
||||
try
|
||||
{
|
||||
physicalDimensions.AddRange(from DataRow dr in ds.Tables[0].Rows
|
||||
let amountOfSubstanceExp = Convert.ToInt32(
|
||||
dr[
|
||||
DbOperations.MMETables.MMEPhysicalDimensionFields.AMOUNT_OFSUBSTANCE_EXP
|
||||
.ToString()])
|
||||
let date = Convert.ToDateTime(
|
||||
dr[DbOperations.MMETables.MMEPhysicalDimensionFields.DATE.ToString()])
|
||||
let defaultUnit = Convert.ToString(dr[
|
||||
DbOperations.MMETables.MMEPhysicalDimensionFields.DEFAULT_UNIT.ToString()])
|
||||
let electricalExp = Convert.ToInt32(dr[
|
||||
DbOperations.MMETables.MMEPhysicalDimensionFields.ELECTRIC_CURRENT_EXP
|
||||
.ToString()])
|
||||
let expired = Convert.ToBoolean(dr[
|
||||
DbOperations.MMETables.MMEPhysicalDimensionFields.EXPIRED.ToString()])
|
||||
let history = Convert.ToString(dr[
|
||||
DbOperations.MMETables.MMEPhysicalDimensionFields.HISTORY.ToString()])
|
||||
let lastChange = Convert.ToDateTime(dr[
|
||||
DbOperations.MMETables.MMEPhysicalDimensionFields.LAST_CHANGE.ToString()])
|
||||
let lastChangeText = Convert.ToString(dr[
|
||||
DbOperations.MMETables.MMEPhysicalDimensionFields.LAST_CHANGE_TEXT
|
||||
.ToString()])
|
||||
let lengthExp = Convert.ToInt32(dr[
|
||||
DbOperations.MMETables.MMEPhysicalDimensionFields.LENGTH_EXP.ToString()])
|
||||
let lumIntExp = Convert.ToInt32(dr[
|
||||
DbOperations.MMETables.MMEPhysicalDimensionFields.LUMINOUS_INTENSITY_EXP
|
||||
.ToString()])
|
||||
let massExp = Convert.ToInt32(dr[
|
||||
DbOperations.MMETables.MMEPhysicalDimensionFields.MASS_EXP.ToString()])
|
||||
let physicalDimension = Convert.ToString(dr[
|
||||
DbOperations.MMETables.MMEPhysicalDimensionFields.PHYSICAL_DIMENSION
|
||||
.ToString()])
|
||||
let remarks = Convert.ToString(dr[
|
||||
DbOperations.MMETables.MMEPhysicalDimensionFields.REMARKS.ToString()])
|
||||
let sGuid = Convert.ToString(dr[
|
||||
DbOperations.MMETables.MMEPhysicalDimensionFields.s_GUID.ToString()])
|
||||
let sortKey = Convert.ToString(dr[
|
||||
DbOperations.MMETables.MMEPhysicalDimensionFields.SORTKEY.ToString()])
|
||||
let tempExp = Convert.ToInt32(dr[
|
||||
DbOperations.MMETables.MMEPhysicalDimensionFields.TEMPERATURE_EXP
|
||||
.ToString()])
|
||||
let text1 = Convert.ToString(dr[
|
||||
DbOperations.MMETables.MMEPhysicalDimensionFields.TEXT_L1.ToString()])
|
||||
let text2 = Convert.ToString(dr[
|
||||
DbOperations.MMETables.MMEPhysicalDimensionFields.TEXT_L2.ToString()])
|
||||
let timeExp = Convert.ToInt32(dr[
|
||||
DbOperations.MMETables.MMEPhysicalDimensionFields.TIME_EXP.ToString()])
|
||||
let version = Convert.ToInt32(dr[
|
||||
DbOperations.MMETables.MMEPhysicalDimensionFields.VERSION.ToString()])
|
||||
select new MMEPhysicalDimensions(sGuid, physicalDimension, text1, text2,
|
||||
defaultUnit, Convert.ToInt64(lengthExp), Convert.ToInt64(timeExp),
|
||||
Convert.ToInt64(massExp), Convert.ToInt64(electricalExp),
|
||||
Convert.ToInt64(tempExp), Convert.ToInt64(lumIntExp),
|
||||
Convert.ToInt64(amountOfSubstanceExp), Convert.ToInt64(version), date,
|
||||
remarks, expired, sortKey, lastChange, lastChangeText, history,
|
||||
MMEPossibleChannels.MMEChannelTypes.SQL));
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
//APILogger.Log("Failed to parse custom physical dimensions: ", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
cmd.Connection.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception) { /*APILogger.Log("failed to retrieve custom physical dimensions", ex); */}
|
||||
|
||||
return physicalDimensions.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,206 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Data.SqlClient;
|
||||
|
||||
namespace DatabaseImport
|
||||
{
|
||||
public class MMEPositions //: AbstractOLEDbWrapper
|
||||
{
|
||||
public string S_GUID { get; }
|
||||
|
||||
public string Position { get; }
|
||||
|
||||
public string Text_L1 { get; }
|
||||
|
||||
public string Text_L2 { get; }
|
||||
|
||||
public long Version { get; }
|
||||
|
||||
public DateTime Date { get; }
|
||||
|
||||
public string Remarks { get; }
|
||||
|
||||
public bool Expired { get; }
|
||||
|
||||
public string SortKey { get; }
|
||||
|
||||
public DateTime Last_Change { get; }
|
||||
|
||||
public string Last_Change_Text { get; }
|
||||
|
||||
public string History { get; }
|
||||
|
||||
public MMEPossibleChannels.MMEChannelTypes RecordType { get; } = MMEPossibleChannels.MMEChannelTypes.ISO13499_106;
|
||||
public MMEPositions(string sGuid, string position, string textL1, string textL2, long version,
|
||||
DateTime date, string remarks, bool expired, string sortKey, DateTime lastChange, string lastChangeText,
|
||||
string history, MMEPossibleChannels.MMEChannelTypes type)
|
||||
{
|
||||
RecordType = type;
|
||||
S_GUID = sGuid;
|
||||
Position = position;
|
||||
Text_L1 = textL1;
|
||||
Text_L2 = textL2;
|
||||
Version = version;
|
||||
Date = date;
|
||||
Remarks = remarks;
|
||||
Expired = expired;
|
||||
SortKey = sortKey;
|
||||
Last_Change = lastChange;
|
||||
Last_Change_Text = lastChangeText;
|
||||
History = history;
|
||||
}
|
||||
public static void DeletePositions()
|
||||
{
|
||||
try
|
||||
{
|
||||
using (var cmd = DbOperations.GetSQLCommand(true))
|
||||
{
|
||||
try
|
||||
{
|
||||
cmd.CommandType = CommandType.StoredProcedure;
|
||||
cmd.CommandText = DbOperationsEnum.StoredProcedure.sp_MMEPositionsDelete.ToString();
|
||||
cmd.Parameters.Add(new SqlParameter("@s_GUID", SqlDbType.UniqueIdentifier) { 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);
|
||||
|
||||
cmd.ExecuteNonQuery();
|
||||
if (int.Parse(errorNumberParam.Value.ToString()) != 0)
|
||||
{
|
||||
//errorMessageParam.Value
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
cmd.Connection.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception) { /*APILogger.Log("failed to delete positions, ", ex);*/ }
|
||||
}
|
||||
public static MMEPositions[] GetPositions()
|
||||
{
|
||||
var positions = new List<MMEPositions>();
|
||||
|
||||
using (var cmd = DbOperations.GetSQLCommand(true))
|
||||
{
|
||||
try
|
||||
{
|
||||
cmd.CommandType = CommandType.StoredProcedure;
|
||||
cmd.CommandText = DbOperationsEnum.StoredProcedure.sp_MMEPositionsGet.ToString();
|
||||
cmd.Parameters.Add(new SqlParameter("@s_GUID", SqlDbType.NVarChar) { Value = null });
|
||||
using (var ds = DbOperations.Connection.QueryDataSet(cmd))
|
||||
{
|
||||
if (ds.Tables.Count <= 0 || ds.Tables[0].Rows.Count <= 0) return positions.ToArray();
|
||||
try
|
||||
{
|
||||
positions.AddRange(from DataRow dr in ds.Tables[0].Rows
|
||||
let date = Convert.ToDateTime(
|
||||
dr[DbOperations.MMETables.MMEPositionsFields.DATE.ToString()])
|
||||
let expired =
|
||||
Convert.ToBoolean(dr[DbOperations.MMETables.MMEPositionsFields.EXPIRED.ToString()])
|
||||
let history =
|
||||
Convert.ToString(dr[DbOperations.MMETables.MMEPositionsFields.HISTORY.ToString()])
|
||||
let lastChange =
|
||||
Convert.ToDateTime(
|
||||
dr[DbOperations.MMETables.MMEPositionsFields.LAST_CHANGE.ToString()])
|
||||
let lastChangeText =
|
||||
Convert.ToString(
|
||||
dr[DbOperations.MMETables.MMEPositionsFields.LAST_CHANGE_TEXT.ToString()])
|
||||
let position =
|
||||
Convert.ToString(dr[DbOperations.MMETables.MMEPositionsFields.POSITION.ToString()])
|
||||
let remarks =
|
||||
Convert.ToString(dr[DbOperations.MMETables.MMEPositionsFields.REMARKS.ToString()])
|
||||
let sGuid = Convert.ToString(
|
||||
dr[DbOperations.MMETables.MMEPositionsFields.s_GUID.ToString()])
|
||||
let sortKey =
|
||||
Convert.ToString(dr[DbOperations.MMETables.MMEPositionsFields.SORTKEY.ToString()])
|
||||
let text1 = Convert.ToString(
|
||||
dr[DbOperations.MMETables.MMEPositionsFields.TEXT_L1.ToString()])
|
||||
let text2 = Convert.ToString(
|
||||
dr[DbOperations.MMETables.MMEPositionsFields.TEXT_L2.ToString()])
|
||||
let version =
|
||||
Convert.ToInt32(dr[DbOperations.MMETables.MMEPositionsFields.VERSION.ToString()])
|
||||
select new MMEPositions(sGuid, position, text1, text2, Convert.ToInt64(version), date,
|
||||
remarks, expired, sortKey, lastChange, lastChangeText, history,
|
||||
MMEPossibleChannels.MMEChannelTypes.ISO13499_106));
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
//APILogger.Log("Failed to get positions", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
cmd.Connection.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
using (var cmd = DbOperations.GetSQLCommand(true))
|
||||
{
|
||||
try
|
||||
{
|
||||
cmd.CommandType = CommandType.StoredProcedure;
|
||||
cmd.CommandText = DbOperationsEnum.StoredProcedure.sp_MMEPositionsGetCustom.ToString();
|
||||
cmd.Parameters.Add(new SqlParameter("@s_GUID", SqlDbType.NVarChar) { Value = null });
|
||||
using (var ds = DbOperations.Connection.QueryDataSet(cmd))
|
||||
{
|
||||
if (ds.Tables.Count <= 0 || ds.Tables[0].Rows.Count <= 0) return positions.ToArray();
|
||||
try
|
||||
{
|
||||
positions.AddRange(from DataRow dr in ds.Tables[0].Rows
|
||||
let date = Convert.ToDateTime(
|
||||
dr[DbOperations.MMETables.MMEPositionsFields.DATE.ToString()])
|
||||
let expired =
|
||||
Convert.ToBoolean(dr[DbOperations.MMETables.MMEPositionsFields.EXPIRED.ToString()])
|
||||
let history =
|
||||
Convert.ToString(dr[DbOperations.MMETables.MMEPositionsFields.HISTORY.ToString()])
|
||||
let lastChange =
|
||||
Convert.ToDateTime(
|
||||
dr[DbOperations.MMETables.MMEPositionsFields.LAST_CHANGE.ToString()])
|
||||
let lastChangeText =
|
||||
Convert.ToString(
|
||||
dr[DbOperations.MMETables.MMEPositionsFields.LAST_CHANGE_TEXT.ToString()])
|
||||
let position =
|
||||
Convert.ToString(dr[DbOperations.MMETables.MMEPositionsFields.POSITION.ToString()])
|
||||
let remarks =
|
||||
Convert.ToString(dr[DbOperations.MMETables.MMEPositionsFields.REMARKS.ToString()])
|
||||
let sGuid = Convert.ToString(
|
||||
dr[DbOperations.MMETables.MMEPositionsFields.s_GUID.ToString()])
|
||||
let sortKey =
|
||||
Convert.ToString(dr[DbOperations.MMETables.MMEPositionsFields.SORTKEY.ToString()])
|
||||
let text1 = Convert.ToString(
|
||||
dr[DbOperations.MMETables.MMEPositionsFields.TEXT_L1.ToString()])
|
||||
let text2 = Convert.ToString(
|
||||
dr[DbOperations.MMETables.MMEPositionsFields.TEXT_L2.ToString()])
|
||||
let version =
|
||||
Convert.ToInt32(dr[DbOperations.MMETables.MMEPositionsFields.VERSION.ToString()])
|
||||
select new MMEPositions(sGuid, position, text1, text2, Convert.ToInt64(version), date,
|
||||
remarks, expired, sortKey, lastChange, lastChangeText, history,
|
||||
MMEPossibleChannels.MMEChannelTypes.SQL));
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
//APILogger.Log("Failed to get custom positions", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
cmd.Connection.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
return positions.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,247 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Data.SqlClient;
|
||||
|
||||
namespace DatabaseImport
|
||||
{
|
||||
/// <summary>
|
||||
/// this is a "possible" channel, once we know what iso object we are dealing with there can be a number of channels
|
||||
/// defined for the object. We might not care about all of them ...
|
||||
/// this is also a template channel, in that some fields will not be known yet (direction, dimension maybe, position, etc)
|
||||
/// TestObjectChannel will consume this channel and then allow setting the locations as needed
|
||||
/// </summary>
|
||||
public class MMEPossibleChannels //: AbstractOLEDbWrapper
|
||||
{
|
||||
public long Id { get; set; }
|
||||
public string Type { get; private set; }
|
||||
public string Test_Object { get; private set; }
|
||||
public string Position { get; private set; }
|
||||
public string Trans_Main_Loc { get; private set; }
|
||||
public string Fine_Loc_1 { get; private set; }
|
||||
public string Fine_Loc_2 { get; private set; }
|
||||
public string Fine_Loc_3 { get; private set; }
|
||||
public string Physical_Dimension { get; private set; }
|
||||
public string Direction { get; private set; }
|
||||
public string Default_Filter_Class { get; private set; }
|
||||
public string Text_L1 { get; private set; }
|
||||
public void SetText1(string text1) { Text_L1 = text1; }
|
||||
public string Text_L2 { get; private set; }
|
||||
public long Version { get; }
|
||||
public DateTime Date { get; }
|
||||
public string Remarks { get; private set; }
|
||||
public bool Expired { get; }
|
||||
public string SortKey { get; }
|
||||
public string Picture_ShortName { get; }
|
||||
public DateTime Last_Change { get; }
|
||||
public string Last_Change_Text { get; }
|
||||
public string History { get; }
|
||||
public int MMEChannelType { get; }
|
||||
public MMEPossibleChannels(MMEPossibleChannels copy)
|
||||
{
|
||||
Id = copy.Id;
|
||||
Type = copy.Type;
|
||||
Test_Object = copy.Test_Object;
|
||||
Position = copy.Position;
|
||||
Trans_Main_Loc = copy.Trans_Main_Loc;
|
||||
Fine_Loc_1 = copy.Fine_Loc_1;
|
||||
Fine_Loc_2 = copy.Fine_Loc_2;
|
||||
Fine_Loc_3 = copy.Fine_Loc_3;
|
||||
Physical_Dimension = copy.Physical_Dimension;
|
||||
Direction = copy.Direction; ;
|
||||
Default_Filter_Class = copy.Default_Filter_Class;
|
||||
Text_L1 = copy.Text_L1;
|
||||
Text_L2 = copy.Text_L2;
|
||||
Version = copy.Version;
|
||||
Date = copy.Date;
|
||||
Remarks = copy.Remarks;
|
||||
Expired = copy.Expired;
|
||||
SortKey = copy.SortKey;
|
||||
Picture_ShortName = copy.Picture_ShortName;
|
||||
Last_Change = copy.Last_Change;
|
||||
Last_Change_Text = copy.Last_Change_Text;
|
||||
History = copy.History;
|
||||
MMEChannelType = copy.MMEChannelType;
|
||||
}
|
||||
public MMEPossibleChannels(long id, string type, string textObject, string position, string transMainLoc,
|
||||
string fineLoc1, string fineLoc2, string fineLoc3, string physicalDimension, string direction, string defaultFilterClass,
|
||||
string textL1, string textL2, long version, DateTime date, string remarks, bool expired, string sortkey,
|
||||
string pictureShortName, DateTime lastChange, string lastChangeText, string history, int mmeChannelType)
|
||||
{
|
||||
Id = id;
|
||||
Type = type;
|
||||
Test_Object = textObject;
|
||||
Position = position;
|
||||
Trans_Main_Loc = transMainLoc;
|
||||
Fine_Loc_1 = fineLoc1;
|
||||
Fine_Loc_2 = fineLoc2;
|
||||
Fine_Loc_3 = fineLoc3;
|
||||
Physical_Dimension = physicalDimension;
|
||||
Direction = direction;
|
||||
Default_Filter_Class = defaultFilterClass;
|
||||
Text_L1 = textL1;
|
||||
Text_L2 = textL2;
|
||||
Version = version;
|
||||
Date = date;
|
||||
Remarks = remarks;
|
||||
Expired = expired;
|
||||
SortKey = sortkey;
|
||||
Picture_ShortName = pictureShortName;
|
||||
Last_Change = lastChange;
|
||||
Last_Change_Text = lastChangeText;
|
||||
History = history;
|
||||
MMEChannelType = mmeChannelType;
|
||||
}
|
||||
public enum MMEChannelTypes
|
||||
{
|
||||
ISO13499_106,
|
||||
SQL
|
||||
}
|
||||
public static void DeletePossibleChannels()
|
||||
{
|
||||
try
|
||||
{
|
||||
using (var cmd = DbOperations.GetSQLCommand(true))
|
||||
{
|
||||
try
|
||||
{
|
||||
cmd.CommandType = CommandType.StoredProcedure;
|
||||
cmd.CommandText = DbOperationsEnum.StoredProcedure.sp_MMEPossibleChannelsDelete.ToString();
|
||||
cmd.Parameters.Add(new SqlParameter("@ID", SqlDbType.UniqueIdentifier) { 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);
|
||||
|
||||
cmd.ExecuteNonQuery();
|
||||
if (int.Parse(errorNumberParam.Value.ToString()) != 0)
|
||||
{
|
||||
//errorMessageParam.Value
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
cmd.Connection.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception) {/* APILogger.Log("failed to delete possible channels, ", ex);*/ }
|
||||
}
|
||||
public static MMEPossibleChannels[] GetPossibleChannels()
|
||||
{
|
||||
var possibleChannels = new List<MMEPossibleChannels>();
|
||||
|
||||
try
|
||||
{
|
||||
using (var cmd = DbOperations.GetSQLCommand(true))
|
||||
{
|
||||
try
|
||||
{
|
||||
cmd.CommandType = CommandType.StoredProcedure;
|
||||
cmd.CommandText = DbOperationsEnum.StoredProcedure.sp_MMEPossibleChannelsGet.ToString();
|
||||
cmd.Parameters.Add(new SqlParameter("@Id", SqlDbType.NVarChar) { Value = null });
|
||||
using (var ds = DbOperations.Connection.QueryDataSet(cmd))
|
||||
{
|
||||
if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
|
||||
{
|
||||
possibleChannels.AddRange(from DataRow dr in ds.Tables[0].Rows
|
||||
let id = Convert.ToInt64(dr["ID"])
|
||||
let type = Convert.ToString(dr["TYPE"])
|
||||
let testobject = Convert.ToString(dr["TEST_OBJECT"])
|
||||
let position = Convert.ToString(dr["POSITION"])
|
||||
let mainloc = Convert.ToString(dr["TRANS_MAIN_LOC"])
|
||||
let fineloc1 = Convert.ToString(dr["FINE_LOC_1"])
|
||||
let fineloc2 = Convert.ToString(dr["FINE_LOC_2"])
|
||||
let fineloc3 = Convert.ToString(dr["FINE_LOC_3"])
|
||||
let dimension = Convert.ToString(dr["PHYSICAL_DIMENSION"])
|
||||
let direction = Convert.ToString(dr["DIRECTION"])
|
||||
let filter = Convert.ToString(dr["DEFAULT_FILTER_CLASS"])
|
||||
let textL1 = Convert.ToString(dr["TEXT_L1"])
|
||||
let textL2 = Convert.ToString(dr["TEXT_L2"])
|
||||
let version = Convert.ToInt32(dr["VERSION"])
|
||||
let date = Convert.ToDateTime(dr["DATE"])
|
||||
let remarks = Convert.ToString(dr["REMARKS"])
|
||||
let expired = Convert.ToBoolean(dr["EXPIRED"])
|
||||
let sortkey = Convert.ToString(dr["SORTKEY"])
|
||||
let pictureShortName = Convert.ToString(dr["PICTURE_SHORTNAME"])
|
||||
let lastChange = Convert.ToDateTime(dr["LAST_CHANGE"])
|
||||
let lastChangeText = Convert.ToString(dr["LAST_CHANGE_TEXT"])
|
||||
let history = Convert.ToString(dr["HISTORY"])
|
||||
let isoFlag = Convert.ToString(dr["ISOFlag"])
|
||||
select new MMEPossibleChannels(id, type, testobject, position, mainloc, fineloc1,
|
||||
fineloc2, fineloc3, dimension, direction, filter, textL1, textL2,
|
||||
Convert.ToInt64(version), date, remarks, expired, sortkey, pictureShortName,
|
||||
lastChange, lastChangeText, history, Convert.ToInt16(isoFlag)));
|
||||
}
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
cmd.Connection.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception) { /*APILogger.Log("failed to get possible channels, ", ex);*/}
|
||||
|
||||
try
|
||||
{
|
||||
using (var cmd = DbOperations.GetSQLCommand(true))
|
||||
{
|
||||
try
|
||||
{
|
||||
cmd.CommandType = CommandType.StoredProcedure;
|
||||
cmd.CommandText = DbOperationsEnum.StoredProcedure.sp_MMEPossibleChannelsGetCustom.ToString();
|
||||
cmd.Parameters.Add(new SqlParameter("@Id", SqlDbType.NVarChar) { Value = null });
|
||||
|
||||
using (var ds = DbOperations.Connection.QueryDataSet(cmd))
|
||||
{
|
||||
if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
|
||||
{
|
||||
possibleChannels.AddRange(from DataRow dr in ds.Tables[0].Rows
|
||||
let id = Convert.ToInt64(dr["ID"])
|
||||
let type = Convert.ToString(dr["TYPE"])
|
||||
let testobject = Convert.ToString(dr["TEST_OBJECT"])
|
||||
let position = Convert.ToString(dr["POSITION"])
|
||||
let mainloc = Convert.ToString(dr["TRANS_MAIN_LOC"])
|
||||
let fineloc1 = Convert.ToString(dr["FINE_LOC_1"])
|
||||
let fineloc2 = Convert.ToString(dr["FINE_LOC_2"])
|
||||
let fineloc3 = Convert.ToString(dr["FINE_LOC_3"])
|
||||
let dimension = Convert.ToString(dr["PHYSICAL_DIMENSION"])
|
||||
let direction = Convert.ToString(dr["DIRECTION"])
|
||||
let filter = Convert.ToString(dr["DEFAULT_FILTER_CLASS"])
|
||||
let textL1 = Convert.ToString(dr["TEXT_L1"])
|
||||
let textL2 = Convert.ToString(dr["TEXT_L2"])
|
||||
let version = Convert.ToInt32(dr["VERSION"])
|
||||
let date = Convert.ToDateTime(dr["DATE"])
|
||||
let remarks = Convert.ToString(dr["REMARKS"])
|
||||
let expired = Convert.ToBoolean(dr["EXPIRED"])
|
||||
let sortkey = Convert.ToString(dr["SORTKEY"])
|
||||
let pictureShortName = Convert.ToString(dr["PICTURE_SHORTNAME"])
|
||||
let lastChange = Convert.ToDateTime(dr["LAST_CHANGE"])
|
||||
let lastChangeText = Convert.ToString(dr["LAST_CHANGE_TEXT"])
|
||||
let history = Convert.ToString(dr["HISTORY"])
|
||||
let isoFlag = MMEChannelTypes.SQL
|
||||
select new MMEPossibleChannels(id, type, testobject, position, mainloc, fineloc1,
|
||||
fineloc2, fineloc3, dimension, direction, filter, textL1, textL2,
|
||||
Convert.ToInt64(version), date, remarks, expired, sortkey, pictureShortName,
|
||||
lastChange, lastChangeText, history, Convert.ToInt16(isoFlag)));
|
||||
}
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
cmd.Connection.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception) { /*APILogger.Log("failed to get possible custom channels, ", ex); */}
|
||||
return possibleChannels.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,270 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Data.SqlClient;
|
||||
|
||||
namespace DatabaseImport
|
||||
{
|
||||
/// <summary>
|
||||
/// a test object is a top level object in the ISO database
|
||||
/// given a test object, it is possible to find all possible channels as defined in ISO
|
||||
/// note there is a ? test object ...
|
||||
/// I'll use these to build templates
|
||||
/// </summary>
|
||||
public class MMETestObjects //: AbstractOLEDbWrapper
|
||||
{
|
||||
public string S_GUID { get; }
|
||||
|
||||
public string Test_Object { get; }
|
||||
|
||||
public string Text_L1 { get; }
|
||||
|
||||
public string Text_L2 { get; }
|
||||
|
||||
public long Version { get; }
|
||||
|
||||
public DateTime Date { get; }
|
||||
|
||||
public string Remarks { get; }
|
||||
|
||||
public bool Expired { get; }
|
||||
|
||||
public string SortKey { get; }
|
||||
|
||||
public DateTime Last_Change { get; }
|
||||
|
||||
public string Last_Change_Text { get; }
|
||||
|
||||
public string History { get; }
|
||||
|
||||
public MMEPossibleChannels.MMEChannelTypes RecordType { get; } = MMEPossibleChannels.MMEChannelTypes.ISO13499_106;
|
||||
public MMETestObjects(string sGuid, string testObject, string textL1, string textL2, long version,
|
||||
DateTime date, string remarks, bool expired, string sortkey, DateTime lastChange, string lastChangeText,
|
||||
string history, MMEPossibleChannels.MMEChannelTypes type)
|
||||
{
|
||||
RecordType = type;
|
||||
S_GUID = sGuid;
|
||||
Test_Object = testObject;
|
||||
Text_L1 = textL1;
|
||||
Text_L2 = textL2;
|
||||
Version = version;
|
||||
Date = date;
|
||||
Remarks = remarks;
|
||||
Expired = expired;
|
||||
SortKey = sortkey;
|
||||
Last_Change = lastChange;
|
||||
Last_Change_Text = lastChangeText;
|
||||
History = history;
|
||||
}
|
||||
public static void DeleteTestObjects()
|
||||
{
|
||||
try
|
||||
{
|
||||
using (var cmd = DbOperations.GetSQLCommand(true))
|
||||
{
|
||||
try
|
||||
{
|
||||
cmd.CommandType = CommandType.StoredProcedure;
|
||||
cmd.CommandText = DbOperationsEnum.StoredProcedure.sp_MMETestObjectsDelete.ToString();
|
||||
cmd.Parameters.Add(new SqlParameter("@s_GUID", SqlDbType.UniqueIdentifier) { 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);
|
||||
|
||||
cmd.ExecuteNonQuery();
|
||||
if (int.Parse(errorNumberParam.Value.ToString()) != 0)
|
||||
{
|
||||
//errorMessageParam.Value
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
cmd.Connection.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception) { /*APILogger.Log("failed to delete test objects, ", ex);*/ }
|
||||
}
|
||||
|
||||
public void Commit()
|
||||
{
|
||||
using (var cmd = DbOperations.GetSQLCommand(true))
|
||||
{
|
||||
try
|
||||
{
|
||||
cmd.CommandType = CommandType.StoredProcedure;
|
||||
cmd.CommandText = DbOperationsEnum.StoredProcedure.sp_MMETestObjectsUpdateInsert.ToString();
|
||||
|
||||
#region params
|
||||
|
||||
cmd.Parameters.Add(
|
||||
new SqlParameter("@s_GUID", SqlDbType.UniqueIdentifier) { Value = Guid.Parse(S_GUID) });
|
||||
cmd.Parameters.Add(new SqlParameter("@TEST_OBJECT", SqlDbType.NVarChar, 50) { Value = Test_Object });
|
||||
cmd.Parameters.Add(new SqlParameter("@TEXT_L1", SqlDbType.NVarChar, 50) { Value = Text_L1 });
|
||||
cmd.Parameters.Add(new SqlParameter("@TEXT_L2", SqlDbType.NVarChar, 50) { Value = Text_L2 });
|
||||
cmd.Parameters.Add(new SqlParameter("@VERSION", SqlDbType.Int) { Value = Version });
|
||||
cmd.Parameters.Add(new SqlParameter("@DATE", SqlDbType.DateTime) { Value = Date });
|
||||
cmd.Parameters.Add(new SqlParameter("@REMARKS", SqlDbType.NVarChar, 50) { Value = Remarks });
|
||||
cmd.Parameters.Add(new SqlParameter("@EXPIRED", SqlDbType.Bit) { Value = Expired });
|
||||
cmd.Parameters.Add(new SqlParameter("@SORTKEY", SqlDbType.NVarChar, 50) { Value = SortKey });
|
||||
cmd.Parameters.Add(new SqlParameter("@LAST_CHANGE", SqlDbType.DateTime) { Value = Last_Change });
|
||||
cmd.Parameters.Add(
|
||||
new SqlParameter("@LAST_CHANGE_TEXT", SqlDbType.NVarChar, 50) { Value = Last_Change_Text });
|
||||
cmd.Parameters.Add(new SqlParameter("@HISTORY", SqlDbType.NVarChar, 50) { Value = History });
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
public static MMETestObjects[] GetTestObjects()
|
||||
{
|
||||
var testObjects = new List<MMETestObjects>();
|
||||
|
||||
try
|
||||
{
|
||||
using (var cmd = DbOperations.GetSQLCommand(true))
|
||||
{
|
||||
try
|
||||
{
|
||||
cmd.CommandType = CommandType.StoredProcedure;
|
||||
cmd.CommandText = DbOperationsEnum.StoredProcedure.sp_MMETestObjectsGet.ToString();
|
||||
cmd.Parameters.Add(new SqlParameter("@s_GUID", SqlDbType.NVarChar) { Value = null });
|
||||
using (var ds = DbOperations.Connection.QueryDataSet(cmd))
|
||||
{
|
||||
if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
|
||||
{
|
||||
try
|
||||
{
|
||||
testObjects.AddRange(from DataRow dr in ds.Tables[0].Rows
|
||||
let date = Convert.ToDateTime(
|
||||
dr[DbOperations.MMETables.MMETestObjectsFields.DATE.ToString()])
|
||||
let expired = Convert.ToBoolean(
|
||||
dr[DbOperations.MMETables.MMETestObjectsFields.EXPIRED.ToString()])
|
||||
let history = Convert.ToString(
|
||||
dr[DbOperations.MMETables.MMETestObjectsFields.HISTORY.ToString()])
|
||||
let lastChange = Convert.ToDateTime(dr[
|
||||
DbOperations.MMETables.MMETestObjectsFields.LAST_CHANGE.ToString()])
|
||||
let lastChangeText = Convert.ToString(dr[
|
||||
DbOperations.MMETables.MMETestObjectsFields.LAST_CHANGE_TEXT.ToString()])
|
||||
let remarks = Convert.ToString(
|
||||
dr[DbOperations.MMETables.MMETestObjectsFields.REMARKS.ToString()])
|
||||
let sGuid = Convert.ToString(
|
||||
dr[DbOperations.MMETables.MMETestObjectsFields.s_GUID.ToString()])
|
||||
let sortKey = Convert.ToString(
|
||||
dr[DbOperations.MMETables.MMETestObjectsFields.SORTKEY.ToString()])
|
||||
let textObject = Convert.ToString(dr[
|
||||
DbOperations.MMETables.MMETestObjectsFields.TEST_OBJECT.ToString()])
|
||||
let text1 = Convert.ToString(
|
||||
dr[DbOperations.MMETables.MMETestObjectsFields.TEXT_L1.ToString()])
|
||||
let text2 = Convert.ToString(
|
||||
dr[DbOperations.MMETables.MMETestObjectsFields.TEXT_L2.ToString()])
|
||||
let version = Convert.ToInt32(
|
||||
dr[DbOperations.MMETables.MMETestObjectsFields.VERSION.ToString()])
|
||||
select new MMETestObjects(sGuid, textObject, text1, text2,
|
||||
Convert.ToInt64(version), date, remarks, expired, sortKey, lastChange,
|
||||
lastChangeText, history, MMEPossibleChannels.MMEChannelTypes.ISO13499_106));
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
//APILogger.Log("Failed to process test objects: ", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
cmd.Connection.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception) { /*APILogger.Log("failed to retrieve test objects, ", ex);*/ }
|
||||
|
||||
try
|
||||
{
|
||||
using (var cmd = DbOperations.GetSQLCommand(true))
|
||||
{
|
||||
try
|
||||
{
|
||||
cmd.CommandType = CommandType.StoredProcedure;
|
||||
cmd.CommandText = DbOperationsEnum.StoredProcedure.sp_MMETestObjectsGetCustom.ToString();
|
||||
cmd.Parameters.Add(new SqlParameter("@s_GUID", SqlDbType.NVarChar) { Value = null });
|
||||
using (var ds = DbOperations.Connection.QueryDataSet(cmd))
|
||||
{
|
||||
if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
|
||||
{
|
||||
try
|
||||
{
|
||||
testObjects.AddRange(from DataRow dr in ds.Tables[0].Rows
|
||||
let date = Convert.ToDateTime(
|
||||
dr[DbOperations.MMETables.MMETestObjectsFields.DATE.ToString()])
|
||||
let expired = Convert.ToBoolean(
|
||||
dr[DbOperations.MMETables.MMETestObjectsFields.EXPIRED.ToString()])
|
||||
let history = Convert.ToString(
|
||||
dr[DbOperations.MMETables.MMETestObjectsFields.HISTORY.ToString()])
|
||||
let lastChange = Convert.ToDateTime(dr[
|
||||
DbOperations.MMETables.MMETestObjectsFields.LAST_CHANGE.ToString()])
|
||||
let lastChangeText = Convert.ToString(dr[
|
||||
DbOperations.MMETables.MMETestObjectsFields.LAST_CHANGE_TEXT.ToString()])
|
||||
let remarks = Convert.ToString(
|
||||
dr[DbOperations.MMETables.MMETestObjectsFields.REMARKS.ToString()])
|
||||
let sGuid = Convert.ToString(
|
||||
dr[DbOperations.MMETables.MMETestObjectsFields.s_GUID.ToString()])
|
||||
let sortKey = Convert.ToString(
|
||||
dr[DbOperations.MMETables.MMETestObjectsFields.SORTKEY.ToString()])
|
||||
let textObject = Convert.ToString(dr[
|
||||
DbOperations.MMETables.MMETestObjectsFields.TEST_OBJECT.ToString()])
|
||||
let text1 = Convert.ToString(
|
||||
dr[DbOperations.MMETables.MMETestObjectsFields.TEXT_L1.ToString()])
|
||||
let text2 = Convert.ToString(
|
||||
dr[DbOperations.MMETables.MMETestObjectsFields.TEXT_L2.ToString()])
|
||||
let version = Convert.ToInt32(
|
||||
dr[DbOperations.MMETables.MMETestObjectsFields.VERSION.ToString()])
|
||||
select new MMETestObjects(sGuid, textObject, text1, text2,
|
||||
Convert.ToInt64(version), date, remarks, expired, sortKey, lastChange,
|
||||
lastChangeText, history, MMEPossibleChannels.MMEChannelTypes.SQL));
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
//APILogger.Log("Failed to process custom test objects: ", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
cmd.Connection.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception) { /*APILogger.Log("failed to retrieve custom test objects, ", ex); */}
|
||||
|
||||
return testObjects.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,231 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Data.SqlClient;
|
||||
|
||||
namespace DatabaseImport
|
||||
{
|
||||
public class MMETransducerMainLocation //: AbstractOLEDbWrapper
|
||||
{
|
||||
public string S_GUID { get; }
|
||||
|
||||
public string Type { get; }
|
||||
|
||||
public string Trans_Main_Loc { get; }
|
||||
|
||||
public string Text_L1 { get; }
|
||||
|
||||
public string Text_L2 { get; }
|
||||
|
||||
public long Version { get; }
|
||||
|
||||
public DateTime Date { get; }
|
||||
|
||||
public string Remarks { get; }
|
||||
|
||||
public bool Expired { get; }
|
||||
|
||||
public string SortKey { get; }
|
||||
|
||||
public string Picture_ShortName { get; }
|
||||
|
||||
public DateTime Last_Change { get; }
|
||||
|
||||
public string Last_Change_Text { get; }
|
||||
|
||||
public string History { get; }
|
||||
|
||||
public MMEPossibleChannels.MMEChannelTypes RecordType { get; }
|
||||
public MMETransducerMainLocation(string sGuid, string type, string transMainLoc, string textL1, string textL2,
|
||||
long version, DateTime date, string remarks, bool expired, string sortkey, string pictureShortName,
|
||||
DateTime lastChange, string lastChangeText, string history, MMEPossibleChannels.MMEChannelTypes recordType)
|
||||
{
|
||||
RecordType = recordType;
|
||||
S_GUID = sGuid;
|
||||
Type = type;
|
||||
Trans_Main_Loc = transMainLoc;
|
||||
Text_L1 = textL1;
|
||||
Text_L2 = textL2;
|
||||
Version = version;
|
||||
Date = date;
|
||||
Remarks = remarks;
|
||||
Expired = expired;
|
||||
SortKey = sortkey;
|
||||
Picture_ShortName = pictureShortName;
|
||||
Last_Change = lastChange;
|
||||
Last_Change_Text = lastChangeText;
|
||||
History = history;
|
||||
}
|
||||
public static void DeleteTransducerMainLocations()
|
||||
{
|
||||
try
|
||||
{
|
||||
using (var cmd = DbOperations.GetSQLCommand(true))
|
||||
{
|
||||
try
|
||||
{
|
||||
cmd.CommandType = CommandType.StoredProcedure;
|
||||
cmd.CommandText = DbOperationsEnum.StoredProcedure.sp_MMEMainLocationsDelete.ToString();
|
||||
cmd.Parameters.Add(new SqlParameter("@s_GUID", SqlDbType.UniqueIdentifier) { 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);
|
||||
|
||||
cmd.ExecuteNonQuery();
|
||||
if (int.Parse(errorNumberParam.Value.ToString()) != 0)
|
||||
{
|
||||
//errorMessageParam.Value
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
cmd.Connection.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception) { /*APILogger.Log("failed to delete main locations, ", ex); */}
|
||||
}
|
||||
public static MMETransducerMainLocation[] GetTransducerMainLocations()
|
||||
{
|
||||
var transducerMainLocations = new List<MMETransducerMainLocation>();
|
||||
try
|
||||
{
|
||||
using (var cmd = DbOperations.GetSQLCommand(true))
|
||||
{
|
||||
try
|
||||
{
|
||||
cmd.CommandType = CommandType.StoredProcedure;
|
||||
cmd.CommandText = DbOperationsEnum.StoredProcedure.sp_MMEMainLocationsGet.ToString();
|
||||
cmd.Parameters.Add(new SqlParameter("@s_GUID", SqlDbType.NVarChar) { Value = null });
|
||||
using (var ds = DbOperations.Connection.QueryDataSet(cmd))
|
||||
{
|
||||
if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
|
||||
{
|
||||
try
|
||||
{
|
||||
transducerMainLocations.AddRange(from DataRow dr in ds.Tables[0].Rows
|
||||
let date = Convert.ToDateTime(
|
||||
dr[DbOperations.MMETables.MMEMainLocationsFields.DATE.ToString()])
|
||||
let expired = Convert.ToBoolean(
|
||||
dr[DbOperations.MMETables.MMEMainLocationsFields.EXPIRED.ToString()])
|
||||
let history = Convert.ToString(
|
||||
dr[DbOperations.MMETables.MMEMainLocationsFields.HISTORY.ToString()])
|
||||
let lastChange = Convert.ToDateTime(dr[
|
||||
DbOperations.MMETables.MMEMainLocationsFields.LAST_CHANGE.ToString()])
|
||||
let lastChangeText = Convert.ToString(dr[
|
||||
DbOperations.MMETables.MMEMainLocationsFields.LAST_CHANGE_TEXT.ToString()])
|
||||
let pictureShortName = Convert.ToString(dr[
|
||||
DbOperations.MMETables.MMEMainLocationsFields.PICTURE_SHORTNAME.ToString()])
|
||||
let remarks = Convert.ToString(
|
||||
dr[DbOperations.MMETables.MMEMainLocationsFields.REMARKS.ToString()])
|
||||
let guid = Convert.ToString(
|
||||
dr[DbOperations.MMETables.MMEMainLocationsFields.s_GUID.ToString()])
|
||||
let sortkey = Convert.ToString(
|
||||
dr[DbOperations.MMETables.MMEMainLocationsFields.SORTKEY.ToString()])
|
||||
let text1 = Convert.ToString(
|
||||
dr[DbOperations.MMETables.MMEMainLocationsFields.TEXT_L1.ToString()])
|
||||
let text2 = Convert.ToString(
|
||||
dr[DbOperations.MMETables.MMEMainLocationsFields.TEXT_L2.ToString()])
|
||||
let mainLoc = Convert.ToString(dr[
|
||||
DbOperations.MMETables.MMEMainLocationsFields.TRANS_MAIN_LOC.ToString()])
|
||||
let type = Convert.ToString(
|
||||
dr[DbOperations.MMETables.MMEMainLocationsFields.TYPE.ToString()])
|
||||
let version = Convert.ToInt32(
|
||||
dr[DbOperations.MMETables.MMEMainLocationsFields.VERSION.ToString()])
|
||||
select new MMETransducerMainLocation(guid, type, mainLoc, text1, text2,
|
||||
Convert.ToInt64(version), date, remarks, expired, sortkey, pictureShortName,
|
||||
lastChange, lastChangeText, history,
|
||||
MMEPossibleChannels.MMEChannelTypes.ISO13499_106));
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
//APILogger.Log("Failed to process main locations: ", ex);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
cmd.Connection.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception) { /*APILogger.Log("failed to retrieve main locations, ", ex);*/ }
|
||||
|
||||
try
|
||||
{
|
||||
using (var cmd = DbOperations.GetSQLCommand(true))
|
||||
{
|
||||
try
|
||||
{
|
||||
cmd.CommandType = CommandType.StoredProcedure;
|
||||
cmd.CommandText = DbOperationsEnum.StoredProcedure.sp_MMEMainLocationsGetCustom.ToString();
|
||||
cmd.Parameters.Add(new SqlParameter("@s_GUID", SqlDbType.NVarChar) { Value = null });
|
||||
using (var ds = DbOperations.Connection.QueryDataSet(cmd))
|
||||
{
|
||||
if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
|
||||
{
|
||||
try
|
||||
{
|
||||
transducerMainLocations.AddRange(from DataRow dr in ds.Tables[0].Rows
|
||||
let date = Convert.ToDateTime(
|
||||
dr[DbOperations.MMETables.MMEMainLocationsFields.DATE.ToString()])
|
||||
let expired = Convert.ToBoolean(
|
||||
dr[DbOperations.MMETables.MMEMainLocationsFields.EXPIRED.ToString()])
|
||||
let history = Convert.ToString(
|
||||
dr[DbOperations.MMETables.MMEMainLocationsFields.HISTORY.ToString()])
|
||||
let lastChange = Convert.ToDateTime(dr[
|
||||
DbOperations.MMETables.MMEMainLocationsFields.LAST_CHANGE.ToString()])
|
||||
let lastChangeText = Convert.ToString(dr[
|
||||
DbOperations.MMETables.MMEMainLocationsFields.LAST_CHANGE_TEXT.ToString()])
|
||||
let pictureShortName = Convert.ToString(dr[
|
||||
DbOperations.MMETables.MMEMainLocationsFields.PICTURE_SHORTNAME.ToString()])
|
||||
let remarks = Convert.ToString(
|
||||
dr[DbOperations.MMETables.MMEMainLocationsFields.REMARKS.ToString()])
|
||||
let guid = Convert.ToString(
|
||||
dr[DbOperations.MMETables.MMEMainLocationsFields.s_GUID.ToString()])
|
||||
let sortkey = Convert.ToString(
|
||||
dr[DbOperations.MMETables.MMEMainLocationsFields.SORTKEY.ToString()])
|
||||
let text1 = Convert.ToString(
|
||||
dr[DbOperations.MMETables.MMEMainLocationsFields.TEXT_L1.ToString()])
|
||||
let text2 = Convert.ToString(
|
||||
dr[DbOperations.MMETables.MMEMainLocationsFields.TEXT_L2.ToString()])
|
||||
let mainLoc = Convert.ToString(dr[
|
||||
DbOperations.MMETables.MMEMainLocationsFields.TRANS_MAIN_LOC.ToString()])
|
||||
let type = Convert.ToString(
|
||||
dr[DbOperations.MMETables.MMEMainLocationsFields.TYPE.ToString()])
|
||||
let version = Convert.ToInt32(
|
||||
dr[DbOperations.MMETables.MMEMainLocationsFields.VERSION.ToString()])
|
||||
select new MMETransducerMainLocation(guid, type, mainLoc, text1, text2,
|
||||
Convert.ToInt64(version), date, remarks, expired, sortkey, pictureShortName,
|
||||
lastChange, lastChangeText, history,
|
||||
MMEPossibleChannels.MMEChannelTypes.SQL));
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
//APILogger.Log("Failed to process custom main locations: ", ex);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
cmd.Connection.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception) { /*APILogger.Log("failed to retrieve custom main locations, ", ex); */}
|
||||
|
||||
return transducerMainLocations.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,129 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Data.SqlClient;
|
||||
|
||||
namespace DatabaseImport
|
||||
{
|
||||
public class TemplateRegion
|
||||
{
|
||||
public string TemplateName { get; }
|
||||
|
||||
public string TemplateZone { get; }
|
||||
|
||||
public int RegionNumber { get; set; }
|
||||
|
||||
public string RegionName { get; set; }
|
||||
|
||||
public string RegionDescription { get; set; }
|
||||
|
||||
public string TestObject { get; set; }
|
||||
|
||||
public string Position { get; set; }
|
||||
|
||||
public string MainLocation { get; set; }
|
||||
|
||||
public string FineLocation1 { get; set; }
|
||||
|
||||
public string FineLocation2 { get; set; }
|
||||
|
||||
public string FineLocation3 { get; set; }
|
||||
|
||||
public string PhysicalDimension { get; set; }
|
||||
|
||||
public string Direction { get; set; }
|
||||
|
||||
public string FilterClass { get; set; }
|
||||
|
||||
public bool LocalOnly { get; } = false;
|
||||
|
||||
private int _upperLeftX = 0;
|
||||
private int _upperLeftY = 0;
|
||||
private int _lowerRightX = 0;
|
||||
private int _lowerRightY = 0;
|
||||
|
||||
public System.Drawing.Point UpperLeft
|
||||
{
|
||||
get => new System.Drawing.Point(_upperLeftX, _upperLeftY);
|
||||
set { _upperLeftX = value.X; _upperLeftY = value.Y; }
|
||||
}
|
||||
|
||||
public System.Drawing.Point LowerRight
|
||||
{
|
||||
get => new System.Drawing.Point(_lowerRightX, _lowerRightY);
|
||||
set { _lowerRightX = value.X; _lowerRightY = value.Y; }
|
||||
}
|
||||
|
||||
public TemplateRegion(string templateName, string zoneName, bool bLocalOnly)
|
||||
{
|
||||
TemplateName = templateName;
|
||||
TemplateZone = zoneName;
|
||||
LocalOnly = bLocalOnly;
|
||||
}
|
||||
|
||||
public TemplateRegion(DataRow dr)
|
||||
{
|
||||
TemplateName = (string)dr["TemplateName"];
|
||||
RegionNumber = Convert.ToInt32(dr["RegionNumber"]);
|
||||
RegionName = (string)dr["RegionName"];
|
||||
RegionDescription = (string)dr["RegionDescription"];
|
||||
TestObject = (string)dr["TestObject"];
|
||||
Position = (string)dr["Position"];
|
||||
MainLocation = (string)dr["MainLocation"];
|
||||
FineLocation1 = (string)dr["FineLocation1"];
|
||||
FineLocation2 = (string)dr["FineLocation2"];
|
||||
FineLocation3 = (string)dr["FineLocation3"];
|
||||
PhysicalDimension = (string)dr["PhysicalDimension"];
|
||||
Direction = (string)dr["Direction"];
|
||||
FilterClass = (string)dr["FilterClass"];
|
||||
LocalOnly = Convert.ToBoolean(dr["LocalOnly"]);
|
||||
_upperLeftX = Convert.ToInt32(dr["UpperLeftX"]);
|
||||
_upperLeftY = Convert.ToInt32(dr["UpperLeftY"]);
|
||||
_lowerRightX = Convert.ToInt32(dr["LowerRightX"]);
|
||||
_lowerRightY = Convert.ToInt32(dr["LowerRightY"]);
|
||||
TemplateZone = (string)dr["ZoneName"];
|
||||
}
|
||||
|
||||
internal static TemplateRegion[] GetAllRegions(string templateName, string zoneName)
|
||||
{
|
||||
var regions = new List<TemplateRegion>();
|
||||
try
|
||||
{
|
||||
using (var cmd = DbOperations.GetSQLCommand(true))
|
||||
{
|
||||
try
|
||||
{
|
||||
cmd.CommandType = CommandType.StoredProcedure;
|
||||
cmd.CommandText = DbOperationsEnum.StoredProcedure.sp_TemplateRegionsGet.ToString();
|
||||
cmd.Parameters.Add(
|
||||
new SqlParameter("@TemplateName", SqlDbType.NVarChar, 255) { Value = templateName });
|
||||
cmd.Parameters.Add(new SqlParameter("@ZoneName", SqlDbType.NVarChar, 50) { Value = zoneName });
|
||||
using (var ds = DbOperations.Connection.QueryDataSet(cmd))
|
||||
{
|
||||
if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
|
||||
{
|
||||
foreach (DataRow dr in ds.Tables[0].Rows)
|
||||
{
|
||||
try
|
||||
{
|
||||
regions.Add(new TemplateRegion(dr));
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
//APILogger.Log("Failed to retrieve a region", templateName, ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
cmd.Connection.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception) {/* APILogger.Log("Failed to retrieve regions", templateName, ex);*/ }
|
||||
return regions.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
|
||||
namespace DatabaseImport
|
||||
{
|
||||
public class TemplateZone
|
||||
{
|
||||
public string TemplateName { get; }
|
||||
|
||||
public string ZoneName { get; } = "";
|
||||
|
||||
public string Picture { get; set; }
|
||||
|
||||
public string Description { get; } = "";
|
||||
|
||||
public TemplateZone(string template, string name, string picture, string description)
|
||||
{
|
||||
ZoneName = name;
|
||||
TemplateName = template;
|
||||
Picture = picture;
|
||||
Description = description;
|
||||
}
|
||||
|
||||
public TemplateZone(DataRow dr)
|
||||
{
|
||||
TemplateName = (string)dr["TemplateName"];
|
||||
if (DBNull.Value == dr["ZoneName"]) { ZoneName = "Default zone"; }
|
||||
else { ZoneName = (string)dr["ZoneName"]; }
|
||||
if (DBNull.Value == dr["ZoneDescription"]) { Description = ""; }
|
||||
else { Description = (string)dr["ZoneDescription"]; }
|
||||
Picture = (string)dr["Picture"];
|
||||
TemplateRegions = TemplateRegion.GetAllRegions(TemplateName, ZoneName);
|
||||
}
|
||||
private readonly List<TemplateRegion> _regions = new List<TemplateRegion>();
|
||||
public TemplateRegion[] TemplateRegions
|
||||
{
|
||||
get => _regions.ToArray();
|
||||
set { _regions.Clear(); _regions.AddRange(value); }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,152 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Data.SqlClient;
|
||||
using DTS.Common.Interface.TestMetaData;
|
||||
|
||||
namespace DatabaseImport.ISO
|
||||
{
|
||||
[Serializable()]
|
||||
public class TestEngineerDetails //: ISerializableFile
|
||||
{
|
||||
private string _testEngineerName = "NOVALUE";
|
||||
public string TestEngineerName
|
||||
{
|
||||
get => _testEngineerName;
|
||||
set
|
||||
{
|
||||
if (value != string.Empty)
|
||||
{
|
||||
_testEngineerName = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private string _testEngineerPhone = "NOVALUE";
|
||||
public string TestEngineerPhone
|
||||
{
|
||||
get => _testEngineerPhone;
|
||||
set
|
||||
{
|
||||
if (value != string.Empty)
|
||||
{
|
||||
_testEngineerPhone = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private string _testEngineerFax = "NOVALUE";
|
||||
public string TestEngineerFax
|
||||
{
|
||||
get => _testEngineerFax;
|
||||
set
|
||||
{
|
||||
if (value != string.Empty)
|
||||
{
|
||||
_testEngineerFax = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private string _testEngineerEmail = "NOVALUE";
|
||||
public string TestEngineerEmail
|
||||
{
|
||||
get => _testEngineerEmail;
|
||||
set
|
||||
{
|
||||
if (value != string.Empty)
|
||||
{
|
||||
_testEngineerEmail = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool LocalOnly { get; set; } = false;
|
||||
|
||||
public string Name { get; set; } = "";
|
||||
|
||||
public DateTime LastModified { get; set; }
|
||||
|
||||
public string LastModifiedBy { get; set; }
|
||||
public int Version { get; set; } = 1;
|
||||
|
||||
public TestEngineerDetails()
|
||||
{
|
||||
}
|
||||
|
||||
public TestEngineerDetails(DataRow dr)
|
||||
{
|
||||
Name = (string)dr["Name"];
|
||||
TestEngineerName = (string)dr["TestEngineerName"];
|
||||
TestEngineerPhone = (string)dr["TestEngineerPhone"];
|
||||
TestEngineerFax = (string)dr["TestEngineerFax"];
|
||||
TestEngineerEmail = (string)dr["TestEngineerEmail"];
|
||||
LocalOnly = Convert.ToBoolean(dr["LocalOnly"]);
|
||||
LastModified = Convert.ToDateTime(dr["LastModified"]);
|
||||
LastModifiedBy = (string)dr["LastModifiedBy"];
|
||||
Version = Convert.ToInt32(dr["Version"]);
|
||||
}
|
||||
public TestEngineerDetails(TestEngineerDetails copy)
|
||||
{
|
||||
Name = copy.Name;
|
||||
TestEngineerName = copy.TestEngineerName;
|
||||
TestEngineerPhone = copy.TestEngineerPhone;
|
||||
TestEngineerFax = copy.TestEngineerFax;
|
||||
TestEngineerEmail = copy.TestEngineerEmail;
|
||||
LocalOnly = copy.LocalOnly;
|
||||
LastModified = copy.LastModified;
|
||||
LastModifiedBy = copy.LastModifiedBy;
|
||||
Version = copy.Version;
|
||||
}
|
||||
public TestEngineerDetails(ITestEngineerDetailsDbRecord testEngineerDetailsDbRecord)
|
||||
{
|
||||
Name = testEngineerDetailsDbRecord.Name;
|
||||
TestEngineerName = testEngineerDetailsDbRecord.TestEngineerName;
|
||||
TestEngineerPhone = testEngineerDetailsDbRecord.TestEngineerPhone;
|
||||
TestEngineerFax = testEngineerDetailsDbRecord.TestEngineerFax;
|
||||
TestEngineerEmail = testEngineerDetailsDbRecord.TestEngineerEmail;
|
||||
LocalOnly = testEngineerDetailsDbRecord.LocalOnly;
|
||||
LastModified = testEngineerDetailsDbRecord.LastModified;
|
||||
LastModifiedBy = testEngineerDetailsDbRecord.LastModifiedBy;
|
||||
Version = testEngineerDetailsDbRecord.Version;
|
||||
}
|
||||
public static void DeleteAllTestEngineerDetails()
|
||||
{
|
||||
try
|
||||
{
|
||||
var errorNumber = DTS.Common.Storage.DbOperations.TestEngineerDetailsDelete(null, out string errorMessage);
|
||||
|
||||
if (errorNumber != 0)
|
||||
{
|
||||
//APILogger.Log("Failed to delete test engineer details", errorMessage);
|
||||
}
|
||||
}
|
||||
catch (Exception) { /*APILogger.Log("Failed to delete test engineer details", ex);*/ }
|
||||
}
|
||||
public static TestEngineerDetails[] GetAllTestEngineerDetails()
|
||||
{
|
||||
var list = new List<TestEngineerDetails>();
|
||||
try
|
||||
{
|
||||
var errorNumber = DTS.Common.Storage.DbOperations.TestEngineerDetailsGet(null, out ITestEngineerDetailsDbRecord[] testEngineerDetailsDbRecords);
|
||||
|
||||
if (errorNumber == 0)
|
||||
{
|
||||
foreach (var testEngineerDetailsDbRecord in testEngineerDetailsDbRecords)
|
||||
{
|
||||
try
|
||||
{
|
||||
list.Add(new TestEngineerDetails(testEngineerDetailsDbRecord));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
//APILogger.Log("failed to get test engineer details", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception) { /*APILogger.Log("Failed to retrieve test engineer details", ex);*/ }
|
||||
return list.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,544 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Data.SqlClient;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace DatabaseImport.ISO
|
||||
{
|
||||
public class TestObject : IComparable
|
||||
{
|
||||
private List<TestObjectChannel> _allChannels = new List<TestObjectChannel>();
|
||||
public TestObjectChannel[] AllChannels
|
||||
{
|
||||
get => _allChannels.ToArray();
|
||||
set
|
||||
{
|
||||
_allChannels = new List<TestObjectChannel>(value);
|
||||
SortChannels();
|
||||
}
|
||||
}
|
||||
|
||||
public void SortChannels()
|
||||
{
|
||||
_allChannels.Sort();
|
||||
}
|
||||
|
||||
public TestObjectChannel GetChannel(string channelid)
|
||||
{
|
||||
return Array.Find(AllChannels, ch => ch.GetId() == channelid || ch.Name == channelid);
|
||||
}
|
||||
public string SerialNumberConverted { get; set; }
|
||||
|
||||
public string SerialNumber { get; set; }
|
||||
|
||||
public string SerialNumberOrOriginalSerialNumber => Embedded ? OriginalSerialNumber : SerialNumber;
|
||||
|
||||
public string TestObjectType { get; set; }
|
||||
|
||||
public string ParentObject { get; set; }
|
||||
|
||||
public bool SysBuilt { get; set; }
|
||||
private List<string> _hardwareIds = new List<string>();
|
||||
public string[] HardwareIds
|
||||
{
|
||||
get => _hardwareIds.ToArray();
|
||||
set { _hardwareIds.Clear(); _hardwareIds.AddRange(value); }
|
||||
}
|
||||
|
||||
public string Template { get; set; }
|
||||
|
||||
public void SetTemplateOnly(string value) { Template = value; }
|
||||
public void SetTemplate(string value, ref ISO13499FileDb db)
|
||||
{
|
||||
Template = value;
|
||||
var template = TestObjectTemplate.GetTemplate(ref db, Template);
|
||||
SetTemplate(template);
|
||||
}
|
||||
public void SetTemplate(TestObjectTemplate template)
|
||||
{
|
||||
_allChannels.Clear();
|
||||
if (null == template) return;
|
||||
Template = template.TemplateName;
|
||||
AllChannels = template.Channels.Select(c => new TestObjectChannel(c, this, template)).ToArray();
|
||||
}
|
||||
|
||||
public bool LocalOnly { get; set; }
|
||||
|
||||
public string LastModifiedBy { get; set; }
|
||||
|
||||
public DateTime LastModified { get; set; }
|
||||
private TestObject(DataRow dr, ref ISO13499FileDb db)
|
||||
{
|
||||
OriginalTemplate = "";
|
||||
OriginalSerialNumber = "";
|
||||
SerialNumberConverted = string.Empty;
|
||||
TestObjectData(dr, ref db);
|
||||
}
|
||||
public bool Embedded { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// original serial number of this group (the serial number will be changed once it's embedded in a test setup)
|
||||
/// </summary>
|
||||
public string OriginalSerialNumber { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// the original template for this group (the template is also changed once it's embedded in a test setup)
|
||||
/// </summary>
|
||||
public string OriginalTemplate { get; set; }
|
||||
private void TestObjectData(DataRow dr, ref ISO13499FileDb db)
|
||||
{
|
||||
SerialNumber = (string)dr["TestObjectName"];
|
||||
LocalOnly = Convert.ToBoolean(dr["LocalOnly"]);
|
||||
SetTemplate((string)dr["TemplateName"], ref db);
|
||||
LastModifiedBy = (string)dr["LastModifiedBy"];
|
||||
LastModified = Convert.ToDateTime(dr["LastModified"]);
|
||||
SysBuilt = Convert.ToBoolean(dr["SysBuilt"]);
|
||||
var o = dr["Embedded"];
|
||||
if (!DBNull.Value.Equals(o))
|
||||
{
|
||||
Embedded = Convert.ToBoolean(o);
|
||||
}
|
||||
o = dr["OrigSerialNumber"];
|
||||
if (!DBNull.Value.Equals(o))
|
||||
{
|
||||
OriginalSerialNumber = Convert.ToString(o);
|
||||
}
|
||||
o = dr["OrigTEmplate"];
|
||||
if (!DBNull.Value.Equals(o))
|
||||
{
|
||||
OriginalTemplate = Convert.ToString(o);
|
||||
}
|
||||
try
|
||||
{
|
||||
if (!DBNull.Value.Equals(dr["ParentObject"]))
|
||||
{
|
||||
ParentObject = (string)dr["ParentObject"];
|
||||
}
|
||||
}
|
||||
catch (Exception) {/* APILogger.Log(ex);*/ }
|
||||
try
|
||||
{
|
||||
using (var cmd = DbOperations.GetSQLCommand(true))
|
||||
{
|
||||
try
|
||||
{
|
||||
cmd.CommandType = CommandType.StoredProcedure;
|
||||
cmd.CommandText = DbOperationsEnum.StoredProcedure.sp_TestObjectChannelSettingsGet.ToString();
|
||||
cmd.Parameters.Add(
|
||||
new SqlParameter("@TestObjectName", SqlDbType.NVarChar, 255) { Value = SerialNumber });
|
||||
cmd.Parameters.Add(new SqlParameter("@ChannelId", SqlDbType.NVarChar, 255) { Value = null });
|
||||
cmd.Parameters.Add(new SqlParameter("@Setting", SqlDbType.NVarChar, 255) { Value = null });
|
||||
cmd.Parameters.Add(
|
||||
new SqlParameter("@SensorSerialNumber", SqlDbType.NVarChar, 255) { Value = null });
|
||||
//cmd.ExecuteNonQuery();
|
||||
using (var ds = DbOperations.Connection.QueryDataSet(cmd))
|
||||
{
|
||||
if (ds.Tables[0].Rows.Count <= 0) return;
|
||||
foreach (DataRow row in ds.Tables[0].Rows)
|
||||
{
|
||||
try
|
||||
{
|
||||
var channelId =
|
||||
(string)row[
|
||||
DbOperations.TestObjectChannelSettings.Fields.ChannelId.ToString()];
|
||||
var sensor =
|
||||
(string)row[
|
||||
DbOperations.TestObjectChannelSettings.Fields.SerialNumber.ToString()];
|
||||
var settings =
|
||||
(string)row[DbOperations.TestObjectChannelSettings.Fields.Setting.ToString()];
|
||||
|
||||
if (string.IsNullOrEmpty(channelId) || string.IsNullOrEmpty(sensor) ||
|
||||
string.IsNullOrEmpty(settings)) continue;
|
||||
|
||||
var sensorsettings = GetSettingsFromString(settings, sensor, channelId);
|
||||
foreach (var setting in sensorsettings)
|
||||
{
|
||||
SetSensorSetting(channelId, sensor, setting);
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
//APILogger.Log(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
cmd.Connection.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception) { /*APILogger.Log(ex); */}
|
||||
}
|
||||
public static SensorSetting[] GetSettingsFromString(string s, string sensor, string channelid)
|
||||
{
|
||||
var tokens = s.Split(',');
|
||||
|
||||
return (from token in tokens select token.Split('=') into subtokens let setting = (SensorSettings)Convert.ToInt32(subtokens[0]) select new SensorSetting(setting, subtokens[1], channelid, sensor)).ToArray();
|
||||
}
|
||||
public TestObject()
|
||||
{
|
||||
OriginalTemplate = "";
|
||||
OriginalSerialNumber = "";
|
||||
SerialNumberConverted = string.Empty;
|
||||
_allChannels = new List<TestObjectChannel>();
|
||||
_hardwareIds = new List<string>();
|
||||
LastModified = DateTime.MinValue;
|
||||
LastModifiedBy = "N/A";
|
||||
LocalOnly = false;
|
||||
SerialNumber = "";
|
||||
Template = "";
|
||||
ParentObject = "";
|
||||
}
|
||||
public enum SensorSettings
|
||||
{
|
||||
Range,
|
||||
CFC,
|
||||
Polarity,
|
||||
Position,
|
||||
LimitDuration,
|
||||
Duration,
|
||||
Delay,
|
||||
OutputMode,
|
||||
SQMode,
|
||||
DIMode,
|
||||
DefaultValue,
|
||||
ActiveValue
|
||||
}
|
||||
public class SensorSetting
|
||||
{
|
||||
public string ChannelId { get; set; }
|
||||
public string SerialNumber { get; set; }
|
||||
public SensorSettings Setting { get; set; }
|
||||
public string Value { get; set; }
|
||||
public SensorSetting(SensorSettings setting, string value, string channelId, string serialNumber)
|
||||
{
|
||||
ChannelId = channelId;
|
||||
Value = value;
|
||||
Setting = setting;
|
||||
SerialNumber = serialNumber;
|
||||
}
|
||||
public SensorSetting(SensorSetting copy)
|
||||
{
|
||||
ChannelId = copy.ChannelId;
|
||||
Value = copy.Value;
|
||||
Setting = copy.Setting;
|
||||
SerialNumber = copy.SerialNumber;
|
||||
}
|
||||
}
|
||||
private Dictionary<string, Dictionary<string, Dictionary<SensorSettings, SensorSetting>>> _sensorSettings = new Dictionary<string, Dictionary<string, Dictionary<SensorSettings, SensorSetting>>>();
|
||||
|
||||
public SensorSetting[] GetSensorSettings(string channelId, string serialNumber)
|
||||
{
|
||||
if (!_sensorSettings.ContainsKey(channelId)) return new SensorSetting[0];
|
||||
return _sensorSettings[channelId].ContainsKey(serialNumber) ? _sensorSettings[channelId][serialNumber].Values.ToArray() : new SensorSetting[0];
|
||||
}
|
||||
public void SetSensorSetting(string channelId, string serialNumber, SensorSetting setting)
|
||||
{
|
||||
if (!_sensorSettings.ContainsKey(channelId)) { _sensorSettings[channelId] = new Dictionary<string, Dictionary<SensorSettings, SensorSetting>>(); }
|
||||
if (!_sensorSettings[channelId].ContainsKey(serialNumber)) { _sensorSettings[channelId][serialNumber] = new Dictionary<SensorSettings, SensorSetting>(); }
|
||||
_sensorSettings[channelId][serialNumber][setting.Setting] = setting;
|
||||
}
|
||||
public TestObject(TestObject copy, ref ISO13499FileDb db)
|
||||
{
|
||||
SerialNumberConverted = string.Empty;
|
||||
OriginalSerialNumber = copy.OriginalSerialNumber;
|
||||
OriginalTemplate = copy.OriginalTemplate;
|
||||
Embedded = copy.Embedded;
|
||||
|
||||
_allChannels = new List<TestObjectChannel>();
|
||||
|
||||
var t = TestObjectTemplate.GetTemplate(ref db, Template);
|
||||
|
||||
copy.SortChannels();
|
||||
foreach (var c in copy.AllChannels) { _allChannels.Add(new TestObjectChannel(c, this, t)); }
|
||||
|
||||
for (var i = 0; i < copy.AllChannels.Length && i < _allChannels.Count; i++)
|
||||
{
|
||||
_allChannels[i].ChannelIdx = i;
|
||||
}
|
||||
|
||||
_hardwareIds = new List<string>(copy.HardwareIds);
|
||||
LastModified = copy.LastModified;
|
||||
LastModifiedBy = copy.LastModifiedBy;
|
||||
LocalOnly = copy.LocalOnly;
|
||||
SerialNumber = copy.SerialNumber;
|
||||
Template = copy.Template;
|
||||
ParentObject = copy.ParentObject;
|
||||
SysBuilt = copy.SysBuilt;
|
||||
using (var e = copy._sensorSettings.GetEnumerator())
|
||||
{
|
||||
_sensorSettings =
|
||||
new Dictionary<string, Dictionary<string, Dictionary<SensorSettings, SensorSetting>>>();
|
||||
while (e.MoveNext())
|
||||
{
|
||||
if (!_sensorSettings.ContainsKey(e.Current.Key))
|
||||
{
|
||||
_sensorSettings[e.Current.Key] =
|
||||
new Dictionary<string, Dictionary<SensorSettings, SensorSetting>>();
|
||||
}
|
||||
using (var e2 = copy._sensorSettings[e.Current.Key].GetEnumerator())
|
||||
{
|
||||
while (e2.MoveNext())
|
||||
{
|
||||
if (!_sensorSettings[e.Current.Key].ContainsKey(e2.Current.Key))
|
||||
{
|
||||
_sensorSettings[e.Current.Key][e2.Current.Key] =
|
||||
new Dictionary<SensorSettings, SensorSetting>();
|
||||
}
|
||||
using (var e3 = copy._sensorSettings[e.Current.Key][e2.Current.Key].GetEnumerator())
|
||||
{
|
||||
while (e3.MoveNext())
|
||||
{
|
||||
_sensorSettings[e.Current.Key][e2.Current.Key][e3.Current.Key] =
|
||||
new SensorSetting(e3.Current.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
private const char CHANNEL_SEPARATOR = 'x';
|
||||
private void GetHardwareAndSensors()
|
||||
{
|
||||
using (var cmd = DbOperations.GetSQLCommand(true))
|
||||
{
|
||||
try
|
||||
{
|
||||
cmd.CommandType = CommandType.StoredProcedure;
|
||||
cmd.CommandText = DbOperationsEnum.StoredProcedure.sp_TestObjectHardwareIdsGet.ToString();
|
||||
|
||||
#region params
|
||||
|
||||
cmd.Parameters.Add(
|
||||
new SqlParameter("@TestObjectName", SqlDbType.NVarChar, 255) { Value = SerialNumber });
|
||||
|
||||
#endregion params
|
||||
|
||||
using (var reader = cmd.ExecuteReader())
|
||||
{
|
||||
var ids = new List<string>();
|
||||
while (reader.Read())
|
||||
{
|
||||
var id = (string)reader["HardwareId"];
|
||||
var tokens = id.Split('_');
|
||||
if (tokens.Length == 3)
|
||||
{
|
||||
var sb = new StringBuilder();
|
||||
sb.AppendFormat("{0}_{1}", tokens[0], tokens[1]);
|
||||
var index = tokens[2].IndexOf(CHANNEL_SEPARATOR);
|
||||
if (index >= 0)
|
||||
{
|
||||
sb.Append(tokens[2].Substring(index));
|
||||
}
|
||||
id = sb.ToString();
|
||||
}
|
||||
if (!ids.Contains(id))
|
||||
{
|
||||
ids.Add(id);
|
||||
}
|
||||
}
|
||||
_hardwareIds = ids;
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
cmd.Connection.Dispose();
|
||||
}
|
||||
}
|
||||
var channelLookup = AllChannels.ToDictionary(ch => ch.GetId());
|
||||
var dasIdToSerialNumber = new Dictionary<int, string>();
|
||||
var dasIdToDasType = new Dictionary<int, int>();
|
||||
using (var cmd = DbOperations.GetSQLCommand(true))
|
||||
{
|
||||
try
|
||||
{
|
||||
cmd.CommandType = CommandType.StoredProcedure;
|
||||
cmd.CommandText = DbOperationsEnum.StoredProcedure.sp_DASGet.ToString();
|
||||
|
||||
#region params
|
||||
|
||||
cmd.Parameters.Add(new SqlParameter("@SerialNumber", SqlDbType.NVarChar) { Value = null });
|
||||
cmd.Parameters.Add(new SqlParameter("@position", SqlDbType.NVarChar) { Value = null });
|
||||
|
||||
#endregion params
|
||||
|
||||
using (var readerDAS = cmd.ExecuteReader())
|
||||
{
|
||||
while (readerDAS.Read())
|
||||
{
|
||||
var dasId = Convert.ToInt32(readerDAS["DASId"]);
|
||||
var serialNumber = Convert.ToString(readerDAS["SerialNumber"]);
|
||||
var iType = Convert.ToInt32(readerDAS["Type"]);
|
||||
dasIdToDasType[dasId] = iType;
|
||||
dasIdToSerialNumber[dasId] = serialNumber;
|
||||
}
|
||||
readerDAS.Close();
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
cmd.Connection.Dispose();
|
||||
}
|
||||
}
|
||||
using (var cmd = DbOperations.GetSQLCommand(true))
|
||||
{
|
||||
try
|
||||
{
|
||||
cmd.CommandType = CommandType.StoredProcedure;
|
||||
cmd.CommandText = DbOperationsEnum.StoredProcedure.sp_TestObjectSensorsGet.ToString();
|
||||
|
||||
#region params
|
||||
|
||||
cmd.Parameters.Add(
|
||||
new SqlParameter("@TestObjectName", SqlDbType.NVarChar, 255) { Value = SerialNumber });
|
||||
|
||||
#endregion params
|
||||
|
||||
using (var ds = DbOperations.Connection.QueryDataSet(cmd))
|
||||
{
|
||||
if (null != ds && ds.Tables.Count > 0)
|
||||
{
|
||||
foreach (DataRow dr in ds.Tables[0].Rows)
|
||||
{
|
||||
var id = Convert.ToString(dr[0]);
|
||||
if (!channelLookup.ContainsKey(id))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
var sensorId = "";
|
||||
var channelIdx = -1;
|
||||
if (!DBNull.Value.Equals(dr["ChannelIdx"]))
|
||||
{
|
||||
channelIdx = Convert.ToInt32(dr["ChannelIdx"]);
|
||||
}
|
||||
if (!DBNull.Value.Equals(dr["SensorId"]))
|
||||
{
|
||||
sensorId = Convert.ToString(dr["SensorId"]);
|
||||
}
|
||||
var hardwareId = "";
|
||||
var dasId = Convert.ToInt32(dr["DasId"]);
|
||||
var dasChannelId = Convert.ToInt32(dr["DasChannelId"]);
|
||||
if (dasIdToSerialNumber.ContainsKey(dasId))
|
||||
{
|
||||
hardwareId = $"{dasIdToSerialNumber[dasId]}_{dasIdToDasType[dasId]}x{dasChannelId}";
|
||||
}
|
||||
channelLookup[id].SensorSerialNumber = sensorId;
|
||||
channelLookup[id].HardwareId = hardwareId;
|
||||
channelLookup[id].ChannelIdx = channelIdx;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
cmd.Connection.Dispose();
|
||||
}
|
||||
}
|
||||
SortChannels();
|
||||
}
|
||||
public static void DeleteAllTestObjects()
|
||||
{
|
||||
try
|
||||
{
|
||||
using (var cmd = DbOperations.GetSQLCommand(true))
|
||||
{
|
||||
try
|
||||
{
|
||||
cmd.CommandType = CommandType.StoredProcedure;
|
||||
cmd.CommandText = DbOperationsEnum.StoredProcedure.sp_TestObjectsDelete.ToString();
|
||||
|
||||
#region params
|
||||
|
||||
cmd.Parameters.Add(new SqlParameter("@TestObjectId", SqlDbType.Int) { Value = 0 });
|
||||
cmd.Parameters.Add(new SqlParameter("@TestObjectName", SqlDbType.NVarChar, 50) { Value = null });
|
||||
|
||||
#region Output
|
||||
|
||||
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 Output
|
||||
|
||||
#endregion params
|
||||
|
||||
cmd.ExecuteNonQuery();
|
||||
|
||||
var error = int.Parse(errorNumberParam.Value.ToString());
|
||||
if (error != 0)
|
||||
{
|
||||
var message = int.Parse(errorNumberParam.Value.ToString());
|
||||
var state = int.Parse(errorNumberParam.Value.ToString());
|
||||
//APILogger.Log(
|
||||
// $"Error:{Convert.ToString(error)}, State:{Convert.ToString(state)} Error: {message}");
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
cmd.Connection.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception) { /*APILogger.Log("failed to delete test objects", ex);*/ }
|
||||
}
|
||||
public static TestObject GetTestObject(string serialNumber, ref ISO13499FileDb db, bool sysBuiltValue)
|
||||
{
|
||||
TestObject testObject = null;
|
||||
try
|
||||
{
|
||||
using (var cmd = DbOperations.GetSQLCommand(true))
|
||||
{
|
||||
try
|
||||
{
|
||||
cmd.CommandType = CommandType.StoredProcedure;
|
||||
cmd.CommandText = DbOperationsEnum.StoredProcedure.sp_TestObjectsGet.ToString();
|
||||
cmd.Parameters.Add(
|
||||
new SqlParameter("@TestObjectName", SqlDbType.NVarChar, 255) { Value = serialNumber });
|
||||
cmd.Parameters.Add(new SqlParameter("@TemplateName", SqlDbType.NVarChar, 255) { Value = null });
|
||||
cmd.Parameters.Add(new SqlParameter("@SysBuilt", SqlDbType.Bit) { Value = sysBuiltValue });
|
||||
|
||||
using (var ds = DbOperations.Connection.QueryDataSet(cmd))
|
||||
{
|
||||
if (null != ds && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
|
||||
{
|
||||
testObject = new TestObject(ds.Tables[0].Rows[0], ref db);
|
||||
}
|
||||
}
|
||||
}
|
||||
finally { cmd.Connection.Dispose(); }
|
||||
}
|
||||
}
|
||||
catch (Exception) { /*APILogger.Log("failed to retrieve test objects", ex);*/ }
|
||||
testObject?.GetHardwareAndSensors();
|
||||
return testObject;
|
||||
}
|
||||
private static int CompareTestObject(TestObject left, TestObject right)
|
||||
{
|
||||
if (left == right) { return 0; }
|
||||
if (null == left) { return -1; }
|
||||
return null == right ? 1 : string.Compare(left.SerialNumber, right.SerialNumber, StringComparison.Ordinal);
|
||||
}
|
||||
|
||||
public int CompareTo(object o)
|
||||
{
|
||||
if (o is TestObject testObject)
|
||||
{
|
||||
return CompareTestObject(this, testObject);
|
||||
}
|
||||
throw new ArgumentException($"object {o} is not the same type as this instance (TestObject)");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
using System;
|
||||
using System.Text;
|
||||
|
||||
namespace DatabaseImport
|
||||
{
|
||||
/// <inheritdoc cref="TestObjectTemplateChannel" />
|
||||
/// <summary>
|
||||
/// this class represents a more simpilized version of the group/test object channel
|
||||
/// this is closer tied to what's in the database
|
||||
/// It extends a template channel adds more meta data
|
||||
/// </summary>
|
||||
public class TestObjectChannel : TestObjectTemplateChannel, IComparable<TestObjectChannel>
|
||||
{
|
||||
/// <summary>
|
||||
/// controls whether channel should be used when collecting data or not
|
||||
/// Disabled channels are not used in run test
|
||||
/// </summary>
|
||||
public bool Disabled { get; set; }
|
||||
public int ChannelIdx { get; set; } = CHANNEL_IDX_UNKNOWN;
|
||||
/// <summary>
|
||||
/// the serial number of the sensor associated with this channel (if any)
|
||||
/// </summary>
|
||||
public string SensorSerialNumber
|
||||
{
|
||||
get => GetProperty("SensorSerialNumber", "") as string;
|
||||
set => SetProperty("SensorSerialNumber", value);
|
||||
}
|
||||
/// <summary>
|
||||
/// the physical hardware channel associated with this channel (if any)
|
||||
/// </summary>
|
||||
public string HardwareId
|
||||
{
|
||||
get => GetProperty("HardwareId", "") as string;
|
||||
set
|
||||
{
|
||||
var tokens = value?.Split('_');
|
||||
if (3 == tokens?.Length)
|
||||
{
|
||||
var sb = new StringBuilder();
|
||||
sb.AppendFormat("{0}_{1}", tokens[0], tokens[1]);
|
||||
var index = tokens[2].IndexOf(CHANNEL_SEPARATOR);
|
||||
if (index >= 0) { sb.Append(tokens[2].Substring(index)); }
|
||||
value = sb.ToString();
|
||||
}
|
||||
SetProperty("HardwareId", value);
|
||||
}
|
||||
}
|
||||
public SquibChannelTypes SquibChannelType
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
/// <summary>
|
||||
/// the test object this channel belongs to
|
||||
/// </summary>
|
||||
public ISO.TestObject TestObject { get; }
|
||||
private const char CHANNEL_SEPARATOR = 'x';
|
||||
public const int CHANNEL_IDX_UNKNOWN = -1;
|
||||
public enum SquibChannelTypes
|
||||
{
|
||||
None, //Non-squib channels
|
||||
Voltage,
|
||||
Current
|
||||
}
|
||||
/// <inheritdoc />
|
||||
/// <summary>
|
||||
/// compares one channel to another, used for sorting
|
||||
/// order is determined by 1) display order, 2) name of the channels, 3) test object serial number (or original serial number)
|
||||
/// </summary>
|
||||
/// <param name="right"></param>
|
||||
/// <returns></returns>
|
||||
public int CompareTo(TestObjectChannel right)
|
||||
{
|
||||
if (null == right) { return 1; }
|
||||
if (this == right) { return 0; }
|
||||
var comp = DisplayOrder.CompareTo(right.DisplayOrder);
|
||||
if (0 != comp) { return comp; }
|
||||
|
||||
comp = string.Compare(Name, right.Name, StringComparison.Ordinal);
|
||||
if (0 != comp) { return comp; }
|
||||
|
||||
if (null == TestObject || null == right.TestObject) return 0;
|
||||
comp = string.Compare(TestObject.SerialNumberOrOriginalSerialNumber, right.TestObject.SerialNumberOrOriginalSerialNumber, StringComparison.Ordinal);
|
||||
return 0 != comp ? comp : 0;
|
||||
}
|
||||
|
||||
public string GetGraphId()
|
||||
{
|
||||
return SquibChannelType == SquibChannelTypes.Current ? GetId() + DTS.Common.Constants.CURRENT_SUFFIX : GetId();
|
||||
}
|
||||
public string GetId()
|
||||
{
|
||||
return GetIdWithSpecificChannelId(Channel.Id);
|
||||
}
|
||||
public string GetIdWithSpecificChannelId(long id)
|
||||
{
|
||||
return $"{TestObject.SerialNumber}_{Channel.MMEChannelType}_{id}";
|
||||
}
|
||||
public TestObjectChannel(TestObjectTemplateChannel copy, ISO.TestObject testObject, ISO.TestObjectTemplate template)
|
||||
: base(copy, template)
|
||||
{
|
||||
TestObject = testObject;
|
||||
if (copy is TestObjectChannel channel)
|
||||
{
|
||||
Disabled = channel.Disabled;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,193 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace DatabaseImport
|
||||
{
|
||||
public class TestObjectMetaData
|
||||
{
|
||||
public static double Version { get; set; } = 1.06;
|
||||
public const string NOVALUE = "NOVALUE";
|
||||
|
||||
public void SetProperty(MetaData meta)
|
||||
{
|
||||
_properties[meta.Name] = meta;
|
||||
}
|
||||
public enum CommentFields
|
||||
{
|
||||
Comment1,
|
||||
Comment2,
|
||||
Comment3,
|
||||
}
|
||||
public enum Fields
|
||||
{
|
||||
NameOfTestObject,
|
||||
VelocityOfTestObject,
|
||||
MassOfTestObject,
|
||||
DriverPositionObject,
|
||||
ImpactSideTestObject,
|
||||
TypeOfTestObject,
|
||||
ClassOfTestObject,
|
||||
CodeOfTestObject,
|
||||
RefNumberOfTestObject,
|
||||
TestObjectComments
|
||||
}
|
||||
public enum OptionFields
|
||||
{
|
||||
Offset,
|
||||
BarrierWidth,
|
||||
BarrierHeight,
|
||||
YawAngle,
|
||||
ReferenceSystem,
|
||||
OriginX,
|
||||
OriginY,
|
||||
OriginZ,
|
||||
NumberOfLoadCells
|
||||
}
|
||||
private Dictionary<string, MetaData> _properties = new Dictionary<string, MetaData>();
|
||||
public TestObjectMetaData(char testobject)
|
||||
{
|
||||
TestObject = testobject;
|
||||
var comments = Enum.GetValues(typeof(CommentFields)).Cast<CommentFields>().ToArray();
|
||||
var fields = Enum.GetValues(typeof(Fields)).Cast<Fields>().ToArray();
|
||||
var optional = Enum.GetValues(typeof(OptionFields)).Cast<OptionFields>().ToArray();
|
||||
foreach (var cfield in comments) { _properties.Add(cfield.ToString(), new MetaData(cfield.ToString(), false, NOVALUE, Version)); }
|
||||
foreach (var field in fields)
|
||||
{
|
||||
switch (field)
|
||||
{
|
||||
case Fields.VelocityOfTestObject:
|
||||
case Fields.MassOfTestObject:
|
||||
_properties.Add(field.ToString(), new MetaData(field.ToString(), false, string.Empty, Version));
|
||||
break;
|
||||
default:
|
||||
_properties.Add(field.ToString(), new MetaData(field.ToString(), false, NOVALUE, Version));
|
||||
break;
|
||||
}
|
||||
}
|
||||
foreach (var ofield in optional)
|
||||
{
|
||||
_properties.Add(ofield.ToString(), new MetaData(ofield.ToString(), true, NOVALUE, Version));
|
||||
}
|
||||
}
|
||||
|
||||
public char TestObject { get; } = '?';
|
||||
}
|
||||
public class MetaData
|
||||
{
|
||||
public string Name { get; }
|
||||
|
||||
public bool IsOptional { get; } = false;
|
||||
|
||||
public double Version { get; } = 1.06D;
|
||||
|
||||
public string Value { get; set; } = "NOVALUE";
|
||||
|
||||
public MetaData(string name, bool optional, string value, double version)
|
||||
{
|
||||
Name = name;
|
||||
IsOptional = optional;
|
||||
Value = value;
|
||||
Version = version;
|
||||
}
|
||||
public MetaData(MetaData copy)
|
||||
{
|
||||
Name = copy.Name;
|
||||
IsOptional = copy.IsOptional;
|
||||
Value = copy.Value;
|
||||
Version = copy.Version;
|
||||
}
|
||||
}
|
||||
public class TestSetupMetaData
|
||||
{
|
||||
public double Version { get; set; } = 1.06;
|
||||
public const string NOVALUE = "NOVALUE";
|
||||
public const string MEDIADEFAULT = "1/1";
|
||||
|
||||
public void SetProperty(MetaData meta, bool requireXCrashCompatibilityForISOExports)
|
||||
{
|
||||
switch (meta.Name)
|
||||
{
|
||||
case "LaboratoryName":
|
||||
case "LaboratoryContactName":
|
||||
case "LaboratoryTestReferenceNumber":
|
||||
case "CustomerName":
|
||||
case "CustomerTestReferenceNumber":
|
||||
if ((meta.Value == NOVALUE) && requireXCrashCompatibilityForISOExports)
|
||||
{
|
||||
meta.Value = string.Empty;
|
||||
}
|
||||
break;
|
||||
}
|
||||
_properties[meta.Name] = meta;
|
||||
}
|
||||
public enum Fields
|
||||
{
|
||||
LabName,
|
||||
LaboratoryContactName,
|
||||
LaboratoryContactPhone,
|
||||
LaboratoryContactFax,
|
||||
LaboratoryContactEmail,
|
||||
LaboratoryName,
|
||||
LaboratoryTestReferenceNumber,
|
||||
LaboratoryProjectReferenceNumber,
|
||||
|
||||
CustName,
|
||||
CustomerName,
|
||||
CustomerTestReferenceNumber,
|
||||
CustomerProjectReferenceNumber,
|
||||
CustomerOrderNumber,
|
||||
CustomerCostUnit,
|
||||
|
||||
TEName,
|
||||
TestEngineerName,
|
||||
TestEngineerPhone,
|
||||
TestEngineerFax,
|
||||
TestEngineerEmail,
|
||||
|
||||
Title,
|
||||
MediumNoNumberOfMedia,
|
||||
TestComment,
|
||||
TypeOfTheTest,
|
||||
ReferenceTemperature,
|
||||
RelativeAirHumidity,
|
||||
Regulation,
|
||||
Subtype,
|
||||
DateOfTheTest
|
||||
}
|
||||
|
||||
private Dictionary<string, MetaData> _properties = new Dictionary<string, MetaData>();
|
||||
public TestSetupMetaData(bool requireXCrashCompatibilityForISOExports)
|
||||
{
|
||||
_testObject = '_';
|
||||
var fields = Enum.GetValues(typeof(Fields)).Cast<Fields>().ToArray();
|
||||
foreach (var field in fields)
|
||||
{
|
||||
switch (field)
|
||||
{
|
||||
case Fields.MediumNoNumberOfMedia:
|
||||
_properties.Add(field.ToString(), new MetaData(field.ToString(), false, MEDIADEFAULT, Version));
|
||||
break;
|
||||
case Fields.LaboratoryName:
|
||||
case Fields.LaboratoryContactName:
|
||||
case Fields.LaboratoryTestReferenceNumber:
|
||||
case Fields.CustomerName:
|
||||
case Fields.CustomerTestReferenceNumber:
|
||||
if (requireXCrashCompatibilityForISOExports)
|
||||
{
|
||||
_properties.Add(field.ToString(), new MetaData(field.ToString(), false, string.Empty, Version));
|
||||
}
|
||||
else
|
||||
{
|
||||
_properties.Add(field.ToString(), new MetaData(field.ToString(), false, NOVALUE, Version));
|
||||
}
|
||||
break;
|
||||
default:
|
||||
_properties.Add(field.ToString(), new MetaData(field.ToString(), false, NOVALUE, Version));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
private char _testObject = '_';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,369 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Data.SqlClient;
|
||||
|
||||
namespace DatabaseImport.ISO
|
||||
{
|
||||
/// <summary>
|
||||
/// this class is a wrapper for the group template per the db, it's supposed to be a lighter weight version of concept of a test object template, with no
|
||||
/// connection to UI, just serialization and structure
|
||||
/// </summary>
|
||||
public class TestObjectTemplate
|
||||
{
|
||||
/// <summary>
|
||||
/// name of the test object template, this could be a GUID in the case of embedded test object templates
|
||||
/// </summary>
|
||||
public string TemplateName { get; set; }
|
||||
/// <summary>
|
||||
/// a human readable name for the template, for an embedded template this is the original template name, for
|
||||
/// a non embedded template, this is the template name (embedded templates have guids for names)
|
||||
/// </summary>
|
||||
public string TemplateNameOrOriginalTemplateName => Embedded ? OriginalTemplateName : TemplateName;
|
||||
|
||||
/// <summary>
|
||||
/// the icon for the template
|
||||
/// </summary>
|
||||
public string Icon { get; set; }
|
||||
/// <summary>
|
||||
/// description for the template
|
||||
/// </summary>
|
||||
public string Description { get; set; }
|
||||
/// <summary>
|
||||
/// whether this template is intended to only be used locally or not
|
||||
/// </summary>
|
||||
public bool LocalOnly { get; set; }
|
||||
/// <summary>
|
||||
/// the version number of this template [not currently used?]
|
||||
/// </summary>
|
||||
public int Version { get; set; }
|
||||
/// <summary>
|
||||
/// last person to modify this template
|
||||
/// </summary>
|
||||
public string LastModifiedBy { get; set; }
|
||||
/// <summary>
|
||||
/// when this template was last modified
|
||||
/// </summary>
|
||||
public DateTime LastModified { get; set; }
|
||||
/// <summary>
|
||||
/// a CRC32 for the template, but not currently used
|
||||
/// original idea was to allow us to not have to check changes in the template, just quickly calculate whether anything has changed
|
||||
/// </summary>
|
||||
public int CRC32 { get; set; }
|
||||
/// <summary>
|
||||
/// test object (iso meta field) for this template
|
||||
/// </summary>
|
||||
public string TestObject { get; set; }
|
||||
/// <summary>
|
||||
/// test object type (iso meta field) for this template, all channels are of this type ...
|
||||
/// </summary>
|
||||
public string TestObjectType { get; set; }
|
||||
/// <summary>
|
||||
/// unsure if this is still used, was originally used to build up templates from sub templates,
|
||||
/// so an ATD could be composed of leg, arm, head, etc
|
||||
/// </summary>
|
||||
public string TemplateParent { get; set; }
|
||||
/// <summary>
|
||||
/// unsure, I think this is whether the group is dynamically added or an existing
|
||||
/// </summary>
|
||||
public bool SysBuilt { get; set; }
|
||||
/// <summary>
|
||||
/// zones where regions on a test object, this is currently hidden, but the idea
|
||||
/// was to associate a picture with a zone, and to allow constructing regions or areas in that zone
|
||||
/// </summary>
|
||||
public TemplateZone[] Zones { get; set; }
|
||||
/// <summary>
|
||||
/// all channels for the template
|
||||
/// </summary>
|
||||
public TestObjectTemplateChannel[] Channels { get; set; }
|
||||
/// <summary>
|
||||
/// the original template name [if we are embedded we got a new name that was a guid, but we store the old name here for readability purposes]
|
||||
/// </summary>
|
||||
public string OriginalTemplateName { get; set; }
|
||||
/// <summary>
|
||||
/// whether this group is embedded in a test setup, or is a user created and living on it's own template
|
||||
/// </summary>
|
||||
public bool Embedded { get; set; }
|
||||
public TestObjectTemplate(DataRow row, ref ISO13499FileDb db, ref List<string> errors)
|
||||
{
|
||||
TemplateName = (string)row["TemplateName"];
|
||||
Icon = (string)row["Icon"];
|
||||
Description = (string)row["Description"];
|
||||
LocalOnly = Convert.ToBoolean(row["LocalOnly"]);
|
||||
Version = Convert.ToInt32(row["Version"]);
|
||||
LastModifiedBy = (string)row["LastModifiedBy"];
|
||||
LastModified = Convert.ToDateTime(row["LastModified"]);
|
||||
CRC32 = Convert.ToInt32(row["CRC32"]);
|
||||
TestObject = (string)row["TestObjectName"];
|
||||
TestObjectType = (string)row["TestObjectType"];
|
||||
var oTemplate = row["OrigTemplateName"];
|
||||
OriginalTemplateName = DBNull.Value.Equals(oTemplate) ? string.Empty : Convert.ToString(oTemplate);
|
||||
var oEmbedded = row["Embedded"];
|
||||
if (!DBNull.Value.Equals(oEmbedded))
|
||||
{
|
||||
Embedded = Convert.ToBoolean(oEmbedded);
|
||||
}
|
||||
try
|
||||
{
|
||||
TemplateParent = DBNull.Value.Equals(row["ParentTemplate"]) ? "" : (string)row["ParentTemplate"];
|
||||
}
|
||||
catch (Exception) { TemplateParent = null; }
|
||||
SysBuilt = Convert.ToBoolean(row["SysBuilt"]);
|
||||
|
||||
var channels = new List<TestObjectTemplateChannel>();
|
||||
var possibleChannels = db.GetPossibleChannelsForType(TestObjectType);
|
||||
var channelLookup = new Dictionary<int, Dictionary<long, TestObjectTemplateChannel>>();
|
||||
|
||||
foreach (var pc in possibleChannels)
|
||||
{
|
||||
try
|
||||
{
|
||||
var newCh = new TestObjectTemplateChannel(pc);
|
||||
newCh.SetTemplate(this);
|
||||
channels.Add(newCh);
|
||||
if (!channelLookup.ContainsKey(newCh.Channel.MMEChannelType))
|
||||
{
|
||||
channelLookup.Add(newCh.Channel.MMEChannelType, new Dictionary<long, TestObjectTemplateChannel>());
|
||||
}
|
||||
channelLookup[newCh.Channel.MMEChannelType][newCh.Channel.Id] = newCh;
|
||||
}
|
||||
catch (Exception) { /*APILogger.Log(ex);*/ }
|
||||
}
|
||||
var failedToLoadChannels = 0;
|
||||
try
|
||||
{
|
||||
|
||||
var channelList = LoadExistingChannels(ref db);
|
||||
foreach (var ch in channelList)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!ch.Required) continue;
|
||||
if (null == ch.Channel) { failedToLoadChannels++; continue; }
|
||||
var old = channelLookup[ch.Channel.MMEChannelType][ch.Channel.Id];
|
||||
channelLookup[ch.Channel.MMEChannelType][ch.Channel.Id] = ch;
|
||||
var index = channels.IndexOf(old);
|
||||
channels.RemoveAt(index);
|
||||
channels.Insert(index, ch);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
//APILogger.Log("Failed to retrieve Template channel", ex);
|
||||
if (null != ch) { errors.Add("Failed to load " + ch.Name + " from template " + TemplateName); }
|
||||
else { errors.Add("Failed to load a channel in " + TemplateName); }
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
errors.Add("Failed to load channels for - " + TemplateName);
|
||||
//APILogger.Log("failed to retrieve template channels, ", TemplateName, ex);
|
||||
}
|
||||
Channels = channels.ToArray();
|
||||
if (failedToLoadChannels > 0)
|
||||
{
|
||||
errors.Add($"Failed to load {failedToLoadChannels:N0} channel(s) from template {TemplateNameOrOriginalTemplateName}");
|
||||
}
|
||||
|
||||
var zones = new List<TemplateZone>();
|
||||
try
|
||||
{
|
||||
using (var cmd = DbOperations.GetSQLCommand(true))
|
||||
{
|
||||
try
|
||||
{
|
||||
cmd.CommandType = CommandType.StoredProcedure;
|
||||
cmd.CommandText = DbOperationsEnum.StoredProcedure.sp_TemplateZonesGet.ToString();
|
||||
cmd.Parameters.Add(
|
||||
new SqlParameter("@TemplateName", SqlDbType.NVarChar) { Value = TemplateName });
|
||||
|
||||
using (var ds = DbOperations.Connection.QueryDataSet(cmd))
|
||||
{
|
||||
if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
|
||||
{
|
||||
zones.Add(new TemplateZone(ds.Tables[0].Rows[0]));
|
||||
//zones.AddRange(from DataRow dr in ds.Tables[0].Rows select new TemplateZone(dr));
|
||||
}
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
cmd.Connection.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception) { /*APILogger.Log("failed to retrieve template regions, ", TemplateName, ex); */}
|
||||
Zones = zones.ToArray();
|
||||
}
|
||||
public TestObjectTemplate(string templateName, bool bLocalOnly)
|
||||
{
|
||||
Version = 1;
|
||||
TemplateName = templateName;
|
||||
LocalOnly = bLocalOnly;
|
||||
Zones = new TemplateZone[0];
|
||||
Channels = new TestObjectTemplateChannel[0];
|
||||
}
|
||||
public TestObjectTemplate(TestObjectTemplate copy, ref ISO13499FileDb db)
|
||||
{
|
||||
if (copy?.TemplateName != null)
|
||||
{
|
||||
TemplateName = copy.TemplateName;
|
||||
}
|
||||
if (copy == null) return;
|
||||
LocalOnly = copy.LocalOnly;
|
||||
Zones = copy.Zones;
|
||||
CRC32 = copy.CRC32;
|
||||
Description = copy.Description;
|
||||
Embedded = copy.Embedded;
|
||||
OriginalTemplateName = copy.OriginalTemplateName;
|
||||
Icon = copy.Icon;
|
||||
LastModified = copy.LastModified;
|
||||
LastModifiedBy = copy.LastModifiedBy;
|
||||
LocalOnly = copy.LocalOnly;
|
||||
SysBuilt = copy.SysBuilt;
|
||||
TemplateParent = copy.TemplateParent;
|
||||
TestObject = copy.TestObject;
|
||||
TestObjectType = copy.TestObjectType;
|
||||
Version = copy.Version;
|
||||
var lookup = new Dictionary<string, bool>();
|
||||
var channels = new List<TestObjectTemplateChannel>();
|
||||
foreach (var c in copy.Channels)
|
||||
{
|
||||
var ch = new TestObjectTemplateChannel(c, this);
|
||||
ch.SetTemplate(this);
|
||||
channels.Add(ch);
|
||||
lookup[$"{c.Channel.Id}x{c.Channel.MMEChannelType}"] = true;
|
||||
}
|
||||
var possibleChannels = db.GetPossibleChannelsForType(TestObjectType);
|
||||
foreach (var pc in possibleChannels)
|
||||
{
|
||||
var key = $"{pc.Id}x{pc.MMEChannelType}";
|
||||
if (lookup.ContainsKey(key)) continue;
|
||||
lookup[key] = true;
|
||||
var ch = new TestObjectTemplateChannel(pc);
|
||||
ch.SetTemplate(this);
|
||||
channels.Insert(0, ch);
|
||||
}
|
||||
Channels = channels.ToArray();
|
||||
}
|
||||
private List<TestObjectTemplateChannel> LoadExistingChannels(ref ISO13499FileDb db)
|
||||
{
|
||||
var existingChannels = new List<TestObjectTemplateChannel>();
|
||||
|
||||
using (var cmd = DbOperations.GetSQLCommand(true))
|
||||
{
|
||||
try
|
||||
{
|
||||
cmd.CommandType = CommandType.StoredProcedure;
|
||||
cmd.CommandText = DbOperationsEnum.StoredProcedure.sp_TemplateChannelsGet.ToString();
|
||||
|
||||
#region params
|
||||
|
||||
cmd.Parameters.Add(
|
||||
new SqlParameter("@TemplateName", SqlDbType.NVarChar, 50) { Value = TemplateName });
|
||||
|
||||
#endregion params
|
||||
|
||||
using (var ds = DbOperations.Connection.QueryDataSet(cmd))
|
||||
{
|
||||
if (ds.Tables.Count <= 0 || ds.Tables[0].Rows.Count <= 0) return existingChannels;
|
||||
foreach (DataRow dr in ds.Tables[0].Rows)
|
||||
{
|
||||
existingChannels.Add(new TestObjectTemplateChannel(dr, this, ref db));
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
cmd.Connection.Dispose();
|
||||
}
|
||||
}
|
||||
return existingChannels;
|
||||
}
|
||||
public static TestObjectTemplate GetTemplate(ref ISO13499FileDb db, string name)
|
||||
{
|
||||
|
||||
if (string.IsNullOrEmpty(name)) return null;
|
||||
|
||||
var errors = new List<string>();
|
||||
var templates = new List<TestObjectTemplate>();
|
||||
try
|
||||
{
|
||||
using (var cmd = DbOperations.GetSQLCommand(true))
|
||||
{
|
||||
try
|
||||
{
|
||||
cmd.CommandType = CommandType.StoredProcedure;
|
||||
cmd.CommandText = DbOperationsEnum.StoredProcedure.sp_TestObjectTemplatesGet.ToString();
|
||||
cmd.Parameters.Add(new SqlParameter("@TemplateName", SqlDbType.NVarChar) { Value = name });
|
||||
cmd.Parameters.Add(new SqlParameter("@SysBuilt", SqlDbType.NVarChar) { Value = null });
|
||||
|
||||
//cmd.ExecuteNonQuery();
|
||||
using (var ds = DbOperations.Connection.QueryDataSet(cmd))
|
||||
{
|
||||
if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
|
||||
{
|
||||
//foreach (DataRow row in ds.Tables[0].Rows)
|
||||
if (ds.Tables[0].Rows.Count > 0)
|
||||
{
|
||||
try
|
||||
{
|
||||
templates.Add(new TestObjectTemplate(ds.Tables[0].Rows[0], ref db, ref errors));
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
//APILogger.Log("Failed to retrieve template", ex2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
cmd.Connection.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception) { /*APILogger.Log("failed to get all templates", ex);*/ }
|
||||
|
||||
return templates.Count > 0 ? templates[0] : null;
|
||||
}
|
||||
public static void DeleteAllTemplates(string templateName = null)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
using (var cmd = DbOperations.GetSQLCommand(true))
|
||||
{
|
||||
try
|
||||
{
|
||||
cmd.CommandType = CommandType.StoredProcedure;
|
||||
cmd.CommandText = DbOperationsEnum.StoredProcedure.sp_TestObjectTemplatesDelete.ToString();
|
||||
cmd.Parameters.Add(new SqlParameter("@TemplateName", SqlDbType.NVarChar)
|
||||
{
|
||||
Value = String.IsNullOrEmpty(templateName) ? null : templateName
|
||||
});
|
||||
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);
|
||||
|
||||
cmd.ExecuteNonQuery();
|
||||
}
|
||||
finally
|
||||
{
|
||||
cmd.Connection.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception) { /*APILogger.Log("Failed to delete template:", templateName, ex);*/ throw; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,207 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Data;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace DatabaseImport
|
||||
{
|
||||
public class TestObjectTemplateChannel : INotifyPropertyChanged
|
||||
{
|
||||
#region INotifyPropertyChanged
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
protected bool SetProperty<T>(ref T storage, T value, string propertyName = null)
|
||||
{
|
||||
if (Equals(storage, value)) return false;
|
||||
|
||||
storage = value;
|
||||
OnPropertyChanged(propertyName);
|
||||
return true;
|
||||
}
|
||||
protected void OnPropertyChanged(string propertyName = null)
|
||||
{
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
||||
}
|
||||
#endregion
|
||||
|
||||
public const string NONISOCHANNELTYPE = "NONISO";
|
||||
public const string SEPARATOR = "_X_";
|
||||
public const string TEST_SPECIFIC_DOUT = "TSD_";
|
||||
public enum DataStatusTypes
|
||||
{
|
||||
OK,
|
||||
ChannelFailed,
|
||||
MeaninglessData,
|
||||
NoData,
|
||||
QuestionableData,
|
||||
ScalingFactorApplied,
|
||||
SystemFailed,
|
||||
LinearisedData,
|
||||
NOVALUE
|
||||
}
|
||||
|
||||
public enum StandardChannelProperties
|
||||
{
|
||||
NameOfTheChannel,
|
||||
DisplayOrder
|
||||
}
|
||||
public int DisplayOrder
|
||||
{
|
||||
get => Convert.ToInt32(_channelProperties[StandardChannelProperties.DisplayOrder.ToString()].Value, System.Globalization.CultureInfo.InvariantCulture);
|
||||
set => _channelProperties[StandardChannelProperties.DisplayOrder.ToString()].Value = value.ToString(System.Globalization.CultureInfo.InvariantCulture);
|
||||
}
|
||||
public int TemplateChannelId { get; set; }
|
||||
public string NameOfTheChannel
|
||||
{
|
||||
get
|
||||
{
|
||||
var s = _channelProperties[StandardChannelProperties.NameOfTheChannel.ToString()].Value as string;
|
||||
if (!string.IsNullOrWhiteSpace(s) && s != DataStatusTypes.NOVALUE.ToString()) return s;
|
||||
if (Name.StartsWith(TEST_SPECIFIC_DOUT))
|
||||
{
|
||||
return $"(Digital Output Setting){Name}";
|
||||
}
|
||||
return Name;
|
||||
}
|
||||
set
|
||||
{
|
||||
_channelProperties[StandardChannelProperties.NameOfTheChannel.ToString()].Value = value;
|
||||
OnPropertyChanged("NameOfTheChannel");
|
||||
}
|
||||
}
|
||||
public string Name
|
||||
{
|
||||
get
|
||||
{
|
||||
var tokens = Channel.Text_L1.Split(new[] { SEPARATOR }, StringSplitOptions.None);
|
||||
return tokens.Last();
|
||||
}
|
||||
}
|
||||
public ISO.TestObjectTemplate Template { get; private set; }
|
||||
private readonly List<string> _channelPropertyNames = new List<string>();
|
||||
private Dictionary<string, ChannelProperty> _channelProperties = new Dictionary<string, ChannelProperty>();
|
||||
public MMEPossibleChannels Channel { get; private set; }
|
||||
public bool LocalOnly { get; set; }
|
||||
// #endregion
|
||||
|
||||
// #region methods
|
||||
protected object GetProperty(string name, object defaultValue)
|
||||
{
|
||||
if (!_channelProperties.ContainsKey(name)) { _channelProperties[name] = new ChannelProperty(name, defaultValue); }
|
||||
return _channelProperties[name].Value;
|
||||
}
|
||||
protected void SetProperty(string name, object value)
|
||||
{
|
||||
if (!_channelProperties.ContainsKey(name)) { _channelProperties[name] = new ChannelProperty(name, value); }
|
||||
else { _channelProperties[name].Value = value; }
|
||||
OnPropertyChanged("name"); // ? variable name instead of "name"
|
||||
}
|
||||
private void AddStandardProperties()
|
||||
{
|
||||
if (null != _channelProperties) { _channelProperties.Clear(); _channelProperties = null; }
|
||||
_channelProperties = new Dictionary<string, ChannelProperty>();
|
||||
var scp = Enum.GetValues(typeof(StandardChannelProperties)).Cast<StandardChannelProperties>().ToArray();
|
||||
foreach (var p in scp)
|
||||
{
|
||||
ChannelProperty cp;
|
||||
switch (p)
|
||||
{
|
||||
case StandardChannelProperties.DisplayOrder: cp = new ChannelProperty(p.ToString(), "0"); break;
|
||||
case StandardChannelProperties.NameOfTheChannel: cp = new ChannelProperty("Name of the channel", "NOVALUE"); break;
|
||||
default: cp = new ChannelProperty(p.ToString(), "NOVALUE"); break;
|
||||
}
|
||||
_channelProperties.Add(p.ToString(), cp);
|
||||
}
|
||||
}
|
||||
public void SetTemplate(ISO.TestObjectTemplate template) { Template = template; }
|
||||
|
||||
private bool _bRequired;
|
||||
|
||||
/// <summary>
|
||||
/// Required channel property raises the OnRequiredChanged event
|
||||
/// </summary>
|
||||
public bool Required
|
||||
{
|
||||
get => _bRequired;
|
||||
set
|
||||
{
|
||||
_bRequired = value;
|
||||
//OnRequiredChanged(new RequiredChangedEventArgs { NewValue = value });
|
||||
_bRequired = value;
|
||||
}
|
||||
}
|
||||
public TestObjectTemplateChannel(DataRow dr, ISO.TestObjectTemplate template, ref ISO13499FileDb db)
|
||||
{
|
||||
Template = template;
|
||||
AddStandardProperties();
|
||||
TemplateChannelId = Convert.ToInt32(dr["TemplateChannelId"]);
|
||||
|
||||
_channelProperties[StandardChannelProperties.NameOfTheChannel.ToString()].Value = (string)dr["NameOfTheChannel"];
|
||||
|
||||
_channelProperties[StandardChannelProperties.DisplayOrder.ToString()].Value = 0;
|
||||
if (!DBNull.Value.Equals(dr["DisplayOrder"]))
|
||||
{
|
||||
_channelProperties[StandardChannelProperties.DisplayOrder.ToString()].Value = Convert.ToInt32(dr["DisplayOrder"]).ToString(System.Globalization.CultureInfo.InvariantCulture);
|
||||
}
|
||||
_bRequired = Convert.ToBoolean(dr["Required"]);
|
||||
LocalOnly = Convert.ToBoolean(dr["LocalOnly"]);
|
||||
var channelId = Convert.ToInt64(dr["MMEChannelId"]);
|
||||
var channelType = Convert.ToInt32(dr["MMEChannelType"]);
|
||||
Channel = db.GetPossibleChannel(channelId, channelType);
|
||||
}
|
||||
public TestObjectTemplateChannel(TestObjectTemplateChannel copy, ISO.TestObjectTemplate template)
|
||||
{
|
||||
TemplateChannelId = copy.TemplateChannelId;
|
||||
LocalOnly = copy.LocalOnly;
|
||||
_bRequired = copy.Required;
|
||||
Channel = new MMEPossibleChannels(copy.Channel);
|
||||
_channelProperties = new Dictionary<string, ChannelProperty>();
|
||||
using (var e = copy._channelProperties.GetEnumerator())
|
||||
{
|
||||
while (e.MoveNext())
|
||||
{
|
||||
_channelProperties[e.Current.Key] = new ChannelProperty(e.Current.Value);
|
||||
}
|
||||
}
|
||||
_channelPropertyNames = new List<string>(copy._channelPropertyNames.ToArray());
|
||||
Template = template;
|
||||
}
|
||||
public TestObjectTemplateChannel(MMEPossibleChannels channel)
|
||||
{
|
||||
Channel = channel;
|
||||
AddStandardProperties();
|
||||
var scp = Enum.GetValues(typeof(StandardChannelProperties)).Cast<StandardChannelProperties>().ToArray();
|
||||
foreach (var p in scp)
|
||||
{
|
||||
switch (p)
|
||||
{
|
||||
case StandardChannelProperties.DisplayOrder: _channelProperties[StandardChannelProperties.DisplayOrder.ToString()].Value = Convert.ToInt32(Channel.Id).ToString(System.Globalization.CultureInfo.InvariantCulture); break;
|
||||
case StandardChannelProperties.NameOfTheChannel: break;
|
||||
}
|
||||
}
|
||||
}
|
||||
//TODO: move to separate class
|
||||
public class ChannelProperty : ISerializable
|
||||
{
|
||||
public string Name { get; }
|
||||
public object Value { get; set; } = "NOVALUE";
|
||||
|
||||
public ChannelProperty(ChannelProperty copy)
|
||||
{
|
||||
Name = copy.Name;
|
||||
Value = copy.Value;
|
||||
}
|
||||
public ChannelProperty(string name, object value)
|
||||
{
|
||||
Name = name;
|
||||
Value = value;
|
||||
}
|
||||
public void GetObjectData(SerializationInfo info, StreamingContext context)
|
||||
{
|
||||
info.AddValue("PropertyName", Name);
|
||||
info.AddValue("PropertyValue", Value, Value.GetType());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,143 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace DatabaseImport
|
||||
{
|
||||
/// <summary>
|
||||
/// a simple setting in a test
|
||||
/// can have a default value, a value, and an id
|
||||
/// default value is used by TestSettingsDictionary for when
|
||||
/// the setting doesn't currently exist or have a value
|
||||
/// </summary>
|
||||
public class TestSetting
|
||||
{
|
||||
public string Id { get; }
|
||||
|
||||
public string Value { get; set; }
|
||||
|
||||
public string DefaultValue { get; }
|
||||
private const string SEPARATOR = "_x_";
|
||||
public TestSetting(TestSetting copy, string value)
|
||||
{
|
||||
Id = copy.Id;
|
||||
DefaultValue = copy.DefaultValue;
|
||||
Value = value;
|
||||
}
|
||||
public TestSetting(TestSetting copy)
|
||||
{
|
||||
Id = copy.Id;
|
||||
DefaultValue = copy.DefaultValue;
|
||||
Value = copy.Value;
|
||||
}
|
||||
public TestSetting(string id, string value, string defaultValue)
|
||||
{
|
||||
Id = id;
|
||||
Value = value;
|
||||
DefaultValue = defaultValue;
|
||||
}
|
||||
public string ToSerializeString()
|
||||
{
|
||||
System.Diagnostics.Trace.Assert(Id.IndexOf(SEPARATOR) < 0);
|
||||
return $"{Id.Replace("=", SEPARATOR)}={Value.Replace("=", SEPARATOR)}";
|
||||
}
|
||||
|
||||
public static bool TryParse(string s, out TestSetting ts)
|
||||
{
|
||||
ts = null;
|
||||
|
||||
var tokens = s.Split(new[] { "=" }, StringSplitOptions.None);
|
||||
if (tokens.Length < 2) { return false; }
|
||||
var id = tokens[0].Replace(SEPARATOR, "=");
|
||||
var val = tokens[1].Replace(SEPARATOR, "=");
|
||||
ts = new TestSetting(id, val, val);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// holds all possible settings for a test
|
||||
/// </summary>
|
||||
public class TestSettingDictionary
|
||||
{
|
||||
public TestSettingDictionary()
|
||||
{
|
||||
}
|
||||
public TestSettingDictionary(TestSettingDictionary copy)
|
||||
{
|
||||
using (var e = copy._lookup.GetEnumerator())
|
||||
{
|
||||
while (e.MoveNext())
|
||||
{
|
||||
_lookup[e.Current.Key] = new TestSetting(e.Current.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
private const string SEPARATOR = "_X_";
|
||||
private readonly Dictionary<string, TestSetting> _lookup = new Dictionary<string, TestSetting>();
|
||||
public string GetValue(string id, string defaultValue)
|
||||
{
|
||||
if (!_lookup.ContainsKey(id)) { return defaultValue; }
|
||||
return _lookup[id].Value ?? _lookup[id].DefaultValue;
|
||||
}
|
||||
public void UnLoad()
|
||||
{
|
||||
_lookup.Clear();
|
||||
}
|
||||
/// <summary>
|
||||
/// used to change the value in the dictionary (just the value, leave everything else the same)
|
||||
/// </summary>
|
||||
/// <param name="setting"></param>
|
||||
/// <param name="value"></param>
|
||||
public void SetValue(TestSetting setting, string value)
|
||||
{
|
||||
//we do it this way to avoid Add() and also to avoid accidentally reusing the input setting inappropriately
|
||||
_lookup[setting.Id] = new TestSetting(setting, value);
|
||||
}
|
||||
/// <summary>
|
||||
/// used to initialize a value in the dictionary
|
||||
/// </summary>
|
||||
/// <param name="setting"></param>
|
||||
public void SetValue(TestSetting setting)
|
||||
{
|
||||
_lookup[setting.Id] = setting;
|
||||
}
|
||||
public void SetValue(string id, string value)
|
||||
{
|
||||
if (!_lookup.ContainsKey(id))
|
||||
{
|
||||
_lookup[id] = new TestSetting(id, value, value);
|
||||
}
|
||||
else { _lookup[id].Value = value; }
|
||||
}
|
||||
public string ToSerializeString()
|
||||
{
|
||||
var sb = new StringBuilder();
|
||||
foreach (var s in _lookup.Values)
|
||||
{
|
||||
var sVal = s.ToSerializeString();
|
||||
// ReSharper disable once StringIndexOfIsCultureSpecific.1
|
||||
System.Diagnostics.Trace.Assert(sVal.IndexOf(SEPARATOR) < 0);
|
||||
sVal = sVal.Replace(System.Globalization.CultureInfo.InvariantCulture.TextInfo.ListSeparator, SEPARATOR);
|
||||
if (sb.Length > 0) { sb.Append(System.Globalization.CultureInfo.InvariantCulture.TextInfo.ListSeparator); }
|
||||
sb.Append(sVal);
|
||||
}
|
||||
return sb.ToString();
|
||||
}
|
||||
public void LoadSettings(string s)
|
||||
{
|
||||
var tokens = s.Split(new[] { System.Globalization.CultureInfo.InvariantCulture.TextInfo.ListSeparator }, StringSplitOptions.None);
|
||||
foreach (var token in tokens)
|
||||
{
|
||||
var tok = token.Replace(SEPARATOR, System.Globalization.CultureInfo.InvariantCulture.TextInfo.ListSeparator);
|
||||
//we prefer the default settings from the application
|
||||
//if for some reason this key is no longer used, we can still stick it in the storage and use it as is
|
||||
if (!TestSetting.TryParse(tok, out var ts)) continue;
|
||||
if (!_lookup.ContainsKey(ts.Id))//no longer has a default setting, just use as is
|
||||
{
|
||||
_lookup[ts.Id] = ts;
|
||||
}
|
||||
else { _lookup[ts.Id].Value = ts.Value; }//default setting exists, just set the value
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user