private bool DeleteRowManual(GiftBatchTDSARecurringGiftDetailRow ARowToDelete, ref string ACompletionMessage) { bool DeletionSuccessful = false; ACompletionMessage = string.Empty; if (ARowToDelete == null) { return DeletionSuccessful; } bool RowToDeleteIsNew = (ARowToDelete.RowState == DataRowState.Added); if (!RowToDeleteIsNew) { try { // temporarily disable New Donor Warning ((TFrmRecurringGiftBatch) this.ParentForm).NewDonorWarning = false; //Return modified row to last saved state to avoid validation failures ARowToDelete.RejectChanges(); ShowDetails(ARowToDelete); if (!((TFrmRecurringGiftBatch) 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 { ((TFrmRecurringGiftBatch) 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; //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) { GiftBatchTDSARecurringGiftDetailRow row = (GiftBatchTDSARecurringGiftDetailRow)rv.Row; if (row.DetailNumber > SelectedDetailNumber) { row.DetailNumber--; } } FGift.LastDetailNumber--; FPetraUtilsObject.SetChangedFlag(); } else { GiftToDeleteTransNo = FGift.GiftTransactionNumber; TLogging.Log("Delete recurring 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}", ARecurringGiftDetailTable.GetBatchNumberDBName(), FBatchNumber, ARecurringGiftDetailTable.GetGiftTransactionNumberDBName(), GiftToDeleteTransNo); DataView giftDetailView = new DataView(FMainDS.ARecurringGiftDetail); giftDetailView.RowFilter = FilterAllGiftDetailsOfBatch; giftDetailView.Sort = String.Format("{0} ASC", ARecurringGiftDetailTable.GetGiftTransactionNumberDBName()); foreach (DataRowView rv in giftDetailView) { GiftBatchTDSARecurringGiftDetailRow row = (GiftBatchTDSARecurringGiftDetailRow)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}", ARecurringGiftTable.GetBatchNumberDBName(), FBatchNumber, ARecurringGiftTable.GetGiftTransactionNumberDBName(), GiftToDeleteTransNo); DataView giftView = new DataView(FMainDS.ARecurringGift); giftView.RowFilter = FilterAllGiftsOfBatch; giftView.Sort = String.Format("{0} ASC", ARecurringGiftTable.GetGiftTransactionNumberDBName()); ARecurringGiftRow giftRowToReceive = null; ARecurringGiftRow giftRowToCopyDown = null; ARecurringGiftRow giftRowCurrent = null; int currentGiftTransNo = 0; foreach (DataRowView gv in giftView) { giftRowCurrent = (ARecurringGiftRow)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.ChargeStatus = MFinanceConstants.MARKED_FOR_DELETION; } //Will always be previous row giftRowToReceive = giftRowCurrent; } FPreviouslySelectedDetailRow = null; FPetraUtilsObject.SetChangedFlag(); FGiftSelectedForDeletion = true; FBatchRow.LastGiftNumber--; } //Try to save changes if (((TFrmRecurringGiftBatch) this.ParentForm).SaveChangesManual()) { //Clear current batch's gift data and reload from server RefreshCurrentRecurringBatchGiftData(FBatchNumber); } else { throw new Exception("Unable to save after deleting a recurring gift!"); } ACompletionMessage = Catalog.GetString("Recurring 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(BackupMainDS); } finally { FMainDS.EnforceConstraints = true; SetGiftDetailDefaultView(); FFilterAndFindObject.ApplyFilter(); this.Cursor = Cursors.Default; } UpdateRecordNumberDisplay(); return DeletionSuccessful; }
private bool OnDeleteRowManual(GiftBatchTDSARecurringGiftDetailRow ARowToDelete, ref string ACompletionMessage) { //TODO: Make this like deleton on GL Transactions form // e.g. pass copy to delete method on server... //GiftBatchTDS TempDS = (GiftBatchTDS)FMainDS.Copy(); //TempDS.Merge(FMainDS); bool DeletionSuccessful = false; ACompletionMessage = string.Empty; if (FBatchRow == null) { FBatchRow = GetRecurringBatchRow(); } if (ARowToDelete == null) { return(false); } int CurrentBatchNo = ARowToDelete.BatchNumber; bool RowToDeleteIsNew = (ARowToDelete.RowState == DataRowState.Added); int CurrentRowIndex = GetSelectedRowIndex(); TFrmRecurringGiftBatch FMyForm = (TFrmRecurringGiftBatch)this.ParentForm; GiftBatchTDS BackupMainDS = null; int SelectedDetailNumber = ARowToDelete.DetailNumber; int RecurringGiftToDeleteTransNo = 0; string FilterAllRecurringGiftsOfBatch = String.Empty; string FilterAllRecurringGiftDetailsOfBatch = String.Empty; int DetailRowCount = FGiftDetailView.Count; try { this.Cursor = Cursors.WaitCursor; //Specify current action FMyForm.FCurrentGiftBatchAction = Logic.TExtraGiftBatchChecks.GiftBatchAction.DELETINGTRANS; //Speeds up deletion of larger gift sets FMainDS.EnforceConstraints = false; // temporarily disable New Donor Warning FMyForm.NewDonorWarning = false; //Backup the Dataset for reversion purposes BackupMainDS = (GiftBatchTDS)FMainDS.GetChangesTyped(false); //Don't run an inactive fields check on this batch FMyForm.GetBatchControl().UpdateRecurringBatchDictionary(CurrentBatchNo); //Delete current row ARowToDelete.RejectChanges(); if (!RowToDeleteIsNew) { ShowDetails(ARowToDelete); } ARowToDelete.Delete(); //If there existed (before the delete row above) more than one detail row, then no need to delete Recurring Gift header row if (DetailRowCount > 1) { ACompletionMessage = Catalog.GetString("Recurring Gift Detail row deleted successfully!"); FGiftSelectedForDeletionFlag = false; foreach (DataRowView rv in FGiftDetailView) { GiftBatchTDSARecurringGiftDetailRow row = (GiftBatchTDSARecurringGiftDetailRow)rv.Row; if (row.DetailNumber > SelectedDetailNumber) { row.DetailNumber--; } } FGift.LastDetailNumber--; } else { ACompletionMessage = Catalog.GetString("Recurring Gift deleted successfully!"); RecurringGiftToDeleteTransNo = FGift.GiftTransactionNumber; // Reduce all Recurring Gift Detail row Transaction numbers by 1 if they are greater then Recurring Gift to be deleted FilterAllRecurringGiftDetailsOfBatch = String.Format("{0}={1} And {2}>{3}", ARecurringGiftDetailTable.GetBatchNumberDBName(), FBatchNumber, ARecurringGiftDetailTable.GetGiftTransactionNumberDBName(), RecurringGiftToDeleteTransNo); DataView RecurringGiftDetailView = new DataView(FMainDS.ARecurringGiftDetail); RecurringGiftDetailView.RowFilter = FilterAllRecurringGiftDetailsOfBatch; RecurringGiftDetailView.Sort = String.Format("{0} ASC", ARecurringGiftDetailTable.GetGiftTransactionNumberDBName()); foreach (DataRowView rv in RecurringGiftDetailView) { GiftBatchTDSARecurringGiftDetailRow row = (GiftBatchTDSARecurringGiftDetailRow)rv.Row; row.GiftTransactionNumber--; } //Cannot delete the Recurring 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 Recurring Gift row to be deleted to the top FilterAllRecurringGiftsOfBatch = String.Format("{0}={1} And {2}>={3}", ARecurringGiftTable.GetBatchNumberDBName(), FBatchNumber, ARecurringGiftTable.GetGiftTransactionNumberDBName(), RecurringGiftToDeleteTransNo); DataView RecurringGiftView = new DataView(FMainDS.ARecurringGift); RecurringGiftView.RowFilter = FilterAllRecurringGiftsOfBatch; RecurringGiftView.Sort = String.Format("{0} ASC", ARecurringGiftTable.GetGiftTransactionNumberDBName()); ARecurringGiftRow RecurringGiftRowToReceive = null; ARecurringGiftRow RecurringGiftRowToCopyDown = null; ARecurringGiftRow RecurringGiftRowCurrent = null; int currentRecurringGiftTransNo = 0; foreach (DataRowView gv in RecurringGiftView) { RecurringGiftRowCurrent = (ARecurringGiftRow)gv.Row; currentRecurringGiftTransNo = RecurringGiftRowCurrent.GiftTransactionNumber; if (currentRecurringGiftTransNo > RecurringGiftToDeleteTransNo) { RecurringGiftRowToCopyDown = RecurringGiftRowCurrent; //Copy column values down for (int j = 3; j < RecurringGiftRowToCopyDown.Table.Columns.Count; j++) { //Update all columns except the pk fields that remain the same if (!RecurringGiftRowToCopyDown.Table.Columns[j].ColumnName.EndsWith("_text")) { RecurringGiftRowToReceive[j] = RecurringGiftRowToCopyDown[j]; } } } if (currentRecurringGiftTransNo == FBatchRow.LastGiftNumber) { //Mark last record for deletion RecurringGiftRowCurrent.ChargeStatus = MFinanceConstants.MARKED_FOR_DELETION; } //Will always be previous row RecurringGiftRowToReceive = RecurringGiftRowCurrent; } FPreviouslySelectedDetailRow = null; FGiftSelectedForDeletionFlag = true; FBatchRow.LastGiftNumber--; } //Save and check for inactive values and ex-workers and anonymous gifts // in other unsaved Batches FPetraUtilsObject.SetChangedFlag(); if (!FMyForm.SaveChangesManual(Logic.TExtraGiftBatchChecks.GiftBatchAction.DELETINGTRANS, false, false)) { FMyForm.GetBatchControl().UpdateRecurringBatchDictionary(); MessageBox.Show(Catalog.GetString("The gift detail has been deleted but the changes are not saved!"), Catalog.GetString("Deletion Warning"), MessageBoxButtons.OK, MessageBoxIcon.Warning); ACompletionMessage = string.Empty; if (FGiftSelectedForDeletionFlag) { FGiftSelectedForDeletionFlag = false; SetBatchLastGiftNumber(); UpdateControlsProtection(); } UpdateTotals(); return(false); } //Clear current batch's gift data and reload from server RefreshRecurringBatchGiftData(FBatchNumber, true); DeletionSuccessful = true; } catch (Exception ex) { //Revert to previous state RevertDataSet(FMainDS, BackupMainDS, CurrentRowIndex); TLogging.LogException(ex, Utilities.GetMethodSignature()); throw; } finally { FMyForm.NewDonorWarning = true; FMainDS.EnforceConstraints = true; FMyForm.FCurrentGiftBatchAction = Logic.TExtraGiftBatchChecks.GiftBatchAction.NONE; this.Cursor = Cursors.Default; } SetGiftDetailDefaultView(); FFilterAndFindObject.ApplyFilter(); UpdateRecordNumberDisplay(); return(DeletionSuccessful); }
private bool OnDeleteRowManual(GiftBatchTDSARecurringGiftDetailRow ARowToDelete, ref string ACompletionMessage) { bool DeletionSuccessful = false; ACompletionMessage = string.Empty; if (ARowToDelete == null) { return(DeletionSuccessful); } bool RowToDeleteIsNew = (ARowToDelete.RowState == DataRowState.Added); if (!RowToDeleteIsNew) { try { // temporarily disable New Donor Warning ((TFrmRecurringGiftBatch)this.ParentForm).NewDonorWarning = false; //Return modified row to last saved state to avoid validation failures ARowToDelete.RejectChanges(); ShowDetails(ARowToDelete); if (!((TFrmRecurringGiftBatch)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 { ((TFrmRecurringGiftBatch)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. //RecurringGiftBatchTDS TempDS = (RecurringGiftBatchTDS)FMainDS.Copy(); //TempDS.Merge(FMainDS); int SelectedDetailNumber = ARowToDelete.DetailNumber; int RecurringGiftToDeleteTransNo = 0; string FilterAllRecurringGiftsOfBatch = String.Empty; string FilterAllRecurringGiftDetailsOfBatch = String.Empty; int DetailRowCount = FGiftDetailView.Count; try { this.Cursor = Cursors.WaitCursor; //Speeds up deletion of larger Recurring Gift sets FMainDS.EnforceConstraints = false; //Delete current detail row ARowToDelete.Delete(); //If there existed (before the delete row above) more than one detail row, then no need to delete Recurring Gift header row if (DetailRowCount > 1) { ACompletionMessage = Catalog.GetString("Recurring Gift Detail row deleted successfully!"); FGiftSelectedForDeletion = false; foreach (DataRowView rv in FGiftDetailView) { GiftBatchTDSARecurringGiftDetailRow row = (GiftBatchTDSARecurringGiftDetailRow)rv.Row; if (row.DetailNumber > SelectedDetailNumber) { row.DetailNumber--; } } FGift.LastDetailNumber--; FPetraUtilsObject.SetChangedFlag(); } else { ACompletionMessage = Catalog.GetString("Recurring Gift deleted successfully!"); RecurringGiftToDeleteTransNo = FGift.GiftTransactionNumber; // Reduce all Recurring Gift Detail row Transaction numbers by 1 if they are greater then Recurring Gift to be deleted FilterAllRecurringGiftDetailsOfBatch = String.Format("{0}={1} And {2}>{3}", ARecurringGiftDetailTable.GetBatchNumberDBName(), FBatchNumber, ARecurringGiftDetailTable.GetGiftTransactionNumberDBName(), RecurringGiftToDeleteTransNo); DataView RecurringGiftDetailView = new DataView(FMainDS.ARecurringGiftDetail); RecurringGiftDetailView.RowFilter = FilterAllRecurringGiftDetailsOfBatch; RecurringGiftDetailView.Sort = String.Format("{0} ASC", ARecurringGiftDetailTable.GetGiftTransactionNumberDBName()); foreach (DataRowView rv in RecurringGiftDetailView) { GiftBatchTDSARecurringGiftDetailRow row = (GiftBatchTDSARecurringGiftDetailRow)rv.Row; row.GiftTransactionNumber--; } //Cannot delete the Recurring 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 Recurring Gift row to be deleted to the top FilterAllRecurringGiftsOfBatch = String.Format("{0}={1} And {2}>={3}", ARecurringGiftTable.GetBatchNumberDBName(), FBatchNumber, ARecurringGiftTable.GetGiftTransactionNumberDBName(), RecurringGiftToDeleteTransNo); DataView RecurringGiftView = new DataView(FMainDS.ARecurringGift); RecurringGiftView.RowFilter = FilterAllRecurringGiftsOfBatch; RecurringGiftView.Sort = String.Format("{0} ASC", ARecurringGiftTable.GetGiftTransactionNumberDBName()); ARecurringGiftRow RecurringGiftRowToReceive = null; ARecurringGiftRow RecurringGiftRowToCopyDown = null; ARecurringGiftRow RecurringGiftRowCurrent = null; int currentRecurringGiftTransNo = 0; foreach (DataRowView gv in RecurringGiftView) { RecurringGiftRowCurrent = (ARecurringGiftRow)gv.Row; currentRecurringGiftTransNo = RecurringGiftRowCurrent.GiftTransactionNumber; if (currentRecurringGiftTransNo > RecurringGiftToDeleteTransNo) { RecurringGiftRowToCopyDown = RecurringGiftRowCurrent; //Copy column values down for (int j = 3; j < RecurringGiftRowToCopyDown.Table.Columns.Count; j++) { //Update all columns except the pk fields that remain the same if (!RecurringGiftRowToCopyDown.Table.Columns[j].ColumnName.EndsWith("_text")) { RecurringGiftRowToReceive[j] = RecurringGiftRowToCopyDown[j]; } } } if (currentRecurringGiftTransNo == FBatchRow.LastGiftNumber) { //Mark last record for deletion RecurringGiftRowCurrent.ChargeStatus = MFinanceConstants.MARKED_FOR_DELETION; } //Will always be previous row RecurringGiftRowToReceive = RecurringGiftRowCurrent; } FPreviouslySelectedDetailRow = null; FPetraUtilsObject.SetChangedFlag(); FGiftSelectedForDeletion = true; FBatchRow.LastGiftNumber--; } //Try to save changes if (((TFrmRecurringGiftBatch)this.ParentForm).SaveChangesManual()) { //Clear current batch's Recurring Gift data and reload from server RefreshCurrentRecurringBatchGiftData(FBatchNumber, true); } else { throw new Exception("Unable to save after deleting a Recurring 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); }