コード例 #1
0
        /// <summary>
        /// Determines which address is the 'Best Address' of a Partner, and returns the PPartnerLocation record which is the
        /// 'Best Address'.
        /// </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>
        /// <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)
        {
            TLocationPK           ReturnValue = new TLocationPK();
            PPartnerLocationTable PartnerLocationDT;
            Boolean NewTransaction;

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

            try
            {
                PartnerLocationDT = PPartnerLocationAccess.LoadViaPPartner(APartnerKey, ReadTransaction);
                ReturnValue       = Ict.Petra.Shared.MPartner.Calculations.DetermineBestAddress(PartnerLocationDT);

                APartnerLocationDR = (PPartnerLocationRow)PartnerLocationDT.Rows.Find(new object[]
                                                                                      { APartnerKey, ReturnValue.SiteKey, ReturnValue.LocationKey });
            }
            finally
            {
                if (NewTransaction)
                {
                    DBAccess.GDBAccessObj.CommitTransaction();
                    TLogging.LogAtLevel(7, "ServerCalculations.DetermineBestAddress: commited own transaction.");
                }
            }

            return(ReturnValue);
        }
コード例 #2
0
        /// <summary>
        /// Determines which address is the 'Best Address' of a Partner, and returns the PPartnerLocation record which is the
        /// 'Best Address'.
        /// </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="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,
                                                       TDataBase ADataBase = null)
        {
            TLocationPK           ReturnValue = new TLocationPK();
            PPartnerLocationTable PartnerLocationDT;
            Boolean NewTransaction;

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

            try
            {
                PartnerLocationDT = PPartnerLocationAccess.LoadViaPPartner(APartnerKey, ReadTransaction);
                ReturnValue       = Ict.Petra.Server.MPartner.Common.Calculations.DetermineBestAddress(PartnerLocationDT);

                APartnerLocationDR = (PPartnerLocationRow)PartnerLocationDT.Rows.Find(new object[]
                                                                                      { APartnerKey, ReturnValue.SiteKey, ReturnValue.LocationKey });
            }
            finally
            {
                if (NewTransaction)
                {
                    ReadTransaction.Commit();
                    TLogging.LogAtLevel(7, "ServerCalculations.DetermineBestAddress: commited own transaction.");
                }
            }

            return(ReturnValue);
        }
コード例 #3
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);
        }
コード例 #4
0
ファイル: Mailing.cs プロジェクト: jsuen123/openpetragit
        /// <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);
        }
コード例 #5
0
        /// <summary>
        /// Load all the data of a partner into a TDS
        /// </summary>
        public static PartnerImportExportTDS ExportPartner(Int64 APartnerKey)
        {
            PartnerImportExportTDS MainDS      = new PartnerImportExportTDS();
            TDBTransaction         Transaction = DBAccess.GDBAccessObj.BeginTransaction(IsolationLevel.ReadCommitted);

            PPartnerAccess.LoadByPrimaryKey(MainDS, APartnerKey, Transaction);
            PChurchAccess.LoadByPrimaryKey(MainDS, APartnerKey, Transaction);
            PFamilyAccess.LoadByPrimaryKey(MainDS, APartnerKey, Transaction);
            PPersonAccess.LoadByPrimaryKey(MainDS, APartnerKey, Transaction);
            POrganisationAccess.LoadByPrimaryKey(MainDS, APartnerKey, Transaction);
            PUnitAccess.LoadByPrimaryKey(MainDS, APartnerKey, Transaction);
            PVenueAccess.LoadByPrimaryKey(MainDS, APartnerKey, Transaction);

            PLocationAccess.LoadViaPPartner(MainDS, APartnerKey, Transaction);
            PPartnerLocationAccess.LoadViaPPartner(MainDS, APartnerKey, Transaction);

            PPartnerCommentAccess.LoadViaPPartner(MainDS, APartnerKey, Transaction);
            PPartnerTypeAccess.LoadViaPPartner(MainDS, APartnerKey, Transaction);
            PPartnerInterestAccess.LoadViaPPartner(MainDS, APartnerKey, Transaction);
            PPartnerGiftDestinationAccess.LoadViaPPartner(MainDS, APartnerKey, Transaction);

            PInterestAccess.LoadAll(MainDS, Transaction);

            PmPersonalDataAccess.LoadByPrimaryKey(MainDS, APartnerKey, Transaction);
            PmPassportDetailsAccess.LoadViaPPerson(MainDS, APartnerKey, Transaction);
            PmDocumentAccess.LoadViaPPartner(MainDS, APartnerKey, Transaction);
            PmDocumentTypeAccess.LoadAll(MainDS, Transaction);
            PmPersonQualificationAccess.LoadViaPPerson(MainDS, APartnerKey, Transaction);
            PmSpecialNeedAccess.LoadViaPPerson(MainDS, APartnerKey, Transaction);
            PmPastExperienceAccess.LoadViaPPerson(MainDS, APartnerKey, Transaction);
            PmPersonLanguageAccess.LoadViaPPerson(MainDS, APartnerKey, Transaction);
            PmPersonAbilityAccess.LoadViaPPerson(MainDS, APartnerKey, Transaction);
            PmStaffDataAccess.LoadViaPPerson(MainDS, APartnerKey, Transaction);
            PmJobAssignmentAccess.LoadViaPPartner(MainDS, APartnerKey, Transaction);
            PmPersonEvaluationAccess.LoadViaPPerson(MainDS, APartnerKey, Transaction);

            PmGeneralApplicationAccess.LoadViaPPersonPartnerKey(MainDS, APartnerKey, Transaction);
            PtApplicationTypeAccess.LoadAll(MainDS, Transaction);
            PmShortTermApplicationAccess.LoadViaPPerson(MainDS, APartnerKey, Transaction);
            PmYearProgramApplicationAccess.LoadViaPPerson(MainDS, APartnerKey, Transaction);

            UmUnitStructureAccess.LoadViaPUnitChildUnitKey(MainDS, APartnerKey, Transaction);
            UmUnitAbilityAccess.LoadViaPUnit(MainDS, APartnerKey, Transaction);
            UmUnitLanguageAccess.LoadViaPUnit(MainDS, APartnerKey, Transaction);
            UmUnitCostAccess.LoadViaPUnit(MainDS, APartnerKey, Transaction);
            UmJobAccess.LoadViaPUnit(MainDS, APartnerKey, Transaction);
            UmJobRequirementAccess.LoadViaPUnit(MainDS, APartnerKey, Transaction);
            UmJobLanguageAccess.LoadViaPUnit(MainDS, APartnerKey, Transaction);
            UmJobQualificationAccess.LoadViaPUnit(MainDS, APartnerKey, Transaction);

            PcBuildingAccess.LoadViaPVenue(MainDS, APartnerKey, Transaction);
            PcRoomAccess.LoadViaPVenue(MainDS, APartnerKey, Transaction);

            DBAccess.GDBAccessObj.RollbackTransaction();
            return(MainDS);
        }
コード例 #6
0
        public static Boolean VerifyPartnerAtLocation(Int64 APartnerKey,
                                                      TLocationPK ALocationKey, out bool AAddressNeitherCurrentNorMailing)
        {
            AAddressNeitherCurrentNorMailing = true;

            TDBTransaction        ReadTransaction;
            Boolean               NewTransaction;
            PPartnerLocationTable PartnerLocationTable;
            Boolean               ReturnValue = true;

            ReadTransaction = DBAccess.GDBAccessObj.GetNewOrExistingTransaction(IsolationLevel.ReadCommitted,
                                                                                TEnforceIsolationLevel.eilMinimum,
                                                                                out NewTransaction);
            try
            {
                PartnerLocationTable = PPartnerLocationAccess.LoadByPrimaryKey(APartnerKey,
                                                                               ALocationKey.SiteKey,
                                                                               ALocationKey.LocationKey,
                                                                               ReadTransaction);
            }
            finally
            {
                if (NewTransaction)
                {
                    DBAccess.GDBAccessObj.CommitTransaction();
                }
            }

            if (PartnerLocationTable.Rows.Count == 0)
            {
                ReturnValue = false;
            }
            else
            {
                PPartnerLocationRow Row = (PPartnerLocationRow)PartnerLocationTable.Rows[0];

                // check if the partner location is either current or if it is a mailing address
                if ((Row.DateEffective > DateTime.Today) ||
                    (!Row.SendMail) ||
                    ((Row.DateGoodUntil != null) &&
                     (Row.DateGoodUntil < DateTime.Today)))
                {
                    AAddressNeitherCurrentNorMailing = true;
                }
                else
                {
                    AAddressNeitherCurrentNorMailing = false;
                }

                ReturnValue = true;
            }

            return(ReturnValue);
        }
