/// <summary> /// Main Method for updating the data that is displayed in the UserControl. /// </summary> /// <param name="APartnerKey">Partner Key of Partner for which Partner Info data should be retrieved.</param> /// <param name="APartnerDR">DataRow containing Partner data, Location Data, Partner Location Data and 'Rest' data.</param> /// <param name="ALocationPK">Location PrimaryKey of the Location for which Address data should be retrieved. /// If it is null, it is constructed from data in APartnerDR!</param> /// <param name="AScope">Scope of data that is already available client-side.</param> private void UpdateControls(Int64 APartnerKey, DataRow APartnerDR, TLocationPK ALocationPK, TPartnerInfoAvailDataEnum AScope) { TLocationPK LocationPK; bool LoadRestOfData; // TLogging.Log("Received UpdateControls request for Partner " + APartnerKey.ToString() + "."); FPartnerKey = APartnerKey; FPartnerDR = APartnerDR; if (ALocationPK != null) { LocationPK = ALocationPK; } else { LocationPK = new TLocationPK(-1, -1); } if (FPartnerDR != null) { FPartnerClass = SharedTypes.PartnerClassStringToEnum( FPartnerDR[PPartnerTable.GetPartnerClassDBName()].ToString()); FPartnerShortName = APartnerDR[PPartnerTable.GetPartnerShortNameDBName()].ToString(); if (LocationPK.LocationKey == -1) { LocationPK = new TLocationPK( Convert.ToInt64(APartnerDR[PLocationTable.GetSiteKeyDBName()]), Convert.ToInt32(APartnerDR[PLocationTable.GetLocationKeyDBName()])); } } LoadRestOfData = FPartnerKey != FLastPartnerKey; ClearControls(!LoadRestOfData); lblNoPartner.Visible = false; pnlKeyInfo.Visible = true; /* * Update Controls with the Data from the passed in DataRow APartnerDR * and with data from the DB, if necessary. */ switch (AScope) { case TPartnerInfoAvailDataEnum.piadHeadOnly: { ShowHideLoadingInfo(true, true, LoadRestOfData); FHeadDataServerRetrieved = false; UpdateControlsHeadData(); if (LoadRestOfData) { lock (FServerCallParamsLock) { FServerCallParams = new TServerCallParams(APartnerKey, LocationPK, AScope, LoadRestOfData, TPartnerInfoScopeEnum.pisLocationPartnerLocationAndRestOnly); } if (!FFetchingData) { // Request Partner Info data from the PetraServer FTimer.Change(0, System.Threading.Timeout.Infinite); } } else { lock (FServerCallParamsLock) { FServerCallParams = new TServerCallParams(APartnerKey, LocationPK, AScope, LoadRestOfData, TPartnerInfoScopeEnum.pisLocationPartnerLocationOnly); } if (!FFetchingData) { // Request Partner Info data from the PetraServer FTimer.Change(0, System.Threading.Timeout.Infinite); } } break; } case TPartnerInfoAvailDataEnum.piadHeadAndLocationOnly: { ShowHideLoadingInfo(true, false, LoadRestOfData); FHeadDataServerRetrieved = false; UpdateControlsHeadData(); FLocationDataServerRetrieved = false; UpdateControlsLocationData(); if (LoadRestOfData) { lock (FServerCallParamsLock) { FServerCallParams = new TServerCallParams(APartnerKey, LocationPK, AScope, LoadRestOfData, TPartnerInfoScopeEnum.pisPartnerLocationAndRestOnly); } if (!FFetchingData) { // Request Partner Info data from the PetraServer FTimer.Change(0, System.Threading.Timeout.Infinite); } } else { lock (FServerCallParamsLock) { FServerCallParams = new TServerCallParams(APartnerKey, LocationPK, AScope, LoadRestOfData, TPartnerInfoScopeEnum.pisPartnerLocationOnly); } if (!FFetchingData) { // Request Partner Info data from the PetraServer FTimer.Change(0, System.Threading.Timeout.Infinite); } } break; } case TPartnerInfoAvailDataEnum.piadNone: { ShowHideLoadingInfoFullSize(true); lock (FServerCallParamsLock) { FServerCallParams = new TServerCallParams(APartnerKey, LocationPK, AScope, LoadRestOfData, TPartnerInfoScopeEnum.pisFull); } if (!FFetchingData) { // Request Partner Info data from the PetraServer FTimer.Change(0, System.Threading.Timeout.Infinite); } break; } case TPartnerInfoAvailDataEnum.piadFull: { ShowHideLoadingInfo(true, true, LoadRestOfData); FHeadDataServerRetrieved = false; UpdateControlsHeadData(); FLocationDataServerRetrieved = false; UpdateControlsLocationData(); UpdateControlsRestData(); ShowHideLoadingInfo(false, true, LoadRestOfData); break; } } FLastPartnerKey = FPartnerKey; }
/// <summary> /// Fetches Partner Info data from the Petra Server. /// </summary> /// <param name="ADummy">A dummy object (needed because called from the Timer). Pass in null.</param> private void FetchDataFromServer(object ADummy) { TimeSpan Duration; PartnerInfoTDS PartlyPopulatedPartnerInfoDS = null; bool ServerCallSuccessful = false; if (FTimer == null) // prevent execution of this Method if Timer is already disposed! { return; } if (FLastDataFeched != DateTime.MinValue) { Duration = DateTime.Now.Subtract(FLastDataFeched); } else { Duration = new TimeSpan(0, 0, 0, 0, MINIMUM_SERVERCALL_GAP); } // Decide whether to make the call to the PetraServer, or whether to delay it. if (Duration.TotalMilliseconds < MINIMUM_SERVERCALL_GAP) { // TLogging.Log("MINIMUM_SERVERCALL_GAP NOT reached, sleeping " + // (MINIMUM_SERVERCALL_GAP - Duration.TotalMilliseconds).ToString() + "ms ..."); FTimer.Change(Convert.ToInt32(MINIMUM_SERVERCALL_GAP - Duration.TotalMilliseconds), System.Threading.Timeout.Infinite); } else { // we are now in the process of fetching data from the PetraServer! FFetchingData = true; FLastDataFeched = DateTime.Now; // We need to work with an exact copy of FServerCallParams because FServerCallParams // can be overwritten anytime! FCurrentServerCallParams = FServerCallParams.GetDeepCopy(); // TLogging.Log("MINIMUM_SERVERCALL_GAP reached, making Server call for Partner " + // FCurrentServerCallParams.PartnerKey.ToString() + ". FCurrentServerCallParams.PartnerInfoScope: " + // FCurrentServerCallParams.PartnerInfoScope.ToString("G") + "..."); FServerCallError = String.Empty; FCurrentServerCallParams.ServerCallOK = false; // Reset Dictionary HyperlinkWithValueArguments = new Dictionary <string, Tuple <TPartnerAttributeTypeValueKind, string>>(1); try { Ict.Common.DB.TServerBusyHelper.CoordinatedAutoRetryCall("Partner Info", ref ServerCallSuccessful, delegate { /* * Actual PetraServer calls! */ if ((FCurrentServerCallParams.PartnerInfoScope == TPartnerInfoScopeEnum.pisPartnerLocationAndRestOnly) || (FCurrentServerCallParams.PartnerInfoScope == TPartnerInfoScopeEnum.pisLocationPartnerLocationAndRestOnly)) { FCurrentServerCallParams.ServerCallOK = TServerLookup.TMPartner.PartnerInfo(FCurrentServerCallParams.PartnerKey, FCurrentServerCallParams.LocationKey, FCurrentServerCallParams.PartnerInfoScope, out FPartnerInfoDS); ServerCallSuccessful = true; FPartnerInfoDS.Merge(FPartnerAttributeCategoryDT); FPartnerInfoDS.Merge(FPartnerAttributeTypeDT); } else if (FCurrentServerCallParams.PartnerInfoScope == TPartnerInfoScopeEnum.pisFull) { FCurrentServerCallParams.ServerCallOK = TServerLookup.TMPartner.PartnerInfo(FCurrentServerCallParams.PartnerKey, FCurrentServerCallParams.PartnerInfoScope, out FPartnerInfoDS); ServerCallSuccessful = true; FPartnerInfoDS.Merge(FPartnerAttributeCategoryDT); FPartnerInfoDS.Merge(FPartnerAttributeTypeDT); FPartnerClass = SharedTypes.PartnerClassStringToEnum(FPartnerInfoDS.PartnerHeadInfo[0].PartnerClass); FPartnerShortName = FPartnerInfoDS.PartnerHeadInfo[0].PartnerShortName; } else { FCurrentServerCallParams.ServerCallOK = TServerLookup.TMPartner.PartnerInfo(FCurrentServerCallParams.PartnerKey, FCurrentServerCallParams.LocationKey, FCurrentServerCallParams.PartnerInfoScope, out PartlyPopulatedPartnerInfoDS); ServerCallSuccessful = true; } }); } catch (ESecurityPartnerAccessDeniedException Exp) { FServerCallError = TMessages.MsgSecurityExceptionString(Exp); } catch (Exception Exc) { FServerCallError = "An error occured while trying to retrieve data for the Partner."; TLogging.Log("Partner Info: An error occured while trying to retrieve data for the Partner! Details:\r\n" + Exc.ToString()); } if (!ServerCallSuccessful) { // ServerCallRetries must be equal to MAX_RETRIES when we get here! FServerCallError = String.Format(StrPartnerInfoCannotBeShownDueToTooBusyServerText, Catalog.GetString(" in the Find Result"), Catalog.GetString(" in the Find Result"), Catalog.GetString("re-run the search operation by pressing 'Search'")); } //MessageBox.Show("FCurrentServerCallParams.ServerCallOK: " + FCurrentServerCallParams.ServerCallOK.ToString()); if (FServerCallError == String.Empty) { /* * Find out if the User requested a different Partner/LocationKey combination * in the meantime. If so, don't update the UI with the currently retrieved data, * but retrive the data for the new Partner/LocationKey combination and update the * UI with that! */ if (FCurrentServerCallParams.IsIdentical(FServerCallParams)) { if ((FCurrentServerCallParams.PartnerInfoScope == TPartnerInfoScopeEnum.pisPartnerLocationOnly) || (FCurrentServerCallParams.PartnerInfoScope == TPartnerInfoScopeEnum.pisLocationPartnerLocationOnly)) { FPartnerInfoDS.PLocation.Rows.Clear(); FPartnerInfoDS.PPartnerLocation.Rows.Clear(); FPartnerInfoDS.Merge(PartlyPopulatedPartnerInfoDS); FPartnerInfoDS.Merge(FPartnerAttributeCategoryDT); FPartnerInfoDS.Merge(FPartnerAttributeTypeDT); } /* * Update the User Interface with the data that was retrieved from the PetraServer! */ UpdateUI(); // we don't fetch data from the PetraServer anymore. FFetchingData = false; } else { // TLogging.Log("Newer FServerCallParams available; making new Server call!"); FetchDataFromServer(null); } } else { /* * An Exception occured while making the call to the PetraServer -> * inform user about that! */ UpdateUI(); // we don't fetch data from the PetraServer anymore. FFetchingData = false; } } }