From a7b0f90a32dcd3319bebeddf2bf33262f6ee6f5d Mon Sep 17 00:00:00 2001 From: aj Date: Thu, 31 May 2018 23:13:14 -0400 Subject: [PATCH] Format total length --- CutToLength/Form1.Designer.cs | 33 ++++++++++++++++----------------- CutToLength/Form1.resx | 3 +++ CutToLength/UIItem.cs | 3 ++- 3 files changed, 21 insertions(+), 18 deletions(-) diff --git a/CutToLength/Form1.Designer.cs b/CutToLength/Form1.Designer.cs index 97324f7..9ad8e3d 100644 --- a/CutToLength/Form1.Designer.cs +++ b/CutToLength/Form1.Designer.cs @@ -29,9 +29,9 @@ private void InitializeComponent() { this.components = new System.ComponentModel.Container(); + System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle3 = new System.Windows.Forms.DataGridViewCellStyle(); System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle1 = new System.Windows.Forms.DataGridViewCellStyle(); System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle2 = new System.Windows.Forms.DataGridViewCellStyle(); - System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle3 = new System.Windows.Forms.DataGridViewCellStyle(); this.dataGridView1 = new System.Windows.Forms.DataGridView(); this.label1 = new System.Windows.Forms.Label(); this.label2 = new System.Windows.Forms.Label(); @@ -43,11 +43,11 @@ this.toolStripButton2 = new System.Windows.Forms.ToolStripButton(); this.toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator(); this.toolStripButton3 = new System.Windows.Forms.ToolStripButton(); - this.itemBindingSource = new System.Windows.Forms.BindingSource(this.components); + this.TotalLength = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.nameDataGridViewTextBoxColumn = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.lengthDataGridViewTextBoxColumn = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.quantityDataGridViewTextBoxColumn = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.totalLengthDataGridViewTextBoxColumn = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.itemBindingSource = new System.Windows.Forms.BindingSource(this.components); ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.numericUpDown2)).BeginInit(); @@ -70,7 +70,7 @@ this.nameDataGridViewTextBoxColumn, this.lengthDataGridViewTextBoxColumn, this.quantityDataGridViewTextBoxColumn, - this.totalLengthDataGridViewTextBoxColumn}); + this.TotalLength}); this.dataGridView1.DataSource = this.itemBindingSource; this.dataGridView1.GridColor = System.Drawing.Color.FromArgb(((int)(((byte)(224)))), ((int)(((byte)(224)))), ((int)(((byte)(224))))); this.dataGridView1.Location = new System.Drawing.Point(12, 122); @@ -204,9 +204,16 @@ this.toolStripButton3.Text = "Run"; this.toolStripButton3.Click += new System.EventHandler(this.toolStripButton3_Click); // - // itemBindingSource + // TotalLength // - this.itemBindingSource.DataSource = typeof(CutToLength.UIItem); + this.TotalLength.DataPropertyName = "TotalLength"; + dataGridViewCellStyle3.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleRight; + dataGridViewCellStyle3.BackColor = System.Drawing.SystemColors.Info; + dataGridViewCellStyle3.Format = "N3"; + this.TotalLength.DefaultCellStyle = dataGridViewCellStyle3; + this.TotalLength.HeaderText = "Total Length"; + this.TotalLength.Name = "TotalLength"; + this.TotalLength.ReadOnly = true; // // nameDataGridViewTextBoxColumn // @@ -233,17 +240,9 @@ this.quantityDataGridViewTextBoxColumn.Name = "quantityDataGridViewTextBoxColumn"; this.quantityDataGridViewTextBoxColumn.Width = 50; // - // totalLengthDataGridViewTextBoxColumn + // itemBindingSource // - this.totalLengthDataGridViewTextBoxColumn.DataPropertyName = "TotalLength"; - dataGridViewCellStyle3.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleRight; - dataGridViewCellStyle3.BackColor = System.Drawing.SystemColors.Info; - dataGridViewCellStyle3.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64))))); - this.totalLengthDataGridViewTextBoxColumn.DefaultCellStyle = dataGridViewCellStyle3; - this.totalLengthDataGridViewTextBoxColumn.HeaderText = "Total Length"; - this.totalLengthDataGridViewTextBoxColumn.Name = "totalLengthDataGridViewTextBoxColumn"; - this.totalLengthDataGridViewTextBoxColumn.ReadOnly = true; - this.totalLengthDataGridViewTextBoxColumn.Width = 120; + this.itemBindingSource.DataSource = typeof(CutToLength.UIItem); // // Form1 // @@ -289,7 +288,7 @@ private System.Windows.Forms.DataGridViewTextBoxColumn nameDataGridViewTextBoxColumn; private System.Windows.Forms.DataGridViewTextBoxColumn lengthDataGridViewTextBoxColumn; private System.Windows.Forms.DataGridViewTextBoxColumn quantityDataGridViewTextBoxColumn; - private System.Windows.Forms.DataGridViewTextBoxColumn totalLengthDataGridViewTextBoxColumn; + private System.Windows.Forms.DataGridViewTextBoxColumn TotalLength; } } diff --git a/CutToLength/Form1.resx b/CutToLength/Form1.resx index 81139af..2ae7c58 100644 --- a/CutToLength/Form1.resx +++ b/CutToLength/Form1.resx @@ -117,6 +117,9 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + True + 17, 17 diff --git a/CutToLength/UIItem.cs b/CutToLength/UIItem.cs index ad4e5cb..cb6e83f 100644 --- a/CutToLength/UIItem.cs +++ b/CutToLength/UIItem.cs @@ -1,4 +1,5 @@ using Newtonsoft.Json; +using System; namespace CutToLength { @@ -15,7 +16,7 @@ namespace CutToLength [JsonIgnore] public double TotalLength { - get { return Length * Quantity; } + get { return Math.Round(Length * Quantity, 8); } } public int Quantity { get; set; } = 1;