Пример #1
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;
        }