feat(ui): add drawing selection form

Added DrawingSelectionForm to allow users to select equipment and drawing at application startup, replacing the previous workflow where drawing selection happened within the main form.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-11-03 06:46:32 -05:00
parent 51bf3b00dd
commit 9b1fbd9fad
3 changed files with 544 additions and 0 deletions

View File

@@ -0,0 +1,255 @@
namespace ExportDXF.Forms
{
partial class DrawingSelectionForm
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.equipmentLabel = new System.Windows.Forms.Label();
this.equipmentComboBox = new System.Windows.Forms.ComboBox();
this.drawingLabel = new System.Windows.Forms.Label();
this.drawingComboBox = new System.Windows.Forms.ComboBox();
this.newDrawingButton = new System.Windows.Forms.Button();
this.newDrawingPanel = new System.Windows.Forms.Panel();
this.qtyNumericUpDown = new System.Windows.Forms.NumericUpDown();
this.qtyLabel = new System.Windows.Forms.Label();
this.descriptionTextBox = new System.Windows.Forms.TextBox();
this.descriptionLabel = new System.Windows.Forms.Label();
this.drawingNumberTextBox = new System.Windows.Forms.TextBox();
this.drawingNumberLabel = new System.Windows.Forms.Label();
this.okButton = new System.Windows.Forms.Button();
this.cancelButton = new System.Windows.Forms.Button();
this.statusLabel = new System.Windows.Forms.Label();
this.newDrawingPanel.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.qtyNumericUpDown)).BeginInit();
this.SuspendLayout();
//
// equipmentLabel
//
this.equipmentLabel.AutoSize = true;
this.equipmentLabel.Location = new System.Drawing.Point(12, 15);
this.equipmentLabel.Name = "equipmentLabel";
this.equipmentLabel.Size = new System.Drawing.Size(82, 17);
this.equipmentLabel.TabIndex = 0;
this.equipmentLabel.Text = "Equipment #";
//
// equipmentComboBox
//
this.equipmentComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.equipmentComboBox.FormattingEnabled = true;
this.equipmentComboBox.Location = new System.Drawing.Point(100, 12);
this.equipmentComboBox.Name = "equipmentComboBox";
this.equipmentComboBox.Size = new System.Drawing.Size(350, 25);
this.equipmentComboBox.TabIndex = 1;
this.equipmentComboBox.SelectedIndexChanged += new System.EventHandler(this.equipmentComboBox_SelectedIndexChanged);
//
// drawingLabel
//
this.drawingLabel.AutoSize = true;
this.drawingLabel.Location = new System.Drawing.Point(12, 48);
this.drawingLabel.Name = "drawingLabel";
this.drawingLabel.Size = new System.Drawing.Size(68, 17);
this.drawingLabel.TabIndex = 2;
this.drawingLabel.Text = "Drawing #";
//
// drawingComboBox
//
this.drawingComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.drawingComboBox.FormattingEnabled = true;
this.drawingComboBox.Location = new System.Drawing.Point(100, 45);
this.drawingComboBox.Name = "drawingComboBox";
this.drawingComboBox.Size = new System.Drawing.Size(250, 25);
this.drawingComboBox.TabIndex = 3;
//
// newDrawingButton
//
this.newDrawingButton.Location = new System.Drawing.Point(356, 44);
this.newDrawingButton.Name = "newDrawingButton";
this.newDrawingButton.Size = new System.Drawing.Size(94, 27);
this.newDrawingButton.TabIndex = 4;
this.newDrawingButton.Text = "New Drawing";
this.newDrawingButton.UseVisualStyleBackColor = true;
this.newDrawingButton.Click += new System.EventHandler(this.newDrawingButton_Click);
//
// newDrawingPanel
//
this.newDrawingPanel.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.newDrawingPanel.Controls.Add(this.qtyNumericUpDown);
this.newDrawingPanel.Controls.Add(this.qtyLabel);
this.newDrawingPanel.Controls.Add(this.descriptionTextBox);
this.newDrawingPanel.Controls.Add(this.descriptionLabel);
this.newDrawingPanel.Controls.Add(this.drawingNumberTextBox);
this.newDrawingPanel.Controls.Add(this.drawingNumberLabel);
this.newDrawingPanel.Location = new System.Drawing.Point(15, 85);
this.newDrawingPanel.Name = "newDrawingPanel";
this.newDrawingPanel.Size = new System.Drawing.Size(435, 120);
this.newDrawingPanel.TabIndex = 5;
this.newDrawingPanel.Visible = false;
//
// qtyNumericUpDown
//
this.qtyNumericUpDown.Location = new System.Drawing.Point(115, 80);
this.qtyNumericUpDown.Maximum = new decimal(new int[] {
10000,
0,
0,
0});
this.qtyNumericUpDown.Minimum = new decimal(new int[] {
1,
0,
0,
0});
this.qtyNumericUpDown.Name = "qtyNumericUpDown";
this.qtyNumericUpDown.Size = new System.Drawing.Size(100, 25);
this.qtyNumericUpDown.TabIndex = 5;
this.qtyNumericUpDown.Value = new decimal(new int[] {
1,
0,
0,
0});
//
// qtyLabel
//
this.qtyLabel.AutoSize = true;
this.qtyLabel.Location = new System.Drawing.Point(10, 82);
this.qtyLabel.Name = "qtyLabel";
this.qtyLabel.Size = new System.Drawing.Size(56, 17);
this.qtyLabel.TabIndex = 4;
this.qtyLabel.Text = "Quantity";
//
// descriptionTextBox
//
this.descriptionTextBox.Location = new System.Drawing.Point(115, 45);
this.descriptionTextBox.Name = "descriptionTextBox";
this.descriptionTextBox.Size = new System.Drawing.Size(300, 25);
this.descriptionTextBox.TabIndex = 3;
//
// descriptionLabel
//
this.descriptionLabel.AutoSize = true;
this.descriptionLabel.Location = new System.Drawing.Point(10, 48);
this.descriptionLabel.Name = "descriptionLabel";
this.descriptionLabel.Size = new System.Drawing.Size(75, 17);
this.descriptionLabel.TabIndex = 2;
this.descriptionLabel.Text = "Description";
//
// drawingNumberTextBox
//
this.drawingNumberTextBox.Location = new System.Drawing.Point(115, 10);
this.drawingNumberTextBox.Name = "drawingNumberTextBox";
this.drawingNumberTextBox.Size = new System.Drawing.Size(300, 25);
this.drawingNumberTextBox.TabIndex = 1;
this.drawingNumberTextBox.TextChanged += new System.EventHandler(this.drawingNumberTextBox_TextChanged);
//
// drawingNumberLabel
//
this.drawingNumberLabel.AutoSize = true;
this.drawingNumberLabel.Location = new System.Drawing.Point(10, 13);
this.drawingNumberLabel.Name = "drawingNumberLabel";
this.drawingNumberLabel.Size = new System.Drawing.Size(99, 17);
this.drawingNumberLabel.TabIndex = 0;
this.drawingNumberLabel.Text = "Drawing Number";
//
// okButton
//
this.okButton.Enabled = false;
this.okButton.Location = new System.Drawing.Point(294, 250);
this.okButton.Name = "okButton";
this.okButton.Size = new System.Drawing.Size(75, 30);
this.okButton.TabIndex = 6;
this.okButton.Text = "OK";
this.okButton.UseVisualStyleBackColor = true;
this.okButton.Click += new System.EventHandler(this.okButton_Click);
//
// cancelButton
//
this.cancelButton.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.cancelButton.Location = new System.Drawing.Point(375, 250);
this.cancelButton.Name = "cancelButton";
this.cancelButton.Size = new System.Drawing.Size(75, 30);
this.cancelButton.TabIndex = 7;
this.cancelButton.Text = "Cancel";
this.cancelButton.UseVisualStyleBackColor = true;
this.cancelButton.Click += new System.EventHandler(this.cancelButton_Click);
//
// statusLabel
//
this.statusLabel.AutoSize = true;
this.statusLabel.Location = new System.Drawing.Point(15, 220);
this.statusLabel.Name = "statusLabel";
this.statusLabel.Size = new System.Drawing.Size(44, 17);
this.statusLabel.TabIndex = 8;
this.statusLabel.Text = "Ready";
//
// DrawingSelectionForm
//
this.AcceptButton = this.okButton;
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None;
this.CancelButton = this.cancelButton;
this.ClientSize = new System.Drawing.Size(464, 291);
this.Controls.Add(this.statusLabel);
this.Controls.Add(this.cancelButton);
this.Controls.Add(this.okButton);
this.Controls.Add(this.newDrawingPanel);
this.Controls.Add(this.newDrawingButton);
this.Controls.Add(this.drawingComboBox);
this.Controls.Add(this.drawingLabel);
this.Controls.Add(this.equipmentComboBox);
this.Controls.Add(this.equipmentLabel);
this.Font = new System.Drawing.Font("Segoe UI", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "DrawingSelectionForm";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "Select Drawing - ExportDXF";
this.newDrawingPanel.ResumeLayout(false);
this.newDrawingPanel.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.qtyNumericUpDown)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.Label equipmentLabel;
private System.Windows.Forms.ComboBox equipmentComboBox;
private System.Windows.Forms.Label drawingLabel;
private System.Windows.Forms.ComboBox drawingComboBox;
private System.Windows.Forms.Button newDrawingButton;
private System.Windows.Forms.Panel newDrawingPanel;
private System.Windows.Forms.TextBox drawingNumberTextBox;
private System.Windows.Forms.Label drawingNumberLabel;
private System.Windows.Forms.TextBox descriptionTextBox;
private System.Windows.Forms.Label descriptionLabel;
private System.Windows.Forms.NumericUpDown qtyNumericUpDown;
private System.Windows.Forms.Label qtyLabel;
private System.Windows.Forms.Button okButton;
private System.Windows.Forms.Button cancelButton;
private System.Windows.Forms.Label statusLabel;
}
}

