wxr
2022-02-21 44538302375e489af520e320de908d8cfcf43691
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
using System;
using HDL_ON.Entity;
using HDL_ON.UI.CSS;
using Shared;
 
namespace HDL_ON.UI
{
    public class SocketPage_InstantaneousValue : FrameLayout
    {
        static SocketPage_InstantaneousValue bodyView;
        HorizontalScrolViewLayout instantaneousValueView;
 
        Function function;
        public SocketPage_InstantaneousValue(Function function)
        {
            this.function = function;
            bodyView = this;
        }
 
        public void LoadPage()
        {
            bodyView.BackgroundColor = CSS.CSS_Color.BackgroundColor;
            FrameLayout contentView = new FrameLayout()
            {
                Y= Application .GetRealHeight(64),
                Height = Application.GetRealHeight(603),
            };
            bodyView.AddChidren(contentView);
 
            instantaneousValueView = new HorizontalScrolViewLayout()
            {
                Y = Application.GetRealHeight(16),
                Width = Application.GetRealWidth(343),
                Height = Application.GetRealHeight(110),
                Gravity = Gravity.CenterHorizontal,
                Radius = (uint)Application.GetRealWidth(12),
                BackgroundColor = CSS.CSS_Color.MainBackgroundColor,
                ScrollEnabled = false,
            };
            contentView.AddChidren(instantaneousValueView);
 
            var voltageAttr = function.GetAttribute("voltage");//电压
            if (voltageAttr != null)
            {
                var view = new InstantaneousValueView();
                view.Init(voltageAttr.curValue.ToString(), Language.StringByID(StringId.VoltageAndUnit));
                view.Tag = "voltage";
                instantaneousValueView.AddChidren(view);
            }
            var currentAttr = function.GetAttribute("current");//电流
            if (currentAttr != null)
            {
                var view = new InstantaneousValueView();
                view.Init(currentAttr.curValue.ToString(), Language.StringByID(StringId.CurrentAndUnit));
                view.Tag = "current";
                instantaneousValueView.AddChidren(view);
            }
            var active_powerAttr = function.GetAttribute("active_power");//有功功率
            if (active_powerAttr != null)
            {
                var view = new InstantaneousValueView();
                view.Init(active_powerAttr.curValue.ToString(), Language.StringByID(StringId.ActivePowerAndUnit));
                view.Tag = "active_power";
                instantaneousValueView.AddChidren(view);
            }
 
            var btnRefresh = new Button()
            {
                Gravity = Gravity.CenterHorizontal,
                Y = Application.GetRealHeight(539),
                Width = Application.GetRealWidth(220),
                Height = Application.GetRealWidth(44),
                Radius = (uint)Application.GetRealWidth(22),
                BackgroundColor = CSS_Color.MainColor,
                TextColor = CSS_Color.MainBackgroundColor,
                TextSize = CSS_FontSize.SubheadingFontSize,
                TextAlignment = TextAlignment.Center,
                IsBold = true,
                TextID = StringId.Refresh,
            };
            contentView.AddChidren(btnRefresh);
            btnRefresh.MouseUpEventHandler = (sender, e) => {
                new System.Threading.Thread(() =>
                {
                    DriverLayer.Control.Ins.SendReadCommand(function);
                })
                { IsBackground = true }.Start();
            };
 
            new TopViewDiv(bodyView, Language.StringByID(StringId.InstantaneousValue)).LoadTopView();
            new System.Threading.Thread(() =>
            {
                DriverLayer.Control.Ins.SendReadCommand(function);
            })
            { IsBackground = true }.Start();
        }
 
        public static void UpdataView(Function updata)
        {
            if (bodyView != null)
            {
                Application.RunOnMainThread(() =>
                {
                    for (int i = 0; i < bodyView.instantaneousValueView.ChildrenCount; i++)
                    {
                        var view = bodyView.instantaneousValueView.GetChildren(i);
                        if (null != view.Tag)
                        {
                            if (view.GetType() == typeof(InstantaneousValueView))
                            {
                                var view2 = view as InstantaneousValueView;
                                switch (view.Tag.ToString())
                                {
                                    case "active_power":
                                        var attr = updata.GetAttribute("active_power");
                                        if (attr != null)
                                        {
                                            view2.btnValue.Text = attr.curValue.ToString();
                                        }
                                        break;
                                    case "voltage":
                                        var attr1 = updata.GetAttribute("voltage");
                                        if (attr1 != null)
                                        {
                                            view2.btnValue.Text = attr1.curValue.ToString();
                                        }
                                        break;
                                    case "current":
                                        var attr2 = updata.GetAttribute("current");
                                        if (attr2 != null)
                                        {
                                            view2.btnValue.Text = attr2.curValue.ToString();
                                        }
                                        break;
                                }
                            }
                        }
                    }
                });
            }
        }
    }
 
 
    public class InstantaneousValueView :FrameLayout
    {
        public FrameLayout View;
        public Button btnValue;
        public Button btnLine;
        public Button btnUnit;
 
        public InstantaneousValueView()
        {
            View = this;
            View.Width = Application.GetRealWidth(115);
            View.Height = Application.GetRealHeight(110);
        }
 
        public void Init(string value, string unit)
        {
 
            btnValue = new Button()
            {
                Height = Application.GetRealHeight(59),
                Y = Application.GetRealWidth(12),
                TextAlignment = TextAlignment.Center,
                TextColor = CSS.CSS_Color.FirstLevelTitleColor,
                TextSize = CSS.CSS_FontSize.EmphasisFontSize_FirstLevel,
                Text = value,
            };
            View.AddChidren(btnValue);
 
            btnLine = new Button()
            {
                Height = Application.GetRealHeight(2),
                Width = Application.GetRealWidth(60),
                Gravity = Gravity.CenterHorizontal,
                BackgroundColor = CSS.CSS_Color.MainColor,
                Y = Application.GetRealHeight(59),
            };
            View.AddChidren(btnLine);
 
            btnUnit = new Button()
            {
                Y = Application.GetRealHeight(59),
                Height = Application.GetRealHeight(33),
                TextAlignment = TextAlignment.Center,
                TextColor = CSS.CSS_Color.PromptingColor1,
                TextSize = CSS.CSS_FontSize.PromptFontSize_FirstLevel,
                Text = unit
            };
            View.AddChidren(btnUnit);
 
 
        }
    }
    
}