From 21e498619c0eebf77d56de974c6925e3f470a03e Mon Sep 17 00:00:00 2001 From: aj Date: Mon, 6 Feb 2017 08:36:35 -0500 Subject: [PATCH] Add project files. --- CutToLength.sln | 22 ++ CutToLength/App.config | 6 + CutToLength/CutToLength.csproj | 106 +++++++ CutToLength/Form1.Designer.cs | 295 ++++++++++++++++++ CutToLength/Form1.cs | 275 ++++++++++++++++ CutToLength/Form1.resx | 126 ++++++++ CutToLength/Program.cs | 22 ++ CutToLength/Properties/AssemblyInfo.cs | 36 +++ .../Properties/DataSources/Item.datasource | 10 + CutToLength/Properties/Resources.Designer.cs | 93 ++++++ CutToLength/Properties/Resources.resx | 130 ++++++++ CutToLength/Properties/Settings.Designer.cs | 30 ++ CutToLength/Properties/Settings.settings | 7 + CutToLength/Resources/Circled Play-32.png | Bin 0 -> 620 bytes CutToLength/Resources/Open Folder-32.png | Bin 0 -> 439 bytes CutToLength/Resources/Save-32.png | Bin 0 -> 438 bytes CutToLength/packages.config | 4 + 17 files changed, 1162 insertions(+) create mode 100644 CutToLength.sln create mode 100644 CutToLength/App.config create mode 100644 CutToLength/CutToLength.csproj create mode 100644 CutToLength/Form1.Designer.cs create mode 100644 CutToLength/Form1.cs create mode 100644 CutToLength/Form1.resx create mode 100644 CutToLength/Program.cs create mode 100644 CutToLength/Properties/AssemblyInfo.cs create mode 100644 CutToLength/Properties/DataSources/Item.datasource create mode 100644 CutToLength/Properties/Resources.Designer.cs create mode 100644 CutToLength/Properties/Resources.resx create mode 100644 CutToLength/Properties/Settings.Designer.cs create mode 100644 CutToLength/Properties/Settings.settings create mode 100644 CutToLength/Resources/Circled Play-32.png create mode 100644 CutToLength/Resources/Open Folder-32.png create mode 100644 CutToLength/Resources/Save-32.png create mode 100644 CutToLength/packages.config diff --git a/CutToLength.sln b/CutToLength.sln new file mode 100644 index 0000000..fc2802a --- /dev/null +++ b/CutToLength.sln @@ -0,0 +1,22 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 14 +VisualStudioVersion = 14.0.25420.1 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CutToLength", "CutToLength\CutToLength.csproj", "{3E82A1E3-07A8-40C4-ABC4-DF24C5120073}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {3E82A1E3-07A8-40C4-ABC4-DF24C5120073}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {3E82A1E3-07A8-40C4-ABC4-DF24C5120073}.Debug|Any CPU.Build.0 = Debug|Any CPU + {3E82A1E3-07A8-40C4-ABC4-DF24C5120073}.Release|Any CPU.ActiveCfg = Release|Any CPU + {3E82A1E3-07A8-40C4-ABC4-DF24C5120073}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/CutToLength/App.config b/CutToLength/App.config new file mode 100644 index 0000000..731f6de --- /dev/null +++ b/CutToLength/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/CutToLength/CutToLength.csproj b/CutToLength/CutToLength.csproj new file mode 100644 index 0000000..76fa617 --- /dev/null +++ b/CutToLength/CutToLength.csproj @@ -0,0 +1,106 @@ + + + + + Debug + AnyCPU + {3E82A1E3-07A8-40C4-ABC4-DF24C5120073} + WinExe + Properties + CutToLength + CutToLength + v4.6.1 + 512 + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll + True + + + + + + + + + + + + + + + + Form + + + Form1.cs + + + + + Form1.cs + + + ResXFileCodeGenerator + Resources.Designer.cs + Designer + + + True + Resources.resx + True + + + + + SettingsSingleFileGenerator + Settings.Designer.cs + + + True + Settings.settings + True + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/CutToLength/Form1.Designer.cs b/CutToLength/Form1.Designer.cs new file mode 100644 index 0000000..ede0fe5 --- /dev/null +++ b/CutToLength/Form1.Designer.cs @@ -0,0 +1,295 @@ +namespace CutToLength +{ + partial class Form1 + { + /// + /// 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.components = new System.ComponentModel.Container(); + 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.itemBindingSource = new System.Windows.Forms.BindingSource(this.components); + this.label1 = new System.Windows.Forms.Label(); + this.label2 = new System.Windows.Forms.Label(); + this.numericUpDown1 = new System.Windows.Forms.NumericUpDown(); + this.label3 = new System.Windows.Forms.Label(); + this.numericUpDown2 = new System.Windows.Forms.NumericUpDown(); + this.toolStrip1 = new System.Windows.Forms.ToolStrip(); + this.toolStripButton1 = new System.Windows.Forms.ToolStripButton(); + this.toolStripButton2 = new System.Windows.Forms.ToolStripButton(); + this.toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator(); + this.toolStripButton3 = new System.Windows.Forms.ToolStripButton(); + 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(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.itemBindingSource)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDown2)).BeginInit(); + this.toolStrip1.SuspendLayout(); + this.SuspendLayout(); + // + // dataGridView1 + // + this.dataGridView1.AllowUserToResizeRows = false; + this.dataGridView1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.dataGridView1.AutoGenerateColumns = false; + this.dataGridView1.BackgroundColor = System.Drawing.Color.White; + this.dataGridView1.ClipboardCopyMode = System.Windows.Forms.DataGridViewClipboardCopyMode.EnableAlwaysIncludeHeaderText; + this.dataGridView1.ColumnHeadersBorderStyle = System.Windows.Forms.DataGridViewHeaderBorderStyle.Single; + this.dataGridView1.ColumnHeadersHeight = 35; + this.dataGridView1.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { + this.nameDataGridViewTextBoxColumn, + this.lengthDataGridViewTextBoxColumn, + this.quantityDataGridViewTextBoxColumn, + this.totalLengthDataGridViewTextBoxColumn}); + 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); + this.dataGridView1.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.dataGridView1.Name = "dataGridView1"; + this.dataGridView1.RowHeadersBorderStyle = System.Windows.Forms.DataGridViewHeaderBorderStyle.Single; + this.dataGridView1.RowHeadersWidthSizeMode = System.Windows.Forms.DataGridViewRowHeadersWidthSizeMode.DisableResizing; + this.dataGridView1.RowTemplate.Height = 30; + this.dataGridView1.Size = new System.Drawing.Size(763, 361); + this.dataGridView1.TabIndex = 5; + // + // itemBindingSource + // + this.itemBindingSource.DataSource = typeof(CutToLength.UIItem); + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Font = new System.Drawing.Font("Segoe UI Semibold", 9.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.label1.ForeColor = System.Drawing.Color.Blue; + 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.Text = "Enter the lengths that will be cut from the stock"; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Font = new System.Drawing.Font("Segoe UI Semibold", 9.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.label2.ForeColor = System.Drawing.Color.Blue; + this.label2.Location = new System.Drawing.Point(21, 50); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(84, 17); + this.label2.TabIndex = 0; + this.label2.Text = "Stock length"; + // + // numericUpDown1 + // + this.numericUpDown1.Location = new System.Drawing.Point(111, 48); + this.numericUpDown1.Maximum = new decimal(new int[] { + 999999, + 0, + 0, + 0}); + this.numericUpDown1.Name = "numericUpDown1"; + this.numericUpDown1.Size = new System.Drawing.Size(139, 25); + this.numericUpDown1.TabIndex = 1; + this.numericUpDown1.Value = new decimal(new int[] { + 240, + 0, + 0, + 0}); + // + // label3 + // + 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(282, 50); + this.label3.Name = "label3"; + this.label3.Size = new System.Drawing.Size(67, 17); + this.label3.TabIndex = 2; + this.label3.Text = "Cut width"; + // + // numericUpDown2 + // + this.numericUpDown2.DecimalPlaces = 4; + this.numericUpDown2.Location = new System.Drawing.Point(355, 48); + this.numericUpDown2.Maximum = new decimal(new int[] { + 999999, + 0, + 0, + 0}); + this.numericUpDown2.Name = "numericUpDown2"; + this.numericUpDown2.Size = new System.Drawing.Size(139, 25); + this.numericUpDown2.TabIndex = 3; + this.numericUpDown2.Value = new decimal(new int[] { + 125, + 0, + 0, + 196608}); + // + // toolStrip1 + // + this.toolStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.toolStripButton1, + this.toolStripButton2, + this.toolStripSeparator1, + this.toolStripButton3}); + 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.Text = "toolStrip1"; + // + // toolStripButton1 + // + this.toolStripButton1.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image; + this.toolStripButton1.Image = global::CutToLength.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); + // + // toolStripButton2 + // + this.toolStripButton2.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image; + this.toolStripButton2.Image = global::CutToLength.Properties.Resources.Save_32; + 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 = "Save"; + this.toolStripButton2.Click += new System.EventHandler(this.toolStripButton2_Click); + // + // toolStripSeparator1 + // + this.toolStripSeparator1.Name = "toolStripSeparator1"; + this.toolStripSeparator1.Size = new System.Drawing.Size(6, 39); + // + // toolStripButton3 + // + this.toolStripButton3.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image; + this.toolStripButton3.Image = global::CutToLength.Properties.Resources.Circled_Play_32; + this.toolStripButton3.ImageScaling = System.Windows.Forms.ToolStripItemImageScaling.None; + this.toolStripButton3.ImageTransparentColor = System.Drawing.Color.Magenta; + this.toolStripButton3.Name = "toolStripButton3"; + this.toolStripButton3.Padding = new System.Windows.Forms.Padding(5, 0, 5, 0); + this.toolStripButton3.Size = new System.Drawing.Size(46, 36); + this.toolStripButton3.Text = "Run"; + this.toolStripButton3.Click += new System.EventHandler(this.toolStripButton3_Click); + // + // nameDataGridViewTextBoxColumn + // + this.nameDataGridViewTextBoxColumn.DataPropertyName = "Name"; + this.nameDataGridViewTextBoxColumn.HeaderText = "Name"; + this.nameDataGridViewTextBoxColumn.Name = "nameDataGridViewTextBoxColumn"; + this.nameDataGridViewTextBoxColumn.Width = 200; + // + // lengthDataGridViewTextBoxColumn + // + this.lengthDataGridViewTextBoxColumn.DataPropertyName = "Length"; + dataGridViewCellStyle1.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleRight; + this.lengthDataGridViewTextBoxColumn.DefaultCellStyle = dataGridViewCellStyle1; + this.lengthDataGridViewTextBoxColumn.HeaderText = "Length"; + this.lengthDataGridViewTextBoxColumn.Name = "lengthDataGridViewTextBoxColumn"; + this.lengthDataGridViewTextBoxColumn.Width = 120; + // + // quantityDataGridViewTextBoxColumn + // + this.quantityDataGridViewTextBoxColumn.DataPropertyName = "Quantity"; + dataGridViewCellStyle2.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleRight; + this.quantityDataGridViewTextBoxColumn.DefaultCellStyle = dataGridViewCellStyle2; + this.quantityDataGridViewTextBoxColumn.HeaderText = "Qty"; + this.quantityDataGridViewTextBoxColumn.Name = "quantityDataGridViewTextBoxColumn"; + this.quantityDataGridViewTextBoxColumn.Width = 50; + // + // totalLengthDataGridViewTextBoxColumn + // + 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; + // + // Form1 + // + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None; + this.ClientSize = new System.Drawing.Size(787, 496); + this.Controls.Add(this.toolStrip1); + this.Controls.Add(this.numericUpDown2); + this.Controls.Add(this.label3); + this.Controls.Add(this.numericUpDown1); + this.Controls.Add(this.label2); + this.Controls.Add(this.label1); + this.Controls.Add(this.dataGridView1); + this.Font = new System.Drawing.Font("Segoe UI", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.MinimumSize = new System.Drawing.Size(570, 457); + this.Name = "Form1"; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; + this.Text = "Cut To Length"; + ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.itemBindingSource)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDown2)).EndInit(); + this.toolStrip1.ResumeLayout(false); + this.toolStrip1.PerformLayout(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + private System.Windows.Forms.DataGridView dataGridView1; + private System.Windows.Forms.BindingSource itemBindingSource; + private System.Windows.Forms.Label label1; + private System.Windows.Forms.Label label2; + private System.Windows.Forms.NumericUpDown numericUpDown1; + private System.Windows.Forms.Label label3; + private System.Windows.Forms.NumericUpDown numericUpDown2; + private System.Windows.Forms.ToolStrip toolStrip1; + private System.Windows.Forms.ToolStripButton toolStripButton1; + private System.Windows.Forms.ToolStripButton toolStripButton2; + private System.Windows.Forms.ToolStripButton toolStripButton3; + private System.Windows.Forms.ToolStripSeparator toolStripSeparator1; + private System.Windows.Forms.DataGridViewTextBoxColumn nameDataGridViewTextBoxColumn; + private System.Windows.Forms.DataGridViewTextBoxColumn lengthDataGridViewTextBoxColumn; + private System.Windows.Forms.DataGridViewTextBoxColumn quantityDataGridViewTextBoxColumn; + private System.Windows.Forms.DataGridViewTextBoxColumn totalLengthDataGridViewTextBoxColumn; + } +} + diff --git a/CutToLength/Form1.cs b/CutToLength/Form1.cs new file mode 100644 index 0000000..075b214 --- /dev/null +++ b/CutToLength/Form1.cs @@ -0,0 +1,275 @@ +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.ComponentModel; +using System.Data; +using System.Diagnostics; +using System.Drawing; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace CutToLength +{ + public partial class Form1 : Form + { + private List items; + + public Form1() + { + InitializeComponent(); + + items = new List(); + + itemBindingSource.DataSource = items; + } + + private void Open() + { + var openFileDialog = new OpenFileDialog(); + openFileDialog.Multiselect = true; + openFileDialog.Filter = "Json File|*.json"; + + if (openFileDialog.ShowDialog() == DialogResult.OK) + { + var data = File.ReadAllText(openFileDialog.FileName); + items = JsonConvert.DeserializeObject>(data); + itemBindingSource.DataSource = items; + } + } + + private void Save() + { + var json = JsonConvert.SerializeObject(items, Formatting.Indented); + + var saveFileDialog = new SaveFileDialog(); + saveFileDialog.Filter = "Json File|*.json"; + + if (saveFileDialog.ShowDialog() == DialogResult.OK) + File.WriteAllText(saveFileDialog.FileName, json); + } + + private void Run() + { + var bins = GetResults(); + + var saveFileDialog = new SaveFileDialog(); + saveFileDialog.Filter = "Text File|*.txt"; + + if (saveFileDialog.ShowDialog() == DialogResult.OK) + { + SaveBins(saveFileDialog.FileName, bins); + } + } + + private List GetResults() + { + var items2 = GetItems().OrderByDescending(i => i.Length); + var bins = new List(); + var length = (double)numericUpDown1.Value; + + foreach (var item in items2) + { + Bin best_bin; + + if (!FindBin(bins.ToArray(), item.Length, out best_bin)) + { + if (item.Length > length) + continue; + + best_bin = CreateBin(); + bins.Add(best_bin); + } + + best_bin.Items.Add(item); + } + + return bins; + } + + private List GetItems() + { + var items2 = new List(); + + foreach (var item in items) + { + for (int i = 0; i < item.Quantity; i++) + { + items2.Add(new BinItem + { + Name = item.Name, + Length = item.Length + }); + } + } + + return items2; + } + + private Bin CreateBin() + { + var length = (double)numericUpDown1.Value; + var spacing = (double)numericUpDown2.Value; + + return new Bin(length) + { + Spacing = spacing + }; + } + + private void SaveBins(string file, IEnumerable bins) + { + var writer = new StreamWriter(file); + writer.AutoFlush = true; + + var max = bins.Max(b => b.Items.Max(i => i.Length.ToString().Length)); + var id = 1; + + foreach (var bin in bins) + { + writer.WriteLine(id++.ToString() + ". " + bin.ToString()); + + var groups = bin.Items.GroupBy(i => i.Name); + + foreach (var group in groups) + { + writer.WriteLine(" {0} {1}\" - {2}", ("(" + group.Count() + ")").PadRight(5), group.First().Length.ToString().PadLeft(max + 2), group.Key); + } + + writer.WriteLine("---------------------------------------------------------------------"); + writer.WriteLine(); + } + + writer.Close(); + + Process.Start(file); + } + + private static bool FindBin(IEnumerable bins, double length, out Bin found) + { + found = null; + + foreach (var bin in bins) + { + if (bin.RemainingLength < length) + continue; + + if (found == null) + found = bin; + + if (bin.RemainingLength < found.RemainingLength) + found = bin; + } + + return (found != null); + } + + private void toolStripButton1_Click(object sender, EventArgs e) + { + Open(); + } + + private void toolStripButton2_Click(object sender, EventArgs e) + { + Save(); + } + + private void toolStripButton3_Click(object sender, EventArgs e) + { + Run(); + } + } + + public class Bin + { + public List Items; + + public Bin(double length) + { + Items = new List(); + Length = length; + } + + public double Spacing { get; set; } + + public double Length { get; set; } + + public double UsedLength + { + get + { + return Items.Sum(i => i.Length) + Spacing * Items.Count; + } + } + + public double RemainingLength + { + get { return Length - UsedLength; } + } + + public double Utilization + { + get { return (UsedLength / Length * 100.0); } + } + + public override string ToString() + { + return string.Format( + "Length: {0}\", {1}\" remaining, {2} items, {3}% utilization", + Math.Round(Length, 4), + Math.Round(RemainingLength, 4), + Items.Count, + Math.Round(Utilization, 2)); + } + } + + public class BinItem + { + public string Name { get; set; } + + public double Length { get; set; } + } + + public class UIItem + { + private string name; + + public UIItem() + { + } + + public string Name + { + get + { + return string.IsNullOrWhiteSpace(name) ? + GetDefaultName() : + name; + } + set + { + name = value; + } + } + + public double Length { get; set; } + + public double TotalLength + { + get { return Length * Quantity; } + } + + public int Quantity { get; set; } = 1; + + private string GetDefaultName() + { + if (Length == 0) + return "-"; + + return string.Format("{0}\" LG", Length); + } + } +} diff --git a/CutToLength/Form1.resx b/CutToLength/Form1.resx new file mode 100644 index 0000000..81139af --- /dev/null +++ b/CutToLength/Form1.resx @@ -0,0 +1,126 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 + + + 17, 17 + + + 172, 17 + + \ No newline at end of file diff --git a/CutToLength/Program.cs b/CutToLength/Program.cs new file mode 100644 index 0000000..d9cc403 --- /dev/null +++ b/CutToLength/Program.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace CutToLength +{ + static class Program + { + /// + /// The main entry point for the application. + /// + [STAThread] + static void Main() + { + Application.EnableVisualStyles(); + Application.SetCompatibleTextRenderingDefault(false); + Application.Run(new Form1()); + } + } +} diff --git a/CutToLength/Properties/AssemblyInfo.cs b/CutToLength/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..8458f90 --- /dev/null +++ b/CutToLength/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("CutToLength")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("CutToLength")] +[assembly: AssemblyCopyright("Copyright © 2017")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("3e82a1e3-07a8-40c4-abc4-df24c5120073")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/CutToLength/Properties/DataSources/Item.datasource b/CutToLength/Properties/DataSources/Item.datasource new file mode 100644 index 0000000..5a64592 --- /dev/null +++ b/CutToLength/Properties/DataSources/Item.datasource @@ -0,0 +1,10 @@ + + + + CutToLength.Item, CutToLength, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null + \ No newline at end of file diff --git a/CutToLength/Properties/Resources.Designer.cs b/CutToLength/Properties/Resources.Designer.cs new file mode 100644 index 0000000..464c646 --- /dev/null +++ b/CutToLength/Properties/Resources.Designer.cs @@ -0,0 +1,93 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace CutToLength.Properties { + using System; + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("CutToLength.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + + /// + /// Looks up a localized resource of type System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap Circled_Play_32 { + get { + object obj = ResourceManager.GetObject("Circled Play-32", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Looks up a localized resource of type System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap Open_Folder_32 { + get { + object obj = ResourceManager.GetObject("Open Folder-32", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Looks up a localized resource of type System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap Save_32 { + get { + object obj = ResourceManager.GetObject("Save-32", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + } +} diff --git a/CutToLength/Properties/Resources.resx b/CutToLength/Properties/Resources.resx new file mode 100644 index 0000000..63af5cd --- /dev/null +++ b/CutToLength/Properties/Resources.resx @@ -0,0 +1,130 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 + + + + ..\Resources\Save-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 + + \ No newline at end of file diff --git a/CutToLength/Properties/Settings.Designer.cs b/CutToLength/Properties/Settings.Designer.cs new file mode 100644 index 0000000..3594227 --- /dev/null +++ b/CutToLength/Properties/Settings.Designer.cs @@ -0,0 +1,30 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace CutToLength.Properties +{ + + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] + internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase + { + + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); + + public static Settings Default + { + get + { + return defaultInstance; + } + } + } +} diff --git a/CutToLength/Properties/Settings.settings b/CutToLength/Properties/Settings.settings new file mode 100644 index 0000000..3964565 --- /dev/null +++ b/CutToLength/Properties/Settings.settings @@ -0,0 +1,7 @@ + + + + + + + diff --git a/CutToLength/Resources/Circled Play-32.png b/CutToLength/Resources/Circled Play-32.png new file mode 100644 index 0000000000000000000000000000000000000000..9bf921052333fd525d535b3e480efcc54c1dc6ba GIT binary patch literal 620 zcmV-y0+aoTP)+4h%4&t{$>zS8Jz5%3ZyH5TdK_fG_P2E z%tSnx%Mg4d&b-*jRg%^x0x33|>RfZ_X?G+0kEobrjUWosB0}FAU=m7XV z^LtyjCqeti;baT#G0_Qd^ik$0U+$&#p%;Ko#rjAjm?HqvdL-{DNqm1{2yR|HxOnue z`3N&ptzL)%l&VEU;JY3_&K8GZc47dYs|3Znx)lf!9Ey$nR-h08m@0h;K%7(o1pjS7 z7@)!cg$@9jUU9JY+Re9t2ioVDf>1p-9;EHi1MYEk4hgPo08BkX2=ihse=XPb6hIfG z?*K2qL3*BWTlxl|5)Si0>=FDU2z7-+fVd!(KTWTpsj$=_fCsUj=U4V;SS2DG;n4bS ziAX0E-*PHW3ND@e+%*-;4cs&zBOkzjkQ!XU;HZv8`g7==Fgv4sj(vzU3zER1R7IMaE`*35K6)A`>UR8KHQ<4`C70000)G#dggonxF--0}j%Hm;$hPpT(bJt}Hc(qyRBFBd?9vxuAWM@NAX zPqq#u0$42rwHmN&Ch7Z(Z$yxR5p{hxc&K(D5Z&KPN%&70fotk{S89Oj8W3E1#w&Hb zz8YX_1E^H=$P4jAJ%6YMXx0JC(gYBv1xIZ?;@{~TP{(_bJ7BE<&4xYz6Ae1?-sJ!` z_kNQzplNUbzqI858TxACMgW4F>5)up0Dt>G3&7?{2kX@fluO&`8X!KfWZux}+kLq1d>zZv hU2(i>3kPy{;1euocOmX>J8J*{002ovPDHLkV1f^sv_b#? literal 0 HcmV?d00001 diff --git a/CutToLength/Resources/Save-32.png b/CutToLength/Resources/Save-32.png new file mode 100644 index 0000000000000000000000000000000000000000..f43425ba85ec0216f0ff75697db1c200ca171404 GIT binary patch literal 438 zcmV;n0ZIOeP)Z zU^9R!4%oDD1H-dt&%x$rWM+bCm;*p;e2$=s17=K{#&GZ6U9iPnJ-rwXz~>0MIRNGe z-hHP9k)wjH4gguqv-cE=ox{Tc;6(WJ86**AWr1nYo0l2%*UZC6_(X@m + + + \ No newline at end of file