From e9802ce44a65a9529788eece868252c1d38b14b7 Mon Sep 17 00:00:00 2001 From: AJ Date: Sun, 30 Jun 2019 21:02:54 -0400 Subject: [PATCH] Split stock length input into feet and inches boxes --- CutToLength/MainForm.Designer.cs | 99 +++++++++++++++++++++++--------- CutToLength/MainForm.cs | 92 +++++++++++++++++++++++------ 2 files changed, 146 insertions(+), 45 deletions(-) diff --git a/CutToLength/MainForm.Designer.cs b/CutToLength/MainForm.Designer.cs index 98e4e66..44c26dc 100644 --- a/CutToLength/MainForm.Designer.cs +++ b/CutToLength/MainForm.Designer.cs @@ -45,11 +45,14 @@ this.textBox1 = new System.Windows.Forms.TextBox(); this.label3 = new System.Windows.Forms.Label(); this.label4 = new System.Windows.Forms.Label(); + this.feetBox = new System.Windows.Forms.TextBox(); + this.label5 = new System.Windows.Forms.Label(); + this.label6 = new System.Windows.Forms.Label(); + this.inchesBox = new System.Windows.Forms.TextBox(); this.nameDataGridViewTextBoxColumn = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.lengthDataGridViewTextBoxColumn = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.quantityDataGridViewTextBoxColumn = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.itemBindingSource = new System.Windows.Forms.BindingSource(this.components); - this.textBox2 = new System.Windows.Forms.TextBox(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit(); this.toolStrip1.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.itemBindingSource)).BeginInit(); @@ -79,8 +82,9 @@ this.dataGridView1.RowHeadersBorderStyle = System.Windows.Forms.DataGridViewHeaderBorderStyle.Single; this.dataGridView1.RowHeadersWidthSizeMode = System.Windows.Forms.DataGridViewRowHeadersWidthSizeMode.DisableResizing; this.dataGridView1.RowTemplate.Height = 26; - this.dataGridView1.Size = new System.Drawing.Size(763, 361); - this.dataGridView1.TabIndex = 5; + this.dataGridView1.Size = new System.Drawing.Size(822, 349); + this.dataGridView1.TabIndex = 11; + this.dataGridView1.CellValidated += new System.Windows.Forms.DataGridViewCellEventHandler(this.DataGridView1_CellValidated); // // TotalLength // @@ -101,7 +105,7 @@ this.label1.Location = new System.Drawing.Point(21, 101); this.label1.Name = "label1"; this.label1.Size = new System.Drawing.Size(300, 17); - this.label1.TabIndex = 4; + this.label1.TabIndex = 10; this.label1.Text = "Enter the lengths that will be cut from the stock"; // // label2 @@ -112,7 +116,7 @@ this.label2.Location = new System.Drawing.Point(20, 45); this.label2.Name = "label2"; this.label2.Size = new System.Drawing.Size(84, 17); - this.label2.TabIndex = 0; + this.label2.TabIndex = 1; this.label2.Text = "Stock length"; // // toolStrip1 @@ -124,8 +128,8 @@ this.runButton}); this.toolStrip1.Location = new System.Drawing.Point(0, 0); this.toolStrip1.Name = "toolStrip1"; - this.toolStrip1.Size = new System.Drawing.Size(787, 39); - this.toolStrip1.TabIndex = 7; + this.toolStrip1.Size = new System.Drawing.Size(846, 39); + this.toolStrip1.TabIndex = 0; this.toolStrip1.Text = "toolStrip1"; // // toolStripButton1 @@ -173,15 +177,15 @@ // this.comboBox1.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; this.comboBox1.FormattingEnabled = true; - this.comboBox1.Location = new System.Drawing.Point(409, 42); + this.comboBox1.Location = new System.Drawing.Point(478, 42); this.comboBox1.Name = "comboBox1"; this.comboBox1.Size = new System.Drawing.Size(184, 25); - this.comboBox1.TabIndex = 8; + this.comboBox1.TabIndex = 7; this.comboBox1.SelectedIndexChanged += new System.EventHandler(this.comboBox1_SelectedIndexChanged); // // textBox1 // - this.textBox1.Location = new System.Drawing.Point(409, 73); + this.textBox1.Location = new System.Drawing.Point(478, 73); this.textBox1.Name = "textBox1"; this.textBox1.Size = new System.Drawing.Size(184, 25); this.textBox1.TabIndex = 9; @@ -192,10 +196,10 @@ this.label3.AutoSize = true; this.label3.Font = new System.Drawing.Font("Segoe UI Semibold", 9.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.label3.ForeColor = System.Drawing.Color.Blue; - this.label3.Location = new System.Drawing.Point(322, 45); + this.label3.Location = new System.Drawing.Point(391, 45); this.label3.Name = "label3"; this.label3.Size = new System.Drawing.Size(81, 17); - this.label3.TabIndex = 0; + this.label3.TabIndex = 6; this.label3.Text = "Cut method"; // // label4 @@ -203,12 +207,58 @@ this.label4.AutoSize = true; this.label4.Font = new System.Drawing.Font("Segoe UI Semibold", 9.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.label4.ForeColor = System.Drawing.Color.Blue; - this.label4.Location = new System.Drawing.Point(336, 76); + this.label4.Location = new System.Drawing.Point(405, 76); this.label4.Name = "label4"; this.label4.Size = new System.Drawing.Size(67, 17); - this.label4.TabIndex = 0; + this.label4.TabIndex = 8; this.label4.Text = "Cut width"; // + // feetBox + // + this.feetBox.Location = new System.Drawing.Point(110, 42); + this.feetBox.Name = "feetBox"; + this.feetBox.Size = new System.Drawing.Size(53, 25); + this.feetBox.TabIndex = 2; + this.feetBox.Text = "12"; + this.feetBox.TextChanged += new System.EventHandler(this.FeetBox_TextChanged); + this.feetBox.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.TextBox2_KeyPress); + this.feetBox.Validating += new System.ComponentModel.CancelEventHandler(this.TextBox2_Validating); + // + // label5 + // + this.label5.AutoSize = true; + this.label5.Font = new System.Drawing.Font("Segoe UI Semibold", 9.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.label5.ForeColor = System.Drawing.Color.Gray; + this.label5.Location = new System.Drawing.Point(166, 45); + this.label5.Margin = new System.Windows.Forms.Padding(0, 0, 3, 0); + this.label5.Name = "label5"; + this.label5.Size = new System.Drawing.Size(17, 17); + this.label5.TabIndex = 3; + this.label5.Text = "ft"; + // + // label6 + // + this.label6.AutoSize = true; + this.label6.Font = new System.Drawing.Font("Segoe UI Semibold", 9.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.label6.ForeColor = System.Drawing.Color.Gray; + this.label6.Location = new System.Drawing.Point(245, 45); + this.label6.Margin = new System.Windows.Forms.Padding(0, 0, 3, 0); + this.label6.Name = "label6"; + this.label6.Size = new System.Drawing.Size(19, 17); + this.label6.TabIndex = 5; + this.label6.Text = "in"; + // + // inchesBox + // + this.inchesBox.Location = new System.Drawing.Point(189, 42); + this.inchesBox.Name = "inchesBox"; + this.inchesBox.Size = new System.Drawing.Size(53, 25); + this.inchesBox.TabIndex = 4; + this.inchesBox.Text = "0"; + this.inchesBox.TextChanged += new System.EventHandler(this.InchesBox_TextChanged); + this.inchesBox.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.TextBox2_KeyPress); + this.inchesBox.Validating += new System.ComponentModel.CancelEventHandler(this.TextBox2_Validating); + // // nameDataGridViewTextBoxColumn // this.nameDataGridViewTextBoxColumn.DataPropertyName = "Name"; @@ -238,25 +288,19 @@ // this.itemBindingSource.DataSource = typeof(CutToLength.UIItem); // - // textBox2 - // - this.textBox2.Location = new System.Drawing.Point(110, 42); - this.textBox2.Name = "textBox2"; - this.textBox2.Size = new System.Drawing.Size(184, 25); - this.textBox2.TabIndex = 9; - this.textBox2.TextChanged += new System.EventHandler(this.textBox1_TextChanged); - this.textBox2.Validating += new System.ComponentModel.CancelEventHandler(this.TextBox2_Validating); - // // MainForm // this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None; - this.ClientSize = new System.Drawing.Size(787, 496); - this.Controls.Add(this.textBox2); + this.ClientSize = new System.Drawing.Size(846, 484); + this.Controls.Add(this.inchesBox); + this.Controls.Add(this.feetBox); this.Controls.Add(this.textBox1); this.Controls.Add(this.comboBox1); this.Controls.Add(this.toolStrip1); this.Controls.Add(this.label4); + this.Controls.Add(this.label6); this.Controls.Add(this.label3); + this.Controls.Add(this.label5); this.Controls.Add(this.label2); this.Controls.Add(this.label1); this.Controls.Add(this.dataGridView1); @@ -293,7 +337,10 @@ private System.Windows.Forms.TextBox textBox1; private System.Windows.Forms.Label label3; private System.Windows.Forms.Label label4; - private System.Windows.Forms.TextBox textBox2; + private System.Windows.Forms.TextBox feetBox; + private System.Windows.Forms.Label label5; + private System.Windows.Forms.Label label6; + private System.Windows.Forms.TextBox inchesBox; } } diff --git a/CutToLength/MainForm.cs b/CutToLength/MainForm.cs index e042350..b99b1ad 100644 --- a/CutToLength/MainForm.cs +++ b/CutToLength/MainForm.cs @@ -2,6 +2,7 @@ using SimpleExpressionEvaluator; using System; using System.Collections.Generic; +using System.ComponentModel; using System.Data; using System.Diagnostics; using System.Drawing; @@ -13,16 +14,17 @@ namespace CutToLength { public partial class MainForm : Form { - private List items; + private BindingList items; public MainForm() { InitializeComponent(); - items = new List(); + items = new BindingList(); + items.ListChanged += Items_ListChanged; itemBindingSource.DataSource = items; - itemBindingSource.CurrentChanged += ItemBindingSource_CurrentChanged; + itemBindingSource.ListChanged += ItemBindingSource_ListChanged; if (!File.Exists(ToolsFilePath)) { @@ -42,21 +44,28 @@ namespace CutToLength } } + private void ItemBindingSource_ListChanged(object sender, ListChangedEventArgs e) + { + UpdateRunButtonState(); + } + + private void Items_ListChanged(object sender, ListChangedEventArgs e) + { + } + protected override void OnLoad(EventArgs e) { base.OnLoad(e); UpdateRunButtonState(); } - private void ItemBindingSource_CurrentChanged(object sender, EventArgs e) - { - UpdateRunButtonState(); - } - private void UpdateRunButtonState() { - runButton.Enabled = items.Any(i => i.Length > 0 && i.Quantity > 0); - saveButton.Enabled = runButton.Enabled; + var hasItems = items.Any(i => i.Length > 0 && i.Quantity > 0); + var validStockLength = !Double.IsNaN(StockLengthInches); + + runButton.Enabled = hasItems && validStockLength; + saveButton.Enabled = hasItems; } private void Open() @@ -68,7 +77,7 @@ namespace CutToLength if (openFileDialog.ShowDialog() == DialogResult.OK) { var data = File.ReadAllText(openFileDialog.FileName); - items = JsonConvert.DeserializeObject>(data); + items = JsonConvert.DeserializeObject>(data); dataGridView1.ClearSelection(); itemBindingSource.DataSource = items; @@ -91,9 +100,31 @@ namespace CutToLength File.WriteAllText(saveFileDialog.FileName, json); } - private double StockLength + private double StockLengthInches { - get { return double.Parse(textBox2.Text); } + get + { + var feet = GetDouble(feetBox); + var inches = GetDouble(inchesBox); + + return feet * 12 + inches; + } + } + + private double GetDouble(TextBox tb) + { + try + { + var x = double.Parse(tb.Text); + tb.ForeColor = SystemColors.WindowText; + return x; + + } + catch + { + tb.ForeColor = Color.Red; + return double.NaN; + } } private void Run() @@ -117,7 +148,7 @@ namespace CutToLength { var items2 = GetItems().OrderByDescending(i => i.Length); var bins = new List(); - var length = StockLength; + var length = StockLengthInches; foreach (var item in items2) { @@ -162,7 +193,7 @@ namespace CutToLength private Bin CreateBin() { - var length = StockLength; + var length = StockLengthInches; var spacing = GetSelectedTool().Kerf; return new Bin(length) @@ -308,14 +339,37 @@ namespace CutToLength try { var ee = new ExpressionEvaluator(); - var x = ee.Evaluate(textBox2.Text); - textBox2.Text = x.ToString(); - textBox2.ForeColor = SystemColors.WindowText; + var x = ee.Evaluate(feetBox.Text); + feetBox.Text = x.ToString(); + feetBox.ForeColor = SystemColors.WindowText; } catch { - textBox2.ForeColor = Color.Red; + feetBox.ForeColor = Color.Red; } } + + private void TextBox2_KeyPress(object sender, KeyPressEventArgs e) + { + + } + + private void DataGridView1_CellValidated(object sender, DataGridViewCellEventArgs e) + { + UpdateRunButtonState(); + + } + + private void FeetBox_TextChanged(object sender, EventArgs e) + { + UpdateRunButtonState(); + + } + + private void InchesBox_TextChanged(object sender, EventArgs e) + { + UpdateRunButtonState(); + + } } }