Beispiel #1
0
 /// <summary>
 /// Constructor
 /// </summary>
 public TUC_GiftBatches_Import(TFrmPetraEditUtils APetraUtilsObject, Int32 ALedgerNumber, IUC_GiftBatches AUserControl)
 {
     FPetraUtilsObject = APetraUtilsObject;
     FLedgerNumber     = ALedgerNumber;
     FMyUserControl    = AUserControl;
     FMyForm           = (TFrmGiftBatch)FPetraUtilsObject.GetForm();
 }
        /// <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;
            }
        }
Beispiel #3
0
        /// <summary>
        /// Constructor
        /// </summary>
        public TUC_GiftBatches_Cancel(TFrmPetraEditUtils APetraUtilsObject, Int32 ALedgerNumber, GiftBatchTDS AMainDS)
        {
            FPetraUtilsObject = APetraUtilsObject;
            FLedgerNumber     = ALedgerNumber;
            FMainDS           = AMainDS;

            FMyForm = (TFrmGiftBatch)FPetraUtilsObject.GetForm();
        }
        /// <summary>
        /// Constructor
        /// </summary>
        public TUC_GiftBatches_Cancel(TFrmPetraEditUtils APetraUtilsObject, Int32 ALedgerNumber, GiftBatchTDS AMainDS)
        {
            FPetraUtilsObject = APetraUtilsObject;
            FLedgerNumber = ALedgerNumber;
            FMainDS = AMainDS;

            FMyForm = (TFrmGiftBatch)FPetraUtilsObject.GetForm();
        }
        private void BtnView_Click(object sender, EventArgs e)
        {
            // get the currently selected row
            DataRow CurrentlySelectedRow = GetCurrentDataRow();

            if (CurrentlySelectedRow != null)
            {
                try
                {
                    this.Cursor = Cursors.WaitCursor;

                    TFrmGiftBatch gb = new TFrmGiftBatch(this);
                    gb.LedgerNumber = FLedgerNumber;

                    // load dataset with data for whole transaction (all details)

                    // Viewmode = true

                    /*gb.ViewModeTDS = TRemote.MFinance.Gift.WebConnectors.LoadAGiftSingle(FLedgerNumber,
                     *  (int)CurrentlySelectedRow["a_batch_number_i"],
                     *  (int)CurrentlySelectedRow["a_gift_transaction_number_i"]);
                     *
                     * if (gb.ViewModeTDS.AGiftBatch[0].BatchStatus == MFinanceConstants.BATCH_POSTED)
                     * {
                     *  // read only if gift belongs to a posted batch
                     *  gb.ViewMode = true;
                     *  gb.ShowDetailsOfOneBatch(FLedgerNumber, (int)CurrentlySelectedRow["a_batch_number_i"],
                     *      gb.ViewModeTDS.AGiftBatch[0].BatchYear, gb.ViewModeTDS.AGiftBatch[0].BatchPeriod);
                     * }
                     * else
                     * {
                     *  gb.ShowDetailsOfOneBatch(FLedgerNumber, (int)CurrentlySelectedRow["a_batch_number_i"],
                     *      gb.ViewModeTDS.AGiftBatch[0].BatchYear, gb.ViewModeTDS.AGiftBatch[0].BatchPeriod);
                     *  gb.DisableBatches();
                     * }*/

                    // Viewmode = false
                    gb.ShowDetailsOfOneBatch(FLedgerNumber, (int)CurrentlySelectedRow["a_batch_number_i"],
                                             (int)CurrentlySelectedRow["a_batch_year_i"], (int)CurrentlySelectedRow["a_batch_period_i"]);

                    gb.SelectTab(TFrmGiftBatch.eGiftTabs.Transactions);

                    gb.FindGiftDetail((int)CurrentlySelectedRow["a_batch_number_i"],
                                      (int)CurrentlySelectedRow["a_gift_transaction_number_i"], (int)CurrentlySelectedRow["a_detail_number_i"]);
                }
                finally
                {
                    this.Cursor = Cursors.Default;
                }
            }
        }
