Пример #1
0
        /// <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);
        }
Пример #2
0
        /// <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);
        }