using System; using System.Collections.Generic; using System.Data; using System.Data.OleDb; using System.Linq; using System.Xml; using DTS.Common.Enums.DBExport; using DTS.Common.Storage; using DTS.Common.Utilities.Logging; namespace DTS.Common.ISO { 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; /// /// import a singular fine location 1 node /// /// /// /// public static MMEFineLocations1 ReadXML(XmlElement node) { var fields = Enum.GetValues(typeof(CustomFinLoc1Fields)).Cast().ToArray(); string sGuid = "", fineLoc1 = "", textL1 = "", textL2 = "", remarks = "", sortKey = "", lastChangeText = "", history = ""; long version = 0; var expired = false; DateTime date = DateTime.Now, lastChange = DateTime.Now; foreach (var field in fields) { switch (field) { case CustomFinLoc1Fields.Date: date = DateTime.Parse(node.GetAttribute(field.ToString()), System.Globalization.CultureInfo.InvariantCulture); break; case CustomFinLoc1Fields.Expired: expired = Convert.ToBoolean(node.GetAttribute(field.ToString())); break; case CustomFinLoc1Fields.Fine_Loc_1: fineLoc1 = node.GetAttribute(field.ToString()); break; case CustomFinLoc1Fields.History: history = node.GetAttribute(field.ToString()); break; case CustomFinLoc1Fields.Last_Change: lastChange = DateTime.Parse(node.GetAttribute(field.ToString()), System.Globalization.CultureInfo.InvariantCulture); break; case CustomFinLoc1Fields.Last_Change_Text: lastChangeText = node.GetAttribute(field.ToString()); break; case CustomFinLoc1Fields.Remarks: remarks = node.GetAttribute(field.ToString()); break; case CustomFinLoc1Fields.S_GUID: sGuid = node.GetAttribute(field.ToString()); break; case CustomFinLoc1Fields.SortKey: sortKey = node.GetAttribute(field.ToString()); break; case CustomFinLoc1Fields.Text_L1: textL1 = node.GetAttribute(field.ToString()); break; case CustomFinLoc1Fields.Text_L2: textL2 = node.GetAttribute(field.ToString()); break; case CustomFinLoc1Fields.Version: version = long.Parse(node.GetAttribute(field.ToString()), System.Globalization.CultureInfo.InvariantCulture); break; default: throw new NotSupportedException("ImportTestSetup::ImportCustomFineLoc1 unsupported field: " + field); } } return new MMEFineLocations1(sGuid, fineLoc1, textL1, textL2, version, date, remarks, expired, sortKey, lastChange, lastChangeText, history, MMEPossibleChannels.MMEChannelTypes.SQL); } 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 MMEFineLocations1() { } public static MMEFineLocations1[] GetFineLocations1() { var fineLocations1 = new List(); using (var cmd = DbOperations.GetISOCommand()) { cmd.CommandType = CommandType.Text; cmd.CommandText = "SELECT * FROM MMEFineLocations1"; try { using (var ISOReader = cmd.ExecuteReader()) { while (ISOReader.Read()) { try { string sGuid = ISOReader["s_GUID"].ToString(); string sFineLoc1 = ISOReader["FINE_LOC_1"].ToString(); string textL1 = ISOReader["TEXT_L1"].ToString(); string textL2 = ISOReader["TEXT_L2"].ToString(); long version = Convert.ToInt64(ISOReader["VERSION"]); DateTime date = (DateTime)ISOReader["DATE"]; string remarks = ISOReader["REMARKS"].ToString(); bool expired = (bool)ISOReader["EXPIRED"]; string sortkey = ISOReader["SORTKEY"].ToString(); DateTime lastChange = GetDate(ISOReader, "LAST_CHANGE"); string lastChangeText = ISOReader["LAST_CHANGE_TEXT"].ToString(); string history = ISOReader["HISTORY"].ToString(); fineLocations1.Add(new MMEFineLocations1(sGuid, sFineLoc1, textL1, textL2, version, date, remarks, expired, sortkey, lastChange, lastChangeText, history, MMEPossibleChannels.MMEChannelTypes.ISO13499_106)); } catch (Exception ex) { APILogger.Log("Failed to process fine loc 1 ", ex); } } } } finally { cmd.Connection.Dispose(); } } return fineLocations1.ToArray(); } } }