示例#1
0
        /// find the current best address for the partner
        public static bool GetBestAddress(Int64 APartnerKey,
                                          out PLocationTable AAddress,
                                          out string ACountryNameLocal,
                                          TDBTransaction ATransaction,
                                          bool AOnlySendMail = false)
        {
            AAddress          = null;
            ACountryNameLocal = "";

            DataSet PartnerLocationsDS = new DataSet();

            PartnerLocationsDS.Tables.Add(new PPartnerLocationTable());
            PartnerLocationsDS.Tables.Add(new PCountryTable());
            DataTable     PartnerLocationTable = PartnerLocationsDS.Tables[PPartnerLocationTable.GetTableName()];
            PCountryTable CountryTable         = (PCountryTable)PartnerLocationsDS.Tables[PCountryTable.GetTableName()];

            CountryTable.DefaultView.Sort = PCountryTable.GetCountryCodeDBName();

            // add special column BestAddress and Icon
            PartnerLocationTable.Columns.Add(new System.Data.DataColumn("BestAddress", typeof(Boolean)));
            PartnerLocationTable.Columns.Add(new System.Data.DataColumn("Icon", typeof(Int32)));

            // find all locations of the partner, put it into a dataset
            PPartnerLocationAccess.LoadViaPPartner(PartnerLocationsDS, APartnerKey, ATransaction);

            Calculations.DeterminePartnerLocationsDateStatus(PartnerLocationsDS);
            Calculations.DetermineBestAddress(PartnerLocationsDS);

            foreach (PPartnerLocationRow row in PartnerLocationTable.Rows)
            {
                if (AOnlySendMail && !Convert.ToBoolean(row[PPartnerLocationTable.GetSendMailDBName()]))
                {
                    // ignore addresses that are not set for receiving mail.
                    continue;
                }

                // find the row with BestAddress = 1
                if (Convert.ToInt32(row["BestAddress"]) == 1)
                {
                    // we also want the post address, need to load the p_location table:
                    AAddress = PLocationAccess.LoadByPrimaryKey(row.SiteKey, row.LocationKey, ATransaction);

                    // watch out for empty country codes
                    if (AAddress[0].CountryCode.Trim().Length > 0)
                    {
                        if (CountryTable.DefaultView.Find(AAddress[0].CountryCode) == -1)
                        {
                            CountryTable.Merge(PCountryAccess.LoadByPrimaryKey(AAddress[0].CountryCode, ATransaction));
                        }

                        ACountryNameLocal = CountryTable[CountryTable.DefaultView.Find(AAddress[0].CountryCode)].CountryNameLocal;
                    }

                    break;
                }
            }

            return(AAddress != null);
        }
示例#2
0
        /// <summary>
        /// get the best email address that is valid today, with some location details
        /// </summary>
        public static string GetBestEmailAddressWithDetails(Int64 APartnerKey, out PLocationTable AAddress, out string ACountryNameLocal)
        {
            string         EmailAddress     = "";
            PLocationTable Address          = null;
            string         CountryNameLocal = "";
            TDBTransaction Transaction      = null;

            DBAccess.GDBAccessObj.GetNewOrExistingAutoReadTransaction(IsolationLevel.ReadCommitted, ref Transaction,
                                                                      delegate
            {
                DataSet PartnerLocationsDS = new DataSet();

                PartnerLocationsDS.Tables.Add(new PPartnerLocationTable());
                PartnerLocationsDS.Tables.Add(new PCountryTable());
                DataTable PartnerLocationTable = PartnerLocationsDS.Tables[PPartnerLocationTable.GetTableName()];
                PCountryTable CountryTable     = (PCountryTable)PartnerLocationsDS.Tables[PCountryTable.GetTableName()];
                CountryTable.DefaultView.Sort  = PCountryTable.GetCountryCodeDBName();

                // add special column BestAddress and Icon
                PartnerLocationTable.Columns.Add(new System.Data.DataColumn("BestAddress", typeof(Boolean)));
                PartnerLocationTable.Columns.Add(new System.Data.DataColumn("Icon", typeof(Int32)));

                // find all locations of the partner, put it into a dataset
                PPartnerLocationAccess.LoadViaPPartner(PartnerLocationsDS, APartnerKey, Transaction);

                Ict.Petra.Shared.MPartner.Calculations.DeterminePartnerLocationsDateStatus(PartnerLocationsDS);
                Ict.Petra.Shared.MPartner.Calculations.DetermineBestAddress(PartnerLocationsDS);

                foreach (PPartnerLocationRow row in PartnerLocationTable.Rows)
                {
                    // find the row with BestAddress = 1
                    if (Convert.ToInt32(row["BestAddress"]) == 1)
                    {
                        if (!row.IsEmailAddressNull())
                        {
                            EmailAddress = row.EmailAddress;
                        }

                        // we also want the post address, need to load the p_location table:
                        Address = PLocationAccess.LoadByPrimaryKey(row.SiteKey, row.LocationKey, Transaction);

                        if (CountryTable.DefaultView.Find(Address[0].CountryCode) == -1)
                        {
                            CountryTable.Merge(PCountryAccess.LoadByPrimaryKey(Address[0].CountryCode, Transaction));
                        }

                        CountryNameLocal = CountryTable[CountryTable.DefaultView.Find(Address[0].CountryCode)].CountryNameLocal;
                    }
                }
            });

            AAddress          = Address;
            ACountryNameLocal = CountryNameLocal;

            return(EmailAddress);
        }
