/// <summary> /// load the gifts into the grid /// </summary> /// <param name="ALedgerNumber"></param> /// <param name="ABatchNumber"></param> /// <param name="ABatchStatus"></param> /// <param name="AForceLoadFromServer">Set to true to get data from the server even though it is apparently the current batch number and status</param> /// <returns>True if gift transactions were loaded from server, false if transactions had been loaded already.</returns> public bool LoadGifts(Int32 ALedgerNumber, Int32 ABatchNumber, string ABatchStatus, bool AForceLoadFromServer = false) { //Set key flags bool FirstGiftTransLoad = (FLedgerNumber == -1); bool SameCurrentBatch = ((FLedgerNumber == ALedgerNumber) && (FBatchNumber == ABatchNumber) && (FBatchStatus == ABatchStatus) && !AForceLoadFromServer); FBatchRow = GetBatchRow(); if ((FBatchRow == null) && (GetAnyBatchRow(ABatchNumber) == null)) { MessageBox.Show(String.Format("Cannot load transactions for Gift Batch {0} as the batch is not currently loaded!", ABatchNumber)); return(false); } //Set key values from Batch FLedgerNumber = ALedgerNumber; FBatchNumber = ABatchNumber; FBatchCurrencyCode = FBatchRow.CurrencyCode; FBatchMethodOfPayment = FBatchRow.MethodOfPaymentCode; FBatchStatus = ABatchStatus; FBatchUnpostedFlag = (FBatchStatus == MFinanceConstants.BATCH_UNPOSTED); if (FirstGiftTransLoad) { InitialiseControls(); } UpdateCurrencySymbols(FBatchCurrencyCode); //Check if the same batch is selected, so no need to apply filter if (SameCurrentBatch) { //Same as previously selected and we have not been asked to force a full refresh if (FBatchUnpostedFlag && (GetSelectedRowIndex() > 0)) { if (FGLEffectivePeriodHasChangedFlag) { //Just in case for the currently selected row, the date field has not been updated FGLEffectivePeriodHasChangedFlag = false; GetSelectedDetailRow().DateEntered = FBatchRow.GlEffectiveDate; dtpDateEntered.Date = FBatchRow.GlEffectiveDate; } GetDetailsFromControls(GetSelectedDetailRow()); } UpdateControlsProtection(); if (FBatchUnpostedFlag && ((FBatchCurrencyCode != FBatchRow.CurrencyCode) || (FBatchExchangeRateToBase != FBatchRow.ExchangeRateToBase))) { UpdateBaseAmount(false); } return(false); } //New Batch FCurrentGiftInBatch = 0; //New set of transactions to be loaded TFrmStatusDialog dlgStatus = new TFrmStatusDialog(FPetraUtilsObject.GetForm()); if (FShowStatusDialogOnLoadFlag == true) { dlgStatus.Show(); FShowStatusDialogOnLoadFlag = false; dlgStatus.Heading = String.Format(Catalog.GetString("Batch {0}"), ABatchNumber); dlgStatus.CurrentStatus = Catalog.GetString("Loading transactions ..."); } FGiftTransactionsLoadedFlag = false; FSuppressListChangedFlag = false; //Apply new filter FPreviouslySelectedDetailRow = null; grdDetails.DataSource = null; // if this form is readonly, then we need all codes, because old (inactive) codes might have been used if (FirstGiftTransLoad || (FActiveOnlyFlag == (ViewMode || !FBatchUnpostedFlag))) { FActiveOnlyFlag = !(ViewMode || !FBatchUnpostedFlag); dlgStatus.CurrentStatus = Catalog.GetString("Initialising controls ..."); try { //Without this, the Save button enables even for Posted batches! FPetraUtilsObject.SuppressChangeDetection = true; TFinanceControls.InitialiseMotivationGroupList(ref cmbDetailMotivationGroupCode, FLedgerNumber, FActiveOnlyFlag); TFinanceControls.InitialiseMotivationDetailList(ref cmbMotivationDetailCode, FLedgerNumber, FActiveOnlyFlag); TFinanceControls.InitialiseMethodOfGivingCodeList(ref cmbDetailMethodOfGivingCode, FActiveOnlyFlag); TFinanceControls.InitialiseMethodOfPaymentCodeList(ref cmbDetailMethodOfPaymentCode, FActiveOnlyFlag); TFinanceControls.InitialisePMailingList(ref cmbDetailMailingCode, FActiveOnlyFlag); } finally { FPetraUtilsObject.SuppressChangeDetection = false; } } // This sets the incomplete filter but does check the panel enabled state ShowData(); // This sets the main part of the filter but excluding the additional items set by the user GUI // It gets the right sort order SetGiftDetailDefaultView(); // only load from server if there are no transactions loaded yet for this batch // otherwise we would overwrite transactions that have already been modified if (FMainDS.AGiftDetail.DefaultView.Count == 0) { dlgStatus.CurrentStatus = Catalog.GetString("Requesting transactions from server ..."); //Load all partners in Batch FMainDS.DonorPartners.Merge(TRemote.MFinance.Gift.WebConnectors.LoadAllPartnerDataForBatch(ALedgerNumber, ABatchNumber)); //LoadAllPartnerDataForBatch(); //Include Donor fields LoadGiftDataForBatch(ALedgerNumber, ABatchNumber); } //Check if need to update batch period in each gift if (FBatchUnpostedFlag) { dlgStatus.CurrentStatus = Catalog.GetString("Updating batch period ..."); ((TFrmGiftBatch)ParentForm).GetBatchControl().UpdateBatchPeriod(); } // Now we set the full filter FFilterAndFindObject.ApplyFilter(); UpdateRecordNumberDisplay(); FFilterAndFindObject.SetRecordNumberDisplayProperties(); SelectRowInGrid(1); UpdateControlsProtection(); dlgStatus.CurrentStatus = Catalog.GetString("Updating totals for the batch ..."); UpdateTotals(); if ((FPreviouslySelectedDetailRow != null) && (FBatchUnpostedFlag)) { bool disableSave = (FBatchRow.RowState == DataRowState.Unchanged && !FPetraUtilsObject.HasChanges); if (disableSave && FPetraUtilsObject.HasChanges && !DataUtilities.DataRowColumnsHaveChanged(FBatchRow)) { FPetraUtilsObject.DisableSaveButton(); } } FGiftTransactionsLoadedFlag = true; dlgStatus.Close(); return(true); }