private void CancelRow(System.Object sender, EventArgs e) { if (FPreviouslySelectedDetailRow == null) { MessageBox.Show(Catalog.GetString("Select the row to cancel first")); return; } TFrmGLBatch MainForm = (TFrmGLBatch)this.ParentForm; int CurrentlySelectedRow = grdDetails.GetFirstHighlightedRowIndex(); try { MainForm.FCurrentGLBatchAction = TGLBatchEnums.GLBatchAction.CANCELLINGJOURNAL; if (FCancelLogicObject.CancelRow(FPreviouslySelectedDetailRow)) { UpdateHeaderTotals(FBatchRow); SelectRowInGrid(CurrentlySelectedRow); UpdateRecordNumberDisplay(); SetJournalDefaultView(); FFilterAndFindObject.ApplyFilter(); UpdateChangeableStatus(); MainForm.DisableTransactions(); } } finally { MainForm.FCurrentGLBatchAction = TGLBatchEnums.GLBatchAction.NONE; } }
/// <summary> /// Will be called by TFormsList to inform any Form that is registered in TFormsList /// about any 'Forms Messages' that are broadcasted. /// </summary> /// <remarks>This screen 'listens' to such 'Forms Message' broadcasts by /// implementing this virtual Method. This Method will be called each time a /// 'Forms Message' broadcast occurs. /// </remarks> /// <param name="AFormsMessage">An instance of a 'Forms Message'. This can be /// inspected for parameters in the Method Body and the Form can use those to choose /// to react on the Message, or not.</param> /// <returns>Returns True if the Form reacted on the specific Forms Message, /// otherwise false.</returns> public bool ProcessFormsMessage(TFormsMessage AFormsMessage) { bool MessageProcessed = false; if (AFormsMessage.MessageClass == TFormsMessageClassEnum.mcAccountsChanged) { string CurrentlySelectedAccountCode = FPreviouslySelectedDetailRow.AccountCode; Type DataTableType; // Load Data DataTable CacheDT = TDataCache.GetSpecificallyFilteredCacheableDataTableFromCache("AccountList", "Ledger", FFilter, out DataTableType); FMainDS.AAccount.Merge(CacheDT); GetData(); // reapply filter FFilterAndFindObject.ApplyFilter(); // reselect the last selected account code if (FPreviouslySelectedDetailRow != null) { SelectAccountInGrid(CurrentlySelectedAccountCode); } UpdateRecordNumberDisplay(); MessageProcessed = true; } return(MessageProcessed); }
private void PostBatch(System.Object sender, EventArgs e) { //get index position of row to post int newCurrentRowPos = GetSelectedRowIndex(); if (FPostLogicObject.PostBatch(FPreviouslySelectedDetailRow, dtpDetailDateEffective.Date.Value, FStartDateCurrentPeriod, FEndDateLastForwardingPeriod)) { // AlanP - commenting out most of this because it should be unnecessary - or should move to ShowDetailsManual() ////Select unposted batch row in same index position as batch just posted //grdDetails.DataSource = null; //grdDetails.DataSource = new DevAge.ComponentModel.BoundDataView(FMainDS.ABatch.DefaultView); if (grdDetails.Rows.Count > 1) { //Needed because posting process forces grid events which sets FDetailGridRowsCountPrevious = FDetailGridRowsCountCurrent // such that a removal of a row is not detected SelectRowInGrid(newCurrentRowPos); } else { EnableButtonControl(false); ClearDetailControls(); btnNew.Focus(); pnlDetails.Enabled = false; } UpdateRecordNumberDisplay(); FFilterAndFindObject.SetRecordNumberDisplayProperties(); } }
/// <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> /// Specifies a new Filter and applies it, then selects the Row passed in with <paramref name="ACurrentRowIndex"/>. /// </summary> /// <param name="ANewCode">New Code to filter on.</param> /// <param name="ACurrentRowIndex">The index of the Row that should get displayed (the 'current' Row).</param> private void FilterOnCode(string ANewCode, int ACurrentRowIndex) { string FilterStr = String.Format("{0}='{1}'", PContactAttributeDetailTable.GetContactAttributeCodeDBName(), ANewCode); FFilterAndFindObject.FilterPanelControls.SetBaseFilter(FilterStr, true); FFilterAndFindObject.ApplyFilter(); grdDetails.SelectRowWithoutFocus(ACurrentRowIndex); }
/// <summary> /// Shows the Filter/Find UserControl and switches to the Find Tab. /// </summary> public void ShowFindPanel() { if (FFilterAndFindObject.FilterFindPanel == null) { FFilterAndFindObject.ToggleFilter(); } FFilterAndFindObject.FilterFindPanel.DisplayFindTab(); }
/// <summary> /// Method to collapse the filter panel if it is open /// </summary> public void CollapseFilterFind() { if (pnlFilterAndFind.Width > 0) { // Get the current row DataRow currentRow = FPreviouslySelectedDetailRow; FFilterAndFindObject.ToggleFilter(); FParentForm.SetSelectedCostCentreCode(currentRow.ItemArray[1].ToString()); } }
private void OnSettingsClassChange(object sender, EventArgs e) { // We get called here when the settings class combo has changed if ((FFilterAndFindObject == null) || (FSuppressClassChange == true)) { return; } if (sender != null) { // We don't do this at startup, but after that we need to set the class back to what it was before if validation fails if (!ValidateAllData(false, TErrorProcessingMode.Epm_All)) { FSuppressClassChange = true; ((TCmbAutoComplete)sender).SetSelectedString(FActiveClass); FSuppressClassChange = false; return; } FActiveClass = ((TCmbAutoComplete)sender).GetSelectedString(); } // We need to know if we are displaying a sysAdmin row or not string sysAdminRowFilter = "12345"; string rowFilter = string.Format("{0}>0 AND ", FControlsCountName); if (cmbClass.SelectedValue == null) { rowFilter += "1=0"; } else if (FLaunchedInSysAdminMode && (cmbClass.SelectedIndex == 0)) { sysAdminRowFilter = string.Format("{0}=0 OR {1} IS NULL", FControlsCountName, SSystemDefaultsTable.GetCategoryDBName()); rowFilter = sysAdminRowFilter; } else { rowFilter += string.Format("{0}='{1}'", SSystemDefaultsTable.GetCategoryDBName(), cmbClass.SelectedValue.ToString()); } FFilterAndFindObject.FilterPanelControls.SetBaseFilter(rowFilter, true); // Both these will cause validation to run, but it should be ok because we checked it above FFilterAndFindObject.ApplyFilter(); SelectRowInGrid(1); // Depending on how validation worked out we now know whether we are displaying the sysAdmin codes or not FShowingSysAdminCodes = FMainDS.SSystemDefaults.DefaultView.RowFilter.StartsWith(sysAdminRowFilter); // Now we can show/hide columns 0 and 1 grdDetails.Columns[0].Visible = FShowingSysAdminCodes; grdDetails.Columns[1].Visible = !FShowingSysAdminCodes; grdDetails.AutoResizeGrid(); }
private void PostBatch(System.Object sender, EventArgs e) { // Although the screen can be used with FINANCE-1, Posting requires FINANCE-2 TSecurityChecks.CheckUserModulePermissions("FINANCE-2", "PostBatch [raised by Client Proxy for ModuleAccessManager]"); if ((GetSelectedRowIndex() < 0) || (FPreviouslySelectedDetailRow == null)) { MessageBox.Show(Catalog.GetString("Please select a GL Batch before posting!")); return; } //get index position of row to post int NewCurrentRowPos = GetSelectedRowIndex(); TFrmGLBatch MainForm = (TFrmGLBatch)this.ParentForm; try { MainForm.FCurrentGLBatchAction = TGLBatchEnums.GLBatchAction.POSTING; if (FPostLogicObject.PostBatch(FPreviouslySelectedDetailRow, dtpDetailDateEffective.Date.Value, FStartDateCurrentPeriod, FEndDateLastForwardingPeriod)) { // AlanP - commenting out most of this because it should be unnecessary - or should move to ShowDetailsManual() ////Select unposted batch row in same index position as batch just posted //grdDetails.DataSource = null; //grdDetails.DataSource = new DevAge.ComponentModel.BoundDataView(FMainDS.ABatch.DefaultView); if (grdDetails.Rows.Count > 1) { //Needed because posting process forces grid events which sets FDetailGridRowsCountPrevious = FDetailGridRowsCountCurrent // such that a removal of a row is not detected SelectRowInGrid(NewCurrentRowPos); } else { EnableButtonControl(false); ClearDetailControls(); btnNew.Focus(); pnlDetails.Enabled = false; } UpdateRecordNumberDisplay(); FFilterAndFindObject.SetRecordNumberDisplayProperties(); } } finally { MainForm.FCurrentGLBatchAction = TGLBatchEnums.GLBatchAction.NONE; } }
private void CancelRow(System.Object sender, EventArgs e) { int CurrentJournalNumber = FPreviouslySelectedDetailRow.JournalNumber; if (FCancelLogicObject.CancelRow(FPreviouslySelectedDetailRow)) { UpdateHeaderTotals(FBatchRow); SetFocusToDetailsGrid(); } SetJournalDefaultView(); FFilterAndFindObject.ApplyFilter(); UpdateChangeableStatus(); ((TFrmGLBatch)ParentForm).DisableTransactions(); }
void chkHideOthers_CheckedChanged(object sender, EventArgs e) { string rowFilter = String.Empty; if (chkHideOthers.Checked) { rowFilter = String.Format("{0}='{1}'", ACorporateExchangeRateTable.GetToCurrencyCodeDBName(), cmbDetailToCurrencyCode.GetSelectedString()); } FFilterAndFindObject.FilterPanelControls.SetBaseFilter(rowFilter, !chkHideOthers.Checked); FFilterAndFindObject.ApplyFilter(); SelectRowInGrid(grdDetails.DataSourceRowToIndex2(FPreviouslySelectedDetailRow) + 1); SetEnabledStates(FPreviouslySelectedDetailRow.RowState == DataRowState.Added); }
/// <summary> /// Updates the data display. Call this after the DataSet has changed. /// </summary> public void UpdateDisplay() { TFrmGLBatch myParentForm = (TFrmGLBatch)ParentForm; Cursor prevCursor = myParentForm.Cursor; try { myParentForm.Cursor = Cursors.WaitCursor; // Remember our current row position int nCurrentRowIndex = GetSelectedRowIndex(); // This single call will fire the event that loads data and populates the grid FFilterAndFindObject.ApplyFilter(); // Did the start-up specify a batch to select? if (myParentForm.InitialBatchNumber > 0) { nCurrentRowIndex = 1; string filter = String.Format("{0}={1}", ABatchTable.GetBatchNumberDBName(), myParentForm.InitialBatchNumber); DataView dv = new DataView(FMainDS.ABatch, filter, "", DataViewRowState.CurrentRows); if (dv.Count > 0) { int rowToSelect = grdDetails.DataSourceRowToIndex2(dv[0].Row) + 1; if (rowToSelect > 0) { nCurrentRowIndex = rowToSelect; myParentForm.InitialBatchFound = true; } } // Reset the start-up value myParentForm.InitialBatchNumber = -1; } // Now we can select the row index we had before (if it exists) SelectRowInGrid(nCurrentRowIndex); UpdateRecordNumberDisplay(); } finally { myParentForm.Cursor = prevCursor; } }
/// <summary> /// Updates the data display. Call this after the DataSet has changed. /// </summary> public void UpdateDisplay() { Cursor prevCursor = ParentForm.Cursor; try { ParentForm.Cursor = Cursors.WaitCursor; // Remember our current row position int nCurrentRowIndex = GetSelectedRowIndex(); // This single call will fire the event that loads data and populates the grid FFilterAndFindObject.ApplyFilter(); // Now we can select the row index we had before (if it exists) SelectRowInGrid(nCurrentRowIndex); UpdateRecordNumberDisplay(); } finally { ParentForm.Cursor = prevCursor; } }
private void RefreshGridData(int ABatchNumber, bool ANoFocusChange, bool ASelectOnly = false) { //string RowFilter = string.Empty; if (!ASelectOnly) { //RowFilter = String.Format("({0}) AND ({1})", FPeriodFilter, FStatusFilter); //// AlanP: review this //FFilterAndFindObject.FilterPanelControls.SetBaseFilter(RowFilter, (FSelectedPeriod == -1) // && (FCurrentBatchViewOption == MFinanceConstants.GL_BATCH_VIEW_ALL)); FFilterAndFindObject.ApplyFilter(); } if (grdDetails.Rows.Count < 2) { ShowDetails(null); ((TFrmGLBatch)this.ParentForm).DisableJournals(); ((TFrmGLBatch)this.ParentForm).DisableTransactions(); } else if (FBatchesLoaded == true) { //Select same row after refilter int newRowToSelectAfterFilter = (ABatchNumber > 0) ? GetDataTableRowIndexByPrimaryKeys(FLedgerNumber, ABatchNumber) : FPrevRowChangedRow; if (ANoFocusChange) { SelectRowInGrid(newRowToSelectAfterFilter); //grdDetails.SelectRowWithoutFocus(newRowToSelectAfterFilter); } else { SelectRowInGrid(newRowToSelectAfterFilter); } } }
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> /// 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(GLBatchTDSARecurringJournalRow ARowToDelete, ref string ACompletionMessage) { //Assign default value(s) bool DeletionSuccessful = false; ACompletionMessage = string.Empty; if (ARowToDelete == null) { return(DeletionSuccessful); } bool RowToDeleteIsNew = (ARowToDelete.RowState == DataRowState.Added); if (!RowToDeleteIsNew) { //Reject any changes which may fail validation ARowToDelete.RejectChanges(); ShowDetails(ARowToDelete); if (!((TFrmRecurringGLBatch)this.ParentForm).SaveChanges()) { MessageBox.Show(Catalog.GetString("Error in trying to save prior to deleting current recurring journal!"), Catalog.GetString("Deletion Error"), MessageBoxButtons.OK, MessageBoxIcon.Error); return(DeletionSuccessful); } } //Backup the Dataset for reversion purposes GLBatchTDS BackupMainDS = (GLBatchTDS)FMainDS.Copy(); BackupMainDS.Merge(FMainDS); //Pass copy to delete method. GLBatchTDS TempDS = (GLBatchTDS)FMainDS.Copy(); TempDS.Merge(FMainDS); FJournalNumberToDelete = ARowToDelete.JournalNumber; int TopMostJrnlNo = FBatchRow.LastJournal; try { this.Cursor = Cursors.WaitCursor; //clear any transactions currently being editied in the Transaction Tab ((TFrmRecurringGLBatch)ParentForm).GetTransactionsControl().ClearCurrentSelection(); if (RowToDeleteIsNew) { ProcessNewlyAddedJournalRowForDeletion(FJournalNumberToDelete); } else { //Load all journals for this batch TempDS.Merge(TRemote.MFinance.GL.WebConnectors.LoadARecurringJournalAndContent(FLedgerNumber, FBatchNumber)); TempDS.AcceptChanges(); //Clear the transactions and load newly saved dataset FMainDS.ARecurringTransAnalAttrib.Clear(); FMainDS.ARecurringTransaction.Clear(); FMainDS.ARecurringJournal.Clear(); FMainDS.Merge(TRemote.MFinance.GL.WebConnectors.ProcessRecurrJrnlTransAttribForDeletion(TempDS, FLedgerNumber, FBatchNumber, TopMostJrnlNo, FJournalNumberToDelete)); } FPreviouslySelectedDetailRow = null; FPetraUtilsObject.SetChangedFlag(); ACompletionMessage = String.Format(Catalog.GetString("Recurring Journal no.: {0} deleted successfully."), FJournalNumberToDelete); DeletionSuccessful = true; } catch (Exception ex) { ACompletionMessage = ex.Message; MessageBox.Show(ex.Message, "Deletion Error", MessageBoxButtons.OK, MessageBoxIcon.Error); //Revert to previous state FMainDS.Merge(BackupMainDS); } finally { SetJournalDefaultView(); FFilterAndFindObject.ApplyFilter(); this.Cursor = Cursors.Default; } return(DeletionSuccessful); }
/// <summary> /// load the journals into the grid /// </summary> /// <param name="ALedgerNumber"></param> /// <param name="ABatchNumber"></param> public void LoadJournals(Int32 ALedgerNumber, Int32 ABatchNumber) { bool FirstRun = (FLedgerNumber != ALedgerNumber); bool BatchChanged = (FBatchNumber != ABatchNumber); FJournalsLoaded = false; FBatchRow = GetBatchRow(); if (FBatchRow == null) { return; } //Check if same Journals as previously selected if (!FirstRun && !BatchChanged) { if (GetSelectedRowIndex() > 0) { GetDetailsFromControls(GetSelectedDetailRow()); } } else { // a different journal FLedgerNumber = ALedgerNumber; FBatchNumber = ABatchNumber; SetJournalDefaultView(); FPreviouslySelectedDetailRow = null; if (FMainDS.ARecurringJournal.DefaultView.Count == 0) { FMainDS.Merge(TRemote.MFinance.GL.WebConnectors.LoadARecurringJournalAndContent(ALedgerNumber, ABatchNumber)); } ShowData(); // Now set up the complete current filter FFilterAndFindObject.ApplyFilter(); } //Check for incorrect Exchange rate to base foreach (DataRowView drv in FMainDS.ARecurringJournal.DefaultView) { ARecurringJournalRow rjr = (ARecurringJournalRow)drv.Row; if (rjr.ExchangeRateToBase == 0) { rjr.ExchangeRateToBase = 1; FPetraUtilsObject.HasChanges = true; } } FJournalsLoaded = true; //This will also call UpdateChangeableStatus SelectRowInGrid((BatchChanged || FirstRun) ? 1 : FPrevRowChangedRow); UpdateRecordNumberDisplay(); FFilterAndFindObject.SetRecordNumberDisplayProperties(); }
/// <summary> /// Creates a new gift or gift detail depending upon the parameter /// </summary> /// <param name="ACompletelyNewGift"></param> private void CreateANewGift(bool ACompletelyNewGift) { AGiftRow CurrentGiftRow = null; bool IsEmptyGrid = (grdDetails.Rows.Count == 1); bool HasChanges = FPetraUtilsObject.HasChanges; bool SelectEndRow = false; bool FPrevRowIsNull = (FPreviouslySelectedDetailRow == null); bool CopyDetails = false; bool AutoSaveSuccessful = FAutoSave && HasChanges && ((TFrmGiftBatch)ParentForm).SaveChangesManual(); FCreatingNewGift = true; try { //May need to copy values down if a new detail row inside current gift int giftTransactionNumber = 0; string donorName = string.Empty; string donorClass = string.Empty; bool confidentialGiftFlag = false; bool chargeFlag = false; bool taxDeductible = false; string motivationGroupCode = string.Empty; string motivationDetailCode = string.Empty; if (AutoSaveSuccessful || ((!FAutoSave || !HasChanges) && ValidateAllData(true, TErrorProcessingMode.Epm_IgnoreNonCritical))) { if (!ACompletelyNewGift) //i.e. a gift detail { ACompletelyNewGift = IsEmptyGrid; } CopyDetails = (!ACompletelyNewGift && !FPrevRowIsNull); if (CopyDetails) { //Allow for possibility that FPrev... may have some null column values giftTransactionNumber = FPreviouslySelectedDetailRow.GiftTransactionNumber; donorName = FPreviouslySelectedDetailRow.IsDonorNameNull() ? string.Empty : FPreviouslySelectedDetailRow.DonorName; donorClass = FPreviouslySelectedDetailRow.IsDonorClassNull() ? string.Empty : FPreviouslySelectedDetailRow.DonorClass; confidentialGiftFlag = FPreviouslySelectedDetailRow.IsConfidentialGiftFlagNull() ? false : FPreviouslySelectedDetailRow.ConfidentialGiftFlag; chargeFlag = FPreviouslySelectedDetailRow.IsChargeFlagNull() ? true : FPreviouslySelectedDetailRow.ChargeFlag; taxDeductible = FPreviouslySelectedDetailRow.IsTaxDeductibleNull() ? true : FPreviouslySelectedDetailRow.TaxDeductible; motivationGroupCode = FPreviouslySelectedDetailRow.IsMotivationGroupCodeNull() ? string.Empty : FPreviouslySelectedDetailRow. MotivationGroupCode; motivationDetailCode = FPreviouslySelectedDetailRow.IsMotivationDetailCodeNull() ? string.Empty : FPreviouslySelectedDetailRow. MotivationDetailCode; } //Set previous row to Null. FPreviouslySelectedDetailRow = null; if (ACompletelyNewGift) { //Run this if a new gift is requested or required. SelectEndRow = true; // we create the row locally, no dataset AGiftRow giftRow = FMainDS.AGift.NewRowTyped(true); giftRow.LedgerNumber = FBatchRow.LedgerNumber; giftRow.BatchNumber = FBatchRow.BatchNumber; giftRow.GiftTransactionNumber = ++FBatchRow.LastGiftNumber; giftRow.MethodOfPaymentCode = FBatchRow.MethodOfPaymentCode; giftRow.LastDetailNumber = 1; giftRow.DateEntered = FBatchRow.GlEffectiveDate; FMainDS.AGift.Rows.Add(giftRow); CurrentGiftRow = giftRow; mniDonorHistory.Enabled = false; //Reset textboxes to zero txtGiftTotal.NumberValueDecimal = 0; } else { CurrentGiftRow = GetGiftRow(giftTransactionNumber); CurrentGiftRow.LastDetailNumber++; //If adding detail to current last gift, then new detail will be bottom row in grid if (FBatchRow.LastGiftNumber == giftTransactionNumber) { SelectEndRow = true; } } //New gifts will require a new detail anyway, so this code always runs GiftBatchTDSAGiftDetailRow newRow = FMainDS.AGiftDetail.NewRowTyped(true); newRow.LedgerNumber = FBatchRow.LedgerNumber; newRow.BatchNumber = FBatchRow.BatchNumber; newRow.GiftTransactionNumber = CurrentGiftRow.GiftTransactionNumber; newRow.DetailNumber = CurrentGiftRow.LastDetailNumber; newRow.MethodOfPaymentCode = CurrentGiftRow.MethodOfPaymentCode; newRow.MethodOfGivingCode = CurrentGiftRow.MethodOfGivingCode; newRow.DonorKey = CurrentGiftRow.DonorKey; if (CopyDetails) { newRow.DonorName = donorName; newRow.DonorClass = donorClass; newRow.ConfidentialGiftFlag = confidentialGiftFlag; newRow.ChargeFlag = chargeFlag; newRow.TaxDeductible = taxDeductible; newRow.MotivationGroupCode = motivationGroupCode; newRow.MotivationDetailCode = motivationDetailCode; // set the auto-populate comment if needed AMotivationDetailRow motivationDetail = (AMotivationDetailRow)FMainDS.AMotivationDetail.Rows.Find( new object[] { FLedgerNumber, newRow.MotivationGroupCode, newRow.MotivationDetailCode }); if ((motivationDetail != null) && motivationDetail.Autopopdesc) { newRow.GiftCommentOne = motivationDetail.MotivationDetailDesc; } } else { newRow.MotivationGroupCode = MFinanceConstants.MOTIVATION_GROUP_GIFT; newRow.MotivationDetailCode = MFinanceConstants.GROUP_DETAIL_SUPPORT; } newRow.DateEntered = CurrentGiftRow.DateEntered; newRow.ReceiptPrinted = false; newRow.ReceiptNumber = 0; if (FTaxDeductiblePercentageEnabled) { newRow.TaxDeductiblePct = newRow.TaxDeductible ? 100.0m : 0.0m; //Set unbound textboxes to 0 txtTaxDeductAmount.NumberValueDecimal = 0.0m; txtNonDeductAmount.NumberValueDecimal = 0.0m; } FMainDS.AGiftDetail.Rows.Add(newRow); FPetraUtilsObject.SetChangedFlag(); if (!SelectEndRow && !SelectDetailRowByDataTableIndex(FMainDS.AGiftDetail.Rows.Count - 1)) { if (!FFilterAndFindObject.IsActiveFilterEqualToBase) { MessageBox.Show( MCommonResourcestrings.StrNewRecordIsFiltered, MCommonResourcestrings.StrAddNewRecordTitle, MessageBoxButtons.OK, MessageBoxIcon.Information); FFilterAndFindObject.FilterPanelControls.ClearAllDiscretionaryFilters(); if (FFilterAndFindObject.FilterFindPanel.ShowApplyFilterButton != TUcoFilterAndFind.FilterContext.None) { FFilterAndFindObject.ApplyFilter(); } SelectDetailRowByDataTableIndex(FMainDS.AGiftDetail.Rows.Count - 1); } } btnDeleteAll.Enabled = btnDelete.Enabled; UpdateRecordNumberDisplay(); FLastDonor = -1; //Select end row if (SelectEndRow) { grdDetails.SelectRowInGrid(grdDetails.Rows.Count - 1); } //Focus accordingly if (ACompletelyNewGift) { txtDetailDonorKey.Focus(); } else { txtDetailRecipientKey.Focus(); } //FPreviouslySelectedDetailRow should now be pointing to the newly added row TUC_GiftTransactions_Recipient.UpdateRecipientKeyText(0, FPreviouslySelectedDetailRow, cmbDetailMotivationGroupCode.GetSelectedString(), cmbDetailMotivationDetailCode.GetSelectedString()); cmbKeyMinistries.Clear(); mniRecipientHistory.Enabled = false; } } finally { FCreatingNewGift = false; if (AutoSaveSuccessful) { FPetraUtilsObject.WriteToStatusBar(MCommonResourcestrings.StrSavingDataSuccessful); } } }
/// <summary> /// load the journals into the grid /// </summary> /// <param name="ACurrentBatchRow"></param> public void LoadJournals(ABatchRow ACurrentBatchRow) { FJournalsLoaded = false; FBatchRow = ACurrentBatchRow; if (FBatchRow == null) { return; } Int32 CurrentLedgerNumber = FBatchRow.LedgerNumber; Int32 CurrentBatchNumber = FBatchRow.BatchNumber; string CurrentBatchStatus = FBatchRow.BatchStatus; bool BatchIsUnposted = (FBatchRow.BatchStatus == MFinanceConstants.BATCH_UNPOSTED); bool FirstRun = (FLedgerNumber != CurrentLedgerNumber); bool BatchChanged = (FBatchNumber != CurrentBatchNumber); bool BatchStatusChanged = (!BatchChanged && (FBatchStatus != CurrentBatchStatus)); if (FirstRun) { FLedgerNumber = CurrentLedgerNumber; } if (BatchChanged) { FBatchNumber = CurrentBatchNumber; } if (BatchStatusChanged) { FBatchStatus = CurrentBatchStatus; } //Create object to control deletion FCancelLogicObject = new TUC_GLJournals_Cancel(FPetraUtilsObject, FLedgerNumber, FMainDS); //Make sure the current effective date for the Batch is correct DateTime BatchDateEffective = FBatchRow.DateEffective; //Check if need to load Journals if (!(FirstRun || BatchChanged || BatchStatusChanged)) { //Need to reconnect FPrev in some circumstances if (FPreviouslySelectedDetailRow == null) { DataRowView rowView = (DataRowView)grdDetails.Rows.IndexToDataSourceRow(FPrevRowChangedRow); if (rowView != null) { FPreviouslySelectedDetailRow = (GLBatchTDSAJournalRow)(rowView.Row); } } // The journals are the same and we have loaded them already if (BatchIsUnposted) { if (GetSelectedRowIndex() > 0) { GetDetailsFromControls(GetSelectedDetailRow()); } } } else { // a different journal SetJournalDefaultView(); FPreviouslySelectedDetailRow = null; //Load Journals if (FMainDS.AJournal.DefaultView.Count == 0) { FMainDS.Merge(TRemote.MFinance.GL.WebConnectors.LoadAJournal(FLedgerNumber, FBatchNumber)); } if (BatchIsUnposted) { if (!dtpDetailDateEffective.Date.HasValue || (dtpDetailDateEffective.Date.Value != BatchDateEffective)) { dtpDetailDateEffective.Date = BatchDateEffective; } } //Check if DateEffective has changed and then update all foreach (DataRowView drv in FMainDS.AJournal.DefaultView) { AJournalRow jr = (AJournalRow)drv.Row; if (jr.DateEffective != BatchDateEffective) { ((TFrmGLBatch)ParentForm).GetTransactionsControl().UpdateTransactionTotals(TGLBatchEnums.eGLLevel.Batch, true); break; } } ShowData(); // Now set up the complete current filter FFilterAndFindObject.FilterPanelControls.SetBaseFilter(FMainDS.AJournal.DefaultView.RowFilter, true); FFilterAndFindObject.ApplyFilter(); } int nRowToSelect = 1; TFrmGLBatch myParentForm = (TFrmGLBatch)ParentForm; if (myParentForm.InitialBatchFound) { DataView myView = (grdDetails.DataSource as DevAge.ComponentModel.BoundDataView).DataView; for (int counter = 0; (counter < myView.Count); counter++) { int myViewJournalNumber = (int)myView[counter][AJournalTable.GetJournalNumberDBName()]; if (myViewJournalNumber == myParentForm.InitialJournalNumber) { nRowToSelect = counter + 1; break; } } } else { nRowToSelect = (BatchChanged || FirstRun) ? 1 : FPrevRowChangedRow; } //This will also call UpdateChangeableStatus SelectRowInGrid(nRowToSelect); UpdateRecordNumberDisplay(); FFilterAndFindObject.SetRecordNumberDisplayProperties(); txtControl.CurrencyCode = TTxtCurrencyTextBox.CURRENCY_STANDARD_2_DP; txtCredit.CurrencyCode = FLedgerBaseCurrency; txtDebit.CurrencyCode = FLedgerBaseCurrency; FJournalsLoaded = true; }
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> /// load the journals into the grid /// </summary> /// <param name="ALedgerNumber"></param> /// <param name="ABatchNumber"></param> /// <param name="ABatchStatus"></param> public void LoadJournals(Int32 ALedgerNumber, Int32 ABatchNumber, string ABatchStatus = MFinanceConstants.BATCH_UNPOSTED) { FJournalsLoaded = false; FBatchRow = GetBatchRow(); if (FBatchRow == null) { return; } FCancelLogicObject = new TUC_GLJournals_Cancel(FPetraUtilsObject, FLedgerNumber, FMainDS); //Make sure the current effective date for the Batch is correct DateTime BatchDateEffective = FBatchRow.DateEffective; bool FirstRun = (FLedgerNumber != ALedgerNumber); bool BatchChanged = (FBatchNumber != ABatchNumber); bool BatchStatusChanged = (!BatchChanged && FBatchStatus != ABatchStatus); //Check if need to load Journals if (FirstRun || BatchChanged || BatchStatusChanged) { FLedgerNumber = ALedgerNumber; FBatchNumber = ABatchNumber; FBatchStatus = ABatchStatus; SetJournalDefaultView(); FPreviouslySelectedDetailRow = null; //Load Journals if (FMainDS.AJournal.DefaultView.Count == 0) { FMainDS.Merge(TRemote.MFinance.GL.WebConnectors.LoadAJournalAndContent(FLedgerNumber, FBatchNumber)); } if (FBatchStatus == MFinanceConstants.BATCH_UNPOSTED) { if (!dtpDetailDateEffective.Date.HasValue || (dtpDetailDateEffective.Date.Value != BatchDateEffective)) { dtpDetailDateEffective.Date = BatchDateEffective; } } foreach (DataRowView drv in FMainDS.AJournal.DefaultView) { AJournalRow jr = (AJournalRow)drv.Row; if (jr.DateEffective != BatchDateEffective) { ((TFrmGLBatch)ParentForm).GetTransactionsControl().UpdateTransactionTotals("BATCH", true); break; } } ShowData(); // Now set up the complete current filter FFilterAndFindObject.FilterPanelControls.SetBaseFilter(FMainDS.AJournal.DefaultView.RowFilter, true); FFilterAndFindObject.ApplyFilter(); } else { // The journals are the same and we have loaded them already if (FBatchRow.BatchStatus == MFinanceConstants.BATCH_UNPOSTED) { if (GetSelectedRowIndex() > 0) { GetDetailsFromControls(GetSelectedDetailRow()); } } } //This will also call UpdateChangeableStatus SelectRowInGrid((BatchChanged || FirstRun) ? 1 : FPrevRowChangedRow); UpdateRecordNumberDisplay(); FFilterAndFindObject.SetRecordNumberDisplayProperties(); FJournalsLoaded = true; }
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(); }
/// <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(GLBatchTDSARecurringJournalRow ARowToDelete, ref string ACompletionMessage) { //Assign default value(s) bool DeletionSuccessful = false; ACompletionMessage = string.Empty; if (ARowToDelete == null) { return(DeletionSuccessful); } //Delete current row ARowToDelete.RejectChanges(); ShowDetails(ARowToDelete); //Take a backup of FMainDS GLBatchTDS BackupMainDS = null; //Pass a copy of FMainDS to the server-side delete method. GLBatchTDS TempDS = (GLBatchTDS)FMainDS.Copy(); TempDS.Merge(FMainDS); int CurrentBatchNumber = ARowToDelete.BatchNumber; bool CurrentBatchJournalTransactionsLoadedAndCurrent = false; FJournalNumberToDelete = ARowToDelete.JournalNumber; int TopMostJrnlNo = FBatchRow.LastJournal; TFrmRecurringGLBatch FMyForm = (TFrmRecurringGLBatch)this.ParentForm; try { this.Cursor = Cursors.WaitCursor; FMyForm.FCurrentGLBatchAction = TGLBatchEnums.GLBatchAction.DELETINGJOURNAL; //Backup the Dataset for reversion purposes BackupMainDS = (GLBatchTDS)FMainDS.GetChangesTyped(false); //Check if current batch transactions are loaded and being viewed in their tab CurrentBatchJournalTransactionsLoadedAndCurrent = (FMyForm.GetTransactionsControl().FBatchNumber == CurrentBatchNumber && FMyForm.GetTransactionsControl().FJournalNumber == FJournalNumberToDelete); //Save and check for inactive values FPetraUtilsObject.SetChangedFlag(); if (!FMyForm.SaveChangesManual(FMyForm.FCurrentGLBatchAction, false, !CurrentBatchJournalTransactionsLoadedAndCurrent)) { string msg = String.Format(Catalog.GetString("Recurring Journal {0} has not been deleted."), FJournalNumberToDelete); MessageBox.Show(msg, Catalog.GetString("Recurring GL Batch Deletion"), MessageBoxButtons.OK, MessageBoxIcon.Information); return(false); } //Remove any changes to current batch that may cause validation issues PrepareJournalDataForDeleting(CurrentBatchNumber, FJournalNumberToDelete, true); if (CurrentBatchJournalTransactionsLoadedAndCurrent) { //Clear any transactions currently being edited in the Transaction Tab FMyForm.GetTransactionsControl().ClearCurrentSelection(CurrentBatchNumber, FJournalNumberToDelete); } //Load all journals for this batch TempDS.Merge(TRemote.MFinance.GL.WebConnectors.LoadARecurringJournalAndRelatedTablesForBatch(FLedgerNumber, FBatchNumber)); TempDS.AcceptChanges(); //Clear the transactions and load newly saved dataset FMainDS.ARecurringTransAnalAttrib.Clear(); FMainDS.ARecurringTransaction.Clear(); FMainDS.ARecurringJournal.Clear(); FMainDS.Merge(TRemote.MFinance.GL.WebConnectors.ProcessRecurrJrnlTransAttribForDeletion(TempDS, FLedgerNumber, FBatchNumber, TopMostJrnlNo, FJournalNumberToDelete)); FPreviouslySelectedDetailRow = null; FPetraUtilsObject.SetChangedFlag(); ACompletionMessage = String.Format(Catalog.GetString("Recurring Journal no.: {0} deleted successfully."), FJournalNumberToDelete); DeletionSuccessful = true; } catch (Exception ex) { //Normally set in PostDeleteManual FMyForm.FCurrentGLBatchAction = TGLBatchEnums.GLBatchAction.NONE; //Revert to previous state RevertDataSet(FMainDS, BackupMainDS); TLogging.LogException(ex, Utilities.GetMethodSignature()); throw; } finally { SetJournalDefaultView(); FFilterAndFindObject.ApplyFilter(); this.Cursor = Cursors.Default; } return(DeletionSuccessful); }
/// <summary> /// Creates a new Recurring Gift or Recurring Gift detail depending upon the parameter /// </summary> /// <param name="ACompletelyNewRecurringGift"></param> private void CreateANewRecurringGift(bool ACompletelyNewRecurringGift) { // Using a button's keyboard shortcut results in a different sequence of Events from clicking it with the mouse. If the current control is in pnlDetails, // then when the New or Delete button's processing attempts to save the current record and calls TFrmPetraUtils.ForceOnLeaveForActiveControl(), // it inadvertently re-raises the pnlDetails.Enter event which activates BeginEditMode() at a point when it's not supposed to be activated, putting // TCmbAutoComplete controls in a state they're not supposed to be in, resulting in a NullReferenceException from FPreviouslySelectedDetailRow // in UC_RecurringGiftTransactions.Motivation.ManualCode.cs, MotivationDetailChanged(). // To fix it, put the focus outside pnlDetails, preventing the whole chain of events from happening. grdDetails.Focus(); ARecurringGiftRow CurrentRecurringGiftRow = null; bool IsEmptyGrid = (grdDetails.Rows.Count == 1); bool HasChanges = FPetraUtilsObject.HasChanges; bool SelectEndRow = false; bool FPrevRowIsNull = (FPreviouslySelectedDetailRow == null); bool CopyDetails = false; bool AutoSaveSuccessful = FSETAutoSaveFlag && HasChanges && ((TFrmRecurringGiftBatch)ParentForm).SaveChangesManual(); FNewGiftInProcess = true; try { //May need to copy values down if a new detail row inside current Recurring Gift int recurringGiftTransactionNumber = 0; string donorName = string.Empty; string donorClass = string.Empty; bool confidentialRecurringGiftFlag = false; bool chargeFlag = false; bool taxDeductible = false; string motivationGroupCode = string.Empty; string motivationDetailCode = string.Empty; if (AutoSaveSuccessful || ((!FSETAutoSaveFlag || !HasChanges) && ValidateAllData(true, TErrorProcessingMode.Epm_IgnoreNonCritical))) { if (!ACompletelyNewRecurringGift) //i.e. a RecurringGift detail { ACompletelyNewRecurringGift = IsEmptyGrid; } CopyDetails = (!ACompletelyNewRecurringGift && !FPrevRowIsNull); if (CopyDetails) { //Allow for possibility that FPrev... may have some null column values recurringGiftTransactionNumber = FPreviouslySelectedDetailRow.GiftTransactionNumber; donorName = FPreviouslySelectedDetailRow.IsDonorNameNull() ? string.Empty : FPreviouslySelectedDetailRow.DonorName; donorClass = FPreviouslySelectedDetailRow.IsDonorClassNull() ? string.Empty : FPreviouslySelectedDetailRow.DonorClass; confidentialRecurringGiftFlag = FPreviouslySelectedDetailRow.IsConfidentialGiftFlagNull() ? false : FPreviouslySelectedDetailRow.ConfidentialGiftFlag; chargeFlag = FPreviouslySelectedDetailRow.IsChargeFlagNull() ? true : FPreviouslySelectedDetailRow.ChargeFlag; taxDeductible = FPreviouslySelectedDetailRow.IsTaxDeductibleNull() ? true : FPreviouslySelectedDetailRow.TaxDeductible; motivationGroupCode = FPreviouslySelectedDetailRow.IsMotivationGroupCodeNull() ? string.Empty : FPreviouslySelectedDetailRow. MotivationGroupCode; motivationDetailCode = FPreviouslySelectedDetailRow.IsMotivationDetailCodeNull() ? string.Empty : FPreviouslySelectedDetailRow. MotivationDetailCode; } //Set previous row to Null. FPreviouslySelectedDetailRow = null; if (ACompletelyNewRecurringGift) { //Run this if a new Recurring Gift is requested or required. SelectEndRow = true; // we create the row locally, no dataset ARecurringGiftRow recurringGiftRow = FMainDS.ARecurringGift.NewRowTyped(true); recurringGiftRow.LedgerNumber = FBatchRow.LedgerNumber; recurringGiftRow.BatchNumber = FBatchRow.BatchNumber; recurringGiftRow.GiftTransactionNumber = ++FBatchRow.LastGiftNumber; recurringGiftRow.MethodOfPaymentCode = FBatchRow.MethodOfPaymentCode; recurringGiftRow.Active = true; recurringGiftRow.LastDetailNumber = 1; FMainDS.ARecurringGift.Rows.Add(recurringGiftRow); CurrentRecurringGiftRow = recurringGiftRow; mniDonorHistory.Enabled = false; //Reset textboxes to zero txtGiftTotal.NumberValueDecimal = 0; } else { CurrentRecurringGiftRow = GetRecurringGiftRow(recurringGiftTransactionNumber); CurrentRecurringGiftRow.LastDetailNumber++; //If adding detail to current last Recurring Gift, then new detail will be bottom row in grid if (FBatchRow.LastGiftNumber == recurringGiftTransactionNumber) { SelectEndRow = true; } } //New Recurring Gifts will require a new detail anyway, so this code always runs GiftBatchTDSARecurringGiftDetailRow newRow = FMainDS.ARecurringGiftDetail.NewRowTyped(true); newRow.LedgerNumber = FBatchRow.LedgerNumber; newRow.BatchNumber = FBatchRow.BatchNumber; newRow.GiftTransactionNumber = CurrentRecurringGiftRow.GiftTransactionNumber; newRow.DetailNumber = CurrentRecurringGiftRow.LastDetailNumber; newRow.DonorKey = CurrentRecurringGiftRow.DonorKey; newRow.Active = CurrentRecurringGiftRow.Active; newRow.MethodOfPaymentCode = CurrentRecurringGiftRow.MethodOfPaymentCode; newRow.MethodOfGivingCode = CurrentRecurringGiftRow.MethodOfGivingCode; newRow.DateEntered = DateTime.Now; if (CopyDetails) { newRow.DonorName = donorName; newRow.DonorClass = donorClass; newRow.ConfidentialGiftFlag = confidentialRecurringGiftFlag; newRow.ChargeFlag = chargeFlag; newRow.TaxDeductible = taxDeductible; newRow.MotivationGroupCode = motivationGroupCode; newRow.MotivationDetailCode = motivationDetailCode; // set the auto-populate comment if needed AMotivationDetailRow motivationDetail = (AMotivationDetailRow)FMainDS.AMotivationDetail.Rows.Find( new object[] { FLedgerNumber, newRow.MotivationGroupCode, newRow.MotivationDetailCode }); if ((motivationDetail != null) && motivationDetail.Autopopdesc) { newRow.GiftCommentOne = motivationDetail.MotivationDetailDesc; } } else { newRow.MotivationGroupCode = MFinanceConstants.MOTIVATION_GROUP_GIFT; newRow.MotivationDetailCode = MFinanceConstants.GROUP_DETAIL_SUPPORT; } cmbMotivationDetailCode.SetSelectedString(newRow.MotivationDetailCode, -1); txtDetailMotivationDetailCode.Text = newRow.MotivationDetailCode; FMainDS.ARecurringGiftDetail.Rows.Add(newRow); FPetraUtilsObject.SetChangedFlag(); if (!SelectEndRow && !SelectDetailRowByDataTableIndex(FMainDS.ARecurringGiftDetail.Rows.Count - 1)) { if (!FFilterAndFindObject.IsActiveFilterEqualToBase) { MessageBox.Show( MCommonResourcestrings.StrNewRecordIsFiltered, MCommonResourcestrings.StrAddNewRecordTitle, MessageBoxButtons.OK, MessageBoxIcon.Information); FFilterAndFindObject.FilterPanelControls.ClearAllDiscretionaryFilters(); if (FFilterAndFindObject.FilterFindPanel.ShowApplyFilterButton != TUcoFilterAndFind.FilterContext.None) { FFilterAndFindObject.ApplyFilter(); } SelectDetailRowByDataTableIndex(FMainDS.ARecurringGiftDetail.Rows.Count - 1); } } btnDeleteAll.Enabled = btnDelete.Enabled; UpdateRecordNumberDisplay(); FLastDonor = -1; //Select end row if (SelectEndRow) { grdDetails.SelectRowInGrid(grdDetails.Rows.Count - 1); } //Focus accordingly if (ACompletelyNewRecurringGift) { txtDetailDonorKey.Focus(); } else { txtDetailRecipientKey.Focus(); } //FPreviouslySelectedDetailRow should now be pointing to the newly added row UpdateRecipientKeyText(0, FPreviouslySelectedDetailRow, cmbDetailMotivationGroupCode.GetSelectedString(), cmbMotivationDetailCode.GetSelectedString()); ClearKeyMinistries(); mniRecipientHistory.Enabled = false; } } finally { FNewGiftInProcess = false; if (AutoSaveSuccessful) { FPetraUtilsObject.WriteToStatusBar(MCommonResourcestrings.StrSavingDataSuccessful); } } }
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> /// auto populate new gift recipient info using the donor's last gift /// </summary> /// <param name="ADonorKey"></param> /// <param name="APartnerShortName"></param> /// <param name="AGiftTransactionNumber"></param> private void AutoPopulateGiftDetail(Int64 ADonorKey, String APartnerShortName, Int32 AGiftTransactionNumber) { FAutoPopulatingGiftInProcess = true; bool IsSplitGift = false; DateTime LatestUnpostedGiftDateEntered = new DateTime(1900, 1, 1); try { //Check for Donor in loaded gift batches // and record most recent date entered AGiftTable DonorRecentGiftsTable = new AGiftTable(); GiftBatchTDSAGiftDetailTable GiftDetailTable = new GiftBatchTDSAGiftDetailTable(); AGiftRow MostRecentLoadedGiftForDonorRow = null; DataView giftDV = new DataView(FMainDS.AGift); giftDV.RowStateFilter = DataViewRowState.CurrentRows; giftDV.RowFilter = string.Format("{0}={1} And Not ({2}={3} And {4}={5})", AGiftTable.GetDonorKeyDBName(), ADonorKey, AGiftTable.GetBatchNumberDBName(), FBatchNumber, AGiftTable.GetGiftTransactionNumberDBName(), AGiftTransactionNumber); giftDV.Sort = String.Format("{0} DESC, {1} DESC", AGiftTable.GetDateEnteredDBName(), AGiftTable.GetGiftTransactionNumberDBName()); if (giftDV.Count > 0) { //Take first row = most recent date entered value MostRecentLoadedGiftForDonorRow = (AGiftRow)giftDV[0].Row; LatestUnpostedGiftDateEntered = MostRecentLoadedGiftForDonorRow.DateEntered; DonorRecentGiftsTable.Rows.Add((object[])MostRecentLoadedGiftForDonorRow.ItemArray.Clone()); } //Check for even more recent saved gifts on server (i.e. not necessarily loaded) GiftDetailTable = TRemote.MFinance.Gift.WebConnectors.LoadDonorLastPostedGift(ADonorKey, FLedgerNumber, LatestUnpostedGiftDateEntered); if (((GiftDetailTable != null) && (GiftDetailTable.Count > 0))) { //UnLoaded/Saved gift from donor is more recent IsSplitGift = (GiftDetailTable.Count > 1); } else if (MostRecentLoadedGiftForDonorRow != null) { //Loaded/unsaved gift from donor is more recent DataView giftDetailDV = new DataView(FMainDS.AGiftDetail); giftDetailDV.RowStateFilter = DataViewRowState.CurrentRows; giftDetailDV.RowFilter = string.Format("{0}={1} And {2}={3}", AGiftDetailTable.GetBatchNumberDBName(), MostRecentLoadedGiftForDonorRow.BatchNumber, AGiftDetailTable.GetGiftTransactionNumberDBName(), MostRecentLoadedGiftForDonorRow.GiftTransactionNumber); foreach (DataRowView drv in giftDetailDV) { GiftBatchTDSAGiftDetailRow gDR = (GiftBatchTDSAGiftDetailRow)drv.Row; GiftDetailTable.Rows.Add((object[])gDR.ItemArray.Clone()); } IsSplitGift = (GiftDetailTable.Count > 1); } else { //nothing to autocopy return; } // if the last gift was a split gift (multiple details) then ask the user if they would like this new gift to also be split if (IsSplitGift) { GiftDetailTable.DefaultView.Sort = GiftBatchTDSAGiftDetailTable.GetDetailNumberDBName() + " ASC"; string Message = string.Format(Catalog.GetString( "The last gift from this donor was a split gift.{0}{0}Here are the details:{0}"), "\n"); int DetailNumber = 1; foreach (DataRowView dvr in GiftDetailTable.DefaultView) { GiftBatchTDSAGiftDetailRow Row = (GiftBatchTDSAGiftDetailRow)dvr.Row; Message += DetailNumber + ") "; if (Row.RecipientKey > 0) { Message += string.Format(Catalog.GetString("Recipient: {0} ({1}); Motivation Group: {2}; Motivation Detail: {3}; Amount: {4}"), Row.RecipientDescription, Row.RecipientKey, Row.MotivationGroupCode, Row.MotivationDetailCode, StringHelper.FormatUsingCurrencyCode(Row.GiftTransactionAmount, GetBatchRow().CurrencyCode) + " " + FBatchRow.CurrencyCode) + "\n"; } DetailNumber++; } Message += "\n" + Catalog.GetString("Do you want to create the same split gift again?"); if (!(MessageBox.Show(Message, Catalog.GetString( "Create Split Gift"), MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)) { if (cmbDetailMethodOfGivingCode.CanFocus) { cmbDetailMethodOfGivingCode.Focus(); } else if (txtDetailReference.CanFocus) { txtDetailReference.Focus(); } return; } } this.Cursor = Cursors.WaitCursor; GiftBatchTDSAGiftDetailRow giftDetailRow = (GiftBatchTDSAGiftDetailRow)GiftDetailTable.DefaultView[0].Row; // Handle first row, which is FPreviouslySelectedDetailRow txtDetailDonorKey.Text = String.Format("{0:0000000000}", ADonorKey); txtDetailRecipientKey.Text = String.Format("{0:0000000000}", giftDetailRow.RecipientKey); cmbDetailMotivationGroupCode.SetSelectedString(giftDetailRow.MotivationGroupCode); txtDetailMotivationDetailCode.Text = giftDetailRow.MotivationDetailCode; cmbMotivationDetailCode.SetSelectedString(giftDetailRow.MotivationDetailCode); chkDetailConfidentialGiftFlag.Checked = giftDetailRow.ConfidentialGiftFlag; // Change #5481 chkDetailChargeFlag.Checked = true; cmbDetailMethodOfPaymentCode.SetSelectedString(FBatchMethodOfPayment, -1); cmbDetailMethodOfGivingCode.SetSelectedString(giftDetailRow.MethodOfGivingCode, -1); //Handle mailing code if (FSETAutoCopyIncludeMailingCodeFlag) { cmbDetailMailingCode.SetSelectedString(giftDetailRow.MailingCode, -1); } else { cmbDetailMailingCode.SelectedIndex = -1; } //Copy the comments and comment types if required if (FSETAutoCopyIncludeCommentsFlag) { txtDetailGiftCommentOne.Text = giftDetailRow.GiftCommentOne; cmbDetailCommentOneType.SetSelectedString(giftDetailRow.CommentOneType); txtDetailGiftCommentTwo.Text = giftDetailRow.GiftCommentTwo; cmbDetailCommentTwoType.SetSelectedString(giftDetailRow.CommentTwoType); txtDetailGiftCommentThree.Text = giftDetailRow.GiftCommentThree; cmbDetailCommentThreeType.SetSelectedString(giftDetailRow.CommentThreeType); } //Handle tax fields on current row if (FSETUseTaxDeductiblePercentageFlag) { bool taxDeductible = (giftDetailRow.IsTaxDeductibleNull() ? true : giftDetailRow.TaxDeductible); giftDetailRow.TaxDeductible = taxDeductible; try { FPetraUtilsObject.SuppressChangeDetection = true; chkDetailTaxDeductible.Checked = taxDeductible; EnableTaxDeductibilityPct(taxDeductible); } finally { FPetraUtilsObject.SuppressChangeDetection = false; } if (!IsSplitGift) { //Most commonly not a split gift (?) if (!taxDeductible) { txtDeductiblePercentage.NumberValueDecimal = 0.0m; } txtTaxDeductAmount.NumberValueDecimal = 0.0m; txtNonDeductAmount.NumberValueDecimal = 0.0m; } else { if (taxDeductible) { //In case the tax percentage has changed or null values in amount fields ReconcileTaxDeductibleAmounts(giftDetailRow); } else { //Changing this will update the unbound amount textboxes txtDeductiblePercentage.NumberValueDecimal = 0.0m; } } } //Process values that are not bound to a control giftDetailRow.ReceiptPrinted = false; giftDetailRow.ReceiptNumber = 0; //Now process other gift details if they exist if (IsSplitGift) { //Only copy amount to first row if copying split gifts txtDetailGiftTransactionAmount.NumberValueDecimal = giftDetailRow.GiftTransactionAmount; // clear previous validation errors. // otherwise we get an error if the user has changed the control immediately after changing the donor key. FPetraUtilsObject.VerificationResultCollection.Clear(); bool SelectEndRow = (FBatchRow.LastGiftNumber == FPreviouslySelectedDetailRow.GiftTransactionNumber); //Just retain other details to add giftDetailRow.Delete(); GiftDetailTable.AcceptChanges(); foreach (DataRowView drv in GiftDetailTable.DefaultView) { GiftBatchTDSAGiftDetailRow detailRow = (GiftBatchTDSAGiftDetailRow)drv.Row; //______________________ //Update basic field values detailRow.LedgerNumber = FLedgerNumber; detailRow.BatchNumber = FBatchNumber; detailRow.GiftTransactionNumber = AGiftTransactionNumber; detailRow.DetailNumber = ++FGift.LastDetailNumber; detailRow.DonorName = APartnerShortName; detailRow.DonorClass = FPreviouslySelectedDetailRow.DonorClass; detailRow.DateEntered = FGift.DateEntered; detailRow.MethodOfPaymentCode = FPreviouslySelectedDetailRow.MethodOfPaymentCode; detailRow.ReceiptPrinted = false; detailRow.ReceiptNumber = 0; // Change #5481 detailRow.ChargeFlag = true; if (!FSETAutoCopyIncludeMailingCodeFlag) { detailRow.MailingCode = string.Empty; } //______________________ //process recipient details to get most recent data Int64 partnerKey = detailRow.RecipientKey; string partnerShortName = string.Empty; TPartnerClass partnerClass; bool recipientIsValid = true; if (TServerLookup.TMPartner.GetPartnerShortName(partnerKey, out partnerShortName, out partnerClass)) { detailRow.RecipientDescription = partnerShortName; detailRow.RecipientClass = partnerClass.ToString(); if (partnerClass == TPartnerClass.FAMILY) { detailRow.RecipientLedgerNumber = TRemote.MFinance.Gift.WebConnectors.GetRecipientFundNumber(partnerKey, FGift.DateEntered); detailRow.RecipientField = detailRow.RecipientLedgerNumber; detailRow.RecipientKeyMinistry = string.Empty; } else { //Class - UNIT Int64 field; string keyMinName; recipientIsValid = TFinanceControls.GetRecipientKeyMinData(partnerKey, out field, out keyMinName); detailRow.RecipientLedgerNumber = field; detailRow.RecipientField = field; detailRow.RecipientKeyMinistry = keyMinName; if (!recipientIsValid) { string msg = String.Format(Catalog.GetString( "Gift: {0}, Detail: {1} has a recipient: '{2}-{3}' that is an inactive Key Ministry!"), AGiftTransactionNumber, detailRow.DetailNumber, partnerKey, keyMinName); MessageBox.Show(msg, Catalog.GetString( "Copying Previous Split Gift"), MessageBoxButtons.OK, MessageBoxIcon.Warning); } } } else { recipientIsValid = false; string msg = String.Format(Catalog.GetString("Gift: {0}, Detail: {1} has an invalid Recipient key: '{2}'!"), AGiftTransactionNumber, detailRow.DetailNumber, partnerKey); MessageBox.Show(msg, Catalog.GetString("Copying Previous Split Gift"), MessageBoxButtons.OK, MessageBoxIcon.Warning); } //______________________ //Process motivation if (string.IsNullOrEmpty(detailRow.MotivationGroupCode)) { detailRow.MotivationGroupCode = string.Empty; string msg = String.Format(Catalog.GetString("Gift: {0}, Detail: {1} has no Motivation Group!"), AGiftTransactionNumber, detailRow.DetailNumber); MessageBox.Show(msg, Catalog.GetString("Copying Previous Split Gift"), MessageBoxButtons.OK, MessageBoxIcon.Warning); } else if (string.IsNullOrEmpty(detailRow.MotivationDetailCode)) { detailRow.MotivationDetailCode = string.Empty; string msg = String.Format(Catalog.GetString("Gift: {0}, Detail: {1} has no Motivation Detail!"), AGiftTransactionNumber, detailRow.DetailNumber); MessageBox.Show(msg, Catalog.GetString("Copying Previous Split Gift"), MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { AMotivationDetailRow motivationDetailRow = null; string motivationGroup = detailRow.MotivationGroupCode; string motivationDetail = detailRow.MotivationDetailCode; motivationDetailRow = (AMotivationDetailRow)FMainDS.AMotivationDetail.Rows.Find( new object[] { FLedgerNumber, motivationGroup, motivationDetail }); if (motivationDetailRow != null) { if (partnerKey > 0) { bool partnerIsMissingLink = false; detailRow.CostCentreCode = TRemote.MFinance.Gift.WebConnectors.RetrieveCostCentreCodeForRecipient(FLedgerNumber, partnerKey, detailRow.RecipientLedgerNumber, detailRow.DateEntered, motivationGroup, motivationDetail, out partnerIsMissingLink); } else { if (motivationGroup != MFinanceConstants.MOTIVATION_GROUP_GIFT) { detailRow.RecipientDescription = motivationGroup; } else { detailRow.RecipientDescription = string.Empty; } detailRow.CostCentreCode = motivationDetailRow.CostCentreCode; } detailRow.AccountCode = motivationDetailRow.AccountCode; if (FSETUseTaxDeductiblePercentageFlag && string.IsNullOrEmpty(motivationDetailRow.TaxDeductibleAccountCode)) { detailRow.TaxDeductibleAccountCode = string.Empty; string msg = String.Format(Catalog.GetString( "Gift: {0}, Detail: {1} has Motivation Detail: {2} which has no Tax Deductible Account!" + "This can be added in Finance / Setup / Motivation Details.{3}{3}" + "Unless this is changed it will be impossible to assign a Tax Deductible Percentage to this gift."), AGiftTransactionNumber, detailRow.DetailNumber, motivationDetail, Environment.NewLine); MessageBox.Show(msg, Catalog.GetString( "Copying Previous Split Gift"), MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { detailRow.TaxDeductibleAccountCode = motivationDetailRow.TaxDeductibleAccountCode; } } else { string msg = String.Format(Catalog.GetString( "Gift: {0}, Detail: {1} has Motivation Group and Detail codes ('{2} : {3}') not found in the database!"), AGiftTransactionNumber, detailRow.DetailNumber, motivationGroup, motivationDetail); MessageBox.Show(msg, Catalog.GetString("Copying Previous Split Gift"), MessageBoxButtons.OK, MessageBoxIcon.Warning); detailRow.TaxDeductible = false; } } //______________________ //Handle tax fields detailRow.TaxDeductiblePct = RetrieveTaxDeductiblePct((recipientIsValid ? detailRow.RecipientKey : 0), detailRow.TaxDeductible); AGiftDetailRow giftDetails = (AGiftDetailRow)detailRow; TaxDeductibility.UpdateTaxDeductibiltyAmounts(ref giftDetails); //______________________ //Process comments if (!FSETAutoCopyIncludeCommentsFlag) { detailRow.SetCommentOneTypeNull(); detailRow.SetCommentTwoTypeNull(); detailRow.SetCommentThreeTypeNull(); detailRow.SetGiftCommentOneNull(); detailRow.SetGiftCommentTwoNull(); detailRow.SetGiftCommentThreeNull(); } detailRow.AcceptChanges(); detailRow.SetAdded(); } //Add in the new records (latter two arguments put in to parallel recurring form) FMainDS.AGiftDetail.Merge(GiftDetailTable, false, MissingSchemaAction.Ignore); int indexOfLatestRow = FMainDS.AGiftDetail.Rows.Count - 1; //Select last row added if (SelectEndRow) { grdDetails.SelectRowInGrid(grdDetails.Rows.Count - 1); } else if (!SelectDetailRowByDataTableIndex(indexOfLatestRow)) { if (!FFilterAndFindObject.IsActiveFilterEqualToBase) { MessageBox.Show( MCommonResourcestrings.StrNewRecordIsFiltered, MCommonResourcestrings.StrAddNewRecordTitle, MessageBoxButtons.OK, MessageBoxIcon.Information); FFilterAndFindObject.FilterPanelControls.ClearAllDiscretionaryFilters(); if (FFilterAndFindObject.FilterFindPanel.ShowApplyFilterButton != TUcoFilterAndFind.FilterContext.None) { FFilterAndFindObject.ApplyFilter(); } SelectDetailRowByDataTableIndex(indexOfLatestRow); } } ClearKeyMinistries(); cmbMotivationDetailCode.Clear(); mniRecipientHistory.Enabled = false; btnDeleteAll.Enabled = btnDelete.Enabled; UpdateRecordNumberDisplay(); FLastDonor = -1; } else { txtDetailDonorKey.FocusTextBoxPartAfterFindScreenCloses = false; txtDetailGiftTransactionAmount.Focus(); } FPetraUtilsObject.SetChangedFlag(); } finally { this.Cursor = Cursors.Default; FAutoPopulatingGiftInProcess = false; } }
/// <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); }
/// <summary> /// Creates a new gift or gift detail depending upon the parameter /// </summary> /// <param name="ACompletelyNewGift"></param> private void CreateANewGift(bool ACompletelyNewGift) { AGiftRow CurrentGiftRow = null; bool IsEmptyGrid = (grdDetails.Rows.Count == 1); FCreatingNewGift = true; try { if (ValidateAllData(true, true)) { if (!ACompletelyNewGift) //i.e. a gift detail { ACompletelyNewGift = IsEmptyGrid; } if (ACompletelyNewGift) { //Run this if a new gift is requested or required. // we create the table locally, no dataset AGiftRow giftRow = FMainDS.AGift.NewRowTyped(true); giftRow.DateEntered = FBatchRow.GlEffectiveDate; giftRow.LedgerNumber = FBatchRow.LedgerNumber; giftRow.BatchNumber = FBatchRow.BatchNumber; giftRow.GiftTransactionNumber = ++FBatchRow.LastGiftNumber; giftRow.MethodOfPaymentCode = FBatchRow.MethodOfPaymentCode; giftRow.LastDetailNumber = 1; FMainDS.AGift.Rows.Add(giftRow); CurrentGiftRow = giftRow; mniDonorHistory.Enabled = false; } else { CurrentGiftRow = GetGiftRow(FPreviouslySelectedDetailRow.GiftTransactionNumber); CurrentGiftRow.LastDetailNumber++; } //New gifts will require a new detail anyway, so this code always runs GiftBatchTDSAGiftDetailRow newRow = FMainDS.AGiftDetail.NewRowTyped(true); newRow.LedgerNumber = FBatchRow.LedgerNumber; newRow.BatchNumber = FBatchRow.BatchNumber; newRow.GiftTransactionNumber = CurrentGiftRow.GiftTransactionNumber; newRow.DetailNumber = CurrentGiftRow.LastDetailNumber; newRow.MethodOfPaymentCode = CurrentGiftRow.MethodOfPaymentCode; newRow.MethodOfGivingCode = CurrentGiftRow.MethodOfGivingCode; newRow.DonorKey = CurrentGiftRow.DonorKey; if (!ACompletelyNewGift && (FPreviouslySelectedDetailRow != null)) { newRow.DonorName = FPreviouslySelectedDetailRow.DonorName; newRow.ConfidentialGiftFlag = FPreviouslySelectedDetailRow.ConfidentialGiftFlag; newRow.ChargeFlag = FPreviouslySelectedDetailRow.ChargeFlag; newRow.TaxDeductible = FPreviouslySelectedDetailRow.TaxDeductible; newRow.MotivationGroupCode = FPreviouslySelectedDetailRow.MotivationGroupCode; newRow.MotivationDetailCode = FPreviouslySelectedDetailRow.MotivationDetailCode; } else { newRow.MotivationGroupCode = MFinanceConstants.MOTIVATION_GROUP_GIFT; newRow.MotivationDetailCode = MFinanceConstants.GROUP_DETAIL_SUPPORT; } newRow.DateEntered = CurrentGiftRow.DateEntered; if (FTaxDeductiblePercentageEnabled) { newRow.TaxDeductiblePct = 100; } FMainDS.AGiftDetail.Rows.Add(newRow); FPetraUtilsObject.SetChangedFlag(); if (!SelectDetailRowByDataTableIndex(FMainDS.AGiftDetail.Rows.Count - 1)) { if (!FFilterAndFindObject.IsActiveFilterEqualToBase) { MessageBox.Show( MCommonResourcestrings.StrNewRecordIsFiltered, MCommonResourcestrings.StrAddNewRecordTitle, MessageBoxButtons.OK, MessageBoxIcon.Information); FFilterAndFindObject.FilterPanelControls.ClearAllDiscretionaryFilters(); if (FFilterAndFindObject.FilterFindPanel.ShowApplyFilterButton != TUcoFilterAndFind.FilterContext.None) { FFilterAndFindObject.ApplyFilter(); } SelectDetailRowByDataTableIndex(FMainDS.AGiftDetail.Rows.Count - 1); } } btnDeleteAll.Enabled = btnDelete.Enabled && (FFilterAndFindObject.IsActiveFilterEqualToBase); UpdateRecordNumberDisplay(); FLastDonor = -1; //Focus accordingly if (ACompletelyNewGift) { txtDetailDonorKey.Focus(); } else { txtDetailRecipientKey.Focus(); } TUC_GiftTransactions_Recipient.UpdateRecipientKeyText(0, FPreviouslySelectedDetailRow, cmbDetailMotivationGroupCode.GetSelectedString(), cmbDetailMotivationDetailCode.GetSelectedString()); cmbKeyMinistries.Clear(); mniRecipientHistory.Enabled = false; } } finally { FCreatingNewGift = false; } }
/// <summary> /// load the journals into the grid /// </summary> /// <param name="ACurrentBatchRow"></param> public void LoadJournals(ARecurringBatchRow ACurrentBatchRow) { FJournalsLoaded = false; FBatchRow = ACurrentBatchRow; if (FBatchRow == null) { return; } Int32 CurrentLedgerNumber = ACurrentBatchRow.LedgerNumber; Int32 CurrentBatchNumber = ACurrentBatchRow.BatchNumber; bool FirstRun = (FLedgerNumber != CurrentLedgerNumber); bool BatchChanged = (FBatchNumber != CurrentBatchNumber); if (FirstRun) { FLedgerNumber = CurrentLedgerNumber; } if (BatchChanged) { FBatchNumber = CurrentBatchNumber; } //Check if same Journals as previously selected if (!(FirstRun || BatchChanged)) { //Need to reconnect FPrev in some circumstances if (FPreviouslySelectedDetailRow == null) { DataRowView rowView = (DataRowView)grdDetails.Rows.IndexToDataSourceRow(FPrevRowChangedRow); if (rowView != null) { FPreviouslySelectedDetailRow = (GLBatchTDSARecurringJournalRow)(rowView.Row); } } if (GetSelectedRowIndex() > 0) { GetDetailsFromControls(GetSelectedDetailRow()); } } else { // a different journal SetJournalDefaultView(); FPreviouslySelectedDetailRow = null; //Load Journals if (FMainDS.ARecurringJournal.DefaultView.Count == 0) { FMainDS.Merge(TRemote.MFinance.GL.WebConnectors.LoadARecurringJournal(FLedgerNumber, FBatchNumber)); } //Ensure Last Batch Number is correct, needed to correct old Petra data if ((FBatchRow.LastJournal != FMainDS.ARecurringJournal.DefaultView.Count) && GLRoutines.UpdateRecurringBatchLastJournal(ref FMainDS, ref FBatchRow)) { FPetraUtilsObject.SetChangedFlag(); } ShowData(); // Now set up the complete current filter FFilterAndFindObject.FilterPanelControls.SetBaseFilter(FMainDS.ARecurringJournal.DefaultView.RowFilter, true); FFilterAndFindObject.ApplyFilter(); } int nRowToSelect = (BatchChanged || FirstRun) ? 1 : FPrevRowChangedRow; //This will also call UpdateChangeableStatus SelectRowInGrid(nRowToSelect); UpdateRecordNumberDisplay(); FFilterAndFindObject.SetRecordNumberDisplayProperties(); //Check for incorrect Exchange rate to base foreach (DataRowView drv in FMainDS.ARecurringJournal.DefaultView) { ARecurringJournalRow rjr = (ARecurringJournalRow)drv.Row; if (rjr.ExchangeRateToBase == 0) { rjr.ExchangeRateToBase = 1; FPetraUtilsObject.HasChanges = true; } } FJournalsLoaded = true; //Check on batch totals if (GLRoutines.UpdateRecurringBatchTotals(ref FMainDS, ref FBatchRow)) { FPetraUtilsObject.SetChangedFlag(); } }
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); }