コード例 #7
0
        public static PartnerEditTDS GetPartnerDetails(Int64 APartnerKey, bool AWithAddressDetails, bool AWithSubscriptions, bool AWithRelationships)
        {
            PartnerEditTDS MainDS = new PartnerEditTDS();

            TDBTransaction Transaction = DBAccess.GDBAccessObj.BeginTransaction(IsolationLevel.Serializable);

            PPartnerAccess.LoadByPrimaryKey(MainDS, APartnerKey, Transaction);

            if (MainDS.PPartner.Rows.Count == 0)
            {
                return(null);
            }

            switch (MainDS.PPartner[0].PartnerClass)
            {
            case MPartnerConstants.PARTNERCLASS_FAMILY:
                PFamilyAccess.LoadByPrimaryKey(MainDS, APartnerKey, Transaction);
                break;

            case MPartnerConstants.PARTNERCLASS_PERSON:
                PPersonAccess.LoadByPrimaryKey(MainDS, APartnerKey, Transaction);
                break;

            case MPartnerConstants.PARTNERCLASS_CHURCH:
                PChurchAccess.LoadByPrimaryKey(MainDS, APartnerKey, Transaction);
                break;

            case MPartnerConstants.PARTNERCLASS_ORGANISATION:
                POrganisationAccess.LoadByPrimaryKey(MainDS, APartnerKey, Transaction);
                break;
            }

            if (AWithAddressDetails)
            {
                PPartnerLocationAccess.LoadViaPPartner(MainDS, APartnerKey, Transaction);
                PLocationAccess.LoadViaPPartner(MainDS, APartnerKey, Transaction);
            }

            if (AWithRelationships)
            {
                PPartnerRelationshipAccess.LoadViaPPartnerPartnerKey(MainDS, APartnerKey, Transaction);
            }

            if (AWithSubscriptions)
            {
                PSubscriptionAccess.LoadViaPPartnerPartnerKey(MainDS, APartnerKey, Transaction);
            }

            DBAccess.GDBAccessObj.RollbackTransaction();

            return(MainDS);
        }
コード例 #8
0
        public static PartnerEditTDS GetPartnerDetails(Int64 APartnerKey, bool AWithAddressDetails, bool AWithSubscriptions, bool AWithRelationships)
        {
            PartnerEditTDS MainDS = new PartnerEditTDS();

            TDBTransaction Transaction = null;

            DBAccess.GDBAccessObj.BeginAutoReadTransaction(IsolationLevel.ReadCommitted, ref Transaction,
                delegate
                {
                    PPartnerAccess.LoadByPrimaryKey(MainDS, APartnerKey, Transaction);

                    if (MainDS.PPartner.Rows.Count > 0)
                    {
                        switch (MainDS.PPartner[0].PartnerClass)
                        {
                            case MPartnerConstants.PARTNERCLASS_FAMILY:
                                PFamilyAccess.LoadByPrimaryKey(MainDS, APartnerKey, Transaction);
                                break;

                            case MPartnerConstants.PARTNERCLASS_PERSON:
                                PPersonAccess.LoadByPrimaryKey(MainDS, APartnerKey, Transaction);
                                break;

                            case MPartnerConstants.PARTNERCLASS_CHURCH:
                                PChurchAccess.LoadByPrimaryKey(MainDS, APartnerKey, Transaction);
                                break;

                            case MPartnerConstants.PARTNERCLASS_ORGANISATION:
                                POrganisationAccess.LoadByPrimaryKey(MainDS, APartnerKey, Transaction);
                                break;
                        }

                        if (AWithAddressDetails)
                        {
                            PPartnerLocationAccess.LoadViaPPartner(MainDS, APartnerKey, Transaction);
                            PLocationAccess.LoadViaPPartner(MainDS, APartnerKey, Transaction);
                        }

                        if (AWithRelationships)
                        {
                            PPartnerRelationshipAccess.LoadViaPPartnerPartnerKey(MainDS, APartnerKey, Transaction);
                        }

                        if (AWithSubscriptions)
                        {
                            PSubscriptionAccess.LoadViaPPartnerPartnerKey(MainDS, APartnerKey, Transaction);
                        }
                    }
                });

            return MainDS;
        }
コード例 #9
0
        public static DataTable RecipientGiftStatementDonorAddressesTable(Int64 ADonorKey, TReportingDbAdapter DbAdapter)
        {
            TDBTransaction Transaction = null;

            // create new datatable
            DataTable Results = new DataTable();

            Results.Columns.Add("DonorKey", typeof(Int64));

            DBAccess.GDBAccessObj.BeginAutoReadTransaction(
                ref Transaction,
                delegate
            {
                // get best address for the partner
                PPartnerLocationTable PartnerLocationDT = PPartnerLocationAccess.LoadViaPPartner(ADonorKey, Transaction);
                TLocationPK BestAddress = Calculations.DetermineBestAddress(PartnerLocationDT);

                string QueryLocation = "SELECT" +
                                       " PUB_p_location.p_locality_c AS Locality," +
                                       " PUB_p_location.p_street_name_c," +
                                       " PUB_p_location.p_address_3_c," +
                                       " PUB_p_location.p_postal_code_c," +
                                       " PUB_p_location.p_city_c," +
                                       " PUB_p_location.p_county_c," +
                                       " PUB_p_location.p_country_code_c," +
                                       " PUB_p_country.p_address_order_i" +

                                       " FROM" +
                                       " PUB_p_location" +

                                       " LEFT JOIN PUB_p_country" +
                                       " ON PUB_p_country.p_country_code_c = PUB_p_location.p_country_code_c" +

                                       " WHERE" +
                                       " PUB_p_location.p_site_key_n = " + BestAddress.SiteKey +
                                       " AND PUB_p_location.p_location_key_i = " + BestAddress.LocationKey;

                Results.Merge(DbAdapter.RunQuery(QueryLocation, "DonorAddresses", Transaction));

                if (Results.Rows.Count == 0)
                {
                    DataRow NewRow     = Results.NewRow();
                    NewRow["Locality"] = "UNKNOWN";
                    Results.Rows.Add(NewRow);
                }

                Results.Rows[0]["DonorKey"] = ADonorKey;
            });

            return(Results);
        }
コード例 #10
0
        /// <summary>
        /// Load data from db.
        /// Data is held in variable MainDS.PPartner and then MainDS.PLocation, PFamilyAccess etc...
        /// The latter is to get the additional information not present in PPartner but in dependent tables.
        /// </summary>
        /// <param name="MainDS">
        /// The Datastructure which is filled with the data from the DB.
        /// It should be empty initially.
        /// </param>
        private static void LoadDataFromDB(ref PartnerEditTDS MainDS)
        {
            TDBTransaction Transaction = DBAccess.GDBAccessObj.BeginTransaction(IsolationLevel.Serializable);

            try
            {
                PPartnerAccess.LoadAll(MainDS, Transaction);
                TLogging.LogAtLevel(TLogging.DEBUGLEVEL_TRACE, "Read Partners from Database : " + MainDS.PPartner.Rows.Count.ToString());
                TLogging.LogAtLevel(TLogging.DEBUGLEVEL_TRACE, "Now reading additional data for each Partner:");

                foreach (PPartnerRow partnerRow in MainDS.PPartner.Rows)
                {
                    long partnerKey = partnerRow.PartnerKey;
                    PLocationAccess.LoadViaPPartner(MainDS, partnerKey, Transaction);
                    PPartnerLocationAccess.LoadViaPPartner(MainDS, partnerKey, Transaction);
                    PPartnerTypeAccess.LoadViaPPartner(MainDS, partnerKey, Transaction);
                    PPersonAccess.LoadViaPPartner(MainDS, partnerKey, Transaction);
                    PFamilyAccess.LoadViaPPartner(MainDS, partnerKey, Transaction);
                    POrganisationAccess.LoadViaPPartnerPartnerKey(MainDS, partnerKey, Transaction);
                    PUnitAccess.LoadViaPPartnerPartnerKey(MainDS, partnerKey, Transaction);
                    UmUnitStructureAccess.LoadViaPUnitChildUnitKey(MainDS, partnerKey, Transaction);
                    PBankAccess.LoadViaPPartnerPartnerKey(MainDS, partnerKey, Transaction);
                }

                if (TLogging.DebugLevel >= TLogging.DEBUGLEVEL_TRACE)
                {
                    TLogging.Log("All in all:");
                    SortedList <string, int> sortedtables = new SortedList <string, int>();
                    sortedtables.Add("PLocation", MainDS.PLocation.Count);
                    sortedtables.Add("PPartnerLocation", MainDS.PPartnerLocation.Count);
                    sortedtables.Add("PPartnerType", MainDS.PPartnerType.Count);
                    sortedtables.Add("PPerson", MainDS.PPerson.Count);
                    sortedtables.Add("PFamily", MainDS.PFamily.Count);
                    sortedtables.Add("POrganisation", MainDS.POrganisation.Count);

                    foreach (KeyValuePair <string, int /*TTypedDataTable*/> pair  in sortedtables)
                    {
                        TLogging.Log(pair.Key + " : " + pair.Value.ToString());
                    }
                }
            }
            catch (Exception e)
            {
                TLogging.Log("ExportPartners: " + e.Message);
            }

            DBAccess.GDBAccessObj.RollbackTransaction();
        }
