405 lines
18 KiB
C#
405 lines
18 KiB
C#
//
|
|
// 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;
|
|
|
|
namespace bsmd.database
|
|
{
|
|
public class PAS : DatabaseEntity, ISublistElement
|
|
{
|
|
|
|
public PAS()
|
|
{
|
|
this.tablename = "[dbo].[PAS]";
|
|
}
|
|
|
|
#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")]
|
|
[Validation(ValidationCode.NOT_NULL)]
|
|
[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; }
|
|
|
|
[ShowReport]
|
|
[ReportDisplayName("Issuing state")]
|
|
[Validation(ValidationCode.OPTIONAL_FLAG_CODE)]
|
|
[ENI2Validation]
|
|
public string PassengerIdentityDocumentIssuingState { get; set; }
|
|
|
|
|
|
[ShowReport]
|
|
[ReportDisplayName("Expiry date")]
|
|
[ENI2Validation]
|
|
public DateTime? PassengerIdentityDocumentExpiryDate { get; set; }
|
|
|
|
[ENI2Validation]
|
|
public bool? NotificationSchengen { get; set; }
|
|
|
|
[ENI2Validation]
|
|
public bool? NotificationPAX { get; set; }
|
|
|
|
//[Validation(ValidationCode.FLAG_CODE)]
|
|
[MaxLength(2)]
|
|
[ENI2Validation] // XXX - TODO
|
|
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; }
|
|
|
|
/// <summary>
|
|
/// Helper property for validation
|
|
/// </summary>
|
|
public bool HasSchengenDetails
|
|
{
|
|
get
|
|
{
|
|
return PassengerIdentityDocumentType.HasValue && !PassengerIdentityDocumentId.IsNullOrEmpty() &&
|
|
PassengerIdentityDocumentExpiryDate.HasValue && !PassengerPortOfEmbarkation.IsNullOrEmpty() && !PassengerPortOfDisembarkation.IsNullOrEmpty();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Helper property for validation
|
|
/// </summary>
|
|
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;
|
|
}
|
|
|
|
query += " ORDER BY CAST(Identifier AS INT)";
|
|
|
|
cmd.CommandText = query;
|
|
}
|
|
|
|
public override List<DatabaseEntity> LoadList(System.Data.IDataReader reader)
|
|
{
|
|
List<DatabaseEntity> result = new List<DatabaseEntity>();
|
|
|
|
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();
|
|
return result;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Validation
|
|
|
|
public override void Validate(List<MessageError> errors, List<MessageViolation> violations)
|
|
{
|
|
/* Nach RM Christin / Trello vom 27.11.17 auskommentiert
|
|
if (this.PassengerPortOfDisembarkation != null)
|
|
{
|
|
if (this.PassengerPortOfDisembarkation.Equals("ZZUKN"))
|
|
violations.Add(RuleEngine.CreateViolation(ValidationCode.NOT_NULL, "PassengerPortOfDisembarkation", null, this.Title, this.Identifier, this.Tablename));
|
|
}
|
|
|
|
if (this.PassengerPortOfEmbarkation != null)
|
|
{
|
|
if (this.PassengerPortOfEmbarkation.Equals("ZZUKN"))
|
|
violations.Add(RuleEngine.CreateViolation(ValidationCode.NOT_NULL, "PassengerPortOfEmbarkation", null, this.Title, this.Identifier, this.Tablename));
|
|
}
|
|
*/
|
|
}
|
|
|
|
#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;
|
|
}
|
|
|
|
query += " ORDER BY CAST(Identifier AS INT)";
|
|
|
|
cmd.CommandText = query;
|
|
}
|
|
|
|
public override List<DatabaseEntity> LoadList(System.Data.IDataReader reader)
|
|
{
|
|
List<DatabaseEntity> result = new List<DatabaseEntity>();
|
|
|
|
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();
|
|
return result;
|
|
}
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
} |