Beispiel #6
0
        /// <summary>
        /// load the batches into the grid
        /// </summary>
        public void LoadBatchesForCurrentYear()
        {
            TFrmGiftBatch MyParentForm        = (TFrmGiftBatch)this.ParentForm;
            bool          PerformStandardLoad = true;

            if (MyParentForm.InitialBatchYear >= 0)
            {
                FLoadAndFilterLogicObject.StatusAll = true;

                int yearIndex = FLoadAndFilterLogicObject.FindYearAsIndex(MyParentForm.InitialBatchYear);

                if (yearIndex >= 0)
                {
                    FLoadAndFilterLogicObject.YearIndex = yearIndex;

                    if (MyParentForm.InitialBatchPeriod >= 0)
                    {
                        FLoadAndFilterLogicObject.PeriodIndex = FLoadAndFilterLogicObject.FindPeriodAsIndex(MyParentForm.InitialBatchPeriod);
                    }
                    else
                    {
                        FLoadAndFilterLogicObject.PeriodIndex = (MyParentForm.InitialBatchYear == FMainDS.ALedger[0].CurrentFinancialYear) ? 1 : 0;
                    }

                    PerformStandardLoad = false;
                }

                // Reset the start-up value
                MyParentForm.InitialBatchYear = -1;
            }

            MyParentForm.ClearCurrentSelections();

            if (ViewMode)
            {
                FMainDS.Merge(ViewModeTDS);
                FLoadAndFilterLogicObject.DisableYearAndPeriod(true);
            }

            if (PerformStandardLoad)
            {
                // Set up for current year with current and forwarding periods (on initial load this will already be set so will not fire a change)
                FLoadAndFilterLogicObject.YearIndex   = 0;
                FLoadAndFilterLogicObject.PeriodIndex = 0;
            }

            // Get the data, populate the grid and re-select the current row (or first row if none currently selected) ...
            RefreshAllData();

            FBatchLoaded = true;
        }
        private void ViewTransaction(object sender, EventArgs e)
        {
            // get the currently selected row
            FPreviouslySelectedDetailRow = GetSelectedDetailRow();

            if ((FPreviouslySelectedDetailRow != null) && (FMainDS != null))
            {
                try
                {
                    this.Cursor = Cursors.WaitCursor;

                    TFrmGiftBatch gb = new TFrmGiftBatch(this);

                    // load dataset with data for whole transaction (all details)
                    gb.ViewModeTDS = TRemote.MFinance.Gift.WebConnectors.LoadAGiftSingle(FLedgerNumber,
                                                                                         (int)FPreviouslySelectedDetailRow["BatchNumber"],
                                                                                         (int)FPreviouslySelectedDetailRow["GiftTransactionNumber"]);

                    if (gb.ViewModeTDS.AGiftBatch[0].BatchStatus == MFinanceConstants.BATCH_POSTED)
                    {
                        // read only if gift belongs to a posted batch
                        gb.ViewMode = true;
                        gb.ShowDetailsOfOneBatch(FLedgerNumber, (int)FPreviouslySelectedDetailRow["BatchNumber"],
                                                 gb.ViewModeTDS.AGiftBatch[0].BatchYear, gb.ViewModeTDS.AGiftBatch[0].BatchPeriod);
                    }
                    else
                    {
                        gb.ShowDetailsOfOneBatch(FLedgerNumber, (int)FPreviouslySelectedDetailRow["BatchNumber"],
                                                 gb.ViewModeTDS.AGiftBatch[0].BatchYear, gb.ViewModeTDS.AGiftBatch[0].BatchPeriod);
                        gb.DisableBatches();
                    }

                    gb.SelectTab(TFrmGiftBatch.eGiftTabs.Transactions);
                    gb.FindGiftDetail((AGiftDetailRow)gb.ViewModeTDS.AGiftDetail.Rows.Find(
                                          new object[] { FLedgerNumber,
                                                         FPreviouslySelectedDetailRow["BatchNumber"],
                                                         FPreviouslySelectedDetailRow["GiftTransactionNumber"],
                                                         FPreviouslySelectedDetailRow["DetailNumber"] }));
                }
                finally
                {
                    this.Cursor = Cursors.Default;
                }
            }
        }
