239 lines
7.6 KiB
C#
239 lines
7.6 KiB
C#
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"]);
|
|
}
|
|
}
|
|
}
|