// // Class: SEC // Current CLR: 4.0.30319.34209 // System: Microsoft Visual Studio 10.0 // Author: dani // Created: 4/3/2015 10:11:02 AM // // Copyright (c) 2015 Informatikbüro Daniel Schick. All rights reserved. using System; using System.Data; using System.Data.SqlClient; using System.Collections.Generic; namespace bsmd.database { public class SEC : DatabaseEntity, ISublistContainer { private List ltpfc = new List(); private List lsts = new List(); public SEC() { this.tablename = "[dbo].[SEC]"; } #region Properties [ShowReport] [Validation1(ValidationCode.NOT_NULL)] public bool? SECSimplification { get; set; } [ShowReport] [Validation1(ValidationCode.LOCODE_GER)] [MaxLength(5)] public string PortOfCallWhereCompleteSECNotified { get; set; } [ShowReport] [Validation2(ValidationCode.NOT_NULL)] [LookupName("SEC.CSOLastName")] [MaxLength(100)] public string CSOLastName { get; set; } [ShowReport] [LookupName("SEC.CSOFirstName")] [MaxLength(100)] public string CSOFirstName { get; set; } [ShowReport] [Validation2(ValidationCode.NOT_NULL)] [LookupName("SEC.CSOPhone")] [MaxLength(100)] public string CSOPhone { get; set; } [ShowReport] [LookupName("SEC.CSOFax")] [MaxLength(100)] public string CSOFax { get; set; } [ShowReport] [LookupName("SEC.CSOEMail")] [MaxLength(100)] public string CSOEMail { get; set; } [ShowReport] [Validation2(ValidationCode.NOT_NULL)] [LookupName("SEC.ValidISSCOnBoard")] public bool? ValidISSCOnBoard { get; set; } [ShowReport] [LookupName("SEC.ReasonsForNoValidISSC")] [MaxLength(255)] public string ReasonsForNoValidISSC { get; set; } [Validation2(ValidationCode.NOT_NULL)] public byte? ISSCType { get; set; } [ShowReport] [ReportDisplayName("ISSC type")] public string ISSCTypeDisplay { get { return Util.GetISSCTypeDisplay(this.ISSCType); } } [Validation2(ValidationCode.NOT_NULL)] // [LookupName("SEC.ISSCIssuerType")] // wird manuell gescannt und konvertiert public byte? ISSCIssuerType { get; set; } [ShowReport] [ReportDisplayName("ISSC issuer type")] public string ISSCIssuerTypeDisplay { get { return Util.GetISSCIssuerTypeDisplay(this.ISSCIssuerType); } } [ShowReport] [Validation2(ValidationCode.NOT_NULL)] [LookupName("SEC.ISSCIssuerName")] [MaxLength(100)] public string ISSCIssuerName { get; set; } [ShowReport] [Validation2(ValidationCode.NOT_NULL)] [LookupName("SEC.ISSCDateOfExpiration")] public DateTime? ISSCDateOfExpiration { get; set; } [ShowReport] [Validation2(ValidationCode.NOT_NULL)] [LookupName("SEC.ApprovedSecurityPlanOnBoard")] public bool? ApprovedSecurityPlanOnBoard { get; set; } [ShowReport] [Validation(ValidationCode.NOT_NULL)] public byte? CurrentShipSecurityLevel { get; set; } [ShowReport] [MaxLength(100)] public string PortFacilityOfArrival { get; set; } [ShowReport] [Validation2(ValidationCode.NOT_NULL)] public byte? GeneralDescriptionOfCargo { get; set; } [LookupName("SEC.MatterToReport")] [MaxLength(1024)] public string MatterToReport { get; set; } public bool? KielCanalPassagePlanned { get; set; } public DateTime? KielCanalPassagePlannedIncomming { get; set; } public DateTime? KielCanalPassagePlannedOutgoing { get; set; } public List LastTenPortFacilitesCalled { get { return this.ltpfc; } } public List ShipToShipActivitiesDuringLastTenPortFacilitiesCalled { get { return this.lsts; } } #endregion #region DatabaseEntity implementation public override void PrepareSave(System.Data.IDbCommand cmd) { SqlCommand scmd = cmd as SqlCommand; scmd.Parameters.AddWithValue("@P1", this.MessageHeader.Id); scmd.Parameters.AddWithNullableValue("@P2", this.SECSimplification); scmd.Parameters.AddWithNullableValue("@P3", this.PortOfCallWhereCompleteSECNotified); scmd.Parameters.AddWithNullableValue("@P4", this.CSOLastName); scmd.Parameters.AddWithNullableValue("@P5", this.CSOFirstName); scmd.Parameters.AddWithNullableValue("@P6", this.CSOPhone); scmd.Parameters.AddWithNullableValue("@P7", this.CSOEMail); scmd.Parameters.AddWithNullableValue("@P8", this.ValidISSCOnBoard); scmd.Parameters.AddWithNullableValue("@P9", this.ReasonsForNoValidISSC); scmd.Parameters.AddWithNullableValue("@P10", this.ISSCType); scmd.Parameters.AddWithNullableValue("@P11", this.ISSCIssuerType); scmd.Parameters.AddWithNullableValue("@P12", this.ISSCIssuerName); scmd.Parameters.AddWithNullableValue("@P13", this.ISSCDateOfExpiration); scmd.Parameters.AddWithNullableValue("@P14", this.ApprovedSecurityPlanOnBoard); scmd.Parameters.AddWithNullableValue("@P15", this.CurrentShipSecurityLevel); scmd.Parameters.AddWithNullableValue("@P16", this.PortFacilityOfArrival); scmd.Parameters.AddWithNullableValue("@P17", this.GeneralDescriptionOfCargo); scmd.Parameters.AddWithNullableValue("@P18", this.CSOFax); scmd.Parameters.AddWithNullableValue("@P19", this.MatterToReport); scmd.Parameters.AddWithNullableValue("@P20", this.KielCanalPassagePlanned); scmd.Parameters.AddWithNullableValue("@P21", this.KielCanalPassagePlannedIncomming); scmd.Parameters.AddWithNullableValue("@P22", this.KielCanalPassagePlannedOutgoing); if (this.IsNew) { this.CreateId(); scmd.Parameters.AddWithValue("@ID", this.Id); scmd.CommandText = string.Format("INSERT INTO {0} (Id, MessageHeaderId, SECSimplification, PortOfCallWhereCompleteSECNotified, " + "CSOLastName, CSOFirstName, CSOPhone, CSOEMail, ValidISSCOnBoard, ReasonsForNoValidISSC, " + "ISSCType, ISSCIssuerType, ISSCIssuerName,ISSCDateOfExpiration, ApprovedSecurityPlanOnBoard, " + "CurrentShipSecurityLevel, PortFacilityOfArrival, GeneralDescriptionOfCargo, CSOFax, MatterToReport, " + "KielCanalPassagePlanned, KielCanalPassagePlannedIncomming, KielCanalPassagePlannedOutgoing) " + "VALUES ( @ID, @P1, @P2, @P3, @P4, @P5, @P6, @P7, @P8, @P9, @P10, @P11, @P12, @P13, @P14, @P15, @P16, " + "@P17, @P18, @P19, @P20, @P21, @P22 )", this.Tablename); } else { scmd.Parameters.AddWithValue(@"ID", this.Id); scmd.CommandText = string.Format("UPDATE {0} SET SECSimplification = @P2, PortOfCallWhereCompleteSECNotified = @P3, " + "CSOLastName = @P4, CSOFirstName = @P5, CSOPhone = @P6," + "CSOEMail = @P7, ValidISSCOnBoard = @P8, ReasonsForNoValidISSC = @P9, " + "ISSCType = @P10, ISSCIssuerType = @P11, ISSCIssuerName = @P12, ISSCDateOfExpiration = @P13, " + "ApprovedSecurityPlanOnBoard = @P14, CurrentShipSecurityLevel = @P15, PortFacilityOfArrival = @P16, " + "GeneralDescriptionOfCargo = @P17, CSOFax = @P18, MatterToReport = @P19, KielCanalPassagePlanned = @P20, " + "KielCanalPassagePlannedIncomming = @P21, KielCanalPassagePlannedOutgoing = @P22 WHERE Id = @ID", this.Tablename); } } public override void PrepareLoadCommand(System.Data.IDbCommand cmd, Message.LoadFilter filter, params object[] criteria) { string query = string.Format("SELECT Id, SECSimplification, PortOfCallWhereCompleteSECNotified, CSOLastName, " + "CSOFirstName, CSOPhone, CSOEMail, ValidISSCOnBoard, ReasonsForNoValidISSC, " + "ISSCType, ISSCIssuerType, ISSCIssuerName, ISSCDateOfExpiration, ApprovedSecurityPlanOnBoard, " + "CurrentShipSecurityLevel, PortFacilityOfArrival, GeneralDescriptionOfCargo, CSOFax, MatterToReport, " + "KielCanalPassagePlanned, KielCanalPassagePlannedIncomming, KielCanalPassagePlannedOutgoing FROM {0}", this.Tablename); switch (filter) { case Message.LoadFilter.MESSAGEHEADER: query += "WHERE MessageHeaderId = @MHID"; ((SqlCommand)cmd).Parameters.AddWithValue("@MHID", criteria[0]); break; case Message.LoadFilter.ALL: default: break; } cmd.CommandText = query; } public override List LoadList(System.Data.IDataReader reader) { List result = new List(); while (reader.Read()) { SEC sec = new SEC(); sec.id = reader.GetGuid(0); if (!reader.IsDBNull(1)) sec.SECSimplification = reader.GetBoolean(1); if (!reader.IsDBNull(2)) sec.PortOfCallWhereCompleteSECNotified = reader.GetString(2); if (!reader.IsDBNull(3)) sec.CSOLastName = reader.GetString(3); if (!reader.IsDBNull(4)) sec.CSOFirstName = reader.GetString(4); if (!reader.IsDBNull(5)) sec.CSOPhone = reader.GetString(5); if (!reader.IsDBNull(6)) sec.CSOEMail = reader.GetString(6); if (!reader.IsDBNull(7)) sec.ValidISSCOnBoard = reader.GetBoolean(7); if (!reader.IsDBNull(8)) sec.ReasonsForNoValidISSC = reader.GetString(8); if (!reader.IsDBNull(9)) sec.ISSCType = reader.GetByte(9); if (!reader.IsDBNull(10)) sec.ISSCIssuerType = reader.GetByte(10); if (!reader.IsDBNull(11)) sec.ISSCIssuerName = reader.GetString(11); if (!reader.IsDBNull(12)) sec.ISSCDateOfExpiration = reader.GetDateTime(12); if (!reader.IsDBNull(13)) sec.ApprovedSecurityPlanOnBoard = reader.GetBoolean(13); if (!reader.IsDBNull(14)) sec.CurrentShipSecurityLevel = reader.GetByte(14); if (!reader.IsDBNull(15)) sec.PortFacilityOfArrival = reader.GetString(15); if (!reader.IsDBNull(16)) sec.GeneralDescriptionOfCargo = reader.GetByte(16); if (!reader.IsDBNull(17)) sec.CSOFax = reader.GetString(17); if (!reader.IsDBNull(18)) sec.MatterToReport = reader.GetString(18); if (!reader.IsDBNull(19)) sec.KielCanalPassagePlanned = reader.GetBoolean(19); if (!reader.IsDBNull(20)) sec.KielCanalPassagePlannedIncomming = reader.GetDateTime(20); if (!reader.IsDBNull(21)) sec.KielCanalPassagePlannedOutgoing = reader.GetDateTime(21); result.Add(sec); } reader.Close(); return result; } #endregion #region sublist lookup implementation public LastTenPortFacilitiesCalled GetPortFacilityWithIdentifier(string identifier) { foreach(ISublistElement lp in this.ltpfc) { if (lp.Identifier.Equals(identifier)) return lp as LastTenPortFacilitiesCalled; } return null; } public ShipToShipActivitiesDuringLastTenPortFacilitiesCalled GetShipToShipWithIdentifier(string identifier) { foreach (ISublistElement lp in this.lsts) { if (lp.Identifier.Equals(identifier)) return lp as ShipToShipActivitiesDuringLastTenPortFacilitiesCalled; } return null; } #endregion #region IMessageParagraph implementation public override string Subtitle { get { return "Sea security notification"; } } public override List ChildParagraphs { get { List result = new List(); foreach (IMessageParagraph imp in this.LastTenPortFacilitesCalled) result.Add(imp); foreach (IMessageParagraph imp in this.ShipToShipActivitiesDuringLastTenPortFacilitiesCalled) result.Add(imp); return result; } } int ISublistContainer.NumberOfExcelRows { get { return 1; } } #endregion #region Validation public override DatabaseEntity.ValidationBlock GetValidationBlock() { return (this.SECSimplification ?? false) ? DatabaseEntity.ValidationBlock.BLOCK1 : DatabaseEntity.ValidationBlock.BLOCK2; } public override void Validate(List errors, List violations) { if (this.GetValidationBlock() == ValidationBlock.BLOCK1) { if (this.PortOfCallWhereCompleteSECNotified.IsNullOrEmpty()) violations.Add(RuleEngine.CreateViolation(ValidationCode.V704, "PortOfCallWhereCompleteSECNotified", null)); } else { if((!this.ValidISSCOnBoard ?? true) && this.ReasonsForNoValidISSC.IsNullOrEmpty()) violations.Add(RuleEngine.CreateViolation(ValidationCode.V702, "Reasons missing", null)); } foreach (LastTenPortFacilitiesCalled L10Called in this.LastTenPortFacilitesCalled) { RuleEngine.ValidateProperties(L10Called, errors); L10Called.Validate(errors, violations); } foreach(ShipToShipActivitiesDuringLastTenPortFacilitiesCalled s2s in this.ShipToShipActivitiesDuringLastTenPortFacilitiesCalled) { RuleEngine.ValidateProperties(s2s, errors); s2s.Validate(errors, violations); } } ISublistElement ISublistContainer.GetSublistElementWithIdentifier(string identifier) { // sinnlos, weil es zwei sublisten gibt foreach (ISublistElement sElem in this.LastTenPortFacilitesCalled) { if (sElem.Identifier.Equals(identifier)) return sElem; } return null; } void ISublistContainer.SaveElements() { foreach (LastTenPortFacilitiesCalled l10c in this.LastTenPortFacilitesCalled) DBManager.Instance.Save(l10c); foreach(ShipToShipActivitiesDuringLastTenPortFacilitiesCalled s2s in this.ShipToShipActivitiesDuringLastTenPortFacilitiesCalled) DBManager.Instance.Save(s2s); } void ISublistContainer.DeleteElements() { foreach (LastTenPortFacilitiesCalled l10c in this.LastTenPortFacilitesCalled) DBManager.Instance.Delete(l10c); foreach (ShipToShipActivitiesDuringLastTenPortFacilitiesCalled s2s in this.ShipToShipActivitiesDuringLastTenPortFacilitiesCalled) DBManager.Instance.Delete(s2s); } #endregion } }