From 8967aa8b55e8571c2458745b053eaef8f928f8cd Mon Sep 17 00:00:00 2001 From: aj Date: Thu, 31 May 2018 22:26:55 -0400 Subject: [PATCH] Cleanup classes. --- CutToLength/Bin.cs | 48 ++++++++++++++++++ CutToLength/BinItem.cs | 9 ++++ CutToLength/CutToLength.csproj | 3 ++ CutToLength/Form1.cs | 90 ---------------------------------- CutToLength/UIItem.cs | 42 ++++++++++++++++ 5 files changed, 102 insertions(+), 90 deletions(-) create mode 100644 CutToLength/Bin.cs create mode 100644 CutToLength/BinItem.cs create mode 100644 CutToLength/UIItem.cs diff --git a/CutToLength/Bin.cs b/CutToLength/Bin.cs new file mode 100644 index 0000000..ba8b0b1 --- /dev/null +++ b/CutToLength/Bin.cs @@ -0,0 +1,48 @@ +using System; +using System.Collections.Generic; + +namespace CutToLength +{ + 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)); + } + } +} diff --git a/CutToLength/BinItem.cs b/CutToLength/BinItem.cs new file mode 100644 index 0000000..cbeea8f --- /dev/null +++ b/CutToLength/BinItem.cs @@ -0,0 +1,9 @@ +namespace CutToLength +{ + public class BinItem + { + public string Name { get; set; } + + public double Length { get; set; } + } +} diff --git a/CutToLength/CutToLength.csproj b/CutToLength/CutToLength.csproj index 53a4c8b..e9b32be 100644 --- a/CutToLength/CutToLength.csproj +++ b/CutToLength/CutToLength.csproj @@ -50,6 +50,8 @@ + + Component @@ -67,6 +69,7 @@ + Form1.cs diff --git a/CutToLength/Form1.cs b/CutToLength/Form1.cs index c493d79..6927cfb 100644 --- a/CutToLength/Form1.cs +++ b/CutToLength/Form1.cs @@ -184,94 +184,4 @@ namespace CutToLength 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/UIItem.cs b/CutToLength/UIItem.cs new file mode 100644 index 0000000..1c3e038 --- /dev/null +++ b/CutToLength/UIItem.cs @@ -0,0 +1,42 @@ +namespace CutToLength +{ + 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); + } + } +}