Пример #1
0
        /// <summary>
        /// Retrieves PartnerLocation information and the rest of the PartnerInfo data, but not the
        /// 'Head' data.
        /// </summary>
        /// <param name="APartnerKey">PartnerKey of Partner to find the short name for</param>
        /// <param name="ALocationKey" >Location Key of the Location that the information should be
        /// retrieved for.</param>
        /// <param name="APartnerInfoDS">Typed DataSet that contains the requested data.</param>
        /// <param name="AIncludeRest">Include 'Rest' data as well</param>
        /// <param name="AReadTransaction" >Open DB Transaction.</param>
        private static bool PartnerLocationInternal(Int64 APartnerKey, TLocationPK ALocationKey,
                                                    ref PartnerInfoTDS APartnerInfoDS,
                                                    bool AIncludeRest, TDBTransaction AReadTransaction)
        {
            bool        ReturnValue = false;
            PPartnerRow PartnerDR;

            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);

                    /*
                     * Partner exists --> we can go ahead with data gathering
                     */
                    PartnerLocationInternal(APartnerKey, ALocationKey, AReadTransaction, ref APartnerInfoDS);

                    if (AIncludeRest)
                    {
                        RestInternal(PartnerDR, ref APartnerInfoDS, AReadTransaction);
                    }

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

                throw;
            }

            return(ReturnValue);
        }
Пример #2
0
        /// <summary>
        /// Retrieves Location and PartnerLocation information and the rest of the PartnerInfo data,
        /// but not the 'Head' data.
        /// </summary>
        /// <param name="APartnerKey">PartnerKey of Partner to find the short name for</param>
        /// <param name="ALocationKey">Location Key of the Location that the information should be
        /// retrieved for.</param>
        /// <param name="APartnerInfoDS">Typed DataSet that contains the requested data.</param>
        /// <param name="AIncludeRest">Include 'Rest' data as well</param>
        /// <param name="AReadTransaction" >Open DB Transaction.</param>
        private static bool LocationPartnerLocationInternal(Int64 APartnerKey, TLocationPK ALocationKey,
                                                            ref PartnerInfoTDS APartnerInfoDS,
                                                            bool AIncludeRest, TDBTransaction AReadTransaction)
        {
            bool                  ReturnValue = false;
            PPartnerRow           PartnerDR;
            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);

                    /*
                     * Load Partner Location data and rest of data first
                     */
                    PartnerLocationInternal(APartnerKey, ALocationKey, AReadTransaction, ref APartnerInfoDS);

                    /*
                     * Load Location Information; this gets merged into the already retrieved
                     * information in APartnerInfoDS (eg. Partner Location data and rest of data)
                     */
                    APartnerInfoDS.Merge(TPPartnerAddressAggregate.LoadByPrimaryKey(
                                             ALocationKey.SiteKey, ALocationKey.LocationKey, AReadTransaction));

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

                    TPPartnerAddressAggregate.ApplySecurity(ref PartnerLocationDT,
                                                            ref LocationDT);

                    if (AIncludeRest)
                    {
                        RestInternal(PartnerDR, ref APartnerInfoDS, AReadTransaction);
                    }

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

                throw;
            }

            return(ReturnValue);
        }
Пример #3
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);
        }