Beispiel #8
0
        public void TestPostAndSaveAfterwards()
        {
            string TestFile = CommonNUnitFunctions.rootPath + "/csharp/ICT/Testing/lib/MFinance/GiftForm/TestData/BatchImportTest.csv";

            TFrmGiftBatch frmBatch = new TFrmGiftBatch(null);

            frmBatch.LedgerNumber = FLedgerNumber;
            frmBatch.Show();

            ImportGiftBatch(TestFile);

            TabControlTester tabGiftBatch = new TabControlTester("tabGiftBatch");
            tabGiftBatch.SelectTab(1);
            TextBoxTester txtDetailGiftTransactionAmount = new TextBoxTester("txtDetailGiftTransactionAmount");
            Assert.AreEqual(Convert.ToDecimal(txtDetailGiftTransactionAmount.Properties.Text), 10000000000M);

            frmBatch.Close();
        }
Beispiel #9
0
        public void TestImportExportGiftBatch()
        {
            // create two test batches, with some strange figures, to test problem with double values
            // TODO export the 2 test batches, with summarize option
            // TODO compare the exported text file

            string TestFile = CommonNUnitFunctions.rootPath + "/csharp/ICT/Testing/lib/MFinance/GiftForm/TestData/BatchImportTest.csv";

            TFrmGiftBatch frmBatch = new TFrmGiftBatch(null);

            frmBatch.LedgerNumber = FLedgerNumber;
            frmBatch.Show();

            ImportGiftBatch(TestFile);

            TabControlTester tabGiftBatch = new TabControlTester("tabGiftBatch");
            tabGiftBatch.SelectTab(1);
            TextBoxTester txtDetailGiftTransactionAmount = new TextBoxTester("txtDetailGiftTransactionAmount");
            Assert.AreEqual(Convert.ToDecimal(txtDetailGiftTransactionAmount.Properties.Text), 10000000000M);

            frmBatch.Close();
        }
