SetDecimalPlaces
    (
        NumericFilterParameters oNumericFilterParameters
    )
    {
        AssertValid();
        Debug.Assert(oNumericFilterParameters != null);

        Int32 iDecimalPlaces = oNumericFilterParameters.DecimalPlaces;

        if (iDecimalPlaces > 0)
        {
            // Start with the number of decimal places displayed in the column
            // plus 1.

            iDecimalPlaces++;

            // Show at least 2.

            iDecimalPlaces = Math.Max(iDecimalPlaces, 2);

            // Don't show more than 6.

            iDecimalPlaces = Math.Min(iDecimalPlaces, 6);
        }

        this.DecimalPlaces = iDecimalPlaces;
    }
 SetUp()
 {
     m_oNumericFilterParameters = new NumericFilterParameters(
         ColumnName, MinimumCellValue, MaximumCellValue, DecimalPlaces);
 }
        //*************************************************************************
        //  Method: GetRangeTrackBarRanges()
        //
        /// <summary>
        /// Gets the ranges to use for a range track bar.
        /// </summary>
        ///
        /// <param name="oNumericFilterParameters">
        /// Parameters for the range track bar.
        /// </param>
        ///
        /// <param name="sTableName">
        /// Name of the table that corresponds to the group box.
        /// </param>
        ///
        /// <param name="decAvailableMinimum">
        /// Where the minimum value in the available range gets stored.
        /// </param>
        ///
        /// <param name="decAvailableMaximum">
        /// Where the maximum value in the available range gets stored.
        /// </param>
        ///
        /// <param name="decSelectedMinimum">
        /// Where the minimum value in the selected range gets stored.
        /// </param>
        ///
        /// <param name="decSelectedMaximum">
        /// Where the maximum value in the selected range gets stored.
        /// </param>
        ///
        /// <param name="sSelectedMinimumAddress">
        /// Where the cell address of the minimum value in the selected range gets
        /// stored.
        /// </param>
        ///
        /// <param name="sSelectedMaximumAddress">
        /// Where the cell address of the maximum value in the selected range gets
        /// stored.
        /// </param>
        //*************************************************************************
        protected void GetRangeTrackBarRanges(
            NumericFilterParameters oNumericFilterParameters,
            String sTableName,
            out Decimal decAvailableMinimum,
            out Decimal decAvailableMaximum,
            out Decimal decSelectedMinimum,
            out Decimal decSelectedMaximum,
            out String sSelectedMinimumAddress,
            out String sSelectedMaximumAddress
            )
        {
            Debug.Assert(oNumericFilterParameters != null);
            Debug.Assert( !String.IsNullOrEmpty(sTableName) );
            AssertValid();

            String sColumnName = oNumericFilterParameters.ColumnName;

            // Excel values are Doubles, but NumericRangeTrackBar values are
            // Decimal.  (That's because NumericRangeTrackBar uses a NumericUpDown
            // control, which can only handle Decimals.)  This can cause problems
            // with very small and very large numbers.
            //
            // For example, the available minimum number 1.54768660209645E-22
            // becomes 1.547687E-22 when converted to a Decimal, and because the
            // Decimal is greater than the Double, using that Decimal for the
            // available minimum would always filter out the edge or vertex row
            // that the 1.54768660209645E-22 came from.
            //
            // Fix this by rounding the available minimum down and the available
            // maximum up if necessary.

            Double dAvailableMinimum = oNumericFilterParameters.MinimumCellValue;
            decAvailableMinimum = (Decimal)dAvailableMinimum;

            if ( (Double)decAvailableMinimum > dAvailableMinimum)
            {
            decAvailableMinimum = Math.Floor(decAvailableMinimum);
            }

            Double dAvailableMaximum = oNumericFilterParameters.MaximumCellValue;
            decAvailableMaximum = (Decimal)dAvailableMaximum;

            if ( (Double)decAvailableMaximum < dAvailableMaximum)
            {
            decAvailableMaximum = Math.Ceiling(decAvailableMaximum);
            }

            // DynamicFilterUtil.GetDynamicFilterParameters() skips zero-width
            // ranges, so this should always be true.

            Debug.Assert(decAvailableMaximum > decAvailableMinimum);

            // If there are already saved selected range settings for this filter
            // and they don't exceed the actual cell values, use them.

            if (
            !m_oDynamicFilterSettings.TryGetSettings(sTableName, sColumnName,
                out decSelectedMinimum, out decSelectedMaximum,
                out sSelectedMinimumAddress, out sSelectedMaximumAddress)
            ||
            decSelectedMinimum < decAvailableMinimum
            ||
            decSelectedMinimum > decAvailableMaximum
            ||
            decSelectedMaximum < decAvailableMinimum
            ||
            decSelectedMaximum > decAvailableMaximum
            )
            {
            // There were no saved selected range settings, or they can't be
            // used.  Set the selected range to the entire available range,
            // then save the settings.

            decSelectedMinimum = decAvailableMinimum;
            decSelectedMaximum = decAvailableMaximum;

            m_oDynamicFilterSettings.SetSettings(sTableName, sColumnName,
                decSelectedMinimum, decSelectedMaximum,
                out sSelectedMinimumAddress, out sSelectedMaximumAddress);
            }

            Debug.Assert(decSelectedMaximum >= decSelectedMinimum);
            Debug.Assert( !String.IsNullOrEmpty(sSelectedMinimumAddress) );
            Debug.Assert( !String.IsNullOrEmpty(sSelectedMaximumAddress) );
        }
        //*************************************************************************
        //  Method: AddRangeTrackBarToGroupBox()
        //
        /// <summary>
        /// Adds a range track bar control to a GroupBox.
        /// </summary>
        ///
        /// <param name="oNumericFilterParameters">
        /// Parameters for the range track bar.
        /// </param>
        ///
        /// <param name="sTableName">
        /// Name of the table that corresponds to the group box.
        /// </param>
        ///
        /// <param name="oGroupBox">
        /// GroupBox to which the range track bar should be added.
        /// </param>
        ///
        /// <param name="oDynamicFilterConditions">
        /// The Excel conditions being built for filtering.
        /// </param>
        ///
        /// <param name="iX">
        /// x-coordinate of the range track bar.
        /// </param>
        ///
        /// <param name="iY">
        /// y-coordinate of the range track bar.  Gets increased by the height of
        /// the range track bar.
        /// </param>
        ///
        /// <returns>
        /// The new range track bar.
        /// </returns>
        //*************************************************************************
        protected IDynamicFilterRangeTrackBar AddRangeTrackBarToGroupBox(
            NumericFilterParameters oNumericFilterParameters,
            String sTableName,
            GroupBox oGroupBox,
            StringBuilder oDynamicFilterConditions,
            Int32 iX,
            ref Int32 iY
            )
        {
            Debug.Assert(oNumericFilterParameters != null);
            Debug.Assert( !String.IsNullOrEmpty(sTableName) );
            Debug.Assert(oGroupBox != null);
            Debug.Assert(oDynamicFilterConditions != null);
            AssertValid();

            String sColumnName = oNumericFilterParameters.ColumnName;

            // Get the ranges to use for the range track bar.

            Decimal decAvailableMinimum, decAvailableMaximum,
            decSelectedMinimum, decSelectedMaximum;

            String sSelectedMinimumAddress, sSelectedMaximumAddress;

            GetRangeTrackBarRanges(oNumericFilterParameters, sTableName,
            out decAvailableMinimum, out decAvailableMaximum,
            out decSelectedMinimum, out decSelectedMaximum,
            out sSelectedMinimumAddress, out sSelectedMaximumAddress);

            // Create a range track bar appropriate for the filter parameters.

            IDynamicFilterRangeTrackBar oDynamicFilterRangeTrackBar;

            if (oNumericFilterParameters is DateTimeFilterParameters)
            {
            oDynamicFilterRangeTrackBar =
                new DynamicFilterDateTimeRangeTrackBar(
                    sTableName, sColumnName);
            }
            else
            {
            oDynamicFilterRangeTrackBar = new DynamicFilterRangeTrackBar(
                sTableName, sColumnName);
            }

            // Set the range track bar's ranges and custom properties.

            oDynamicFilterRangeTrackBar.SetAvailableRange(
            decAvailableMinimum, decAvailableMaximum);

            oDynamicFilterRangeTrackBar.SetSelectedRange(
            decSelectedMinimum, decSelectedMaximum);

            oDynamicFilterRangeTrackBar.SetCustomProperties(
            oNumericFilterParameters);

            // Position the range track bar.

            Debug.Assert(oDynamicFilterRangeTrackBar is Control);

            Control oControl = (Control)oDynamicFilterRangeTrackBar;

            oControl.Location = new Point(iX, iY);
            oControl.Width = oGroupBox.Width - (2 * iX);

            oControl.Anchor = AnchorStyles.Left | AnchorStyles.Top
            | AnchorStyles.Right;

            // Make sure that a bunch of unwanted events during initialization are
            // avoided.

            Debug.Assert(!m_bHandleControlEvents);

            oDynamicFilterRangeTrackBar.SelectedRangeChanged +=
            new EventHandler(this.RangeTrackBar_SelectedRangeChanged);

            oGroupBox.Controls.Add(oControl);

            iY += oControl.Height + DynamicFilterControlBottomMargin;

            // Append a pair of conditions to the Excel conditions.  Sample
            // appended conditions:
            //
            // [ColumnName1] >= Misc!$P$2, [ColumnName1] <= Misc!$Q$2,

            oDynamicFilterConditions.AppendFormat(

            "[{0}] >= {1}!{2}, [{0}] <= {1}!{3},"
            ,
            sColumnName,
            WorksheetNames.Miscellaneous,
            sSelectedMinimumAddress,
            sSelectedMaximumAddress
            );

            return (oDynamicFilterRangeTrackBar);
        }
 public void TearDown()
 {
     m_oNumericFilterParameters = null;
 }
 public void SetUp()
 {
     m_oNumericFilterParameters = new NumericFilterParameters(
     ColumnName, MinimumCellValue, MaximumCellValue, DecimalPlaces);
 }
 //*************************************************************************
 //  Constructor: NumericFilterParametersTest()
 //
 /// <summary>
 /// Initializes a new instance of the <see
 /// cref="NumericFilterParametersTest" /> class.
 /// </summary>
 //*************************************************************************
 public NumericFilterParametersTest()
 {
     m_oNumericFilterParameters = null;
 }