diff --git a/CutList/CutList.csproj b/CutList/CutList.csproj index 03597cb..843dd39 100644 --- a/CutList/CutList.csproj +++ b/CutList/CutList.csproj @@ -83,7 +83,9 @@ - + + Component + Form @@ -91,16 +93,20 @@ MainForm.cs - + + Form + ResultsForm.cs + - + + MainForm.cs diff --git a/CutList/Forms/MainForm.Designer.cs b/CutList/Forms/MainForm.Designer.cs index 4d53886..efcb291 100644 --- a/CutList/Forms/MainForm.Designer.cs +++ b/CutList/Forms/MainForm.Designer.cs @@ -29,16 +29,14 @@ private void InitializeComponent() { this.components = new System.ComponentModel.Container(); + System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle3 = new System.Windows.Forms.DataGridViewCellStyle(); System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle4 = 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.TotalLength = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.toolStrip1 = new System.Windows.Forms.ToolStrip(); - this.toolStripButton1 = new System.Windows.Forms.ToolStripButton(); - this.saveButton = new System.Windows.Forms.ToolStripButton(); this.toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator(); - this.runButton = new System.Windows.Forms.ToolStripButton(); this.comboBox1 = new System.Windows.Forms.ComboBox(); this.textBox1 = new System.Windows.Forms.TextBox(); this.label3 = new System.Windows.Forms.Label(); @@ -48,15 +46,18 @@ this.tabPage1 = new System.Windows.Forms.TabPage(); this.dataGridView2 = new System.Windows.Forms.DataGridView(); this.TotalLengthString = 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.itemBindingSource = new System.Windows.Forms.BindingSource(this.components); this.lengthInputValueDataGridViewTextBoxColumn = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.quantityDataGridViewTextBoxColumn1 = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.priorityDataGridViewTextBoxColumn = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.binInputItemBindingSource = new System.Windows.Forms.BindingSource(this.components); - this.nameDataGridViewTextBoxColumn = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.lengthDataGridViewTextBoxColumn = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.quantityDataGridViewTextBoxColumn = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.TotalLength = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.toolStripButton2 = new System.Windows.Forms.ToolStripButton(); + this.toolStripButton1 = new System.Windows.Forms.ToolStripButton(); + this.saveButton = new System.Windows.Forms.ToolStripButton(); + this.runButton = new System.Windows.Forms.ToolStripButton(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit(); this.toolStrip1.SuspendLayout(); this.tabControl1.SuspendLayout(); @@ -96,9 +97,22 @@ this.dataGridView1.CellValidated += new System.Windows.Forms.DataGridViewCellEventHandler(this.dataGridView1_CellEndEdit); this.dataGridView1.DataError += new System.Windows.Forms.DataGridViewDataErrorEventHandler(this.dataGridView1_DataError); // + // TotalLength + // + this.TotalLength.DataPropertyName = "TotalLengthString"; + 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; + this.TotalLength.Width = 150; + // // toolStrip1 // this.toolStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.toolStripButton2, this.toolStripButton1, this.saveButton, this.toolStripSeparator1, @@ -109,47 +123,11 @@ this.toolStrip1.TabIndex = 0; this.toolStrip1.Text = "toolStrip1"; // - // toolStripButton1 - // - this.toolStripButton1.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image; - this.toolStripButton1.Image = global::CutList.Properties.Resources.Open_Folder_32; - this.toolStripButton1.ImageScaling = System.Windows.Forms.ToolStripItemImageScaling.None; - this.toolStripButton1.ImageTransparentColor = System.Drawing.Color.Magenta; - this.toolStripButton1.Name = "toolStripButton1"; - this.toolStripButton1.Padding = new System.Windows.Forms.Padding(5, 0, 5, 0); - this.toolStripButton1.Size = new System.Drawing.Size(46, 36); - this.toolStripButton1.Text = "Open"; - this.toolStripButton1.Click += new System.EventHandler(this.toolStripButton1_Click); - // - // saveButton - // - this.saveButton.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image; - this.saveButton.Image = global::CutList.Properties.Resources.Save_32; - this.saveButton.ImageScaling = System.Windows.Forms.ToolStripItemImageScaling.None; - this.saveButton.ImageTransparentColor = System.Drawing.Color.Magenta; - this.saveButton.Name = "saveButton"; - this.saveButton.Padding = new System.Windows.Forms.Padding(5, 0, 5, 0); - this.saveButton.Size = new System.Drawing.Size(46, 36); - this.saveButton.Text = "Save"; - this.saveButton.Click += new System.EventHandler(this.saveButton_Click); - // // toolStripSeparator1 // this.toolStripSeparator1.Name = "toolStripSeparator1"; this.toolStripSeparator1.Size = new System.Drawing.Size(6, 39); // - // runButton - // - this.runButton.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image; - this.runButton.Image = global::CutList.Properties.Resources.Circled_Play_32; - this.runButton.ImageScaling = System.Windows.Forms.ToolStripItemImageScaling.None; - this.runButton.ImageTransparentColor = System.Drawing.Color.Magenta; - this.runButton.Name = "runButton"; - this.runButton.Padding = new System.Windows.Forms.Padding(5, 0, 5, 0); - this.runButton.Size = new System.Drawing.Size(46, 36); - this.runButton.Text = "Run"; - this.runButton.Click += new System.EventHandler(this.runButton_Click); - // // comboBox1 // this.comboBox1.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; @@ -199,6 +177,7 @@ this.tabControl1.Controls.Add(this.tabPage1); this.tabControl1.Location = new System.Drawing.Point(12, 42); this.tabControl1.Name = "tabControl1"; + this.tabControl1.Padding = new System.Drawing.Point(20, 3); this.tabControl1.SelectedIndex = 0; this.tabControl1.Size = new System.Drawing.Size(856, 495); this.tabControl1.TabIndex = 12; @@ -252,7 +231,7 @@ this.dataGridView2.RowHeadersBorderStyle = System.Windows.Forms.DataGridViewHeaderBorderStyle.Single; this.dataGridView2.RowHeadersWidthSizeMode = System.Windows.Forms.DataGridViewRowHeadersWidthSizeMode.DisableResizing; this.dataGridView2.RowTemplate.Height = 26; - this.dataGridView2.Size = new System.Drawing.Size(836, 343); + this.dataGridView2.Size = new System.Drawing.Size(836, 339); this.dataGridView2.TabIndex = 12; this.dataGridView2.CellContentClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.dataGridView2_CellContentClick); this.dataGridView2.CellEndEdit += new System.Windows.Forms.DataGridViewCellEventHandler(this.dataGridView2_CellEndEdit); @@ -266,32 +245,6 @@ this.TotalLengthString.Name = "TotalLengthString"; this.TotalLengthString.ReadOnly = true; // - // itemBindingSource - // - this.itemBindingSource.DataSource = typeof(CutList.Models.Item); - // - // lengthInputValueDataGridViewTextBoxColumn - // - this.lengthInputValueDataGridViewTextBoxColumn.DataPropertyName = "LengthInputValue"; - this.lengthInputValueDataGridViewTextBoxColumn.HeaderText = "Length"; - this.lengthInputValueDataGridViewTextBoxColumn.Name = "lengthInputValueDataGridViewTextBoxColumn"; - // - // quantityDataGridViewTextBoxColumn1 - // - this.quantityDataGridViewTextBoxColumn1.DataPropertyName = "Quantity"; - this.quantityDataGridViewTextBoxColumn1.HeaderText = "Quantity"; - this.quantityDataGridViewTextBoxColumn1.Name = "quantityDataGridViewTextBoxColumn1"; - // - // priorityDataGridViewTextBoxColumn - // - this.priorityDataGridViewTextBoxColumn.DataPropertyName = "Priority"; - this.priorityDataGridViewTextBoxColumn.HeaderText = "Priority"; - this.priorityDataGridViewTextBoxColumn.Name = "priorityDataGridViewTextBoxColumn"; - // - // binInputItemBindingSource - // - this.binInputItemBindingSource.DataSource = typeof(CutList.Models.BinInputItem); - // // nameDataGridViewTextBoxColumn // this.nameDataGridViewTextBoxColumn.DataPropertyName = "Name"; @@ -317,17 +270,79 @@ this.quantityDataGridViewTextBoxColumn.Name = "quantityDataGridViewTextBoxColumn"; this.quantityDataGridViewTextBoxColumn.Width = 50; // - // TotalLength + // itemBindingSource // - this.TotalLength.DataPropertyName = "TotalLengthString"; - 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; - this.TotalLength.Width = 150; + this.itemBindingSource.DataSource = typeof(CutList.Models.PartInputItem); + // + // lengthInputValueDataGridViewTextBoxColumn + // + this.lengthInputValueDataGridViewTextBoxColumn.DataPropertyName = "LengthInputValue"; + this.lengthInputValueDataGridViewTextBoxColumn.HeaderText = "Length"; + this.lengthInputValueDataGridViewTextBoxColumn.Name = "lengthInputValueDataGridViewTextBoxColumn"; + // + // quantityDataGridViewTextBoxColumn1 + // + this.quantityDataGridViewTextBoxColumn1.DataPropertyName = "Quantity"; + this.quantityDataGridViewTextBoxColumn1.HeaderText = "Quantity"; + this.quantityDataGridViewTextBoxColumn1.Name = "quantityDataGridViewTextBoxColumn1"; + // + // priorityDataGridViewTextBoxColumn + // + this.priorityDataGridViewTextBoxColumn.DataPropertyName = "Priority"; + this.priorityDataGridViewTextBoxColumn.HeaderText = "Priority"; + this.priorityDataGridViewTextBoxColumn.Name = "priorityDataGridViewTextBoxColumn"; + // + // binInputItemBindingSource + // + this.binInputItemBindingSource.DataSource = typeof(CutList.Models.BinInputItem); + // + // toolStripButton2 + // + this.toolStripButton2.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image; + this.toolStripButton2.Image = global::CutList.Properties.Resources.gnome_document_new; + this.toolStripButton2.ImageScaling = System.Windows.Forms.ToolStripItemImageScaling.None; + this.toolStripButton2.ImageTransparentColor = System.Drawing.Color.Magenta; + this.toolStripButton2.Name = "toolStripButton2"; + this.toolStripButton2.Padding = new System.Windows.Forms.Padding(5, 0, 5, 0); + this.toolStripButton2.Size = new System.Drawing.Size(46, 36); + this.toolStripButton2.Text = "Open"; + this.toolStripButton2.Click += new System.EventHandler(this.toolStripButton2_Click); + // + // toolStripButton1 + // + this.toolStripButton1.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image; + this.toolStripButton1.Image = global::CutList.Properties.Resources.Open_Folder_32; + this.toolStripButton1.ImageScaling = System.Windows.Forms.ToolStripItemImageScaling.None; + this.toolStripButton1.ImageTransparentColor = System.Drawing.Color.Magenta; + this.toolStripButton1.Name = "toolStripButton1"; + this.toolStripButton1.Padding = new System.Windows.Forms.Padding(5, 0, 5, 0); + this.toolStripButton1.Size = new System.Drawing.Size(46, 36); + this.toolStripButton1.Text = "Open"; + this.toolStripButton1.Click += new System.EventHandler(this.toolStripButton1_Click); + // + // saveButton + // + this.saveButton.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image; + this.saveButton.Image = global::CutList.Properties.Resources.Save_32; + this.saveButton.ImageScaling = System.Windows.Forms.ToolStripItemImageScaling.None; + this.saveButton.ImageTransparentColor = System.Drawing.Color.Magenta; + this.saveButton.Name = "saveButton"; + this.saveButton.Padding = new System.Windows.Forms.Padding(5, 0, 5, 0); + this.saveButton.Size = new System.Drawing.Size(46, 36); + this.saveButton.Text = "Save"; + this.saveButton.Click += new System.EventHandler(this.saveButton_Click); + // + // runButton + // + this.runButton.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image; + this.runButton.Image = global::CutList.Properties.Resources.Circled_Play_32; + this.runButton.ImageScaling = System.Windows.Forms.ToolStripItemImageScaling.None; + this.runButton.ImageTransparentColor = System.Drawing.Color.Magenta; + this.runButton.Name = "runButton"; + this.runButton.Padding = new System.Windows.Forms.Padding(5, 0, 5, 0); + this.runButton.Size = new System.Drawing.Size(46, 36); + this.runButton.Text = "Run"; + this.runButton.Click += new System.EventHandler(this.runButton_Click); // // MainForm // @@ -381,6 +396,7 @@ private System.Windows.Forms.DataGridViewTextBoxColumn lengthDataGridViewTextBoxColumn; private System.Windows.Forms.DataGridViewTextBoxColumn quantityDataGridViewTextBoxColumn; private System.Windows.Forms.DataGridViewTextBoxColumn TotalLength; + private System.Windows.Forms.ToolStripButton toolStripButton2; } } diff --git a/CutList/Forms/MainForm.cs b/CutList/Forms/MainForm.cs index d4bcf8e..4dcaed9 100644 --- a/CutList/Forms/MainForm.cs +++ b/CutList/Forms/MainForm.cs @@ -14,20 +14,21 @@ namespace CutList.Forms { public partial class MainForm : Form { - private BindingList items; + private BindingList parts; private BindingList bins; + private string documentPath; public MainForm() { InitializeComponent(); - items = new BindingList(); + parts = new BindingList(); bins = new BindingList(); dataGridView1.DrawingRowNumbers(); dataGridView2.DrawingRowNumbers(); - itemBindingSource.DataSource = items; + itemBindingSource.DataSource = parts; itemBindingSource.ListChanged += ItemBindingSource_ListChanged; binInputItemBindingSource.DataSource = bins; @@ -66,7 +67,7 @@ namespace CutList.Forms private bool IsValid() { - if (!items.Any(i => i.Length > 0 && i.Quantity > 0)) + if (!parts.Any(i => i.Length > 0 && i.Quantity > 0)) return false; if (!bins.Any(i => i.Length > 0 && i.Quantity > 0)) @@ -93,19 +94,21 @@ namespace CutList.Forms if (openFileDialog.ShowDialog() == DialogResult.OK) { - var data = File.ReadAllText(openFileDialog.FileName); - items = JsonConvert.DeserializeObject>(data); + documentPath = openFileDialog.FileName; + var data = File.ReadAllText(documentPath); + parts = JsonConvert.DeserializeObject>(data); dataGridView1.ClearSelection(); - itemBindingSource.DataSource = items; + itemBindingSource.DataSource = parts; + UpdateRunButtonState(); } } private void Save() { - var itemsToSave = items; + var itemsToSave = parts; - if (dataGridView1.Rows[items.Count - 1].IsNewRow == true) + if (dataGridView1.Rows[parts.Count - 1].IsNewRow == true) itemsToSave.RemoveAt(itemsToSave.Count - 1); var json = JsonConvert.SerializeObject(itemsToSave, Formatting.Indented); @@ -139,11 +142,26 @@ namespace CutList.Forms var items = GetItems(); var result = engine.Pack(items); - var form = new ResultsForm(); + var filename = GetResultsSaveName(); + var form = new ResultsForm(filename); form.Bins = result.Bins; form.ShowDialog(); } + private string GetResultsSaveName() + { + if (documentPath != null) + return Path.GetFileNameWithoutExtension(documentPath); + + var today = DateTime.Today; + var year = today.Year.ToString(); + var month = today.Month.ToString().PadLeft(2, '0'); + var day = today.Day.ToString().PadLeft(2, '0'); + var name = $"Cut List {year}-{month}-{day}"; + + return name; + } + private string ToolsFilePath { get { return Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Data\\Tools.json"); } @@ -161,7 +179,7 @@ namespace CutList.Forms { var items2 = new List(); - foreach (var item in items) + foreach (var item in parts) { if (item.Length == null || item.Length == 0) continue; @@ -288,5 +306,33 @@ namespace CutList.Forms { UpdateRunButtonState(); } + + private void toolStripButton2_Click(object sender, EventArgs e) + { + documentPath = null; + parts = new BindingList(); + bins = new BindingList(); + + dataGridView1.DataSource = parts; + dataGridView2.DataSource = bins; + UpdateRunButtonState(); + } + } + + public class Document + { + public Document() + { + + } + + [JsonIgnore] + public string SavePath { get; set; } + + public List Tools { get; set; } + + public List PartsToNest { get; set; } + + public List StockBins { get; set; } } } \ No newline at end of file diff --git a/CutList/Forms/ResultsForm.Designer.cs b/CutList/Forms/ResultsForm.Designer.cs index dc65731..7e57635 100644 --- a/CutList/Forms/ResultsForm.Designer.cs +++ b/CutList/Forms/ResultsForm.Designer.cs @@ -202,7 +202,7 @@ // // uIItemBindingSource // - this.uIItemBindingSource.DataSource = typeof(CutList.Models.Item); + this.uIItemBindingSource.DataSource = typeof(CutList.Models.PartInputItem); // // menuStrip1 // diff --git a/CutList/Forms/ResultsForm.cs b/CutList/Forms/ResultsForm.cs index 609578b..184f01d 100644 --- a/CutList/Forms/ResultsForm.cs +++ b/CutList/Forms/ResultsForm.cs @@ -10,10 +10,13 @@ namespace CutList.Forms { public partial class ResultsForm : Form { - public ResultsForm() + private string filename; + public ResultsForm(string filename) { InitializeComponent(); dataGridView1.DrawingRowNumbers(); + + this.filename = filename; } private void dataGridView1_RowEnter(object sender, DataGridViewCellEventArgs e) @@ -39,10 +42,7 @@ namespace CutList.Forms { var s = new SaveFileDialog(); - var today = DateTime.Today; - var name = $"{today.Year}-{today.Month.ToString().PadLeft(2, '0')}-{today.Day.ToString().PadLeft(2, '0')} cut list.txt"; - - s.FileName = name; + s.FileName = filename; s.Filter = "Text File|*.txt"; if (s.ShowDialog() != DialogResult.OK) diff --git a/CutList/Models/Item.cs b/CutList/Models/LengthItem.cs similarity index 91% rename from CutList/Models/Item.cs rename to CutList/Models/LengthItem.cs index 3653d2c..90d7ea2 100644 --- a/CutList/Models/Item.cs +++ b/CutList/Models/LengthItem.cs @@ -4,15 +4,6 @@ using System; namespace CutList.Models { - public class Item : LengthItem - { - public Item() - { - } - - public string Name { get; set; } - } - public class LengthItem { public int Quantity { get; set; } = 1; diff --git a/CutList/Models/PartInputItem.cs b/CutList/Models/PartInputItem.cs new file mode 100644 index 0000000..a7f22d4 --- /dev/null +++ b/CutList/Models/PartInputItem.cs @@ -0,0 +1,11 @@ +namespace CutList.Models +{ + public class PartInputItem : LengthItem + { + public PartInputItem() + { + } + + public string Name { get; set; } + } +} \ No newline at end of file diff --git a/CutList/Properties/Resources.Designer.cs b/CutList/Properties/Resources.Designer.cs index 3fc19a8..ed32f2a 100644 --- a/CutList/Properties/Resources.Designer.cs +++ b/CutList/Properties/Resources.Designer.cs @@ -70,6 +70,16 @@ namespace CutList.Properties { } } + /// + /// Looks up a localized resource of type System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap gnome_document_new { + get { + object obj = ResourceManager.GetObject("gnome_document_new", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + /// /// Looks up a localized resource of type System.Drawing.Bitmap. /// diff --git a/CutList/Properties/Resources.resx b/CutList/Properties/Resources.resx index 63af5cd..ad26d49 100644 --- a/CutList/Properties/Resources.resx +++ b/CutList/Properties/Resources.resx @@ -118,13 +118,16 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - ..\Resources\Save-32.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + ..\Resources\Circled Play-32.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a ..\Resources\Open Folder-32.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a - - ..\Resources\Circled Play-32.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + ..\Resources\Save-32.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\gnome_document_new.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a \ No newline at end of file diff --git a/CutList/Resources/gnome_document_new.png b/CutList/Resources/gnome_document_new.png new file mode 100644 index 0000000..0035c41 Binary files /dev/null and b/CutList/Resources/gnome_document_new.png differ