Пример #4
0
        /// <summary>
        /// Retrieves PartnerLocation information and the rest of the PartnerInfo data, but not the
        /// 'Head' data.
        /// </summary>
        /// <param name="APartnerKey">PartnerKey of Partner to find the short name for</param>
        /// <param name="ALocationKey" >Location Key of the Location that the information should be
        /// retrieved for.</param>
        /// <param name="APartnerInfoDS">Typed DataSet that contains the requested data.</param>
        /// <param name="AIncludeRest">Include 'Rest' data as well</param>
        private static bool PartnerLocationInternal(Int64 APartnerKey, TLocationPK ALocationKey,
                                                    ref PartnerInfoTDS APartnerInfoDS,
                                                    bool AIncludeRest)
        {
            bool           ReturnValue = false;
            TDBTransaction ReadTransaction;
            Boolean        NewTransaction = false;
            PPartnerRow    PartnerDR;

            ReadTransaction = DBAccess.GDBAccessObj.GetNewOrExistingTransaction(IsolationLevel.RepeatableRead,
                                                                                TEnforceIsolationLevel.eilMinimum,
                                                                                out NewTransaction);

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

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

                    /*
                     * Partner exists --> we can go ahead with data gathering
                     */
                    PartnerLocationInternal(APartnerKey, ALocationKey, ReadTransaction, ref APartnerInfoDS);

                    if (AIncludeRest)
                    {
                        RestInternal(PartnerDR, ReadTransaction, ref APartnerInfoDS);
                    }

                    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.PartnerLocationInternal exception: " + Exp.ToString(), TLoggingType.ToLogfile);
                TLogging.Log(Exp.StackTrace, TLoggingType.ToLogfile);
                throw;
            }
            finally
            {
                if (NewTransaction)
                {
                    DBAccess.GDBAccessObj.CommitTransaction();
                    TLogging.LogAtLevel(7, "TServerLookups_PartnerInfo.LocationPartnerLocationAndRestOnly: committed own transaction.");
                }
            }

            return(ReturnValue);
        }
Пример #5
0
        /// <summary>
        /// Retrieves Location and PartnerLocation information and the rest of the PartnerInfo data,
        /// but not the 'Head' data.
        /// </summary>
        /// <param name="APartnerKey">PartnerKey of Partner to find the short name for</param>
        /// <param name="ALocationKey">Location Key of the Location that the information should be
        /// retrieved for.</param>
        /// <param name="APartnerInfoDS">Typed DataSet that contains the requested data.</param>
        /// <param name="AIncludeRest">Include 'Rest' data as well</param>
        private static bool LocationPartnerLocationInternal(Int64 APartnerKey, TLocationPK ALocationKey,
                                                            ref PartnerInfoTDS APartnerInfoDS,
                                                            bool AIncludeRest)
        {
            bool                  ReturnValue = false;
            TDBTransaction        ReadTransaction;
            Boolean               NewTransaction = false;
            PPartnerRow           PartnerDR;
            PLocationTable        LocationDT;
            PPartnerLocationTable PartnerLocationDT;


            ReadTransaction = DBAccess.GDBAccessObj.GetNewOrExistingTransaction(IsolationLevel.RepeatableRead,
                                                                                TEnforceIsolationLevel.eilMinimum,
                                                                                out NewTransaction);

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

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

                    /*
                     * Load Partner Location data and rest of data first
                     */
                    PartnerLocationInternal(APartnerKey, ALocationKey, ReadTransaction, ref APartnerInfoDS);

                    /*
                     * Load Location Information; this gets merged into the already retrieved
                     * information in APartnerInfoDS (eg. Partner Location data and rest of data)
                     */
                    APartnerInfoDS.Merge(TPPartnerAddressAggregate.LoadByPrimaryKey(
                                             ALocationKey.SiteKey, ALocationKey.LocationKey, ReadTransaction));

                    // Apply Address Security
                    LocationDT        = APartnerInfoDS.PLocation;
                    PartnerLocationDT = APartnerInfoDS.PPartnerLocation;
                    TPPartnerAddressAggregate.ApplySecurity(ref PartnerLocationDT,
                                                            ref LocationDT);

                    if (AIncludeRest)
                    {
                        RestInternal(PartnerDR, ReadTransaction, ref APartnerInfoDS);
                    }

                    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.PartnerLocationInternal exception: " + Exp.ToString(), TLoggingType.ToLogfile);
                TLogging.Log(Exp.StackTrace, TLoggingType.ToLogfile);
                throw;
            }
            finally
            {
                if (NewTransaction)
                {
                    DBAccess.GDBAccessObj.CommitTransaction();
                    TLogging.LogAtLevel(7, "TServerLookups_PartnerInfo.LocationPartnerLocationAndRestOnly: committed own transaction.");
                }
            }

            return(ReturnValue);
        }