Beispiel #10
0
        /// <summary>
        /// The main method that handles all filtering.  Every change on the filter panel causes this event to fire.
        /// It is important to manage the fact that this method may be called recursively and so nesting can be tricky!
        /// </summary>
        /// <param name="AFilterString">On entry this parameter contains the filter control's best guess for the current filter.
        /// The code can modify this string in the light of current control values.</param>
        public void ApplyFilterManual(ref string AFilterString)
        {
            if (!FFilterIsActivated)
            {
                // use anything until we have been activated.
                return;
            }

            string WorkingFilter     = String.Empty;
            string AdditionalFilter  = String.Empty;
            bool   ShowingAllPeriods = false;

            // Remove the old base filter
            if (FPrevBaseFilter.Length > 0)
            {
                // The additional filter is the part that is coming from the extra filter panel
                AdditionalFilter = AFilterString.Substring(FPrevBaseFilter.Length);

                if (AdditionalFilter.StartsWith(CommonJoinString.JOIN_STRING_SQL_AND))
                {
                    AdditionalFilter = AdditionalFilter.Substring(CommonJoinString.JOIN_STRING_SQL_AND.Length);
                }
            }

            int NewYear = FcmbYearEnding.GetSelectedInt32();

            if (NewYear != FPrevYearEnding)
            {
                FPrevYearEnding = NewYear;

                // This will trigger a re-entrant call to this method
                RefreshPeriods(NewYear);

                // Apply the last good filter as we unwind the nesting
                AFilterString = FPrevFilter;
                return;
            }

            int NewPeriod = FcmbPeriod.GetSelectedInt32();

            ALedgerRow LedgerRow =
                ((ALedgerTable)TDataCache.TMFinance.GetCacheableFinanceTable(TCacheableFinanceTablesEnum.LedgerDetails, FLedgerNumber))[0];

            int CurrentLedgerYear   = LedgerRow.CurrentFinancialYear;
            int CurrentLedgerPeriod = LedgerRow.CurrentPeriod;

            if (NewYear == -1)
            {
                NewYear = CurrentLedgerYear;

                WorkingFilter     = String.Format("{0} = {1}", AGiftBatchTable.GetBatchYearDBName(), NewYear);
                ShowingAllPeriods = true;
            }
            else
            {
                WorkingFilter = String.Format("{0} = {1}", AGiftBatchTable.GetBatchYearDBName(), NewYear);

                if (NewPeriod == 0)  //All periods for year
                {
                    //Nothing to add to filter
                    ShowingAllPeriods = true;
                }
                else if (NewPeriod == -1)  //Current and forwarding
                {
                    WorkingFilter += String.Format(" AND {0} >= {1}", AGiftBatchTable.GetBatchPeriodDBName(), CurrentLedgerPeriod);
                }
                else if (NewPeriod > 0)  //Specific period
                {
                    WorkingFilter += String.Format(" AND {0} = {1}", AGiftBatchTable.GetBatchPeriodDBName(), NewPeriod);
                }
            }

            if (!BatchYearIsLoaded(NewYear))
            {
                FMainDS.Merge(TRemote.MFinance.Gift.WebConnectors.LoadAGiftBatchForYearPeriod(FLedgerNumber, NewYear, NewPeriod));

                // Set the flag on the transaction tab to show the status dialog again when the transactions are loaded for a new year
                TFrmGiftBatch giftBatchForm = (TFrmGiftBatch)FPetraUtilsObject.GetForm();
                giftBatchForm.GetTransactionsControl().ShowStatusDialogOnLoad = true;
            }

            if (FrbtEditing.Checked)
            {
                StringHelper.JoinAndAppend(ref WorkingFilter, String.Format("{0} = '{1}'",
                                                                            AGiftBatchTable.GetBatchStatusDBName(),
                                                                            MFinanceConstants.BATCH_UNPOSTED),
                                           CommonJoinString.JOIN_STRING_SQL_AND);
            }
            else if (FrbtPosting.Checked)
            {
                // note: batches
                StringHelper.JoinAndAppend(ref WorkingFilter, String.Format("({0} = '{1}') AND ({2} > 0) AND (({4} = 0) OR ({4} = {3}))",
                                                                            AGiftBatchTable.GetBatchStatusDBName(),
                                                                            MFinanceConstants.BATCH_UNPOSTED,
                                                                            AGiftBatchTable.GetLastGiftNumberDBName(),
                                                                            AGiftBatchTable.GetBatchTotalDBName(),
                                                                            AGiftBatchTable.GetHashTotalDBName()),
                                           CommonJoinString.JOIN_STRING_SQL_AND);
            }
            else //(FrbtAll.Checked)
            {
            }

            FFilterFindPanelObject.FilterPanelControls.SetBaseFilter(WorkingFilter, FrbtAll.Checked && ShowingAllPeriods);
            FPrevBaseFilter = WorkingFilter;

            AFilterString = WorkingFilter;
            StringHelper.JoinAndAppend(ref AFilterString, AdditionalFilter, CommonJoinString.JOIN_STRING_SQL_AND);

            FPrevFilter = AFilterString;
        }
        private void BtnView_Click(object sender, EventArgs e)
        {
            // get the currently selected row
            DataRow CurrentlySelectedRow = GetCurrentDataRow();

            if (CurrentlySelectedRow != null)
            {
                try
                {
                    this.Cursor = Cursors.WaitCursor;

                    TFrmGiftBatch gb = new TFrmGiftBatch(this);
                    gb.LedgerNumber = FLedgerNumber;

                    // load dataset with data for whole transaction (all details)

                    // Viewmode = true

                    /*gb.ViewModeTDS = TRemote.MFinance.Gift.WebConnectors.LoadAGiftSingle(FLedgerNumber,
                     *  (int)CurrentlySelectedRow["a_batch_number_i"],
                     *  (int)CurrentlySelectedRow["a_gift_transaction_number_i"]);
                     *
                     * if (gb.ViewModeTDS.AGiftBatch[0].BatchStatus == MFinanceConstants.BATCH_POSTED)
                     * {
                     *  // read only if gift belongs to a posted batch
                     *  gb.ViewMode = true;
                     *  gb.ShowDetailsOfOneBatch(FLedgerNumber, (int)CurrentlySelectedRow["a_batch_number_i"],
                     *      gb.ViewModeTDS.AGiftBatch[0].BatchYear, gb.ViewModeTDS.AGiftBatch[0].BatchPeriod);
                     * }
                     * else
                     * {
                     *  gb.ShowDetailsOfOneBatch(FLedgerNumber, (int)CurrentlySelectedRow["a_batch_number_i"],
                     *      gb.ViewModeTDS.AGiftBatch[0].BatchYear, gb.ViewModeTDS.AGiftBatch[0].BatchPeriod);
                     *  gb.DisableBatches();
                     * }*/

                    // Viewmode = false
                    gb.ShowDetailsOfOneBatch(FLedgerNumber, (int)CurrentlySelectedRow["a_batch_number_i"],
                        (int)CurrentlySelectedRow["a_batch_year_i"], (int)CurrentlySelectedRow["a_batch_period_i"]);

                    gb.SelectTab(TFrmGiftBatch.eGiftTabs.Transactions);

                    gb.FindGiftDetail((int)CurrentlySelectedRow["a_batch_number_i"],
                        (int)CurrentlySelectedRow["a_gift_transaction_number_i"], (int)CurrentlySelectedRow["a_detail_number_i"]);
                }
                finally
                {
                    this.Cursor = Cursors.Default;
                }
            }
        }
        /// <summary>
        /// update the transaction DateEntered from outside
        /// </summary>
        /// <param name="ABatchRow"></param>
        public void UpdateDateEntered(AGiftBatchRow ABatchRow)
        {
            Int32    ledgerNumber;
            Int32    batchNumber;
            DateTime batchEffectiveDate;

            if (ABatchRow.BatchStatus != MFinanceConstants.BATCH_UNPOSTED)
            {
                return;
            }

            ledgerNumber       = ABatchRow.LedgerNumber;
            batchNumber        = ABatchRow.BatchNumber;
            batchEffectiveDate = ABatchRow.GlEffectiveDate;

            DataView giftDataView = new DataView(FMainDS.AGift);

            giftDataView.RowFilter = String.Format("{0}={1} And {2}={3}",
                                                   AGiftTable.GetLedgerNumberDBName(),
                                                   ledgerNumber,
                                                   AGiftTable.GetBatchNumberDBName(),
                                                   batchNumber);

            DataView giftDetailDataView = new DataView(FMainDS.AGiftDetail);

            giftDetailDataView.RowFilter = String.Format("{0}={1} And {2}={3}",
                                                         AGiftDetailTable.GetLedgerNumberDBName(),
                                                         ledgerNumber,
                                                         AGiftDetailTable.GetBatchNumberDBName(),
                                                         batchNumber);

            ((TFrmGiftBatch)ParentForm).EnsureGiftDataPresent(ledgerNumber, batchNumber);

            if ((FPreviouslySelectedDetailRow != null) && (FBatchNumber == batchNumber))
            {
                //Rows already active in transaction tab. Need to set current row as code below will not update currently selected row
                FGLEffectivePeriodHasChangedFlag   = true;
                GetSelectedDetailRow().DateEntered = batchEffectiveDate;
            }

            TFrmGiftBatch ParentGiftBatchForm = (TFrmGiftBatch)ParentForm;

            ParentGiftBatchForm.Cursor = Cursors.WaitCursor;

            //Update all gift rows in this batch
            foreach (DataRowView dv in giftDataView)
            {
                AGiftRow giftRow = (AGiftRow)dv.Row;
                giftRow.DateEntered = batchEffectiveDate;
            }

            //Update all gift detail rows in this batch
            foreach (DataRowView dv in giftDetailDataView)
            {
                GiftBatchTDSAGiftDetailRow giftDetailRow = (GiftBatchTDSAGiftDetailRow)dv.Row;
                UpdateGiftDestinationOnDateChange(ref giftDetailRow, batchEffectiveDate);
            }

            ParentGiftBatchForm.Cursor = Cursors.Default;

            //If current row exists then refresh details
            if (FGLEffectivePeriodHasChangedFlag)
            {
                ShowDetails();
            }
        }
        private void ViewTransaction(object sender, EventArgs e)
        {
            // get the currently selected row
            FPreviouslySelectedDetailRow = GetSelectedDetailRow();

            if ((FPreviouslySelectedDetailRow != null) && (FMainDS != null))
            {
                try
                {
                    this.Cursor = Cursors.WaitCursor;

                    TFrmGiftBatch gb = new TFrmGiftBatch(this);

                    // load dataset with data for whole transaction (all details)
                    gb.ViewModeTDS = TRemote.MFinance.Gift.WebConnectors.LoadAGiftSingle(FLedgerNumber,
                        (int)FPreviouslySelectedDetailRow["BatchNumber"],
                        (int)FPreviouslySelectedDetailRow["GiftTransactionNumber"]);

                    if (gb.ViewModeTDS.AGiftBatch[0].BatchStatus == MFinanceConstants.BATCH_POSTED)
                    {
                        // read only if gift belongs to a posted batch
                        gb.ViewMode = true;
                        gb.ShowDetailsOfOneBatch(FLedgerNumber, (int)FPreviouslySelectedDetailRow["BatchNumber"],
                            gb.ViewModeTDS.AGiftBatch[0].BatchYear, gb.ViewModeTDS.AGiftBatch[0].BatchPeriod);
                    }
                    else
                    {
                        gb.ShowDetailsOfOneBatch(FLedgerNumber, (int)FPreviouslySelectedDetailRow["BatchNumber"],
                            gb.ViewModeTDS.AGiftBatch[0].BatchYear, gb.ViewModeTDS.AGiftBatch[0].BatchPeriod);
                        gb.DisableBatches();
                    }

                    gb.SelectTab(TFrmGiftBatch.eGiftTabs.Transactions);
                    gb.FindGiftDetail((AGiftDetailRow)gb.ViewModeTDS.AGiftDetail.Rows.Find(
                            new object[] { FLedgerNumber,
                                           FPreviouslySelectedDetailRow["BatchNumber"],
                                           FPreviouslySelectedDetailRow["GiftTransactionNumber"],
                                           FPreviouslySelectedDetailRow["DetailNumber"] }));
                }
                finally
                {
                    this.Cursor = Cursors.Default;
                }
            }
        }