コード例 #11
0
        public static ConferenceSetupTDS LoadConferenceSettings(long AConferenceKey, out string AConferenceName)
        {
            Boolean NewTransaction;

            ConferenceSetupTDS MainDS = new ConferenceSetupTDS();

            TDBTransaction Transaction = DBAccess.GDBAccessObj.GetNewOrExistingTransaction(IsolationLevel.ReadCommitted,
                                                                                           TEnforceIsolationLevel.eilMinimum,
                                                                                           out NewTransaction);

            PPartnerLocationAccess.LoadViaPPartner(MainDS, AConferenceKey, Transaction);
            PcConferenceAccess.LoadByPrimaryKey(MainDS, AConferenceKey, Transaction);
            PcConferenceOptionAccess.LoadViaPcConference(MainDS, AConferenceKey, Transaction);
            PcDiscountAccess.LoadViaPcConference(MainDS, AConferenceKey, Transaction);
            PcConferenceVenueAccess.LoadViaPcConference(MainDS, AConferenceKey, Transaction);
            PUnitAccess.LoadByPrimaryKey(MainDS, AConferenceKey, Transaction);
            AConferenceName = PPartnerAccess.LoadByPrimaryKey(MainDS, AConferenceKey, Transaction).PartnerShortName;

            foreach (ConferenceSetupTDSPcConferenceVenueRow VenueRow in MainDS.PcConferenceVenue.Rows)
            {
                string        VenueName;
                TPartnerClass PartnerClass;
                MPartner.Partner.ServerLookups.WebConnectors.TPartnerServerLookups.GetPartnerShortName(VenueRow.VenueKey,
                                                                                                       out VenueName,
                                                                                                       out PartnerClass);
                VenueRow.VenueName = VenueName;
            }

            // Accept row changes here so that the Client gets 'unmodified' rows
            MainDS.AcceptChanges();

            // Remove all Tables that were not filled with data before remoting them.
            MainDS.RemoveEmptyTables();

            if (NewTransaction)
            {
                DBAccess.GDBAccessObj.RollbackTransaction();
            }

            return(MainDS);
        }
コード例 #12
0
        public static ConferenceSetupTDS LoadConferenceSettings(long AConferenceKey, out string AConferenceName)
        {
            ConferenceSetupTDS MainDS         = new ConferenceSetupTDS();
            string             ConferenceName = null;

            TDBTransaction Transaction = new TDBTransaction();

            DBAccess.ReadTransaction(
                ref Transaction,
                delegate
            {
                PPartnerLocationAccess.LoadViaPPartner(MainDS, AConferenceKey, Transaction);
                PcConferenceAccess.LoadByPrimaryKey(MainDS, AConferenceKey, Transaction);
                PcConferenceOptionAccess.LoadViaPcConference(MainDS, AConferenceKey, Transaction);
                PcDiscountAccess.LoadViaPcConference(MainDS, AConferenceKey, Transaction);
                PcConferenceVenueAccess.LoadViaPcConference(MainDS, AConferenceKey, Transaction);
                PUnitAccess.LoadByPrimaryKey(MainDS, AConferenceKey, Transaction);
                ConferenceName = PPartnerAccess.LoadByPrimaryKey(MainDS, AConferenceKey, Transaction).PartnerShortName;
            });

            foreach (ConferenceSetupTDSPcConferenceVenueRow VenueRow in MainDS.PcConferenceVenue.Rows)
            {
                string        VenueName;
                TPartnerClass PartnerClass;
                MPartner.Partner.ServerLookups.WebConnectors.TPartnerServerLookups.GetPartnerShortName(VenueRow.VenueKey,
                                                                                                       out VenueName,
                                                                                                       out PartnerClass);
                VenueRow.VenueName = VenueName;
            }

            // Accept row changes here so that the Client gets 'unmodified' rows
            MainDS.AcceptChanges();

            // Remove all Tables that were not filled with data before remoting them.
            MainDS.RemoveEmptyTables();

            AConferenceName = ConferenceName;

            return(MainDS);
        }
コード例 #13
0
        /// <summary>
        /// Load all the data of a partner into a TDS
        /// </summary>
        public static PartnerImportExportTDS ExportPartner(Int64 APartnerKey, TPartnerClass?APartnerClass = null)
        {
            PartnerImportExportTDS MainDS = new PartnerImportExportTDS();

            TDBTransaction Transaction = new TDBTransaction();

            DBAccess.ReadTransaction(
                ref Transaction,
                delegate
            {
                PPartnerAccess.LoadByPrimaryKey(MainDS, APartnerKey, Transaction);

                // APartnerClass is optional but if it was not provided we need to assign to it now
                if (APartnerClass == null)
                {
                    APartnerClass = SharedTypes.PartnerClassStringToEnum(MainDS.PPartner[0].PartnerClass);
                }

                if (APartnerClass == TPartnerClass.CHURCH)
                {
                    PChurchAccess.LoadByPrimaryKey(MainDS, APartnerKey, Transaction);
                }
                else if (APartnerClass == TPartnerClass.FAMILY)
                {
                    PFamilyAccess.LoadByPrimaryKey(MainDS, APartnerKey, Transaction);

                    PPartnerGiftDestinationAccess.LoadViaPPartner(MainDS, APartnerKey, Transaction);
                }
                else if (APartnerClass == TPartnerClass.PERSON)
                {
                    PPersonAccess.LoadByPrimaryKey(MainDS, APartnerKey, Transaction);

                    PmPersonalDataAccess.LoadByPrimaryKey(MainDS, APartnerKey, Transaction);
                    PmPassportDetailsAccess.LoadViaPPerson(MainDS, APartnerKey, Transaction);
                    PmDocumentAccess.LoadViaPPartner(MainDS, APartnerKey, Transaction);
                    PmDocumentTypeAccess.LoadAll(MainDS, Transaction);
                    PmPersonQualificationAccess.LoadViaPPerson(MainDS, APartnerKey, Transaction);
                    PmSpecialNeedAccess.LoadViaPPerson(MainDS, APartnerKey, Transaction);
                    PmPastExperienceAccess.LoadViaPPerson(MainDS, APartnerKey, Transaction);
                    PmPersonLanguageAccess.LoadViaPPerson(MainDS, APartnerKey, Transaction);
                    PmPersonAbilityAccess.LoadViaPPerson(MainDS, APartnerKey, Transaction);
                    PmStaffDataAccess.LoadViaPPerson(MainDS, APartnerKey, Transaction);
                    PmJobAssignmentAccess.LoadViaPPartner(MainDS, APartnerKey, Transaction);
                    PmPersonEvaluationAccess.LoadViaPPerson(MainDS, APartnerKey, Transaction);
                    PmPersonSkillAccess.LoadViaPPerson(MainDS, APartnerKey, Transaction);

                    PmGeneralApplicationAccess.LoadViaPPersonPartnerKey(MainDS, APartnerKey, Transaction);
                    PtApplicationTypeAccess.LoadAll(MainDS, Transaction);
                    PmShortTermApplicationAccess.LoadViaPPerson(MainDS, APartnerKey, Transaction);
                    PmYearProgramApplicationAccess.LoadViaPPerson(MainDS, APartnerKey, Transaction);
                }
                else if (APartnerClass == TPartnerClass.ORGANISATION)
                {
                    POrganisationAccess.LoadByPrimaryKey(MainDS, APartnerKey, Transaction);
                }
                else if (APartnerClass == TPartnerClass.UNIT)
                {
                    PUnitAccess.LoadByPrimaryKey(MainDS, APartnerKey, Transaction);

                    UmUnitStructureAccess.LoadViaPUnitChildUnitKey(MainDS, APartnerKey, Transaction);
                    UmUnitAbilityAccess.LoadViaPUnit(MainDS, APartnerKey, Transaction);
                    UmUnitLanguageAccess.LoadViaPUnit(MainDS, APartnerKey, Transaction);
                    UmUnitCostAccess.LoadViaPUnit(MainDS, APartnerKey, Transaction);
                    UmJobAccess.LoadViaPUnit(MainDS, APartnerKey, Transaction);
                    UmJobRequirementAccess.LoadViaPUnit(MainDS, APartnerKey, Transaction);
                    UmJobLanguageAccess.LoadViaPUnit(MainDS, APartnerKey, Transaction);
                    UmJobQualificationAccess.LoadViaPUnit(MainDS, APartnerKey, Transaction);
                }
                else if (APartnerClass == TPartnerClass.VENUE)
                {
                    PVenueAccess.LoadByPrimaryKey(MainDS, APartnerKey, Transaction);

                    PcBuildingAccess.LoadViaPVenue(MainDS, APartnerKey, Transaction);
                    PcRoomAccess.LoadViaPVenue(MainDS, APartnerKey, Transaction);
                }

                PPartnerAttributeAccess.LoadViaPPartner(MainDS, APartnerKey, Transaction);

                PLocationAccess.LoadViaPPartner(MainDS, APartnerKey, Transaction);
                PPartnerLocationAccess.LoadViaPPartner(MainDS, APartnerKey, Transaction);

                PPartnerCommentAccess.LoadViaPPartner(MainDS, APartnerKey, Transaction);
                PPartnerTypeAccess.LoadViaPPartner(MainDS, APartnerKey, Transaction);
                PPartnerInterestAccess.LoadViaPPartner(MainDS, APartnerKey, Transaction);
                PInterestAccess.LoadAll(MainDS, Transaction);
            });

            return(MainDS);
        }
