Update MaterialCost when MaterialMilliliters changes (#449)

- (Add) Property `StartingMaterialMilliliters`: Gets the starting material milliliters when the file loaded
- (Add) Property `StartingMaterialCost`: Gets the starting material cost when the file loaded
- (Improvement) Update `MaterialCost` when `MaterialMilliliters` changes (#449)
This commit is contained in:
Tiago Conceição
2022-04-05 22:19:50 +01:00
parent 306b4d5141
commit 71f6407845
2 changed files with 26 additions and 4 deletions
+22 -3
View File
@@ -2724,6 +2724,11 @@ public abstract class FileFormat : BindableBase, IDisposable, IEquatable<FileFor
}
}
/// <summary>
/// Gets the starting material milliliters when the file loaded
/// </summary>
public float StartingMaterialMilliliters { get; private set; }
/// <summary>
/// Gets the estimate used material in ml
/// </summary>
@@ -2740,7 +2745,13 @@ public abstract class FileFormat : BindableBase, IDisposable, IEquatable<FileFor
value = (float)Math.Round(value, 3);
}
RaiseAndSetIfChanged(ref _materialMilliliters, value);
if(!RaiseAndSetIfChanged(ref _materialMilliliters, value)) return;
if (StartingMaterialMilliliters > 0 && StartingMaterialCost > 0)
{
MaterialCost = _materialMilliliters * StartingMaterialCost / StartingMaterialMilliliters;
}
//RaisePropertyChanged(nameof(MaterialCost));
}
}
@@ -2753,16 +2764,21 @@ public abstract class FileFormat : BindableBase, IDisposable, IEquatable<FileFor
public virtual float MaterialGrams
{
get => _materialGrams;
set => RaiseAndSetIfChanged(ref _materialGrams, value);
set => RaiseAndSetIfChanged(ref _materialGrams, (float)Math.Round(value, 3));
}
/// <summary>
/// Gets the starting material cost when the file loaded
/// </summary>
public float StartingMaterialCost { get; private set; }
/// <summary>
/// Gets the estimate material cost
/// </summary>
public virtual float MaterialCost
{
get => _materialCost;
set => RaiseAndSetIfChanged(ref _materialCost, value);
set => RaiseAndSetIfChanged(ref _materialCost, (float)Math.Round(value, 3));
}
/// <summary>
@@ -3295,6 +3311,9 @@ public abstract class FileFormat : BindableBase, IDisposable, IEquatable<FileFor
DecodeInternally(progress);
IsModified = false;
StartingMaterialMilliliters = MaterialMilliliters;
StartingMaterialCost = MaterialCost;
progress.ThrowIfCancellationRequested();
+4 -1
View File
@@ -488,7 +488,10 @@ public class SL1File : FileFormat
public override float MaterialGrams => (float) Math.Round(OutputConfigSettings.UsedMaterial * MaterialSettings.MaterialDensity, 3);
public override float MaterialCost => MaterialSettings.BottleVolume > 0 ? (float) Math.Round(OutputConfigSettings.UsedMaterial * MaterialSettings.BottleCost / MaterialSettings.BottleVolume, 3) : 0;
public override float MaterialCost =>
MaterialSettings.BottleVolume > 0
? (float) Math.Round(OutputConfigSettings.UsedMaterial * MaterialSettings.BottleCost / MaterialSettings.BottleVolume, 3)
: base.MaterialCost;
public override string? MaterialName
{