/// <summary> /// Refresh the data in the grid and the details after the database content was changed on the server /// The current filter is not changed. The highlighted row index remains the same (if possible) after the refresh. /// </summary> public void RefreshAllData() { // Remember our current row position int nCurrentRowIndex = GetSelectedRowIndex(); int nCurrentBatchNumber = -1; if (FPreviouslySelectedDetailRow != null) { nCurrentBatchNumber = FPreviouslySelectedDetailRow.BatchNumber; } TFrmGiftBatch parentForm = (TFrmGiftBatch)ParentForm; Cursor prevCursor = parentForm.Cursor; parentForm.Cursor = Cursors.WaitCursor; if ((FMainDS != null) && (FMainDS.AGiftBatch != null)) { // Remove all data from our DataSet object - the grid will go empty! FMainDS.AGiftBatch.Rows.Clear(); } try { FPetraUtilsObject.DisableDataChangedEvent(); // Calling ApplyFilter() will automatically load the data for the currently selected year // because our ApplyFilterManual() code will do that for us FFilterAndFindObject.ApplyFilter(); // Now we can select the gift batch we had before (if it still exists on the grid) if (!SelectBatchNumber(nCurrentBatchNumber)) { // If batch is no longer in the grid then select the batch that is in the same position SelectRowInGrid(nCurrentRowIndex); } UpdateRecordNumberDisplay(); TUC_GiftTransactions TransactionForm = parentForm.GetTransactionsControl(); if (TransactionForm != null) { parentForm.EnableTransactions(grdDetails.Rows.Count > 1); // if the batch number = -1 then this is not a valid instance of TUC_GiftTransactions and we do not need to refresh if (TransactionForm.FBatchNumber != -1) { // This will update the transactions to match the current batch TransactionForm.RefreshAllData(); } } } finally { FPetraUtilsObject.EnableDataChangedEvent(); parentForm.Cursor = prevCursor; } }
/// <summary> /// Method to cancel a specified batch /// </summary> /// <param name="ACurrentBatchRow"></param> /// <returns></returns> public bool CancelBatch(AGiftBatchRow ACurrentBatchRow) { string CancelMessage = string.Empty; string CompletionMessage = string.Empty; string ExistingBatchStatus = string.Empty; decimal ExistingBatchTotal = 0; List <string> ModifiedDetailKeys = new List <string>(); if ((ACurrentBatchRow == null) || (ACurrentBatchRow.BatchStatus != MFinanceConstants.BATCH_UNPOSTED)) { return(false); } CancelMessage = String.Format(Catalog.GetString("Are you sure you want to cancel gift batch number: {0}?"), ACurrentBatchRow.BatchNumber); if ((MessageBox.Show(CancelMessage, "Cancel Batch", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) != System.Windows.Forms.DialogResult.Yes)) { return(false); } // first save any changes if (!FMyForm.SaveChangesManual(TExtraGiftBatchChecks.GiftBatchAction.CANCELLING)) { return(false); } try { //Normally need to set the message parameters before the delete is performed if requiring any of the row values CompletionMessage = String.Format(Catalog.GetString("Batch no.: {0} cancelled successfully."), ACurrentBatchRow.BatchNumber); ExistingBatchTotal = ACurrentBatchRow.BatchTotal; ExistingBatchStatus = ACurrentBatchRow.BatchStatus; //Load all journals for current Batch //clear any transactions currently being editied in the Transaction Tab FMyForm.GetTransactionsControl().ClearCurrentSelection(); //Clear gifts and details etc for current Batch FMainDS.AGiftDetail.Clear(); FMainDS.AGift.Clear(); //Load tables afresh FMainDS.Merge(TRemote.MFinance.Gift.WebConnectors.LoadGiftTransactionsForBatch(FLedgerNumber, ACurrentBatchRow.BatchNumber)); FMainDS.AcceptChanges(); //Delete gift details for (int i = FMainDS.AGiftDetail.Count - 1; i >= 0; i--) { // if the gift detail being cancelled is a reversed gift if (FMainDS.AGiftDetail[i].ModifiedDetail && !string.IsNullOrEmpty(FMainDS.AGiftDetail[i].ModifiedDetailKey)) { ModifiedDetailKeys.Add(FMainDS.AGiftDetail[i].ModifiedDetailKey); } FMainDS.AGiftDetail[i].Delete(); } //Delete gifts for (int i = FMainDS.AGift.Count - 1; i >= 0; i--) { FMainDS.AGift[i].Delete(); } //Batch is only cancelled and never deleted ACurrentBatchRow.BeginEdit(); ACurrentBatchRow.BatchTotal = 0; ACurrentBatchRow.BatchStatus = MFinanceConstants.BATCH_CANCELLED; ACurrentBatchRow.EndEdit(); FPetraUtilsObject.HasChanges = true; // save first, then post if (!FMyForm.SaveChanges()) { ACurrentBatchRow.BeginEdit(); //Should normally be Unposted, but allow for other status values in future ACurrentBatchRow.BatchTotal = ExistingBatchTotal; ACurrentBatchRow.BatchStatus = ExistingBatchStatus; ACurrentBatchRow.EndEdit(); // saving failed, therefore do not try to cancel MessageBox.Show(Catalog.GetString("The cancelled batch failed to save!")); } else { TRemote.MFinance.Gift.WebConnectors.RemoveModifiedDetailOnCancel(FLedgerNumber, ModifiedDetailKeys); MessageBox.Show(CompletionMessage, "Batch Cancelled", MessageBoxButtons.OK, MessageBoxIcon.Information); } } catch (Exception ex) { CompletionMessage = ex.Message; MessageBox.Show(ex.Message, "Cancellation Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } return(false); }
/// <summary> /// The main method that handles all filtering. Every change on the filter panel causes this event to fire. /// It is important to manage the fact that this method may be called recursively and so nesting can be tricky! /// </summary> /// <param name="AFilterString">On entry this parameter contains the filter control's best guess for the current filter. /// The code can modify this string in the light of current control values.</param> public void ApplyFilterManual(ref string AFilterString) { if (!FFilterIsActivated) { // use anything until we have been activated. return; } string WorkingFilter = String.Empty; string AdditionalFilter = String.Empty; bool ShowingAllPeriods = false; // Remove the old base filter if (FPrevBaseFilter.Length > 0) { // The additional filter is the part that is coming from the extra filter panel AdditionalFilter = AFilterString.Substring(FPrevBaseFilter.Length); if (AdditionalFilter.StartsWith(CommonJoinString.JOIN_STRING_SQL_AND)) { AdditionalFilter = AdditionalFilter.Substring(CommonJoinString.JOIN_STRING_SQL_AND.Length); } } int NewYear = FcmbYearEnding.GetSelectedInt32(); if (NewYear != FPrevYearEnding) { FPrevYearEnding = NewYear; // This will trigger a re-entrant call to this method RefreshPeriods(NewYear); // Apply the last good filter as we unwind the nesting AFilterString = FPrevFilter; return; } int NewPeriod = FcmbPeriod.GetSelectedInt32(); ALedgerRow LedgerRow = ((ALedgerTable)TDataCache.TMFinance.GetCacheableFinanceTable(TCacheableFinanceTablesEnum.LedgerDetails, FLedgerNumber))[0]; int CurrentLedgerYear = LedgerRow.CurrentFinancialYear; int CurrentLedgerPeriod = LedgerRow.CurrentPeriod; if (NewYear == -1) { NewYear = CurrentLedgerYear; WorkingFilter = String.Format("{0} = {1}", AGiftBatchTable.GetBatchYearDBName(), NewYear); ShowingAllPeriods = true; } else { WorkingFilter = String.Format("{0} = {1}", AGiftBatchTable.GetBatchYearDBName(), NewYear); if (NewPeriod == 0) //All periods for year { //Nothing to add to filter ShowingAllPeriods = true; } else if (NewPeriod == -1) //Current and forwarding { WorkingFilter += String.Format(" AND {0} >= {1}", AGiftBatchTable.GetBatchPeriodDBName(), CurrentLedgerPeriod); } else if (NewPeriod > 0) //Specific period { WorkingFilter += String.Format(" AND {0} = {1}", AGiftBatchTable.GetBatchPeriodDBName(), NewPeriod); } } if (!BatchYearIsLoaded(NewYear)) { FMainDS.Merge(TRemote.MFinance.Gift.WebConnectors.LoadAGiftBatchForYearPeriod(FLedgerNumber, NewYear, NewPeriod)); // Set the flag on the transaction tab to show the status dialog again when the transactions are loaded for a new year TFrmGiftBatch giftBatchForm = (TFrmGiftBatch)FPetraUtilsObject.GetForm(); giftBatchForm.GetTransactionsControl().ShowStatusDialogOnLoad = true; } if (FrbtEditing.Checked) { StringHelper.JoinAndAppend(ref WorkingFilter, String.Format("{0} = '{1}'", AGiftBatchTable.GetBatchStatusDBName(), MFinanceConstants.BATCH_UNPOSTED), CommonJoinString.JOIN_STRING_SQL_AND); } else if (FrbtPosting.Checked) { // note: batches StringHelper.JoinAndAppend(ref WorkingFilter, String.Format("({0} = '{1}') AND ({2} > 0) AND (({4} = 0) OR ({4} = {3}))", AGiftBatchTable.GetBatchStatusDBName(), MFinanceConstants.BATCH_UNPOSTED, AGiftBatchTable.GetLastGiftNumberDBName(), AGiftBatchTable.GetBatchTotalDBName(), AGiftBatchTable.GetHashTotalDBName()), CommonJoinString.JOIN_STRING_SQL_AND); } else //(FrbtAll.Checked) { } FFilterFindPanelObject.FilterPanelControls.SetBaseFilter(WorkingFilter, FrbtAll.Checked && ShowingAllPeriods); FPrevBaseFilter = WorkingFilter; AFilterString = WorkingFilter; StringHelper.JoinAndAppend(ref AFilterString, AdditionalFilter, CommonJoinString.JOIN_STRING_SQL_AND); FPrevFilter = AFilterString; }
/// <summary> /// Method to cancel a specified batch /// </summary> /// <param name="ABatchRowToCancel"></param> /// <returns></returns> public bool CancelBatch(AGiftBatchRow ABatchRowToCancel) { bool CancellationSuccessful = false; if ((ABatchRowToCancel == null) || (ABatchRowToCancel.BatchStatus != MFinanceConstants.BATCH_UNPOSTED)) { return(false); } int CurrentBatchNo = ABatchRowToCancel.BatchNumber; bool CurrentBatchTransactionsLoadedAndCurrent = false; string CancelMessage = string.Empty; string CompletionMessage = string.Empty; List <string> ModifiedDetailKeys = new List <string>(); CancelMessage = String.Format(Catalog.GetString("Are you sure you want to cancel Gift Batch {0}?"), CurrentBatchNo); if ((MessageBox.Show(CancelMessage, "Cancel Gift Batch", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) != System.Windows.Forms.DialogResult.Yes)) { return(false); } //Backup the Dataset for reversion purposes GiftBatchTDS BackupMainDS = null; try { FMyForm.Cursor = Cursors.WaitCursor; //Backup the Dataset for reversion purposes BackupMainDS = (GiftBatchTDS)FMainDS.GetChangesTyped(false); //Don't run an inactive fields check on this batch FMyForm.GetBatchControl().UpdateUnpostedBatchDictionary(CurrentBatchNo); //Check if current batch gift details are currently loaded CurrentBatchTransactionsLoadedAndCurrent = (FMyForm.GetTransactionsControl().FBatchNumber == CurrentBatchNo); //Save and check for inactive values and ex-workers and anonymous gifts // in other unsaved Batches FPetraUtilsObject.SetChangedFlag(); if (!FMyForm.SaveChangesManual(TExtraGiftBatchChecks.GiftBatchAction.CANCELLING, !CurrentBatchTransactionsLoadedAndCurrent)) { FMyForm.GetBatchControl().UpdateUnpostedBatchDictionary(); CompletionMessage = String.Format(Catalog.GetString("Gift Batch {0} has not been cancelled."), CurrentBatchNo); MessageBox.Show(CompletionMessage, "Gift Batch Cancelled", MessageBoxButtons.OK, MessageBoxIcon.Information); return(false); } //Remove any changes to current batch that may cause validation issues FMyForm.GetBatchControl().PrepareBatchDataForCancelling(CurrentBatchNo, true); if (CurrentBatchTransactionsLoadedAndCurrent) { //Clear any transactions currently being edited in the Transaction Tab FMyForm.GetTransactionsControl().ClearCurrentSelection(CurrentBatchNo); } //Delete transactions FMyForm.GetTransactionsControl().DeleteBatchGiftData(CurrentBatchNo, ref ModifiedDetailKeys); //Batch is only cancelled and never deleted ABatchRowToCancel.BeginEdit(); ABatchRowToCancel.BatchTotal = 0; ABatchRowToCancel.LastGiftNumber = 0; ABatchRowToCancel.BatchStatus = MFinanceConstants.BATCH_CANCELLED; ABatchRowToCancel.EndEdit(); if (ModifiedDetailKeys.Count > 0) { TRemote.MFinance.Gift.WebConnectors.ReversedGiftReset(FLedgerNumber, ModifiedDetailKeys); } FPetraUtilsObject.SetChangedFlag(); FMyForm.SaveChangesManual(); CompletionMessage = String.Format(Catalog.GetString("Batch no.: {0} cancelled successfully."), CurrentBatchNo); MessageBox.Show(CompletionMessage, "Gift Batch Cancelled", MessageBoxButtons.OK, MessageBoxIcon.Information); FMyForm.DisableTransactions(); CancellationSuccessful = true; } catch (Exception ex) { //Revert to previous state if (BackupMainDS != null) { FMainDS.RejectChanges(); FMainDS.Merge(BackupMainDS); FMyForm.GetBatchControl().ShowDetailsRefresh(); } TLogging.LogException(ex, Utilities.GetMethodSignature()); throw; } finally { FMyForm.Cursor = Cursors.Default; } return(CancellationSuccessful); }
/// <summary> /// Method to cancel a specified batch /// </summary> /// <param name="ACurrentBatchRow"></param> /// <returns></returns> public bool CancelBatch(AGiftBatchRow ACurrentBatchRow) { //Assign default value(s) bool CancellationSuccessful = false; string CancelMessage = string.Empty; string CompletionMessage = string.Empty; List <string> ModifiedDetailKeys = new List <string>(); if ((ACurrentBatchRow == null) || (ACurrentBatchRow.BatchStatus != MFinanceConstants.BATCH_UNPOSTED)) { return(CancellationSuccessful); } int CurrentBatchNo = ACurrentBatchRow.BatchNumber; CancelMessage = String.Format(Catalog.GetString("Are you sure you want to cancel gift batch number: {0}?"), ACurrentBatchRow.BatchNumber); if ((MessageBox.Show(CancelMessage, "Cancel Batch", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) != System.Windows.Forms.DialogResult.Yes)) { return(CancellationSuccessful); } //Backup the Dataset for reversion purposes GiftBatchTDS BackupMainDS = (GiftBatchTDS)FMainDS.Copy(); BackupMainDS.Merge(FMainDS); try { FMyForm.Cursor = Cursors.WaitCursor; //Normally need to set the message parameters before the delete is performed if requiring any of the row values CompletionMessage = String.Format(Catalog.GetString("Batch no.: {0} cancelled successfully."), ACurrentBatchRow.BatchNumber); FMyForm.GetBatchControl().UndoModifiedBatchRow(ACurrentBatchRow, true); //Load all journals for current Batch //clear any transactions currently being editied in the Transaction Tab FMyForm.GetTransactionsControl().ClearCurrentSelection(); //Delete transactions DataView GiftDV = new DataView(FMainDS.AGift); DataView GiftDetailDV = new DataView(FMainDS.AGiftDetail); GiftDV.AllowDelete = true; GiftDetailDV.AllowDelete = true; GiftDV.RowFilter = String.Format("{0}={1}", AGiftTable.GetBatchNumberDBName(), CurrentBatchNo); GiftDV.Sort = AGiftTable.GetGiftTransactionNumberDBName() + " DESC"; GiftDetailDV.RowFilter = String.Format("{0}={1}", AGiftDetailTable.GetBatchNumberDBName(), CurrentBatchNo); GiftDetailDV.Sort = String.Format("{0} DESC, {1} DESC", AGiftDetailTable.GetGiftTransactionNumberDBName(), AGiftDetailTable.GetDetailNumberDBName()); foreach (DataRowView drv in GiftDetailDV) { AGiftDetailRow gdr = (AGiftDetailRow)drv.Row; // if the gift detail being cancelled is a reversed gift if (gdr.ModifiedDetail && !string.IsNullOrEmpty(gdr.ModifiedDetailKey)) { ModifiedDetailKeys.Add(gdr.ModifiedDetailKey); } gdr.Delete(); } for (int i = 0; i < GiftDV.Count; i++) { GiftDV.Delete(i); } //Batch is only cancelled and never deleted ACurrentBatchRow.BatchTotal = 0; ACurrentBatchRow.LastGiftNumber = 0; ACurrentBatchRow.BatchStatus = MFinanceConstants.BATCH_CANCELLED; FPetraUtilsObject.SetChangedFlag(); // save first if (FMyForm.SaveChanges()) { if (ModifiedDetailKeys.Count > 0) { TRemote.MFinance.Gift.WebConnectors.ReversedGiftReset(FLedgerNumber, ModifiedDetailKeys); } MessageBox.Show(CompletionMessage, "Batch Cancelled", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { throw new Exception(Catalog.GetString("The batch failed to save after being cancelled! Reopen the form and retry.")); } CancellationSuccessful = true; } catch (Exception ex) { //Revert to previous state FMainDS.Merge(BackupMainDS); CompletionMessage = ex.Message; MessageBox.Show(CompletionMessage, "Cancellation Error", MessageBoxButtons.OK, MessageBoxIcon.Error); TLogging.LogException(ex, Utilities.GetMethodSignature()); throw; } finally { FMyForm.Cursor = Cursors.Default; } return(CancellationSuccessful); }
/// <summary> /// Method to cancel a specified batch /// </summary> /// <param name="ACurrentBatchRow"></param> /// <returns></returns> public bool CancelBatch(AGiftBatchRow ACurrentBatchRow) { //Assign default value(s) bool CancellationSuccessful = false; string CancelMessage = string.Empty; string CompletionMessage = string.Empty; List <string> ModifiedDetailKeys = new List <string>(); if ((ACurrentBatchRow == null) || (ACurrentBatchRow.BatchStatus != MFinanceConstants.BATCH_UNPOSTED)) { return(CancellationSuccessful); } CancelMessage = String.Format(Catalog.GetString("Are you sure you want to cancel gift batch number: {0}?"), ACurrentBatchRow.BatchNumber); if ((MessageBox.Show(CancelMessage, "Cancel Batch", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) != System.Windows.Forms.DialogResult.Yes)) { return(CancellationSuccessful); } //Backup the Dataset for reversion purposes GiftBatchTDS BackupMainDS = (GiftBatchTDS)FMainDS.Copy(); BackupMainDS.Merge(FMainDS); try { FMyForm.Cursor = Cursors.WaitCursor; //Normally need to set the message parameters before the delete is performed if requiring any of the row values CompletionMessage = String.Format(Catalog.GetString("Batch no.: {0} cancelled successfully."), ACurrentBatchRow.BatchNumber); FMyForm.GetBatchControl().UndoModifiedBatchRow(ACurrentBatchRow, true); //Load all journals for current Batch //clear any transactions currently being editied in the Transaction Tab FMyForm.GetTransactionsControl().ClearCurrentSelection(); //Clear gifts and details etc for current and any other loaded batches FMainDS.AGiftDetail.Clear(); FMainDS.AGift.Clear(); //Load tables afresh FMainDS.Merge(TRemote.MFinance.Gift.WebConnectors.LoadGiftTransactionsForBatch(FLedgerNumber, ACurrentBatchRow.BatchNumber)); FMainDS.AcceptChanges(); //Delete gift details for (int i = FMainDS.AGiftDetail.Count - 1; i >= 0; i--) { // if the gift detail being cancelled is a reversed gift if (FMainDS.AGiftDetail[i].ModifiedDetail && !string.IsNullOrEmpty(FMainDS.AGiftDetail[i].ModifiedDetailKey)) { ModifiedDetailKeys.Add(FMainDS.AGiftDetail[i].ModifiedDetailKey); } FMainDS.AGiftDetail[i].Delete(); } //Delete gifts for (int i = FMainDS.AGift.Count - 1; i >= 0; i--) { FMainDS.AGift[i].Delete(); } //Batch is only cancelled and never deleted ACurrentBatchRow.BatchTotal = 0; ACurrentBatchRow.BatchStatus = MFinanceConstants.BATCH_CANCELLED; // save first if (FMyForm.SaveChanges()) { TRemote.MFinance.Gift.WebConnectors.RemoveModifiedDetailOnCancel(FLedgerNumber, ModifiedDetailKeys); MessageBox.Show(CompletionMessage, "Batch Cancelled", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { throw new Exception(Catalog.GetString("The batch failed to save after being cancelled! Reopen the form and retry.")); } CancellationSuccessful = true; } catch (Exception ex) { CompletionMessage = ex.Message; MessageBox.Show(CompletionMessage, "Cancellation Error", MessageBoxButtons.OK, MessageBoxIcon.Error); //Revert to previous state FMainDS.Merge(BackupMainDS); } finally { FMyForm.Cursor = Cursors.Default; } return(CancellationSuccessful); }