コード例 #14
0
        public static void CreateNewConference(long APartnerKey)
        {
            TDBTransaction Transaction  = new TDBTransaction();
            TDataBase      db           = DBAccess.Connect("CreateNewConference");
            bool           SubmissionOK = false;

            PcConferenceTable     ConferenceTable;
            PUnitTable            UnitTable;
            PPartnerLocationTable PartnerLocationTable;

            db.WriteTransaction(ref Transaction, ref SubmissionOK,
                                delegate
            {
                try
                {
                    ConferenceTable      = PcConferenceAccess.LoadAll(Transaction);
                    UnitTable            = PUnitAccess.LoadByPrimaryKey(APartnerKey, Transaction);
                    PartnerLocationTable = PPartnerLocationAccess.LoadViaPPartner(APartnerKey, Transaction);

                    DateTime Start = new DateTime();
                    DateTime End   = new DateTime();

                    foreach (PPartnerLocationRow PartnerLocationRow in PartnerLocationTable.Rows)
                    {
                        if ((PartnerLocationRow.DateEffective != null) || (PartnerLocationRow.DateGoodUntil != null))
                        {
                            if (PartnerLocationRow.DateEffective != null)
                            {
                                Start = (DateTime)PartnerLocationRow.DateEffective;
                            }

                            if (PartnerLocationRow.DateGoodUntil != null)
                            {
                                End = (DateTime)PartnerLocationRow.DateGoodUntil;
                            }

                            break;
                        }
                    }

                    // set column values
                    PcConferenceRow AddRow = ConferenceTable.NewRowTyped();
                    AddRow.ConferenceKey   = APartnerKey;

                    string OutreachPrefix = ((PUnitRow)UnitTable.Rows[0]).OutreachCode;

                    if (OutreachPrefix.Length > 4)
                    {
                        AddRow.OutreachPrefix = OutreachPrefix.Substring(0, 5);
                    }
                    else
                    {
                        AddRow.OutreachPrefix = OutreachPrefix;
                    }

                    if (Start != DateTime.MinValue)
                    {
                        AddRow.Start = Start;
                    }

                    if (End != DateTime.MinValue)
                    {
                        AddRow.End = End;
                    }

                    string CurrencyCode = ((PUnitRow)UnitTable.Rows[0]).OutreachCostCurrencyCode;

                    if (!string.IsNullOrEmpty(CurrencyCode))
                    {
                        AddRow.CurrencyCode = CurrencyCode;
                    }
                    else
                    {
                        AddRow.CurrencyCode = "USD";
                    }

                    // add new row to database table
                    ConferenceTable.Rows.Add(AddRow);
                    PcConferenceAccess.SubmitChanges(ConferenceTable, Transaction);

                    SubmissionOK = true;
                }
                catch (Exception Exc)
                {
                    TLogging.Log("An Exception occured during the creation of a new Conference:" + Environment.NewLine + Exc.ToString());
                }
            });
        }
コード例 #15
0
        public static void CreateNewConference(long APartnerKey)
        {
            TDBTransaction        Transaction;
            PcConferenceTable     ConferenceTable;
            PUnitTable            UnitTable;
            PPartnerLocationTable PartnerLocationTable;

            Transaction = DBAccess.GDBAccessObj.BeginTransaction(IsolationLevel.Serializable);

            try
            {
                ConferenceTable      = PcConferenceAccess.LoadAll(Transaction);
                UnitTable            = PUnitAccess.LoadByPrimaryKey(APartnerKey, Transaction);
                PartnerLocationTable = PPartnerLocationAccess.LoadViaPPartner(APartnerKey, Transaction);

                DateTime Start = new DateTime();
                DateTime End   = new DateTime();

                foreach (PPartnerLocationRow PartnerLocationRow in PartnerLocationTable.Rows)
                {
                    if ((PartnerLocationRow.DateEffective != null) || (PartnerLocationRow.DateGoodUntil != null))
                    {
                        if (PartnerLocationRow.DateEffective != null)
                        {
                            Start = (DateTime)PartnerLocationRow.DateEffective;
                        }

                        if (PartnerLocationRow.DateGoodUntil != null)
                        {
                            End = (DateTime)PartnerLocationRow.DateGoodUntil;
                        }

                        break;
                    }
                }

                // set column values
                PcConferenceRow AddRow = ConferenceTable.NewRowTyped();
                AddRow.ConferenceKey = APartnerKey;

                string OutreachPrefix = ((PUnitRow)UnitTable.Rows[0]).OutreachCode;

                if (OutreachPrefix.Length > 4)
                {
                    AddRow.OutreachPrefix = OutreachPrefix.Substring(0, 5);
                }
                else
                {
                    AddRow.OutreachPrefix = OutreachPrefix;
                }

                if (Start != DateTime.MinValue)
                {
                    AddRow.Start = Start;
                }

                if (End != DateTime.MinValue)
                {
                    AddRow.End = End;
                }

                string CurrencyCode = ((PUnitRow)UnitTable.Rows[0]).OutreachCostCurrencyCode;

                if (!string.IsNullOrEmpty(CurrencyCode))
                {
                    AddRow.CurrencyCode = CurrencyCode;
                }
                else
                {
                    AddRow.CurrencyCode = "USD";
                }

                // add new row to database table
                ConferenceTable.Rows.Add(AddRow);
                PcConferenceAccess.SubmitChanges(ConferenceTable, Transaction);

                DBAccess.GDBAccessObj.CommitTransaction();
                TLogging.LogAtLevel(7, "TConferenceDataReaderWebConnector.CreateNewConference: commit own transaction.");
            }
            catch (Exception Exc)
            {
                TLogging.Log("An Exception occured during the creation of a new Conference:" + Environment.NewLine + Exc.ToString());

                DBAccess.GDBAccessObj.RollbackTransaction();

                throw;
            }
        }
