wxr
2023-07-29 166c81e63cd1d0a1649823e4299daeaaf1ea0987
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
using System;
using System.Collections.Generic;
using HDL_ON.DAL.Server;
using HDL_ON.DriverLayer;
using HDL_ON.Entity;
using HDL_ON.UI.CSS;
using Shared;
namespace HDL_ON.UI
{
    /// <summary>
    /// 三相空开能源界面
    /// </summary>
    public class AirSwitchP3EnergyPage : FrameLayout
    {
        static AirSwitchP3EnergyPage bodyView;
 
        /// <summary>
        /// 总功耗-饼图
        /// </summary>
        MyEchartsViewOn myEchartsView_Pie;
        /// <summary>
        /// 曲线图数据string
        /// </summary>
        EchartsOption_BrokenLine brokenLine;
 
 
        /// <summary>
        /// 插查询的能源列表
        /// </summary>
        List<Function> queryList = new List<Function>();
        /// <summary>
        /// 查询条件
        /// hour、week、month
        /// </summary>
        string curQueryType = "hour";
 
 
        /// <summary>
        /// 能源列表区域
        /// </summary>
        FrameLayout energyListView;
        /// <summary>
        /// 历史数据图表
        /// </summary>
        MyEchartsViewOn myEchartsView_Line;
 
        //5C62FE
 
        Function device;
        /// <summary>
        /// 主页
        /// </summary>
        public AirSwitchP3EnergyPage(Function function)
        {
            bodyView = this;
            device = function;
        }
 