Beispiel #14
0
        /// <summary>
        /// show the form for the gift reversal/adjustment
        /// </summary>
        /// <param name="AFunctionName">Which function shall be called on the server</param>
        private void ShowRevertAdjustForm(GiftAdjustmentFunctionEnum AFunctionName)
        {
            TFrmGiftBatch ParentGiftBatchForm = (TFrmGiftBatch)ParentForm;
            bool          ReverseWholeBatch   = (AFunctionName == GiftAdjustmentFunctionEnum.ReverseGiftBatch);
            bool          AdjustGift          = (AFunctionName == GiftAdjustmentFunctionEnum.AdjustGift);

            if (!ParentGiftBatchForm.SaveChangesManual())
            {
                return;
            }

            ParentGiftBatchForm.Cursor = Cursors.WaitCursor;

            AGiftBatchRow giftBatch   = ((TFrmGiftBatch)ParentForm).GetBatchControl().GetSelectedDetailRow();
            int           BatchNumber = giftBatch.BatchNumber;

            if (giftBatch == null)
            {
                MessageBox.Show(Catalog.GetString("Please select a Gift Batch to Reverse."));
                ParentGiftBatchForm.Cursor = Cursors.Default;
                return;
            }

            if (!giftBatch.BatchStatus.Equals(MFinanceConstants.BATCH_POSTED))
            {
                MessageBox.Show(Catalog.GetString("This function is only possible when the selected batch is already posted."));
                ParentGiftBatchForm.Cursor = Cursors.Default;
                return;
            }

            if (FPetraUtilsObject.HasChanges)
            {
                MessageBox.Show(Catalog.GetString("Please save first and than try again!"));
                ParentGiftBatchForm.Cursor = Cursors.Default;
                return;
            }

            if (ReverseWholeBatch && (FBatchNumber != BatchNumber))
            {
                ParentGiftBatchForm.SelectTab(TFrmGiftBatch.eGiftTabs.Transactions, true);
                ParentGiftBatchForm.SelectTab(TFrmGiftBatch.eGiftTabs.Batches);
                ParentGiftBatchForm.Cursor = Cursors.WaitCursor;
            }

            if (!ReverseWholeBatch && (FPreviouslySelectedDetailRow == null))
            {
                MessageBox.Show(Catalog.GetString("Please select a Gift to Adjust/Reverse."));
                ParentGiftBatchForm.Cursor = Cursors.Default;
                return;
            }

            TFrmGiftRevertAdjust revertForm = new TFrmGiftRevertAdjust(FPetraUtilsObject.GetForm());

            if (AdjustGift)
            {
                if (FSETUseTaxDeductiblePercentageFlag)
                {
                    revertForm.CheckTaxDeductPctChange = true;
                }

                revertForm.CheckGiftDestinationChange = true;
            }

            try
            {
                ParentForm.ShowInTaskbar = false;
                revertForm.LedgerNumber  = FLedgerNumber;
                revertForm.CurrencyCode  = giftBatch.CurrencyCode;

                // put spaces inbetween words
                revertForm.Text = Regex.Replace(AFunctionName.ToString(), "([a-z])([A-Z])", @"$1 $2");

                revertForm.AddParam("Function", AFunctionName);
                revertForm.AddParam("BatchNumber", giftBatch.BatchNumber);

                if (AdjustGift)
                {
                    int workingTransactionNumber = FPreviouslySelectedDetailRow.GiftTransactionNumber;
                    int workingDetailNumber      = FPreviouslySelectedDetailRow.DetailNumber;
                    revertForm.GiftDetailRow = (AGiftDetailRow)FMainDS.AGiftDetail.Rows.Find(
                        new object[] { giftBatch.LedgerNumber, giftBatch.BatchNumber, workingTransactionNumber, workingDetailNumber });
                }

                if (ReverseWholeBatch)
                {
                    revertForm.GetGiftsForReverseAdjust(); // Added Feb '17 Tim Ingham - previously, reversing a whole batch didn't work.
                }

                if (!revertForm.IsDisposed && (revertForm.ShowDialog() == DialogResult.OK))
                {
                    ParentGiftBatchForm.Cursor = Cursors.WaitCursor;

                    if ((revertForm.AdjustmentBatchNumber > 0) && (revertForm.AdjustmentBatchNumber != giftBatch.BatchNumber))
                    {
                        // select the relevant batch
                        ParentGiftBatchForm.InitialBatchNumber = revertForm.AdjustmentBatchNumber;
                    }

                    ParentGiftBatchForm.RefreshAll();
                }
            }
            finally
            {
                ParentGiftBatchForm.Cursor = Cursors.WaitCursor;
                revertForm.Dispose();
                ParentForm.ShowInTaskbar   = true;
                ParentGiftBatchForm.Cursor = Cursors.Default;
            }

            if (AdjustGift && (ParentGiftBatchForm.ActiveTab() == TFrmGiftBatch.eGiftTabs.Transactions))
            {
                //Select first row for adjusting, i.e. first +ve amount
                foreach (DataRowView drv in FMainDS.AGiftDetail.DefaultView)
                {
                    AGiftDetailRow gdr = (AGiftDetailRow)drv.Row;

                    if (gdr.GiftTransactionAmount > 0)
                    {
                        grdDetails.SelectRowInGrid(grdDetails.Rows.DataSourceRowToIndex(drv) + 1);
                    }
                }
            }
        }
