using Newtonsoft.Json; using System; using System.Collections.Generic; using System.Collections.Specialized; using System.ComponentModel.DataAnnotations.Schema; using System.Linq; using System.Text; using System.Threading.Tasks; using Tango.Core; namespace Tango.BL.Entities { public class RmlExtensionTestResult : RmlExtensionTestResultBase { [NotMapped] [JsonIgnore] public TensileResult WhiteColor { get; set; } public RmlExtensionTestResult() { } protected override void OnTensileResultsChanged(SynchronizedObservableCollection tensileresults) { base.OnTensileResultsChanged(tensileresults); if (TensileResults != null) { TensileResults.CollectionChanged -= OnTensileResultsCollectionChanged; TensileResults.CollectionChanged += OnTensileResultsCollectionChanged; AddEventsOnUpdateCollection(); } } private void OnTensileResultsCollectionChanged(object sender, NotifyCollectionChangedEventArgs e) { if (e.Action == NotifyCollectionChangedAction.Add) { AddEventsOnUpdateCollection(); } } private void AddEventsOnUpdateCollection() { foreach (var result in TensileResults) { if (result.IsWhiteColor) { WhiteColor = result; WhiteColor.MaxLoadChanged -= WhiteColor_MaxLoadChanged; WhiteColor.MaxLoadChanged += WhiteColor_MaxLoadChanged; WhiteColor.StrainMaxLoadChanged -= WhiteColor_StrainMaxLoadChanged; WhiteColor.StrainMaxLoadChanged += WhiteColor_StrainMaxLoadChanged; } else { result.MaxLoadChanged -= Result_MaxLoadChanged; result.MaxLoadChanged += Result_MaxLoadChanged; result.StrainMaxLoadChanged -= Result_StrainMaxLoadChanged; result.StrainMaxLoadChanged += Result_StrainMaxLoadChanged; } } } private void WhiteColor_MaxLoadChanged(object sender, double? e) { foreach (var result in TensileResults) { if (WhiteColor == null || WhiteColor.MaxLoad == 0) result.PercentChangeLoad = 0; else if (!result.IsWhiteColor) result.PercentChangeLoad = 100 - ((result.MaxLoad * 100) / WhiteColor.MaxLoad); } } private void WhiteColor_StrainMaxLoadChanged(object sender, double? e) { foreach (var result in TensileResults) { if (WhiteColor == null || WhiteColor.StrainMaxLoad == 0) result.PercentChangeStrain = 0; else if (!result.IsWhiteColor) result.PercentChangeStrain = 100 - ((result.StrainMaxLoad * 100) / WhiteColor.StrainMaxLoad); } } private void Result_MaxLoadChanged(object sender, double? e) { if (sender is TensileResult) { TensileResult result = sender as TensileResult; if (WhiteColor == null || WhiteColor.MaxLoad == 0) result.PercentChangeLoad = 0; else result.PercentChangeLoad = 100 - ((result.MaxLoad * 100) / WhiteColor.MaxLoad); } } private void Result_StrainMaxLoadChanged(object sender, double? e) { if (sender is TensileResult) { TensileResult result = sender as TensileResult; if (WhiteColor == null || WhiteColor.StrainMaxLoad == 0) result.PercentChangeStrain = 0; else result.PercentChangeStrain = 100 - ((result.StrainMaxLoad * 100) / WhiteColor.StrainMaxLoad); } } } }