示例#3
0
        /// <summary>
        /// Filter data by postcode (if applicable)
        /// </summary>
        /// <param name="APartnerkeys"></param>
        /// <param name="AAddressFilterAdded"></param>
        /// <param name="AParameters"></param>
        /// <param name="ATransaction"></param>
        public static void PostcodeFilter(ref DataTable APartnerkeys,
                                          ref bool AAddressFilterAdded,
                                          TParameterList AParameters,
                                          TDBTransaction ATransaction)
        {
            // if filter exists
            if ((AParameters.Exists("param_region") && !string.IsNullOrEmpty(AParameters.Get("param_region").ToString())) ||
                (AParameters.Exists("param_postcode_from") && !string.IsNullOrEmpty(AParameters.Get("param_postcode_from").ToString())) ||
                (AParameters.Exists("param_postcode_to") && !string.IsNullOrEmpty(AParameters.Get("param_postcode_to").ToString())))
            {
                DataTable partnerkeysCopy = APartnerkeys.Copy();
                int       i = 0;

                foreach (DataRow Row in partnerkeysCopy.Rows)
                {
                    // get postcode for current partner's location
                    PLocationRow LocationRow = (PLocationRow)PLocationAccess.LoadByPrimaryKey(
                        Convert.ToInt64(Row["p_site_key_n"]), Convert.ToInt32(Row["p_location_key_i"]),
                        ATransaction)[0];

                    if (!AddressMeetsPostCodeCriteriaOrEmpty(LocationRow.PostalCode,
                                                             AParameters.Get("param_region").ToString(),
                                                             AParameters.Get("param_postcode_from").ToString(),
                                                             AParameters.Get("param_postcode_to").ToString()))
                    {
                        // remove record if it is excluded by the filter
                        APartnerkeys.Rows.RemoveAt(i);
                    }
                    else
                    {
                        i++;
                    }
                }

                AAddressFilterAdded = true;
            }
        }
        /// <summary>
        /// Determines which address is the 'Best Address' of a Partner, and returns the PLocation record which the
        /// 'Best Address' is pointing to.
        /// </summary>
        /// <remarks>There are two similar shared Methods in Namespace Ict.Petra.Server.MPartner.Common.Calculations,
        /// both called 'DetermineBestAddress' which work by passing in the PartnerLocations of a Partner in an Argument
        /// and which return a <see cref="TLocationPK" />. As those Methods don't access the database, these Methods
        /// can be used client-side as well!</remarks>
        /// <param name="APartnerKey">PartnerKey of the Partner whose addresses should be checked.</param>
        /// <param name="APartnerLocationDR">PPartnerLocation Record that is the record that is the Location of the 'Best Address'.</param>
        /// <param name="ALocationDR">PLocation Record that the 'Best Address' is pointing to.</param>
        /// <param name="ADataBase">An instantiated <see cref="TDataBase" /> object, or null (default = null). If null
        /// gets passed then the Method executes DB commands with a new Database connection</param>
        /// <returns>A <see cref="TLocationPK" /> which points to the 'Best Address'. If no 'Best Address' was found,
        /// SiteKey and LocationKey of this instance will be both -1.</returns>
        public static TLocationPK DetermineBestAddress(Int64 APartnerKey, out PPartnerLocationRow APartnerLocationDR,
                                                       out PLocationRow ALocationDR, TDataBase ADataBase = null)
        {
            PLocationTable LocationDT;
            TLocationPK    BestLocation = new TLocationPK();
            Boolean        NewTransaction;

            APartnerLocationDR = null;
            ALocationDR        = null;

            BestLocation = DetermineBestAddress(APartnerKey, out APartnerLocationDR);

            TDataBase      db = DBAccess.Connect("DetermineBestAddress", ADataBase);
            TDBTransaction ReadTransaction = db.GetNewOrExistingTransaction(
                MCommonConstants.CACHEABLEDT_ISOLATIONLEVEL,
                out NewTransaction);

            try
            {
                LocationDT = PLocationAccess.LoadByPrimaryKey(BestLocation.SiteKey, BestLocation.LocationKey, ReadTransaction);

                if (LocationDT.Rows.Count > 0)
                {
                    ALocationDR = LocationDT[0];
                }
            }
            finally
            {
                if (NewTransaction)
                {
                    ReadTransaction.Commit();
                    TLogging.LogAtLevel(7, "ServerCalculations.DetermineBestAddress: commited own transaction.");
                }
            }

            return(BestLocation);
        }