        /// <summary>
        /// 
        /// </summary>
        public void LoadPage()
        {
            new TopViewDiv(bodyView, Language.StringByID(StringId.EnergyMonitoring)).LoadTopView(0xFFF7F7F7);
            bodyView.BackgroundColor = 0xFFF5F7FA;
 
            var contentView = new VerticalScrolViewLayout()
            {
                Y = Application.GetRealHeight(64),
                Height = Application.GetRealHeight(667-64),
                BackgroundColor = 0xFFF5F7FA,
            };
            bodyView.AddChidren(contentView);
 
            contentView.AddChidren(new Button()
            {
                Height = Application.GetRealHeight(12),
            });
 
 
            brokenLine = new EchartsOption_BrokenLine();
 
            #region 选择数据日期范围
            var showDataTypeView = new FrameLayout()
            {
                X = Application.GetRealWidth(143),
                Y = Application.GetRealHeight(12),
                Width = Application.GetRealWidth(216),
                Height = Application.GetRealHeight(27),
                //BackgroundImagePath = "FunctionIcon/EnvironmentalScience/SensorHistoryBg1.png",
            };
            contentView.AddChidren(showDataTypeView);
 
            var btnShowHistroyData_Day = new Button()
            {
                Width = Application.GetRealWidth(54),
                Height = Application.GetRealHeight(27),
                TextAlignment = TextAlignment.Center,
                TextColor = CSS_Color.PromptingColor1,
                SelectedTextColor = CSS_Color.MainColor,
                TextSize = CSS_FontSize.PromptFontSize_FirstLevel,
                IsSelected = true,
                TextID = StringId.day,
                SelectedBackgroundColor = 0x1F5C62FE,
                BackgroundColor = 0x1F5C62FE,
                BorderColor = CSS_Color.MainColor,
                BorderWidth = 2,
            };
            showDataTypeView.AddChidren(btnShowHistroyData_Day);
            btnShowHistroyData_Day.SetCornerWithSameRadius((uint)Application.GetRealHeight(6), HDLUtils.RectCornerTopLeft | HDLUtils.RectCornerBottomLeft);
 
          
            var btnShowHistroyData_Month = new Button()
            {
                X = Application.GetRealWidth(54),
                Width = Application.GetRealWidth(54),
                TextAlignment = TextAlignment.Center,
                TextColor = CSS_Color.PromptingColor1,
                SelectedTextColor = CSS_Color.MainColor,
                TextSize = CSS_FontSize.PromptFontSize_FirstLevel,
                TextID = StringId.month,
                BorderWidth = 1,
                BorderColor = CSS_Color.PromptingColor1,
            };
            showDataTypeView.AddChidren(btnShowHistroyData_Month);
 
            var btnShowHistroyData_Year = new Button()
            {
                X = Application.GetRealWidth(54 * 2),
                Width = Application.GetRealWidth(54),
                TextAlignment = TextAlignment.Center,
                TextColor = CSS_Color.PromptingColor1,
                SelectedTextColor = CSS_Color.MainColor,
                TextSize = CSS_FontSize.PromptFontSize_FirstLevel,
                TextID = StringId.Years,
                BorderWidth = 1,
                BorderColor = CSS_Color.PromptingColor1,
            };
            showDataTypeView.AddChidren(btnShowHistroyData_Year);
 
            var btnShowHistroyData_Total = new Button()
            {
                X = Application.GetRealWidth(54 * 3),
                Width = Application.GetRealWidth(54),
                TextAlignment = TextAlignment.Center,
                TextColor = CSS_Color.PromptingColor1,
                SelectedTextColor = CSS_Color.MainColor,
                TextSize = CSS_FontSize.PromptFontSize_FirstLevel,
                TextID = StringId.Total,
                BorderWidth = 1,
                BorderColor = CSS_Color.PromptingColor1,
            };
            showDataTypeView.AddChidren(btnShowHistroyData_Total);
 
 
            btnShowHistroyData_Day.MouseUpEventHandler = (sender, e) =>
            {
                //showDataTypeView.BackgroundImagePath = "FunctionIcon/EnvironmentalScience/SensorHistoryBg1.png";
                //btnShowHistroyData_Day.IsSelected = true;
                //btnShowHistroyData_Year.IsSelected = false;
                //btnShowHistroyData_Month.IsSelected = false;
                //curQueryType = "hour";
                //brokenLine.YvalueText = "";
                //foreach (var enery in queryList)
                //{
                //    LoadMothed_GetHistoryData(enery, false);
                //}
            };
 
            btnShowHistroyData_Month.MouseUpEventHandler = (sender, e) =>
            {
                //showDataTypeView.BackgroundImagePath = "FunctionIcon/EnvironmentalScience/SensorHistoryBg2.png";
                //btnShowHistroyData_Day.IsSelected = false;
                //btnShowHistroyData_Year.IsSelected = false;
                //btnShowHistroyData_Month.IsSelected = true;
                //curQueryType = "week";
                //brokenLine.YvalueText = "";
                //foreach (var enery in queryList)
                //{
                //    LoadMothed_GetHistoryData(enery, false);
                //}
            };
            btnShowHistroyData_Year.MouseUpEventHandler = (sender, e) =>
            {
                //showDataTypeView.BackgroundImagePath = "FunctionIcon/EnvironmentalScience/SensorHistoryBg3.png";
                //btnShowHistroyData_Day.IsSelected = false;
                //btnShowHistroyData_Year.IsSelected = true;
                //btnShowHistroyData_Month.IsSelected = false;
                //curQueryType = "month";
                //brokenLine.YvalueText = "";
                //foreach (var enery in queryList)
                //{
                //    LoadMothed_GetHistoryData(enery, false);
                //}
            };
 
            #endregion
 
            contentView.AddChidren(new Button()
            {
                Height = Application.GetRealHeight(12),
            });
 
            var historyDataView = new FrameLayout()
            {
                Gravity = Gravity.CenterHorizontal,
                Width = Application.GetRealWidth(343),
                Height = Application.GetRealWidth(330),
            };
            contentView.AddChidren(historyDataView);
 
            myEchartsView_Line = new MyEchartsViewOn()
            {
                Y = Application.GetRealWidth(10),
                Height = Application.GetRealWidth(280),
            };
            historyDataView.AddChidren(myEchartsView_Line);
 
            //EnergyRow(energy, energyListView, index);
            new System.Threading.Thread(() =>
                {
                    Control.Ins.SendReadCommand(device);
                })
                { IsBackground = true }.Start();
 
 
        }
 
 
 
 
        /// <summary>
        /// 读取历史数据
        /// </summary>
        void LoadMothed_GetHistoryData()
        {
 
            var loadPage = new Loading()
            {
                LodingBackgroundColor = 0x88888888,
            };
            bodyView.AddChidren(loadPage);
 
            new System.Threading.Thread(() =>
            {
                try
                {
                    Application.RunOnMainThread(() =>
                    {
                        loadPage.Start(Language.StringByID(StringId.PleaseWait));
                    });
 
                    var sensorType = device.spk.Split(".")[1];
                    var revertObj = new HttpServerRequest().GetSensorHistory(curQueryType, device.deviceId, "total_electricity");
                    if (revertObj != null)
                    {
                        if (revertObj.Code == StateCode.SUCCESS)
                        {
                            var revertData = Newtonsoft.Json.JsonConvert.DeserializeObject<List<EnvironmentalSensorHistor>>(revertObj.Data.ToString());
 
                            List<string> vs = new List<string>();
                            if (brokenLine.YvalueText == "")
                            {
                                foreach (var data in revertData)
                                {
                                    vs.Add(data.fieldName);
                                }
                                brokenLine.InitXdataText(vs);
                            }
                            if (device.GetAttribute("ydata") == null)
                            {
                                device.attributes.Add(new FunctionAttributes() { key = "ydata" });
                            }
                            device.SetAttrState("ydata", brokenLine.InitYdataText(device.name, revertData, device.GetAttrState("color")) + ",");
                        }
                    }
                    brokenLine.yTitle = Language.StringByID(StringId.EnergyConsumption) + "(kW)";
                    brokenLine.xTitle = Language.StringByID(StringId.timeMode);
                    if (curQueryType != "hour")
                    {
                        brokenLine.xTitle = Language.StringByID(StringId.Date);
                    }
                    var opString = brokenLine.InitOption();
 
                    Application.RunOnMainThread(() =>
                    {
                        myEchartsView_Line.ShowWithOption(opString);
                    });
                }
                catch (Exception ex)
                {
                    MainPage.Log($"sensor history error : {ex.Message}");
                }
                finally
                {
                    Application.RunOnMainThread(() =>
                    {
                        loadPage.Hide();
                    });
                }
            })
            { IsBackground = true }.Start();
        }
 
 
    }
}