/// <summary> /// Returns the 'nationality' of a passport and marks expired passports up. /// </summary> /// <param name="ACacheRetriever">Delegate that returns the specified DataTable from the data cache (client- or serverside). /// Delegate Method needs to be for the MPartner Cache (that is, it needs to work with the <see cref="TCacheableCommonTablesEnum" /> Enum!</param> /// <param name="APassportDR">DataRow containing information about a passport.</param> /// <returns>Country name that goes with the passport's Nationality Code, except for the case /// where no country name is found for the Nationality Code, then the Nationality Code is returned. /// If a passport is expired, the string " (exp.)" (potentially translated) is added as a postfix.</returns> public static string DeterminePassportNationality(TGetCacheableDataTableFromCache ACacheRetriever, PmPassportDetailsRow APassportDR) { string ReturnValue; ReturnValue = CommonCodeHelper.GetCountryName( @ACacheRetriever, APassportDR.PassportNationalityCode); // Fallback: If no country name exists in the Chacheable DataTable, use the Nationality Code. if (ReturnValue == String.Empty) { ReturnValue = APassportDR.PassportNationalityCode; } if ((APassportDR.DateOfExpiration.HasValue) && (APassportDR.DateOfExpiration.Value.Date < DateTime.Now.Date)) { if ((!APassportDR.IsMainPassportNull()) && (APassportDR.MainPassport)) { ReturnValue += PASSPORTMAIN_EXPIRED; } else { ReturnValue += PASSPORT_EXPIRED; } } return(ReturnValue); }
/// <summary> /// Determines a PERSON's Nationalities (deduced from its passports). /// </summary> /// <remarks> /// <para>Algorithm:</para> /// <list type="number"> /// <item>Check pm_main_passport_l flag</item> /// <list type="number"> /// <item>if null, don't do anything special (Note: Partner Import does not write to this field, it stays null if it isn't found in the import file [which will be the case for Petra 2.x])</item> /// <item>if false, do likewise</item> /// <item>if true, list as FIRST Country</item> /// </list> /// </list> /// <item>Order by pm_date_of_issue_d</item> /// <list type="number"> /// <item>order Countries by pm_date_of_issue_d DESC, except for the FIRST Country</item> /// <list type="number"> /// <item>in case there are several FIRST Countries (which in theory should not happen), they are ordered by pm_date_of_issue_d DESC in themselves at the beginning of the list of Countries.</item> /// </list> /// </list> /// <item>Check for passport expiration</item> /// <list type="number"> /// <item>If a passport's expiry date is set and it is in the past</item> /// <list type="number"> /// <item>show the Country + " (exp.)".</item> /// </list> /// </list> /// <item>Elimination of duplicate listings</item> /// <list type="number"> /// <item>If a country of issue comes up twice</item> /// <list type="number"> /// <item>eliminate the duplicate, except if the Country is listed once by its name and one with the exp. postfix.</item> /// </list> /// </list> /// <para>Additionally, a warning text " MAIN!)" to the postfix " (exp." is added if the expired passport is the /// 'Main Passport' (pm_main_passport_l=true) of the PERSON.</para> /// </remarks> /// <param name="ACacheRetriever">Delegate that returns the specified DataTable from the data cache (client- or serverside). /// Delegate Method needs to be for the MPartner Cache (that is, it needs to work with the <see cref="TCacheableCommonTablesEnum" /> Enum!</param> /// <param name="APassportDetailsDT"></param> /// <returns></returns> public static string DeterminePersonsNationalities(TGetCacheableDataTableFromCache ACacheRetriever, PmPassportDetailsTable APassportDetailsDT) { HashSet <string> Nationalities = new HashSet <string>(); string NationalitiesStr = String.Empty; PmPassportDetailsRow PassportDR; DataView OrderedPassportsDV = new DataView( APassportDetailsDT, null, PmPassportDetailsTable.GetDateOfIssueDBName() + " DESC", DataViewRowState.CurrentRows); // If a Passport's MainPassport flag is set, record it as the first Nationality foreach (DataRowView OrderedPassport in OrderedPassportsDV) { PassportDR = (PmPassportDetailsRow)OrderedPassport.Row; if (!PassportDR.IsMainPassportNull() && PassportDR.MainPassport) { // Add the Nationality (Note: Duplicates are taken care of automatically as this is a HashSet!) Nationalities.Add(DeterminePassportNationality(ACacheRetriever, PassportDR)); // Note: We could leave the loop here if we assume that there is ever only going to be ONE // 'first Nationality', but that assumption could be wrong and we want to make sure to list // all 'first Nationalities', ordered by pm_date_of_issue_d DESC in themselves. } } // Add the rest of the Nationalities (Note: Duplicates are taken care of automatically as this is a HashSet!) foreach (DataRowView OrderedPassport in OrderedPassportsDV) { Nationalities.Add(DeterminePassportNationality(ACacheRetriever, (PmPassportDetailsRow)OrderedPassport.Row)); } // Put all Nationalities in a string foreach (string Nationality in Nationalities) { NationalitiesStr += Nationality + ", "; } if (NationalitiesStr.Length > 0) { return(NationalitiesStr.Substring(0, NationalitiesStr.Length - 2)); // remove last comma } else { return(String.Empty); } }
/// <summary> /// Returns the description of a Marital Status Code. /// </summary> /// <param name="ACacheRetriever">Delegate that returns the specified DataTable from the data cache (client- or serverside). /// Delegate Method needs to be for the MPartner Cache (that is, it needs to work with the <see cref="TCacheablePartnerTablesEnum" /> Enum!</param> /// <param name="AMaritalStatusCode">Marital Status Code.</param> /// <returns>The description of a Marital Status Code, or empty string if the Marital Status Code could not be identified.</returns> public static string GetMaritalStatusDescription(TGetCacheableDataTableFromCache ACacheRetriever, string AMaritalStatusCode) { DataTable CachedDT; DataRow FoundDR; string ReturnValue = ""; Type tmp; CachedDT = ACacheRetriever(Enum.GetName(typeof(TCacheablePartnerTablesEnum), TCacheablePartnerTablesEnum.MaritalStatusList), out tmp); FoundDR = CachedDT.Rows.Find(new object[] { AMaritalStatusCode }); if (FoundDR != null) { ReturnValue = FoundDR[PtMaritalStatusTable.ColumnDescriptionId].ToString(); } return(ReturnValue); }
/// <summary> /// Returns the description of a Marital Status Code. /// </summary> /// <param name="ACacheRetriever">Delegate that returns the specified DataTable from the data cache (client- or serverside). /// Delegate Method needs to be for the MPartner Cache (that is, it needs to work with the <see cref="TCacheablePartnerTablesEnum" /> Enum!</param> /// <param name="AMaritalStatusCode">Marital Status Code.</param> /// <returns>The description of a Marital Status Code, or empty string if the Marital Status Code could not be identified.</returns> public static string GetMaritalStatusDescription(TGetCacheableDataTableFromCache ACacheRetriever, string AMaritalStatusCode) { DataTable CachedDT; DataRow FoundDR; string ReturnValue = ""; Type tmp; CachedDT = ACacheRetriever(Enum.GetName(typeof(TCacheablePartnerTablesEnum), TCacheablePartnerTablesEnum.MaritalStatusList), out tmp); FoundDR = CachedDT.Rows.Find(new object[] { AMaritalStatusCode }); if (FoundDR != null) { ReturnValue = FoundDR[PtMaritalStatusTable.ColumnDescriptionId].ToString(); } return ReturnValue; }
/// <summary> /// Returns the International Telephone Code of a Country. /// </summary> /// <param name="ACacheRetriever">Delegate that returns the specified DataTable from the data cache (client- or serverside). /// Delegate Method needs to be for the MCommon Cache (that is, it needs to work with the <see cref="TCacheableCommonTablesEnum" /> Enum!</param> /// <param name="AIntlTelephoneCode">International Telephone Code.</param> /// <returns>The description of a Country Code, or empty string if the Country Code could not be identified.</returns> public static string GetCountryIntlTelephoneCode(TGetCacheableDataTableFromCache ACacheRetriever, string AIntlTelephoneCode) { DataTable CachedDT; DataRow FoundDR; string ReturnValue = ""; Type tmp; CachedDT = ACacheRetriever(Enum.GetName(typeof(TCacheableCommonTablesEnum), TCacheableCommonTablesEnum.CountryList), out tmp); FoundDR = CachedDT.Rows.Find(new object[] { AIntlTelephoneCode }); if (FoundDR != null) { ReturnValue = FoundDR[PCountryTable.ColumnInternatTelephoneCodeId].ToString(); } return ReturnValue; }
/// <summary> /// Returns the International Telephone Code of a Country. /// </summary> /// <param name="ACacheRetriever">Delegate that returns the specified DataTable from the data cache (client- or serverside). /// Delegate Method needs to be for the MCommon Cache (that is, it needs to work with the <see cref="TCacheableCommonTablesEnum" /> Enum!</param> /// <param name="AIntlTelephoneCode">International Telephone Code.</param> /// <returns>The description of a Country Code, or empty string if the Country Code could not be identified.</returns> public static string GetCountryIntlTelephoneCode(TGetCacheableDataTableFromCache ACacheRetriever, string AIntlTelephoneCode) { DataTable CachedDT; DataRow FoundDR; string ReturnValue = ""; Type tmp; CachedDT = ACacheRetriever(Enum.GetName(typeof(TCacheableCommonTablesEnum), TCacheableCommonTablesEnum.CountryList), out tmp); FoundDR = CachedDT.Rows.Find(new object[] { AIntlTelephoneCode }); if (FoundDR != null) { ReturnValue = FoundDR[PCountryTable.ColumnInternatTelephoneCodeId].ToString(); } return(ReturnValue); }
/// <summary> /// Determines a PERSON's Nationalities (deduced from its passports). /// </summary> /// <remarks> /// <para>Algorithm:</para> /// <list type="number"> /// <item>Check pm_main_passport_l flag</item> /// <list type="number"> /// <item>if null, don't do anything special (Note: Partner Import does not write to this field, it stays null if it isn't found in the import file [which will be the case for Petra 2.x])</item> /// <item>if false, do likewise</item> /// <item>if true, list as FIRST Country</item> /// </list> /// </list> /// <item>Order by pm_date_of_issue_d</item> /// <list type="number"> /// <item>order Countries by pm_date_of_issue_d DESC, except for the FIRST Country</item> /// <list type="number"> /// <item>in case there are several FIRST Countries (which in theory should not happen), they are ordered by pm_date_of_issue_d DESC in themselves at the beginning of the list of Countries.</item> /// </list> /// </list> /// <item>Check for passport expiration</item> /// <list type="number"> /// <item>If a passport's expiry date is set and it is in the past</item> /// <list type="number"> /// <item>show the Country + " (exp.)".</item> /// </list> /// </list> /// <item>Elimination of duplicate listings</item> /// <list type="number"> /// <item>If a country of issue comes up twice</item> /// <list type="number"> /// <item>eliminate the duplicate, except if the Country is listed once by its name and one with the exp. postfix.</item> /// </list> /// </list> /// <para>Additionally, a warning text " MAIN!)" to the postfix " (exp." is added if the expired passport is the /// 'Main Passport' (pm_main_passport_l=true) of the PERSON.</para> /// </remarks> /// <param name="ACacheRetriever">Delegate that returns the specified DataTable from the data cache (client- or serverside). /// Delegate Method needs to be for the MPartner Cache (that is, it needs to work with the <see cref="TCacheableCommonTablesEnum" /> Enum!</param> /// <param name="APassportDetailsDT"></param> /// <returns></returns> public static string DeterminePersonsNationalities(TGetCacheableDataTableFromCache ACacheRetriever, PmPassportDetailsTable APassportDetailsDT) { HashSet <string>Nationalities = new HashSet <string>(); string NationalitiesStr = String.Empty; PmPassportDetailsRow PassportDR; DataView OrderedPassportsDV = new DataView( APassportDetailsDT, null, PmPassportDetailsTable.GetDateOfIssueDBName() + " DESC", DataViewRowState.CurrentRows); // If a Passport's MainPassport flag is set, record it as the first Nationality foreach (DataRowView OrderedPassport in OrderedPassportsDV) { PassportDR = (PmPassportDetailsRow)OrderedPassport.Row; if (!PassportDR.IsMainPassportNull() && PassportDR.MainPassport) { // Add the Nationality (Note: Duplicates are taken care of automatically as this is a HashSet!) Nationalities.Add(DeterminePassportNationality(ACacheRetriever, PassportDR)); // Note: We could leave the loop here if we assume that there is ever only going to be ONE // 'first Nationality', but that assumption could be wrong and we want to make sure to list // all 'first Nationalities', ordered by pm_date_of_issue_d DESC in themselves. } } // Add the rest of the Nationalities (Note: Duplicates are taken care of automatically as this is a HashSet!) foreach (DataRowView OrderedPassport in OrderedPassportsDV) { Nationalities.Add(DeterminePassportNationality(ACacheRetriever, (PmPassportDetailsRow)OrderedPassport.Row)); } // Put all Nationalities in a string foreach (string Nationality in Nationalities) { NationalitiesStr += Nationality + ", "; } if (NationalitiesStr.Length > 0) { return NationalitiesStr.Substring(0, NationalitiesStr.Length - 2); // remove last comma } else { return String.Empty; } }
/// <summary> /// Returns the 'nationality' of a passport and marks expired passports up. /// </summary> /// <param name="ACacheRetriever">Delegate that returns the specified DataTable from the data cache (client- or serverside). /// Delegate Method needs to be for the MPartner Cache (that is, it needs to work with the <see cref="TCacheableCommonTablesEnum" /> Enum!</param> /// <param name="APassportDR">DataRow containing information about a passport.</param> /// <returns>Country name that goes with the passport's Nationality Code, except for the case /// where no country name is found for the Nationality Code, then the Nationality Code is returned. /// If a passport is expired, the string " (exp.)" (potentially translated) is added as a postfix.</returns> public static string DeterminePassportNationality(TGetCacheableDataTableFromCache ACacheRetriever, PmPassportDetailsRow APassportDR) { string ReturnValue; ReturnValue = CommonCodeHelper.GetCountryName( @ACacheRetriever, APassportDR.PassportNationalityCode); // Fallback: If no country name exists in the Chacheable DataTable, use the Nationality Code. if (ReturnValue == String.Empty) { ReturnValue = APassportDR.PassportNationalityCode; } if ((APassportDR.DateOfExpiration.HasValue) && (APassportDR.DateOfExpiration.Value.Date < DateTime.Now.Date)) { if ((!APassportDR.IsMainPassportNull()) && (APassportDR.MainPassport)) { ReturnValue += PASSPORTMAIN_EXPIRED; } else { ReturnValue += PASSPORT_EXPIRED; } } return ReturnValue; }
/// <summary> /// Validates the Partner Detail data of a Partner of PartnerClass PERSON. /// </summary> /// <param name="AContext">Context that describes where the data validation failed.</param> /// <param name="ARow">The <see cref="DataRow" /> which holds the the data against which the validation is run.</param> /// <param name="ACacheRetriever">Delegate that returns the specified DataTable from the data cache (client- or serverside). /// Delegate Method needs to be for the MPartner Cache (that is, it needs to work with the <see cref="TCacheablePartnerTablesEnum" /> Enum!</param> /// <param name="AVerificationResultCollection">Will be filled with any <see cref="TVerificationResult" /> items if /// data validation errors occur.</param> /// <param name="AValidationControlsDict">A <see cref="TValidationControlsDict" /> containing the Controls that /// display data that is about to be validated.</param> /// <returns>void</returns> public static void ValidatePartnerPersonManual(object AContext, PPersonRow ARow, TGetCacheableDataTableFromCache ACacheRetriever, ref TVerificationResultCollection AVerificationResultCollection, TValidationControlsDict AValidationControlsDict) { DataColumn ValidationColumn; TValidationControlsData ValidationControlsData; TVerificationResult VerificationResult; // Don't validate deleted DataRows if (ARow.RowState == DataRowState.Deleted) { return; } // 'Date of Birth' must have a sensible value (must not be below 1850 and must not lie in the future) ValidationColumn = ARow.Table.Columns[PPersonTable.ColumnDateOfBirthId]; if (AValidationControlsDict.TryGetValue(ValidationColumn, out ValidationControlsData)) { if (!ARow.IsDateOfBirthNull()) { VerificationResult = TDateChecks.IsDateBetweenDates( ARow.DateOfBirth, new DateTime(1850, 1, 1), DateTime.Today, ValidationControlsData.ValidationControlLabel, TDateBetweenDatesCheckType.dbdctUnrealisticDate, TDateBetweenDatesCheckType.dbdctNoFutureDate, AContext, ValidationColumn, ValidationControlsData.ValidationControl); // Handle addition to/removal from TVerificationResultCollection AVerificationResultCollection.Auto_Add_Or_AddOrRemove(AContext, VerificationResult, ValidationColumn); } } // 'Marital Status' must not be unassignable ValidationColumn = ARow.Table.Columns[PPersonTable.ColumnMaritalStatusId]; if (AValidationControlsDict.TryGetValue(ValidationColumn, out ValidationControlsData)) { PtMaritalStatusTable TypeTable; PtMaritalStatusRow TypeRow; VerificationResult = null; if ((!ARow.IsMaritalStatusNull()) && (ARow.MaritalStatus != String.Empty)) { TypeTable = (PtMaritalStatusTable)TSharedDataCache.TMPartner.GetCacheablePartnerTable( TCacheablePartnerTablesEnum.MaritalStatusList); TypeRow = (PtMaritalStatusRow)TypeTable.Rows.Find(ARow.MaritalStatus); // 'Marital Status' must not be unassignable if ((TypeRow != null) && !TypeRow.AssignableFlag && (TypeRow.IsAssignableDateNull() || (TypeRow.AssignableDate <= DateTime.Today))) { // if 'Marital Status' is unassignable then check if the value has been changed or if it is a new record if (TSharedValidationHelper.IsRowAddedOrFieldModified(ARow, PPersonTable.GetMaritalStatusDBName())) { VerificationResult = new TScreenVerificationResult(new TVerificationResult(AContext, ErrorCodes.GetErrorInfo(PetraErrorCodes.ERR_VALUEUNASSIGNABLE_WARNING, new string[] { ValidationControlsData.ValidationControlLabel, ARow.MaritalStatus })), ValidationColumn, ValidationControlsData.ValidationControl); } } } // Handle addition/removal to/from TVerificationResultCollection AVerificationResultCollection.Auto_Add_Or_AddOrRemove(AContext, VerificationResult, ValidationColumn); } // 'MaritalStatusSince' must be valid ValidationColumn = ARow.Table.Columns[PPersonTable.ColumnMaritalStatusSinceId]; if (AValidationControlsDict.TryGetValue(ValidationColumn, out ValidationControlsData)) { VerificationResult = TSharedValidationControlHelper.IsNotInvalidDate(ARow.MaritalStatusSince, ValidationControlsData.ValidationControlLabel, AVerificationResultCollection, false, AContext, ValidationColumn, ValidationControlsData.ValidationControl); // Handle addition to/removal from TVerificationResultCollection AVerificationResultCollection.Auto_Add_Or_AddOrRemove(AContext, VerificationResult, ValidationColumn); } // 'OccupationCode' must be valid ValidationColumn = ARow.Table.Columns[PPersonTable.ColumnOccupationCodeId]; if (AValidationControlsDict.TryGetValue(ValidationColumn, out ValidationControlsData)) { if (!string.IsNullOrEmpty(ARow.OccupationCode)) { Type tmp; DataTable CachedDT = ACacheRetriever(Enum.GetName(typeof(TCacheablePartnerTablesEnum), TCacheablePartnerTablesEnum.OccupationList), out tmp); DataRow FoundDR = CachedDT.Rows.Find(new object[] { ARow.OccupationCode }); if (FoundDR == null) { VerificationResult = new TVerificationResult(ValidationControlsData.ValidationControl, ErrorCodes.GetErrorInfo( PetraErrorCodes.ERR_OCCUPATIONCODE_INVALID, new string[] { ARow.OccupationCode })); VerificationResult = new TScreenVerificationResult(VerificationResult, ValidationColumn, ValidationControlsData.ValidationControl); // Handle addition to/removal from TVerificationResultCollection AVerificationResultCollection.Auto_Add_Or_AddOrRemove(AContext, VerificationResult, ValidationColumn); } } } }