/// <summary>
        /// Called when data got saved in the screen. This Method takes over changed data
        /// into FMainDS, which is different than the Partner Edit screen's FMainDS, in
        /// order to have current data on which decisions on whether to refresh certain
        /// parts of the 'Overview' need to be updated.
        /// </summary>
        /// <param name="APartnerAttributesOrRelationsChanged">NOT USED IN THIS CONTEXT!  (Set to true by the SaveChanges Method
        /// of the Partner Edit screen if PartnerAttributes or Relationships have changed.)</param>
        public void RefreshPersonnelDataAfterMerge(bool APartnerAttributesOrRelationsChanged)
        {
            //
            // Need to merge Tables from PartnerEditTDS into IndividualDataTDS so the updated s_modification_id_t of modififed Rows is held correctly in IndividualDataTDS, too!
            //

            // ...but first empty relevant DataTables to ensure that DataRows that got deleted in FPartnerEditTDS are reflected in FMainDS (just performing a Merge wouldn't remove them!)
            if (FMainDS.Tables.Contains(PPartnerLocationTable.GetTableName()))
            {
                FMainDS.Tables[PPartnerLocationTable.GetTableName()].Rows.Clear();
            }

            if (FMainDS.Tables.Contains(PLocationTable.GetTableName()))
            {
                FMainDS.Tables[PLocationTable.GetTableName()].Rows.Clear();
            }

            if (FMainDS.Tables.Contains(PPartnerRelationshipTable.GetTableName()))
            {
                FMainDS.Tables[PPartnerRelationshipTable.GetTableName()].Rows.Clear();
            }

            // Now perform the Merge operation
            FMainDS.Merge(FPartnerEditTDS);

            // Call AcceptChanges on IndividualDataTDS so that we don't have any changed data anymore (this is done to PartnerEditTDS, too, after this Method returns)!
            FMainDS.AcceptChanges();
        }
Example #2
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);
        }
Example #3
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);
        }
Example #4
0
        /// <summary>
        /// Retrieves all of the PartnerInfo data.
        /// </summary>
        /// <param name="APartnerKey">PartnerKey of Partner to find the PartnerInfo data for</param>
        /// <param name="APartnerInfoDS">Typed DataSet that contains the requested data.</param>
        /// <param name="AReadTransaction" >Open DB Transaction.</param>
        /// <returns>True if Partner exists, otherwise false.</returns>
        public static bool AllPartnerInfoData(Int64 APartnerKey, ref PartnerInfoTDS APartnerInfoDS,
                                              TDBTransaction AReadTransaction)
        {
            bool        ReturnValue = false;
            PPartnerRow PartnerDR;

            TLocationPK           BestLocationPK;
            PLocationRow          LocationDR;
            PLocationRow          LocationDR2;
            PPartnerLocationRow   PartnerLocationDR;
            PPartnerLocationRow   PartnerLocationDR2;
            PLocationTable        LocationDT;
            PPartnerLocationTable PartnerLocationDT;

            try
            {
                /*
                 * Check for existance of Partner
                 */
                PartnerDR = MCommonMain.CheckPartnerExists2(APartnerKey, true, AReadTransaction.DataBaseObj);

                if (PartnerDR != null)
                {
                    /*
                     * Perform security checks; these throw ESecurityPartnerAccessDeniedException
                     * in case access isn't granted.
                     */
                    TSecurity.CanAccessPartnerExc(PartnerDR, AReadTransaction.DataBaseObj);

                    /*
                     * Get the Partner's Address data of its 'Best' Address
                     */
                    if (TMailing.GetPartnersBestLocationData(APartnerKey, out BestLocationPK,
                                                             out LocationDR, out PartnerLocationDR, AReadTransaction.DataBaseObj))
                    {
                        #region Process Address

                        /*
                         * Check for existance of PLocation and PPartnerLocation Tables in the passed in
                         * DataSet APartnerInfoDS.
                         */
                        if (!APartnerInfoDS.Tables.Contains(PLocationTable.GetTableName()))
                        {
                            // Need to create Table here
                            APartnerInfoDS.Tables.Add(new PLocationTable());
                        }

                        if (!APartnerInfoDS.Tables.Contains(PPartnerLocationTable.GetTableName()))
                        {
                            // Need to create Table here
                            APartnerInfoDS.Tables.Add(new PPartnerLocationTable());
                        }

                        // Add copies of the Location and PartnerLocation DataRows of the 'Best Address'

                        /*
                         * Remove DataColumns that might have been added by the call to
                         * TMailing.GetPartnersBestLocationData - otherwise PartnerLocationDR2.ItemArray
                         * assignment will fail.
                         */
                        if (PartnerLocationDR.Table.Columns.Contains(Calculations.PARTNERLOCATION_BESTADDR_COLUMN))
                        {
                            PartnerLocationDR.Table.Columns.Remove(Calculations.PARTNERLOCATION_BESTADDR_COLUMN);
                        }

                        if (PartnerLocationDR.Table.Columns.Contains(Calculations.PARTNERLOCATION_ICON_COLUMN))
                        {
                            PartnerLocationDR.Table.Columns.Remove(Calculations.PARTNERLOCATION_ICON_COLUMN);
                        }

                        LocationDR2                  = APartnerInfoDS.PLocation.NewRowTyped(false);
                        LocationDR2.ItemArray        = LocationDR.ItemArray;
                        PartnerLocationDR2           = APartnerInfoDS.PPartnerLocation.NewRowTyped(false);
                        PartnerLocationDR2.ItemArray = PartnerLocationDR.ItemArray;

                        APartnerInfoDS.PLocation.Rows.Add(LocationDR2);
                        APartnerInfoDS.PPartnerLocation.Rows.Add(PartnerLocationDR2);

                        #endregion

                        // Apply Address Security
                        LocationDT        = APartnerInfoDS.PLocation;
                        PartnerLocationDT = APartnerInfoDS.PPartnerLocation;

                        TPPartnerAddressAggregate.ApplySecurity(ref PartnerLocationDT,
                                                                ref LocationDT);

                        // Process 'Head' data and rest of data for the Partner
                        HeadInternal(PartnerDR, ref APartnerInfoDS);
                        RestInternal(PartnerDR, ref APartnerInfoDS, AReadTransaction);

                        ReturnValue = true;
                    }
                }
            }
            catch (ESecurityPartnerAccessDeniedException)
            {
                // don't log this exception - this is thrown on purpose here and the Client needs to deal with it.
                throw;
            }
            catch (Exception Exp)
            {
                TLogging.Log("TServerLookups_PartnerInfo.AllPartnerInfoData exception: " + Exp.ToString(), TLoggingType.ToLogfile);
                TLogging.Log(Exp.StackTrace, TLoggingType.ToLogfile);

                throw;
            }

            return(ReturnValue);
        }