wei
2021-07-01 2835fe50d3e194c21b16fec1c53ff905dd3a3ceb
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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
using System;
using HDL_ON.DAL.Server;
using HDL_ON.Entity;
using HDL_ON.UI.CSS;
using Newtonsoft.Json.Linq;
using Shared;
 
namespace HDL_ON.UI
{
    public partial class FunctionBaseInfoSetPage : FrameLayout
    {
        #region 控件列表
        FrameLayout bodyView;
        /// <summary>
        /// 功能名称显示按钮
        /// </summary>
        Button btnFunctionName;
        /// <summary>
        /// 功能名称编辑按钮
        /// </summary>
        Button btnEditName;
        /// <summary>
        /// 位置信息显示按钮
        /// </summary>
        Button btnLocationValues;
        /// <summary>
        /// 位置信息跳转编辑按钮
        /// </summary>
        Button btnLocationInfoRight;
 
        #endregion
 
        #region 局部变量
        Function function;
        /// <summary>
        /// 后退时,刷新之前界面的显示信息
        /// </summary>
        Action actionRefresh;
        #endregion
 
        public FunctionBaseInfoSetPage(Function func, Action action)
        {
            bodyView = this;
            function = func;
            actionRefresh = action;
        }
        /// <summary>
        /// 加载界面
        /// </summary>
        public void LoadPage()
        {
            bodyView.BackgroundColor = CSS_Color.BackgroundColor;
            new TopViewDiv(bodyView, Language.StringByID(StringId.Setting)).LoadTopView(actionRefresh);
 
            var contentView = new VerticalScrolViewLayout()
            {
                Y = Application.GetRealHeight(64),
                Height = Application.GetRealHeight(600),
                ScrollEnabled = false,
            };
            bodyView.AddChidren(contentView);
 
            #region name view
            var nameView = new FrameLayout()
            {
                Height = Application.GetRealHeight(50),
                BackgroundColor = CSS_Color.MainBackgroundColor,
            };
            contentView.AddChidren(nameView);
 
            var btnNameText = new Button()
            {
                X = Application.GetRealWidth(16),
                Width = Application.GetRealWidth(160),
                TextAlignment = TextAlignment.CenterLeft,
                TextColor = CSS_Color.FirstLevelTitleColor,
                TextSize = CSS_FontSize.SubheadingFontSize,
                TextID = StringId.Name,
            };
            nameView.AddChidren(btnNameText);
 
            btnFunctionName = new Button()
            {
                X = Application.GetRealWidth(86),
                Width = Application.GetRealWidth(237),
                TextAlignment = TextAlignment.CenterRight,
                TextColor = CSS_Color.PromptingColor1,
                TextSize = CSS_FontSize.TextFontSize,
                Text = function.name,
            };
            nameView.AddChidren(btnFunctionName);
 
            btnEditName = new Button()
            {
                X = Application.GetRealWidth(333),
                Gravity = Gravity.CenterVertical,
                Width = Application.GetMinRealAverage(28),
                Height = Application.GetMinRealAverage(28),
                UnSelectedImagePath = "Public/Edit.png",
            };
            nameView.AddChidren(btnEditName);
 
            nameView.AddChidren(
                new Button()
                {
                    Gravity = Gravity.CenterHorizontal,
                    Y = Application.GetRealHeight(49),
                    BackgroundColor = CSS_Color.DividingLineColor,
                    Width = Application.GetRealWidth(343),
                    Height = Application.GetRealHeight(1)
                });
 
            #endregion
 
            #region 位置管理
            var locationMagtView = new FrameLayout()
            {
                Height = Application.GetRealHeight(55),
                BackgroundColor = CSS_Color.MainBackgroundColor,
            };
            contentView.AddChidren(locationMagtView);
 
            var btnLocationMagtTitle = new Button()
            {
                X = Application.GetRealWidth(16),
                Width = Application.GetRealWidth(160),
                TextAlignment = TextAlignment.CenterLeft,
                TextColor = CSS_Color.FirstLevelTitleColor,
                TextSize = CSS_FontSize.SubheadingFontSize,
                TextID = StringId.LocationManagement,
            };
            locationMagtView.AddChidren(btnLocationMagtTitle);
 
            btnLocationValues = new Button()
            {
                X = Application.GetRealWidth(86),
                Width = Application.GetRealWidth(237),
                TextAlignment = TextAlignment.CenterRight,
                TextColor = CSS_Color.PromptingColor1,
                TextSize = CSS_FontSize.TextFontSize,
                Text = function.GetRoomListName(),
            };
            locationMagtView.AddChidren(btnLocationValues);
 
            btnLocationInfoRight = new Button()
            {
                X = Application.GetRealWidth(339),
                Gravity = Gravity.CenterVertical,
                Width = Application.GetMinRealAverage(16),
                Height = Application.GetMinRealAverage(16),
                UnSelectedImagePath = "Public/RightIcon.png",
            };
            locationMagtView.AddChidren(btnLocationInfoRight);
 
            locationMagtView.AddChidren(
                new Button()
                {
                    Gravity = Gravity.CenterHorizontal,
                    Y = Application.GetRealHeight(54),
                    BackgroundColor = CSS_Color.DividingLineColor,
                    Width = Application.GetRealWidth(343),
                    Height = Application.GetRealHeight(1)
                });
            #endregion
 
            #region 共享
            //var sharedView = new FrameLayout()
            //{
            //    Height = Application.GetRealHeight(55),
            //    BackgroundColor = CSS_Color.MainBackgroundColor,
            //};
            //contentView.AddChidren(sharedView);
 
            //var btnSharedText = new Button()
            //{
            //    X = Application.GetRealWidth(16),
            //    Width = Application.GetRealWidth(160),
            //    TextAlignment = TextAlignment.CenterLeft,
            //    TextColor = CSS_Color.FirstLevelTitleColor,
            //    TextSize = CSS_FontSize.SubheadingFontSize,
            //    TextID = StringId.Shared,
            //};
            //sharedView.AddChidren(btnSharedText);
 
            //var btnSharedRight = new Button()
            //{
            //    X = Application.GetRealWidth(339),
            //    Gravity = Gravity.CenterVertical,
            //    Width = Application.GetMinRealAverage(16),
            //    Height = Application.GetMinRealAverage(16),
            //    UnSelectedImagePath = "Public/RightIcon.png",
            //};
            //sharedView.AddChidren(btnSharedRight);
 
            //sharedView.AddChidren(
            //    new Button()
            //    {
            //        Gravity = Gravity.CenterHorizontal,
            //        Y = Application.GetRealHeight(54),
            //        BackgroundColor = CSS_Color.DividingLineColor,
            //        Width = Application.GetRealWidth(343),
            //        Height = Application.GetRealHeight(1)
            //    });
            #endregion
 
#if stage2
            #region 添加到桌面
            var addToDesktopView = new FrameLayout()
            {
                Height = Application.GetRealHeight(55),
                BackgroundColor = CSS_Color.MainBackgroundColor,
            };
            contentView.AddChidren(addToDesktopView);
 
            var btnAddToDesktopText = new Button()
            {
                X = Application.GetRealWidth(16),
                Width = Application.GetRealWidth(160),
                TextAlignment = TextAlignment.CenterLeft,
                TextColor = CSS_Color.FirstLevelTitleColor,
                TextSize = CSS_FontSize.SubheadingFontSize,
                TextID = StringId.AddToDesktop,
            };
            addToDesktopView.AddChidren(btnAddToDesktopText);
 
            var btnAddToDesktopRight = new Button()
            {
                X = Application.GetRealWidth(339),
                Gravity = Gravity.CenterVertical,
                Width = Application.GetMinRealAverage(16),
                Height = Application.GetMinRealAverage(16),
                UnSelectedImagePath = "Public/RightIcon.png",
            };
            addToDesktopView.AddChidren(btnAddToDesktopRight);
 
            #endregion
#endif
 
            if (function.spk == SPK.ElectricEnergy)
            {
                #region 能源数据
                var energyView1 = new FrameLayout()
                {
                    Height = Application.GetRealHeight(55),
                    BackgroundColor = CSS_Color.MainBackgroundColor,
                };
                contentView.AddChidren(energyView1);
 
                var btnEnergyText1 = new Button()
                {
                    X = Application.GetRealWidth(16),
                    Width = Application.GetRealWidth(160),
                    TextAlignment = TextAlignment.CenterLeft,
                    TextColor = CSS_Color.FirstLevelTitleColor,
                    TextSize = CSS_FontSize.SubheadingFontSize,
                    TextID = StringId.RealTimeEnergyConsumption,
                };
                energyView1.AddChidren(btnEnergyText1);
 
 
                double realTimePower = 0;
                double.TryParse(function.GetAttrState(FunctionAttributeKey.Power), out realTimePower);
                realTimePower /= 1000;
 
                var energyValue1 = new Button()
                {
                    Width = Application.GetRealWidth(355),
                    TextAlignment = TextAlignment.CenterRight,
                    TextSize = CSS_FontSize.TextFontSize,
                    TextColor = CSS_Color.PromptingColor1,
                    Text = realTimePower + "kW",
                };
                energyView1.AddChidren(energyValue1);
 
                energyView1.AddChidren(
                    new Button()
                    {
                        Gravity = Gravity.CenterHorizontal,
                        Y = Application.GetRealHeight(54),
                        BackgroundColor = CSS_Color.DividingLineColor,
                        Width = Application.GetRealWidth(343),
                        Height = Application.GetRealHeight(1)
                    });
                //-----------------
 
                var energyView2 = new FrameLayout()
                {
                    Height = Application.GetRealHeight(55),
                    BackgroundColor = CSS_Color.MainBackgroundColor,
                };
                contentView.AddChidren(energyView2);
 
                var btnEnergyText2 = new Button()
                {
                    X = Application.GetRealWidth(16),
                    Width = Application.GetRealWidth(160),
                    TextAlignment = TextAlignment.CenterLeft,
                    TextColor = CSS_Color.FirstLevelTitleColor,
                    TextSize = CSS_FontSize.SubheadingFontSize,
                    TextID = StringId.EnergyConsumptionOfThisMonth,
                };
                energyView2.AddChidren(btnEnergyText2);
 
                var btnEnergyValue2 = new Button()
                {
                    Width = Application.GetRealWidth(355),
                    TextAlignment = TextAlignment.CenterRight,
                    TextSize = CSS_FontSize.TextFontSize,
                    TextColor = CSS_Color.PromptingColor1,
                    Text = "--kW",
                };
                energyView2.AddChidren(btnEnergyValue2);
 
                energyView2.AddChidren(
                    new Button()
                    {
                        Gravity = Gravity.CenterHorizontal,
                        Y = Application.GetRealHeight(54),
                        BackgroundColor = CSS_Color.DividingLineColor,
                        Width = Application.GetRealWidth(343),
                        Height = Application.GetRealHeight(1)
                    });
 
                new System.Threading.Thread(() =>
                {
                    var pm = new HttpServerRequest();
                    var data = pm.GetLastMonthHistory(function.deviceId, FunctionAttributeKey.TotalElectricity);
                    if (data != null)
                    {
                        if (data.Code == StateCode.SUCCESS)
                        {
                            var dataPack = Newtonsoft.Json.JsonConvert.DeserializeObject<JObject>(data.Data.ToString());
                            if (dataPack != null)
                            {
                                try
                                {
                                    var dataValue = dataPack.GetValue("monthDiff").ToString();
                                    if (!string.IsNullOrEmpty(dataValue))
                                    {
                                        Application.RunOnMainThread(() =>
                                        {
                                            btnEnergyValue2.Text = dataValue + "kW‧h";
                                        });
                                    }
                                }
                                catch
                                {
 
                                }
                            }
                        }
                    }
 
                })
                { IsBackground = true }.Start();
 
                #endregion
            }
 
            LoadEventList();
        }
 
 
    }
}