Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated to .Net and made main command readers use async /await #169

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/SQLQueryStress/AboutBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,13 @@ FROM sys.databases
Settings for a test, including the query, database information, and parameter assignments, can be saved and re-loaded using the File menu. Keep in mind that all database information is persisted -- do not save sensitive database passwords!";
*/
}

/*
public sealed override string Text
{
get { return base.Text; }
set { base.Text = value; }
}

*/
private void okButton_Click(object sender, EventArgs e)
{
Dispose();
Expand Down
170 changes: 170 additions & 0 deletions src/SQLQueryStress/Controls/GanttChartControl.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Windows.Forms;

namespace SQLQueryStress.Controls
{
public class GanttChartControl : UserControl
{
private VScrollBar _verticalScrollBar;
private HScrollBar _horizontalScrollBar;
private Panel _chartPanel;
private readonly float _timeScale = 20.0f; // pixels per second
private readonly int _rowHeight = 20;
private readonly int _rowSpacing = 4;
private DateTime _ganttStartTime;
private readonly List<GanttItem> _ganttItems = new List<GanttItem>();
private readonly Random _random = new Random(42);

public GanttChartControl()
{
InitializeComponents();
InitializeGanttChart();
}

public void AddGanttItem(GanttItem item)
{
_ganttItems.Add(item);
_chartPanel.Invalidate();
}

public void AddGanttItem(int row, DateTime startTime, int durationMS)
{
_ganttItems.Add(new GanttItem
{
Row = row,
StartTime = startTime,
Duration = TimeSpan.FromMilliseconds(durationMS),
Color = Color.FromArgb(_random.Next(64, 255), _random.Next(64, 255), _random.Next(64, 255))
});
}

public void ClearItems(){
_ganttStartTime = DateTime.Now;
_ganttItems.Clear();
_chartPanel.Invalidate();
}

private void InitializeComponents()
{
// Initialize panel
_chartPanel = new Panel();
_chartPanel.Dock = DockStyle.Fill;
_chartPanel.BackColor = Color.White;
_chartPanel.Paint += GanttChartPanel_Paint;
_chartPanel.Resize += (s, e) => UpdateScrollBars();

// Initialize scroll bars
_verticalScrollBar = new VScrollBar();
_horizontalScrollBar = new HScrollBar();

_verticalScrollBar.Dock = DockStyle.Right;
_horizontalScrollBar.Dock = DockStyle.Bottom;

_verticalScrollBar.Scroll += (s, e) => _chartPanel.Invalidate();
_horizontalScrollBar.Scroll += (s, e) => _chartPanel.Invalidate();

// Add controls
Controls.Add(_chartPanel);
Controls.Add(_verticalScrollBar);
Controls.Add(_horizontalScrollBar);
}

private void InitializeGanttChart()
{
// Create dummy data
_ganttStartTime = DateTime.Now;

UpdateScrollBars();
}

private void UpdateScrollBars()
{
if (_ganttItems.Count == 0) return;

// Calculate content size
var lastEndTime = _ganttItems.Max(x => x.StartTime.Add(x.Duration));
var totalSeconds = (lastEndTime - _ganttStartTime).TotalSeconds;
var contentWidth = (int)(totalSeconds * _timeScale);
var contentHeight = 10 * (_rowHeight + _rowSpacing);

// Update horizontal scrollbar
_horizontalScrollBar.Maximum = Math.Max(0, contentWidth - _chartPanel.Width + _horizontalScrollBar.LargeChange);
_horizontalScrollBar.LargeChange = _chartPanel.Width / 4;
_horizontalScrollBar.SmallChange = _chartPanel.Width / 10;

// Update vertical scrollbar
_verticalScrollBar.Maximum = Math.Max(0, contentHeight - _chartPanel.Height + _verticalScrollBar.LargeChange);
_verticalScrollBar.LargeChange = _chartPanel.Height / 4;
_verticalScrollBar.SmallChange = _rowHeight;
}

private void GanttChartPanel_Paint(object sender, PaintEventArgs e)
{
e.Graphics.Clear(Color.White);

// Apply scrolling offset
e.Graphics.TranslateTransform(-_horizontalScrollBar.Value, -_verticalScrollBar.Value);

// Draw row backgrounds
using (var brush = new SolidBrush(Color.FromArgb(245, 245, 245)))
{
for (int i = 0; i < 10; i++)
{
if (i % 2 == 0) continue;
e.Graphics.FillRectangle(brush, 0, i * (_rowHeight + _rowSpacing),
_chartPanel.Width + _horizontalScrollBar.Value, _rowHeight);
}
}
Debug.WriteLine($"Drawing {_ganttItems.Count} items");
int c = 0;
// Draw items
foreach (var item in _ganttItems.OrderBy(x=>x.Row))
{
var offsetSeconds = (item.StartTime - _ganttStartTime).TotalSeconds;
var x = (float)(offsetSeconds * _timeScale);
var y = item.Row * (_rowHeight + _rowSpacing);
var width = (float)(item.Duration.TotalSeconds * _timeScale);

if (item.Row == 1)
{
Debug.WriteLine($"Drawing {c++},{item.StartTime.Millisecond},{item.Duration.TotalMilliseconds}{x},{y},{width}");
}
using (var brush = new SolidBrush(item.Color))
{
var rect = new RectangleF(x, y, width, _rowHeight);
e.Graphics.FillRectangle(brush, rect);

using (var pen = new Pen(Color.FromArgb(100, 100, 100)))
{
e.Graphics.DrawRectangle(pen, x, y, width, _rowHeight);
}
}
}

// Draw time scale
using (var pen = new Pen(Color.Black))
using (var font = new Font("Arial", 8))
using (var brush = new SolidBrush(Color.Black))
{
for (int i = 0; i <= 60; i += 5)
{
var x = i * _timeScale;
e.Graphics.DrawLine(pen, x, 0, x, 10 * (_rowHeight + _rowSpacing));
e.Graphics.DrawString($"{i}s", font, brush, x, -15);
}
}
}
}

public class GanttItem
{
public int Row { get; set; }
public DateTime StartTime { get; set; }
public TimeSpan Duration { get; set; }
public Color Color { get; set; }
}
}
2 changes: 2 additions & 0 deletions src/SQLQueryStress/DataViewer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System;
using System.Data;
using System.Windows.Forms;
using System.ComponentModel;

#endregion

Expand All @@ -15,6 +16,7 @@ public DataViewer()
InitializeComponent();
}

[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public DataTable DataView { get; set; }

private void Form2_Load(object sender, EventArgs e)
Expand Down
Loading