コード例 #16
0
        public static PartnerEditTDS GetPartnerDetails(Int64 APartnerKey,
                                                       out List <string> ASubscriptions,
                                                       out List <string> APartnerTypes,
                                                       out string ADefaultEmailAddress,
                                                       out string ADefaultPhoneMobile,
                                                       out string ADefaultPhoneLandline)
        {
            PartnerEditTDS MainDS               = new PartnerEditTDS();
            List <string>  Subscriptions        = new List <string>();
            List <string>  PartnerTypes         = new List <string>();
            string         DefaultEmailAddress  = String.Empty;
            string         DefaultPhoneMobile   = String.Empty;
            string         DefaultPhoneLandline = String.Empty;

            TDBTransaction Transaction = null;

            DBAccess.GDBAccessObj.BeginAutoReadTransaction(IsolationLevel.ReadCommitted, ref Transaction,
                                                           delegate
            {
                PPartnerAccess.LoadByPrimaryKey(MainDS, APartnerKey, Transaction);

                if (MainDS.PPartner.Rows.Count > 0)
                {
                    switch (MainDS.PPartner[0].PartnerClass)
                    {
                    case MPartnerConstants.PARTNERCLASS_FAMILY:
                        PFamilyAccess.LoadByPrimaryKey(MainDS, APartnerKey, Transaction);
                        break;

                    case MPartnerConstants.PARTNERCLASS_PERSON:
                        PPersonAccess.LoadByPrimaryKey(MainDS, APartnerKey, Transaction);
                        break;

                    case MPartnerConstants.PARTNERCLASS_CHURCH:
                        PChurchAccess.LoadByPrimaryKey(MainDS, APartnerKey, Transaction);
                        break;

                    case MPartnerConstants.PARTNERCLASS_ORGANISATION:
                        POrganisationAccess.LoadByPrimaryKey(MainDS, APartnerKey, Transaction);
                        break;

                    case MPartnerConstants.PARTNERCLASS_BANK:
                        PBankAccess.LoadByPrimaryKey(MainDS, APartnerKey, Transaction);
                        break;

                    case MPartnerConstants.PARTNERCLASS_UNIT:
                        PUnitAccess.LoadByPrimaryKey(MainDS, APartnerKey, Transaction);
                        break;
                    }

                    if (true)
                    {
                        PPartnerLocationAccess.LoadViaPPartner(MainDS, APartnerKey, Transaction);
                        PLocationAccess.LoadViaPPartner(MainDS, APartnerKey, Transaction);
                    }

                    if (true)
                    {
                        PPartnerRelationshipAccess.LoadViaPPartnerPartnerKey(MainDS, APartnerKey, Transaction);
                    }

                    if (true)
                    {
                        PPublicationAccess.LoadAll(MainDS, Transaction);
                        PSubscriptionAccess.LoadViaPPartnerPartnerKey(MainDS, APartnerKey, Transaction);

                        foreach (PSubscriptionRow subscription in MainDS.PSubscription.Rows)
                        {
                            Subscriptions.Add(subscription.PublicationCode);
                        }
                    }

                    PPartnerStatusAccess.LoadAll(MainDS, Transaction);
                    PTypeAccess.LoadAll(MainDS, Transaction);
                    PPartnerTypeAccess.LoadViaPPartner(MainDS, APartnerKey, Transaction);

                    foreach (PPartnerTypeRow partnertype in MainDS.PPartnerType.Rows)
                    {
                        PartnerTypes.Add(partnertype.TypeCode);
                    }

                    PPartnerAttributeAccess.LoadViaPPartner(MainDS, APartnerKey, Transaction);

                    foreach (PPartnerAttributeRow partnerattr in MainDS.PPartnerAttribute.Rows)
                    {
                        if (partnerattr.AttributeType == MPartnerConstants.ATTR_TYPE_EMAIL)
                        {
                            DefaultEmailAddress = partnerattr.Value;
                        }
                        else if (partnerattr.AttributeType == MPartnerConstants.ATTR_TYPE_PHONE)
                        {
                            DefaultPhoneLandline = partnerattr.Value;
                        }
                        else if (partnerattr.AttributeType == MPartnerConstants.ATTR_TYPE_MOBILE_PHONE)
                        {
                            DefaultPhoneMobile = partnerattr.Value;
                        }
                    }
                }
            });

            APartnerTypes         = PartnerTypes;
            ASubscriptions        = Subscriptions;
            ADefaultEmailAddress  = DefaultEmailAddress;
            ADefaultPhoneMobile   = DefaultPhoneMobile;
            ADefaultPhoneLandline = DefaultPhoneLandline;

            return(MainDS);
        }
コード例 #17
0
        public void TestNewPartnerWithLocation0()
        {
            TPartnerEditUIConnector connector = new TPartnerEditUIConnector();

            PartnerEditTDS MainDS = new PartnerEditTDS();

            PPartnerRow PartnerRow = TCreateTestPartnerData.CreateNewFamilyPartner(MainDS);

            PPartnerLocationRow PartnerLocationRow = MainDS.PPartnerLocation.NewRowTyped();

            PartnerLocationRow.SiteKey     = DomainManager.GSiteKey;
            PartnerLocationRow.PartnerKey  = PartnerRow.PartnerKey;
            PartnerLocationRow.LocationKey = 0;
            MainDS.PPartnerLocation.Rows.Add(PartnerLocationRow);

            DataSet ResponseDS = new PartnerEditTDS();
            TVerificationResultCollection VerificationResult;

            TSubmitChangesResult result = connector.SubmitChanges(ref MainDS, ref ResponseDS, out VerificationResult);

            CommonNUnitFunctions.EnsureNullOrOnlyNonCriticalVerificationResults(VerificationResult,
                                                                                "There was a critical error when saving:");

            Assert.AreEqual(TSubmitChangesResult.scrOK, result, "Create a partner with location 0");

            TCreateTestPartnerData.CreateNewLocation(PartnerRow.PartnerKey, MainDS);

            // remove location 0, same is done in csharp\ICT\Petra\Client\MCommon\logic\UC_PartnerAddresses.cs TUCPartnerAddressesLogic::AddRecord
            // Check if record with PartnerLocation.LocationKey = 0 is around > delete it
            DataRow PartnerLocationRecordZero =
                MainDS.PPartnerLocation.Rows.Find(new object[] { PartnerRow.PartnerKey, DomainManager.GSiteKey, 0 });

            if (PartnerLocationRecordZero != null)
            {
                DataRow LocationRecordZero = MainDS.PLocation.Rows.Find(new object[] { DomainManager.GSiteKey, 0 });

                if (LocationRecordZero != null)
                {
                    LocationRecordZero.Delete();
                }

                PartnerLocationRecordZero.Delete();
            }

            ResponseDS = new PartnerEditTDS();
            result     = connector.SubmitChanges(ref MainDS, ref ResponseDS, out VerificationResult);

            CommonNUnitFunctions.EnsureNullOrOnlyNonCriticalVerificationResults(VerificationResult,
                                                                                "There was a critical error when saving:");

            Assert.AreEqual(TSubmitChangesResult.scrOK, result, "Replace location 0 of partner");

            Assert.AreEqual(1, MainDS.PPartnerLocation.Rows.Count, "the partner should only have one location in the dataset");

            // get all addresses of the partner
            TDBTransaction ReadTransaction = null;

            DBAccess.GDBAccessObj.GetNewOrExistingAutoReadTransaction(IsolationLevel.ReadCommitted, TEnforceIsolationLevel.eilMinimum,
                                                                      ref ReadTransaction,
                                                                      delegate
            {
                PPartnerLocationTable testPartnerLocations = PPartnerLocationAccess.LoadViaPPartner(PartnerRow.PartnerKey, ReadTransaction);
                Assert.AreEqual(1, testPartnerLocations.Rows.Count, "the partner should only have one location");
                Assert.Greater(testPartnerLocations[0].LocationKey, 0, "TPartnerEditUIConnector SubmitChanges returns valid location key");
            });
        }