Пример #6
0
        /// <summary>
        /// Creates a list of locations for a given Partner.
        /// </summary>
        /// <remarks>Corresponds in parts with with Progress 4GL Method
        /// 'GetPartnerLocations' in partner/maillib.p.</remarks>
        /// <param name="APartnerKey">PartnerKey of the Partner being processed.</param>
        /// <param name="AMailingAddressesOnly">If true: only include addresses with mailing flag set.</param>
        /// <param name="AIncludeCurrentAddresses">If true: include current addresses.</param>
        /// <param name="AIncludeFutureAddresses">If true: include future addresses.</param>
        /// <param name="AIncludeExpiredAddresses">If true: include expired addresses.</param>
        /// <param name="APartnerLocations">The Locations of the Partner being processed.</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 the 'globally available'
        /// <see cref="DBAccess.GDBAccessObj" /> instance, otherwise with the instance that gets passed in with this
        /// Argument!</param>
        /// <returns>False if an invalid PartnerKey was passed in or if Petra Security
        /// denied access to the Partner, otherwise true.</returns>
        public static bool GetPartnerLocations(Int64 APartnerKey,
                                               bool AMailingAddressesOnly,
                                               bool AIncludeCurrentAddresses,
                                               bool AIncludeFutureAddresses,
                                               bool AIncludeExpiredAddresses,
                                               out PPartnerLocationTable APartnerLocations,
                                               TDataBase ADataBase = null)
        {
            TDBTransaction ReadTransaction;
            Boolean        NewTransaction;

            String  SelectSQL;
            DataSet FillDataSet;

            OdbcParameter param;

            // Initialise out Argument
            APartnerLocations = null;

            if (APartnerKey > 0)
            {
                TLogging.LogAtLevel(8, "TMailing.GetPartnerLocations: Checking access to Partner.");

                if (TSecurity.CanAccessPartnerByKey(APartnerKey, false, ADataBase) ==
                    TPartnerAccessLevelEnum.palGranted)
                {
                    ReadTransaction = DBAccess.GetDBAccessObj(ADataBase).GetNewOrExistingTransaction(
                        IsolationLevel.ReadCommitted,
                        TEnforceIsolationLevel.eilMinimum,
                        out NewTransaction);

                    // Load Partner Locations, taking passed in restrictions into account.
                    try
                    {
                        SelectSQL =
                            "SELECT *" +
                            "  FROM PUB_" + PPartnerLocationTable.GetTableDBName() +
                            " WHERE " + PPartnerLocationTable.GetPartnerKeyDBName() + " = ?" +
                            "   AND (NOT ? = true OR (? = true AND " + PPartnerLocationTable.GetSendMailDBName() + " = true))" +
                            "   AND ((? = true AND ((" + PPartnerLocationTable.GetDateEffectiveDBName() + " <= ?" +
                            "          OR " + PPartnerLocationTable.GetDateEffectiveDBName() + " IS NULL)" +
                            "     AND (" + PPartnerLocationTable.GetDateGoodUntilDBName() + " >= ?" +
                            "          OR " + PPartnerLocationTable.GetDateGoodUntilDBName() + " IS NULL)))" +
                            "     OR (? = true AND " + PPartnerLocationTable.GetDateEffectiveDBName() + " > ?)" +
                            "     OR (? = true AND " + PPartnerLocationTable.GetDateGoodUntilDBName() + " < ?))";

                        List <OdbcParameter> parameters = new List <OdbcParameter>();
                        param       = new OdbcParameter("PartnerKey", OdbcType.Decimal, 10);
                        param.Value = APartnerKey;
                        parameters.Add(param);
                        param       = new OdbcParameter("MailingAddressOnly1", OdbcType.Bit);
                        param.Value = AMailingAddressesOnly;
                        parameters.Add(param);
                        param       = new OdbcParameter("MailingAddressOnly2", OdbcType.Bit);
                        param.Value = AMailingAddressesOnly;
                        parameters.Add(param);
                        param       = new OdbcParameter("IncludeCurrentAddresses", OdbcType.Bit);
                        param.Value = AIncludeCurrentAddresses;
                        parameters.Add(param);
                        param       = new OdbcParameter("TodaysDate1", OdbcType.Date);
                        param.Value = DateTime.Now;
                        parameters.Add(param);
                        param       = new OdbcParameter("TodaysDate2", OdbcType.Date);
                        param.Value = DateTime.Now;
                        parameters.Add(param);
                        param       = new OdbcParameter("IncludeFutureAddresses", OdbcType.Bit);
                        param.Value = AIncludeFutureAddresses;
                        parameters.Add(param);
                        param       = new OdbcParameter("TodaysDate3", OdbcType.Date);
                        param.Value = DateTime.Now;
                        parameters.Add(param);
                        param       = new OdbcParameter("IncludeExpiredAddresses", OdbcType.Bit);
                        param.Value = AIncludeExpiredAddresses;
                        parameters.Add(param);
                        param       = new OdbcParameter("TodaysDate4", OdbcType.Date);
                        param.Value = DateTime.Now;
                        parameters.Add(param);

                        /*
                         * Our out Argument 'APartnerLocations' is a Typed DataTable, but SelectDT
                         * returns an untyped DataTable, therefore we need to create a Typed DataTable
                         * that contains the data of the returned untyped DataTable!
                         */
                        FillDataSet       = new DataSet();
                        APartnerLocations = new PPartnerLocationTable(PPartnerLocationTable.GetTableDBName());
                        FillDataSet.Tables.Add(APartnerLocations);

                        DBAccess.GetDBAccessObj(ADataBase).Select(FillDataSet, SelectSQL,
                                                                  PPartnerLocationTable.GetTableDBName(),
                                                                  ReadTransaction,
                                                                  parameters.ToArray());
//                      TLogging.LogAtLevel(7, "TMailing.GetPartnerLocations:  FillDataSet.Tables.Count: " + FillDataSet.Tables.Count.ToString());
                        FillDataSet.Tables.Remove(APartnerLocations);

                        if (APartnerLocations.Rows.Count > 0)
                        {
//                          TLogging.LogAtLevel(7, "TMailing.GetPartnerLocations: Found " + APartnerLocations.Rows.Count.ToString() + " PartnerLocations found for Partner " + APartnerKey.ToString() + ".");
                        }
                        else
                        {
                            /*
                             * /* No Rows returned = no PartnerLocations for Partner.
                             * That shouldn't happen with existing Partners, but if it does (eg. non-existing
                             * PartnerKey passed in) we return an empty Typed DataTable.
                             */
//                          TLogging.LogAtLevel(7, "TMailing.GetPartnerLocations: No PartnerLocations found for Partner " + APartnerKey.ToString() + "!");
                            APartnerLocations = new PPartnerLocationTable();
                        }
                    }
                    finally
                    {
                        if (NewTransaction)
                        {
                            DBAccess.GetDBAccessObj(ADataBase).CommitTransaction();
                            TLogging.LogAtLevel(7, "TMailing.GetPartnerLocations: committed own transaction.");
                        }
                    }

                    return(true);
                }
                else
                {
                    TLogging.LogAtLevel(8, "TMailing.GetPartnerLocations: Access to Partner DENIED!");

                    // Petra Security prevents us from accessing this Partner -> return false;
                    return(false);
                }
            }
            else
            {
                // Invalid PartnerKey -> return false;
                return(false);
            }
        }