diff --git a/ExportDXF/Forms/DrawingSelectionForm.Designer.cs b/ExportDXF/Forms/DrawingSelectionForm.Designer.cs
new file mode 100644
index 0000000..5ad2ce7
--- /dev/null
+++ b/ExportDXF/Forms/DrawingSelectionForm.Designer.cs
@@ -0,0 +1,255 @@
+namespace ExportDXF.Forms
+{
+ partial class DrawingSelectionForm
+ {
+ ///
+ /// Required designer variable.
+ ///
+ private System.ComponentModel.IContainer components = null;
+
+ ///
+ /// Clean up any resources being used.
+ ///
+ /// true if managed resources should be disposed; otherwise, false.
+ protected override void Dispose(bool disposing)
+ {
+ if (disposing && (components != null))
+ {
+ components.Dispose();
+ }
+ base.Dispose(disposing);
+ }
+
+ #region Windows Form Designer generated code
+
+ ///
+ /// Required method for Designer support - do not modify
+ /// the contents of this method with the code editor.
+ ///
+ 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;
+ }
+}
diff --git a/ExportDXF/Forms/DrawingSelectionForm.cs b/ExportDXF/Forms/DrawingSelectionForm.cs
new file mode 100644
index 0000000..7d766f0
--- /dev/null
+++ b/ExportDXF/Forms/DrawingSelectionForm.cs
@@ -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();
+ }
+ }
+}
diff --git a/ExportDXF/Forms/DrawingSelectionForm.resx b/ExportDXF/Forms/DrawingSelectionForm.resx
new file mode 100644
index 0000000..459ff73
--- /dev/null
+++ b/ExportDXF/Forms/DrawingSelectionForm.resx
@@ -0,0 +1,61 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ text/microsoft-resx
+
+
+ 2.0
+
+
+ System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+