diff --git a/ENI-2/ENI2/ENI2/App.config b/ENI-2/ENI2/ENI2/App.config index 59d78db3..1d027849 100644 --- a/ENI-2/ENI2/ENI2/App.config +++ b/ENI-2/ENI2/ENI2/App.config @@ -31,7 +31,7 @@ - Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=nsw;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False + Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=E:\DATA\DB\NSW.MDF;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False diff --git a/ENI-2/ENI2/ENI2/MainWindow.xaml.cs b/ENI-2/ENI2/ENI2/MainWindow.xaml.cs index 24edc984..584c83c5 100644 --- a/ENI-2/ENI2/ENI2/MainWindow.xaml.cs +++ b/ENI-2/ENI2/ENI2/MainWindow.xaml.cs @@ -510,6 +510,7 @@ namespace ENI2 this.busyIndicator.IsBusy = false; this.labelStatusBar.Text = string.Format("Rep.Party: {0} {1} [{2}]", this.userEntity.FirstName, this.userEntity.LastName, this.userEntity.Logon); App.UserId = this.userEntity.Id; + ReportingParty.CurrentReportingParty = this.userEntity; if (this.userEntity.IsAdmin) { this.buttonUserAdmin.Visibility = Visibility.Visible; diff --git a/Stundensheet.xlsx b/Stundensheet.xlsx index 0fb6375a..9b6fc73d 100644 Binary files a/Stundensheet.xlsx and b/Stundensheet.xlsx differ diff --git a/nsw/Source/bsmd.database/CallPurpose.cs b/nsw/Source/bsmd.database/CallPurpose.cs index e5bf4918..d92bbeee 100644 --- a/nsw/Source/bsmd.database/CallPurpose.cs +++ b/nsw/Source/bsmd.database/CallPurpose.cs @@ -11,6 +11,7 @@ using System; using System.Data; using System.Data.SqlClient; using System.Collections.Generic; +using Newtonsoft.Json; namespace bsmd.database { @@ -24,6 +25,7 @@ namespace bsmd.database #region Properties + [JsonIgnore] public NOA_NOD NOA_NOD { get; set; } [ShowReport] @@ -38,6 +40,7 @@ namespace bsmd.database public string Identifier { get; set; } + [JsonIgnore] public string SublistCollectionKey { get { return "callpurpose"; } } #endregion diff --git a/nsw/Source/bsmd.database/DBManager.cs b/nsw/Source/bsmd.database/DBManager.cs index f9980963..435a6a4f 100644 --- a/nsw/Source/bsmd.database/DBManager.cs +++ b/nsw/Source/bsmd.database/DBManager.cs @@ -12,7 +12,9 @@ using System.Collections.Generic; using System.Data; using System.Data.SqlClient; using System.Diagnostics; +using Newtonsoft.Json; using log4net; +using System.Reflection; namespace bsmd.database { @@ -29,6 +31,7 @@ namespace bsmd.database private readonly object _lock = new object(); private bool _closeConnectionAfterUse = false; private readonly List truncatedFieldCollection = new List(); + private Dictionary messageHistoryTypeDict; #endregion @@ -44,6 +47,15 @@ namespace bsmd.database #endregion + #region Construction + + public DBManager() + { + this.InitializeMessageHistoryTypes(); + } + + #endregion + #region Properties public static DBManager Instance @@ -329,8 +341,7 @@ namespace bsmd.database { result = (Message) messages[0]; // es kann nur eine sein result.MessageCore = core; - List lm = new List(); - lm.Add(result); + List lm = new List { result }; this.LoadMessageDependencies(lm); } @@ -711,18 +722,80 @@ namespace bsmd.database } } + #region MessageHistory + + /// + /// Diskussion: Es wäre besser, wenn man hier nur Message serialisieren würde. Allerdings wird der "Inhalt" bei + /// einer Neuanlage erst nach der Message gespeichert und wäre dann hier nicht vorhanden. Es muss daher ein Switch über alle Element + /// Typen durchgeführt werden. + /// + /// private void CreateEntityHistoryEntry(DatabaseEntity entity) { - // switch(entity.) + // sehr schöner Ansatz, den ich doch nicht verwendet habe; + //var @switch = new Dictionary { + // { typeof(Type1), () => ... }, + // { typeof(Type2), () => ... }, + // { typeof(Type3), () => ... }, + //}; + + //@switch[typeof(MyType)](); + + Type entityType = entity.GetType(); // 1. prüfen ob für das Objekt ein Historieneintrag angelegt werden soll + if (this.messageHistoryTypeDict.ContainsKey(entityType)) { - // 2. falls ja Objekt serialisieren - - // 3. MessageHistory Element speichern - // (das könnte auch in einem Background Thread passieren, da der Wert erst irgendwann gelesen wird und aktuell nicht relevant ist) - + // 2. falls ja Objekt serialisieren + MessageHistory mh = new MessageHistory(); + mh.EntityId = entity.MessageHeader.Id.Value; + mh.EntityName = entityType.Name; + mh.EntityType = entityType.ToString(); + mh.EntityValues = JsonConvert.SerializeObject(entity); + if (ReportingParty.CurrentReportingParty != null) + mh.ReportingPartyId = ReportingParty.CurrentReportingParty.Id.Value; + + // 3. MessageHistory Element speichern + // TODO: das könnte auch in einem Background Thread passieren, da der Wert erst irgendwann gelesen wird und aktuell nicht relevant ist + SqlCommand cmd = new SqlCommand(); + mh.PrepareSave(cmd); + int queryResult = this.PerformNonQuery(cmd); + this.LogNonQueryResult(cmd.CommandText, queryResult); + } } + private void InitializeMessageHistoryTypes() + { + this.messageHistoryTypeDict = new Dictionary + { + { typeof(AGNT), typeof(AGNT).Name }, + { typeof(ATA), typeof(ATA).Name }, + { typeof(ATD), typeof(ATD).Name }, + { typeof(BRKA), typeof(BRKA).Name }, + { typeof(BRKD), typeof(BRKD).Name }, + { typeof(CREW), typeof(CREW).Name }, + { typeof(HAZ), typeof(HAZ).Name }, + { typeof(INFO), typeof(INFO).Name }, + { typeof(LADG), typeof(LADG).Name }, + { typeof(MDH), typeof(MDH).Name }, + { typeof(NAME), typeof(NAME).Name }, + { typeof(NOA_NOD), typeof(NOA_NOD).Name }, + { typeof(PAS), typeof(PAS).Name }, + { typeof(POBA), typeof(POBA).Name }, + { typeof(POBD), typeof(POBD).Name }, + { typeof(PRE72H), typeof(PRE72H).Name }, + { typeof(SEC), typeof(SEC).Name }, + { typeof(SERV), typeof(SERV).Name }, + { typeof(STAT), typeof(STAT).Name }, + { typeof(STO), typeof(STO).Name }, + { typeof(TIEFA), typeof(TIEFA).Name }, + { typeof(TIEFD), typeof(TIEFD).Name }, + { typeof(TOWA), typeof(TOWA).Name }, + { typeof(TOWD), typeof(TOWD).Name }, + { typeof(WAS), typeof(WAS).Name } + }; + } + + #endregion #region CreateMessage() diff --git a/nsw/Source/bsmd.database/DatabaseEntity.cs b/nsw/Source/bsmd.database/DatabaseEntity.cs index c9c050fc..bfc94d46 100644 --- a/nsw/Source/bsmd.database/DatabaseEntity.cs +++ b/nsw/Source/bsmd.database/DatabaseEntity.cs @@ -16,6 +16,7 @@ using System.Reflection; using System.Text.RegularExpressions; using System.Xml.Serialization; using System.IO; +using Newtonsoft.Json; using log4net; namespace bsmd.database @@ -24,7 +25,7 @@ namespace bsmd.database [XmlInclude(typeof(Message))] [XmlInclude(typeof(MessageCore))] [XmlInclude(typeof(AGNT))] - public abstract class DatabaseEntity : IMessageParagraph, IEquatable, ICloneable + public abstract class DatabaseEntity : IDatabaseEntity, IMessageParagraph, IEquatable, ICloneable { protected Guid? id; protected string tablename; @@ -53,8 +54,10 @@ namespace bsmd.database /// /// Nachrichtentyp der abgeleiteten Meldeklassen /// + [JsonIgnore] public Message.NotificationClass MessageNotificationClass { get; set; } + [JsonIgnore] public string MessageNotificationClassDisplay { get @@ -66,16 +69,19 @@ namespace bsmd.database /// /// Referenz zur eigentlichen Schiffankunft /// + [JsonIgnore] public MessageCore MessageCore { get; set; } /// /// gemeinschaftliche Daten /// - public Message MessageHeader { get; set; } + [JsonIgnore] + public Message MessageHeader { get; set; } /// /// SQL Table name to construct queries /// + [JsonIgnore] public virtual string Tablename { get { return this.tablename; } } /// @@ -86,11 +92,13 @@ namespace bsmd.database /// /// IsNew Flag /// + [JsonIgnore] public bool IsNew { get { return !this.id.HasValue; } } /// /// Flag zeigt an ob das Objekt geändert wurde /// + [JsonIgnore] public bool IsDirty { get; set; } #endregion @@ -114,6 +122,7 @@ namespace bsmd.database /// /// Ergebnismenge begrenzen: NULL = kein Limit. Abgeleitete Klassen *können* diesen Parameter berücksichtigen /// + [JsonIgnore] public int? ResultLimit { get; set; } public abstract void PrepareLoadCommand(IDbCommand cmd, Message.LoadFilter filter, params object[] criteria); @@ -174,7 +183,7 @@ namespace bsmd.database public virtual ValidationBlock GetValidationBlock() { return ValidationBlock.BLOCK1; - } + } #endregion @@ -271,6 +280,7 @@ namespace bsmd.database #region IMessageParagraph implementation + [JsonIgnore] public virtual string Title { get @@ -280,11 +290,13 @@ namespace bsmd.database } } + [JsonIgnore] public virtual string Subtitle { get { return string.Empty; } } + [JsonIgnore] public virtual bool ShowChildrenAsTable { get { return false; } @@ -293,6 +305,7 @@ namespace bsmd.database /// /// must be overridden if it must make sense /// + [JsonIgnore] public virtual List> MessageText { get { @@ -321,8 +334,8 @@ namespace bsmd.database public virtual string GetDisplayValue(PropertyInfo property) { - bool isDouble = (property.PropertyType == typeof(Nullable)); - bool isDateTime = (property.PropertyType == typeof(Nullable)); + bool isDouble = (property.PropertyType == typeof(double?)); + bool isDateTime = (property.PropertyType == typeof(DateTime?)); object propValue = property.GetValue(this, null); if (propValue == null) return ""; @@ -352,6 +365,7 @@ namespace bsmd.database return value; } + [JsonIgnore] public virtual List ChildParagraphs { get { return null; } } #endregion @@ -365,35 +379,7 @@ namespace bsmd.database return entity; } - #endregion - - #region Serialization - - public static DatabaseEntity Deserialize(string serializedClass) - { - - return null; - } - - public string Serialize() - { - using (StringWriter sw = new StringWriter()) - { - try - { - XmlSerializer serializer = new XmlSerializer(this.GetType()); - serializer.Serialize(sw, this); - return sw.ToString(); - } - catch (Exception ex) - { - _log.ErrorFormat("Serialization failed: {0}", ex.Message); - } - } - return null; - } - - #endregion + #endregion } } diff --git a/nsw/Source/bsmd.database/IBCPosition.cs b/nsw/Source/bsmd.database/IBCPosition.cs index 2792f4f3..ab2626ca 100644 --- a/nsw/Source/bsmd.database/IBCPosition.cs +++ b/nsw/Source/bsmd.database/IBCPosition.cs @@ -13,6 +13,7 @@ using System.Data; using System.Data.SqlClient; using System.Reflection; using System.Text.RegularExpressions; +using Newtonsoft.Json; namespace bsmd.database { @@ -56,6 +57,7 @@ namespace bsmd.database #region Properties + [JsonIgnore] public HAZ HAZ { get; set; } [ShowReport] @@ -71,6 +73,7 @@ namespace bsmd.database [ShowReport] [ReportDisplayName("PollutionCategory")] + [JsonIgnore] public string PollutionCategoryDisplay { get @@ -86,6 +89,7 @@ namespace bsmd.database [ShowReport] [ReportDisplayName("Hazards")] + [JsonIgnore] public string HazardsDisplay { get @@ -102,6 +106,7 @@ namespace bsmd.database [ShowReport] [ReportDisplayName("FlashpointInformation")] + [JsonIgnore] public string FlashpointInformationDisplay { get @@ -152,6 +157,7 @@ namespace bsmd.database public string Identifier { get; set; } + [JsonIgnore] public string SublistCollectionKey { get { return "ibc"; } } #endregion diff --git a/nsw/Source/bsmd.database/IDatabaseEntity.cs b/nsw/Source/bsmd.database/IDatabaseEntity.cs new file mode 100644 index 00000000..865fa820 --- /dev/null +++ b/nsw/Source/bsmd.database/IDatabaseEntity.cs @@ -0,0 +1,25 @@ +// Copyright (c) 2015-2017 schick Informatik +// Description: Interface für DB Objekte, die nicht von DatabaseEntity erben + +using System; +using System.Data; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace bsmd.database +{ + public interface IDatabaseEntity + { + + string Tablename { get; } + + void PrepareSave(IDbCommand cmd); + + void PrepareDelete(IDbCommand cmd); + + List LoadList(IDataReader reader); + + } +} diff --git a/nsw/Source/bsmd.database/IGCPosition.cs b/nsw/Source/bsmd.database/IGCPosition.cs index 9d9e9c34..5f14edc7 100644 --- a/nsw/Source/bsmd.database/IGCPosition.cs +++ b/nsw/Source/bsmd.database/IGCPosition.cs @@ -11,6 +11,7 @@ using System; using System.Collections.Generic; using System.Data; using System.Data.SqlClient; +using Newtonsoft.Json; namespace bsmd.database { @@ -24,6 +25,7 @@ namespace bsmd.database #region Properties + [JsonIgnore] public HAZ HAZ { get; set; } [ShowReport] @@ -72,6 +74,7 @@ namespace bsmd.database public string Identifier { get; set; } + [JsonIgnore] public string SublistCollectionKey { get { return "igc"; } } #endregion diff --git a/nsw/Source/bsmd.database/IMDGPosition.cs b/nsw/Source/bsmd.database/IMDGPosition.cs index ed94d2a9..5be004bd 100644 --- a/nsw/Source/bsmd.database/IMDGPosition.cs +++ b/nsw/Source/bsmd.database/IMDGPosition.cs @@ -13,14 +13,12 @@ using System.Data; using System.Data.SqlClient; using System.Text; using System.Text.RegularExpressions; +using Newtonsoft.Json; namespace bsmd.database { public class IMDGPosition : DatabaseEntity, ISublistElement { - - private List subsidiaryRisksList = new List(); - public IMDGPosition() { this.tablename = "[dbo].[IMDGPosition]"; @@ -28,6 +26,7 @@ namespace bsmd.database #region Properties + [JsonIgnore] public HAZ HAZ { get; set; } [ShowReport] @@ -189,23 +188,24 @@ namespace bsmd.database [MaxLength(255)] [ENI2Validation] public string Remarks { get; set; } - - public List SubsidiaryRiskList { get { return this.subsidiaryRisksList; } } + + public List SubsidiaryRiskList { get; private set; } = new List(); /// /// Hilfsproperty, um subsidiary risks als kommaseparierte Liste anzuzeigen (ENI-2) /// [ENI2Validation] + [JsonIgnore] public string SubsidiaryRiskText { get { StringBuilder sb = new StringBuilder(); - for (int i = 0; i < this.subsidiaryRisksList.Count; i++) + for (int i = 0; i < this.SubsidiaryRiskList.Count; i++) { if (i > 0) sb.Append(", "); - sb.Append(this.subsidiaryRisksList[i].SubsidiaryRisk); + sb.Append(this.SubsidiaryRiskList[i].SubsidiaryRisk); } return sb.ToString(); } @@ -254,15 +254,16 @@ namespace bsmd.database // remove remaining risk (no longer valid) foreach (SubsidiaryRisks remainingRisk in this.SubsidiaryRiskList) DBManager.Instance.Delete(remainingRisk); - this.subsidiaryRisksList.Clear(); + this.SubsidiaryRiskList.Clear(); // add existing and new risk - this.subsidiaryRisksList.AddRange(foundList); + this.SubsidiaryRiskList.AddRange(foundList); } } } public string Identifier { get; set; } + [JsonIgnore] public string SublistCollectionKey { get { return "imdg"; } } #endregion @@ -523,7 +524,7 @@ namespace bsmd.database { IMDGPosition imdg = this.MemberwiseClone() as IMDGPosition; imdg.id = null; - imdg.subsidiaryRisksList = new List(); + imdg.SubsidiaryRiskList = new List(); foreach (SubsidiaryRisks sr in this.SubsidiaryRiskList) { diff --git a/nsw/Source/bsmd.database/IMSBCPosition.cs b/nsw/Source/bsmd.database/IMSBCPosition.cs index fed50128..8ae483bd 100644 --- a/nsw/Source/bsmd.database/IMSBCPosition.cs +++ b/nsw/Source/bsmd.database/IMSBCPosition.cs @@ -11,6 +11,7 @@ using System; using System.Collections.Generic; using System.Data; using System.Data.SqlClient; +using Newtonsoft.Json; namespace bsmd.database { @@ -24,6 +25,7 @@ namespace bsmd.database #region Properties + [JsonIgnore] public HAZ HAZ { get; set; } [ShowReport] @@ -77,6 +79,7 @@ namespace bsmd.database public string Identifier { get; set; } + [JsonIgnore] public string SublistCollectionKey { get { return "imsbc"; } } #endregion diff --git a/nsw/Source/bsmd.database/InfectedArea.cs b/nsw/Source/bsmd.database/InfectedArea.cs index 936c4bc8..ce3c491b 100644 --- a/nsw/Source/bsmd.database/InfectedArea.cs +++ b/nsw/Source/bsmd.database/InfectedArea.cs @@ -11,6 +11,7 @@ using System; using System.Collections.Generic; using System.Data; using System.Data.SqlClient; +using Newtonsoft.Json; namespace bsmd.database { @@ -24,6 +25,7 @@ namespace bsmd.database #region Properties + [JsonIgnore] public MDH MDH { get; set; } [ShowReport] @@ -37,6 +39,7 @@ namespace bsmd.database public string Identifier { get; set; } + [JsonIgnore] public string SublistCollectionKey { get { return "infectedarea"; } } #endregion diff --git a/nsw/Source/bsmd.database/LastTenPortFacilitiesCalled.cs b/nsw/Source/bsmd.database/LastTenPortFacilitiesCalled.cs index bd85661c..ecaa4903 100644 --- a/nsw/Source/bsmd.database/LastTenPortFacilitiesCalled.cs +++ b/nsw/Source/bsmd.database/LastTenPortFacilitiesCalled.cs @@ -11,6 +11,7 @@ using System; using System.Data; using System.Data.SqlClient; using System.Collections.Generic; +using Newtonsoft.Json; namespace bsmd.database { @@ -24,6 +25,7 @@ namespace bsmd.database #region Properties + [JsonIgnore] public SEC SEC { get; set; } [ShowReport] @@ -76,6 +78,7 @@ namespace bsmd.database public string Identifier { get; set; } + [JsonIgnore] public string SublistCollectionKey { get { return "l10pfc"; } } #endregion @@ -110,7 +113,7 @@ namespace bsmd.database } else { - scmd.Parameters.AddWithValue(@"ID", this.Id); + scmd.Parameters.AddWithValue("ID", this.Id); scmd.CommandText = string.Format("UPDATE {0} SET PortFacilityPortName = @P2, PortFacilityPortCountry = @P3, " + "PortFacilityPortLoCode = @P4, PortFacilityDateOfArrival = @P5, PortFacilityDateOfDeparture = @P6," + "PortFacilityShipSecurityLevel = @P7, PortFacilitySecurityMattersToReport = @P8, PortFacilityGISISCode = @P9, " + diff --git a/nsw/Source/bsmd.database/MARPOL_Annex_I_Position.cs b/nsw/Source/bsmd.database/MARPOL_Annex_I_Position.cs index 9d801caa..f1108a3d 100644 --- a/nsw/Source/bsmd.database/MARPOL_Annex_I_Position.cs +++ b/nsw/Source/bsmd.database/MARPOL_Annex_I_Position.cs @@ -12,6 +12,7 @@ using System.Collections.Generic; using System.Data; using System.Data.SqlClient; using System.Text.RegularExpressions; +using Newtonsoft.Json; namespace bsmd.database { @@ -25,6 +26,7 @@ namespace bsmd.database #region Properties + [JsonIgnore] public HAZ HAZ { get; set; } [ShowReport] @@ -85,6 +87,7 @@ namespace bsmd.database public string Identifier { get; set; } + [JsonIgnore] public string SublistCollectionKey { get { return "marpol"; } } #endregion @@ -116,7 +119,7 @@ namespace bsmd.database } else { - scmd.Parameters.AddWithValue(@"ID", this.Id); + scmd.Parameters.AddWithValue("@ID", this.Id); scmd.CommandText = string.Format("UPDATE {0} SET Name = @P2, FlashpointInformation= @P3, Flashpoint_CEL = @P4, " + "Quantity_KGM = @P5, StowagePosition = @P6, PortOfLoading = @P7, PortOfDischarge = @P8, Remarks = @P9, " + "Identifier = @P10 WHERE Id = @ID", this.Tablename); @@ -183,8 +186,8 @@ namespace bsmd.database this.HAZ.IsDeparture ? "HAZD" : "HAZA")); if (!this.Flashpoint_CEL.IsNullOrEmpty()) - { - string pattern = @"^[<>]?\-?[0-9]+(\.[0-9]+)?$"; + { + const string pattern = @"^[<>]?\-?[0-9]+(\.[0-9]+)?$"; Regex regex = new Regex(pattern); if (!regex.IsMatch(this.Flashpoint_CEL)) diff --git a/nsw/Source/bsmd.database/Message.cs b/nsw/Source/bsmd.database/Message.cs index 39a73a90..71c58767 100644 --- a/nsw/Source/bsmd.database/Message.cs +++ b/nsw/Source/bsmd.database/Message.cs @@ -13,17 +13,8 @@ namespace bsmd.database public class Message : DatabaseEntity, ISublistContainer, IComparable { - #region Fields - - private Guid? messageCoreId; - private Guid? reportingPartyId; +#region Fields private ReportingParty reportingParty; - private DateTime? created; - private DateTime? changed; - private List errorList = new List(); - private List violationList = new List(); - private List systemErrorList = new List(); - private ObservableCollection elements = new ObservableCollection(); #endregion @@ -172,14 +163,20 @@ namespace bsmd.database { [Description("Unspecified")] UNDEFINED, + DBH, + DAKOSY, + [Description("HIS-Nord")] DUDR, + [Description("DBH Testsystem")] DBH_TEST, + [Description("Dakosy Testsystem")] DAKOSY_TEST, + [Description("HIS-Nord Testsystem")] DUDR_TEST } @@ -204,7 +201,7 @@ namespace bsmd.database public Guid? MessageId { get; set; } - public Guid? MessageCoreId { get { return this.messageCoreId; } set { this.messageCoreId = value; } } + public Guid? MessageCoreId { get; set; } public DateTime? SentAt { get; set; } @@ -221,7 +218,7 @@ namespace bsmd.database public MessageStatus? Status { get; set; } [ShowReport] - public DateTime? Created { get { return this.created; } } + public DateTime? Created { get; private set; } /// /// Vorwärts-Referenzen auf die von diesem Header-Element abhängigen speziellen Nachrichten-Datensätzen @@ -229,7 +226,7 @@ namespace bsmd.database /// BRKA, BRKD, LADG, CREW, PAS, SERV, TOWA, TOWD, STO, CREWD, PASD /// sonst hat die Liste immer ein Element /// - public ObservableCollection Elements { get { return this.elements; } } + public ObservableCollection Elements { get; } = new ObservableCollection(); /// /// Der Meldende @@ -241,11 +238,11 @@ namespace bsmd.database { if (value == null) { - this.reportingPartyId = null; + this.ReportingPartyId = null; } else { - this.reportingPartyId = value.Id; + this.ReportingPartyId = value.Id; } this.reportingParty = value; } @@ -274,22 +271,22 @@ namespace bsmd.database /// /// Fehlerliste (Rückgabe vom NSW) /// - public List ErrorList { get { return this.errorList; } } + public List ErrorList { get; } = new List(); /// /// Violation-Liste (Rückgabe vom NSW) /// - public List ViolationList { get { return this.violationList; } } + public List ViolationList { get; } = new List(); /// /// Liste mit "System"-Errors (HIS-Nord) /// - public List SystemErrorList { get { return this.systemErrorList; } } + public List SystemErrorList { get; } = new List(); /// /// Property to overwrite reporting party in certain circumstances (other melder meldet) /// - public Guid? ReportingPartyId { get { return this.reportingPartyId; } set { this.reportingPartyId = value; } } + public Guid? ReportingPartyId { get; set; } /// /// Urheber der Nachricht (Excel oder HE) @@ -304,7 +301,7 @@ namespace bsmd.database /// /// Database last "Changed" date display /// - public DateTime? Changed { get { return this.changed; } } + public DateTime? Changed { get; private set; } /// /// ENI-2 detail group text @@ -357,7 +354,7 @@ namespace bsmd.database this.ViolationList.IsNullOrEmpty() && this.ErrorList.IsNullOrEmpty() && this.Status.HasValue && - !(this.Reset) && + !this.Reset && (this.Status.Value == MessageStatus.ACCEPTED); } } @@ -374,9 +371,9 @@ namespace bsmd.database #region IDatabaseEntity implementation - public override void PrepareSave(IDbCommand cmdParam) + public override void PrepareSave(IDbCommand dbCommand) { - SqlCommand cmd = cmdParam as SqlCommand; + SqlCommand cmd = dbCommand as SqlCommand; if (this.ClientRequestId != null) cmd.Parameters.AddWithValue("@CLIENTREQUESTID", Guid.Parse(this.ClientRequestId)); @@ -407,7 +404,7 @@ namespace bsmd.database else cmd.Parameters.AddWithValue("@STATUS", DBNull.Value); - cmd.Parameters.AddWithNullableValue("@REPORTINGPARTYID", this.reportingPartyId); + cmd.Parameters.AddWithNullableValue("@REPORTINGPARTYID", this.ReportingPartyId); cmd.Parameters.AddWithValue("@BSMDSTATUS", this.InternalStatus); cmd.Parameters.AddWithNullableValue("@LASTSTATUS", this.LastStatus); cmd.Parameters.AddWithValue("@HIS", this.HIS); @@ -508,7 +505,7 @@ namespace bsmd.database Message msg = new Message(); msg.id = reader.GetGuid(0); if (!reader.IsDBNull(1)) msg.ClientRequestId = reader.GetGuid(1).ToString(); - msg.messageCoreId = reader.GetGuid(2); + msg.MessageCoreId = reader.GetGuid(2); if(!reader.IsDBNull(3)) msg.MessageId = reader.GetGuid(3); if (!reader.IsDBNull(4)) msg.SentAt = reader.GetDateTime(4); if (!reader.IsDBNull(5)) msg.ReceivedAt = reader.GetDateTime(5); @@ -517,14 +514,14 @@ namespace bsmd.database if (!reader.IsDBNull(8)) msg.Reset = reader.GetBoolean(8); if (!reader.IsDBNull(9)) msg.Cancel = reader.GetBoolean(9); if (!reader.IsDBNull(10)) msg.Status = (MessageStatus)Enum.ToObject(typeof(MessageStatus), reader.GetByte(10)); - if (!reader.IsDBNull(11)) msg.reportingPartyId = reader.GetGuid(11); + if (!reader.IsDBNull(11)) msg.ReportingPartyId = reader.GetGuid(11); if (!reader.IsDBNull(12)) msg.InternalStatus = (BSMDStatus)Enum.ToObject(typeof(BSMDStatus), reader.GetByte(12)); if (!reader.IsDBNull(13)) msg.LastStatus = (BSMDStatus)Enum.ToObject(typeof(BSMDStatus), reader.GetByte(13)); if (!reader.IsDBNull(14)) msg.HIS = (NSWProvider)Enum.ToObject(typeof(NSWProvider), reader.GetByte(14)); - if (!reader.IsDBNull(15)) msg.created = reader.GetDateTime(15); + if (!reader.IsDBNull(15)) msg.Created = reader.GetDateTime(15); if (!reader.IsDBNull(16)) msg.CreatedBy = reader.GetString(16); if (!reader.IsDBNull(17)) msg.ChangedBy = reader.GetString(17); - if (!reader.IsDBNull(18)) msg.changed = reader.GetDateTime(18); + if (!reader.IsDBNull(18)) msg.Changed = reader.GetDateTime(18); if (!reader.IsDBNull(19)) msg.StatusInfo = reader.GetString(19); if (!reader.IsDBNull(20)) msg.SendSuccess = reader.GetBoolean(20); if (!reader.IsDBNull(21)) msg.SentBy = reader.GetString(21); @@ -542,8 +539,8 @@ namespace bsmd.database { foreach (Message message in messages) { - if (message.reportingPartyId.HasValue && reportingParties.ContainsKey(message.reportingPartyId.Value)) - message.reportingParty = reportingParties[message.reportingPartyId.Value]; + if (message.ReportingPartyId.HasValue && reportingParties.ContainsKey(message.ReportingPartyId.Value)) + message.reportingParty = reportingParties[message.ReportingPartyId.Value]; } } @@ -551,14 +548,13 @@ namespace bsmd.database { foreach (Message message in messages) { - if (message.messageCoreId.HasValue && messageCores.ContainsKey(message.messageCoreId.Value)) - message.MessageCore = messageCores[message.messageCoreId.Value]; + if (message.MessageCoreId.HasValue && messageCores.ContainsKey(message.MessageCoreId.Value)) + message.MessageCore = messageCores[message.MessageCoreId.Value]; } } public static bool IsListClass(NotificationClass notificationClass) - { - bool result = false; + { switch(notificationClass) { @@ -576,7 +572,7 @@ namespace bsmd.database return true; } - return result; + return false; } @@ -624,7 +620,7 @@ namespace bsmd.database foreach (DatabaseEntity entity in this.Elements) { ISublistElement sublistElement = entity as ISublistElement; - if ((sublistElement != null ) && (sublistElement.Identifier != null)) + if (sublistElement?.Identifier != null) { if (((ISublistElement)entity).Identifier.Equals(identifier)) return entity as ISublistElement; @@ -661,9 +657,9 @@ namespace bsmd.database foreach (DatabaseEntity dbEntity in this.Elements) { DBManager.Instance.Save(dbEntity); - if (dbEntity is ISublistContainer) + if (dbEntity is ISublistContainer sublistContainer) { - ((ISublistContainer)dbEntity).SaveElements(); + (sublistContainer).SaveElements(); } } } @@ -672,9 +668,9 @@ namespace bsmd.database { foreach (DatabaseEntity dbEntity in this.Elements) { - if (dbEntity is ISublistContainer) + if (dbEntity is ISublistContainer sublistContainer) { - ((ISublistContainer)dbEntity).DeleteElements(); + (sublistContainer).DeleteElements(); } DBManager.Instance.Delete(dbEntity); } diff --git a/nsw/Source/bsmd.database/MessageHistory.cs b/nsw/Source/bsmd.database/MessageHistory.cs index ec27cc9b..1c37624b 100644 --- a/nsw/Source/bsmd.database/MessageHistory.cs +++ b/nsw/Source/bsmd.database/MessageHistory.cs @@ -3,31 +3,94 @@ using System; using System.Collections.Generic; +using System.Data; +using System.Data.SqlClient; using System.Linq; using System.Text; namespace bsmd.database { - public class MessageHistory + public class MessageHistory : IDatabaseEntity { + private const string tableName = "[MessageHistory]"; + #region Properties + public string Tablename { get { return tableName; } } + + public Guid? Id { get; set; } + public Guid? ReportingPartyId { get; set; } - ReportingParty CreatedBy { get; set; } + public ReportingParty CreatedBy { get; set; } - public Guid EntityId { get; private set; } + public Guid EntityId { get; internal set; } - public string EntityType { get; private set; } + public string EntityType { get; internal set; } - public string EntityName { get; private set; } + public string EntityName { get; internal set; } - public string EntityValues { get; private set; } + public string EntityValues { get; internal set; } public DateTime Created { get; private set; } #endregion + #region IDatabaseEntity implementation + + public void PrepareSave(IDbCommand cmd) + { + SqlCommand scmd = cmd as SqlCommand; + + // es gibt nur insert + this.Id = Guid.NewGuid(); + scmd.Parameters.AddWithValue("@ID", this.Id); + scmd.Parameters.AddWithNullableValue("@P1", this.ReportingPartyId); + scmd.Parameters.AddWithValue("@P2", this.EntityId); + scmd.Parameters.AddWithValue("@P3", this.EntityType); + scmd.Parameters.AddWithValue("@P4", this.EntityName); + scmd.Parameters.AddWithValue("@P5", this.EntityValues); + scmd.Parameters.AddWithValue("@P6", DateTime.Now); + + cmd.CommandText = string.Format("INSERT INTO {0} (Id, ReportingPartyId, EntityId, EntityType, " + + "EntityName, EntityValues, Timestamp) VALUES (@ID, @P1, @P2, @P3, @P4, @P5, @P6)", this.Tablename); + } + + public void PrepareDelete(IDbCommand cmd) + { + SqlCommand scmd = cmd as SqlCommand; + scmd.CommandText = string.Format("DELETE FROM {0} WHERE Id = @ID", Tablename); + scmd.Parameters.AddWithValue("@ID", this.Id); + } + + public List LoadList(IDataReader reader) + { + List result = new List(); + + while (reader.Read()) + { + MessageHistory mh = new MessageHistory(); + mh.Id = reader.GetGuid(0); + if (!reader.IsDBNull(1)) mh.ReportingPartyId = reader.GetGuid(1); + if (!reader.IsDBNull(2)) mh.EntityId = reader.GetGuid(2); + if (!reader.IsDBNull(3)) mh.EntityType = reader.GetString(3); + if (!reader.IsDBNull(4)) mh.EntityName = reader.GetString(4); + if (!reader.IsDBNull(5)) mh.EntityValues = reader.GetString(5); + if (!reader.IsDBNull(6)) mh.Created = reader.GetDateTime(6); + + result.Add(mh); + } + reader.Close(); + return result; + } + + List IDatabaseEntity.LoadList(IDataReader reader) + { + throw new NotImplementedException(); + } + + #endregion + } } diff --git a/nsw/Source/bsmd.database/PortArea.cs b/nsw/Source/bsmd.database/PortArea.cs index c7f8449c..4a2d6305 100644 --- a/nsw/Source/bsmd.database/PortArea.cs +++ b/nsw/Source/bsmd.database/PortArea.cs @@ -1,6 +1,10 @@ -using System; +// Copyright (c) 2015-2017 schick Informatik +// Description: + +using System; using System.Collections.Generic; using System.Data; +using Newtonsoft.Json; namespace bsmd.database { diff --git a/nsw/Source/bsmd.database/PortOfCallLast30Days.cs b/nsw/Source/bsmd.database/PortOfCallLast30Days.cs index 36ffcf7c..fb735d5e 100644 --- a/nsw/Source/bsmd.database/PortOfCallLast30Days.cs +++ b/nsw/Source/bsmd.database/PortOfCallLast30Days.cs @@ -12,14 +12,12 @@ using System.Data; using System.Text; using System.Data.SqlClient; using System.Collections.Generic; +using Newtonsoft.Json; namespace bsmd.database { public class PortOfCallLast30Days : DatabaseEntity, ISublistElement, ISublistContainer { - - private List poc30Crew = new List(); - public PortOfCallLast30Days() { this.tablename = "[dbo].[PortOfCallLast30Days]"; @@ -27,9 +25,10 @@ namespace bsmd.database #region Properties + [JsonIgnore] public MDH MDH { get; set; } - public List CrewJoinedShip { get { return this.poc30Crew; } } + public List CrewJoinedShip { get; private set; } = new List(); [ShowReport] [Validation2(ValidationCode.LOCODE)] [MaxLength(5)] @@ -48,11 +47,13 @@ namespace bsmd.database public string Identifier { get; set; } + [JsonIgnore] public string SublistCollectionKey { get { return "pocl30d"; } } /// /// Hilfsproperty, um eine kommaseparierte Liste von Crew (analog ANSW) im ENI-2 anzuzeigen, /// + [JsonIgnore] [ENI2Validation] public string CrewMembersJoinedText { @@ -272,7 +273,7 @@ namespace bsmd.database { PortOfCallLast30Days p30 = this.MemberwiseClone() as PortOfCallLast30Days; p30.id = null; - p30.poc30Crew = new List(); + p30.CrewJoinedShip = new List(); foreach (PortOfCallLast30DaysCrewJoinedShip p30Crew in this.CrewJoinedShip) { diff --git a/nsw/Source/bsmd.database/PortOfCallLast30DaysCrewJoinedShip.cs b/nsw/Source/bsmd.database/PortOfCallLast30DaysCrewJoinedShip.cs index 4ffc224b..c2d384d8 100644 --- a/nsw/Source/bsmd.database/PortOfCallLast30DaysCrewJoinedShip.cs +++ b/nsw/Source/bsmd.database/PortOfCallLast30DaysCrewJoinedShip.cs @@ -11,6 +11,7 @@ using System; using System.Data; using System.Data.SqlClient; using System.Collections.Generic; +using Newtonsoft.Json; namespace bsmd.database { @@ -24,6 +25,7 @@ namespace bsmd.database #region Properties + [JsonIgnore] public PortOfCallLast30Days PortOfCallLast30Days { get; set; } [ShowReport] @@ -34,6 +36,7 @@ namespace bsmd.database public string Identifier { get; set; } + [JsonIgnore] public string SublistCollectionKey { get { return "pocl30dcjs"; } } #endregion diff --git a/nsw/Source/bsmd.database/PortOfItinerary.cs b/nsw/Source/bsmd.database/PortOfItinerary.cs index f82630f2..aa9ff25e 100644 --- a/nsw/Source/bsmd.database/PortOfItinerary.cs +++ b/nsw/Source/bsmd.database/PortOfItinerary.cs @@ -11,6 +11,7 @@ using System; using System.Data; using System.Data.SqlClient; using System.Collections.Generic; +using Newtonsoft.Json; namespace bsmd.database { @@ -24,6 +25,7 @@ namespace bsmd.database #region Properties + [JsonIgnore] public BPOL BPOL { get; set; } [ShowReport] @@ -43,6 +45,7 @@ namespace bsmd.database public string Identifier { get; set; } + [JsonIgnore] public string SublistCollectionKey { get { return "poi"; } } #endregion diff --git a/nsw/Source/bsmd.database/ReportingParty.cs b/nsw/Source/bsmd.database/ReportingParty.cs index 417c2083..c2d6bf5b 100644 --- a/nsw/Source/bsmd.database/ReportingParty.cs +++ b/nsw/Source/bsmd.database/ReportingParty.cs @@ -11,16 +11,15 @@ namespace bsmd.database { public class ReportingParty : DatabaseEntity { - private DateTime? _created, _changed; + + #region Enums public enum LogonResult { OK, FAILED, USERUKN - } - - #region enumerations + } public enum ReportingPartyTypeEnum { MASTER, SHIPOWNER, CHARTERER, AGENT, PORT_AUTHORITY, CARRIER, OTHERS } @@ -99,6 +98,11 @@ namespace bsmd.database public ReportingPartyTypeEnum? ReportingPartyType { get; set; } + /// + /// Reference to current user (for data history) + /// + public static ReportingParty CurrentReportingParty { get; set; } + #endregion #region ENI Logon User Properties @@ -124,9 +128,9 @@ namespace bsmd.database /// public string Salt { get; set; } - public DateTime? Created { get { return _created; } } + public DateTime? Created { get; private set; } - public DateTime? Changed { get { return _changed; } } + public DateTime? Changed { get; private set; } public int Flags { get; set; } @@ -249,8 +253,8 @@ namespace bsmd.database if (!reader.IsDBNull(11)) rp.Logon = reader.GetString(11); if (!reader.IsDBNull(12)) rp.PasswordHash = reader.GetString(12); if (!reader.IsDBNull(13)) rp.Salt = reader.GetGuid(13).ToString(); - if (!reader.IsDBNull(14)) rp._created = reader.GetDateTime(14); - if (!reader.IsDBNull(15)) rp._changed = reader.GetDateTime(15); + if (!reader.IsDBNull(14)) rp.Created = reader.GetDateTime(14); + if (!reader.IsDBNull(15)) rp.Changed = reader.GetDateTime(15); if (!reader.IsDBNull(16)) rp.Flags = reader.GetInt32(16); if (!reader.IsDBNull(17)) rp.Deleted = reader.GetInt32(17); if (!reader.IsDBNull(18)) rp.UserEMail = reader.GetString(18); diff --git a/nsw/Source/bsmd.database/SanitaryMeasuresDetail.cs b/nsw/Source/bsmd.database/SanitaryMeasuresDetail.cs index 3bf163d1..d65e11f8 100644 --- a/nsw/Source/bsmd.database/SanitaryMeasuresDetail.cs +++ b/nsw/Source/bsmd.database/SanitaryMeasuresDetail.cs @@ -12,6 +12,7 @@ using System; using System.Collections.Generic; using System.Data.SqlClient; using System.Data; +using Newtonsoft.Json; namespace bsmd.database { @@ -25,6 +26,7 @@ namespace bsmd.database #region Properties + [JsonIgnore] public MDH MDH { get; set; } [ShowReport] @@ -45,6 +47,7 @@ namespace bsmd.database public string Identifier { get; set; } + [JsonIgnore] public string SublistCollectionKey { get { return "smd"; } } #endregion diff --git a/nsw/Source/bsmd.database/ShipToShipActivitiesDuringLastTenPortFacilitiesCalled.cs b/nsw/Source/bsmd.database/ShipToShipActivitiesDuringLastTenPortFacilitiesCalled.cs index 67959bb3..2ce4267e 100644 --- a/nsw/Source/bsmd.database/ShipToShipActivitiesDuringLastTenPortFacilitiesCalled.cs +++ b/nsw/Source/bsmd.database/ShipToShipActivitiesDuringLastTenPortFacilitiesCalled.cs @@ -11,6 +11,7 @@ using System; using System.Data; using System.Data.SqlClient; using System.Collections.Generic; +using Newtonsoft.Json; namespace bsmd.database { @@ -24,6 +25,7 @@ namespace bsmd.database #region Properties + [JsonIgnore] public SEC SEC { get; set; } [ShowReport] @@ -71,6 +73,7 @@ namespace bsmd.database public string Identifier { get; set; } + [JsonIgnore] public string SublistCollectionKey { get { return "s2s"; } } #endregion diff --git a/nsw/Source/bsmd.database/StowawaysJoiningLocation.cs b/nsw/Source/bsmd.database/StowawaysJoiningLocation.cs index 2ed3dd2a..8accc63f 100644 --- a/nsw/Source/bsmd.database/StowawaysJoiningLocation.cs +++ b/nsw/Source/bsmd.database/StowawaysJoiningLocation.cs @@ -12,6 +12,7 @@ using System; using System.Collections.Generic; using System.Data.SqlClient; using System.Data; +using Newtonsoft.Json; namespace bsmd.database { @@ -25,6 +26,7 @@ namespace bsmd.database #region Properties + [JsonIgnore] public MDH MDH { get; set; } [ShowReport] @@ -35,6 +37,7 @@ namespace bsmd.database public string Identifier { get; set; } + [JsonIgnore] public string SublistCollectionKey { get { return "stowaways"; } } #endregion diff --git a/nsw/Source/bsmd.database/SubsidiaryRisks.cs b/nsw/Source/bsmd.database/SubsidiaryRisks.cs index 06b58d97..8f0463e5 100644 --- a/nsw/Source/bsmd.database/SubsidiaryRisks.cs +++ b/nsw/Source/bsmd.database/SubsidiaryRisks.cs @@ -11,6 +11,7 @@ using System; using System.Collections.Generic; using System.Data; using System.Data.SqlClient; +using Newtonsoft.Json; namespace bsmd.database { @@ -24,6 +25,7 @@ namespace bsmd.database #region Properties + [JsonIgnore] public IMDGPosition IMDGPosition { get; set; } [ShowReport] @@ -33,6 +35,7 @@ namespace bsmd.database public string Identifier { get; set; } + [JsonIgnore] public string SublistCollectionKey { get { return "subsidiaryrisks"; } } #endregion diff --git a/nsw/Source/bsmd.database/Waste.cs b/nsw/Source/bsmd.database/Waste.cs index f711ff0e..1618c6f5 100644 --- a/nsw/Source/bsmd.database/Waste.cs +++ b/nsw/Source/bsmd.database/Waste.cs @@ -9,6 +9,7 @@ using System.Data.SqlClient; using System.Collections.Generic; +using Newtonsoft.Json; namespace bsmd.database { @@ -22,8 +23,10 @@ namespace bsmd.database #region Properties + [JsonIgnore] public WAS WAS { get; set; } + [JsonIgnore] [ShowReport] public string WasteTypeDisplay { @@ -47,6 +50,7 @@ namespace bsmd.database } [ShowReport] + [JsonIgnore] public string WasteTypeDisplayV4 { get @@ -75,6 +79,7 @@ namespace bsmd.database } } + [JsonIgnore] public string WasteTypeDisplayGrid { get @@ -122,8 +127,10 @@ namespace bsmd.database public string Identifier { get; set; } + [JsonIgnore] public string SublistCollectionKey { get { return "waste"; } } + [JsonIgnore] public bool HasValidWasteCode { get diff --git a/nsw/Source/bsmd.database/WasteDisposalServiceProvider.cs b/nsw/Source/bsmd.database/WasteDisposalServiceProvider.cs index 2aa008a0..3bbdb06f 100644 --- a/nsw/Source/bsmd.database/WasteDisposalServiceProvider.cs +++ b/nsw/Source/bsmd.database/WasteDisposalServiceProvider.cs @@ -11,6 +11,7 @@ using System; using System.Data; using System.Data.SqlClient; using System.Collections.Generic; +using Newtonsoft.Json; namespace bsmd.database { @@ -24,6 +25,7 @@ namespace bsmd.database #region Properties + [JsonIgnore] public WAS WAS { get; set; } [ShowReport] @@ -33,10 +35,12 @@ namespace bsmd.database public string WasteDisposalServiceProviderName { get; set; } [Obsolete] + [JsonIgnore] public byte? WasteDisposalDelivery { get; set; } public string Identifier { get; set; } + [JsonIgnore] public string SublistCollectionKey { get { return "wdsp"; } } #endregion diff --git a/nsw/Source/bsmd.database/bsmd.database.csproj b/nsw/Source/bsmd.database/bsmd.database.csproj index 7db99649..d4f21d48 100644 --- a/nsw/Source/bsmd.database/bsmd.database.csproj +++ b/nsw/Source/bsmd.database/bsmd.database.csproj @@ -44,6 +44,9 @@ ..\..\..\ENI-2\ENI2\ENI2\packages\log4net.2.0.8\lib\net45-full\log4net.dll True + + ..\..\..\ENI-2\ENI2\ENI2\packages\Newtonsoft.Json.12.0.2\lib\net45\Newtonsoft.Json.dll + @@ -65,6 +68,7 @@ + diff --git a/nsw/Source/bsmd.database/packages.config b/nsw/Source/bsmd.database/packages.config index 9a0551c5..82cbcac8 100644 --- a/nsw/Source/bsmd.database/packages.config +++ b/nsw/Source/bsmd.database/packages.config @@ -1,4 +1,5 @@  + \ No newline at end of file