示例#5
0
        /// <summary>
        /// Determines which address is the 'Best Address' of a Partner, and returns the PLocation record which the
        /// 'Best Address' is pointing to.
        /// </summary>
        /// <remarks>There are two similar shared Methods in Namespace Ict.Petra.Shared.MPartner.Calculations,
        /// both called 'DetermineBestAddress' which work by passing in the PartnerLocations of a Partner in an Argument
        /// and which return a <see cref="TLocationPK" />. As those Methods don't access the database, these Methods
        /// can be used client-side as well!</remarks>
        /// <param name="APartnerKey">PartnerKey of the Partner whose addresses should be checked.</param>
        /// <param name="APartnerLocationDR">PPartnerLocation Record that is the record that is the Location of the 'Best Address'.</param>
        /// <param name="ALocationDR">PLocation Record that the 'Best Address' is pointing to.</param>
        /// <returns>A <see cref="TLocationPK" /> which points to the 'Best Address'. If no 'Best Address' was found,
        /// SiteKey and LocationKey of this instance will be both -1.</returns>
        public static TLocationPK DetermineBestAddress(Int64 APartnerKey, out PPartnerLocationRow APartnerLocationDR, out PLocationRow ALocationDR)
        {
            PLocationTable LocationDT;
            TLocationPK    BestLocation = new TLocationPK();
            Boolean        NewTransaction;

            APartnerLocationDR = null;
            ALocationDR        = null;

            BestLocation = DetermineBestAddress(APartnerKey, out APartnerLocationDR);

            TDBTransaction ReadTransaction = DBAccess.GDBAccessObj.GetNewOrExistingTransaction(
                Ict.Petra.Server.MCommon.MCommonConstants.CACHEABLEDT_ISOLATIONLEVEL,
                TEnforceIsolationLevel.eilMinimum,
                out NewTransaction);

            try
            {
                LocationDT = PLocationAccess.LoadByPrimaryKey(BestLocation.SiteKey, BestLocation.LocationKey, ReadTransaction);

                if (LocationDT.Rows.Count > 0)
                {
                    ALocationDR = LocationDT[0];
                }
            }
            finally
            {
                if (NewTransaction)
                {
                    DBAccess.GDBAccessObj.CommitTransaction();
                    TLogging.LogAtLevel(7, "ServerCalculations.DetermineBestAddress: commited own transaction.");
                }
            }

            return(BestLocation);
        }
