/// <summary>todoComment</summary> public void SpecialInitUserControl() { // Set up screen logic FLogic.MultiTableDS = (PartnerEditTDS)FMainDS; FLogic.PartnerEditUIConnector = FPartnerEditUIConnector; FLogic.LoadDataOnDemand(); grdDetails.Columns.Clear(); grdDetails.AddTextColumn("Description", FMainDS.PPartnerRelationship.ColumnDisplayRelationDescription); grdDetails.AddPartnerKeyColumn("Partner Key", FMainDS.PPartnerRelationship.Columns["OtherPartnerKey"]); grdDetails.AddTextColumn("Partner Name", FMainDS.PPartnerRelationship.Columns[PartnerEditTDSPPartnerRelationshipTable.GetPartnerShortNameDBName()]); grdDetails.AddTextColumn("Class", FMainDS.PPartnerRelationship.Columns[PartnerEditTDSPPartnerRelationshipTable.GetPartnerClassDBName()]); grdDetails.AddTextColumn("Comment", FMainDS.PPartnerRelationship.Columns[PPartnerRelationshipTable.GetCommentDBName()]); OnHookupDataChange(new THookupPartnerEditDataChangeEventArgs(TPartnerEditTabPageEnum.petpPartnerRelationships)); // Hook up DataSavingStarted Event to be able to run code before SaveChanges is doing anything FPetraUtilsObject.DataSavingStarted += new TDataSavingStartHandler(this.DataSavingStarted); // hook up partner changed event for partner key and relation key so grid can be updated when new record is created // where data did not already come from server txtPPartnerRelationshipPartnerKey.ValueChanged += new TDelegatePartnerChanged(txtPPartnerRelationshipPartnerKey_ValueChanged); txtPPartnerRelationshipRelationKey.ValueChanged += new TDelegatePartnerChanged(txtPPartnerRelationshipRelationKey_ValueChanged); if (grdDetails.Rows.Count > 1) { grdDetails.SelectRowInGrid(1); ShowDetails(1); // do this as for some reason details are not automatically show here at the moment } else { btnEditOtherPartner.Enabled = false; } }
/// <summary> /// Calls the normal ShowData() Method and then performs the rest of the /// setting up of the data that is shown in the screen. /// </summary> /// <returns>void</returns> private void SpecialShowData() { ShowData((PPersonRow)FMainDS.PPerson.Rows[0]); // Check for unexpected condition... if (FMainDS.SummaryData.Rows.Count == 0) { MessageBox.Show("FMainDS.SummaryData holds NO ROWS!", DEV_FIX); } // Show note about multiple Churches/Pastors, if applicable SetupMultipleRecordsInfoText(); // Setup Jobs/Commitments Grid DataView myDataView = FMainDS.JobAssignmentStaffDataCombined.DefaultView; myDataView.AllowNew = false; myDataView.Sort = PmJobAssignmentTable.GetFromDateDBName() + " DESC"; grdDetails.DataSource = new DevAge.ComponentModel.BoundDataView(myDataView); // Determine the 'Primary Phone Number' and the 'Primary E-mail Address' of the PERSON if (FMainDS.Tables[PPartnerAttributeTable.GetTableName()] != null) { DeterminePrimaryEmailAndPrimaryPhone(out FPhoneOfPerson, out FEmailOfPerson); } // Record current relationship(s) that are supporting Church(es) of the PERSON if (FMainDS.Tables[PPartnerRelationshipTable.GetTableName()] != null) { DetermineChurchRelationships(out FSupportingChurchesPartnerKeys); } }
/// <summary> /// Called when data got saved in the screen. This Method takes over changed data /// into FMainDS, which is different than the Partner Edit screen's FMainDS, in /// order to have current data on which decisions on whether to refresh certain /// parts of the 'Overview' need to be updated. /// </summary> /// <param name="APartnerAttributesOrRelationsChanged">NOT USED IN THIS CONTEXT! (Set to true by the SaveChanges Method /// of the Partner Edit screen if PartnerAttributes or Relationships have changed.)</param> public void RefreshPersonnelDataAfterMerge(bool APartnerAttributesOrRelationsChanged) { // // Need to merge Tables from PartnerEditTDS into IndividualDataTDS so the updated s_modification_id_t of modififed Rows is held correctly in IndividualDataTDS, too! // // ...but first empty relevant DataTables to ensure that DataRows that got deleted in FPartnerEditTDS are reflected in FMainDS (just performing a Merge wouldn't remove them!) if (FMainDS.Tables.Contains(PPartnerLocationTable.GetTableName())) { FMainDS.Tables[PPartnerLocationTable.GetTableName()].Rows.Clear(); } if (FMainDS.Tables.Contains(PLocationTable.GetTableName())) { FMainDS.Tables[PLocationTable.GetTableName()].Rows.Clear(); } if (FMainDS.Tables.Contains(PPartnerRelationshipTable.GetTableName())) { FMainDS.Tables[PPartnerRelationshipTable.GetTableName()].Rows.Clear(); } // Now perform the Merge operation FMainDS.Merge(FPartnerEditTDS); // Call AcceptChanges on IndividualDataTDS so that we don't have any changed data anymore (this is done to PartnerEditTDS, too, after this Method returns)! FMainDS.AcceptChanges(); }
private void ShowEmergencyContacts(object sender, EventArgs e) { string contactFor = string.Empty; string primaryContact = Catalog.GetString("PRIMARY EMERGENCY CONTACT") + Environment.NewLine + Environment.NewLine; string secondaryContact = Catalog.GetString("SECONDARY EMERGENCY CONTACT") + Environment.NewLine + Environment.NewLine; Int64 primaryContactKey = 0; Int64 secondaryContactKey = 0; if ((FMainDS.PPerson != null) && (FMainDS.PPerson.Rows.Count > 0)) { PPersonRow row = (PPersonRow)FMainDS.PPerson.Rows[0]; contactFor = String.Format(Catalog.GetString("Emergency Contact Information For: {0} {1} {2} [{3:0000000000}]"), row.Title, row.FirstName, row.FamilyName, row.PartnerKey); FPetraUtilsObject.GetForm().Cursor = Cursors.WaitCursor; PPartnerRelationshipTable relationshipTable = TRemote.MPartner.Partner.WebConnectors.GetPartnerRelationships(row.PartnerKey); FPetraUtilsObject.GetForm().Cursor = Cursors.Default; for (int i = 0; i < relationshipTable.Rows.Count; i++) { PPartnerRelationshipRow relationshipRow = (PPartnerRelationshipRow)relationshipTable.Rows[i]; if (string.Compare(relationshipRow.RelationName, "EMER-1", true) == 0) { ParseEmergencyContactData(ref primaryContact, relationshipRow); primaryContactKey = relationshipRow.PartnerKey; } else if (string.Compare(relationshipRow.RelationName, "EMER-2", true) == 0) { ParseEmergencyContactData(ref secondaryContact, relationshipRow); secondaryContactKey = relationshipRow.PartnerKey; } } } if (primaryContactKey == 0) { primaryContact += Catalog.GetString("No primary contact"); } if (secondaryContactKey == 0) { secondaryContact += Catalog.GetString("No secondary contact"); } if ((primaryContactKey != 0) || (secondaryContactKey != 0)) { // Show the emergency contacts dialog and pass it the inofrmation we have found TFrmEmergencyContactsDialog dlg = new TFrmEmergencyContactsDialog(FPetraUtilsObject.GetCallerForm()); dlg.SetParameters(contactFor, primaryContact, secondaryContact, primaryContactKey, secondaryContactKey); dlg.Show(); } else { MessageBox.Show(Catalog.GetString("There is no emergency contact information for this person."), Catalog.GetString("Emergency Contacts"), MessageBoxButtons.OK, MessageBoxIcon.Information); } }
/// <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> /// Called when data got saved in the screen. Performs a check whether reloading /// of the 'SummaryData' is necessary to reflect changes that were done elsewhere /// in the Partner Edit screen and which just got saved. /// </summary> /// <returns>void</returns> public void CheckForRefreshOfDisplayedData(bool AJobAndStaffDataGridNeedsRefresh) { bool RefreshNecessary = false; string PhoneOfPerson; string EmailOfPerson; if (!AJobAndStaffDataGridNeedsRefresh) { Int64[] SupportingChurchesPartnerKeys = new long[0]; if (FMainDS.Tables[PPartnerAttributeTable.GetTableName()] != null) { // Check for change of the 'Primary Phone Number' and the 'Primary E-mail Address' of the PERSON DeterminePrimaryEmailAndPrimaryPhone(out PhoneOfPerson, out EmailOfPerson); if ((PhoneOfPerson != FPhoneOfPerson) || (EmailOfPerson != FEmailOfPerson)) { RefreshNecessary = true; } } if (FMainDS.Tables[PPartnerRelationshipTable.GetTableName()] != null) { // Check for change in supporting Church/es relationship(s) DetermineChurchRelationships(out SupportingChurchesPartnerKeys); if ((FSupportingChurchesPartnerKeys == null) || (FSupportingChurchesPartnerKeys.Length != SupportingChurchesPartnerKeys.Length)) { RefreshNecessary = true; } else { for (int Counter = 0; Counter < SupportingChurchesPartnerKeys.Length; Counter++) { if (SupportingChurchesPartnerKeys[Counter] != FSupportingChurchesPartnerKeys[Counter]) { RefreshNecessary = true; } } } } } else { RefreshNecessary = true; } if (RefreshNecessary) { // Call WebConnector to retrieve SummaryData afresh! IndividualDataTDS FillDS = new IndividualDataTDS(); FillDS.Merge(FMainDS.MiscellaneousData); TRemote.MPersonnel.Person.DataElements.WebConnectors.GetSummaryData(FMainDS.PPerson[0].PartnerKey, ref FillDS); FMainDS.SummaryData.Rows.Clear(); FMainDS.Merge(FillDS.SummaryData); FMainDS.JobAssignmentStaffDataCombined.Rows.Clear(); FMainDS.Merge(FillDS.JobAssignmentStaffDataCombined); // Refresh the displayed data SpecialShowData(); } }
/// <summary> /// Add the address details of the supporting church of a partner to the results /// </summary> /// <param name="APartnerKey">The partner key of whom the supporting church details should be added</param> /// <returns></returns> private bool GetChurch(Int64 APartnerKey) { PPartnerRelationshipTable RelationshipTable; PPartnerTable ChurchTable; string PhoneNumber; string EmailAddress; Dictionary <String, String> GatheredResults = new Dictionary <String, String>(); PPartnerRelationshipRow TemplateRow = new PPartnerRelationshipTable().NewRowTyped(false); TemplateRow.RelationKey = APartnerKey; TemplateRow.RelationName = "SUPPCHURCH"; RelationshipTable = PPartnerRelationshipAccess.LoadUsingTemplate(TemplateRow, situation.GetDatabaseConnection().Transaction); bool IsFirstAddress = true; foreach (PPartnerRelationshipRow Row in RelationshipTable.Rows) { ChurchTable = PPartnerAccess.LoadByPrimaryKey(Row.PartnerKey, situation.GetDatabaseConnection().Transaction); if (ChurchTable.Rows.Count < 1) { continue; } PPartnerLocationRow PartnerLocationRow; PLocationTable LocationTable; if (!TRptUserFunctionsPartner.GetPartnerBestAddressRow(Row.PartnerKey, situation, out PartnerLocationRow)) { continue; } LocationTable = PLocationAccess.LoadByPrimaryKey(PartnerLocationRow.SiteKey, PartnerLocationRow.LocationKey, situation.GetDatabaseConnection().Transaction); if (LocationTable.Rows.Count < 1) { continue; } if (IsFirstAddress) { GatheredResults.Add("Church-Name", ((PPartnerRow)ChurchTable.Rows[0]).PartnerShortName); } else { GatheredResults["Church-Name"] += ", " + ((PPartnerRow)ChurchTable.Rows[0]).PartnerShortName + " "; } // Add this church address to the results // the variables will be something like Church-PostalCode, Church-StreetName // get the location details into the parameters foreach (DataColumn col in LocationTable.Columns) { if (IsFirstAddress) { GatheredResults.Add("Church-" + StringHelper.UpperCamelCase(col.ColumnName, true, true), LocationTable.Rows[0][col.ColumnName].ToString()); } else { GatheredResults["Church-" + StringHelper.UpperCamelCase(col.ColumnName, true, true)] += ", " + LocationTable.Rows[0][col.ColumnName].ToString(); } } if (IsFirstAddress) { // also put the phone number and email etc into the parameters TContactDetailsAggregate.GetPrimaryEmailAndPrimaryPhone(Row.PartnerKey, out PhoneNumber, out EmailAddress); // Add Calculation Parameter for 'Primary Email Address' (String.Empty is supplied if the Partner hasn't got one) situation.GetParameters().AddCalculationParameter("Church-EmailAddress", new TVariant(EmailAddress ?? String.Empty)); // Add Calculation Parameter for 'Primary Phone Number' (String.Empty is supplied if the Partner hasn't got one) situation.GetParameters().AddCalculationParameter("Church-Telephone", new TVariant(PhoneNumber ?? String.Empty)); // At present we no longer support the reporting of the following, so we set those Calculation Parameters to String.Empty GatheredResults.Add("Church-FaxNumber", String.Empty); GatheredResults.Add("Church-MobileNumber", String.Empty); GatheredResults.Add("Church-AlternateTelephone", String.Empty); } IsFirstAddress = false; } if (IsFirstAddress) { situation.GetParameters().RemoveVariable("Church-Telephone"); situation.GetParameters().RemoveVariable("Church-FaxNumber"); situation.GetParameters().RemoveVariable("Church-EmailAddress"); situation.GetParameters().RemoveVariable("Church-MobileNumber"); situation.GetParameters().RemoveVariable("Church-AlternateTelephone"); situation.GetParameters().RemoveVariable("Church-Name"); situation.GetParameters().RemoveVariable("Church-Locality"); situation.GetParameters().RemoveVariable("Church-Address3"); situation.GetParameters().RemoveVariable("Church-City"); situation.GetParameters().RemoveVariable("Church-CountryCode"); situation.GetParameters().RemoveVariable("Church-County"); situation.GetParameters().RemoveVariable("Church-PostalCode"); situation.GetParameters().RemoveVariable("Church-StreetName"); } else { foreach (KeyValuePair <String, String> kvp in GatheredResults) { situation.GetParameters().Add(kvp.Key, new TVariant(kvp.Value)); } } return(true); }
private static bool CanChurchPartnerBeDeleted(Int64 APartnerKey, TDBTransaction ATransaction, out String ADisplayMessage) { ADisplayMessage = ""; // make sure this is not a supporting church PPartnerRelationshipTable PartnerRelationshipTemplateTable = new PPartnerRelationshipTable(); PPartnerRelationshipRow PartnerRelationshipTemplateRow; StringCollection TemplateOperators; PartnerRelationshipTemplateRow = (PPartnerRelationshipRow)PartnerRelationshipTemplateTable.NewRow(); PartnerRelationshipTemplateRow.PartnerKey = APartnerKey; PartnerRelationshipTemplateRow.RelationName = "SUPPCHURCH"; TemplateOperators = new StringCollection(); TemplateOperators.Add("="); if (PPartnerRelationshipAccess.CountUsingTemplate(PartnerRelationshipTemplateRow, TemplateOperators, ATransaction) > 0) { ADisplayMessage = Catalog.GetString("Unable to delete a supporting church."); return false; } return true; }
/// <summary> /// Loads Partner Types Data from Petra Server into FMainDS. /// </summary> /// <returns>true if successful, otherwise false.</returns> public Boolean LoadDataOnDemand() { Boolean ReturnValue; DataColumn ForeignTableColumn; PRelationTable relationTable; Boolean NoAcceptChangesNeeded = false; // Load Partner Types, if not already loaded try { // Make sure that Typed DataTables are already there at Client side if (FMainDS.PPartnerRelationship == null) { FMainDS.Tables.Add(new PartnerEditTDSPPartnerRelationshipTable()); FMainDS.InitVars(); } else { // special case: if there are already relations on the client before server data is // loaded then don't call AcceptChanges later. This is the case for a newly created // Person record when a relation to the Family record is automatically created but // not yet saved to the database (therefore it appears in the local data sets but not // the one's retrieved from the database) if (FMainDS.PPartnerRelationship.Rows.Count > 0) { NoAcceptChangesNeeded = true; } } if (TClientSettings.DelayedDataLoading) { FMainDS.Merge(FPartnerEditUIConnector.GetDataPartnerRelationships()); // Make DataRows unchanged if ((FMainDS.PPartnerRelationship.Rows.Count > 0) && !NoAcceptChangesNeeded) { FMainDS.PPartnerRelationship.AcceptChanges(); } } // fill extra fields in PartnerRelationship table for description and reciprocal description // so the expression can later on decide which value to use in each case relationTable = (PRelationTable)TDataCache.TMPartner.GetCacheablePartnerTable(TCacheablePartnerTablesEnum.RelationList); PRelationRow relationRow; PartnerEditTDSPPartnerRelationshipRow relationshipRow; foreach (DataRow row in FMainDS.PPartnerRelationship.Rows) { relationshipRow = (PartnerEditTDSPPartnerRelationshipRow)row; relationRow = (PRelationRow)relationTable.Rows.Find(relationshipRow.RelationName); if (relationRow != null) { relationshipRow.RelationDescription = relationRow.RelationDescription; relationshipRow.ReciprocalRelationDescription = relationRow.ReciprocalDescription; } } // Relations are not automatically enabled. Need to enable them here in order to use for columns. FMainDS.EnableRelations(); // add column to display the other partner key depending on direction of relationship ForeignTableColumn = new DataColumn(); ForeignTableColumn.DataType = System.Type.GetType("System.Int64"); ForeignTableColumn.ColumnName = "OtherPartnerKey"; ForeignTableColumn.Expression = "IIF(" + PPartnerRelationshipTable.GetPartnerKeyDBName() + "=" + ((PPartnerRow)FMainDS.PPartner.Rows[0]).PartnerKey.ToString() + "," + PPartnerRelationshipTable.GetRelationKeyDBName() + "," + PPartnerRelationshipTable.GetPartnerKeyDBName() + ")"; FMainDS.PPartnerRelationship.Columns.Add(ForeignTableColumn); // make sure that description column takes the correct description (normal or reciprocal) FMainDS.PPartnerRelationship.ColumnDisplayRelationDescription.Expression = "IIF(" + PPartnerRelationshipTable.GetPartnerKeyDBName() + "=" + ((PPartnerRow)FMainDS.PPartner.Rows[0]).PartnerKey.ToString() + "," + FMainDS.PPartnerRelationship.ColumnRelationDescription + "," + FMainDS.PPartnerRelationship.ColumnReciprocalRelationDescription + ")"; if (FMainDS.PPartnerRelationship.Rows.Count != 0) { ReturnValue = true; } else { ReturnValue = false; } } catch (System.NullReferenceException) { return(false); } catch (Exception) { throw; } return(ReturnValue); }
/// <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); }
/// <summary> /// Add the address details of the supporting church of a partner to the results /// </summary> /// <param name="APartnerKey">The partner key of whom the supporting church details should be added</param> /// <returns></returns> private bool GetChurch(Int64 APartnerKey) { PPartnerRelationshipTable RelationshipTable; PPartnerTable ChurchTable; string PhoneNumber; string EmailAddress; Dictionary <String, String>GatheredResults = new Dictionary <String, String>(); PPartnerRelationshipRow TemplateRow = new PPartnerRelationshipTable().NewRowTyped(false); TemplateRow.RelationKey = APartnerKey; TemplateRow.RelationName = "SUPPCHURCH"; RelationshipTable = PPartnerRelationshipAccess.LoadUsingTemplate(TemplateRow, situation.GetDatabaseConnection().Transaction); bool IsFirstAddress = true; foreach (PPartnerRelationshipRow Row in RelationshipTable.Rows) { ChurchTable = PPartnerAccess.LoadByPrimaryKey(Row.PartnerKey, situation.GetDatabaseConnection().Transaction); if (ChurchTable.Rows.Count < 1) { continue; } PPartnerLocationRow PartnerLocationRow; PLocationTable LocationTable; if (!TRptUserFunctionsPartner.GetPartnerBestAddressRow(Row.PartnerKey, situation, out PartnerLocationRow)) { continue; } LocationTable = PLocationAccess.LoadByPrimaryKey(PartnerLocationRow.SiteKey, PartnerLocationRow.LocationKey, situation.GetDatabaseConnection().Transaction); if (LocationTable.Rows.Count < 1) { continue; } if (IsFirstAddress) { GatheredResults.Add("Church-Name", ((PPartnerRow)ChurchTable.Rows[0]).PartnerShortName); } else { GatheredResults["Church-Name"] += ", " + ((PPartnerRow)ChurchTable.Rows[0]).PartnerShortName + " "; } // Add this church address to the results // the variables will be something like Church-PostalCode, Church-StreetName // get the location details into the parameters foreach (DataColumn col in LocationTable.Columns) { if (IsFirstAddress) { GatheredResults.Add("Church-" + StringHelper.UpperCamelCase(col.ColumnName, true, true), LocationTable.Rows[0][col.ColumnName].ToString()); } else { GatheredResults["Church-" + StringHelper.UpperCamelCase(col.ColumnName, true, true)] += ", " + LocationTable.Rows[0][col.ColumnName].ToString(); } } if (IsFirstAddress) { // also put the phone number and email etc into the parameters TContactDetailsAggregate.GetPrimaryEmailAndPrimaryPhone(Row.PartnerKey, out PhoneNumber, out EmailAddress); // Add Calculation Parameter for 'Primary Email Address' (String.Empty is supplied if the Partner hasn't got one) situation.GetParameters().AddCalculationParameter("Church-EmailAddress", new TVariant(EmailAddress ?? String.Empty)); // Add Calculation Parameter for 'Primary Phone Number' (String.Empty is supplied if the Partner hasn't got one) situation.GetParameters().AddCalculationParameter("Church-Telephone", new TVariant(PhoneNumber ?? String.Empty)); // At present we no longer support the reporting of the following, so we set those Calculation Parameters to String.Empty GatheredResults.Add("Church-FaxNumber", String.Empty); GatheredResults.Add("Church-MobileNumber", String.Empty); GatheredResults.Add("Church-AlternateTelephone", String.Empty); } IsFirstAddress = false; } if (IsFirstAddress) { situation.GetParameters().RemoveVariable("Church-Telephone"); situation.GetParameters().RemoveVariable("Church-FaxNumber"); situation.GetParameters().RemoveVariable("Church-EmailAddress"); situation.GetParameters().RemoveVariable("Church-MobileNumber"); situation.GetParameters().RemoveVariable("Church-AlternateTelephone"); situation.GetParameters().RemoveVariable("Church-Name"); situation.GetParameters().RemoveVariable("Church-Locality"); situation.GetParameters().RemoveVariable("Church-Address3"); situation.GetParameters().RemoveVariable("Church-City"); situation.GetParameters().RemoveVariable("Church-CountryCode"); situation.GetParameters().RemoveVariable("Church-County"); situation.GetParameters().RemoveVariable("Church-PostalCode"); situation.GetParameters().RemoveVariable("Church-StreetName"); } else { foreach (KeyValuePair <String, String>kvp in GatheredResults) { situation.GetParameters().Add(kvp.Key, new TVariant(kvp.Value)); } } return true; }
/// <summary> /// Add the address details of the supporting church of a partner to the results /// </summary> /// <param name="APartnerKey">The partner key of whom the supporting church details should be added</param> /// <returns></returns> private bool GetChurch(Int64 APartnerKey) { PPartnerRelationshipTable RelationshipTable; PPartnerTable ChurchTable; Dictionary <String, String> GatheredResults = new Dictionary <String, String>(); PPartnerRelationshipRow TemplateRow = new PPartnerRelationshipTable().NewRowTyped(false); TemplateRow.RelationKey = APartnerKey; TemplateRow.RelationName = "SUPPCHURCH"; RelationshipTable = PPartnerRelationshipAccess.LoadUsingTemplate(TemplateRow, situation.GetDatabaseConnection().Transaction); bool IsFirstAddress = true; foreach (PPartnerRelationshipRow Row in RelationshipTable.Rows) { ChurchTable = PPartnerAccess.LoadByPrimaryKey(Row.PartnerKey, situation.GetDatabaseConnection().Transaction); if (ChurchTable.Rows.Count < 1) { continue; } PPartnerLocationRow PartnerLocationRow; PLocationTable LocationTable; if (!TRptUserFunctionsPartner.GetPartnerBestAddressRow(Row.PartnerKey, situation, out PartnerLocationRow)) { continue; } LocationTable = PLocationAccess.LoadByPrimaryKey(PartnerLocationRow.SiteKey, PartnerLocationRow.LocationKey, situation.GetDatabaseConnection().Transaction); if (LocationTable.Rows.Count < 1) { continue; } if (IsFirstAddress) { GatheredResults.Add("Church-Name", ((PPartnerRow)ChurchTable.Rows[0]).PartnerShortName); } else { GatheredResults["Church-Name"] += ", " + ((PPartnerRow)ChurchTable.Rows[0]).PartnerShortName + " "; } // Add this church address to the results // the variables will be something like Church-PostalCode, Church-StreetName // get the location details into the parameters foreach (DataColumn col in LocationTable.Columns) { if (IsFirstAddress) { GatheredResults.Add("Church-" + StringHelper.UpperCamelCase(col.ColumnName, true, true), LocationTable.Rows[0][col.ColumnName].ToString()); } else { GatheredResults["Church-" + StringHelper.UpperCamelCase(col.ColumnName, true, true)] += ", " + LocationTable.Rows[0][col.ColumnName].ToString(); } } // also put the phone number and email etc into the parameters String TelephoneNumber; String FaxNumber; if (PartnerLocationRow.Extension > 0) { TelephoneNumber = PartnerLocationRow.TelephoneNumber + PartnerLocationRow.Extension.ToString(); } else { TelephoneNumber = PartnerLocationRow.TelephoneNumber; } if (PartnerLocationRow.FaxExtension > 0) { FaxNumber = PartnerLocationRow.FaxNumber + PartnerLocationRow.FaxExtension.ToString(); } else { FaxNumber = PartnerLocationRow.FaxNumber; } if (IsFirstAddress) { GatheredResults.Add("Church-Telephone", TelephoneNumber); GatheredResults.Add("Church-FaxNumber", FaxNumber); GatheredResults.Add("Church-EmailAddress", PartnerLocationRow.EmailAddress); GatheredResults.Add("Church-MobileNumber", PartnerLocationRow.MobileNumber); GatheredResults.Add("Church-AlternateTelephone", PartnerLocationRow.AlternateTelephone); } else { GatheredResults["Church-Telephone"] += ", " + TelephoneNumber; GatheredResults["Church-FaxNumber"] += ", " + FaxNumber; GatheredResults["Church-EmailAddress"] += ", " + PartnerLocationRow.EmailAddress; GatheredResults["Church-MobileNumber"] += ", " + PartnerLocationRow.MobileNumber; GatheredResults["Church-AlternateTelephone"] += ", " + PartnerLocationRow.AlternateTelephone; } IsFirstAddress = false; } if (IsFirstAddress) { situation.GetParameters().RemoveVariable("Church-Telephone"); situation.GetParameters().RemoveVariable("Church-FaxNumber"); situation.GetParameters().RemoveVariable("Church-EmailAddress"); situation.GetParameters().RemoveVariable("Church-MobileNumber"); situation.GetParameters().RemoveVariable("Church-AlternateTelephone"); situation.GetParameters().RemoveVariable("Church-Name"); situation.GetParameters().RemoveVariable("Church-Locality"); situation.GetParameters().RemoveVariable("Church-Address3"); situation.GetParameters().RemoveVariable("Church-City"); situation.GetParameters().RemoveVariable("Church-CountryCode"); situation.GetParameters().RemoveVariable("Church-County"); situation.GetParameters().RemoveVariable("Church-PostalCode"); situation.GetParameters().RemoveVariable("Church-StreetName"); } else { foreach (KeyValuePair <String, String> kvp in GatheredResults) { situation.GetParameters().Add(kvp.Key, new TVariant(kvp.Value)); } } return(true); }
public static void FillFormDataFromPartner(Int64 APartnerKey, ref TFormDataPartner AFormDataPartner, TFormLetterInfo AFormLetterInfo, Int64 ASiteKey = 0, Int32 ALocationKey = 0) { TPartnerClass PartnerClass; String ShortName; TStdPartnerStatusCode PartnerStatusCode; Int64 FamilyKey = 0; TFormDataPartner formData = null; TDBTransaction ReadTransaction = null; DBAccess.GDBAccessObj.GetNewOrExistingAutoReadTransaction(IsolationLevel.ReadCommitted, TEnforceIsolationLevel.eilMinimum, ref ReadTransaction, delegate { if (MCommonMain.RetrievePartnerShortName(APartnerKey, out ShortName, out PartnerClass, out PartnerStatusCode, ReadTransaction)) { switch (PartnerClass) { case TPartnerClass.PERSON: formData = new TFormDataPerson(); formData.IsPersonRecord = true; break; default: formData = new TFormDataPartner(); formData.IsPersonRecord = false; break; } // set current date formData.CurrentDate = DateTime.Today; // retrieve general Partner information if (AFormLetterInfo.IsRetrievalRequested(TFormDataRetrievalSection.eGeneral)) { String SiteName; TPartnerClass SiteClass; if (TPartnerServerLookups.GetPartnerShortName(DomainManager.GSiteKey, out SiteName, out SiteClass)) { formData.RecordingField = SiteName; } } // retrieve general Partner information if (AFormLetterInfo.IsRetrievalRequested(TFormDataRetrievalSection.ePartner)) { PPartnerTable PartnerTable; PPartnerRow PartnerRow; PartnerTable = PPartnerAccess.LoadByPrimaryKey(APartnerKey, ReadTransaction); if (PartnerTable.Count > 0) { PartnerRow = (PPartnerRow)PartnerTable.Rows[0]; formData.PartnerKey = PartnerRow.PartnerKey.ToString("0000000000"); formData.Name = Calculations.FormatShortName(PartnerRow.PartnerShortName, eShortNameFormat.eReverseWithoutTitle); formData.ShortName = PartnerRow.PartnerShortName; formData.LocalName = PartnerRow.PartnerShortNameLoc; formData.AddresseeType = PartnerRow.AddresseeTypeCode; formData.LanguageCode = PartnerRow.LanguageCode; formData.Notes = PartnerRow.Comment; formData.ReceiptLetterFrequency = PartnerRow.ReceiptLetterFrequency; if (PartnerRow.PartnerShortName.Contains(",")) { formData.Title = Calculations.FormatShortName(PartnerRow.PartnerShortName, eShortNameFormat.eOnlyTitle); } else { formData.Title = ""; } } if (PartnerClass == TPartnerClass.PERSON) { PPersonTable PersonTable; PPersonRow PersonRow; PersonTable = PPersonAccess.LoadByPrimaryKey(APartnerKey, ReadTransaction); if (PersonTable.Count > 0) { PersonRow = (PPersonRow)PersonTable.Rows[0]; formData.FirstName = PersonRow.FirstName; formData.LastName = PersonRow.FamilyName; } } else if (PartnerClass == TPartnerClass.FAMILY) { PFamilyTable FamilyTable; PFamilyRow FamilyRow; FamilyTable = PFamilyAccess.LoadByPrimaryKey(APartnerKey, ReadTransaction); if (FamilyTable.Count > 0) { FamilyRow = (PFamilyRow)FamilyTable.Rows[0]; formData.FirstName = FamilyRow.FirstName; formData.LastName = FamilyRow.FamilyName; } } } // retrieve Person information if (AFormLetterInfo.IsRetrievalRequested(TFormDataRetrievalSection.ePerson) && (PartnerClass == TPartnerClass.PERSON) && (formData.GetType() == typeof(TFormDataPerson))) { PPersonTable PersonTable; PPersonRow PersonRow; TFormDataPerson PersonFormData = (TFormDataPerson)formData; PersonTable = PPersonAccess.LoadByPrimaryKey(APartnerKey, ReadTransaction); if (PersonTable.Count > 0) { PersonRow = (PPersonRow)PersonTable.Rows[0]; PersonFormData.Title = PersonRow.Title; PersonFormData.Decorations = PersonRow.Decorations; PersonFormData.MiddleName = PersonRow.MiddleName1; PersonFormData.PreferedName = PersonRow.PreferedName; PersonFormData.DateOfBirth = PersonRow.DateOfBirth; PersonFormData.Gender = PersonRow.Gender; PersonFormData.MaritalStatus = PersonRow.MaritalStatus; PersonFormData.OccupationCode = PersonRow.OccupationCode; if (!PersonRow.IsOccupationCodeNull() && (PersonRow.OccupationCode != "")) { // retrieve occupation description from occupation table TPartnerCacheable CachePopulator = new TPartnerCacheable(); POccupationTable OccupationTable = (POccupationTable)CachePopulator.GetCacheableTable(TCacheablePartnerTablesEnum.OccupationList); POccupationRow OccupationRow = (POccupationRow)OccupationTable.Rows.Find(new object[] { PersonRow.OccupationCode }); if (OccupationRow != null) { PersonFormData.Occupation = OccupationRow.OccupationDescription; } } // Get supporting church, if there is one. (Actually there may be more than one!) // The RelationKey should hold the PERSON key and PartnerKey should hold supporter key PPartnerRelationshipTable tmpTable = new PPartnerRelationshipTable(); PPartnerRelationshipRow templateRow = tmpTable.NewRowTyped(false); templateRow.RelationName = "SUPPCHURCH"; templateRow.RelationKey = APartnerKey; PPartnerRelationshipTable supportingChurchTable = PPartnerRelationshipAccess.LoadUsingTemplate(templateRow, ReadTransaction); int supportingChurchCount = supportingChurchTable.Rows.Count; // If the user has got RelationKey and PartnerKey back to front we will get no results PersonFormData.SendingChurchName = String.Empty; for (int i = 0; i < supportingChurchCount; i++) { // Go round each supporting church // Get the short name for the sending church // Foreign key constraint means that this row is bound to exist string churchName; TPartnerClass churchClass; TStdPartnerStatusCode churchStatus; long supportingChurchKey = ((PPartnerRelationshipRow)supportingChurchTable.Rows[i]).PartnerKey; if (MCommonMain.RetrievePartnerShortName(supportingChurchKey, out churchName, out churchClass, out churchStatus, ReadTransaction)) { // The church name can be empty but that would be unusual // churchClass should be CHURCH or ORGANISATION if everything is the right way round // but we do not check this - nor churchStatus if (churchName.Length == 0) { churchName = Catalog.GetString("Not available"); } if (supportingChurchCount > 1) { if (i > 0) { PersonFormData.SendingChurchName += Catalog.GetString(" AND "); } PersonFormData.SendingChurchName += String.Format("{0}: '{1}'", i + 1, churchName); } else { PersonFormData.SendingChurchName += String.Format("'{0}'", churchName); } } } // we need this for later in case we retrieve family members FamilyKey = PersonRow.FamilyKey; // retrieve Special Needs information if (AFormLetterInfo.IsRetrievalRequested(TFormDataRetrievalSection.eSpecialNeeds)) { PmSpecialNeedTable SpecialNeedTable; PmSpecialNeedRow SpecialNeedRow; SpecialNeedTable = PmSpecialNeedAccess.LoadViaPPerson(APartnerKey, ReadTransaction); if (SpecialNeedTable.Count > 0) { SpecialNeedRow = (PmSpecialNeedRow)SpecialNeedTable.Rows[0]; PersonFormData.DietaryNeeds = SpecialNeedRow.DietaryComment; PersonFormData.MedicalNeeds = SpecialNeedRow.MedicalComment; PersonFormData.OtherNeeds = SpecialNeedRow.OtherSpecialNeed; PersonFormData.Vegetarian = SpecialNeedRow.VegetarianFlag; } } // retrieve Personal Data information if (AFormLetterInfo.IsRetrievalRequested(TFormDataRetrievalSection.ePersonalData)) { PmPersonalDataTable PersonalDataTable; PmPersonalDataRow PersonalDataRow; PersonalDataTable = PmPersonalDataAccess.LoadViaPPerson(APartnerKey, ReadTransaction); if (PersonalDataTable.Count > 0) { PersonalDataRow = (PmPersonalDataRow)PersonalDataTable.Rows[0]; if (!PersonalDataRow.IsBelieverSinceYearNull() && (PersonalDataRow.BelieverSinceYear != 0)) { PersonFormData.YearsBeliever = (DateTime.Today.Year - PersonalDataRow.BelieverSinceYear).ToString(); } PersonFormData.CommentBeliever = PersonalDataRow.BelieverSinceComment; } } } } // retrieve Family member information if (AFormLetterInfo.IsRetrievalRequested(TFormDataRetrievalSection.eFamilyMember)) { // Retrieve family key for FAMILY class. In case of PERSON this has already been done earlier. if (PartnerClass == TPartnerClass.FAMILY) { FamilyKey = APartnerKey; } if (FamilyKey != 0) { PPersonTable FamilyMembersTable; TFormDataFamilyMember FamilyMemberRecord; String PersonShortName; TPartnerClass PersonClass; FamilyMembersTable = PPersonAccess.LoadViaPFamily(FamilyKey, ReadTransaction); foreach (PPersonRow PersonRow in FamilyMembersTable.Rows) { // only add this person if it is not the main record if (PersonRow.PartnerKey != APartnerKey) { FamilyMemberRecord = new TFormDataFamilyMember(); TPartnerServerLookups.GetPartnerShortName(PersonRow.PartnerKey, out PersonShortName, out PersonClass); FamilyMemberRecord.Name = PersonShortName; FamilyMemberRecord.DateOfBirth = PersonRow.DateOfBirth; formData.AddFamilyMember(FamilyMemberRecord); } } } } // retrieve Contact information if (AFormLetterInfo.IsRetrievalRequested(TFormDataRetrievalSection.eContact)) { string Phone; string Email; // retrieve primary phone and primary email TContactDetailsAggregate.GetPrimaryEmailAndPrimaryPhone(APartnerKey, out Phone, out Email); formData.PrimaryPhone = Phone; formData.PrimaryEmail = Email; // check for skype as it may not often be used // if there is more than one skype id then at the moment the first one found is used if (AFormLetterInfo.ContainsTag("Skype")) { PPartnerAttributeTable AttributeTable = PPartnerAttributeAccess.LoadViaPPartner(APartnerKey, ReadTransaction); foreach (PPartnerAttributeRow AttributeRow in AttributeTable.Rows) { if (AttributeRow.AttributeType == "Skype") // check if we can maybe use constant value instead of string { formData.Skype = AttributeRow.Value; break; } } } } // retrieve Location and formality information if (AFormLetterInfo.IsRetrievalRequested(TFormDataRetrievalSection.eLocation) || AFormLetterInfo.IsRetrievalRequested(TFormDataRetrievalSection.eLocationBlock) || AFormLetterInfo.IsRetrievalRequested(TFormDataRetrievalSection.eFormalGreetings)) { PLocationTable LocationTable; PLocationRow LocationRow; String CountryName = ""; if (ALocationKey == 0) { // no address set -> retrieve best address TAddressTools.GetBestAddress(APartnerKey, out LocationTable, out CountryName, ReadTransaction); } else { LocationTable = PLocationAccess.LoadByPrimaryKey(ASiteKey, ALocationKey, ReadTransaction); } if (LocationTable.Count > 0) { LocationRow = (PLocationRow)LocationTable.Rows[0]; formData.LocationKey = LocationRow.LocationKey; formData.Address1 = LocationRow.Locality; formData.AddressStreet2 = LocationRow.StreetName; formData.Address3 = LocationRow.Address3; formData.PostalCode = LocationRow.PostalCode; formData.County = LocationRow.County; formData.CountryName = CountryName; formData.City = LocationRow.City; formData.CountryCode = LocationRow.CountryCode; // retrieve country name from country table TCacheable CachePopulator = new TCacheable(); PCountryTable CountryTable = (PCountryTable)CachePopulator.GetCacheableTable(TCacheableCommonTablesEnum.CountryList); PCountryRow CountryRow = (PCountryRow)CountryTable.Rows.Find(new object[] { LocationRow.CountryCode }); if (CountryRow != null) { formData.CountryName = CountryRow.CountryName; formData.CountryInLocalLanguage = CountryRow.CountryNameLocal; } } // build address block (need to have retrieved location data beforehand) if (AFormLetterInfo.IsRetrievalRequested(TFormDataRetrievalSection.eLocationBlock)) { formData.AddressBlock = BuildAddressBlock(formData, AFormLetterInfo.AddressLayoutCode, PartnerClass, ReadTransaction); } // retrieve formality information (need to have retrieved country, language and addressee type beforehand) if (AFormLetterInfo.IsRetrievalRequested(TFormDataRetrievalSection.eFormalGreetings)) { String SalutationText; String ClosingText; InitializeFormality(AFormLetterInfo, ReadTransaction); AFormLetterInfo.RetrieveFormalityGreeting(formData, out SalutationText, out ClosingText); ResolveGreetingPlaceholders(formData, AFormLetterInfo, APartnerKey, ShortName, PartnerClass, ref SalutationText, ref ClosingText, ReadTransaction); formData.FormalSalutation = SalutationText; formData.FormalClosing = ClosingText; } } // retrieve Contact Log information if (AFormLetterInfo.IsRetrievalRequested(TFormDataRetrievalSection.eContactLog)) { PContactLogTable ContactLogTable; TFormDataContactLog ContactLogRecord; ContactLogTable = PContactLogAccess.LoadViaPPartnerPPartnerContact(APartnerKey, ReadTransaction); foreach (PContactLogRow ContactLogRow in ContactLogTable.Rows) { ContactLogRecord = new TFormDataContactLog(); ContactLogRecord.Contactor = ContactLogRow.Contactor; ContactLogRecord.Notes = ContactLogRow.ContactComment; formData.AddContactLog(ContactLogRecord); } } // retrieve Subscription information if (AFormLetterInfo.IsRetrievalRequested(TFormDataRetrievalSection.eSubscription)) { PSubscriptionTable SubscriptionTable; TFormDataSubscription SubscriptionRecord; SubscriptionTable = PSubscriptionAccess.LoadViaPPartnerPartnerKey(APartnerKey, ReadTransaction); foreach (PSubscriptionRow SubscriptionRow in SubscriptionTable.Rows) { SubscriptionRecord = new TFormDataSubscription(); SubscriptionRecord.PublicationCode = SubscriptionRow.PublicationCode; SubscriptionRecord.Status = SubscriptionRow.SubscriptionStatus; formData.AddSubscription(SubscriptionRecord); } } // retrieve banking information if (AFormLetterInfo.IsRetrievalRequested(TFormDataRetrievalSection.eBanking)) { PBankingDetailsUsageTable BankingDetailsUsageTable = new PBankingDetailsUsageTable(); PBankingDetailsUsageRow BankingDetailsUsageTemplateRow = BankingDetailsUsageTable.NewRowTyped(false); BankingDetailsUsageTemplateRow.PartnerKey = APartnerKey; BankingDetailsUsageTemplateRow.Type = MPartnerConstants.BANKINGUSAGETYPE_MAIN; BankingDetailsUsageTable = PBankingDetailsUsageAccess.LoadUsingTemplate(BankingDetailsUsageTemplateRow, ReadTransaction); if (BankingDetailsUsageTable.Count > 0) { // in this case there is a main bank account for this partner PBankingDetailsTable BankingDetailsTable; PBankingDetailsRow BankingDetailsRow; BankingDetailsTable = (PBankingDetailsTable)(PBankingDetailsAccess.LoadByPrimaryKey(((PBankingDetailsUsageRow)BankingDetailsUsageTable. Rows[0]). BankingDetailsKey, ReadTransaction)); if (BankingDetailsTable.Count > 0) { BankingDetailsRow = (PBankingDetailsRow)BankingDetailsTable.Rows[0]; formData.BankAccountName = BankingDetailsRow.AccountName; formData.BankAccountNumber = BankingDetailsRow.BankAccountNumber; formData.IBANUnformatted = BankingDetailsRow.Iban; //formData.IBANFormatted = ...; // now retrieve bank information PBankTable BankTable; PBankRow BankRow; BankTable = (PBankTable)(PBankAccess.LoadByPrimaryKey(BankingDetailsRow.BankKey, ReadTransaction)); if (BankTable.Count > 0) { BankRow = (PBankRow)BankTable.Rows[0]; formData.BankName = BankRow.BranchName; formData.BankBranchCode = BankRow.BranchCode; formData.BICSwiftCode = BankRow.Bic; } } } } if ((PartnerClass == TPartnerClass.PERSON) && (formData.GetType() == typeof(TFormDataPerson))) { // retrieve Passport information if (AFormLetterInfo.IsRetrievalRequested(TFormDataRetrievalSection.ePassport)) { PmPassportDetailsTable PassportTable; TFormDataPassport PassportRecord; PassportTable = PmPassportDetailsAccess.LoadViaPPerson(APartnerKey, ReadTransaction); foreach (PmPassportDetailsRow PassportRow in PassportTable.Rows) { PassportRecord = new TFormDataPassport(); PassportRecord.PassportName = PassportRow.FullPassportName; PassportRecord.NationalityCode = PassportRow.PassportNationalityCode; // retrieve country name from country table TCacheable CachePopulator = new TCacheable(); PCountryTable CountryTable = (PCountryTable)CachePopulator.GetCacheableTable(TCacheableCommonTablesEnum.CountryList); PCountryRow CountryRow = (PCountryRow)CountryTable.Rows.Find(new object[] { PassportRow.PassportNationalityCode }); if (CountryRow != null) { PassportRecord.NationalityName = CountryRow.CountryName; } PassportRecord.TypeCode = PassportRow.PassportDetailsType; // retrieve passport type name from type table TPersonnelCacheable PersonnelCachePopulator = new TPersonnelCacheable(); PtPassportTypeTable TypeTable = (PtPassportTypeTable)PersonnelCachePopulator.GetCacheableTable(TCacheablePersonTablesEnum.PassportTypeList); PtPassportTypeRow TypeRow = (PtPassportTypeRow)TypeTable.Rows.Find(new object[] { PassportRow.PassportDetailsType }); if (TypeRow != null) { PassportRecord.TypeDescription = TypeRow.Description; } // set number and nationality in main record (only for main passport or if there is just one) if (PassportRow.MainPassport || (PassportTable.Count == 1)) { ((TFormDataPerson)formData).PassportNumber = PassportRow.PassportNumber; ((TFormDataPerson)formData).PassportNationality = PassportRow.PassportNationalityCode; ((TFormDataPerson)formData).PassportName = PassportRow.FullPassportName; } PassportRecord.DateOfIssue = PassportRow.DateOfIssue; PassportRecord.PlaceOfIssue = PassportRow.PlaceOfIssue; PassportRecord.DateOfExpiry = PassportRow.DateOfExpiration; PassportRecord.PlaceOfBirth = PassportRow.PlaceOfBirth; ((TFormDataPerson)formData).AddPassport(PassportRecord); } } // retrieve Language information if (AFormLetterInfo.IsRetrievalRequested(TFormDataRetrievalSection.eLanguage)) { PmPersonLanguageTable PersonLanguageTable; TFormDataLanguage PersonLanguageRecord; PersonLanguageTable = PmPersonLanguageAccess.LoadViaPPerson(APartnerKey, ReadTransaction); foreach (PmPersonLanguageRow PersonLanguageRow in PersonLanguageTable.Rows) { PersonLanguageRecord = new TFormDataLanguage(); PersonLanguageRecord.Code = PersonLanguageRow.LanguageCode; // retrieve language name from language table TCacheable CachePopulator = new TCacheable(); PLanguageTable LanguageTable = (PLanguageTable)CachePopulator.GetCacheableTable(TCacheableCommonTablesEnum.LanguageCodeList); PLanguageRow LanguageRow = (PLanguageRow)LanguageTable.Rows.Find(new object[] { PersonLanguageRow.LanguageCode }); if (LanguageRow != null) { PersonLanguageRecord.Name = LanguageRow.LanguageDescription; } PersonLanguageRecord.Level = PersonLanguageRow.LanguageLevel.ToString(); // retrieve language level name from language level table TPersonnelCacheable CachePopulatorPersonnel = new TPersonnelCacheable(); PtLanguageLevelTable LanguageLevelTable = (PtLanguageLevelTable)CachePopulatorPersonnel.GetCacheableTable(TCacheablePersonTablesEnum.LanguageLevelList); PtLanguageLevelRow LanguageLevelRow = (PtLanguageLevelRow)LanguageLevelTable.Rows.Find(new object[] { PersonLanguageRow.LanguageLevel }); if (LanguageLevelRow != null) { PersonLanguageRecord.LevelDesc = LanguageLevelRow.LanguageLevelDescr; } PersonLanguageRecord.Comment = PersonLanguageRow.Comment; ((TFormDataPerson)formData).AddLanguage(PersonLanguageRecord); } } // retrieve Skill information if (AFormLetterInfo.IsRetrievalRequested(TFormDataRetrievalSection.eSkill)) { PmPersonSkillTable PersonSkillTable; TFormDataSkill PersonSkillRecord; PersonSkillTable = PmPersonSkillAccess.LoadViaPPerson(APartnerKey, ReadTransaction); foreach (PmPersonSkillRow PersonSkillRow in PersonSkillTable.Rows) { PersonSkillRecord = new TFormDataSkill(); PersonSkillRecord.Category = PersonSkillRow.SkillCategoryCode; PersonSkillRecord.Description = PersonSkillRow.DescriptionEnglish; // if no description in local language then use english PersonSkillRecord.DescriptionLocalOrDefault = PersonSkillRow.DescriptionLocal; if (PersonSkillRow.DescriptionLocal != "") { PersonSkillRecord.DescriptionLocalOrDefault = PersonSkillRow.DescriptionEnglish; } PersonSkillRecord.Level = PersonSkillRow.SkillLevel; // retrieve skill level name from skill level table TPersonnelCacheable CachePopulatorPersonnel = new TPersonnelCacheable(); PtSkillLevelTable SkillLevelTable = (PtSkillLevelTable)CachePopulatorPersonnel.GetCacheableTable(TCacheablePersonTablesEnum.SkillLevelList); PtSkillLevelRow SkillLevelRow = (PtSkillLevelRow)SkillLevelTable.Rows.Find(new object[] { PersonSkillRow.SkillLevel }); if (SkillLevelRow != null) { PersonSkillRecord.LevelDesc = SkillLevelRow.Description; } PersonSkillRecord.YearsExp = PersonSkillRow.YearsOfExperience; PersonSkillRecord.Professional = PersonSkillRow.ProfessionalSkill; PersonSkillRecord.Degree = PersonSkillRow.Degree; PersonSkillRecord.Comment = PersonSkillRow.Comment; ((TFormDataPerson)formData).AddSkill(PersonSkillRecord); } } // retrieve past work experience information if (AFormLetterInfo.IsRetrievalRequested(TFormDataRetrievalSection.eWorkExperience)) { TFormDataWorkExperience PersonExpRecord; String UnitShortName; TPartnerClass UnitClass; // retrieve applications for short term events String SqlStmt = TDataBase.ReadSqlFile("Personnel.FormLetters.GetAppTravelDates.sql"); OdbcParameter[] parameters = new OdbcParameter[1]; parameters[0] = new OdbcParameter("PartnerKey", OdbcType.BigInt); parameters[0].Value = APartnerKey; DataTable travelData = DBAccess.GDBAccessObj.SelectDT(SqlStmt, "TravelDates", ReadTransaction, parameters); for (int i = 0; i < travelData.Rows.Count; i++) { PersonExpRecord = new TFormDataWorkExperience(); if ((travelData.Rows[i][0]).GetType() == typeof(DateTime)) { PersonExpRecord.StartDate = (DateTime?)travelData.Rows[i][0]; } if ((travelData.Rows[i][1]).GetType() == typeof(DateTime)) { PersonExpRecord.EndDate = (DateTime?)travelData.Rows[i][1]; } PersonExpRecord.Organisation = ""; PersonExpRecord.Role = ""; PersonExpRecord.Category = ""; PersonExpRecord.SameOrg = true; PersonExpRecord.SimilarOrg = true; PersonExpRecord.Comment = ""; // check if unit exists and use unit name as location if (TPartnerServerLookups.GetPartnerShortName((Int64)travelData.Rows[i][2], out UnitShortName, out UnitClass)) { PersonExpRecord.Location = UnitShortName; } else { PersonExpRecord.Location = travelData.Rows[i][3].ToString(); } ((TFormDataPerson)formData).AddWorkExperience(PersonExpRecord); } // retrieve actual past experience records PmPastExperienceTable PersonExpTable; PersonExpTable = PmPastExperienceAccess.LoadViaPPerson(APartnerKey, ReadTransaction); foreach (PmPastExperienceRow PersonExpRow in PersonExpTable.Rows) { PersonExpRecord = new TFormDataWorkExperience(); PersonExpRecord.StartDate = PersonExpRow.StartDate; PersonExpRecord.EndDate = PersonExpRow.EndDate; PersonExpRecord.Location = PersonExpRow.PrevLocation; PersonExpRecord.Organisation = PersonExpRow.OtherOrganisation; PersonExpRecord.Role = PersonExpRow.PrevRole; PersonExpRecord.Category = PersonExpRow.Category; PersonExpRecord.SameOrg = PersonExpRow.PrevWorkHere; PersonExpRecord.SimilarOrg = PersonExpRow.PrevWork; PersonExpRecord.Comment = PersonExpRow.PastExpComments; ((TFormDataPerson)formData).AddWorkExperience(PersonExpRecord); } } } } }); AFormDataPartner = formData; }
/// <summary> /// Count the relationships /// </summary> /// <param name="ATable">table with subscriptions</param> /// <param name="ATotalRelationships">returns the total number of relationships</param> public static void CalculateTabCountsPartnerRelationships(PPartnerRelationshipTable ATable, out Int32 ATotalRelationships) { // Inspect only CurrentRows (this excludes Deleted DataRows) ATotalRelationships = new DataView(ATable, "", "", DataViewRowState.CurrentRows).Count; }
/// <summary> /// performs database changes to move person from current (old) family to new family record /// </summary> /// <param name="APersonKey"></param> /// <param name="AOldFamilyKey"></param> /// <param name="ANewFamilyKey"></param> /// <param name="AProblemMessage"></param> /// <returns>true if change of family completed successfully</returns> public static bool ChangeFamily(Int64 APersonKey, Int64 AOldFamilyKey, Int64 ANewFamilyKey, out String AProblemMessage) { bool Result = true; PFamilyTable OldFamilyDT; PFamilyTable NewFamilyDT; PPersonTable PersonDT; PPartnerRelationshipTable RelationshipDT; PPartnerRelationshipRow RelationshipRow; TPartnerFamilyIDHandling FamilyIDHandling; Int32 NewFamilyID; TDBTransaction Transaction = DBAccess.GDBAccessObj.BeginTransaction(IsolationLevel.Serializable); try { PersonDT = PPersonAccess.LoadByPrimaryKey(APersonKey, Transaction); FamilyIDHandling = new TPartnerFamilyIDHandling(); if (FamilyIDHandling.GetNewFamilyID_FamilyChange(ANewFamilyKey, PersonDT[0].FamilyId, out NewFamilyID, out AProblemMessage) == TFamilyIDSuccessEnum.fiError) { // this should not really happen but we cannot continue if it does Result = false; } if (Result) { // reset family id and family key for person PersonDT[0].FamilyId = NewFamilyID; PersonDT[0].FamilyKey = ANewFamilyKey; PPersonAccess.SubmitChanges(PersonDT, Transaction); // reset family members flag in old family if this person was the last family member if (PPersonAccess.CountViaPFamily(AOldFamilyKey, Transaction) == 0) { OldFamilyDT = PFamilyAccess.LoadByPrimaryKey(AOldFamilyKey, Transaction); OldFamilyDT[0].FamilyMembers = false; PFamilyAccess.SubmitChanges(OldFamilyDT, Transaction); } // remove relationships between person and old family PPartnerRelationshipAccess.DeleteByPrimaryKey(AOldFamilyKey, "FAMILY", APersonKey, Transaction); // set family members flag for new family as there is now at least one member NewFamilyDT = PFamilyAccess.LoadByPrimaryKey(ANewFamilyKey, Transaction); NewFamilyDT[0].FamilyMembers = true; PFamilyAccess.SubmitChanges(NewFamilyDT, Transaction); // create relationship between person and new family if ((!PPartnerRelationshipAccess.Exists(ANewFamilyKey, "FAMILY", APersonKey, Transaction))) { RelationshipDT = new PPartnerRelationshipTable(); RelationshipRow = RelationshipDT.NewRowTyped(true); RelationshipRow.PartnerKey = ANewFamilyKey; RelationshipRow.RelationKey = APersonKey; RelationshipRow.RelationName = "FAMILY"; RelationshipRow.Comment = "System Generated"; RelationshipDT.Rows.Add(RelationshipRow); PPartnerRelationshipAccess.SubmitChanges(RelationshipDT, Transaction); } } if (Result) { DBAccess.GDBAccessObj.CommitTransaction(); } else { DBAccess.GDBAccessObj.RollbackTransaction(); } } catch (Exception Exc) { TLogging.Log("An Exception occured during a change of a Family:" + Environment.NewLine + Exc.ToString()); DBAccess.GDBAccessObj.RollbackTransaction(); throw; } return Result; }