View File

@@ -0,0 +1,228 @@
using ExportDXF.Services;
using System;
using System.Drawing;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace ExportDXF.Forms
{
public partial class DrawingSelectionForm : Form
{
private readonly ICutFabApiClient _apiClient;
public int? SelectedDrawingId { get; private set; }
public string SelectedDrawingNumber { get; private set; }
public DrawingSelectionForm(ICutFabApiClient apiClient)
{
_apiClient = apiClient ?? throw new ArgumentNullException(nameof(apiClient));
InitializeComponent();
}
protected override async void OnLoad(EventArgs e)
{
base.OnLoad(e);
await LoadEquipmentAsync();
}
private async Task LoadEquipmentAsync()
{
try
{
statusLabel.Text = "Loading equipment...";
statusLabel.ForeColor = Color.Black;
var equipment = await _apiClient.GetEquipmentAsync();
equipmentComboBox.DisplayMember = nameof(CutFabApiClient.ApiEquipment.EquipmentNumber);
equipmentComboBox.ValueMember = nameof(CutFabApiClient.ApiEquipment.ID);
equipmentComboBox.DataSource = equipment;
if (equipment.Count > 0)
{
equipmentComboBox.SelectedIndex = 0;
statusLabel.Text = $"Loaded {equipment.Count} equipment record(s)";
statusLabel.ForeColor = Color.Green;
}
else
{
statusLabel.Text = "No equipment found";
statusLabel.ForeColor = Color.Red;
}
}
catch (Exception ex)
{
statusLabel.Text = $"Error loading equipment: {ex.Message}";
statusLabel.ForeColor = Color.Red;
MessageBox.Show($"Failed to load equipment: {ex.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private async void equipmentComboBox_SelectedIndexChanged(object sender, EventArgs e)
{
await LoadDrawingsAsync();
}
private async Task LoadDrawingsAsync()
{
try
{
var selectedEquipment = equipmentComboBox.SelectedItem as CutFabApiClient.ApiEquipment;
if (selectedEquipment == null)
{
drawingComboBox.DataSource = null;
return;
}
statusLabel.Text = "Loading drawings...";
statusLabel.ForeColor = Color.Black;
var drawings = await _apiClient.GetDrawingsForEquipmentAsync(selectedEquipment.ID);
drawingComboBox.DisplayMember = nameof(CutFabApiClient.ApiDrawingSummary.DrawingNumber);
drawingComboBox.ValueMember = nameof(CutFabApiClient.ApiDrawingSummary.ID);
drawingComboBox.DataSource = drawings;
if (drawings.Count > 0)
{
statusLabel.Text = $"Loaded {drawings.Count} drawing(s)";
statusLabel.ForeColor = Color.Green;
drawingComboBox.Enabled = true;
}
else
{
statusLabel.Text = "No drawings found for this equipment";
statusLabel.ForeColor = Color.DarkBlue;
drawingComboBox.Enabled = false;
}
UpdateOkButtonState();
}
catch (Exception ex)
{
statusLabel.Text = $"Error loading drawings: {ex.Message}";
statusLabel.ForeColor = Color.Red;
}
}
private void newDrawingButton_Click(object sender, EventArgs e)
{
ToggleNewDrawingMode(!newDrawingPanel.Visible);
}
private void ToggleNewDrawingMode(bool enabled)
{
newDrawingPanel.Visible = enabled;
drawingComboBox.Enabled = !enabled;
newDrawingButton.Text = enabled ? "Cancel New" : "New Drawing";
if (enabled)
{
drawingNumberTextBox.Focus();
}
UpdateOkButtonState();
}
private void drawingNumberTextBox_TextChanged(object sender, EventArgs e)
{
UpdateOkButtonState();
}
private void UpdateOkButtonState()
{
if (newDrawingPanel.Visible)
{
// Creating new drawing - require drawing number
okButton.Enabled = !string.IsNullOrWhiteSpace(drawingNumberTextBox.Text);
}
else
{
// Selecting existing drawing
okButton.Enabled = drawingComboBox.SelectedItem != null;
}
}
private async void okButton_Click(object sender, EventArgs e)
{
try
{
okButton.Enabled = false;
statusLabel.Text = "Processing...";
statusLabel.ForeColor = Color.Black;
if (newDrawingPanel.Visible)
{
// Create new drawing
await CreateNewDrawingAsync();
}
else
{
// Use existing drawing
var selectedDrawing = drawingComboBox.SelectedItem as CutFabApiClient.ApiDrawingSummary;
if (selectedDrawing != null)
{
SelectedDrawingId = selectedDrawing.ID;
SelectedDrawingNumber = selectedDrawing.DrawingNumber;
DialogResult = DialogResult.OK;
Close();
}
}
}
catch (Exception ex)
{
statusLabel.Text = $"Error: {ex.Message}";
statusLabel.ForeColor = Color.Red;
MessageBox.Show($"Operation failed: {ex.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
okButton.Enabled = true;
}
}
private async Task CreateNewDrawingAsync()
{
var selectedEquipment = equipmentComboBox.SelectedItem as CutFabApiClient.ApiEquipment;
if (selectedEquipment == null)
{
MessageBox.Show("Please select equipment first.", "Validation Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
var drawingNumber = drawingNumberTextBox.Text.Trim();
if (string.IsNullOrWhiteSpace(drawingNumber))
{
MessageBox.Show("Please enter a drawing number.", "Validation Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
statusLabel.Text = "Creating new drawing...";
statusLabel.ForeColor = Color.Black;
var response = await _apiClient.CreateDrawingWithInfoAsync(selectedEquipment.ID, drawingNumber);
if (response.Success && response.Data.HasValue)
{
SelectedDrawingId = response.Data.Value;
SelectedDrawingNumber = drawingNumber;
statusLabel.Text = "Drawing created successfully";
statusLabel.ForeColor = Color.Green;
DialogResult = DialogResult.OK;
Close();
}
else
{
var errorMsg = response.Error ?? "Unknown error occurred";
statusLabel.Text = $"Failed to create drawing: {errorMsg}";
statusLabel.ForeColor = Color.Red;
MessageBox.Show($"Failed to create drawing: {errorMsg}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
okButton.Enabled = true;
}
}
private void cancelButton_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.Cancel;
Close();
}
}
}

View File

@@ -0,0 +1,61 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>