示例#6
0
        /// <summary>
        /// This report considers gifts given between the two specified dates, and can include all gifts or, if
        /// selected, those to a particular motivation, motivation detail or recipient. For the defined set of gifts
        /// and its total value, the donors are sorted into a list, starting with those who gave most, and showing
        /// the percentage that their gifts contributed to the total received (for this motivation or recipient, if
        /// specified) and the cumulative percentage, moving down the list starting with the top donor.
        /// </summary>
        /// <param name="ATotalAmount">Pre calculated value of the total gifts given with these parameters</param>
        /// <param name="ATopXPercent">Upper limit of the percentage to show in the report</param>
        /// <param name="ABottomXPercent">Lower limit of the percentage to show in the report</param>
        /// <param name="AExtract">true to use only partners from an extract</param>
        /// <param name="AExtractName">extract name</param>
        /// <param name="AStartDate">Start date of the gifts given</param>
        /// <param name="AEndDate">End date of the gifts given</param>
        /// <param name="ARecipientKey">Partner key of a specific recipient. If 0 then use all recipients</param>
        /// <param name="AMotivationGroup">Limit gifts to this motivation group. If % use all motivation groups</param>
        /// <param name="AMotivationDetail">Limit gifts to this motivation detail. If % use all motivation details</param>
        /// <returns></returns>
        private bool MakeTopDonor(decimal ATotalAmount, decimal ATopXPercent, decimal ABottomXPercent,
                                  bool AExtract, String AExtractName, DateTime AStartDate, DateTime AEndDate,
                                  Int64 ARecipientKey, String AMotivationGroup, String AMotivationDetail)
        {
            Int64         LedgerNumber = situation.GetParameters().Get("param_ledger_number_i").ToInt64();
            String        CurrencyType = situation.GetParameters().Get("param_currency").ToString();
            StringBuilder SqlString    = new StringBuilder();

            SqlString.Append("SELECT DISTINCT ");
            SqlString.Append("gift.p_donor_key_n AS DonorKey, ");
            SqlString.Append(PPartnerTable.GetTableDBName() + "." + PPartnerTable.GetPartnerShortNameDBName() + " AS ShortName, ");
            SqlString.Append(PPartnerTable.GetTableDBName() + "." + PPartnerTable.GetPartnerClassDBName() + " AS PartnerClass, ");

            if (CurrencyType == "Base")
            {
                SqlString.Append("SUM(detail." + AGiftDetailTable.GetGiftAmountDBName() + ") AS Amount ");
            }
            else
            {
                SqlString.Append("SUM(detail." + AGiftDetailTable.GetGiftAmountIntlDBName() + ") AS Amount ");
            }

            SqlString.Append(
                " FROM " + AGiftTable.GetTableDBName() + " as gift, " + AGiftDetailTable.GetTableDBName() + " as detail, " +
                PPartnerTable.GetTableDBName() + ", " + AGiftBatchTable.GetTableDBName() + " ");

            if (AExtract)
            {
                SqlString.Append(", " + MExtractTable.GetTableDBName() + ", " + MExtractMasterTable.GetTableDBName());
                SqlString.Append(
                    " WHERE gift." + AGiftTable.GetDonorKeyDBName() + " = " + MExtractTable.GetTableDBName() + "." +
                    MExtractTable.GetPartnerKeyDBName());
                SqlString.Append(
                    " AND " + MExtractTable.GetTableDBName() + "." + MExtractTable.GetExtractIdDBName() + " = " +
                    MExtractMasterTable.GetTableDBName() +
                    "." + MExtractMasterTable.GetExtractIdDBName());
                SqlString.Append(" AND " + MExtractMasterTable.GetTableDBName() + "." + MExtractMasterTable.GetExtractNameDBName() + " = '");
                SqlString.Append(AExtractName);
                SqlString.Append("' AND ");
            }
            else
            {
                SqlString.Append(" WHERE ");
            }

            SqlString.Append(" detail." + AGiftDetailTable.GetLedgerNumberDBName() + " = gift." + AGiftTable.GetLedgerNumberDBName());
            SqlString.Append(" AND detail." + AGiftDetailTable.GetBatchNumberDBName() + " = gift." + AGiftTable.GetBatchNumberDBName());
            SqlString.Append(
                " AND detail." + AGiftDetailTable.GetGiftTransactionNumberDBName() + " = gift." + AGiftTable.GetGiftTransactionNumberDBName());
            SqlString.Append(" AND gift." + AGiftTable.GetDateEnteredDBName() + " BETWEEN '");
            SqlString.Append(AStartDate.ToString("yyyy-MM-dd"));
            SqlString.Append("' AND '");
            SqlString.Append(AEndDate.ToString("yyyy-MM-dd"));
            SqlString.Append("' AND gift." + AGiftTable.GetLedgerNumberDBName() + " = ");
            SqlString.Append(LedgerNumber.ToString());
            SqlString.Append(" AND " + AGiftBatchTable.GetTableDBName() + "." + AGiftBatchTable.GetLedgerNumberDBName() + " = ");
            SqlString.Append(LedgerNumber.ToString());
            SqlString.Append(
                " AND " + AGiftBatchTable.GetTableDBName() + "." + AGiftBatchTable.GetBatchNumberDBName() + " = gift." +
                AGiftTable.GetBatchNumberDBName());
            SqlString.Append(" AND ( " + AGiftBatchTable.GetTableDBName() + "." + AGiftBatchTable.GetBatchStatusDBName() + " = 'Posted' OR ");
            SqlString.Append(AGiftBatchTable.GetTableDBName() + "." + AGiftBatchTable.GetBatchStatusDBName() + " = 'posted' ) ");
            SqlString.Append(
                " AND " + PPartnerTable.GetTableDBName() + "." + PPartnerTable.GetPartnerKeyDBName() + " = gift." + AGiftTable.GetDonorKeyDBName());

            if (ARecipientKey != 0)
            {
                SqlString.Append(" AND detail." + AGiftDetailTable.GetRecipientKeyDBName() + " = ");
                SqlString.Append(ARecipientKey.ToString());
            }

            if (AMotivationGroup != "%")
            {
                SqlString.Append(" AND  detail." + AGiftDetailTable.GetMotivationGroupCodeDBName() + " LIKE '");
                SqlString.Append(AMotivationGroup);
                SqlString.Append("' ");
            }

            if (AMotivationDetail != "%")
            {
                SqlString.Append(" AND  detail." + AGiftDetailTable.GetMotivationDetailCodeDBName() + " LIKE '");
                SqlString.Append(AMotivationDetail);
                SqlString.Append("' ");
            }

            SqlString.Append(" GROUP BY gift." + AGiftTable.GetDonorKeyDBName() + ", ");
            SqlString.Append(PPartnerTable.GetTableDBName() + "." + PPartnerTable.GetPartnerShortNameDBName() + ", ");
            SqlString.Append(PPartnerTable.GetTableDBName() + "." + PPartnerTable.GetPartnerClassDBName());
            SqlString.Append(" ORDER BY Amount DESC");

            DataTable Table = situation.GetDatabaseConnection().SelectDT(SqlString.ToString(), "table",
                                                                         situation.GetDatabaseConnection().Transaction, new OdbcParameter[] { });

            decimal CummulativeAmount = 0;
            decimal TopAmount         = ATotalAmount * ATopXPercent / 100;
            decimal BottomAmount      = ATotalAmount * ABottomXPercent / 100;

            int NumColumns = 7;
            int ChildRow   = 1;

            situation.GetResults().Clear();

            for (int Counter = 0; Counter < Table.Rows.Count; ++Counter)
            {
                decimal CurrentAmount = Convert.ToDecimal(Table.Rows[Counter]["Amount"]);

                if (CurrentAmount < 0)
                {
                    continue;
                }

                if ((CummulativeAmount <= TopAmount) &&
                    (CummulativeAmount >= BottomAmount))
                {
                    Int64  DonorKey     = Convert.ToInt64(Table.Rows[Counter]["DonorKey"]);
                    String ShortName    = (String)Table.Rows[Counter]["ShortName"];
                    String PartnerClass = (String)Table.Rows[Counter]["PartnerClass"];

                    CummulativeAmount += CurrentAmount;

                    // Transfer to results
                    TVariant[] Header      = new TVariant[NumColumns];
                    TVariant[] Description =
                    {
                        new TVariant(), new TVariant()
                    };
                    TVariant[] Columns = new TVariant[NumColumns];

                    for (int Counter2 = 0; Counter2 < NumColumns; ++Counter2)
                    {
                        Header[Counter2]  = new TVariant();
                        Columns[Counter2] = new TVariant();
                    }

                    StringBuilder       PartnerAddress = new StringBuilder();
                    PPartnerLocationRow AddressRow;

                    if (Ict.Petra.Server.MReporting.MPartner.TRptUserFunctionsPartner.GetPartnerBestAddressRow(DonorKey, situation, out AddressRow))
                    {
                        PLocationTable LocationTable = PLocationAccess.LoadByPrimaryKey(AddressRow.SiteKey,
                                                                                        AddressRow.LocationKey, situation.GetDatabaseConnection().Transaction);

                        if (LocationTable.Rows.Count > 0)
                        {
                            PLocationRow LocationRow = (PLocationRow)LocationTable.Rows[0];

                            PartnerAddress.Append(LocationRow.Locality);

                            if (LocationRow.Locality.Length > 0)
                            {
                                PartnerAddress.Append(", ");
                            }

                            PartnerAddress.Append(LocationRow.StreetName);

                            if (PartnerAddress.Length > 0)
                            {
                                PartnerAddress.Append(", ");
                            }

                            PartnerAddress.Append(LocationRow.Address3);

                            if (PartnerAddress.Length > 0)
                            {
                                PartnerAddress.Append(", ");
                            }

                            PartnerAddress.Append(LocationRow.PostalCode);
                            PartnerAddress.Append(" ");
                            PartnerAddress.Append(LocationRow.City);

                            if (LocationRow.County.Length > 0)
                            {
                                PartnerAddress.Append(", ");
                                PartnerAddress.Append(LocationRow.County);
                            }

                            PartnerAddress.Append(", ");
                            PartnerAddress.Append(LocationRow.CountryCode);
                        }
                    }

                    Columns[0] = new TVariant(DonorKey.ToString("0000000000"));
                    Columns[1] = new TVariant(PartnerClass);
                    Columns[2] = new TVariant(ShortName);
                    Columns[3] = new TVariant(CurrentAmount, "-#,##0.00;#,##0.00");
                    Columns[4] = new TVariant((CurrentAmount * 100 / ATotalAmount), "-#,##0.00;#,##0.00");
                    Columns[5] = new TVariant((CummulativeAmount * 100 / ATotalAmount), "-#,##0.00;#,##0.00");
                    Columns[6] = new TVariant(PartnerAddress.ToString());

                    situation.GetResults().AddRow(0, ChildRow++, true, 2, "", "", false,
                                                  Header, Description, Columns);
                }
                else
                {
                    CummulativeAmount += CurrentAmount;
                }
            }

            return(true);
        }
