/// <summary>
        /// read the values from the controls and give them to the calculator
        /// </summary>
        /// <param name="ACalculator"></param>
        /// <param name="AReportAction"></param>
        public void ReadControls(TRptCalculator ACalculator, TReportActionEnum AReportAction)
        {
            if (chkHideEmptyLines.Checked)
            {
                ACalculator.AddParameter("param_hide_empty_lines", "true");
            }
            else
            {
                ACalculator.AddParameter("param_hide_empty_lines", "false");
            }

            if (chkPrintTwoLines.Checked)
            {
                ACalculator.AddParameter("param_print_two_lines", "true");
                // we can't sort with two lines
                ACalculator.RemoveParameter("param_sortby_columns");
            }
            else
            {
                ACalculator.AddParameter("param_print_two_lines", "false");
            }
        }
        //
        // This will be called if the Fast Reports Wrapper loaded OK.
        // Returns True if the data apparently loaded OK and the report should be printed.
        private bool LoadReportData(TRptCalculator ACalc)
        {
            ArrayList reportParam = ACalc.GetParameters().Elems;

            Dictionary <String, TVariant>paramsDictionary = new Dictionary <string, TVariant>();

            foreach (Shared.MReporting.TParameter p in reportParam)
            {
                if (p.name.StartsWith("param") && (p.name != "param_calculation") && (!paramsDictionary.ContainsKey(p.name)))
                {
                    paramsDictionary.Add(p.name, p.value);
                }
            }

            DataTable ReportTable = TRemote.MReporting.WebConnectors.GetReportDataTable("GiftBatchDetail", paramsDictionary);

            if (this.IsDisposed) // There's no cancel function as such - if the user has pressed Esc the form is closed!
            {
                return false;
            }

            if (ReportTable == null)
            {
                FPetraUtilsObject.WriteToStatusBar("Report Cancelled.");
                return false;
            }

            FPetraUtilsObject.FFastReportsPlugin.RegisterData(ReportTable, "GiftBatchDetail");

            //
            // I need to get the name of the current ledger..

            DataTable LedgerNameTable = TDataCache.TMFinance.GetCacheableFinanceTable(TCacheableFinanceTablesEnum.LedgerNameList);
            DataView LedgerView = new DataView(LedgerNameTable);
            LedgerView.RowFilter = "LedgerNumber=" + FLedgerNumber;
            String LedgerName = "";

            if (LedgerView.Count > 0)
            {
                LedgerName = LedgerView[0].Row["LedgerName"].ToString();
            }

            ACalc.AddStringParameter("param_ledger_name", LedgerName);
            ACalc.AddStringParameter("param_linked_partner_cc", ""); // I may want to use this for auto_email, but usually it's unused.

            bool TaxDeductiblePercentageEnabled = Convert.ToBoolean(
                TSystemDefaults.GetSystemDefault(SharedConstants.SYSDEFAULT_TAXDEDUCTIBLEPERCENTAGE, "FALSE"));

            ACalc.AddParameter("param_tax_deductible_pct", TaxDeductiblePercentageEnabled);

            if (ACalc.GetParameters().Exists("param_currency")
                && (ACalc.GetParameters().Get("param_currency").ToString() == Catalog.GetString("Transaction")))
            {
                ACalc.RemoveParameter("param_currency_name");
                ACalc.AddParameter("param_currency_name",
                    TRemote.MFinance.Reporting.WebConnectors.GetTransactionCurrency(FLedgerNumber, Convert.ToInt32(txtBatchNumber.Text)));
            }

            return true;
        }
        private void ReadControlsManual(TRptCalculator ACalc, TReportActionEnum AReportAction)
        {
            if (AReportAction == TReportActionEnum.raGenerate)
            {
                if (rbtPartner.Checked && (txtDonor.Text == "0000000000"))
                {
                    TVerificationResult VerificationResult = new TVerificationResult(
                        Catalog.GetString("No donor selected."),
                        Catalog.GetString("Please select a donor."),
                        TResultSeverity.Resv_Critical);

                    FPetraUtilsObject.AddVerificationResult(VerificationResult);
                }

                if (rbtExtract.Checked && (txtExtract.Text == ""))
                {
                    TVerificationResult VerificationMessage = new TVerificationResult(
                        Catalog.GetString("Enter an extract name"),
                        Catalog.GetString("No extract name entered!"), TResultSeverity.Resv_Critical);
                    FPetraUtilsObject.AddVerificationResult(VerificationMessage);
                }

                if (txtMinAmount.NumberValueInt > txtMaxAmount.NumberValueInt)
                {
                    TVerificationResult VerificationResult = new TVerificationResult(
                        Catalog.GetString("Gift Limit wrong."),
                        Catalog.GetString("Minimum Amount can't be greater than Maximum Amount."),
                        TResultSeverity.Resv_Critical);
                    FPetraUtilsObject.AddVerificationResult(VerificationResult);
                }

                if (!dtpFromDate.ValidDate() || !dtpToDate.ValidDate())
                {
                    TVerificationResult VerificationResult = new TVerificationResult(
                        Catalog.GetString("Date format problem"),
                        Catalog.GetString("Please check the date entry."),
                        TResultSeverity.Resv_Critical);
                    FPetraUtilsObject.AddVerificationResult(VerificationResult);
                }

                if ((cmbReportType.SelectedItem.ToString() == "Complete")
                    && (dtpFromDate.Date > dtpToDate.Date))
                {
                    TVerificationResult VerificationResult = new TVerificationResult(
                        Catalog.GetString("From date is later than to date."),
                        Catalog.GetString("Please change from date or to date."),
                        TResultSeverity.Resv_Critical);
                    FPetraUtilsObject.AddVerificationResult(VerificationResult);
                }
            }

            ACalc.AddParameter("param_ledger_number_i", FLedgerNumber);
            ACalc.AddParameter("param_donorkey", txtDonor.Text);
            ACalc.AddParameter("param_extract_name", txtExtract.Text);

            //TODO: Calendar vs Financial Date Handling - Confirm that these should not be ledger dates, i.e. allowing for >12 periods and non-calendar period boundaries
            DateTime FromDateThisYear = new DateTime(DateTime.Today.Year, 1, 1);
            DateTime ToDatePreviousYear = new DateTime(DateTime.Today.Year - 1, 12, 31);
            DateTime FromDatePreviousYear = new DateTime(DateTime.Today.Year - 1, 1, 1);

            ACalc.AddParameter("param_end_date_this_year", DateTime.Today);
            ACalc.AddParameter("param_start_date_this_year", FromDateThisYear);
            ACalc.AddParameter("param_end_date_previous_year", ToDatePreviousYear);
            ACalc.AddParameter("param_start_date_previous_year", FromDatePreviousYear);

            if (cmbReportType.SelectedItem.ToString() == "Totals")
            {
                DateTime FromDate = new DateTime(DateTime.Today.Year - 3, 1, 1);
                ACalc.RemoveParameter("param_from_date");
                ACalc.RemoveParameter("param_to_date");
                ACalc.AddParameter("param_from_date", FromDate);
                ACalc.AddParameter("param_to_date", DateTime.Today);

                ACalc.AddParameter("Month0", 1);
                ACalc.AddParameter("Month1", 2);
                ACalc.AddParameter("Year0", DateTime.Today.Year);
                ACalc.AddParameter("Year1", DateTime.Today.Year - 1);
                ACalc.AddParameter("Year2", DateTime.Today.Year - 2);
                ACalc.AddParameter("Year3", DateTime.Today.Year - 3);

                int ColumnCounter = 0;
                ACalc.AddParameter("param_calculation", "Month", ColumnCounter);
                ACalc.AddParameter("ColumnWidth", (float)3.0, ColumnCounter);
                ++ColumnCounter;
                ACalc.AddParameter("param_calculation", "Year-0", ColumnCounter);
                ACalc.AddParameter("ColumnWidth", (float)2.0, ColumnCounter);
                ++ColumnCounter;
                ACalc.AddParameter("param_calculation", "Count-0", ColumnCounter);
                ACalc.AddParameter("ColumnWidth", (float)0.8, ColumnCounter);
                ++ColumnCounter;
                ACalc.AddParameter("param_calculation", "Year-1", ColumnCounter);
                ACalc.AddParameter("ColumnWidth", (float)2.0, ColumnCounter);
                ++ColumnCounter;
                ACalc.AddParameter("param_calculation", "Count-1", ColumnCounter);
                ACalc.AddParameter("ColumnWidth", (float)0.8, ColumnCounter);
                ++ColumnCounter;
                ACalc.AddParameter("param_calculation", "Year-2", ColumnCounter);
                ACalc.AddParameter("ColumnWidth", (float)2.0, ColumnCounter);
                ++ColumnCounter;
                ACalc.AddParameter("param_calculation", "Count-2", ColumnCounter);
                ACalc.AddParameter("ColumnWidth", (float)0.8, ColumnCounter);
                ++ColumnCounter;
                ACalc.AddParameter("param_calculation", "Year-3", ColumnCounter);
                ACalc.AddParameter("ColumnWidth", (float)2.0, ColumnCounter);
                ++ColumnCounter;
                ACalc.AddParameter("param_calculation", "Count-3", ColumnCounter);
                ACalc.AddParameter("ColumnWidth", (float)0.8, ColumnCounter);
                ++ColumnCounter;
                ACalc.SetMaxDisplayColumns(ColumnCounter);
            }
            else
            {
                int MaxColumns = ACalc.GetParameters().Get("MaxDisplayColumns").ToInt();

                for (int Counter = 0; Counter <= MaxColumns; ++Counter)
                {
                    String ColumnName = ACalc.GetParameters().Get("param_calculation", Counter, 0).ToString();

                    if (ColumnName == "Gift Amount")
                    {
                        ACalc.AddParameter("param_gift_amount_column", Counter);
                    }
                }
            }
        }
        private void ReadControlsManual(TRptCalculator ACalc, TReportActionEnum AReportAction)
        {
            ACalc.AddParameter("param_ledger_number_i", FLedgerNumber);

            int MaxColumns = ACalc.GetParameters().Get("MaxDisplayColumns").ToInt();

            for (int Counter = 0; Counter <= MaxColumns; ++Counter)
            {
                String ColumnName = ACalc.GetParameters().Get("param_calculation", Counter, 0).ToString();

                if (ColumnName == "Total Gifts")
                {
                    ACalc.AddParameter("param_gift_amount_column", Counter);
                }
            }

            // this parameter is added incorrectly by the generated code
            ACalc.RemoveParameter("param_minimum_amount");
            ACalc.AddParameter("param_minimum_amount", this.txtMinimumAmount.NumberValueDecimal);
        }
        //
        // This will be called if the Fast Reports Wrapper loaded OK.
        // Returns True if the data apparently loaded OK and the report should be printed.
        private bool LoadReportData(TRptCalculator ACalc)
        {
            //
            // I need to get the name of the current ledger..

            DataTable LedgerNameTable = TDataCache.TMFinance.GetCacheableFinanceTable(TCacheableFinanceTablesEnum.LedgerNameList);
            DataView LedgerView = new DataView(LedgerNameTable);

            LedgerView.RowFilter = "LedgerNumber=" + FLedgerNumber;
            String LedgerName = "";

            if (LedgerView.Count > 0)
            {
                LedgerName = LedgerView[0].Row["LedgerName"].ToString();
            }

            if (!Int32.TryParse(txtBatchNumber.Text, out FBatchNumber))
            {
                MessageBox.Show(
                    Catalog.GetString("Fault: No valid Batch number"),
                    Catalog.GetString("Gift Batch Detail"));
                return false;
            }

            ACalc.AddStringParameter("param_ledger_name", LedgerName);
            ACalc.AddStringParameter("param_linked_partner_cc", ""); // I may want to use this for auto_email, but usually it's unused.

            if (ACalc.GetParameters().Exists("param_currency")
                && (ACalc.GetParameters().Get("param_currency").ToString() == Catalog.GetString("Transaction")))
            {
                ACalc.RemoveParameter("param_currency_name");
                ACalc.AddParameter("param_currency_name",
                    TRemote.MFinance.Reporting.WebConnectors.GetTransactionCurrency(FLedgerNumber, FBatchNumber));
            }

            ACalc.AddParameter("param_ledger_number_i", FLedgerNumber);
            ACalc.AddParameter("param_batch_number_i", FBatchNumber);


            ArrayList reportParam = ACalc.GetParameters().Elems;

            Dictionary <String, TVariant>paramsDictionary = new Dictionary <string, TVariant>();

            foreach (Shared.MReporting.TParameter p in reportParam)
            {
                if (p.name.StartsWith("param") && (p.name != "param_calculation") && (!paramsDictionary.ContainsKey(p.name)))
                {
                    paramsDictionary.Add(p.name, p.value);
                }
            }

            DataTable ReportTable = TRemote.MReporting.WebConnectors.GetReportDataTable("GiftBatchDetail", paramsDictionary);

            if (this.IsDisposed) // There's no cancel function as such - if the user has pressed Esc the form is closed!
            {
                return false;
            }

            if (ReportTable == null)
            {
                FPetraUtilsObject.WriteToStatusBar("Report Cancelled.");
                return false;
            }

            FPetraUtilsObject.FFastReportsPlugin.RegisterData(ReportTable, "GiftBatchDetail");

            return true;
        }