/// <summary> /// Determines whether a PERSON has one or more 'Supporting Church' Relationship(s). /// </summary> /// <param name="ASupportingChurchesPartnerKeys">PartnerKeys of 'Supporting Churches'.</param> /// <returns>void</returns> private void DetermineChurchRelationships(out long[] ASupportingChurchesPartnerKeys) { DataRow[] SupportingChurches; // Initialise out Argument ASupportingChurchesPartnerKeys = new long[0]; SupportingChurches = FMainDS.Tables[PPartnerRelationshipTable.GetTableName()].Select( PPartnerRelationshipTable.GetRelationNameDBName() + "= 'SUPPCHURCH'"); if (SupportingChurches != null) { ASupportingChurchesPartnerKeys = new long[SupportingChurches.Length]; for (int Counter = 0; Counter < SupportingChurches.Length; Counter++) { ASupportingChurchesPartnerKeys[Counter] = (long)SupportingChurches[Counter][PPartnerRelationshipTable.GetPartnerKeyDBName()]; } } }
/// <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); }