コード例 #18
0
        /// Upgrade to version 2015-01
        public static bool UpgradeDatabase201412_201501()
        {
            // There are no new tables and fields

            TDBTransaction       SubmitChangesTransaction = null;
            TSubmitChangesResult SubmissionResult         = TSubmitChangesResult.scrError;

            DBAccess.GDBAccessObj.BeginAutoTransaction(IsolationLevel.Serializable, ref SubmitChangesTransaction,
                                                       ref SubmissionResult,
                                                       delegate
            {
                PPartnerAttributeTable partnerattributes = new PPartnerAttributeTable();
                PPartnerLocationTable partnerlocations   = PPartnerLocationAccess.LoadAll(SubmitChangesTransaction);

                // this update only works for very simple databases, only one partner location record per partner...
                if (partnerlocations.Count > 1000)
                {
                    throw new Exception("the upgrade has not been optimized for huge databases");
                }

                List <Int64> PartnerKeys = new List <Int64>();

                foreach (PPartnerLocationRow partnerlocation in partnerlocations.Rows)
                {
                    if (!PartnerKeys.Contains(partnerlocation.PartnerKey))
                    {
                        PartnerKeys.Add(partnerlocation.PartnerKey);
                    }
                    else
                    {
                        TLogging.Log("several locations for partner " + partnerlocation.PartnerKey.ToString());
                    }
                }

                // Number for the p_sequence_i Column. Gets increased with every p_partner_attribute record that gets produced!
                int SequenceNumber = 0;

                foreach (Int64 partnerkey in PartnerKeys)
                {
                    // Get that Partner's p_partner_location records from PPartnerLocationRecords
                    DataRow[] CurrentRows = partnerlocations.Select(PPartnerLocationTable.GetPartnerKeyDBName() + " = " + partnerkey.ToString());

                    if (CurrentRows.Length == 0)
                    {
                        continue;
                    }

                    DataTable PPartnersLocationsDT = GetNewPPartnerLocationTableInstance();

                    foreach (DataRow r in CurrentRows)
                    {
                        PPartnersLocationsDT.Rows.Add(r.ItemArray);
                    }

                    TLocationPK bestAddress = Calculations.DetermineBestAddress(PPartnersLocationsDT);

                    int IndexPhone  = 0;
                    int IndexEmail  = 0;
                    int IndexFax    = 0;
                    int IndexUrl    = 0;
                    int IndexMobile = 0;

                    List <string> AvoidDuplicates = new List <string>();
                    string AttributeConcatenated;

                    foreach (PPartnerLocationRow partnerlocation in PPartnersLocationsDT.Rows)
                    {
                        bool primaryAddress =
                            (bestAddress.LocationKey == partnerlocation.LocationKey && bestAddress.SiteKey == partnerlocation.SiteKey);
                        bool currentAddress  = (((int)partnerlocation[PARTNERLOCATION_ICON_COLUMN]) == 1);
                        bool businessAddress = (partnerlocation.LocationType == "BUSINESS" || partnerlocation.LocationType == "FIELD");
                        // TODO: avoid duplicate entries with the same type

                        if (!partnerlocation.IsEmailAddressNull())
                        {
                            PPartnerAttributeRow partnerattribute = partnerattributes.NewRowTyped();
                            partnerattribute.Sequence             = SequenceNumber++;
                            partnerattribute.PartnerKey           = partnerlocation.PartnerKey;
                            partnerattribute.Value               = partnerlocation.EmailAddress;
                            partnerattribute.AttributeType       = MPartnerConstants.ATTR_TYPE_EMAIL;
                            partnerattribute.Current             = currentAddress;
                            partnerattribute.Primary             = primaryAddress;
                            partnerattribute.Index               = IndexEmail++;
                            partnerattribute.Specialised         = businessAddress;
                            partnerattribute.NoLongerCurrentFrom = partnerlocation.DateGoodUntil;

                            AttributeConcatenated = ConcatPartnerAttributes(partnerattribute);

                            if (!AvoidDuplicates.Contains(AttributeConcatenated))
                            {
                                partnerattributes.Rows.Add(partnerattribute);
                                AvoidDuplicates.Add(AttributeConcatenated);
                            }
                            else
                            {
                                TLogging.Log("dropping duplicate " + AttributeConcatenated);
                            }

                            partnerlocation.SetEmailAddressNull();
                        }

                        if (!partnerlocation.IsTelephoneNumberNull())
                        {
                            if (!partnerlocation.IsExtensionNull())
                            {
                                partnerlocation.TelephoneNumber += "-" + partnerlocation.Extension;
                            }

                            PPartnerAttributeRow partnerattribute = partnerattributes.NewRowTyped();
                            partnerattribute.Sequence             = SequenceNumber++;
                            partnerattribute.PartnerKey           = partnerlocation.PartnerKey;
                            partnerattribute.Value               = partnerlocation.TelephoneNumber;
                            partnerattribute.AttributeType       = MPartnerConstants.ATTR_TYPE_PHONE;
                            partnerattribute.Current             = currentAddress;
                            partnerattribute.Primary             = primaryAddress;
                            partnerattribute.Index               = IndexPhone++;
                            partnerattribute.Specialised         = businessAddress;
                            partnerattribute.NoLongerCurrentFrom = partnerlocation.DateGoodUntil;

                            AttributeConcatenated = ConcatPartnerAttributes(partnerattribute);

                            if (!AvoidDuplicates.Contains(AttributeConcatenated))
                            {
                                partnerattributes.Rows.Add(partnerattribute);
                                AvoidDuplicates.Add(AttributeConcatenated);
                            }
                            else
                            {
                                TLogging.Log("dropping duplicate " + AttributeConcatenated);
                            }

                            partnerlocation.SetTelephoneNumberNull();
                        }

                        if (!partnerlocation.IsFaxNumberNull())
                        {
                            if (!partnerlocation.IsFaxExtensionNull())
                            {
                                partnerlocation.FaxNumber += "-" + partnerlocation.FaxExtension;
                            }

                            PPartnerAttributeRow partnerattribute = partnerattributes.NewRowTyped();
                            partnerattribute.Sequence             = SequenceNumber++;
                            partnerattribute.PartnerKey           = partnerlocation.PartnerKey;
                            partnerattribute.Value               = partnerlocation.FaxNumber;
                            partnerattribute.AttributeType       = MPartnerConstants.ATTR_TYPE_FAX;
                            partnerattribute.Current             = currentAddress;
                            partnerattribute.Primary             = primaryAddress;
                            partnerattribute.Index               = IndexFax++;
                            partnerattribute.Specialised         = businessAddress;
                            partnerattribute.NoLongerCurrentFrom = partnerlocation.DateGoodUntil;

                            AttributeConcatenated = ConcatPartnerAttributes(partnerattribute);

                            if (!AvoidDuplicates.Contains(AttributeConcatenated))
                            {
                                partnerattributes.Rows.Add(partnerattribute);
                                AvoidDuplicates.Add(AttributeConcatenated);
                            }
                            else
                            {
                                TLogging.Log("dropping duplicate " + AttributeConcatenated);
                            }

                            partnerlocation.SetFaxNumberNull();
                        }

                        if (!partnerlocation.IsAlternateTelephoneNull())
                        {
                            PPartnerAttributeRow partnerattribute = partnerattributes.NewRowTyped();
                            partnerattribute.Sequence             = SequenceNumber++;
                            partnerattribute.PartnerKey           = partnerlocation.PartnerKey;
                            partnerattribute.Value               = partnerlocation.AlternateTelephone;
                            partnerattribute.AttributeType       = MPartnerConstants.ATTR_TYPE_PHONE;
                            partnerattribute.Current             = currentAddress;
                            partnerattribute.Primary             = primaryAddress;
                            partnerattribute.Index               = IndexPhone++;
                            partnerattribute.Specialised         = businessAddress;
                            partnerattribute.NoLongerCurrentFrom = partnerlocation.DateGoodUntil;

                            AttributeConcatenated = ConcatPartnerAttributes(partnerattribute);

                            if (!AvoidDuplicates.Contains(AttributeConcatenated))
                            {
                                partnerattributes.Rows.Add(partnerattribute);
                                AvoidDuplicates.Add(AttributeConcatenated);
                            }
                            else
                            {
                                TLogging.Log("dropping duplicate " + AttributeConcatenated);
                            }

                            partnerlocation.SetAlternateTelephoneNull();
                        }

                        if (!partnerlocation.IsMobileNumberNull())
                        {
                            PPartnerAttributeRow partnerattribute = partnerattributes.NewRowTyped();
                            partnerattribute.Sequence             = SequenceNumber++;
                            partnerattribute.PartnerKey           = partnerlocation.PartnerKey;
                            partnerattribute.Value               = partnerlocation.MobileNumber;
                            partnerattribute.AttributeType       = MPartnerConstants.ATTR_TYPE_MOBILE_PHONE;
                            partnerattribute.Current             = currentAddress;
                            partnerattribute.Primary             = primaryAddress;
                            partnerattribute.Index               = IndexMobile++;
                            partnerattribute.Specialised         = businessAddress;
                            partnerattribute.NoLongerCurrentFrom = partnerlocation.DateGoodUntil;

                            AttributeConcatenated = ConcatPartnerAttributes(partnerattribute);

                            if (!AvoidDuplicates.Contains(AttributeConcatenated))
                            {
                                partnerattributes.Rows.Add(partnerattribute);
                                AvoidDuplicates.Add(AttributeConcatenated);
                            }
                            else
                            {
                                TLogging.Log("dropping duplicate " + AttributeConcatenated);
                            }

                            partnerlocation.SetMobileNumberNull();
                        }

                        if (!partnerlocation.IsUrlNull())
                        {
                            PPartnerAttributeRow partnerattribute = partnerattributes.NewRowTyped();
                            partnerattribute.Sequence             = SequenceNumber++;
                            partnerattribute.PartnerKey           = partnerlocation.PartnerKey;
                            partnerattribute.Value               = partnerlocation.Url;
                            partnerattribute.AttributeType       = MPartnerConstants.ATTR_TYPE_WEBSITE;
                            partnerattribute.Current             = currentAddress;
                            partnerattribute.Primary             = primaryAddress;
                            partnerattribute.Index               = IndexUrl++;
                            partnerattribute.Specialised         = businessAddress;
                            partnerattribute.NoLongerCurrentFrom = partnerlocation.DateGoodUntil;

                            AttributeConcatenated = ConcatPartnerAttributes(partnerattribute);

                            if (!AvoidDuplicates.Contains(AttributeConcatenated))
                            {
                                partnerattributes.Rows.Add(partnerattribute);
                                AvoidDuplicates.Add(AttributeConcatenated);
                            }
                            else
                            {
                                TLogging.Log("dropping duplicate " + AttributeConcatenated);
                            }

                            partnerlocation.SetUrlNull();
                        }
                    }
                }

                PPartnerLocationAccess.SubmitChanges(partnerlocations, SubmitChangesTransaction);
                PPartnerAttributeAccess.SubmitChanges(partnerattributes, SubmitChangesTransaction);
                SubmissionResult = TSubmitChangesResult.scrOK;
            });
            return(true);
        }
