mirror of
https://github.com/ajisaacs/OpenNest.git
synced 2026-11-23 12:27:41 -05:00
refactor(grids): add text columns through GridStyle
The saved-nests browser and Get Materials built their text columns with near-identical helpers; GridStyle.AddTextColumn now holds the one copy. Get Materials names its right-aligned numeric columns explicitly, so every column keeps its name, width, alignment and format. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
74e65feb7c
commit
9edc01760b
3 files changed
+46
-62
No files matched your search
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Reflection;
|
||||
using System.Windows.Forms;
|
||||
@@ -54,6 +54,31 @@ public static class GridStyle
|
||||
return grid;
|
||||
}
|
||||
|
||||
/// <summary>Adds a text column to <paramref name="grid"/>, its cells right-aligned when <paramref name="alignRight"/>.</summary>
|
||||
public static DataGridViewTextBoxColumn AddTextColumn(
|
||||
DataGridView grid,
|
||||
string name,
|
||||
string header,
|
||||
int width,
|
||||
Type valueType,
|
||||
bool alignRight = false,
|
||||
string format = null)
|
||||
{
|
||||
var column = new DataGridViewTextBoxColumn
|
||||
{
|
||||
Name = name,
|
||||
HeaderText = header,
|
||||
Width = width,
|
||||
ValueType = valueType,
|
||||
};
|
||||
if (alignRight)
|
||||
column.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;
|
||||
if (format != null)
|
||||
column.DefaultCellStyle.Format = format;
|
||||
grid.Columns.Add(column);
|
||||
return column;
|
||||
}
|
||||
|
||||
private static readonly PropertyInfo KeyboardToolTipProperty = typeof(DataGridView).GetProperty(
|
||||
"KeyboardToolTip", BindingFlags.Instance | BindingFlags.NonPublic);
|
||||
|
||||
|
||||
@@ -64,13 +64,13 @@ public sealed class NestMaterialsForm : Form
|
||||
AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.None,
|
||||
ClipboardCopyMode = DataGridViewClipboardCopyMode.EnableAlwaysIncludeHeaderText,
|
||||
}, sizeColumns: false);
|
||||
AddColumn("Material", 160, typeof(string));
|
||||
AddColumn("Grade", 90, typeof(string));
|
||||
AddColumn("Thickness", 80, typeof(double), "0.####");
|
||||
AddColumn("Units", 50, typeof(string));
|
||||
AddColumn("Size", 130, typeof(string));
|
||||
AddColumn("Quantity", 70, typeof(int), "N0");
|
||||
var nests = AddColumn("Nests", 500, typeof(string));
|
||||
GridStyle.AddTextColumn(grid, "Material", "Material", 160, typeof(string));
|
||||
GridStyle.AddTextColumn(grid, "Grade", "Grade", 90, typeof(string));
|
||||
GridStyle.AddTextColumn(grid, "Thickness", "Thickness", 80, typeof(double), alignRight: true, format: "0.####");
|
||||
GridStyle.AddTextColumn(grid, "Units", "Units", 50, typeof(string));
|
||||
GridStyle.AddTextColumn(grid, "Size", "Size", 130, typeof(string));
|
||||
GridStyle.AddTextColumn(grid, "Quantity", "Quantity", 70, typeof(int), alignRight: true, format: "N0");
|
||||
var nests = GridStyle.AddTextColumn(grid, "Nests", "Nests", 500, typeof(string));
|
||||
nests.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
||||
nests.DefaultCellStyle.WrapMode = DataGridViewTriState.True;
|
||||
grid.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells;
|
||||
@@ -99,23 +99,6 @@ public sealed class NestMaterialsForm : Form
|
||||
FormClosed += (_, _) => cancellation.Cancel();
|
||||
}
|
||||
|
||||
private DataGridViewTextBoxColumn AddColumn(string header, int width, Type valueType, string format = null)
|
||||
{
|
||||
var column = new DataGridViewTextBoxColumn
|
||||
{
|
||||
Name = header,
|
||||
HeaderText = header,
|
||||
Width = width,
|
||||
ValueType = valueType,
|
||||
};
|
||||
if (valueType != typeof(string))
|
||||
column.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;
|
||||
if (format != null)
|
||||
column.DefaultCellStyle.Format = format;
|
||||
grid.Columns.Add(column);
|
||||
return column;
|
||||
}
|
||||
|
||||
private async Task RunAsync()
|
||||
{
|
||||
var token = cancellation.Token;
|
||||
|
||||
@@ -176,12 +176,12 @@ public sealed class SavedNestsForm : Form
|
||||
// Details of the highlighted nest.
|
||||
platesGrid = CreateGrid();
|
||||
platesGrid.RowHeadersVisible = false;
|
||||
AddColumn(platesGrid, "Number", "#", 50, typeof(int), alignRight: true);
|
||||
AddColumn(platesGrid, "Duplicates", "Duplicates", 90, typeof(int), alignRight: true);
|
||||
AddColumn(platesGrid, PlateSizeColumn, "Plate size", 140, typeof(string));
|
||||
AddColumn(platesGrid, "Parts", "Parts", 70, typeof(int), alignRight: true);
|
||||
AddColumn(platesGrid, "Drawings", "Drawings", 80, typeof(int), alignRight: true);
|
||||
AddColumn(platesGrid, "Utilization", "Utilization", 90, typeof(double), alignRight: true, format: "P1");
|
||||
GridStyle.AddTextColumn(platesGrid, "Number", "#", 50, typeof(int), alignRight: true);
|
||||
GridStyle.AddTextColumn(platesGrid, "Duplicates", "Duplicates", 90, typeof(int), alignRight: true);
|
||||
GridStyle.AddTextColumn(platesGrid, PlateSizeColumn, "Plate size", 140, typeof(string));
|
||||
GridStyle.AddTextColumn(platesGrid, "Parts", "Parts", 70, typeof(int), alignRight: true);
|
||||
GridStyle.AddTextColumn(platesGrid, "Drawings", "Drawings", 80, typeof(int), alignRight: true);
|
||||
GridStyle.AddTextColumn(platesGrid, "Utilization", "Utilization", 90, typeof(double), alignRight: true, format: "P1");
|
||||
platesGrid.SelectionChanged += (_, _) =>
|
||||
{
|
||||
// Read the selected row: while this event runs, CurrentRow still names the
|
||||
@@ -192,12 +192,12 @@ public sealed class SavedNestsForm : Form
|
||||
|
||||
drawingsGrid = CreateGrid();
|
||||
drawingsGrid.RowHeadersVisible = false;
|
||||
AddColumn(drawingsGrid, "Drawing", "Drawing", 220, typeof(string));
|
||||
AddColumn(drawingsGrid, "Customer", "Customer", 160, typeof(string));
|
||||
AddColumn(drawingsGrid, "Required", "Required", 80, typeof(int), alignRight: true);
|
||||
AddColumn(drawingsGrid, "Nested", "Nested", 80, typeof(int), alignRight: true);
|
||||
AddColumn(drawingsGrid, "Remaining", "Remaining", 90, typeof(int), alignRight: true);
|
||||
AddColumn(drawingsGrid, AreaColumn, "Area", 100, typeof(double), alignRight: true, format: "0.###");
|
||||
GridStyle.AddTextColumn(drawingsGrid, "Drawing", "Drawing", 220, typeof(string));
|
||||
GridStyle.AddTextColumn(drawingsGrid, "Customer", "Customer", 160, typeof(string));
|
||||
GridStyle.AddTextColumn(drawingsGrid, "Required", "Required", 80, typeof(int), alignRight: true);
|
||||
GridStyle.AddTextColumn(drawingsGrid, "Nested", "Nested", 80, typeof(int), alignRight: true);
|
||||
GridStyle.AddTextColumn(drawingsGrid, "Remaining", "Remaining", 90, typeof(int), alignRight: true);
|
||||
GridStyle.AddTextColumn(drawingsGrid, AreaColumn, "Area", 100, typeof(double), alignRight: true, format: "0.###");
|
||||
|
||||
detailsTabs = new TabControl { Dock = DockStyle.Fill };
|
||||
detailsTabs.TabPages.Add(ControlFactory.Tab("Plates", platesGrid));
|
||||
@@ -423,34 +423,10 @@ public sealed class SavedNestsForm : Form
|
||||
});
|
||||
}
|
||||
|
||||
private static DataGridViewTextBoxColumn AddColumn(
|
||||
DataGridView grid,
|
||||
string name,
|
||||
string header,
|
||||
int width,
|
||||
Type valueType,
|
||||
bool alignRight = false,
|
||||
string format = null)
|
||||
{
|
||||
var column = new DataGridViewTextBoxColumn
|
||||
{
|
||||
Name = name,
|
||||
HeaderText = header,
|
||||
Width = width,
|
||||
ValueType = valueType,
|
||||
};
|
||||
if (alignRight)
|
||||
column.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;
|
||||
if (format != null)
|
||||
column.DefaultCellStyle.Format = format;
|
||||
grid.Columns.Add(column);
|
||||
return column;
|
||||
}
|
||||
|
||||
private void AddNestColumn(string header, NestSortField sortField, int width, bool alignRight = false)
|
||||
{
|
||||
// Cells hold display text: the server has already sorted the page.
|
||||
var column = AddColumn(nestGrid, header, header, width, typeof(string), alignRight);
|
||||
var column = GridStyle.AddTextColumn(nestGrid, header, header, width, typeof(string), alignRight);
|
||||
column.SortMode = DataGridViewColumnSortMode.Programmatic;
|
||||
column.Tag = sortField;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user