Parcourir la source

More PRSDesktop usages of double adjusted

Kenric Nugteren il y a 2 semaines
Parent
commit
267c1a66d6

+ 6 - 6
prs.desktop/Dashboards/Manufacturing/FactoryFloorAnalysis.xaml.cs

@@ -230,7 +230,7 @@ namespace PRSDesktop
 
             var packetIDs = completedstages.Keys.ToArray();
 
-            var totals = new Dictionary<string, double>();
+            var totals = new Dictionary<string, decimal>();
             var qtytotal = 0;
             for(var i = 0; i < packetIDs.Length; ++i)
             {
@@ -264,11 +264,11 @@ namespace PRSDesktop
                         }
 
                         var prefix = string.Format("{0}:{1}:", section.Factory.Name, NotAlphaNumeric().Replace(section.Name, ""));
-                        var estimated = stage.Time.TotalHours * firstStage.Parent.Quantity;
+                        var estimated = stage.Time.TotalHoursDecimal() * firstStage.Parent.Quantity;
                         var histrecords = history.GetValueOrDefault((firstStage.Parent.ID, stage.Section.ID)) ?? [];
-                        var actual = new TimeSpan(histrecords.Sum(x => x.WorkDuration.Ticks + x.QADuration.Ticks)).TotalHours;
+                        var actual = new TimeSpan(histrecords.Sum(x => x.WorkDuration.Ticks + x.QADuration.Ticks)).TotalHoursDecimal();
 
-                        if (actual > 0.0F)
+                        if (actual > 0)
                         {
                             if (data.Columns.Contains(prefix + "Est"))
                             {
@@ -360,11 +360,11 @@ namespace PRSDesktop
             var sectionName = section.Name;
             var columnname = string.Format("{0}:{1}:{2}", factory, NotAlphaNumeric().Replace(sectionName, ""), subcolumn);
             columns.Add(columnname);
-            data.Columns.Add(columnname, typeof(double));
+            data.Columns.Add(columnname, typeof(decimal));
             SectionDisplayNames[columnname] = sectionName;
         }
 
-        private static void UpdateColumn(Dictionary<string, double> totals, DataRow row, string fieldname, double value)
+        private static void UpdateColumn(Dictionary<string, decimal> totals, DataRow row, string fieldname, decimal value)
         {
             row[fieldname] = value;
             if (!totals.TryGetValue(fieldname, out var total))

+ 7 - 7
prs.desktop/Dashboards/Manufacturing/FactoryProductivity.xaml.cs

@@ -254,7 +254,7 @@ namespace PRSDesktop
                 foreach (var record in records)
                 {
                     mySheet.Range[iRow, 1].Text = record.Name;
-                    mySheet.Range[iRow, iCol].Number = Math.Truncate(record.Hours * 100.0F) / 100.0F;
+                    mySheet.Range[iRow, iCol].Number = Convert.ToDouble(Math.Truncate(record.Hours * 100) / 100);
                     iRow++;
                 }
 
@@ -293,8 +293,8 @@ namespace PRSDesktop
             public int Packets { get; set; }
 
             //public double QAHours { get; set; }
-            public double Hours { get; set; }
-            public double LostTime { get; set; }
+            public decimal Hours { get; set; }
+            public decimal LostTime { get; set; }
         }
 
         public class HistoryViewModel
@@ -462,8 +462,8 @@ namespace PRSDesktop
                         Staff.Add(record);
                     }
 
-                    var hrs = row.Get<ManufacturingHistory, TimeSpan>(x => x.QADuration).TotalHours +
-                              row.Get<ManufacturingHistory, TimeSpan>(x => x.WorkDuration).TotalHours;
+                    var hrs = row.Get<ManufacturingHistory, TimeSpan>(x => x.QADuration).TotalHoursDecimal() +
+                              row.Get<ManufacturingHistory, TimeSpan>(x => x.WorkDuration).TotalHoursDecimal();
                     if (Entity.IsEntityLinkValid<ManufacturingHistory, ManufacturingPacketLink>(x => x.Packet, row))
                         record.Hours += hrs;
                     else
@@ -501,8 +501,8 @@ namespace PRSDesktop
 
                     var record = value.FirstOrDefault(x => string.Equals(x.Name, staff));
                     record.Packets = record.Packets + row.Get<ManufacturingHistory, int>(x => x.WorkCompleted);
-                    record.Hours = record.Hours + row.Get<ManufacturingHistory, TimeSpan>(x => x.QADuration).TotalHours +
-                                   row.Get<ManufacturingHistory, TimeSpan>(x => x.WorkDuration).TotalHours;
+                    record.Hours = record.Hours + row.Get<ManufacturingHistory, TimeSpan>(x => x.QADuration).TotalHoursDecimal() +
+                                   row.Get<ManufacturingHistory, TimeSpan>(x => x.WorkDuration).TotalHoursDecimal();
                 }
             }
         }

