aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Tango.BL/Entities/RmlExtensionTestResult.cs
blob: cee7c5bc76c2a326b3147361b7f416751912bb03 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
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<TensileResult> 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);
            }
        }
    }
}