private void SetIsExpanded(int RowIndex, bool Expanded) { this.SuspendLayout(); try { if (this.Rows.Count > 0 && this.Rows[0].Cells.Count > 0) { this.CurrentCell = this.Rows[0].Cells[0]; //helps prevent an error when you make the currently selected cell invisible } int iMasterRowIndex = RowIndex; _Expanded[RowIndex] = Expanded; IDtsGridRowData ganttRowData = (IDtsGridRowData)((BindingSource)this.DataSource)[RowIndex]; int iIndent = ganttRowData.Indent; RowIndex++; ganttRowData = (IDtsGridRowData)((BindingSource)this.DataSource)[RowIndex]; while (RowIndex < this.Rows.Count && ganttRowData.Indent > iIndent) { if (!Expanded && this.Rows[RowIndex].Tag == null) { this.Rows[RowIndex].Visible = Expanded; this.Rows[RowIndex].Tag = iMasterRowIndex; } else { if ((this.Rows[RowIndex].Tag as int?) == iMasterRowIndex) { this.Rows[RowIndex].Visible = Expanded; this.Rows[RowIndex].Tag = null; } } RowIndex++; if (RowIndex < this.Rows.Count) { ganttRowData = (IDtsGridRowData)((BindingSource)this.DataSource)[RowIndex]; } else { break; } } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("error in SetIsExpanded for row " + RowIndex + ", Expanded=" + Expanded.ToString() + "\r\n" + ex.Message + "\r\n" + ex.StackTrace); } finally { this.ResumeLayout(); } }
protected override void OnDataBindingComplete(DataGridViewBindingCompleteEventArgs e) { SetupComponent(); int i = 0; bool bResetExpanded = true; if (this.Rows.Count > 0) { IDtsGridRowData dataPackage = ((BindingSource)this.DataSource)[0] as IDtsGridRowData; if (dataPackage != null && dataPackage is DtsObjectPerformance) { if (_LastPackageId == dataPackage.UniqueId && _Expanded.Length == this.Rows.Count) { bResetExpanded = false; } _LastPackageId = dataPackage.UniqueId; } } if (bResetExpanded) { _Expanded = new bool?[this.Rows.Count]; } foreach (object oDataRow in ((BindingSource)this.DataSource)) { IDtsGridRowData ganttRowData = oDataRow as IDtsGridRowData; if (ganttRowData != null) { this.Rows[i].Cells[0].Style.Padding = new Padding((ganttRowData.Indent + 2) * INDENTATION_WIDTH, 2, 2, 2); } if (ganttRowData.Type == typeof(ExecutionTree) && _Expanded[i] != true) { _Expanded[i] = false; SetIsExpanded(i, false); } else if (ganttRowData.Type != typeof(ExecutionTree) && _Expanded[i] == false) { _Expanded[i] = false; SetIsExpanded(i, false); } else { _Expanded[i] = true; } i++; } base.OnDataBindingComplete(e); }
protected override void OnCellMouseUp(DataGridViewCellMouseEventArgs e) { if (((e.Button == MouseButtons.Left)) && ((e.ColumnIndex == 0) && (e.RowIndex >= 0))) { Point location = base.GetCellDisplayRectangle(0, e.RowIndex, false).Location; location.Offset(e.Location); HitTestInfo hitInfo = base.HitTest(location.X, location.Y); if (hitInfo.ColumnIndex != 0) { return; } DataGridViewCell cell = base.Rows[e.RowIndex].Cells[0]; if (e.X < cell.Style.Padding.Left) { IDtsGridRowData ganttRowData = ((BindingSource)this.DataSource)[e.RowIndex] as IDtsGridRowData; if (ganttRowData != null && ganttRowData.HasChildren) { base.EndEdit(); if ((e.X >= ((cell.Style.Padding.Left - BIDSHelper.Resources.Common.Package.Width) - INDENTATION_WIDTH)) && (e.X < (cell.Style.Padding.Left - BIDSHelper.Resources.Common.Package.Width))) { this.SetIsExpanded(e.RowIndex, !this.GetIsExpanded(e.RowIndex)); //this.InvokePaint(this, new PaintEventArgs(this.CreateGraphics(), this.GetColumnDisplayRectangle(1, false))); //don't think this is necessary } } } } else if (e.Button == MouseButtons.Right && e.ColumnIndex == 0 && e.RowIndex >= 0) { IDtsGridRowData rowData = ((BindingSource)this.DataSource)[e.RowIndex] as IDtsGridRowData; if (rowData is DtsPipelinePerformance && this.ParentPerformanceTab != null) { Rectangle rect = this.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, true); this._ContextMenuDataFlowTaskID = (rowData as DtsPipelinePerformance).ID; this.contextMenuBreakdown.Show(this, new Point(e.X, rect.Y + e.Y)); } } base.OnCellMouseUp(e); }
protected override void OnRowPostPaint(DataGridViewRowPostPaintEventArgs e) { if (_History.Count == 0 || _History[_History.Count - 1].Count <= e.RowIndex) { return; } IDtsGridRowData ganttRowData = _History[_History.Count - 1][e.RowIndex] as IDtsGridRowData; if (ganttRowData == null) { return; } long iAvgTotal = 0; int iAvgCount = 0; for (int i = _History.Count - 1; i >= 0; i--) { //find matching UniqueId DataGridViewCell cell = Rows[e.RowIndex].Cells[_History.Count - i]; IDtsGridRowData dataThisColumn = null; foreach (IDtsGridRowData data in _History[i]) { if (data.UniqueId == ganttRowData.UniqueId) { dataThisColumn = data; int?iTotalSeconds = data.TotalSeconds; if (iTotalSeconds != null) { cell.Value = ((float)iTotalSeconds).ToString("F0"); iAvgCount++; iAvgTotal += (long)iTotalSeconds; } cell.Style.ForeColor = (data.IsError ? Color.Red : Color.Black); break; } } Bitmap bmp = null; if (i - 1 >= 0 && dataThisColumn != null) { foreach (IDtsGridRowData data in _History[i - 1]) { if (data.UniqueId == dataThisColumn.UniqueId) { int?iDataTotalSeconds = data.TotalSeconds; int?iMainTotalSeconds = dataThisColumn.TotalSeconds; if (iDataTotalSeconds == null || iMainTotalSeconds == null) { break; } else if (iMainTotalSeconds > iDataTotalSeconds) { bmp = BIDSHelper.Resources.Common.arrowUp; } else if (iMainTotalSeconds < iDataTotalSeconds) { bmp = BIDSHelper.Resources.Common.arrowDown; } else { bmp = BIDSHelper.Resources.Common.arrowFlat; } break; } } } if (_History.Count > 1) { cell.Style.Padding = new Padding(2, 2, 18, 2); } if (bmp != null) { Rectangle rectangle2 = base.GetCellDisplayRectangle(cell.ColumnIndex, e.RowIndex, false); int num4 = this.Columns[cell.ColumnIndex].Width - rectangle2.Width; e.Graphics.SetClip(rectangle2); int y = Math.Max(0, (rectangle2.Y + (rectangle2.Height / 2)) - (bmp.Height / 2) - 1); e.Graphics.DrawImage(bmp, rectangle2.Right - bmp.Width - num4 - 2, y); e.Graphics.ResetClip(); } } if (_History.Count > 1 && iAvgCount > 0) { //fill in average column DataGridViewCell cell = Rows[e.RowIndex].Cells[this.Columns.Count - 1]; cell.Value = ((float)(((float)iAvgTotal) / iAvgCount)).ToString("F2"); } base.OnRowPostPaint(e); }
private void DrawGanttBar(DataGridViewCellPaintingEventArgs e, int RowIndex) { Graphics graphics = e.Graphics; if (listRowBitmaps == null) { return; } if (listRowBitmaps.Count > RowIndex && listRowBitmaps[RowIndex] != null) { RectangleF clipRectangle = base.GetCellDisplayRectangle(1, RowIndex, false); graphics.DrawImage(listRowBitmaps[RowIndex], e.CellBounds.X, e.CellBounds.Y); return; } IDtsGridRowData dataPackage = (IDtsGridRowData)((BindingSource)DataSource)[0]; if (dataPackage.DateRanges.Count > 0) { TimeSpan tsTotal; if (dataPackage.DateRanges[0].EndDate > DateTime.MinValue) { tsTotal = dataPackage.DateRanges[0].EndDate.Subtract(dataPackage.DateRanges[0].StartDate); } else { tsTotal = _DataBindingDate.Subtract(dataPackage.DateRanges[0].StartDate); } if (Columns[1].Width != ((int)(tsTotal.TotalSeconds * PIXELS_PER_SECOND + 2))) { Columns[1].Width = ((int)(tsTotal.TotalSeconds * PIXELS_PER_SECOND + 2)); } RectangleF clipRectangle = base.GetCellDisplayRectangle(1, RowIndex, false); graphics.SetClip(clipRectangle); float height = clipRectangle.Height; int num4 = this.Columns[1].Width - (int)clipRectangle.Width; if (this.IsRowVisible(RowIndex)) { int iRowHeight = Rows[RowIndex].Height; int iBarHeight = iRowHeight - 6; Bitmap canvas = new Bitmap((int)clipRectangle.Width, (int)clipRectangle.Height, e.Graphics); Graphics gBitmap = Graphics.FromImage(canvas); gBitmap.SmoothingMode = SmoothingMode.AntiAlias; gBitmap.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAliasGridFit; IDtsGridRowData data = (IDtsGridRowData)((BindingSource)DataSource)[RowIndex]; DateRange rangePrev = null; int iOverlappingDiamonds = 1; for (int iRange = 0; iRange < data.DateRanges.Count; iRange++) { DateRange range = data.DateRanges[iRange]; TimeSpan tsLeft = range.StartDate.Subtract(dataPackage.DateRanges[0].StartDate); if (data.Type == typeof(PipelinePath)) { int x = (int)(PIXELS_PER_SECOND * tsLeft.TotalSeconds); if (x > 0) { x -= BIDSHelper.Resources.Common.SmallBlueDiamond.Width / 2; } else { x -= 4; } if (rangePrev != null && rangePrev.StartDate == range.StartDate) { iOverlappingDiamonds++; PointF pointDot = new PointF(x, 0); if (iRange == data.DateRanges.Count - 1 || data.DateRanges[iRange + 1].StartDate != range.StartDate) { string s = (iOverlappingDiamonds > 9 ? "+" : iOverlappingDiamonds.ToString()); gBitmap.DrawString(s, FONT_DIAMOND_SUPERSCRIPT, Brushes.DarkBlue, new PointF(x + 7F, -1F)); gBitmap.DrawIcon(BIDSHelper.Resources.Common.SmallBlueDiamond, x, (int)3); } } else { iOverlappingDiamonds = 1; gBitmap.DrawIcon(BIDSHelper.Resources.Common.SmallBlueDiamond, x, (int)3); } } else { TimeSpan tsBar; if (range.EndDate > DateTime.MinValue) { tsBar = range.EndDate.Subtract(range.StartDate); } else { tsBar = _DataBindingDate.Subtract(range.StartDate); } float x = (float)(PIXELS_PER_SECOND * tsLeft.TotalSeconds); float width = (float)(PIXELS_PER_SECOND * tsBar.TotalSeconds); if (width < (float)(iBarHeight) / 2f) { width = (float)(iBarHeight) / 2f; if (x > 0) { x -= width / 2f; } } GraphicsPath path = GetRoundedRectanglePath(x, 2, width, (float)(iBarHeight), (float)((iBarHeight) / 5f)); Color colorDark = (data.IsError ? Color.DarkRed : Color.DarkBlue); Color colorLight = (data.IsError ? Color.Red : Color.Blue); gBitmap.FillPath(new LinearGradientBrush(new Point(0, 2), new Point(0, 2 + iBarHeight), Color.FromArgb(0x80, colorLight), Color.FromArgb(0xe0, colorDark)), path); gBitmap.DrawPath(Pens.Black, path); } rangePrev = range; } //cache the bitmap so the expense of recreating it won't have to happen on scroll of the grid if (listRowBitmaps.Count > RowIndex) { listRowBitmaps[RowIndex] = canvas; clipRectangle = base.GetCellDisplayRectangle(1, RowIndex, false); graphics.DrawImage(listRowBitmaps[RowIndex], e.CellBounds.X, e.CellBounds.Y); } } } graphics.ResetClip(); }
protected override void OnRowPostPaint(DataGridViewRowPostPaintEventArgs e) { if (this.DataSource == null) { return; } IDtsGridRowData ganttRowData = ((BindingSource)this.DataSource)[e.RowIndex] as IDtsGridRowData; if (ganttRowData != null) { Rectangle rectangle2 = base.GetCellDisplayRectangle(0, e.RowIndex, false); int num4 = this.Columns[0].Width - rectangle2.Width; e.Graphics.SetClip(rectangle2); if (ganttRowData.HasChildren) { Icon iconPlusMinus = this.GetIsExpanded(e.RowIndex) ? BIDSHelper.Resources.Common.MinusSign : BIDSHelper.Resources.Common.PlusSign; int y = Math.Max(0, (rectangle2.Y + (rectangle2.Height / 2)) - (iconPlusMinus.Height / 2) - 1); e.Graphics.DrawIcon(iconPlusMinus, (rectangle2.X + (ganttRowData.Indent * INDENTATION_WIDTH)) - num4, y); } Icon icon = null; if (ganttRowData.Type == typeof(Microsoft.SqlServer.Dts.Runtime.Package)) { icon = BIDSHelper.Resources.Common.Package; } else if (ganttRowData.Type == typeof(DtsPipelinePerformance)) { icon = BIDSHelper.Resources.Versioned.DataFlow; } else if (ganttRowData.Type == typeof(ExecutionTree)) { icon = BIDSHelper.Resources.Common.TreeViewTab; } else if (ganttRowData.Type == typeof(PipelinePath)) { icon = BIDSHelper.Resources.Common.Path; } else if (ganttRowData.Type == typeof(DtsPipelineTestDirector.DtsPipelineComponentTest)) { DtsPipelineTestDirector.DtsPipelineComponentTest test = (DtsPipelineTestDirector.DtsPipelineComponentTest)ganttRowData; if (test.TestType == DtsPipelineTestDirector.DtsPipelineComponentTestType.SourceOnly) { icon = BIDSHelper.Resources.Versioned.SourceComponent; } else if (test.TestType == DtsPipelineTestDirector.DtsPipelineComponentTestType.DestinationOnly) { icon = BIDSHelper.Resources.Versioned.DestinationComponent; } else { icon = BIDSHelper.Resources.Common.TaskSmall; } } else { icon = BIDSHelper.Resources.Common.TaskSmall; } if (icon != null) { if (icon.Height > 16 || icon.Width > 16) { try { icon = new Icon(icon, new Size(16, 16)); } catch { } } if (icon.Height > 16 || icon.Width > 16) { //properly deal with 32x32 data flow icon we can't get a 16x16 version with code above int x = (rectangle2.X + (ganttRowData.Indent * INDENTATION_WIDTH)) - num4 + 16; int y = Math.Max(0, (rectangle2.Y + (rectangle2.Height / 2)) - (16 / 2) - 1); e.Graphics.DrawIcon(icon, new Rectangle(x, y, 16, 16)); } else { int x = (rectangle2.X + (ganttRowData.Indent * INDENTATION_WIDTH)) - num4 + icon.Width; int y = Math.Max(0, (rectangle2.Y + (rectangle2.Height / 2)) - (icon.Height / 2) - 1); e.Graphics.DrawIcon(icon, x, y); } } e.Graphics.ResetClip(); Rows[e.RowIndex].Cells[0].Style.ForeColor = (ganttRowData.IsError ? Color.Red : Color.Black); } base.OnRowPostPaint(e); }