コード例 #19
0
ファイル: Extracts.cs プロジェクト: merbst/openpetra
        /// <summary>
        /// Determine best location for partner out of a list of possible locations. Or simply find best one
        /// if no suggestion is made.
        /// </summary>
        /// <param name="APartnerKey"></param>
        /// <param name="ALocationKeyList"></param>
        /// <param name="APartnerLocationKeysTable"></param>
        /// <param name="ATransaction"></param>
        /// <returns>True if the address was found and added, otherwise false.</returns>
        private static Boolean DetermineAndAddBestLocationKey(
            Int64 APartnerKey,
            List <TLocationPK> ALocationKeyList,
            ref PPartnerLocationTable APartnerLocationKeysTable,
            TDBTransaction ATransaction)
        {
            PPartnerLocationTable AllPartnerLocationTable;
            PPartnerLocationTable FilteredPartnerLocationTable = new PPartnerLocationTable();
            TLocationPK           LocationPK = new TLocationPK();
            PPartnerLocationRow   PartnerLocationKeyRow;
            PPartnerLocationRow   PartnerLocationRowCopy;
            TLocationPK           BestLocationPK;

            if (ALocationKeyList.Count == 0)
            {
                // no list suggested: find best address in db for this partner
                BestLocationPK = TMailing.GetPartnersBestLocation(APartnerKey);
            }
            else if (ALocationKeyList.Count == 1)
            {
                // only one location suggested: take this one
                BestLocationPK = ALocationKeyList[0];
            }
            else
            {
                // Process location key list related to partner.
                // In order to use Calculations.DetermineBestAddress we need to first retrieve full data
                // for all suggested records from the db. Therefore load all locations for this partner
                // and then create a table of the ones that are suggested.
                AllPartnerLocationTable = PPartnerLocationAccess.LoadViaPPartner(APartnerKey, ATransaction);

                foreach (PPartnerLocationRow PartnerLocationRow in AllPartnerLocationTable.Rows)
                {
                    LocationPK.SiteKey     = PartnerLocationRow.SiteKey;
                    LocationPK.LocationKey = PartnerLocationRow.LocationKey;

                    if (ALocationKeyList.Contains(LocationPK))
                    {
                        PartnerLocationRowCopy = (PPartnerLocationRow)FilteredPartnerLocationTable.NewRow();
                        DataUtilities.CopyAllColumnValues(PartnerLocationRow, PartnerLocationRowCopy);
                        FilteredPartnerLocationTable.Rows.Add(PartnerLocationRowCopy);
                    }
                }

                BestLocationPK = Calculations.DetermineBestAddress(FilteredPartnerLocationTable);
            }

            // create new row, initialize it and add it to the table
            if (BestLocationPK.LocationKey != -1)
            {
                PartnerLocationKeyRow = (PPartnerLocationRow)APartnerLocationKeysTable.NewRow();
                PartnerLocationKeyRow[PPartnerLocationTable.GetPartnerKeyDBName()]  = APartnerKey;
                PartnerLocationKeyRow[PPartnerLocationTable.GetSiteKeyDBName()]     = BestLocationPK.SiteKey;
                PartnerLocationKeyRow[PPartnerLocationTable.GetLocationKeyDBName()] = BestLocationPK.LocationKey;

                // only add row if it does not already exist
                if (!APartnerLocationKeysTable.Rows.Contains(
                        new object[] { PartnerLocationKeyRow.PartnerKey, PartnerLocationKeyRow.SiteKey, PartnerLocationKeyRow.LocationKey }))
                {
                    APartnerLocationKeysTable.Rows.Add(PartnerLocationKeyRow);
                }

                return(true);
            }
            else
            {
                return(false);
            }
        }
コード例 #20
0
ファイル: Extracts.cs プロジェクト: merbst/openpetra
        /// <summary>
        /// extend an extract from a list of best addresses
        /// </summary>
        /// <param name="AExtractId">Extract Id of the Extract to extend</param>
        /// <param name="APartnerKeysTable"></param>
        /// <param name="APartnerKeyColumn">number of the column that contains the partner keys</param>
        /// <param name="ASiteKeyColumn">number of the column that contains the site keys</param>
        /// <param name="ALocationKeyColumn">number of the column that contains the location keys</param>
        /// <param name="AKeyCount">The number of keys that were actually added to the extract (any duplicates are excluded)</param>
        /// <param name="AIgnoredKeyList">A reference to a List of long.  If not null the server will fill it with the partner keys that were ignored.  Does not include duplicates.</param>
        /// <param name="AIgnoreDuplicates">true if duplicates should be looked out for. Can be set to false if called only once and not several times per extract.</param>
        /// <param name="AIgnoreInactive">true if inactive partners should be ignored</param>
        /// <param name="AIgnoreNonMailingLocations">true to ignore if the partner's best address is a non-mailing location</param>
        /// <param name="AIgnoreNoSolicitations">true to ignore partners where the No Solicitations flag is set</param>
        public static void ExtendExtractFromListOfPartnerKeys(
            Int32 AExtractId,
            DataTable APartnerKeysTable,
            Int32 APartnerKeyColumn,
            Int32 ASiteKeyColumn,
            Int32 ALocationKeyColumn,
            out Int32 AKeyCount,
            out List <long> AIgnoredKeyList,
            bool AIgnoreDuplicates,
            bool AIgnoreInactive,
            bool AIgnoreNonMailingLocations,
            bool AIgnoreNoSolicitations)
        {
            int RecordCounter = 0;
            PPartnerLocationTable PartnerLocationKeysTable;
            Int64 PartnerKey;

            List <long> ignoredKeyList = new List <long>();

            TDBTransaction Transaction  = null;
            bool           SubmissionOK = true;

            DBAccess.GDBAccessObj.GetNewOrExistingAutoTransaction(IsolationLevel.Serializable, ref Transaction, ref SubmissionOK,
                                                                  delegate
            {
                // Pre-process the table to remove partner rows that do not match the filter requirements
                for (int i = APartnerKeysTable.Rows.Count - 1; i >= 0; i--)
                {
                    DataRow dr       = APartnerKeysTable.Rows[i];
                    Int64 partnerKey = Convert.ToInt64(dr[APartnerKeyColumn]);

                    // Get a partner record containing our fields of interest
                    StringCollection fields = new StringCollection();
                    fields.Add(PPartnerTable.GetStatusCodeDBName());
                    fields.Add(PPartnerTable.GetNoSolicitationsDBName());
                    DataTable dt = PPartnerAccess.LoadByPrimaryKey(partnerKey, fields, Transaction);

                    if (dt.Rows.Count > 0)
                    {
                        if (AIgnoreInactive || AIgnoreNoSolicitations)
                        {
                            bool isActive         = false;
                            bool isNoSolicitation = false;
                            object o = dt.Rows[0][PPartnerTable.GetStatusCodeDBName()];

                            if (o != null)
                            {
                                TStdPartnerStatusCode statusCode = SharedTypes.StdPartnerStatusCodeStringToEnum(o.ToString());
                                isActive = (statusCode == TStdPartnerStatusCode.spscACTIVE);
                            }

                            o = dt.Rows[0][PPartnerTable.GetNoSolicitationsDBName()];

                            if (o != null)
                            {
                                isNoSolicitation = Convert.ToBoolean(o);
                            }

                            if ((AIgnoreInactive && !isActive) || (AIgnoreNoSolicitations && isNoSolicitation))
                            {
                                ignoredKeyList.Add(partnerKey);
                                APartnerKeysTable.Rows.Remove(dr);
                            }
                        }
                    }
                    else
                    {
                        ignoredKeyList.Add(partnerKey);
                    }
                }

                MExtractTable ExtractTable = new MExtractTable();
                ExtractTable = MExtractAccess.LoadViaMExtractMaster(AExtractId, Transaction);

                // Location Keys need to be determined as extracts do not only need partner keys but
                // also Location Keys.
                DetermineBestLocationKeys(APartnerKeysTable, APartnerKeyColumn, ASiteKeyColumn,
                                          ALocationKeyColumn, out PartnerLocationKeysTable,
                                          Transaction);

                // use the returned table which contains partner and location keys to build the extract
                foreach (PPartnerLocationRow PartnerLocationRow in PartnerLocationKeysTable.Rows)
                {
                    PartnerKey = PartnerLocationRow.PartnerKey;

                    if (PartnerKey > 0)
                    {
                        if (AIgnoreNonMailingLocations)
                        {
                            // The PartnerLocationRow only contains the PK fields so now we need to get the SendMail column
                            StringCollection fields = new StringCollection();
                            fields.Add(PPartnerLocationTable.GetSendMailDBName());

                            PPartnerLocationTable t =
                                PPartnerLocationAccess.LoadByPrimaryKey(PartnerKey, PartnerLocationRow.SiteKey,
                                                                        PartnerLocationRow.LocationKey, fields, Transaction);

                            if ((t != null) && (t.Rows.Count > 0) && (((PPartnerLocationRow)t.Rows[0]).SendMail == false))
                            {
                                ignoredKeyList.Add(PartnerKey);
                                continue;
                            }
                        }

                        RecordCounter += 1;
                        TLogging.LogAtLevel(1, "Preparing Partner " + PartnerKey + " (Record Number " + RecordCounter + ")");

                        // add row for partner to extract and fill with contents
                        MExtractRow NewRow = ExtractTable.NewRowTyped();
                        NewRow.ExtractId   = AExtractId;
                        NewRow.PartnerKey  = PartnerKey;
                        NewRow.SiteKey     = Convert.ToInt64(PartnerLocationRow[PPartnerLocationTable.GetSiteKeyDBName()]);
                        NewRow.LocationKey = Convert.ToInt32(PartnerLocationRow[PPartnerLocationTable.GetLocationKeyDBName()]);

                        // only add row if it does not already exist for this partner
                        if (AIgnoreDuplicates || !ExtractTable.Rows.Contains(new object[] { NewRow.ExtractId, NewRow.PartnerKey, NewRow.SiteKey }))
                        {
                            ExtractTable.Rows.Add(NewRow);
                        }
                    }
                }

                if (ExtractTable.Rows.Count > 0)
                {
                    // update field in extract master for quick access to number of partners in extract
                    MExtractMasterTable ExtractMaster = MExtractMasterAccess.LoadByPrimaryKey(AExtractId, Transaction);
                    ExtractMaster[0].KeyCount         = ExtractTable.Rows.Count;

                    ExtractTable.ThrowAwayAfterSubmitChanges = true;     // no need to keep data as this increases speed significantly

                    MExtractAccess.SubmitChanges(ExtractTable, Transaction);

                    MExtractMasterAccess.SubmitChanges(ExtractMaster, Transaction);
                }
            });

            AKeyCount       = RecordCounter;
            AIgnoredKeyList = ignoredKeyList;
        }
