/// <summary> /// Gets nationalities from all of a Partner's recorded passports /// </summary> /// <param name="APartnerKey">Partner key</param> /// <returns>returns nationalities in a comma seperated string</returns> private string GetNationalities(Int64 APartnerKey) { TCacheable CommonCacheable = new TCacheable(); StringCollection PassportColumns = StringHelper.StrSplit( PmPassportDetailsTable.GetDateOfIssueDBName() + "," + PmPassportDetailsTable.GetDateOfExpirationDBName() + "," + PmPassportDetailsTable.GetPassportNationalityCodeDBName() + "," + PmPassportDetailsTable.GetMainPassportDBName(), ","); PmPassportDetailsTable PassportDetailsDT = PmPassportDetailsAccess.LoadViaPPerson(APartnerKey, PassportColumns, situation.GetDatabaseConnection().Transaction, null, 0, 0); return(Ict.Petra.Shared.MPersonnel.Calculations.DeterminePersonsNationalities( @CommonCacheable.GetCacheableTable, PassportDetailsDT)); }
/// <summary> /// Get the passport details and restores them as parameters. /// If there is a passport with the MainPassport flag set, then use this passport. /// Otherwise use the most recent passport which has a passport number. /// </summary> /// <param name="APartnerKey">Partner key</param> /// <param name="ASituation">A current Report Situation</param> /// <returns>true if one passport was found, otherwise false</returns> public static PmPassportDetailsRow GetLatestPassport(Int64 APartnerKey, TRptSituation ASituation) { PmPassportDetailsTable PassportTable = null; PmPassportDetailsRow ResultPassportRow = null; StringCollection PassportCollumns = new StringCollection(); StringCollection OrderList = new StringCollection(); PassportCollumns.Add(PmPassportDetailsTable.GetPassportNationalityCodeDBName()); PassportCollumns.Add(PmPassportDetailsTable.GetPassportNumberDBName()); PassportCollumns.Add(PmPassportDetailsTable.GetDateOfExpirationDBName()); PassportCollumns.Add(PmPassportDetailsTable.GetFullPassportNameDBName()); OrderList.Add("ORDER BY " + PmPassportDetailsTable.GetDateOfExpirationDBName() + " DESC"); PassportTable = PmPassportDetailsAccess.LoadViaPPerson(APartnerKey, PassportCollumns, ASituation.GetDatabaseConnection().Transaction, OrderList, 0, 0); // Look for MainPassport flag foreach (PmPassportDetailsRow Row in PassportTable.Rows) { if (!Row.IsMainPassportNull() && Row.MainPassport) { ResultPassportRow = Row; break; } } // Look for the most recent passport with a passport number if (ResultPassportRow == null) { foreach (PmPassportDetailsRow Row in PassportTable.Rows) { if (Row.PassportNumber.Length > 0) { ResultPassportRow = Row; break; } } } return(ResultPassportRow); }
/// <summary> /// Adds one partner to the report table /// </summary> /// <param name="APartnerKey">The partner key of the current partner</param> /// <param name="AGender">Gender of the current partner</param> /// <param name="ALanguageCode">The mother language of the current partner</param> /// <param name="ASituation">The current report situation</param> /// <returns></returns> public bool CalculateNationalities(long APartnerKey, String AGender, String ALanguageCode, ref TRptSituation ASituation) { TCacheable CommonCacheable = new TCacheable(); StringCollection PassportColumns = StringHelper.StrSplit( PmPassportDetailsTable.GetDateOfIssueDBName() + "," + PmPassportDetailsTable.GetDateOfExpirationDBName() + "," + PmPassportDetailsTable.GetPassportNationalityCodeDBName() + "," + PmPassportDetailsTable.GetMainPassportDBName(), ","); PmPassportDetailsTable PassportDetailsDT = PmPassportDetailsAccess.LoadViaPPerson(APartnerKey, PassportColumns, ASituation.GetDatabaseConnection().Transaction, null, 0, 0); string Nationalities = Ict.Petra.Shared.MPersonnel.Calculations.DeterminePersonsNationalities( @CommonCacheable.GetCacheableTable, PassportDetailsDT); string[] NationalitiesArray = Nationalities.Split(','); bool FoundNationality = false; List <string> PreviousNationalities = new List <string>(); foreach (string Nationality in NationalitiesArray) { string SingleNationality = Nationality; // remove all characters other than the country name SingleNationality = Nationality.TrimStart(' '); if (SingleNationality.EndsWith(Ict.Petra.Shared.MPersonnel.Calculations.PASSPORT_EXPIRED)) { SingleNationality = SingleNationality.Remove(SingleNationality.Length - Ict.Petra.Shared.MPersonnel.Calculations.PASSPORT_EXPIRED.Length); } else if (SingleNationality.EndsWith(Ict.Petra.Shared.MPersonnel.Calculations.PASSPORTMAIN_EXPIRED)) { SingleNationality = SingleNationality.Remove(SingleNationality.Length - Ict.Petra.Shared.MPersonnel.Calculations.PASSPORTMAIN_EXPIRED.Length); } if (SingleNationality == "") { SingleNationality = Catalog.GetString("UNKNOWN"); } // make sure that this nationality has not already been processed for this partner if (!PreviousNationalities.Contains(SingleNationality)) { for (int Counter = 0; Counter < FNationalityTable.Rows.Count; ++Counter) { if (((String)FNationalityTable.Rows[Counter][COLUMNNATIONALITYCODE] == SingleNationality)) { FoundNationality = true; AddAttendeeToTable(Counter, AGender, SingleNationality, ALanguageCode); } } if (!FoundNationality) { AddAttendeeToTable(-1, AGender, SingleNationality, ALanguageCode); } PreviousNationalities.Add(SingleNationality); } } return(true); }
/// <summary> /// Retrieves data that will be shown on the 'Overview' UserControl and adds it to <paramref name="AIndividualDataDS" />. /// </summary> /// <param name="APartnerKey">PartnerKey of the Person to load data for.</param> /// <param name="AIndividualDataDS">Typed DataSet of Type <see cref="IndividualDataTDS" />. Needs to be instantiated already!</param> /// <param name="AReadTransaction">Open Database transaction.</param> /// <returns>void</returns> private static void BuildSummaryData(Int64 APartnerKey, ref IndividualDataTDS AIndividualDataDS, TDBTransaction AReadTransaction) { string StrNotAvailable = Catalog.GetString("Not Available"); IndividualDataTDSSummaryDataTable SummaryDT; IndividualDataTDSSummaryDataRow SummaryDR; IndividualDataTDSMiscellaneousDataRow MiscellaneousDataDR = AIndividualDataDS.MiscellaneousData[0]; PPersonTable PPersonDT; PPersonRow PersonDR = null; PmPassportDetailsTable PassportDetailsDT; PmStaffDataTable PmStaffDataDT; PmStaffDataRow PmStaffDataDR = null; PmJobAssignmentTable PmJobAssignmentDT = null; PUnitTable PUnitDT = null; PmJobAssignmentRow PmJobAssignmentDR; IndividualDataTDSJobAssignmentStaffDataCombinedRow JobAssiStaffDataCombDR; int JobAssiStaffDataCombKey = 0; TCacheable CommonCacheable = new TCacheable(); TPartnerCacheable PartnerCacheable = new TPartnerCacheable(); string MaritalStatusDescr; StringCollection PassportColumns; string Nationalities; PPartnerRelationshipTable PartnerRelationshipDT; PPartnerTable PartnerDT; PPartnerRow PartnerDR = null; PLocationRow LocationDR; PPartnerLocationRow PartnerLocationDR; string PhoneNumber; string EmailAddress; Int64 ChurchPartnerKey; SummaryDT = new IndividualDataTDSSummaryDataTable(); SummaryDR = SummaryDT.NewRowTyped(false); SummaryDR.PartnerKey = APartnerKey; #region Person Info PPersonDT = PPersonAccess.LoadByPrimaryKey(APartnerKey, AReadTransaction); if (PPersonDT.Rows.Count == 1) { PersonDR = (PPersonRow)PPersonDT.Rows[0]; } if (PersonDR != null) { SummaryDR.DateOfBirth = PersonDR.DateOfBirth; SummaryDR.Gender = PersonDR.Gender; MaritalStatusDescr = PartnerCodeHelper.GetMaritalStatusDescription( @PartnerCacheable.GetCacheableTable, PersonDR.MaritalStatus); if (MaritalStatusDescr != String.Empty) { MaritalStatusDescr = " - " + MaritalStatusDescr; } SummaryDR.MaritalStatus = PersonDR.MaritalStatus + MaritalStatusDescr; } else { SummaryDR.SetDateOfBirthNull(); SummaryDR.Gender = StrNotAvailable; SummaryDR.MaritalStatus = StrNotAvailable; } #region Nationalities PassportColumns = StringHelper.StrSplit( PmPassportDetailsTable.GetDateOfIssueDBName() + "," + PmPassportDetailsTable.GetDateOfExpirationDBName() + "," + PmPassportDetailsTable.GetPassportNationalityCodeDBName() + "," + PmPassportDetailsTable.GetMainPassportDBName(), ","); PassportDetailsDT = PmPassportDetailsAccess.LoadViaPPerson(APartnerKey, PassportColumns, AReadTransaction, null, 0, 0); Nationalities = Ict.Petra.Shared.MPersonnel.Calculations.DeterminePersonsNationalities( @CommonCacheable.GetCacheableTable, PassportDetailsDT); if (Nationalities != String.Empty) { SummaryDR.Nationalities = Nationalities; } else { SummaryDR.Nationalities = StrNotAvailable; } #endregion #region Phone and Email (from 'Best Address') if (TContactDetailsAggregate.GetPrimaryEmailAndPrimaryPhone(APartnerKey, out PhoneNumber, out EmailAddress)) { SummaryDR.PrimaryPhoneNumber = PhoneNumber ?? StrNotAvailable; SummaryDR.PrimaryEmailAddress = EmailAddress ?? StrNotAvailable; } else { SummaryDR.PrimaryPhoneNumber = StrNotAvailable; SummaryDR.PrimaryEmailAddress = StrNotAvailable; } #endregion #endregion #region Commitments/Jobs PmStaffDataDT = PmStaffDataAccess.LoadViaPPerson(APartnerKey, AReadTransaction); MiscellaneousDataDR.ItemsCountCommitmentPeriods = PmStaffDataDT.Rows.Count; // First check if the PERSON has got any Commitments if (PmStaffDataDT.Rows.Count > 0) { foreach (DataRow DR in PmStaffDataDT.Rows) { JobAssiStaffDataCombDR = AIndividualDataDS.JobAssignmentStaffDataCombined.NewRowTyped(false); JobAssiStaffDataCombDR.Key = JobAssiStaffDataCombKey++; JobAssiStaffDataCombDR.PartnerKey = APartnerKey; PmStaffDataDR = (PmStaffDataRow)DR; if (!(PmStaffDataDR.IsReceivingFieldNull()) && (PmStaffDataDR.ReceivingField != 0)) { PUnitDT = PUnitAccess.LoadByPrimaryKey(PmStaffDataDR.ReceivingField, AReadTransaction); JobAssiStaffDataCombDR.FieldKey = PmStaffDataDR.ReceivingField; JobAssiStaffDataCombDR.FieldName = PUnitDT[0].UnitName; } else { JobAssiStaffDataCombDR.FieldKey = 0; JobAssiStaffDataCombDR.FieldName = "[None]"; } JobAssiStaffDataCombDR.Position = PmStaffDataDR.JobTitle; JobAssiStaffDataCombDR.FromDate = PmStaffDataDR.StartOfCommitment; JobAssiStaffDataCombDR.ToDate = PmStaffDataDR.EndOfCommitment; AIndividualDataDS.JobAssignmentStaffDataCombined.Rows.Add(JobAssiStaffDataCombDR); } } else { // The PERSON hasn't got any Commitments, therefore check if the PERSON has any Job Assignments PmJobAssignmentDT = PmJobAssignmentAccess.LoadViaPPartner(APartnerKey, AReadTransaction); if (PmJobAssignmentDT.Rows.Count > 0) { foreach (DataRow DR in PmJobAssignmentDT.Rows) { JobAssiStaffDataCombDR = AIndividualDataDS.JobAssignmentStaffDataCombined.NewRowTyped(false); JobAssiStaffDataCombDR.Key = JobAssiStaffDataCombKey++; JobAssiStaffDataCombDR.PartnerKey = APartnerKey; PmJobAssignmentDR = (PmJobAssignmentRow)DR; if (PmJobAssignmentDR.UnitKey != 0) { PUnitDT = PUnitAccess.LoadByPrimaryKey(PmJobAssignmentDR.UnitKey, AReadTransaction); JobAssiStaffDataCombDR.FieldKey = PmJobAssignmentDR.UnitKey; JobAssiStaffDataCombDR.FieldName = PUnitDT[0].UnitName; } else { JobAssiStaffDataCombDR.FieldKey = 0; JobAssiStaffDataCombDR.FieldName = "[None]"; } JobAssiStaffDataCombDR.Position = PmJobAssignmentDR.PositionName; JobAssiStaffDataCombDR.FromDate = PmJobAssignmentDR.FromDate; JobAssiStaffDataCombDR.ToDate = PmJobAssignmentDR.ToDate; AIndividualDataDS.JobAssignmentStaffDataCombined.Rows.Add(JobAssiStaffDataCombDR); } } } #endregion #region Church Info SummaryDR.ChurchName = StrNotAvailable; SummaryDR.ChurchAddress = StrNotAvailable; SummaryDR.ChurchPrimaryPhoneNumber = StrNotAvailable; SummaryDR.ChurchPastor = StrNotAvailable; SummaryDR.ChurchPastorsPrimaryPhoneNumber = StrNotAvailable; SummaryDR.NumberOfShownSupportingChurchPastors = 0; // Find SUPPCHURCH Relationship PartnerRelationshipDT = PPartnerRelationshipAccess.LoadUsingTemplate(new TSearchCriteria[] { new TSearchCriteria(PPartnerRelationshipTable.GetRelationKeyDBName(), APartnerKey), new TSearchCriteria(PPartnerRelationshipTable.GetRelationNameDBName(), "SUPPCHURCH") }, AReadTransaction); SummaryDR.NumberOfShownSupportingChurches = PartnerRelationshipDT.Rows.Count; if (PartnerRelationshipDT.Rows.Count > 0) { ChurchPartnerKey = PartnerRelationshipDT[0].PartnerKey; // Load Church Partner PartnerDT = PPartnerAccess.LoadByPrimaryKey(ChurchPartnerKey, AReadTransaction); if (PartnerDT.Rows.Count > 0) { PartnerDR = PartnerDT[0]; // Church Name if (PartnerDR.PartnerShortName != String.Empty) { SummaryDR.ChurchName = PartnerDR.PartnerShortName; } #region Church Address and Phone ServerCalculations.DetermineBestAddress(PartnerRelationshipDT[0].PartnerKey, out PartnerLocationDR, out LocationDR); if (LocationDR != null) { SummaryDR.ChurchAddress = Calculations.DetermineLocationString(LocationDR, Calculations.TPartnerLocationFormatEnum.plfCommaSeparated); } if (TContactDetailsAggregate.GetPrimaryPhoneNumber(PartnerRelationshipDT[0].PartnerKey, out PhoneNumber)) { SummaryDR.ChurchPrimaryPhoneNumber = PhoneNumber ?? StrNotAvailable; } else { SummaryDR.ChurchPrimaryPhoneNumber = StrNotAvailable; } #endregion #region Pastor // Find PASTOR Relationship PartnerRelationshipDT.Rows.Clear(); PartnerRelationshipDT = PPartnerRelationshipAccess.LoadUsingTemplate(new TSearchCriteria[] { new TSearchCriteria(PPartnerRelationshipTable.GetPartnerKeyDBName(), ChurchPartnerKey), new TSearchCriteria(PPartnerRelationshipTable.GetRelationNameDBName(), "PASTOR") }, AReadTransaction); SummaryDR.NumberOfShownSupportingChurchPastors = PartnerRelationshipDT.Rows.Count; if (PartnerRelationshipDT.Rows.Count > 0) { // Load PASTOR Partner PartnerDT = PPartnerAccess.LoadByPrimaryKey(PartnerRelationshipDT[0].RelationKey, AReadTransaction); if (PartnerDT.Rows.Count > 0) { PartnerDR = PartnerDT[0]; // Pastor's Name if (PartnerDR.PartnerShortName != String.Empty) { SummaryDR.ChurchPastor = PartnerDR.PartnerShortName; } #region Pastor's Phone if (TContactDetailsAggregate.GetPrimaryPhoneNumber(PartnerRelationshipDT[0].RelationKey, out PhoneNumber)) { SummaryDR.ChurchPastorsPrimaryPhoneNumber = PhoneNumber ?? StrNotAvailable; } else { SummaryDR.ChurchPastorsPrimaryPhoneNumber = StrNotAvailable; } #endregion } } #endregion } } #endregion // Add Summary DataRow to Summary DataTable SummaryDT.Rows.Add(SummaryDR); // Add Row to 'SummaryData' DataTable in Typed DataSet 'IndividualDataTDS' AIndividualDataDS.Merge(SummaryDT); }