private void RevertDataSet(GiftBatchTDS AMainDS, GiftBatchTDS ABackupDS) { AMainDS.ALedger.Clear(); AMainDS.AGiftDetail.Clear(); AMainDS.AGift.Clear(); AMainDS.AGiftBatch.Clear(); AMainDS.Merge(ABackupDS); }
public void SpeedTestLoadIntoTypedTable() { TDBTransaction ReadTransaction = null; DateTime before = DateTime.Now; DateTime after = DateTime.Now; GiftBatchTDS ds = new GiftBatchTDS(); DBAccess.GDBAccessObj.GetNewOrExistingAutoReadTransaction( IsolationLevel.ReadCommitted, TEnforceIsolationLevel.eilMinimum, ref ReadTransaction, delegate { string sql = "SELECT PUB_a_gift_detail.*, false AS AlreadyMatched, PUB_a_gift_batch.a_batch_status_c AS BatchStatus " + "FROM PUB_a_gift_batch, PUB_a_gift_detail " + "WHERE PUB_a_gift_detail.a_ledger_number_i = PUB_a_gift_batch.a_ledger_number_i AND PUB_a_gift_detail.a_batch_number_i = PUB_a_gift_batch.a_batch_number_i"; before = DateTime.Now; DataTable untyped = DBAccess.GDBAccessObj.SelectDT(sql, "test", ReadTransaction); after = DateTime.Now; TLogging.Log(String.Format("loading all {0} gift details into an untyped table took {1} milliseconds", untyped.Rows.Count, (after.Subtract(before)).TotalMilliseconds)); GiftBatchTDSAGiftDetailTable typed = new GiftBatchTDSAGiftDetailTable(); before = DateTime.Now; DBAccess.GDBAccessObj.SelectDT(typed, sql, ReadTransaction, new OdbcParameter[0], 0, 0); after = DateTime.Now; TLogging.Log(String.Format("loading all {0} gift details into a typed table took {1} milliseconds", typed.Rows.Count, (after.Subtract(before)).TotalMilliseconds)); AMotivationDetailAccess.LoadAll(ds, ReadTransaction); before = DateTime.Now; DBAccess.GDBAccessObj.Select(ds, sql, ds.AGiftDetail.TableName, ReadTransaction); after = DateTime.Now; }); TLogging.Log(String.Format("loading all {0} gift details into a typed dataset took {1} milliseconds", ds.AGiftDetail.Rows.Count, (after.Subtract(before)).TotalMilliseconds)); before = DateTime.Now; GiftBatchTDS ds2 = new GiftBatchTDS(); ds2.Merge(ds.AGiftDetail); after = DateTime.Now; TLogging.Log(String.Format("merging typed table into other dataset took {0} milliseconds", (after.Subtract(before)).TotalMilliseconds)); }
private void RevertDataSet(GiftBatchTDS AMainDS, GiftBatchTDS ABackupDS, int ASelectRowInGrid = 0) { if ((ABackupDS != null) && (AMainDS != null)) { AMainDS.RejectChanges(); AMainDS.Merge(ABackupDS); if (ASelectRowInGrid > 0) { SelectRowInGrid(ASelectRowInGrid); } } }
/// <summary> /// Deletes the current row and optionally populates a completion message /// </summary> /// <param name="ARowToDelete">the currently selected row to delete</param> /// <param name="ACompletionMessage">if specified, is the deletion completion message</param> /// <returns>true if row deletion is successful</returns> private bool DeleteRowManual(ARecurringGiftBatchRow ARowToDelete, ref string ACompletionMessage) { bool DeletionSuccessful = false; if (ARowToDelete == null) { return(DeletionSuccessful); } int BatchNumber = ARowToDelete.BatchNumber; ACompletionMessage = string.Empty; bool RowToDeleteIsNew = (ARowToDelete.RowState == DataRowState.Added); //Backup the Dataset for reversion purposes GiftBatchTDS BackupMainDS = (GiftBatchTDS)FMainDS.Copy(); BackupMainDS.Merge(FMainDS); if (!RowToDeleteIsNew) { //Return modified row to last saved state to avoid validation failures ARowToDelete.RejectChanges(); ShowDetails(ARowToDelete); if (!((TFrmRecurringGiftBatch)FPetraUtilsObject.GetForm()).SaveChangesManual(TExtraGiftBatchChecks.GiftBatchAction.DELETING)) { MessageBox.Show(Catalog.GetString("Error in trying to save prior to deleting current recurring gift batch!"), Catalog.GetString("Deletion Error"), MessageBoxButtons.OK, MessageBoxIcon.Error); return(DeletionSuccessful); } } try { this.Cursor = Cursors.WaitCursor; ACompletionMessage = String.Format(Catalog.GetString("Batch no.: {0} deleted successfully."), BatchNumber); //clear any transactions currently being editied in the Transaction Tab ((TFrmRecurringGiftBatch)ParentForm).GetTransactionsControl().ClearCurrentSelection(); if (!RowToDeleteIsNew) { //Load tables afresh FMainDS.Merge(TRemote.MFinance.Gift.WebConnectors.LoadRecurringGiftTransactionsForBatch(FLedgerNumber, BatchNumber)); } ((TFrmRecurringGiftBatch)ParentForm).GetTransactionsControl().DeleteCurrentRecurringBatchGiftData(BatchNumber); // Delete the recurring batch row. ARowToDelete.Delete(); FPreviouslySelectedDetailRow = null; DeletionSuccessful = true; } catch (Exception ex) { ACompletionMessage = ex.Message; MessageBox.Show(ACompletionMessage, "Deletion Error", MessageBoxButtons.OK, MessageBoxIcon.Error); //Revert to previous state FMainDS.Merge(BackupMainDS); } finally { this.Cursor = Cursors.Default; } UpdateRecordNumberDisplay(); return(DeletionSuccessful); }
private bool OnDeleteRowManual(GiftBatchTDSAGiftDetailRow ARowToDelete, ref string ACompletionMessage) { bool deletionSuccessful = false; string originatingDetailRef = string.Empty; ACompletionMessage = string.Empty; if (ARowToDelete == null) { return(deletionSuccessful); } // temporarily disable New Donor Warning ((TFrmGiftBatch)this.ParentForm).NewDonorWarning = false; if ((ARowToDelete.RowState != DataRowState.Added) && !((TFrmGiftBatch)this.ParentForm).SaveChangesManual()) { MessageBox.Show("Error in trying to save prior to deleting current gift detail!"); return(deletionSuccessful); } ((TFrmGiftBatch)this.ParentForm).NewDonorWarning = true; //Backup the Dataset for reversion purposes GiftBatchTDS FTempDS = (GiftBatchTDS)FMainDS.Copy(); FTempDS.Merge(FMainDS); if (ARowToDelete.RowState != DataRowState.Added) { //Required to deal with concurrency errors FMainDS.AcceptChanges(); } int selectedDetailNumber = ARowToDelete.DetailNumber; int giftToDeleteTransNo = 0; string filterAllGiftsOfBatch = String.Empty; string filterAllGiftDetailsOfBatch = String.Empty; int detailRowCount = FGiftDetailView.Count; try { //Speeds up deletion of larger gift sets FMainDS.EnforceConstraints = false; if (ARowToDelete.ModifiedDetailKey != null) { originatingDetailRef = ARowToDelete.ModifiedDetailKey; } //Delete current detail row ARowToDelete.Delete(); //If there existed (before the delete row above) more than one detail row, then no need to delete gift header row if (detailRowCount > 1) { FGiftSelectedForDeletion = false; foreach (DataRowView rv in FGiftDetailView) { GiftBatchTDSAGiftDetailRow row = (GiftBatchTDSAGiftDetailRow)rv.Row; if (row.DetailNumber > selectedDetailNumber) { row.DetailNumber--; } } FGift.LastDetailNumber--; FPetraUtilsObject.SetChangedFlag(); } else { giftToDeleteTransNo = FGift.GiftTransactionNumber; TLogging.Log("Delete row: " + giftToDeleteTransNo.ToString()); // Reduce all Gift Detail row Transaction numbers by 1 if they are greater then gift to be deleted filterAllGiftDetailsOfBatch = String.Format("{0}={1} And {2}>{3}", AGiftDetailTable.GetBatchNumberDBName(), FBatchNumber, AGiftDetailTable.GetGiftTransactionNumberDBName(), giftToDeleteTransNo); DataView giftDetailView = new DataView(FMainDS.AGiftDetail); giftDetailView.RowFilter = filterAllGiftDetailsOfBatch; giftDetailView.Sort = String.Format("{0} ASC", AGiftDetailTable.GetGiftTransactionNumberDBName()); foreach (DataRowView rv in giftDetailView) { GiftBatchTDSAGiftDetailRow row = (GiftBatchTDSAGiftDetailRow)rv.Row; row.GiftTransactionNumber--; } //Cannot delete the gift row, just copy the data of rows above down by 1 row // and then mark the top row for deletion //In other words, bubble the gift row to be deleted to the top filterAllGiftsOfBatch = String.Format("{0}={1} And {2}>={3}", AGiftTable.GetBatchNumberDBName(), FBatchNumber, AGiftTable.GetGiftTransactionNumberDBName(), giftToDeleteTransNo); DataView giftView = new DataView(FMainDS.AGift); giftView.RowFilter = filterAllGiftsOfBatch; giftView.Sort = String.Format("{0} ASC", AGiftTable.GetGiftTransactionNumberDBName()); AGiftRow giftRowToReceive = null; AGiftRow giftRowToCopyDown = null; AGiftRow giftRowCurrent = null; int currentGiftTransNo = 0; foreach (DataRowView gv in giftView) { giftRowCurrent = (AGiftRow)gv.Row; currentGiftTransNo = giftRowCurrent.GiftTransactionNumber; if (currentGiftTransNo > giftToDeleteTransNo) { giftRowToCopyDown = giftRowCurrent; //Copy column values down for (int j = 3; j < giftRowToCopyDown.Table.Columns.Count; j++) { //Update all columns except the pk fields that remain the same if (!giftRowToCopyDown.Table.Columns[j].ColumnName.EndsWith("_text")) { giftRowToReceive[j] = giftRowToCopyDown[j]; } } } if (currentGiftTransNo == FBatchRow.LastGiftNumber) { //Mark last record for deletion giftRowCurrent.GiftStatus = MFinanceConstants.MARKED_FOR_DELETION; } //Will always be previous row giftRowToReceive = giftRowCurrent; } FPreviouslySelectedDetailRow = null; FPetraUtilsObject.SetChangedFlag(); FGiftSelectedForDeletion = true; FBatchRow.LastGiftNumber--; } //Force a change in the batch row to make sure it exists in the dataset to save FBatchRow.DateModified = DateTime.Now; //Check if deleting a reversed gift detail if (originatingDetailRef.StartsWith("|")) { bool ok = TRemote.MFinance.Gift.WebConnectors.ReversedGiftReset(FLedgerNumber, originatingDetailRef); if (!ok) { throw new Exception("Error in trying to reset Modified Detail field of the originating gift detail."); } } //Try to save changes if (((TFrmGiftBatch)this.ParentForm).SaveChangesManual()) { //Clear current batch's gift data and reload from server RefreshCurrentBatchGiftData(FBatchNumber); } else { throw new Exception("Unable to save after deleting a gift!"); } ACompletionMessage = Catalog.GetString("Gift row deleted successfully!"); deletionSuccessful = true; } catch (Exception ex) { ACompletionMessage = ex.Message; MessageBox.Show(ex.Message, "Gift Deletion Error", MessageBoxButtons.OK, MessageBoxIcon.Error); //Revert to previous state FMainDS.Merge(FTempDS); } finally { FMainDS.EnforceConstraints = true; SetGiftDetailDefaultView(); FFilterAndFindObject.ApplyFilter(); } UpdateRecordNumberDisplay(); return(deletionSuccessful); }
/// <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> /// Deletes the current row and optionally populates a completion message /// </summary> /// <param name="ARowToDelete">the currently selected row to delete</param> /// <param name="AFPrevRow">Is FPreviouslySelectedDetailRow</param> /// <param name="ACompletionMessage">if specified, is the deletion completion message</param> /// <returns>true if row deletion is successful</returns> public bool DeleteRowManual(ARecurringGiftBatchRow ARowToDelete, ref ARecurringGiftBatchRow AFPrevRow, ref string ACompletionMessage) { bool DeletionSuccessful = false; ACompletionMessage = string.Empty; if (ARowToDelete == null) { return(false); } int CurrentBatchNo = ARowToDelete.BatchNumber; bool CurrentBatchTransactionsLoadedAndCurrent = false; //Backup the Dataset for reversion purposes GiftBatchTDS BackupMainDS = null; try { FMyForm.Cursor = Cursors.WaitCursor; //Backup the changes to allow rollback BackupMainDS = (GiftBatchTDS)FMainDS.GetChangesTyped(false); //Don't run an inactive fields check on this batch FMyForm.GetBatchControl().UpdateRecurringBatchDictionary(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.DELETING, !CurrentBatchTransactionsLoadedAndCurrent)) { FMyForm.GetBatchControl().UpdateRecurringBatchDictionary(); string msg = String.Format(Catalog.GetString("Recurring Batch {0} has not been deleted."), CurrentBatchNo); MessageBox.Show(msg, "Recurring Gift Batch Deleted", MessageBoxButtons.OK, MessageBoxIcon.Information); return(false); } //Remove any changes to current batch that may cause validation issues FMyForm.GetBatchControl().PrepareBatchDataForDeleting(CurrentBatchNo, true); if (CurrentBatchTransactionsLoadedAndCurrent) { //Clear any transactions currently being edited in the Transaction Tab FMyForm.GetTransactionsControl().ClearCurrentSelection(CurrentBatchNo); } //Delete transactions FMyForm.GetTransactionsControl().DeleteRecurringBatchGiftData(CurrentBatchNo); // Delete the recurring batch row and save again after deleting the batch row. ARowToDelete.Delete(); ACompletionMessage = String.Format(Catalog.GetString("Recurring Gift Batch no.: {0} deleted successfully."), CurrentBatchNo); AFPrevRow = null; DeletionSuccessful = 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(DeletionSuccessful); }
/// <summary> /// Clear the gift data of the current batch without marking records for delete /// </summary> private bool RefreshBatchGiftData(Int32 ABatchNumber, bool AAcceptChanges = false, bool AHandleDataSetBackup = false) { bool RetVal = false; //Copy and backup the current dataset GiftBatchTDS BackupDS = null; GiftBatchTDS TempDS = (GiftBatchTDS)FMainDS.Copy(); TempDS.Merge(FMainDS); if (AHandleDataSetBackup) { BackupDS = (GiftBatchTDS)FMainDS.GetChangesTyped(false); } try { this.Cursor = Cursors.WaitCursor; //Remove current batch gift data DataView giftDetailView = new DataView(TempDS.AGiftDetail); giftDetailView.RowFilter = String.Format("{0}={1}", AGiftDetailTable.GetBatchNumberDBName(), ABatchNumber); giftDetailView.Sort = String.Format("{0} DESC, {1} DESC", AGiftDetailTable.GetGiftTransactionNumberDBName(), AGiftDetailTable.GetDetailNumberDBName()); foreach (DataRowView dr in giftDetailView) { dr.Delete(); } DataView giftView = new DataView(TempDS.AGift); giftView.RowFilter = String.Format("{0}={1}", AGiftTable.GetBatchNumberDBName(), ABatchNumber); giftView.Sort = String.Format("{0} DESC", AGiftTable.GetGiftTransactionNumberDBName()); foreach (DataRowView dr in giftView) { dr.Delete(); } TempDS.AcceptChanges(); //Clear all gift data from Main dataset gift tables FMainDS.AGiftDetail.Clear(); FMainDS.AGift.Clear(); //Bring data back in from other batches if it exists if (TempDS.AGift.Count > 0) { FMainDS.AGift.Merge(TempDS.AGift); FMainDS.AGiftDetail.Merge(TempDS.AGiftDetail); } //TODO: Confirm I need to AcceptChanges FMainDS.Merge(TRemote.MFinance.Gift.WebConnectors.LoadGiftTransactionsForBatch(FLedgerNumber, ABatchNumber)); if (AAcceptChanges) { FMainDS.AcceptChanges(); } RetVal = true; } catch (Exception ex) { //If not revert on error then calling method will if (AHandleDataSetBackup) { RevertDataSet(FMainDS, BackupDS); } TLogging.LogException(ex, Utilities.GetMethodSignature()); throw; } finally { this.Cursor = Cursors.Default; } return(RetVal); }
/// <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); }
private void DeleteAllGifts(System.Object sender, EventArgs e) { TFrmRecurringGiftBatch FMyForm = (TFrmRecurringGiftBatch)this.ParentForm; string CompletionMessage = string.Empty; int BatchNumberToClear = FBatchNumber; if ((FPreviouslySelectedDetailRow == null)) { return; } else if (!FFilterAndFindObject.IsActiveFilterEqualToBase) { MessageBox.Show(Catalog.GetString("Please remove the filter before attempting to delete all Recurring Gifts in this batch."), Catalog.GetString("Delete All Recurring Gifts")); return; } //Backup the Dataset for reversion purposes GiftBatchTDS BackupDS = (GiftBatchTDS)FMainDS.Copy(); BackupDS.Merge(FMainDS); if (MessageBox.Show(String.Format(Catalog.GetString( "You have chosen to delete all Gifts from Recurring Batch: {0}.{1}{1}Are you sure you want to delete all?"), BatchNumberToClear, Environment.NewLine), Catalog.GetString("Confirm Delete All"), MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) != System.Windows.Forms.DialogResult.Yes) { return; } try { this.Cursor = Cursors.WaitCursor; //Specify current action FMyForm.FCurrentGiftBatchAction = Logic.TExtraGiftBatchChecks.GiftBatchAction.DELETINGTRANS; //clear any transactions currently being editied in the Transaction Tab ClearCurrentSelection(0, false); //Now delete all Recurring Gift data for current batch DeleteRecurringBatchGiftData(BatchNumberToClear); FBatchRow.BatchTotal = 0; txtBatchTotal.NumberValueDecimal = 0; // Be sure to set the last Recurring Gift number in the parent table before saving all the changes FBatchRow.LastGiftNumber = 0; FPetraUtilsObject.SetChangedFlag(); // save changes if (((TFrmRecurringGiftBatch)ParentForm).SaveChangesManual()) { CompletionMessage = Catalog.GetString("All Recurring Gifts and their details deleted successfully."); MessageBox.Show(CompletionMessage, Catalog.GetString("Recurring Gifts Deletion"), MessageBoxButtons.OK, MessageBoxIcon.Information); } else { CompletionMessage = Catalog.GetString("All Recurring Gifts and their details have been deleted but saving the changes failed!"); MessageBox.Show(CompletionMessage, Catalog.GetString("All Gifts Deletion"), MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } } catch (Exception ex) { //Revert to previous state RevertDataSet(FMainDS, BackupDS); TLogging.LogException(ex, Utilities.GetMethodSignature()); throw; } finally { FMyForm.FCurrentGiftBatchAction = Logic.TExtraGiftBatchChecks.GiftBatchAction.NONE; this.Cursor = Cursors.Default; } SetGiftDetailDefaultView(); FFilterAndFindObject.ApplyFilter(); if (grdDetails.Rows.Count < 2) { ShowDetails(null); UpdateControlsProtection(); } UpdateRecordNumberDisplay(); }
private void DeleteAllGifts(System.Object sender, EventArgs e) { string CompletionMessage = string.Empty; int BatchNumberToClear = FBatchNumber; List <string> OriginatingDetailRef = new List <string>(); if ((FPreviouslySelectedDetailRow == null) || (FBatchRow.BatchStatus != MFinanceConstants.BATCH_UNPOSTED)) { return; } else if (!FFilterAndFindObject.IsActiveFilterEqualToBase) { MessageBox.Show(Catalog.GetString("Please remove the filter before attempting to delete all gifts in this batch."), Catalog.GetString("Delete All Gifts")); return; } //Backup the Dataset for reversion purposes GiftBatchTDS BackupMainDS = (GiftBatchTDS)FMainDS.Copy(); BackupMainDS.Merge(FMainDS); if (MessageBox.Show(String.Format(Catalog.GetString( "You have chosen to delete all gifts from Gift Batch ({0}).{1}{1}Are you sure you want to delete all?"), BatchNumberToClear, Environment.NewLine), Catalog.GetString("Confirm Delete All"), MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == System.Windows.Forms.DialogResult.Yes) { try { this.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("All gifts and details deleted successfully."), FPreviouslySelectedDetailRow.BatchNumber); //clear any transactions currently being editied in the Transaction Tab ClearCurrentSelection(false); //Now delete all gift data for current batch DeleteCurrentBatchGiftData(BatchNumberToClear, ref OriginatingDetailRef); FBatchRow.BatchTotal = 0; txtBatchTotal.NumberValueDecimal = 0; // Be sure to set the last gift number in the parent table before saving all the changes FBatchRow.LastGiftNumber = 0; FPetraUtilsObject.SetChangedFlag(); // save first, then post if (((TFrmGiftBatch)ParentForm).SaveChangesManual()) { //Check if have deleted a reversing gift detail if (OriginatingDetailRef.Count > 0) { TRemote.MFinance.Gift.WebConnectors.ReversedGiftReset(FLedgerNumber, OriginatingDetailRef); } MessageBox.Show(CompletionMessage, "All Gifts Deleted.", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { throw new Exception("Unable to save after deleting all gifts!"); } } catch (Exception ex) { //Revert to previous state RevertDataSet(FMainDS, BackupMainDS); TLogging.LogException(ex, Utilities.GetMethodSignature()); throw; } finally { SetGiftDetailDefaultView(); FFilterAndFindObject.ApplyFilter(); this.Cursor = Cursors.Default; } } if (grdDetails.Rows.Count < 2) { ShowDetails(null); UpdateControlsProtection(); } UpdateRecordNumberDisplay(); }
/// <summary> /// Checks the entire gift batch for inactive values and informs the user /// </summary> /// <param name="ALedgerNumber"></param> /// <param name="AAction"></param> /// <param name="AMainDS"></param> /// <param name="APetraUtilsObject"></param> /// <param name="AIsRecurringGift"></param> /// <returns></returns> public static bool CheckForInactiveFieldValues(Int32 ALedgerNumber, GiftBatchAction AAction, GiftBatchTDS AMainDS, TFrmPetraEditUtils APetraUtilsObject, Boolean AIsRecurringGift = false) { #region Validate Arguments if (AMainDS == null) { throw new EFinanceSystemInvalidLedgerNumberException(String.Format(Catalog.GetString( "Function:{0} - The Gift Batch dataset is empty!"), Utilities.GetMethodName(true))); } else if (AMainDS.AGiftBatch.Count == 0) { throw new ArgumentException(String.Format(Catalog.GetString( "Function:{0} - The Gift Batch table contains no batches to validate!"), Utilities.GetMethodName(true))); } #endregion Validate Arguments //TODO: Need to rewrite... bool RetVal = false; bool ChangesAtGiftBatchLevel = false; bool ChangesAtGiftLevel = false; bool ChangesAtGiftDetailLevel = false; string IndentifyRecurring = (AIsRecurringGift ? "ARecurring" : "A"); Type GiftBatchTableType = Type.GetType(IndentifyRecurring + "GiftBatchTable"); bool WarnOfInactiveValuesOnPosting = TUserDefaults.GetBooleanDefault(TUserDefaults.FINANCE_GIFT_WARN_OF_INACTIVE_VALUES_ON_POSTING, true); if ((AAction == GiftBatchAction.POSTING) && !WarnOfInactiveValuesOnPosting) { return(true); } if (APetraUtilsObject.HasChanges) { GiftBatchTDS Changes = new GiftBatchTDS(); //Batch level if (!AIsRecurringGift && (AMainDS.AGiftBatch.GetChangesTyped() != null)) { Changes.Merge(AMainDS.AGiftBatch.GetChangesTyped()); ChangesAtGiftBatchLevel = true; } else if (AIsRecurringGift && (AMainDS.ARecurringGiftBatch.GetChangesTyped() != null)) { Changes.Merge(AMainDS.ARecurringGiftBatch.GetChangesTyped()); ChangesAtGiftBatchLevel = true; } //Gift level if (!AIsRecurringGift && (AMainDS.AGift.GetChangesTyped() != null)) { Changes.Merge(AMainDS.AGift.GetChangesTyped()); ChangesAtGiftLevel = true; } else if (AIsRecurringGift && (AMainDS.ARecurringGift.GetChangesTyped() != null)) { Changes.Merge(AMainDS.ARecurringGift.GetChangesTyped()); ChangesAtGiftLevel = true; } //Detail level if (!AIsRecurringGift && (AMainDS.AGiftDetail.GetChangesTyped() != null)) { Changes.Merge(AMainDS.AGiftDetail.GetChangesTyped()); ChangesAtGiftDetailLevel = true; } else if (AIsRecurringGift && (AMainDS.ARecurringGiftDetail.GetChangesTyped() != null)) { Changes.Merge(AMainDS.ARecurringGiftDetail.GetChangesTyped()); ChangesAtGiftDetailLevel = true; } //Process changes if (ChangesAtGiftBatchLevel) { //***Batch level //TODO: Check for inactive Bank Cost Centre if (!AIsRecurringGift) { } else { //Recurring gift batch changes } //TODO: Check for inactive Bank Account if (!AIsRecurringGift) { } else { //Recurring gift batch changes } //TODO: Check for inactive Currency Code if (!AIsRecurringGift) { } else { //Recurring gift batch changes } //TODO: Check for inactive Method of Payment if (!AIsRecurringGift) { } else { //Recurring gift batch changes } } if (ChangesAtGiftLevel) { //**Gift-level //TODO: Check for inactive Donor if (!AIsRecurringGift) { } else { //Recurring gift batch changes } //TODO: Check for inactive Method of Payment if (!AIsRecurringGift) { } else { //Recurring gift batch changes } //TODO: Check for inactive Method of Giving if (!AIsRecurringGift) { } else { //Recurring gift batch changes } } if (ChangesAtGiftDetailLevel) { //*Detail-level //TODO: Check for inactive Recipient if (!AIsRecurringGift) { } else { //Recurring gift batch changes } //TODO: Check for inactive Key Ministry if (!AIsRecurringGift) { } else { //Recurring gift batch changes } //TODO: Check for inactive Cost Centre if (!AIsRecurringGift) { } else { //Recurring gift batch changes } //TODO: Check for inactive Account if (!AIsRecurringGift) { } else { //Recurring gift batch changes } //TODO: Check for inactive Tax Account if (!AIsRecurringGift) { } else { //Recurring gift batch changes } //TODO: Check for inactive Motivation Group or Detail if (!AIsRecurringGift) { } else { //Recurring gift batch changes } //TODO: Check for inactive MailingCode if (!AIsRecurringGift) { } else { //Recurring gift batch changes } } } return(RetVal); }
private bool OnDeleteRowManual(GiftBatchTDSAGiftDetailRow ARowToDelete, ref string ACompletionMessage) { bool DeletionSuccessful = false; List <string> OriginatingDetailRef = new List <string>(); ACompletionMessage = string.Empty; if (ARowToDelete == null) { return(DeletionSuccessful); } bool RowToDeleteIsNew = (ARowToDelete.RowState == DataRowState.Added); if (!RowToDeleteIsNew) { try { // temporarily disable New Donor Warning ((TFrmGiftBatch)this.ParentForm).NewDonorWarning = false; //Return modified row to last saved state to avoid validation failures ARowToDelete.RejectChanges(); ShowDetails(ARowToDelete); if (!((TFrmGiftBatch)this.ParentForm).SaveChanges()) { MessageBox.Show(Catalog.GetString("Error in trying to save prior to deleting current gift detail!"), Catalog.GetString("Deletion Error"), MessageBoxButtons.OK, MessageBoxIcon.Error); return(DeletionSuccessful); } } finally { ((TFrmGiftBatch)this.ParentForm).NewDonorWarning = true; } } //Backup the Dataset for reversion purposes GiftBatchTDS BackupMainDS = (GiftBatchTDS)FMainDS.Copy(); BackupMainDS.Merge(FMainDS); //To be used later....Pass copy to delete method. //GiftBatchTDS TempDS = (GiftBatchTDS)FMainDS.Copy(); //TempDS.Merge(FMainDS); int SelectedDetailNumber = ARowToDelete.DetailNumber; int GiftToDeleteTransNo = 0; string FilterAllGiftsOfBatch = String.Empty; string FilterAllGiftDetailsOfBatch = String.Empty; int DetailRowCount = FGiftDetailView.Count; try { this.Cursor = Cursors.WaitCursor; //Speeds up deletion of larger gift sets FMainDS.EnforceConstraints = false; if ((ARowToDelete.ModifiedDetailKey != null) && (ARowToDelete.ModifiedDetailKey.Length > 0)) { OriginatingDetailRef.Add(ARowToDelete.ModifiedDetailKey); } //Delete current detail row ARowToDelete.Delete(); //If there existed (before the delete row above) more than one detail row, then no need to delete gift header row if (DetailRowCount > 1) { ACompletionMessage = Catalog.GetString("Gift Detail row deleted successfully!"); FGiftSelectedForDeletion = false; foreach (DataRowView rv in FGiftDetailView) { GiftBatchTDSAGiftDetailRow row = (GiftBatchTDSAGiftDetailRow)rv.Row; if (row.DetailNumber > SelectedDetailNumber) { row.DetailNumber--; } } FGift.LastDetailNumber--; FPetraUtilsObject.SetChangedFlag(); } else { ACompletionMessage = Catalog.GetString("Gift deleted successfully!"); GiftToDeleteTransNo = FGift.GiftTransactionNumber; // Reduce all Gift Detail row Transaction numbers by 1 if they are greater then gift to be deleted FilterAllGiftDetailsOfBatch = String.Format("{0}={1} And {2}>{3}", AGiftDetailTable.GetBatchNumberDBName(), FBatchNumber, AGiftDetailTable.GetGiftTransactionNumberDBName(), GiftToDeleteTransNo); DataView giftDetailView = new DataView(FMainDS.AGiftDetail); giftDetailView.RowFilter = FilterAllGiftDetailsOfBatch; giftDetailView.Sort = String.Format("{0} ASC", AGiftDetailTable.GetGiftTransactionNumberDBName()); foreach (DataRowView rv in giftDetailView) { GiftBatchTDSAGiftDetailRow row = (GiftBatchTDSAGiftDetailRow)rv.Row; row.GiftTransactionNumber--; } //Cannot delete the gift row, just copy the data of rows above down by 1 row // and then mark the top row for deletion //In other words, bubble the gift row to be deleted to the top FilterAllGiftsOfBatch = String.Format("{0}={1} And {2}>={3}", AGiftTable.GetBatchNumberDBName(), FBatchNumber, AGiftTable.GetGiftTransactionNumberDBName(), GiftToDeleteTransNo); DataView giftView = new DataView(FMainDS.AGift); giftView.RowFilter = FilterAllGiftsOfBatch; giftView.Sort = String.Format("{0} ASC", AGiftTable.GetGiftTransactionNumberDBName()); AGiftRow giftRowToReceive = null; AGiftRow giftRowToCopyDown = null; AGiftRow giftRowCurrent = null; int currentGiftTransNo = 0; foreach (DataRowView gv in giftView) { giftRowCurrent = (AGiftRow)gv.Row; currentGiftTransNo = giftRowCurrent.GiftTransactionNumber; if (currentGiftTransNo > GiftToDeleteTransNo) { giftRowToCopyDown = giftRowCurrent; //Copy column values down for (int j = 3; j < giftRowToCopyDown.Table.Columns.Count; j++) { //Update all columns except the pk fields that remain the same if (!giftRowToCopyDown.Table.Columns[j].ColumnName.EndsWith("_text")) { giftRowToReceive[j] = giftRowToCopyDown[j]; } } } if (currentGiftTransNo == FBatchRow.LastGiftNumber) { //Mark last record for deletion giftRowCurrent.GiftStatus = MFinanceConstants.MARKED_FOR_DELETION; } //Will always be previous row giftRowToReceive = giftRowCurrent; } FPreviouslySelectedDetailRow = null; FPetraUtilsObject.SetChangedFlag(); FGiftSelectedForDeletion = true; FBatchRow.LastGiftNumber--; } //Try to save changes if (((TFrmGiftBatch)this.ParentForm).SaveChangesManual()) { //Check if have deleted a reversing gift detail if (OriginatingDetailRef.Count > 0) { TRemote.MFinance.Gift.WebConnectors.ReversedGiftReset(FLedgerNumber, OriginatingDetailRef); } //Clear current batch's gift data and reload from server RefreshCurrentBatchGiftData(FBatchNumber, true); } else { throw new Exception("Unable to save after deleting a gift!"); } DeletionSuccessful = true; } catch (Exception ex) { //Revert to previous state RevertDataSet(FMainDS, BackupMainDS); TLogging.LogException(ex, Utilities.GetMethodSignature()); throw; } finally { FMainDS.EnforceConstraints = true; SetGiftDetailDefaultView(); FFilterAndFindObject.ApplyFilter(); this.Cursor = Cursors.Default; } UpdateRecordNumberDisplay(); return(DeletionSuccessful); }
/// <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)); } 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) { StringHelper.JoinAndAppend(ref workingFilter, String.Format("({0} = '{1}') AND ({2} <> 0) AND (({3} = 0) OR ({3} = {2}))", AGiftBatchTable.GetBatchStatusDBName(), MFinanceConstants.BATCH_UNPOSTED, 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; //TLogging.Log(String.Format("working filter: {0}", workingFilter)); }