示例#7
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);
        }
示例#8
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);
        }
示例#9
0
        private static PartnerDetails GetDonor(Int64 APartnerKey)
        {
            if (DonorList.ContainsKey(APartnerKey))
            {
                return(DonorList[APartnerKey]);
            }

            PartnerDetails Ret        = new PartnerDetails();
            PPartnerTable  PartnerTbl = PPartnerAccess.LoadByPrimaryKey(APartnerKey, FTransaction);

            if (PartnerTbl.Rows.Count > 0)
            {
                PPartnerRow PartnerRow = PartnerTbl[0];

                Ret.LastName  = PartnerRow.PartnerShortName;
                Ret.Anonymous = PartnerRow.AnonymousDonor;

                if (PartnerRow.PartnerClass == "PERSON")
                {
                    PPersonTable PersonTbl = PPersonAccess.LoadByPrimaryKey(APartnerKey, FTransaction);

                    if (PersonTbl.Rows.Count > 0)
                    {
                        PPersonRow PersonRow = PersonTbl[0];
                        Ret.FirstName = PersonRow.FirstName;
                        Ret.LastName  = PersonRow.FamilyName;
                        Ret.Class     = "PERSON";
                    }
                }

                if (PartnerRow.PartnerClass == "FAMILY")
                {
                    PFamilyTable FamilyTbl = PFamilyAccess.LoadByPrimaryKey(APartnerKey, FTransaction);

                    if (FamilyTbl.Rows.Count > 0)
                    {
                        PFamilyRow FamilyRow = FamilyTbl[0];
                        Ret.FirstName = FamilyRow.FirstName;
                        Ret.LastName  = FamilyRow.FamilyName;
                        Ret.Class     = "FAMILY";
                    }
                }

                PPartnerLocationRow PartnerLocationRow;
                TLocationPK         LocationKey = ServerCalculations.DetermineBestAddress(APartnerKey, out PartnerLocationRow);

                if (LocationKey.LocationKey != -1)
                {
                    Ret.Email     = PartnerLocationRow.EmailAddress;
                    Ret.Telephone = PartnerLocationRow.TelephoneNumber;
                    PLocationTable LocationTbl = PLocationAccess.LoadByPrimaryKey(PartnerLocationRow.SiteKey,
                                                                                  PartnerLocationRow.LocationKey,
                                                                                  FTransaction);

                    if (LocationTbl.Rows.Count > 0)
                    {
                        PLocationRow LocationRow = LocationTbl[0];
                        Ret.Address = Calculations.DetermineLocationString(LocationRow, Calculations.TPartnerLocationFormatEnum.plfCommaSeparated);
                    }
                }
            }

            DonorList.Add(APartnerKey, Ret);
            return(Ret);
        }