aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/PPC/Tango.PPC.UI/Converters/ProgressWeightSpoolConverter.cs
blob: 05a41912ceaf7e5079bf455e164b3d1758ba372d (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
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Data;


namespace Tango.PPC.UI.Converters
{
    public class ProgressWeightSpoolConverter : IMultiValueConverter
    {
        public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
        {
            try
            {
                if (values.Count() == 3)
                {
                    double length = System.Convert.ToDouble(values[0]);
                    bool forOneSpool = System.Convert.ToBoolean(values[1]);
                    double coef = System.Convert.ToDouble(values[2]);
                    var totalBy4Spools = (double)length * 4;// spools ;
                    
                    var weight = ((double)totalBy4Spools * coef) / (1000);//(g)
                    if (forOneSpool)
                    {
                        return (double)weight / 4;
                    }
                    return weight;

                }
                if (values.Count() == 4)
                {
                    double length = System.Convert.ToDouble(values[0]);
                    bool forOneSpool = System.Convert.ToBoolean(values[1]);
                    double currentProgresslength = System.Convert.ToDouble(values[2]);
                    double coef = System.Convert.ToDouble(values[3]);

                    var totalBy4Spools = (double)length * 4;
                    var currentProgressBy4Spools = (double)currentProgresslength * 4;

                    int coeff = (int)currentProgressBy4Spools / (int)totalBy4Spools;
                    var progressCurrent = coeff == 0 ? currentProgressBy4Spools : currentProgressBy4Spools % (coeff * totalBy4Spools);//show for progress
                    var weight = ((double)progressCurrent * coef) / (1000);//(g)
                    if (forOneSpool)
                    {
                        return (double)weight / 4;

                    }
                    return weight;
                }
                return "-";
            }
            catch
            {
                return "-";
            }
        }

        public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}