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); }
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> /// 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; } }
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); }
private bool OnDeleteRowManual(GiftBatchTDSAGiftDetailRow 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 = GetBatchRow(); } if ((ARowToDelete == null) || (FBatchRow.BatchStatus != MFinanceConstants.BATCH_UNPOSTED)) { return(false); } int CurrentBatchNo = ARowToDelete.BatchNumber; bool RowToDeleteIsNew = (ARowToDelete.RowState == DataRowState.Added); int CurrentRowIndex = GetSelectedRowIndex(); TFrmGiftBatch FMyForm = (TFrmGiftBatch)this.ParentForm; GiftBatchTDS BackupMainDS = null; List <string> OriginatingDetailRef = new List <string>(); int SelectedDetailNumber = ARowToDelete.DetailNumber; int GiftToDeleteTransNo = 0; string FilterAllGiftsOfBatch = String.Empty; string FilterAllGiftDetailsOfBatch = 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().UpdateUnpostedBatchDictionary(CurrentBatchNo); if ((ARowToDelete.ModifiedDetailKey != null) && (ARowToDelete.ModifiedDetailKey.Length > 0)) { OriginatingDetailRef.Add(ARowToDelete.ModifiedDetailKey); } //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 gift header row if (DetailRowCount > 1) { ACompletionMessage = Catalog.GetString("Gift Detail row deleted successfully!"); FGiftSelectedForDeletionFlag = false; foreach (DataRowView rv in FGiftDetailView) { GiftBatchTDSAGiftDetailRow row = (GiftBatchTDSAGiftDetailRow)rv.Row; if (row.DetailNumber > SelectedDetailNumber) { row.DetailNumber--; } } FGift.LastDetailNumber--; } 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; 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().UpdateUnpostedBatchDictionary(); 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); } //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 RefreshBatchGiftData(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); }