Skip to content

Commit

Permalink
Open In New Window improvement
Browse files Browse the repository at this point in the history
Pass data and parameters.
  • Loading branch information
DavidWiseman committed Nov 10, 2024
1 parent 0dbb573 commit 2045abf
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 22 deletions.
16 changes: 8 additions & 8 deletions DBADashGUI/CustomReports/CustomReportView.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

45 changes: 31 additions & 14 deletions DBADashGUI/CustomReports/CustomReportView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,21 @@ private void SetCellHighlightingRules(DBADashDataGridView dgv)
{
var customReportResult = Report.CustomReportResults[dgv.ResultSetID];
var columnName = dgv.Columns[dgv.ClickedColumnIndex].DataPropertyName;
customReportResult.CellHighlightingRules.TryGetValue(dgv.Columns[dgv.ClickedColumnIndex].DataPropertyName,
customReportResult.CellHighlightingRules.TryGetValue(
dgv.Columns[dgv.ClickedColumnIndex].DataPropertyName,
out var ruleSet);

var frm = new CellHighlightingRulesConfig()
{
ColumnList = dgv.Columns,
CellHighlightingRules = new KeyValuePair<string, CellHighlightingRuleSet>(columnName,
ruleSet.DeepCopy() ?? new CellHighlightingRuleSet() { TargetColumn = columnName }),
CellValue = dgv.ClickedRowIndex >= 0 ? dgv.Rows[dgv.ClickedRowIndex].Cells[dgv.ClickedColumnIndex].Value : null,
CellValue = dgv.ClickedRowIndex >= 0
? dgv.Rows[dgv.ClickedRowIndex].Cells[dgv.ClickedColumnIndex].Value
: null,
CellValueIsNull = dgv.ClickedRowIndex >= 0 &&
dgv.Rows[dgv.ClickedRowIndex].Cells[dgv.ClickedColumnIndex].Value.DBNullToNull() == null
dgv.Rows[dgv.ClickedRowIndex].Cells[dgv.ClickedColumnIndex].Value
.DBNullToNull() == null
};

frm.ShowDialog();
Expand All @@ -81,7 +85,7 @@ private void SetCellHighlightingRules(DBADashDataGridView dgv)
catch (Exception ex)
{
MessageBox.Show("Error setting highlighting rules: " + ex.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error);
MessageBoxIcon.Error);
}
}

Expand Down Expand Up @@ -122,7 +126,7 @@ private void AddLink_Click(DBADashDataGridView dgv)
catch (Exception ex)
{
MessageBox.Show("Error adding link: " + ex.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error);
MessageBoxIcon.Error);
}
}

Expand Down Expand Up @@ -151,12 +155,14 @@ private void ConvertLocalMenuItem_Click(object sender, DBADashDataGridView dgv)
switch (convertLocalMenuItem.Checked)
{
case true when Report.CustomReportResults[dgv.ResultSetID].DoNotConvertToLocalTimeZone.Contains(name):
if (MessageBox.Show("Convert column from UTC to local time?", "Convert?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) return;
if (MessageBox.Show("Convert column from UTC to local time?", "Convert?", MessageBoxButtons.YesNo,
MessageBoxIcon.Question) == DialogResult.No) return;
Report.CustomReportResults[dgv.ResultSetID].DoNotConvertToLocalTimeZone.Remove(name);
break;

case false when !Report.CustomReportResults[dgv.ResultSetID].DoNotConvertToLocalTimeZone.Contains(name):
if (MessageBox.Show("Remove UTC to local time zone conversion for this column?", "Convert?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) return;
if (MessageBox.Show("Remove UTC to local time zone conversion for this column?", "Convert?",
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) return;
Report.CustomReportResults[dgv.ResultSetID].DoNotConvertToLocalTimeZone.Add(name);
break;
}
Expand Down Expand Up @@ -184,12 +190,13 @@ private void RenameColumnMenuItem_Click(DBADashDataGridView dgv)
{
newName = dgv.Columns[dgv.ClickedColumnIndex].DataPropertyName;
}

dgv.Columns[dgv.ClickedColumnIndex].HeaderText = newName;
try
{
var alias = dgv.Columns.Cast<DataGridViewColumn>()
.Where(column => column.DataPropertyName != column.HeaderText)
.ToDictionary(column => column.DataPropertyName, column => column.HeaderText);
.Where(column => column.DataPropertyName != column.HeaderText)
.ToDictionary(column => column.DataPropertyName, column => column.HeaderText);
Report.CustomReportResults[dgv.ResultSetID].ColumnAlias = alias;
Report.Update();
}
Expand Down Expand Up @@ -221,7 +228,9 @@ private void ConvertDateTimeColsToLocalTimeZone(DataSet ds)
if (!Report.CustomReportResults.TryGetValue(i, out var result)) continue;
var dt = ds.Tables[i];
var convertCols = dt.Columns.Cast<DataColumn>()
.Where(column => column.DataType == typeof(DateTime) && !result.DoNotConvertToLocalTimeZone.Contains(column.ColumnName))
.Where(column =>
column.DataType == typeof(DateTime) &&
!result.DoNotConvertToLocalTimeZone.Contains(column.ColumnName))
.Select(column => column.ColumnName).ToList();
if (convertCols.Count > 0)
{
Expand Down Expand Up @@ -274,6 +283,7 @@ public void RefreshData()
MessageBoxIcon.Warning);
return;
}

if (Report is DirectExecutionReport)
{
RefreshDataMessage();
Expand All @@ -283,10 +293,7 @@ public void RefreshData()
StartTimer();
cancellationTokenSource = new CancellationTokenSource();
IsMessageInProgress = true;
Task.Run(() =>
{
_ = RefreshDataRepository(cancellationTokenSource.Token);
});
Task.Run(() => { _ = RefreshDataRepository(cancellationTokenSource.Token); });
}
}

Expand Down Expand Up @@ -347,6 +354,13 @@ public async Task RefreshDataRepository(CancellationToken token)
}
}

public void ShowData(DataSet ds)
{
reportDS = ds;
ShowTable();
LoadResultsCombo();
}

private bool IsMessageInProgress
{
get => tsCancel.Enabled;
Expand Down Expand Up @@ -1377,9 +1391,12 @@ await MessagingHelper.SendMessageAndProcessReply(msg, context, SetStatus, Proces
private void TsNewWindow_Click(object sender, EventArgs e)
{
var frm = new CustomReportViewer();

var ctx = context.DeepCopy();
ctx.Report = Report;
frm.Context = ctx;
frm.DataSet = reportDS;
frm.CustomParams = customParams;
frm.Show();
}
}
Expand Down
7 changes: 7 additions & 0 deletions DBADashGUI/CustomReports/CustomReportViewer.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Data;
using System.Windows.Forms;
using DBADash;

Expand All @@ -16,10 +17,16 @@ public CustomReportViewer()

public List<CustomSqlParameter> CustomParams { get; set; }

public DataSet DataSet;

private async void CustomReportViewer_Load(object sender, EventArgs e)
{
Text = Context.Report.ReportName;
await customReportView1.SetContext(Context, CustomParams);
if(DataSet != null)
{
customReportView1.ShowData(DataSet);
}
}
}
}

0 comments on commit 2045abf

Please sign in to comment.