/// <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); }
/// <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); }
/// <summary> /// Returns miscellaneous Partner data. /// </summary> /// <remarks>Used by the Partner Info UserControl.</remarks> /// <param name="APartnerKey">PartnerKey of the Partner for which the data /// should be retrieved.</param> /// <param name="ALocationKey">LocationKey of the Location for which data /// for the Partner specified should be retrieved.</param> /// <param name="APartnerInfoScope">Scope of data that should be loaded and /// returned by the PetraServer.</param> /// <param name="APartnerInfoDS">Typed DataSet that contains the requested Partner data.</param> /// <returns>True if the Partner exists, otherwise false.</returns> public static Boolean PartnerInfo(Int64 APartnerKey, TLocationPK ALocationKey, TPartnerInfoScopeEnum APartnerInfoScope, out PartnerInfoTDS APartnerInfoDS) { return(TRemote.MPartner.Partner.ServerLookups.WebConnectors.PartnerInfo(APartnerKey, ALocationKey, APartnerInfoScope, out APartnerInfoDS)); }
/// <summary> /// Determines which address is the 'Best Address' of a Partner. /// </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> /// <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) { TLocationPK BestLocation = new TLocationPK(); PPartnerLocationRow Tmp; BestLocation = DetermineBestAddress(APartnerKey, out Tmp); return(BestLocation); }
/// <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); }
/// <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> /// Checks whether the Partner has an Address with the specified PK. /// </summary> /// <remarks>Displays an error message to the user if it will return false!</remarks> /// <param name="ALocationPK">PK of a DataRow in the PLocation table.</param> /// <returns>True if the Address was found, otherwise false.</returns> public bool IsAddressRowPresent(TLocationPK ALocationPK) { if (FCurrentModuleTabGroup == TPartnerEditScreenLogic.TModuleTabGroupEnum.mtgPartner) { return(ucoPartnerTabSet.IsAddressRowPresent(ALocationPK)); } else { throw new EOPAppException("This Menu item must only be used when the Partner Data Tab Group is shown"); } }
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); }
/// <summary> /// Determines which address is the 'Best Address' of a Partner, and returns the PLocation record which the /// 'Best Address' is pointing to. /// </summary> /// <remarks>There are two similar shared Methods in Namespace Ict.Petra.Shared.MPartner.Calculations, /// both called 'DetermineBestAddress' which work by passing in the PartnerLocations of a Partner in an Argument /// and which return a <see cref="TLocationPK" />. As those Methods don't access the database, these Methods /// can be used client-side as well!</remarks> /// <param name="APartnerKey">PartnerKey of the Partner whose addresses should be checked.</param> /// <param name="ALocationDR">PLocation Record that the 'Best Address' is pointing to.</param> /// <returns>A <see cref="TLocationPK" /> which points to the 'Best Address'. If no 'Best Address' was found, /// SiteKey and LocationKey of this instance will be both -1.</returns> public static TLocationPK DetermineBestAddress(Int64 APartnerKey, out PLocationRow ALocationDR) { TLocationPK BestLocation = new TLocationPK(); PPartnerLocationRow Tmp; ALocationDR = null; BestLocation = DetermineBestAddress(APartnerKey, out Tmp, out ALocationDR); return(BestLocation); }
private static PartnerDetails GetRecipient(Int64 APartnerKey) { if (RecipientList.ContainsKey(APartnerKey)) { return(RecipientList[APartnerKey]); } PartnerDetails Ret = new PartnerDetails(); PPartnerTable PartnerTbl = PPartnerAccess.LoadByPrimaryKey(APartnerKey, FTransaction); if (PartnerTbl.Rows.Count > 0) { PPartnerRow PartnerRow = PartnerTbl[0]; Ret.LastName = PartnerRow.PartnerShortName; if (PartnerRow.PartnerClass == "PERSON") { PPersonTable PersonTbl = PPersonAccess.LoadByPrimaryKey(APartnerKey, FTransaction); if (PersonTbl.Rows.Count > 0) { PPersonRow PersonRow = PersonTbl[0]; Ret.FirstName = PersonRow.FirstName; Ret.LastName = PersonRow.FamilyName; Ret.Class = "PERSON"; } } if (PartnerRow.PartnerClass == "FAMILY") { PFamilyTable FamilyTbl = PFamilyAccess.LoadByPrimaryKey(APartnerKey, FTransaction); if (FamilyTbl.Rows.Count > 0) { PFamilyRow FamilyRow = FamilyTbl[0]; Ret.FirstName = FamilyRow.FirstName; Ret.LastName = FamilyRow.FamilyName; Ret.Class = "FAMILY"; } } PPartnerLocationRow LocationRow; TLocationPK LocationKey = ServerCalculations.DetermineBestAddress(APartnerKey, out LocationRow); if (LocationKey.LocationKey != -1) { Ret.Email = LocationRow.EmailAddress; } } RecipientList.Add(APartnerKey, Ret); return(Ret); }
/// create a new Person public static void NewPartner_Person(Form AParentForm) { TFrmPartnerEdit frm = new TFrmPartnerEdit(AParentForm); System.Int64 FamilyKey = GetLastUsedFamilyKey(); TLocationPK LocationSiteKey = TRemote.MPartner.Partner.WebConnectors.DetermineBestAddress(FamilyKey); frm.SetParameters(TScreenMode.smNew, "PERSON", -1, -1, "", "", false, FamilyKey, LocationSiteKey.LocationKey, LocationSiteKey.SiteKey); frm.Show(); }
/// <summary> /// Adds a Partner to an Extract, if they are not already present /// </summary> /// <param name="APartnerKey">PartnerKey of Partner</param> /// <param name="ALocationPK">Location PK of a Partner's PartnerLocation /// (usually the LocationPK of the 'Best Address' of the Partner).</param> /// <param name="AExtractId">ExtractId of the Extract that the Partner should /// get added to.</param> /// <returns>True if the Partner was added to the Extract, otherwise false.</returns> public static bool AddPartnerToExtract(Int64 APartnerKey, TLocationPK ALocationPK, int AExtractId) { TDBTransaction Transaction = null; bool SubmissionOK = false; MExtractTable TemplateTable; MExtractRow TemplateRow; MExtractRow NewRow; if (APartnerKey > 0) { DBAccess.GDBAccessObj.GetNewOrExistingAutoTransaction(IsolationLevel.Serializable, ref Transaction, ref SubmissionOK, delegate { /* * First check whether the Partner isn't already in that Extract */ TemplateTable = new MExtractTable(); TemplateRow = TemplateTable.NewRowTyped(false); TemplateRow.ExtractId = AExtractId; TemplateRow.PartnerKey = APartnerKey; if (MExtractAccess.CountUsingTemplate(TemplateRow, null, Transaction) == 0) { /* * Add Partner to Extract. */ NewRow = TemplateTable.NewRowTyped(false); NewRow.ExtractId = AExtractId; NewRow.PartnerKey = APartnerKey; NewRow.SiteKey = ALocationPK.SiteKey; NewRow.LocationKey = ALocationPK.LocationKey; TemplateTable.Rows.Add(NewRow); MExtractAccess.SubmitChanges(TemplateTable, Transaction); SubmissionOK = true; } else { // Partner is already in that Extract -> Partner does not get added. SubmissionOK = false; } }); } else { // Invalid PartnerKey -> return false; SubmissionOK = false; } return(SubmissionOK); }
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); }
/// <summary> /// Returns the Primary Key of the Location of the 'Best Address' of a Partner. /// </summary> /// <param name="APartnerKey">PartneKey of the Partner for which the 'Best Address' /// should be loaded for.</param> /// <returns>TLocationPK(-1,-1) 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 the Primary Key of the Location of the 'Best Address' of the Partner.</returns> public static TLocationPK GetPartnersBestLocation(Int64 APartnerKey) { TLocationPK ReturnValue = new TLocationPK(-1, -1); TLocationPK LocationPK; PLocationRow LocationDR; PPartnerLocationRow PartnerLocationDR; if (GetPartnersBestLocationData(APartnerKey, out LocationPK, out LocationDR, out PartnerLocationDR)) { ReturnValue = LocationPK; } return(ReturnValue); }
private void ShowFamilyPartnerSelection(Boolean AShow) { if (AShow) { if (!FFamilyPartnerSelectionSetup) { if (FFamilyPartnerKey != -1) { txtFamilyPartnerBox.Text = FFamilyPartnerKey.ToString(); } else { this.Cursor = Cursors.WaitCursor; try { FFamilyPartnerKey = GetLastUsedFamilyKey(); if (FFamilyPartnerKey != 0) { TLocationPK FamilysBestAddress = TRemote.MPartner.Partner.WebConnectors.DetermineBestAddress(FFamilyPartnerKey); FFamilyLocationKey = FamilysBestAddress.LocationKey; FFamilySiteKey = FamilysBestAddress.SiteKey; txtFamilyPartnerBox.Text = FFamilyPartnerKey.ToString(); } else { FFamilyPartnerKey = -1; } } finally { this.Cursor = Cursors.Default; } } FFamilyPartnerSelectionSetup = true; } } txtFamilyPartnerBox.Visible = AShow; }
/// <summary> /// Determines which address is the 'Best Address' of a Partner, and marks it in the DataColumn 'BestAddress'. /// </summary> /// <remarks>This method overload exists primarily for use in data migration from a legacy DB system. /// It gets called via .NET Reflection from Ict.Tools.DataDumpPetra2! /// DO NOT REMOVE THIS METHOD - although an IDE will not find any references to this Method!</remarks> /// <param name="APartnerLocationsDT">DataTable containing the addresses of a Partner.</param> /// <param name="ASiteKey">Site Key of the 'Best Address'.</param> /// <param name="ALocationKey">Location Key of the 'Best Address'.</param> /// <returns>True if a 'Best Address' was found, otherwise false. /// In the latter case ASiteKey and ALocationKey will be both -1, too.</returns> public static bool DetermineBestAddress(DataTable APartnerLocationsDT, out Int64 ASiteKey, out int ALocationKey) { TLocationPK PK = DetermineBestAddress(APartnerLocationsDT); if ((PK.SiteKey == -1) && (PK.LocationKey == -1)) { ASiteKey = -1; ALocationKey = -1; return(false); } else { ASiteKey = PK.SiteKey; ALocationKey = PK.LocationKey; return(true); } }
/// <summary> /// todoComment /// </summary> /// <returns></returns> public TLocationPK DetermineCurrentLocationPK() { DataRow CurrentDR = this.CurrentDataRow; TLocationPK LocationPK; if (CurrentDR != null) { // get LocationKey of current DataRow LocationPK = new TLocationPK(Convert.ToInt64(CurrentDR[PPartnerLocationTable.GetSiteKeyDBName()]), Convert.ToInt32(CurrentDR[PPartnerLocationTable.GetLocationKeyDBName()])); } else { LocationPK = new TLocationPK(-1, -1); } // MessageBox.Show('SiteKey: ' + LocationPK.SiteKey.ToString + "\r\n" + // 'LocationKey: ' + LocationPK.LocationKey.ToString); return(LocationPK); }
/// <summary> /// Returns the PLocationRow of the 'Best Address'. /// </summary> /// <remarks>The 'DetermineBestAddress' Method overload that returns a <see cref="TLocationPK" /> must /// have been run before and that return value must be passed into the present Method with the /// <paramref name="ABestLocationPK" /> Argument!!!</remarks> /// <param name="ABestLocationPK">Primary Key of the 'Best Location' (as determined by the /// 'DetermineBestAddress' Method overload that returns a <see cref="TLocationPK" />).</param> /// <param name="ALocationDT">Location Table that contains the Location record that is referenced with /// <paramref name="ABestLocationPK" />.</param> /// <returns>Location Row of the 'Best Address'.</returns> public static PLocationRow FindBestAddressLocation(TLocationPK ABestLocationPK, PLocationTable ALocationDT) { PLocationRow BestLocationDR; if ((ABestLocationPK.SiteKey == -1) && (ABestLocationPK.LocationKey == -1)) { throw new EOPAppException( "FindBestAddressLocation Method was unable to determine the 'Best Address' (PPartnerLocation error)! (Was 'DetermineBestAddress' run before?)"); } BestLocationDR = (PLocationRow)ALocationDT.Rows.Find( new object[] { ABestLocationPK.SiteKey, ABestLocationPK.LocationKey }); if (BestLocationDR == null) { throw new EOPAppException( "FindBestAddressLocation Method was unable to determine the 'Best Address' (PLocation error)! (Was 'DetermineBestAddress' run before?)"); } return(BestLocationDR); }
/// <summary> /// Determines which address is the 'Best Address' of a Partner, and returns the PLocation record which the /// 'Best Address' is pointing to. /// </summary> /// <remarks>There are two similar shared Methods in Namespace Ict.Petra.Server.MPartner.Common.Calculations, /// both called 'DetermineBestAddress' which work by passing in the PartnerLocations of a Partner in an Argument /// and which return a <see cref="TLocationPK" />. As those Methods don't access the database, these Methods /// can be used client-side as well!</remarks> /// <param name="APartnerKey">PartnerKey of the Partner whose addresses should be checked.</param> /// <param name="APartnerLocationDR">PPartnerLocation Record that is the record that is the Location of the 'Best Address'.</param> /// <param name="ALocationDR">PLocation Record that the 'Best Address' is pointing to.</param> /// <param name="ADataBase">An instantiated <see cref="TDataBase" /> object, or null (default = null). If null /// gets passed then the Method executes DB commands with a new Database connection</param> /// <returns>A <see cref="TLocationPK" /> which points to the 'Best Address'. If no 'Best Address' was found, /// SiteKey and LocationKey of this instance will be both -1.</returns> public static TLocationPK DetermineBestAddress(Int64 APartnerKey, out PPartnerLocationRow APartnerLocationDR, out PLocationRow ALocationDR, TDataBase ADataBase = null) { PLocationTable LocationDT; TLocationPK BestLocation = new TLocationPK(); Boolean NewTransaction; APartnerLocationDR = null; ALocationDR = null; BestLocation = DetermineBestAddress(APartnerKey, out APartnerLocationDR); TDataBase db = DBAccess.Connect("DetermineBestAddress", ADataBase); TDBTransaction ReadTransaction = db.GetNewOrExistingTransaction( MCommonConstants.CACHEABLEDT_ISOLATIONLEVEL, out NewTransaction); try { LocationDT = PLocationAccess.LoadByPrimaryKey(BestLocation.SiteKey, BestLocation.LocationKey, ReadTransaction); if (LocationDT.Rows.Count > 0) { ALocationDR = LocationDT[0]; } } finally { if (NewTransaction) { ReadTransaction.Commit(); TLogging.LogAtLevel(7, "ServerCalculations.DetermineBestAddress: commited own transaction."); } } return(BestLocation); }
/// <summary> /// Returns the PLocationRow of the 'Best Address'. /// </summary> /// <remarks>One of the 'DetermineBestAddress' Methods must have been run before on the PartnerLocation /// Table that gets passed in in the <paramref name="APartnerLocationDT" /> Argument!!!</remarks> /// <param name="APartnerLocationDT">Typed PartnerLocation Table that was already processed by one of the /// 'DetermineBestAddress' Methods.</param> /// <param name="ALocationDT">Location Table that contains all Location records that are referenced in /// <paramref name="APartnerLocationDT" />.</param> /// <returns>Location Row of the 'Best Address'.</returns> public static PLocationRow FindBestAddressLocation(PartnerEditTDSPPartnerLocationTable APartnerLocationDT, PLocationTable ALocationDT) { PartnerEditTDSPPartnerLocationRow CheckDR; string NameOfBestAddrColumn = PartnerEditTDSPPartnerLocationTable.GetBestAddressDBName(); var BestLocationPK = new TLocationPK(-1, -1); PLocationRow BestLocationDR; for (int Counter = 0; Counter < APartnerLocationDT.Count; Counter++) { CheckDR = APartnerLocationDT[Counter]; if (CheckDR[NameOfBestAddrColumn] == ((object)1)) { BestLocationPK = new TLocationPK(CheckDR.SiteKey, CheckDR.LocationKey); } } if ((BestLocationPK.SiteKey == -1) && (BestLocationPK.LocationKey == -1)) { throw new EOPAppException( "FindBestAddressLocation Method was unable to determine the 'Best Address' (PPartnerLocation error)! (Was 'DetermineBestAddress' run before?)"); } BestLocationDR = (PLocationRow)ALocationDT.Rows.Find( new object[] { BestLocationPK.SiteKey, BestLocationPK.LocationKey }); if (BestLocationDR == null) { throw new EOPAppException( "FindBestAddressLocation Method was unable to determine the 'Best Address' (PLocation error)! (Was 'DetermineBestAddress' run before?)"); } return(BestLocationDR); }
/// <summary> /// Causes the 'Partner Info' UserControl to update itself. /// </summary> /// <param name="ALocationDataAvailable">Set to true if Location data is available.</param> /// <param name="APartnerInfoUC">Instance of the PartnerInfo UserControl</param> /// <returns>True if an 'update' was done, false if the Partner Info Control already had current data and hence no /// update was done.</returns> public bool UpdatePartnerInfoPanel(bool ALocationDataAvailable, TUC_PartnerInfo APartnerInfoUC) { bool ReturnValue = false; TLocationPK CurrentLocationPK; CurrentLocationPK = DetermineCurrentLocationPK(); // MessageBox.Show("Current PartnerKey: " + PartnerKey.ToString() + Environment.NewLine + // "FLastPartnerKeyInfoPanelOpened: " + FLastPartnerKeyInfoPanelOpened.ToString() + Environment.NewLine + // "CurrentLocationPK: " + CurrentLocationPK.SiteKey.ToString() + ", " + CurrentLocationPK.LocationKey.ToString() + Environment.NewLine + // "FLastLocationPKInfoPanelOpened: " + FLastLocationPKInfoPanelOpened.SiteKey.ToString() + ", " + FLastLocationPKInfoPanelOpened.LocationKey.ToString()); if ((CurrentDataRow != null) && (((FLastPartnerKeyInfoPanelOpened == PartnerKey) && ((FLastLocationPKInfoPanelOpened.SiteKey != CurrentLocationPK.SiteKey) || (FLastLocationPKInfoPanelOpened.LocationKey != CurrentLocationPK.LocationKey))) || (FLastPartnerKeyInfoPanelOpened != PartnerKey))) { FLastPartnerKeyInfoPanelOpened = PartnerKey; FLastLocationPKInfoPanelOpened = CurrentLocationPK; if (ALocationDataAvailable) { // We have Location data available APartnerInfoUC.PassPartnerDataPartialWithLocation(PartnerKey, CurrentDataRow); } else { // We don't have Location data available APartnerInfoUC.PassPartnerDataPartialWithoutLocation(PartnerKey, CurrentDataRow); } ReturnValue = true; } return(ReturnValue); }
/// <summary> /// Determines which address is the 'Best Address' of a Partner, and returns the PLocation record which the /// 'Best Address' is pointing to. /// </summary> /// <remarks>There are two similar shared Methods in Namespace Ict.Petra.Shared.MPartner.Calculations, /// both called 'DetermineBestAddress' which work by passing in the PartnerLocations of a Partner in an Argument /// and which return a <see cref="TLocationPK" />. As those Methods don't access the database, these Methods /// can be used client-side as well!</remarks> /// <param name="APartnerKey">PartnerKey of the Partner whose addresses should be checked.</param> /// <param name="APartnerLocationDR">PPartnerLocation Record that is the record that is the Location of the 'Best Address'.</param> /// <param name="ALocationDR">PLocation Record that the 'Best Address' is pointing to.</param> /// <returns>A <see cref="TLocationPK" /> which points to the 'Best Address'. If no 'Best Address' was found, /// SiteKey and LocationKey of this instance will be both -1.</returns> public static TLocationPK DetermineBestAddress(Int64 APartnerKey, out PPartnerLocationRow APartnerLocationDR, out PLocationRow ALocationDR) { PLocationTable LocationDT; TLocationPK BestLocation = new TLocationPK(); Boolean NewTransaction; APartnerLocationDR = null; ALocationDR = null; BestLocation = DetermineBestAddress(APartnerKey, out APartnerLocationDR); TDBTransaction ReadTransaction = DBAccess.GDBAccessObj.GetNewOrExistingTransaction( Ict.Petra.Server.MCommon.MCommonConstants.CACHEABLEDT_ISOLATIONLEVEL, TEnforceIsolationLevel.eilMinimum, out NewTransaction); try { LocationDT = PLocationAccess.LoadByPrimaryKey(BestLocation.SiteKey, BestLocation.LocationKey, ReadTransaction); if (LocationDT.Rows.Count > 0) { ALocationDR = LocationDT[0]; } } finally { if (NewTransaction) { DBAccess.GDBAccessObj.CommitTransaction(); TLogging.LogAtLevel(7, "ServerCalculations.DetermineBestAddress: commited own transaction."); } } return(BestLocation); }
/// <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 PartnerInfo data 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="AReadTransaction" >Open DB Transaction.</param> /// <returns>True if Partner exists, otherwise false.</returns> public static bool LocationPartnerLocationOnly(Int64 APartnerKey, TLocationPK ALocationKey, ref PartnerInfoTDS APartnerInfoDS, TDBTransaction AReadTransaction) { return(LocationPartnerLocationInternal(APartnerKey, ALocationKey, ref APartnerInfoDS, false, AReadTransaction)); }
/// <summary> /// Resets the 'last partner' data that is held in the 'Partner Info' UserControl. /// </summary> public void ResetLastPartnerDataInfoPanel() { FLastPartnerKeyInfoPanelOpened = -1; FLastLocationPKInfoPanelOpened = new TLocationPK(-1, -1); }
/// <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); }
/// <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); } }
/// <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 PartnerInfo data 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> /// <returns>True if Partner exists, otherwise false.</returns> public static bool LocationPartnerLocationOnly(Int64 APartnerKey, TLocationPK ALocationKey, ref PartnerInfoTDS APartnerInfoDS) { return(LocationPartnerLocationInternal(APartnerKey, ALocationKey, ref APartnerInfoDS, false)); }
/// <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 PartnerInfo data 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> /// <returns>True if Partner exists, otherwise false.</returns> public static bool PartnerLocationAndRestOnly(Int64 APartnerKey, TLocationPK ALocationKey, ref PartnerInfoTDS APartnerInfoDS) { return(PartnerLocationInternal(APartnerKey, ALocationKey, ref APartnerInfoDS, true)); }
/// <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 PartnerLocation information and the rest of the PartnerInfo data, but not the /// 'Head' data. /// </summary> /// <param name="APartnerKey">PartnerKey of Partner to find the PartnerInfo data 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="AReadTransaction" >Open DB Transaction.</param> /// <returns>True if Partner exists, otherwise false.</returns> public static bool PartnerLocationAndRestOnly(Int64 APartnerKey, TLocationPK ALocationKey, ref PartnerInfoTDS APartnerInfoDS, TDBTransaction AReadTransaction) { return(PartnerLocationInternal(APartnerKey, ALocationKey, ref APartnerInfoDS, true, AReadTransaction)); }