コード例 #21
0
        public static PartnerEditTDS GetPartnerDetails(Int64 APartnerKey,
                                                       out List <string> ASubscriptions,
                                                       out List <string> APartnerTypes,
                                                       out string ADefaultEmailAddress,
                                                       out string ADefaultPhoneMobile,
                                                       out string ADefaultPhoneLandline)
        {
            PartnerEditTDS MainDS               = new PartnerEditTDS();
            List <string>  Subscriptions        = new List <string>();
            List <string>  PartnerTypes         = new List <string>();
            string         DefaultEmailAddress  = String.Empty;
            string         DefaultPhoneMobile   = String.Empty;
            string         DefaultPhoneLandline = String.Empty;

            TDBTransaction Transaction = new TDBTransaction();

            DBAccess.ReadTransaction(ref Transaction,
                                     delegate
            {
                PPartnerAccess.LoadByPrimaryKey(MainDS, APartnerKey, Transaction);

                if (MainDS.PPartner.Rows.Count > 0)
                {
                    switch (MainDS.PPartner[0].PartnerClass)
                    {
                    case MPartnerConstants.PARTNERCLASS_FAMILY:
                        PFamilyAccess.LoadByPrimaryKey(MainDS, APartnerKey, Transaction);
                        break;

                    case MPartnerConstants.PARTNERCLASS_PERSON:
                        PPersonAccess.LoadByPrimaryKey(MainDS, APartnerKey, Transaction);
                        break;

                    case MPartnerConstants.PARTNERCLASS_CHURCH:
                        PChurchAccess.LoadByPrimaryKey(MainDS, APartnerKey, Transaction);
                        break;

                    case MPartnerConstants.PARTNERCLASS_ORGANISATION:
                        POrganisationAccess.LoadByPrimaryKey(MainDS, APartnerKey, Transaction);
                        break;

                    case MPartnerConstants.PARTNERCLASS_BANK:
                        PBankAccess.LoadByPrimaryKey(MainDS, APartnerKey, Transaction);
                        break;

                    case MPartnerConstants.PARTNERCLASS_UNIT:
                        PUnitAccess.LoadByPrimaryKey(MainDS, APartnerKey, Transaction);
                        break;
                    }

                    if (true)
                    {
                        PPartnerLocationAccess.LoadViaPPartner(MainDS, APartnerKey, Transaction);
                        PLocationAccess.LoadViaPPartner(MainDS, APartnerKey, Transaction);
                    }

                    if (true)
                    {
                        PPartnerRelationshipAccess.LoadViaPPartnerPartnerKey(MainDS, APartnerKey, Transaction);
                    }

                    if (true)
                    {
                        PCountryAccess.LoadAll(MainDS, Transaction);
                    }

                    if (true)
                    {
                        PPublicationAccess.LoadAll(MainDS, Transaction);
                        PSubscriptionAccess.LoadViaPPartnerPartnerKey(MainDS, APartnerKey, Transaction);

                        foreach (PSubscriptionRow subscription in MainDS.PSubscription.Rows)
                        {
                            Subscriptions.Add(subscription.PublicationCode);
                        }
                    }

                    if (true)
                    {
                        PBankingDetailsAccess.LoadViaPPartner(MainDS, APartnerKey, Transaction);
                        PPartnerBankingDetailsAccess.LoadViaPPartner(MainDS, APartnerKey, Transaction);
                        PBankingDetailsUsageAccess.LoadViaPPartner(MainDS, APartnerKey, Transaction);

                        foreach (PartnerEditTDSPBankingDetailsRow banking in MainDS.PBankingDetails.Rows)
                        {
                            PBankAccess.LoadByPrimaryKey(MainDS, banking.BankKey, Transaction);
                            banking.Bic        = MainDS.PBank[0].Bic;
                            banking.BranchName = MainDS.PBank[0].BranchName;
                            banking.Iban       = FormatIBAN(banking.Iban);
                            MainDS.PBank.Rows.Clear();
                        }

                        foreach (PartnerEditTDSPBankingDetailsRow bd in MainDS.PBankingDetails.Rows)
                        {
                            bd.MainAccount =
                                (MainDS.PBankingDetailsUsage.Rows.Find(
                                     new object[] { APartnerKey, bd.BankingDetailsKey, MPartnerConstants.BANKINGUSAGETYPE_MAIN }) != null);
                        }

                        MainDS.PBankingDetailsUsage.Rows.Clear();
                    }

                    PPartnerStatusAccess.LoadAll(MainDS, Transaction);
                    PTypeRow templateRow   = MainDS.PType.NewRowTyped();
                    templateRow.SystemType = false;
                    templateRow.SetTypeDeletableNull();
                    templateRow.SetDateCreatedNull();
                    PTypeAccess.LoadUsingTemplate(MainDS, templateRow, Transaction);
                    PPartnerTypeAccess.LoadViaPPartner(MainDS, APartnerKey, Transaction);

                    foreach (PPartnerTypeRow partnertype in MainDS.PPartnerType.Rows)
                    {
                        PartnerTypes.Add(partnertype.TypeCode);
                    }

                    PPartnerAttributeAccess.LoadViaPPartner(MainDS, APartnerKey, Transaction);

                    foreach (PPartnerAttributeRow partnerattr in MainDS.PPartnerAttribute.Rows)
                    {
                        if (partnerattr.AttributeType == MPartnerConstants.ATTR_TYPE_EMAIL)
                        {
                            DefaultEmailAddress = partnerattr.Value;
                        }
                        else if (partnerattr.AttributeType == MPartnerConstants.ATTR_TYPE_PHONE)
                        {
                            DefaultPhoneLandline = partnerattr.Value;
                        }
                        else if (partnerattr.AttributeType == MPartnerConstants.ATTR_TYPE_MOBILE_PHONE)
                        {
                            DefaultPhoneMobile = partnerattr.Value;
                        }
                    }
                }
            });

            APartnerTypes         = PartnerTypes;
            ASubscriptions        = Subscriptions;
            ADefaultEmailAddress  = DefaultEmailAddress;
            ADefaultPhoneMobile   = DefaultPhoneMobile;
            ADefaultPhoneLandline = DefaultPhoneLandline;

            return(MainDS);
        }