Prechádzať zdrojové kódy

DESKTOP - improvements to JobBOM Create PO function

Nick-PRSDigital@bitbucket.org 2 rokov pred
rodič
commit
edde517892

+ 47 - 32
prs.classes/EnclosedEntities/Dimensions/Dimensions.cs

@@ -5,13 +5,13 @@ using System.Collections.Generic;
 namespace Comal.Classes
 {
 
-    public abstract class Dimensions<TLink,TUnit> : EnclosedEntity, IDimensions 
-        where TLink : DimensionUnitLink<TUnit>, new() 
+    public abstract class Dimensions<TLink, TUnit> : EnclosedEntity, IDimensions
+        where TLink : DimensionUnitLink<TUnit>, new()
         where TUnit : DimensionUnit, new()
     {
 
         public Dimensions() : base() { }
-        
+
         public Dimensions(Func<BaseObject> entity) : base(entity) { }
 
         [EditorSequence(1)]
@@ -20,93 +20,93 @@ namespace Comal.Classes
         public abstract TLink Unit { get; set; }
 
         public IDimensionUnit GetUnit() => Unit;
-        
+
         [DoubleEditor(Visible = Visible.Hidden)]
         [EditorSequence(2)]
         [Caption("Quantity", IncludePath = false)]
         [RequiredColumn]
         public abstract double Quantity { get; set; }
-        
+
         [DoubleEditor(Visible = Visible.Hidden)]
         [EditorSequence(3)]
         [Caption("Length", IncludePath = false)]
         [RequiredColumn]
         public abstract double Length { get; set; }
-        
+
         [DoubleEditor(Visible = Visible.Hidden)]
         [EditorSequence(4)]
         [Caption("Width", IncludePath = false)]
         [RequiredColumn]
         public abstract double Width { get; set; }
-        
+
         [DoubleEditor(Visible = Visible.Hidden)]
         [EditorSequence(5)]
         [Caption("Height", IncludePath = false)]
         [RequiredColumn]
         public abstract double Height { get; set; }
-        
+
         [DoubleEditor(Visible = Visible.Hidden)]
         [EditorSequence(6)]
         [Caption("Weight", IncludePath = false)]
         [RequiredColumn]
         public abstract double Weight { get; set; }
-        
+
         [DoubleEditor(Visible = Visible.Optional, Editable = Editable.Hidden)]
         [Caption("Value", IncludePath = false)]
         [EditorSequence(7)]
         [RequiredColumn]
         public abstract double Value { get; set; }
-        
-        [TextBoxEditor(Visible = Visible.Default, Editable=Editable.Hidden)]
+
+        [TextBoxEditor(Visible = Visible.Default, Editable = Editable.Hidden)]
         [EditorSequence(8)]
         [Caption("Unit Size", IncludePath = false)]
         [RequiredColumn]
         public abstract String UnitSize { get; set; }
-        
+
         protected override void Init()
         {
             base.Init();
             Unit = Activator.CreateInstance(typeof(TLink), new object[] { new Func<BaseObject>(LinkedEntity) }) as TLink;
             Unit.PropertyChanged += (s, e) =>
             {
-                if(e.PropertyName == "ID")
+                if (e.PropertyName == "ID")
                 {
                     DoPropertyChanged("Unit." + e.PropertyName, OriginalValues.GetValueOrDefault("Unit." + e.PropertyName), Unit.ID);
                 }
-                else if(e.PropertyName == "Formula")
+                else if (e.PropertyName == "Formula")
                 {
                     DoPropertyChanged("Unit." + e.PropertyName, OriginalValues.GetValueOrDefault("Unit." + e.PropertyName), Unit.Formula);
                 }
-                else if(e.PropertyName == "Format")
+                else if (e.PropertyName == "Format")
                 {
                     DoPropertyChanged("Unit." + e.PropertyName, OriginalValues.GetValueOrDefault("Unit." + e.PropertyName), Unit.Format);
                 }
             };
         }
-        
+
         private bool bCalculating = false;
 
-        private static Column<Dimensions<TLink,TUnit>> unitid = new Column<Dimensions<TLink,TUnit>>(x => x.Unit.ID);
-        private static Column<Dimensions<TLink,TUnit>> quantity = new Column<Dimensions<TLink,TUnit>>(x => x.Quantity);
-        private static Column<Dimensions<TLink,TUnit>> length = new Column<Dimensions<TLink,TUnit>>(x => x.Length);
-        private static Column<Dimensions<TLink,TUnit>> width = new Column<Dimensions<TLink,TUnit>>(x => x.Width);
-        private static Column<Dimensions<TLink,TUnit>> height = new Column<Dimensions<TLink,TUnit>>(x => x.Height);
-        private static Column<Dimensions<TLink,TUnit>> weight = new Column<Dimensions<TLink,TUnit>>(x => x.Weight);
-        private static Column<Dimensions<TLink,TUnit>> sizeformula = new Column<Dimensions<TLink,TUnit>>(x => x.Unit.Formula);
-        private static Column<Dimensions<TLink,TUnit>> sizeformat = new Column<Dimensions<TLink,TUnit>>(x => x.Unit.Format);
-        
+        private static Column<Dimensions<TLink, TUnit>> unitid = new Column<Dimensions<TLink, TUnit>>(x => x.Unit.ID);
+        private static Column<Dimensions<TLink, TUnit>> quantity = new Column<Dimensions<TLink, TUnit>>(x => x.Quantity);
+        private static Column<Dimensions<TLink, TUnit>> length = new Column<Dimensions<TLink, TUnit>>(x => x.Length);
+        private static Column<Dimensions<TLink, TUnit>> width = new Column<Dimensions<TLink, TUnit>>(x => x.Width);
+        private static Column<Dimensions<TLink, TUnit>> height = new Column<Dimensions<TLink, TUnit>>(x => x.Height);
+        private static Column<Dimensions<TLink, TUnit>> weight = new Column<Dimensions<TLink, TUnit>>(x => x.Weight);
+        private static Column<Dimensions<TLink, TUnit>> sizeformula = new Column<Dimensions<TLink, TUnit>>(x => x.Unit.Formula);
+        private static Column<Dimensions<TLink, TUnit>> sizeformat = new Column<Dimensions<TLink, TUnit>>(x => x.Unit.Format);
+
         protected override void DoPropertyChanged(string name, object? before, object? after)
         {
             base.DoPropertyChanged(name, before, after);
 
             if (bCalculating)
                 return;
-            
+
             bCalculating = true;
-            
+
             try
             {
-                
+
                 if (unitid.IsEqualTo(name))
                     Calculate(Quantity, Length, Width, Height, Weight, Unit.Formula, Unit.Format);
                 else if (quantity.IsEqualTo(name))
@@ -154,11 +154,11 @@ namespace Comal.Classes
             }
             finally
             {
-                bCalculating = false;                
+                bCalculating = false;
             }
         }
 
-        
+
         private void Calculate(object? quantity, object? length, object? width, object? height, object? weight, string? formula, string? format)
         {
             if (Evaluate<double>(formula, quantity, length, width, height, weight, out double value))
@@ -169,7 +169,7 @@ namespace Comal.Classes
 
         private bool Evaluate<T>(string? formula, object? quantity, object? length, object? width, object? height, object? weight, out T result)
         {
-            
+
             if (!String.IsNullOrWhiteSpace(formula))
             {
                 var variables = new Dictionary<string, object?>()
@@ -184,7 +184,7 @@ namespace Comal.Classes
                 {
                     var expr = new CoreExpression(formula);
                     var eval = expr.Evaluate(variables);
-                    result = (T)CoreUtils.ChangeType(eval,typeof(T));
+                    result = (T)CoreUtils.ChangeType(eval, typeof(T));
                     return true;
                 }
                 catch (Exception e)
@@ -215,5 +215,20 @@ namespace Comal.Classes
             if (!observing)
                 SetObserving(true);
         }
+
+        public override string ToString()
+        {
+            var result = Value != 0 ? Math.Round(Value, 3).ToString() : "";
+            result = !string.IsNullOrWhiteSpace(UnitSize) ? result + " " + UnitSize + ", " : "Empty unitsize";
+            result = Quantity != 0 ? result + "Quantity: " + Quantity + ", " : result;
+            result = Length != 0 ? result + "Length: " + Length + ", " : result;
+            result = Width != 0 ? result + "Width: " + Width + ", " : result;
+            result = Height != 0 ? result + "Height: " + Height + ", " : result;
+            result = Weight != 0 ? result + "Weight: " + Weight : result;
+            if (result.EndsWith(", "))
+                result = result.Remove(result.Length - 2);
+
+            return result;
+        }
     }
 }

+ 2 - 2
prs.desktop/Panels/Jobs/JobBillOfMaterialsItemsGrid.cs

@@ -278,8 +278,7 @@ namespace PRSDesktop
                 PurchaseOrderItem POItem = new PurchaseOrderItem();
                 POItem.Product.ID = BOMItem.Product.ID;
                 POItem.Product.Code = BOMItem.Product.Code;
-                POItem.Product.Name = BOMItem.Product.Name;
-                POItem.Description = BOMItem.Product.Name;
+                POItem.Product.Name = BOMItem.Product.Name;               
                 POItem.Qty = BOMItem.Quantity;
                 POItem.Dimensions.CopyFrom(BOMItem.Dimensions);
                 POItem.Style.ID = BOMItem.Style.ID;
@@ -287,6 +286,7 @@ namespace PRSDesktop
                 POItem.Style.Description = BOMItem.Style.Description;
                 POItem.Job.ID = BOMItem.Job.ID;
                 POItem.Dimensions.UnitSize = BOMItem.Dimensions.UnitSize;
+                POItem.Description = BOMItem.Product.Name + " (" + BOMItem.Dimensions.ToString() + ")";
                 items.Add(POItem);
             }
             result.LoadRows(items);