SetCustomProperties ( DynamicFilterParameters dynamicFilterParameters ) { AssertValid(); Debug.Assert(dynamicFilterParameters != null); Debug.Assert(dynamicFilterParameters is NumericFilterParameters); SetDecimalPlaces((NumericFilterParameters)dynamicFilterParameters); Decimal decSmallChange; if (this.DecimalPlaces == 0) { decSmallChange = 1; } else { decSmallChange = (this.AvailableMaximum - this.AvailableMinimum) / 100; } this.SmallChange = decSmallChange; }
SetCustomProperties ( DynamicFilterParameters dynamicFilterParameters ) { AssertValid(); Debug.Assert(dynamicFilterParameters is DateTimeFilterParameters); DateTimeFilterParameters oDateTimeFilterParameters = (DateTimeFilterParameters)dynamicFilterParameters; // Set the format of the wrapped control based on the Excel column // format. SimpleDateTimeFormat eDateTimeRangeTrackBarFormat = SimpleDateTimeFormat.Date; switch (oDateTimeFilterParameters.Format) { case ExcelColumnFormat.Date: break; case ExcelColumnFormat.Time: eDateTimeRangeTrackBarFormat = SimpleDateTimeFormat.Time; break; case ExcelColumnFormat.DateAndTime: eDateTimeRangeTrackBarFormat = SimpleDateTimeFormat.DateAndTime; break; default: Debug.Assert(false); break; } this.Format = eDateTimeRangeTrackBarFormat; this.SmallChangeMinutes = Math.Max(1, (Decimal)((base.AvailableMaximum - base.AvailableMinimum). TotalMinutes / 100.0)); }
//************************************************************************* // Method: SetCustomProperties() // /// <summary> /// Sets the properties specific to the wrapped control. /// </summary> /// /// <param name="dynamicFilterParameters"> /// Parameters for the range track bar. /// </param> /// /// <remarks> /// The <see cref="DynamicFilterDialog" /> calls this after it has called /// <see cref="IDynamicFilterRangeTrackBar.SetAvailableRange" /> and <see /// cref="IDynamicFilterRangeTrackBar.SetSelectedRange" />. The /// implementation should set any custom properties that are specific to /// the wrapped control and not otherwise exposed via this interface. /// </remarks> //************************************************************************* public void SetCustomProperties( DynamicFilterParameters dynamicFilterParameters ) { AssertValid(); Debug.Assert(dynamicFilterParameters is DateTimeFilterParameters); DateTimeFilterParameters oDateTimeFilterParameters = (DateTimeFilterParameters)dynamicFilterParameters; // Set the format of the wrapped control based on the Excel column // format. SimpleDateTimeFormat eDateTimeRangeTrackBarFormat = SimpleDateTimeFormat.Date; switch (oDateTimeFilterParameters.Format) { case ExcelColumnFormat.Date: break; case ExcelColumnFormat.Time: eDateTimeRangeTrackBarFormat = SimpleDateTimeFormat.Time; break; case ExcelColumnFormat.DateAndTime: eDateTimeRangeTrackBarFormat = SimpleDateTimeFormat.DateAndTime; break; default: Debug.Assert(false); break; } this.Format = eDateTimeRangeTrackBarFormat; this.SmallChangeMinutes = Math.Max(1, (Decimal)( (base.AvailableMaximum - base.AvailableMinimum). TotalMinutes / 100.0 ) ); }
public void TearDown() { m_oDynamicFilterParameters = null; }
public void SetUp() { m_oDynamicFilterParameters = new DynamicFilterParameters(ColumnName); }
//************************************************************************* // Constructor: DynamicFilterParametersTest() // /// <summary> /// Initializes a new instance of the <see /// cref="DynamicFilterParametersTest" /> class. /// </summary> //************************************************************************* public DynamicFilterParametersTest() { m_oDynamicFilterParameters = null; }
//************************************************************************* // Method: AddLabelToGroupBox() // /// <summary> /// Adds a dynamic filter control Label to a GroupBox. /// </summary> /// /// <param name="oDynamicFilterParameters"> /// Parameters for the dynamic filter control. /// </param> /// /// <param name="oGroupBox"> /// GroupBox to which the Label should be added. /// </param> /// /// <param name="iX"> /// x-coordinate of the Label. /// </param> /// /// <param name="iY"> /// y-coordinate of the Label. Note that this does NOT get increased by /// the height of the Label. The histogram, which has the same Top /// coordinate as the Label, is taller than the Label, so /// AddHistogramImageToPictureBox() increases iY, not this method. /// </param> /// /// <returns> /// The new Label. /// </returns> //************************************************************************* protected Label AddLabelToGroupBox( DynamicFilterParameters oDynamicFilterParameters, GroupBox oGroupBox, Int32 iX, Int32 iY ) { Debug.Assert(oGroupBox != null); Debug.Assert(oDynamicFilterParameters != null); AssertValid(); Label oLabel = new Label(); oLabel.Text = oDynamicFilterParameters.ColumnName + ":"; oLabel.Location = new Point(iX, iY); oLabel.Margin = Padding.Empty; oLabel.AutoEllipsis = true; // The actual size of the Label will get set by the caller. oLabel.AutoSize = false; oGroupBox.Controls.Add(oLabel); return (oLabel); }
//************************************************************************* // Method: AddHistogramToGroupBox() // /// <summary> /// Adds a dynamic filter control histogram to a GroupBox. /// </summary> /// /// <param name="sWorksheetName"> /// Name of the worksheet containing the column the histogram is for. /// </param> /// /// <param name="oDynamicFilterParameters"> /// Parameters for the dynamic filter control. /// </param> /// /// <param name="oGroupBox"> /// GroupBox to which the histogram should be added. /// </param> /// /// <param name="iX"> /// x-coordinate of the histogram. /// </param> /// /// <param name="iY"> /// y-coordinate of the histogram. Gets increased by the height of the /// histogram. /// </param> /// /// <returns> /// The new PictureBox that displays the histogram. /// </returns> //************************************************************************* protected PictureBox AddHistogramToGroupBox( String sWorksheetName, DynamicFilterParameters oDynamicFilterParameters, GroupBox oGroupBox, Int32 iX, ref Int32 iY ) { Debug.Assert( !String.IsNullOrEmpty(sWorksheetName) ); Debug.Assert(oDynamicFilterParameters != null); Debug.Assert(oGroupBox != null); AssertValid(); // The histogram is a PictureBox containing an image created by Excel. PictureBoxPlus oPictureBox = new PictureBoxPlus(); oPictureBox.Location = new Point(iX, iY); oPictureBox.Margin = Padding.Empty; oPictureBox.Height = HistogramHeight; oPictureBox.SizeMode = PictureBoxSizeMode.StretchImage; oPictureBox.Anchor = AnchorStyles.Left | AnchorStyles.Top | AnchorStyles.Right; oGroupBox.Controls.Add(oPictureBox); AddHistogramImageToPictureBox(sWorksheetName, oDynamicFilterParameters, oPictureBox); iY += oPictureBox.Height + HistogramBottomMargin; return (oPictureBox); }
//************************************************************************* // Method: AddHistogramImageToPictureBox() // /// <summary> /// Adds a dynamic filter control histogram image to a PictureBox. /// </summary> /// /// <param name="sWorksheetName"> /// Name of the worksheet containing the column the histogram is for. /// </param> /// /// <param name="oDynamicFilterParameters"> /// Parameters for the dynamic filter control. /// </param> /// /// <param name="oPictureBox"> /// The PictureBox to which the histogram image should be added. /// </param> //************************************************************************* protected void AddHistogramImageToPictureBox( String sWorksheetName, DynamicFilterParameters oDynamicFilterParameters, PictureBoxPlus oPictureBox ) { Debug.Assert( !String.IsNullOrEmpty(sWorksheetName) ); Debug.Assert(oDynamicFilterParameters != null); Debug.Assert(oPictureBox != null); AssertValid(); // This method uses the following technique to get Excel to generate // the histogram image. // // There is a hidden chart on the Miscellaneous worksheet that is // used for the histogram. It gets its data from two columns in a // hidden table on the Overall Metrics worksheet that use Excel // formulas to calculate the frequency distribution of the values in an // Excel column, called the "source column." The formulas use Excel's // INDIRECT() function to get the address of the source column from a // cell named NamedRange.DynamicFilterSourceColumnRange. // // In a new workbook, the frequency distribution columns initially // contain all #REF! errors, because the named range is empty. This // method sets the named range to something like // "Vertices[ColumnName]", then forces Excel to recalculate the // frequency distribution columns. This causes a histogram to appear // in the chart. An image of the chart is then copied to the clipboard // and pasted into the PictureBox. Microsoft.Office.Interop.Excel.Worksheet oOverallMetricsWorksheet, oMiscellaneousWorksheet; Microsoft.Office.Interop.Excel.Range oDynamicFilterSourceColumnRange, oDynamicFilterForceCalculationRange; Microsoft.Office.Interop.Excel.Chart oDynamicFilterHistogram; if ( ExcelUtil.TryGetWorksheet(m_oWorkbook, WorksheetNames.OverallMetrics, out oOverallMetricsWorksheet) && ExcelUtil.TryGetNamedRange(oOverallMetricsWorksheet, NamedRangeNames.DynamicFilterSourceColumnRange, out oDynamicFilterSourceColumnRange) && ExcelUtil.TryGetNamedRange(oOverallMetricsWorksheet, NamedRangeNames.DynamicFilterForceCalculationRange, out oDynamicFilterForceCalculationRange) && ExcelUtil.TryGetWorksheet(m_oWorkbook, WorksheetNames.Miscellaneous, out oMiscellaneousWorksheet) && ExcelUtil.TryGetChart(oMiscellaneousWorksheet, ChartNames.DynamicFilterHistogram, out oDynamicFilterHistogram) ) { // Set the named range to the address of the source column. // Sample: "Vertices[Degree]". oDynamicFilterSourceColumnRange.set_Value(Missing.Value, String.Format( "{0}[{1}]", sWorksheetName, oDynamicFilterParameters.ColumnName ) ); // Excel's automatic calculation may be turned off, either by the // user or by code elsewhere in this dialog. Make sure the // frequency distribution columns get calculated. oDynamicFilterForceCalculationRange.Calculate(); // Make sure the chart is drawn immediately. oDynamicFilterHistogram.Refresh(); // Tell Excel to copy the chart image to the clipboard. (Although // the second argument to CopyPicture is xlBitmap, no bitmap gets // copied. Instead, Excel uses an enhanced metafile.) oDynamicFilterHistogram.CopyPicture( Microsoft.Office.Interop.Excel.XlPictureAppearance.xlScreen, Microsoft.Office.Interop.Excel.XlCopyPictureFormat.xlBitmap, Microsoft.Office.Interop.Excel.XlPictureAppearance.xlScreen); oPictureBox.TryPasteEnhancedMetafile(); } }