+ 7 - 7
prs.desktop/Dashboards/Manufacturing/JobManufacturingSummary.xaml.cs

@@ -48,13 +48,13 @@ namespace PRSDesktop.Dashboards.Manufacturing
 
         public Guid ID { get; set; }
 
-        public double NHours { get; set; }
+        public decimal NHours { get; set; }
 
         public int NPackets { get; set; }
 
         public Visibility HoursVisibility;
 
-        public JobModel(string jobNumber, string name, Guid ID, double nHours, int nPackets)
+        public JobModel(string jobNumber, string name, Guid ID, decimal nHours, int nPackets)
         {
             JobNumber = jobNumber;
             Name = name;
@@ -69,7 +69,7 @@ namespace PRSDesktop.Dashboards.Manufacturing
         private bool _empty;
 
         public int NPackets { get; set; }
-        public double NHours { get; set; }
+        public decimal NHours { get; set; }
         public bool Empty
         {
             get => _empty || NPackets == 0;
@@ -87,7 +87,7 @@ namespace PRSDesktop.Dashboards.Manufacturing
         public CardModel()
         {
             NPackets = 0;
-            NHours = 0.0;
+            NHours = 0;
             Empty = true;
         }
     }
@@ -123,7 +123,7 @@ namespace PRSDesktop.Dashboards.Manufacturing
         {
             public int NPackets { get; set; } = 0;
 
-            public double NHours { get; set; } = 0;
+            public decimal NHours { get; set; } = 0;
         }
 
 
@@ -363,7 +363,7 @@ namespace PRSDesktop.Dashboards.Manufacturing
                         HoursVisibility = Properties.IncludeTimeRemaining ? Visibility.Visible : Visibility.Collapsed
                     }, (c, p) =>
                     {
-                        c.NHours += p.TimeRemaining.TotalHours;
+                        c.NHours += p.TimeRemaining.TotalHoursDecimal();
                         ++c.NPackets;
                         return c;
                     })));
@@ -445,7 +445,7 @@ namespace PRSDesktop.Dashboards.Manufacturing
             {
                 var any = false;
 
-                var nHours = 0.0;
+                var nHours = 0m;
                 var nPackets = 0;
                 foreach (var (id, column) in FactoryColumns.Concat(SectionColumns))
                 {

+ 4 - 4
prs.desktop/Dashboards/Manufacturing/ManufacturingStatusWidget.xaml.cs

@@ -33,8 +33,8 @@ namespace PRSDesktop
             report.Columns.Add("Setout", typeof(string));
             report.Columns.Add("Serial", typeof(string));
             report.Columns.Add("Description", typeof(string));
-            report.Columns.Add("Estimated", typeof(double));
-            report.Columns.Add("Actual", typeof(double));
+            report.Columns.Add("Estimated", typeof(decimal));
+            report.Columns.Add("Actual", typeof(decimal));
             report.Columns.Add("Overdue", typeof(int));
             report.PrimaryKey = new[] { report.Columns[0] };
         }
@@ -112,8 +112,8 @@ namespace PRSDesktop
                     var setout = packet.Get<ManufacturingPacket, string>(x => x.SetoutLink.Number);
                     var serial = packet.Get<ManufacturingPacket, string>(x => x.Serial);
                     var description = packet.Get<ManufacturingPacket, string>(x => x.Description);
-                    var est = packet.Get<ManufacturingPacket, TimeSpan>(x => x.Time).TotalHours;
-                    var act = packet.Get<ManufacturingPacket, TimeSpan>(x => x.ActualTime).TotalHours;
+                    var est = packet.Get<ManufacturingPacket, TimeSpan>(x => x.Time).TotalHoursDecimal();
+                    var act = packet.Get<ManufacturingPacket, TimeSpan>(x => x.ActualTime).TotalHoursDecimal();
                     report.Rows.Add(pktid, setout, serial, description, est, act);
                 }
             }

+ 4 - 4
prs.desktop/Dashboards/Manufacturing/ManufacturingTemplateAnalysis.xaml.cs

@@ -177,13 +177,13 @@ namespace PRSDesktop
                     {
                         total += times[section.ID];
                         if (qty > 0 && times[section.ID] > 0)
-                            values.Add(Math.Truncate(new TimeSpan(times[section.ID] / qty).TotalHours * 100.0F) / 100.0F);
+                            values.Add(Math.Truncate(new TimeSpan(times[section.ID] / qty).TotalHoursDecimal() * 100) / 100);
                         else
                             values.Add(null);
                     }
 
                     if (qty > 0 && total > 0)
