//
// Class: PAS
// Current CLR: 4.0.30319.34209
// System: Microsoft Visual Studio 10.0
// Author: dani
// Created: 4/2/2015 8:36:42 PM
//
// Copyright (c) 2015 Informatikbüro Daniel Schick. All rights reserved.
using System;
using System.Data;
using System.Data.SqlClient;
using System.Collections.Generic;
using System.Linq;
namespace bsmd.database
{
public class PAS : DatabaseEntity, ISublistElement, IBulkSaver
{
#region Construction
public PAS()
{
this.tablename = "[dbo].[PAS]";
}
#endregion
#region Properties
[ShowReport]
[ReportDisplayName("Last name")]
[Validation(ValidationCode.NOT_NULL)]
[MaxLength(100)]
[ENI2Validation]
public string PassengerLastName { get; set; }
[ShowReport]
[ReportDisplayName("First name")]
[Validation(ValidationCode.NOT_NULL)]
[MaxLength(100)]
[ENI2Validation]
public string PassengerFirstName { get; set; }
[ShowReport]
[ReportDisplayName("Place of birth")]
[MaxLength(100)]
[ENI2Validation]
public string PassengerPlaceOfBirth { get; set; }
[Validation(ValidationCode.NOT_NULL)]
[ENI2Validation]
public DateTime? PassengerDateOfBirth { get; set; }
[ShowReport]
[ReportDisplayName("Date of birth")]
public string PassengerDateOfBirthDisplay
{
get
{
if (this.PassengerDateOfBirth.HasValue)
return this.PassengerDateOfBirth.Value.ToShortDateString();
return string.Empty;
}
}
[ENI2Validation]
public byte? PassengerGender { get; set; }
[ShowReport]
[ReportDisplayName("Gender")]
public string PassengerGenderDisplay { get { return Util.GetGenderDisplay(this.PassengerGender); } }
[ShowReport]
[ReportDisplayName("Nationality")]
[Validation(ValidationCode.FLAG_CODE)]
[MaxLength(2)]
[ENI2Validation]
public string PassengerNationality { get; set; }
[Validation(ValidationCode.NOT_NULL)]
[ENI2Validation]
public byte? PassengerIdentityDocumentType { get; set; }
[ShowReport]
[ReportDisplayName("Identity document type")]
public string PassengerIdentityDocumentTypeDisplay { get { return Util.GetIdentityDocumentTypeDisplay(this.PassengerIdentityDocumentType); } }
[ShowReport]
[ReportDisplayName("Identity document id")]
[Validation(ValidationCode.NOT_NULL)]
[MaxLength(100)]
[ENI2Validation]
public string PassengerIdentityDocumentId { get; set; }
[ShowReport]
[ReportDisplayName("Visa number")]
[MaxLength(100)]
[ENI2Validation]
public string PassengerVisaNumber { get; set; }
[ShowReport]
[ReportDisplayName("Port of embarkation")]
[Validation(ValidationCode.LOCODE)]
[MaxLength(5)]
[ENI2Validation]
public string PassengerPortOfEmbarkation { get; set; }
[ShowReport]
[ReportDisplayName("Port of disembarkation")]
[Validation(ValidationCode.LOCODE)]
[MaxLength(5)]
[ENI2Validation]
public string PassengerPortOfDisembarkation { get; set; }
[ShowReport]
[ReportDisplayName("In transit")]
[Validation(ValidationCode.NOT_NULL)]
[ENI2Validation]
public bool? PassengerInTransit { get; set; } = false;
[ShowReport]
[ReportDisplayName("Issuing state")]
[Validation(ValidationCode.FLAG_CODE)]
[ENI2Validation]
public string PassengerIdentityDocumentIssuingState { get; set; }
[Validation(ValidationCode.PAST_DATE)]
[ENI2Validation]
public DateTime? PassengerIdentityDocumentExpiryDate { get; set; }
[ShowReport]
[ReportDisplayName("Expiry date")]
public string PassengerIdentityDocumentExpiryDateDisplay
{
get
{
if (this.PassengerIdentityDocumentExpiryDate.HasValue)
return this.PassengerIdentityDocumentExpiryDate.Value.ToShortDateString();
return string.Empty;
}
}
[ENI2Validation]
public bool? NotificationSchengen { get; set; }
[ENI2Validation]
public bool? NotificationPAX { get; set; }
[MaxLength(2)]
[ENI2Validation]
public string PassengerCountryOfBirth { get; set; }
[ENI2Validation]
[ReportDisplayName("Emergency care")]
[MaxLength(255)]
public string EmergencyCare { get; set; }
[ENI2Validation]
[ReportDisplayName("Emergency contact number")]
[MaxLength(99)]
public string EmergencyContactNumber { get; set; }
///
/// Helper property for validation
///
public bool HasSchengenDetails
{
get
{
return PassengerIdentityDocumentType.HasValue && !PassengerIdentityDocumentId.IsNullOrEmpty() && !PassengerIdentityDocumentIssuingState.IsNullOrEmpty() &&
PassengerIdentityDocumentExpiryDate.HasValue && !PassengerPortOfEmbarkation.IsNullOrEmpty() && !PassengerPortOfDisembarkation.IsNullOrEmpty();
}
}
///
/// Helper property for validation
///
public bool HasPAXDetails
{
get
{
return !EmergencyCare.IsNullOrEmpty() && !EmergencyContactNumber.IsNullOrEmpty();
}
}
public string Identifier { get; set; }
public string SublistCollectionKey { get { return "pas"; } }
[ENI2Validation]
public bool IsDeparture { get; set; }
public override string Subtitle
{
get
{
return "Passenger information";
}
}
#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.PassengerLastName);
scmd.Parameters.AddWithNullableValue("@P3", this.PassengerFirstName);
scmd.Parameters.AddWithNullableValue("@P4", this.PassengerPlaceOfBirth);
scmd.Parameters.AddWithNullableValue("@P5", this.PassengerDateOfBirth);
scmd.Parameters.AddWithNullableValue("@P6", this.PassengerGender);
scmd.Parameters.AddWithNullableValue("@P7", this.PassengerNationality);
scmd.Parameters.AddWithNullableValue("@P8", this.PassengerIdentityDocumentType);
scmd.Parameters.AddWithNullableValue("@P9", this.PassengerIdentityDocumentId);
scmd.Parameters.AddWithNullableValue("@P10", this.PassengerVisaNumber);
scmd.Parameters.AddWithNullableValue("@P11", this.PassengerPortOfEmbarkation);
scmd.Parameters.AddWithNullableValue("@P12", this.PassengerPortOfDisembarkation);
scmd.Parameters.AddWithNullableValue("@P13", this.PassengerInTransit);
scmd.Parameters.AddWithNullableValue("@P14", this.Identifier);
scmd.Parameters.AddWithValue("@P15", this.IsDeparture);
scmd.Parameters.AddWithNullableValue("@P16", this.PassengerIdentityDocumentIssuingState);
scmd.Parameters.AddWithNullableValue("@P17", this.PassengerIdentityDocumentExpiryDate);
scmd.Parameters.AddWithNullableValue("@P18", this.NotificationSchengen);
scmd.Parameters.AddWithNullableValue("@P19", this.NotificationPAX);
scmd.Parameters.AddWithNullableValue("@P20", this.EmergencyCare);
scmd.Parameters.AddWithNullableValue("@P21", this.EmergencyContactNumber);
scmd.Parameters.AddWithNullableValue("@P22", this.PassengerCountryOfBirth);
if (this.IsNew)
{
this.CreateId();
scmd.Parameters.AddWithValue("@ID", this.Id);
scmd.CommandText = string.Format("INSERT INTO {0} (Id, MessageHeaderId, PassengerLastName, PassengerFirstName, " +
"PassengerPlaceOfBirth, PassengerDateOfBirth, PassengerGender, PassengerNationality, PassengerIdentityDocumentType, " +
"PassengerIdentityDocumentId, PassengerVisaNumber, PassengerPortOfEmbarkation, PassengerPortOfDisembarkation," +
"PassengerInTransit, Identifier, IsDeparture, PassengerIdentityDocumentIssuingState, PassengerIdentityDocumentExpiryDate, " +
"NotificationSchengen, NotificationPAX, EmergencyCare, EmergencyContactNumber, PassengerCountryOfBirth) " +
"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 PassengerLastName = @P2, PassengerFirstName = @P3, " +
"PassengerPlaceOfBirth = @P4, PassengerDateOfBirth = @P5, PassengerGender = @P6," +
"PassengerNationality = @P7, PassengerIdentityDocumentType = @P8, PassengerIdentityDocumentId = @P9, " +
"PassengerVisaNumber = @P10, PassengerPortOfEmbarkation = @P11, PassengerPortOfDisembarkation = @P12, " +
"PassengerInTransit = @P13, IsDeparture = @P15, Identifier = @P14, PassengerIdentityDocumentIssuingState = @P16, " +
"PassengerIdentityDocumentExpiryDate = @P17, NotificationSchengen = @P18, NotificationPAX = @P19, " +
"EmergencyCare = @P20, EmergencyContactNumber = @P21, PassengerCountryOfBirth = @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, PassengerLastName, PassengerFirstName, PassengerPlaceOfBirth, " +
"PassengerDateOfBirth, PassengerGender, PassengerNationality, PassengerIdentityDocumentType, PassengerIdentityDocumentId, " +
"PassengerVisaNumber, PassengerPortOfEmbarkation, PassengerPortOfDisembarkation, PassengerInTransit, Identifier, " +
"IsDeparture, PassengerIdentityDocumentIssuingState, PassengerIdentityDocumentExpiryDate, NotificationSchengen, " +
"NotificationPAX, EmergencyCare, EmergencyContactNumber, PassengerCountryOfBirth FROM {0}",
this.Tablename);
switch (filter)
{
case Message.LoadFilter.MESSAGEHEADER:
query += " WHERE IsDeparture = 0 AND MessageHeaderId = @MHID";
((SqlCommand)cmd).Parameters.AddWithValue("@MHID", criteria[0]);
break;
case Message.LoadFilter.ALL:
default:
query += " WHERE IsDeparture = 0";
break;
}
cmd.CommandText = query;
}
public override List LoadList(System.Data.IDataReader reader)
{
List result = new List();
while (reader.Read())
{
PAS pas = new PAS();
pas.id = reader.GetGuid(0);
if (!reader.IsDBNull(1)) pas.PassengerLastName = reader.GetString(1);
if (!reader.IsDBNull(2)) pas.PassengerFirstName = reader.GetString(2);
if (!reader.IsDBNull(3)) pas.PassengerPlaceOfBirth = reader.GetString(3);
if (!reader.IsDBNull(4)) pas.PassengerDateOfBirth = reader.GetDateTime(4);
if (!reader.IsDBNull(5)) pas.PassengerGender = reader.GetByte(5);
if (!reader.IsDBNull(6)) pas.PassengerNationality = reader.GetString(6);
if (!reader.IsDBNull(7)) pas.PassengerIdentityDocumentType = reader.GetByte(7);
if (!reader.IsDBNull(8)) pas.PassengerIdentityDocumentId = reader.GetString(8);
if (!reader.IsDBNull(9)) pas.PassengerVisaNumber = reader.GetString(9);
if (!reader.IsDBNull(10)) pas.PassengerPortOfEmbarkation = reader.GetString(10);
if (!reader.IsDBNull(11)) pas.PassengerPortOfDisembarkation = reader.GetString(11);
if (!reader.IsDBNull(12)) pas.PassengerInTransit = reader.GetBoolean(12);
if (!reader.IsDBNull(13)) pas.Identifier = reader.GetString(13);
if (!reader.IsDBNull(14)) pas.IsDeparture = reader.GetBoolean(14);
if (!reader.IsDBNull(15)) pas.PassengerIdentityDocumentIssuingState = reader.GetString(15);
if (!reader.IsDBNull(16)) pas.PassengerIdentityDocumentExpiryDate = reader.GetDateTime(16);
if (!reader.IsDBNull(17)) pas.NotificationSchengen = reader.GetBoolean(17);
if (!reader.IsDBNull(18)) pas.NotificationPAX = reader.GetBoolean(18);
if (!reader.IsDBNull(19)) pas.EmergencyCare = reader.GetString(19);
if (!reader.IsDBNull(20)) pas.EmergencyContactNumber = reader.GetString(20);
if (!reader.IsDBNull(21)) pas.PassengerCountryOfBirth = reader.GetString(21);
result.Add(pas);
}
reader.Close();
result.Sort();
return result;
}
public override string Title => "PASA";
#endregion
#region Validation
public override void Validate(List errors, List violations)
{
// /* Nach RM Christin / Trello vom 27.11.17 auskommentiert
// und heute (19.10.22) wieder einkommentiert
if (this.PassengerPortOfDisembarkation != null)
{
if (this.PassengerPortOfDisembarkation.Equals("ZZUKN"))
violations.Add(RuleEngine.CreateViolation(ValidationCode.NOT_NULL, "Port of disembarkation set to ZZUKN", null, this.Title, this.Identifier, this.IsDeparture ? "PASD" : "PASA"));
}
if (this.PassengerPortOfEmbarkation != null)
{
if (this.PassengerPortOfEmbarkation.Equals("ZZUKN"))
violations.Add(RuleEngine.CreateViolation(ValidationCode.NOT_NULL, "Port of embarkation set to ZZUKN", null, this.Title, this.Identifier, this.IsDeparture ? "PASD" : "PASA"));
}
if (this.PassengerIdentityDocumentType.HasValue)
{
if (this.PassengerIdentityDocumentType.Value == 5)
violations.Add(RuleEngine.CreateViolation(ValidationCode.IMPLAUSIBLE, "Doc. type set to OTHER_LEGAL_IDENTITY_DOCUMENT", null, this.Title, this.Identifier, this.IsDeparture ? "PASD" : "PASA"));
}
if (this.PassengerNationality != null)
{
if (this.PassengerNationality.Equals("XX"))
violations.Add(RuleEngine.CreateViolation(ValidationCode.IMPLAUSIBLE, "Nationality set to XX", null, this.Title, this.Identifier, this.IsDeparture ? "PASD" : "PASA"));
}
if (this.PassengerIdentityDocumentIssuingState != null)
{
if (this.PassengerIdentityDocumentIssuingState.Equals("XX"))
violations.Add(RuleEngine.CreateViolation(ValidationCode.IMPLAUSIBLE, "Id. doc issuing state set to XX", null, this.Title, this.Identifier, this.IsDeparture ? "PASD" : "PASA"));
}
if (this.PassengerIdentityDocumentExpiryDate.HasValue)
{
if (this.PassengerIdentityDocumentExpiryDate.Equals(new DateTime(2100, 12, 31)))
violations.Add(RuleEngine.CreateViolation(ValidationCode.IMPLAUSIBLE, "Id doc expiry date set to 31/12/2100", null, this.Title, this.Identifier, this.IsDeparture ? "PASD" : "PASA"));
if ((this.PassengerIdentityDocumentExpiryDate >= CREW.CLAMPMAXDATE) || (this.PassengerIdentityDocumentExpiryDate <= CREW.CLAMPMINDATE))
violations.Add(RuleEngine.CreateViolation(ValidationCode.IMPLAUSIBLE, "Check identity document expiry date", null, this.Title, this.Identifier, this.IsDeparture ? "PASD" : "PASA"));
}
if (this.PassengerGender.HasValue)
{
if (this.PassengerGender == 0)
violations.Add(RuleEngine.CreateViolation(ValidationCode.IMPLAUSIBLE, "Gender set to unknown", null, this.Title, this.Identifier, this.IsDeparture ? "PASD" : "PASA"));
}
if (this.PassengerDateOfBirth.HasValue)
{
if (this.PassengerDateOfBirth.Value > DateTime.Today)
violations.Add(RuleEngine.CreateViolation(ValidationCode.TIME_IMPLAUSIBLE, "Date of birth is in the future", null, this.Title, this.Identifier, this.IsDeparture ? "PASD" : "PASA"));
if (this.PassengerDateOfBirth <= CREW.CLAMPMINDATE)
violations.Add(RuleEngine.CreateViolation(ValidationCode.TIME_IMPLAUSIBLE, "Check date of birth", null, this.Title, this.Identifier, this.IsDeparture ? "PASD" : "PASA"));
}
// NSW 7.2 rules
if ((this.NotificationSchengen ?? false) && (!this.HasSchengenDetails))
{
errors.Add(RuleEngine.CreateError(ValidationCode.V202, "Schengen flag set but no data", null, this.Title, null, this.IsDeparture ? "PASD" : "PASA"));
}
if (!(this.NotificationSchengen ?? false) && (this.HasSchengenDetails))
{
errors.Add(RuleEngine.CreateError(ValidationCode.V202, "Schengen data given but flag not set", null, this.Title, null, this.IsDeparture ? "PASD" : "PASA"));
}
if ((this.NotificationPAX ?? false) && (!this.HasPAXDetails))
{
errors.Add(RuleEngine.CreateError(ValidationCode.V203, "PAX flag set but no data - emergency details", null, this.Title, null, this.IsDeparture ? "PASD" : "PASA"));
}
if (!(this.NotificationPAX ?? false) && (this.HasPAXDetails))
{
errors.Add(RuleEngine.CreateError(ValidationCode.V203, "PAX data given but flag not set", null, this.Title, null, this.IsDeparture ? "PASD" : "PASA"));
}
}
#endregion
#region IBulkSaver implementation
public DataTable PrepareBulkInsert(List databaseEntities)
{
DataTable result = new DataTable();
result.Columns.Add(new DataColumn { ColumnName = "MessageHeaderId", DataType = MessageHeader.Id.GetType() });
result.Columns.Add(new DataColumn { ColumnName = "PassengerLastName", DataType = typeof(string), AllowDBNull = true });
result.Columns.Add(new DataColumn { ColumnName = "PassengerFirstName", DataType = typeof(string), AllowDBNull = true });
result.Columns.Add(new DataColumn { ColumnName = "PassengerPlaceOfBirth", DataType = typeof(string), AllowDBNull = true });
result.Columns.Add(new DataColumn { ColumnName = "PassengerDateOfBirth", DataType = typeof(DateTime), AllowDBNull = true });
result.Columns.Add(new DataColumn { ColumnName = "PassengerGender", DataType = typeof(byte), AllowDBNull = true });
result.Columns.Add(new DataColumn { ColumnName = "PassengerNationality", DataType = typeof(string), AllowDBNull = true });
result.Columns.Add(new DataColumn { ColumnName = "PassengerIdentityDocumentType", DataType = typeof(byte), AllowDBNull = true });
result.Columns.Add(new DataColumn { ColumnName = "PassengerIdentityDocumentId", DataType = typeof(string), AllowDBNull = true });
result.Columns.Add(new DataColumn { ColumnName = "PassengerVisaNumber", DataType = typeof(string), AllowDBNull = true });
result.Columns.Add(new DataColumn { ColumnName = "PassengerPortOfEmbarkation", DataType = typeof(string), AllowDBNull = true });
result.Columns.Add(new DataColumn { ColumnName = "PassengerPortOfDisembarkation", DataType = typeof(string), AllowDBNull = true });
result.Columns.Add(new DataColumn { ColumnName = "PassengerInTransit", DataType = typeof(bool), AllowDBNull = true });
result.Columns.Add(new DataColumn { ColumnName = "Identifier", DataType = typeof(string), AllowDBNull = true });
result.Columns.Add(new DataColumn { ColumnName = "IsDeparture", DataType = typeof(bool), AllowDBNull = true });
result.Columns.Add(new DataColumn { ColumnName = "PassengerIdentityDocumentIssuingState", DataType = typeof(string), AllowDBNull = true });
result.Columns.Add(new DataColumn { ColumnName = "PassengerIdentityDocumentExpiryDate", DataType = typeof(DateTime), AllowDBNull = true });
result.Columns.Add(new DataColumn { ColumnName = "NotificationSchengen", DataType = typeof(bool), AllowDBNull = true });
result.Columns.Add(new DataColumn { ColumnName = "NotificationPAX", DataType = typeof(bool), AllowDBNull = true });
result.Columns.Add(new DataColumn { ColumnName = "EmergencyCare", DataType = typeof(string), AllowDBNull = true });
result.Columns.Add(new DataColumn { ColumnName = "EmergencyContactNumber", DataType = typeof(string), AllowDBNull = true });
result.Columns.Add(new DataColumn { ColumnName = "PassengerCountryOfBirth", DataType = typeof(string), AllowDBNull = true });
foreach (PAS pas in databaseEntities.Cast())
{
DataRow row = result.NewRow();
row[0] = pas.MessageHeader.Id;
row[1] = pas.PassengerLastName ?? (object)DBNull.Value;
row[2] = pas.PassengerFirstName ?? (object)DBNull.Value;
row[3] = pas.PassengerPlaceOfBirth ?? (object)DBNull.Value;
row[4] = pas.PassengerDateOfBirth ?? (object)DBNull.Value;
row[5] = pas.PassengerGender ?? (object)DBNull.Value;
row[6] = pas.PassengerNationality ?? (object)DBNull.Value;
row[7] = pas.PassengerIdentityDocumentType ?? (object)DBNull.Value;
row[8] = pas.PassengerIdentityDocumentId ?? (object)DBNull.Value;
row[9] = pas.PassengerVisaNumber ?? (object)DBNull.Value;
row[10] = pas.PassengerPortOfEmbarkation ?? (object)DBNull.Value;
row[11] = pas.PassengerPortOfDisembarkation ?? (object)DBNull.Value;
row[12] = pas.PassengerInTransit ?? (object)DBNull.Value;
row[13] = pas.Identifier ?? (object)DBNull.Value;
row[14] = pas.IsDeparture;
row[15] = pas.PassengerIdentityDocumentIssuingState ?? (object)DBNull.Value;
row[16] = pas.PassengerIdentityDocumentExpiryDate ?? (object)DBNull.Value;
row[17] = pas.NotificationSchengen ?? (object)DBNull.Value;
row[18] = pas.NotificationPAX ?? (object)DBNull.Value;
row[19] = pas.EmergencyCare ?? (object)DBNull.Value;
row[20] = pas.EmergencyContactNumber ?? (object)DBNull.Value;
row[21] = pas.PassengerCountryOfBirth ?? (object)DBNull.Value;
result.Rows.Add(row);
}
result.TableName = this.tablename;
return result;
}
#endregion
#region IComparable implementation
public int CompareTo(object obj)
{
if (obj is null)
return 1;
if (!(obj is PAS)) return 1;
if (Int32.TryParse(((PAS)obj).Identifier, out int i1) && Int32.TryParse(this.Identifier, out int i2))
return i2.CompareTo(i1);
return this.Identifier.CompareTo(((PAS)obj).Identifier);
}
#endregion
#region public copy func
public void CopyFromPAS(PAS pas)
{
if (pas == null) return;
this.PassengerLastName = pas.PassengerLastName;
this.PassengerFirstName = pas.PassengerFirstName;
this.PassengerPlaceOfBirth = pas.PassengerPlaceOfBirth;
this.PassengerDateOfBirth = pas.PassengerDateOfBirth;
this.PassengerGender = pas.PassengerGender;
this.PassengerNationality = pas.PassengerNationality;
this.PassengerIdentityDocumentType = pas.PassengerIdentityDocumentType;
this.PassengerIdentityDocumentId = pas.PassengerIdentityDocumentId;
this.PassengerVisaNumber = pas.PassengerVisaNumber;
this.PassengerPortOfEmbarkation = pas.PassengerPortOfEmbarkation;
this.PassengerPortOfDisembarkation = pas.PassengerPortOfDisembarkation;
this.PassengerInTransit = pas.PassengerInTransit;
this.PassengerIdentityDocumentIssuingState = pas.PassengerIdentityDocumentIssuingState;
this.PassengerIdentityDocumentExpiryDate = pas.PassengerIdentityDocumentExpiryDate;
this.NotificationSchengen = pas.NotificationSchengen;
this.NotificationPAX = pas.NotificationPAX;
this.PassengerCountryOfBirth = pas.PassengerCountryOfBirth;
this.EmergencyCare = pas.EmergencyCare;
this.EmergencyContactNumber = pas.EmergencyContactNumber;
}
#endregion
#region public static helper funcs
public static PAS CreateCommon(List pasList)
{
PAS pas = new PAS(); // template entity
//
if (pasList.IsNullOrEmpty())
return pas;
string passengerLastName = pasList[0].PassengerLastName;
if (pasList.All(x => Extensions.AreEqual(x.PassengerLastName, passengerLastName)))
pas.PassengerLastName = passengerLastName;
string passengerFirstName = pasList[0].PassengerFirstName;
if(pasList.All(x => Extensions.AreEqual(x.PassengerFirstName, passengerFirstName)))
pas.PassengerFirstName = passengerFirstName;
string passengerPlaceOfBirth = pasList[0].PassengerPlaceOfBirth;
if(pasList.All(x => Extensions.AreEqual(x.PassengerPlaceOfBirth, passengerPlaceOfBirth)))
pas.PassengerPlaceOfBirth = passengerPlaceOfBirth;
DateTime? passengerDateOfBirth = pasList[0].PassengerDateOfBirth;
if(pasList.All(x => Extensions.AreEqual(x.PassengerDateOfBirth, passengerDateOfBirth)))
pas.PassengerDateOfBirth = passengerDateOfBirth;
byte? passengerGender = pasList[0].PassengerGender;
if(pasList.All(x => Extensions.AreEqual(x.PassengerGender, passengerGender)))
pas.PassengerGender = passengerGender;
string passengerNationality = pasList[0].PassengerNationality;
if(pasList.All(x => Extensions.AreEqual(x.PassengerNationality, passengerNationality)))
pas.PassengerNationality = passengerNationality;
byte? passengerIdentityDocumentType = pasList[0].PassengerIdentityDocumentType;
if(pasList.All(x => Extensions.AreEqual(x.PassengerIdentityDocumentType, passengerIdentityDocumentType)))
pas.PassengerIdentityDocumentType = passengerIdentityDocumentType;
string passengerIdentityDocumentId = pasList[0].PassengerIdentityDocumentId;
if(pasList.All(x => Extensions.AreEqual(x.PassengerIdentityDocumentId, passengerIdentityDocumentId)))
pas.PassengerIdentityDocumentId = passengerIdentityDocumentId;
string passengerVisaNumber = pasList[0].PassengerVisaNumber;
if(pasList.All(x => Extensions.AreEqual(x.PassengerVisaNumber, passengerVisaNumber)))
pas.PassengerVisaNumber = passengerVisaNumber;
string passengerPortOfEmbarkation = pasList[0].PassengerPortOfEmbarkation;
if (pasList.All(x => Extensions.AreEqual(x.PassengerPortOfEmbarkation, passengerPortOfEmbarkation)))
pas.PassengerPortOfEmbarkation = passengerPortOfEmbarkation;
string passengerPortOfDisembarkation = pasList[0].PassengerPortOfDisembarkation;
if(pasList.All(x => Extensions.AreEqual(x.PassengerPortOfDisembarkation, passengerPortOfDisembarkation)))
pas.PassengerPortOfDisembarkation = passengerPortOfDisembarkation;
bool? passengerInTransit = pasList[0].PassengerInTransit;
if(pasList.All(x => Extensions.AreEqual(x.PassengerInTransit, passengerInTransit)))
pas.PassengerInTransit = passengerInTransit;
string passengerIdentityDocumentIssuingState = pasList[0].PassengerIdentityDocumentIssuingState;
if(pasList.All(x => Extensions.AreEqual(x.PassengerIdentityDocumentIssuingState, passengerIdentityDocumentIssuingState)))
pas.PassengerIdentityDocumentIssuingState = passengerIdentityDocumentIssuingState;
DateTime? passengerIdentityDocumentExpiryDate = pasList[0].PassengerIdentityDocumentExpiryDate;
if(pasList.All(x => Extensions.AreEqual(x.PassengerIdentityDocumentExpiryDate, passengerIdentityDocumentExpiryDate)))
pas.PassengerIdentityDocumentExpiryDate = passengerIdentityDocumentExpiryDate;
bool? notificationSchengen = pasList[0].NotificationSchengen;
if(pasList.All(x => Extensions.AreEqual(x.NotificationSchengen, notificationSchengen)))
pas.NotificationSchengen = notificationSchengen;
bool? notificationPAX = pasList[0].NotificationPAX;
if(pasList.All(x => Extensions.AreEqual(x.NotificationPAX, notificationPAX)))
pas.NotificationPAX = notificationPAX;
string passengerCountryOfBirth = pasList[0].PassengerCountryOfBirth;
if(pasList.All(x => Extensions.AreEqual(x.PassengerCountryOfBirth, passengerCountryOfBirth)))
pas.PassengerCountryOfBirth = passengerCountryOfBirth;
string emergencyCare = pasList[0].EmergencyCare;
if(pasList.All(x => Extensions.AreEqual(x.EmergencyCare, emergencyCare)))
pas.EmergencyCare = emergencyCare;
string emergencyContactNumber = pasList[0].EmergencyContactNumber;
if(pasList.All(x => Extensions.AreEqual(x.EmergencyContactNumber, emergencyContactNumber)))
pas.EmergencyContactNumber = emergencyContactNumber;
return pas;
}
public static void WriteTemplateToList(PAS pas, List pasList)
{
if (!pas.PassengerLastName.IsNullOrEmpty())
pasList.ForEach(x => x.PassengerLastName = pas.PassengerLastName);
if (!pas.PassengerFirstName.IsNullOrEmpty())
pasList.ForEach(x => x.PassengerFirstName = pas.PassengerFirstName);
if(!pas.PassengerPlaceOfBirth.IsNullOrEmpty())
pasList.ForEach(x => x.PassengerPlaceOfBirth = pas.PassengerPlaceOfBirth);
if(pas.PassengerDateOfBirth.HasValue)
pasList.ForEach(x => x.PassengerDateOfBirth = pas.PassengerDateOfBirth.Value);
if(pas.PassengerGender.HasValue)
pasList.ForEach(x => x.PassengerGender = pas.PassengerGender.Value);
if(!pas.PassengerNationality.IsNullOrEmpty())
pasList.ForEach(x => x.PassengerNationality = pas.PassengerNationality);
if(pas.PassengerIdentityDocumentType.HasValue)
pasList.ForEach(x => x.PassengerIdentityDocumentType = pas.PassengerIdentityDocumentType.Value);
if(!pas.PassengerIdentityDocumentId.IsNullOrEmpty())
pasList.ForEach(x => x.PassengerIdentityDocumentId = pas.PassengerIdentityDocumentId);
if(!pas.PassengerVisaNumber.IsNullOrEmpty())
pasList.ForEach(x => x.PassengerVisaNumber = pas.PassengerVisaNumber);
if(!pas.PassengerPortOfEmbarkation.IsNullOrEmpty())
pasList.ForEach(x => x.PassengerPortOfEmbarkation = pas.PassengerPortOfEmbarkation);
if(!pas.PassengerPortOfDisembarkation.IsNullOrEmpty())
pasList.ForEach(x => x.PassengerPortOfDisembarkation = pas.PassengerPortOfDisembarkation);
if(pas.PassengerInTransit.HasValue)
pasList.ForEach(x => x.PassengerInTransit = pas.PassengerInTransit.Value);
if(!pas.PassengerIdentityDocumentIssuingState.IsNullOrEmpty())
pasList.ForEach(x => x.PassengerIdentityDocumentIssuingState = pas.PassengerIdentityDocumentIssuingState);
if(pas.PassengerIdentityDocumentExpiryDate.HasValue)
pasList.ForEach(x => x.PassengerIdentityDocumentExpiryDate = pas.PassengerIdentityDocumentExpiryDate.Value);
if(pas.NotificationSchengen.HasValue)
pasList.ForEach(x => x.NotificationSchengen = pas.NotificationSchengen.Value);
if(pas.NotificationPAX.HasValue)
pasList.ForEach(x => x.NotificationPAX = pas.NotificationPAX.Value);
if(!pas.PassengerCountryOfBirth.IsNullOrEmpty())
pasList.ForEach(x => x.PassengerCountryOfBirth = pas.PassengerCountryOfBirth);
if(!pas.EmergencyCare.IsNullOrEmpty())
pasList.ForEach(x => x.EmergencyCare = pas.EmergencyCare);
if(!pas.EmergencyContactNumber.IsNullOrEmpty())
pasList.ForEach(x => x.EmergencyContactNumber = pas.EmergencyContactNumber);
}
#endregion
}
#region class PASD
public class PASD : PAS
{
public override void PrepareLoadCommand(System.Data.IDbCommand cmd, Message.LoadFilter filter, params object[] criteria)
{
string query = string.Format("SELECT Id, PassengerLastName, PassengerFirstName, PassengerPlaceOfBirth, " +
"PassengerDateOfBirth, PassengerGender, PassengerNationality, PassengerIdentityDocumentType, PassengerIdentityDocumentId, " +
"PassengerVisaNumber, PassengerPortOfEmbarkation, PassengerPortOfDisembarkation, PassengerInTransit, Identifier, IsDeparture, " +
"PassengerIdentityDocumentIssuingState, PassengerIdentityDocumentExpiryDate, NotificationSchengen, NotificationPAX, " +
"EmergencyCare, EmergencyContactNumber, PassengerCountryOfBirth FROM {0}",
this.Tablename);
switch (filter)
{
case Message.LoadFilter.MESSAGEHEADER:
query += " WHERE IsDeparture = 1 AND MessageHeaderId = @MHID";
((SqlCommand)cmd).Parameters.AddWithValue("@MHID", criteria[0]);
break;
case Message.LoadFilter.ALL:
default:
query += " WHERE IsDeparture = 1";
break;
}
cmd.CommandText = query;
}
public override string Title => "PASD";
public override List LoadList(System.Data.IDataReader reader)
{
List result = new List();
while (reader.Read())
{
PASD pas = new PASD();
pas.id = reader.GetGuid(0);
if (!reader.IsDBNull(1)) pas.PassengerLastName = reader.GetString(1);
if (!reader.IsDBNull(2)) pas.PassengerFirstName = reader.GetString(2);
if (!reader.IsDBNull(3)) pas.PassengerPlaceOfBirth = reader.GetString(3);
if (!reader.IsDBNull(4)) pas.PassengerDateOfBirth = reader.GetDateTime(4);
if (!reader.IsDBNull(5)) pas.PassengerGender = reader.GetByte(5);
if (!reader.IsDBNull(6)) pas.PassengerNationality = reader.GetString(6);
if (!reader.IsDBNull(7)) pas.PassengerIdentityDocumentType = reader.GetByte(7);
if (!reader.IsDBNull(8)) pas.PassengerIdentityDocumentId = reader.GetString(8);
if (!reader.IsDBNull(9)) pas.PassengerVisaNumber = reader.GetString(9);
if (!reader.IsDBNull(10)) pas.PassengerPortOfEmbarkation = reader.GetString(10);
if (!reader.IsDBNull(11)) pas.PassengerPortOfDisembarkation = reader.GetString(11);
if (!reader.IsDBNull(12)) pas.PassengerInTransit = reader.GetBoolean(12);
if (!reader.IsDBNull(13)) pas.Identifier = reader.GetString(13);
if (!reader.IsDBNull(14)) pas.IsDeparture = reader.GetBoolean(14);
if (!reader.IsDBNull(15)) pas.PassengerIdentityDocumentIssuingState = reader.GetString(15);
if (!reader.IsDBNull(16)) pas.PassengerIdentityDocumentExpiryDate = reader.GetDateTime(16);
if (!reader.IsDBNull(17)) pas.NotificationSchengen = reader.GetBoolean(17);
if (!reader.IsDBNull(18)) pas.NotificationPAX = reader.GetBoolean(18);
if (!reader.IsDBNull(19)) pas.EmergencyCare = reader.GetString(19);
if (!reader.IsDBNull(20)) pas.EmergencyContactNumber = reader.GetString(20);
if (!reader.IsDBNull(21)) pas.PassengerCountryOfBirth = reader.GetString(21);
result.Add(pas);
}
reader.Close();
result.Sort();
return result;
}
}
#endregion
}