Beispiel #15
0
        private void DeleteAllGifts(System.Object sender, EventArgs e)
        {
            TFrmGiftBatch FMyForm = (TFrmGiftBatch)this.ParentForm;

            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 BackupDS = null;

            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)
            {
                return;
            }

            try
            {
                this.Cursor = Cursors.WaitCursor;
                //Specify current action
                FMyForm.FCurrentGiftBatchAction = Logic.TExtraGiftBatchChecks.GiftBatchAction.DELETINGTRANS;

                //Backup the Dataset for reversion purposes
                BackupDS = (GiftBatchTDS)FMainDS.GetChangesTyped(false);

                //clear any transactions currently being editied in the Transaction Tab
                ClearCurrentSelection(0, false);

                //Now delete all gift data for current batch
                DeleteBatchGiftData(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 changes
                if (FMyForm.SaveChangesManual(Logic.TExtraGiftBatchChecks.GiftBatchAction.DELETINGTRANS, false, false))
                {
                    //Check if have deleted a reversing gift detail
                    if (OriginatingDetailRef.Count > 0)
                    {
                        TRemote.MFinance.Gift.WebConnectors.ReversedGiftReset(FLedgerNumber, OriginatingDetailRef);
                    }

                    CompletionMessage = Catalog.GetString("All Gifts and their details deleted successfully.");

                    MessageBox.Show(CompletionMessage,
                                    Catalog.GetString("Gifts Deletion"),
                                    MessageBoxButtons.OK,
                                    MessageBoxIcon.Information);
                }
                else
                {
                    CompletionMessage = Catalog.GetString("All 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();
        }
Beispiel #16
0
        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);
        }