/// <summary> /// Retrieves PartnerLocation information. /// </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="AReadTransaction">Open Database Transaction.</param> /// <param name="APartnerInfoDS">Typed DataSet that contains the requested data.</param> private static void PartnerLocationInternal(Int64 APartnerKey, TLocationPK ALocationKey, TDBTransaction AReadTransaction, ref PartnerInfoTDS APartnerInfoDS) { /* * Load PartnerLocation Information; this gets merged into the already retrieved * information in APartnerInfoDS (eg. 'Head' data) */ APartnerInfoDS.Merge(TPPartnerAddressAggregate.LoadByPrimaryKey( APartnerKey, ALocationKey.SiteKey, ALocationKey.LocationKey, AReadTransaction)); }
/// <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); }
/// <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); }
/// <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); }
/// <summary> /// Returns the Primary Key of the Location and the Location and PartnerLocation DataRows /// of the 'Best Address' of a Partner. /// </summary> /// <param name="APartnerKey">PartnerKey of the Partner for which the 'Best Address' /// should be loaded for.</param> /// <param name="ABestAddressPK">Primary Key of the 'Best Address' Location</param> /// <param name="ALocationDR">DataRow containing the 'Best Address' Location</param> /// <param name="APartnerLocationDR">DataRow containing the 'Best Address' PartnerLocation</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 or if Location/PartnerLocation Data could not be loaded for the /// Partner, otherwise true.</returns> public static bool GetPartnersBestLocationData(Int64 APartnerKey, out TLocationPK ABestAddressPK, out PLocationRow ALocationDR, out PPartnerLocationRow APartnerLocationDR, TDataBase ADataBase = null) { TDBTransaction ReadTransaction; Boolean NewTransaction; PPartnerLocationTable PartnerLocationDT; PLocationTable LocationDT; ALocationDR = null; APartnerLocationDR = null; ABestAddressPK = null; if (APartnerKey > 0) { ReadTransaction = DBAccess.GetDBAccessObj(ADataBase).GetNewOrExistingTransaction( IsolationLevel.ReadCommitted, TEnforceIsolationLevel.eilMinimum, out NewTransaction); try { if (TMailing.GetPartnerLocations(APartnerKey, false, true, true, true, out PartnerLocationDT, ADataBase)) { TLogging.LogAtLevel(8, "TMailing.GetPartnersBestLocationData: processing " + PartnerLocationDT.Rows.Count.ToString() + " Locations..."); if (PartnerLocationDT.Rows.Count > 1) { Calculations.DeterminePartnerLocationsDateStatus(PartnerLocationDT, DateTime.Today); ABestAddressPK = Calculations.DetermineBestAddress(PartnerLocationDT); } else if (PartnerLocationDT.Rows.Count == 1) { ABestAddressPK = new TLocationPK(PartnerLocationDT[0].SiteKey, PartnerLocationDT[0].LocationKey); } else { return(false); } // TLogging.LogAtLevel(8, "TMailing.GetPartnersBestLocationData: BestAddressPK: " + ABestAddressPK.SiteKey.ToString() + ", " + ABestAddressPK.LocationKey.ToString()); APartnerLocationDR = (PPartnerLocationRow)PartnerLocationDT.Rows.Find( new object[] { APartnerKey, ABestAddressPK.SiteKey, ABestAddressPK.LocationKey }); LocationDT = TPPartnerAddressAggregate.LoadByPrimaryKey( ABestAddressPK.SiteKey, ABestAddressPK.LocationKey, ReadTransaction); if (LocationDT != null) { ALocationDR = LocationDT[0]; } else { return(false); } return(true); } else { return(false); } } finally { if (NewTransaction) { DBAccess.GDBAccessObj.CommitTransaction(); TLogging.LogAtLevel(8, "TMailing.GetPartnersBestLocationData: committed own transaction."); } } } else { return(false); } }