-                        values.Add(Math.Truncate(new TimeSpan(total / qty).TotalHours * 100.0F) / 100.0F);
+                        values.Add(Math.Truncate(new TimeSpan(total / qty).TotalHoursDecimal() * 100) / 100);
                     else
                         values.Add(null);
 
@@ -227,11 +227,11 @@ namespace PRSDesktop
 
                 var columnname = string.Format("{0}:{1}", section.Factory.Name, Regex.Replace(section.Name, "[^a-zA-Z0-9]", ""));
                 columns[section.Factory.Name].Add(columnname);
-                data.Columns.Add(columnname, typeof(double));
+                data.Columns.Add(columnname, typeof(decimal));
                 SectionDisplayNames[columnname] = section.Name;
             }
 
-            data.Columns.Add("Total", typeof(double));
+            data.Columns.Add("Total", typeof(decimal));
 
             dataGrid.ItemsSource = data;
 

+ 1 - 1
prs.desktop/Panels/Factory/FactoryPackGrid.cs

@@ -240,7 +240,7 @@ public class FactoryPackGrid : DynamicDataGrid<StockHolding>
         private StockDimensions? _dimensions;
         
         [EditorSequence(4)] 
-        public double Qty { get; set; }
+        public decimal Qty { get; set; }
 
         [EditorSequence(5)]
         public JobLink Job => InitializeField(ref _job, nameof(Job));

+ 2 - 2
prs.desktop/Panels/Products/Locations/StockTakeWindow.xaml.cs

@@ -315,14 +315,14 @@ namespace PRSDesktop
                new CoreColumn()
                {
                    ColumnName = "OriginalQty",
-                   DataType = typeof(double)
+                   DataType = typeof(decimal)
                });
 
             result.Columns.Add(
                 new CoreColumn()
                 {
                     ColumnName = "NewQty",
-                    DataType = typeof(double)
+                    DataType = typeof(decimal)
                 });
 
             return result;

+ 0 - 31
prs.desktop/Panels/Stock Forecast/StockForecastGrid.cs

@@ -757,37 +757,6 @@ public class StockForecastGrid : DynamicItemsListGrid<StockForecastItem>, IDataM
         return subset.ToArray();
     }
 
-    private double Aggregate<TSource>(CoreTable table, IEnumerable<CoreRow> rows, bool hasstyle, bool hasjob, Expression<Func<TSource, object>> source, CoreRow? target = null, Expression<Func<ProductInstance, object>>? aggregate = null)
-    {
-        int srcol = table.GetColumnIndex(source);
-        
-        if (srcol == -1)
-            return 0.00;
-
-        var total =  rows.Aggregate(0d, (value, row) => value + (double)(row.Values[srcol] ?? 0.0d));
-        
-        // int productcol = columns.IndexOf(x => x.Product.ID);
-        // int stylecol = hasstyle ? columns.IndexOf(x => x.Style.ID) : -1;
-        // int jobcol = hasjob ? columns.IndexOf(x => x.Job.ID) : -1;
-        // int unitcol = columns.IndexOf(x => x.Dimensions.UnitSize);
-        //
-        // var tuples = rows.Select(r => new Tuple<Guid, Guid?, Guid?, String, double>(
-        //     (Guid)(r.Values[productcol] ?? Guid.Empty),
-        //     (hasstyle ? (Guid)(r.Values[stylecol] ?? Guid.Empty) : null),
-        //     (hasjob ? (Guid)(r.Values[jobcol] ?? Guid.Empty) : null),
-        //     (String)(r.Values[unitcol] ?? ""),
-        //     (double)(r.Values[aggcol] ?? 0.0d))
-        // ).ToArray();
-        //
-        // var total = tuples.Aggregate(0d, (value, tuple) => value + tuple.Item5);
-
-        if(aggregate is not null)
-        {
-            target?.Set(aggregate, total);
-        }
-        return total;
-    }
-
     private decimal? GetColumnCalculatedData(ColumnTag tag, CoreRow row)
     {
         return tag switch

+ 2 - 2
prs.licensing/Engine/LicensingEngineProperties.cs

@@ -17,7 +17,7 @@ public class LicenseTimeDiscount : BaseObject
     
     [EditorSequence(2)]
     [DoubleEditor(Alignment = Alignment.MiddleCenter)]
-    public double Discount { get; set; }
+    public decimal Discount { get; set; }
 }
 
 public class LicenseUserDiscount : BaseObject
@@ -28,7 +28,7 @@ public class LicenseUserDiscount : BaseObject
     
     [EditorSequence(2)]
     [DoubleEditor(Alignment = Alignment.MiddleCenter)]
-    public double Discount { get; set; }
+    public decimal Discount { get; set; }
 }
 
 public class LicenseProductMapping : BaseObject