1
wxr
2023-03-31 7e42cc13a14b7de31c9f5d5c61cdf24f3246335d
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
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
using Shared.SimpleControl.Phone;
using System;
namespace Shared.SimpleControl.Pad
{
 
    /// <summary>
    /// 地热设备房间
    /// </summary>
    public class UserDeviceToFH : Shared.Dialog
    {
 
        /// <summary>
        /// 当前界面
        /// </summary>
        static UserDeviceToFH curView;
        UserFHPage ControlBodyView;
 
        FrameLayout bodyScrolView;
        VerticalScrolViewLayout RoomListScrolView;
 
        /// <summary>
        /// 构造函数
        /// </summary>
        public UserDeviceToFH ()
        {
            curView = this;
            showAllRoomFH ();
            readAllStatus ();
        }
 
        /// <summary>
        /// 更新当前地热
        /// </summary>
        public static void UpdateStatus (Common updataFH)
        {
            if (curView == null) {
                return;
            }
            Application.RunOnMainThread (() => {
                for (int i = 0; i < curView.RoomListScrolView.ChildrenCount; i++) {
                    if (curView.RoomListScrolView.GetChildren (i).GetType () == typeof (RowLayout)) {
                        var fhRow = (RowLayout)curView.RoomListScrolView.GetChildren (i);
                        if (fhRow.Tag.ToString () != updataFH.CommonLoopID) {
                            continue;
                        }
                        for (int j = 0; j < fhRow.ChildrenCount; j++) {
                            if (fhRow.GetChildren (j).GetType () == typeof (Button)) {
                                var btn = (Button)fhRow.GetChildren (j);
                                if (btn.Tag == null) {
                                    continue;
                                }
                                if (btn.Tag.ToString () == "Switch") {
                                    if ((updataFH as FoolHeat).Status == 0) {
                                        btn.IsSelected = false;
                                    } else {
                                        btn.IsSelected = true;
                                    }
                                } else if (btn.Tag.ToString () == "Temperature") {
                                    btn.Text = (updataFH as FoolHeat).WorkingTemperature.ToString () + "°C";
                                }
                            }
                        }
                    }
                }
            });
        }
 
        /// <summary>
        /// 显示房间的所有地热
        /// </summary>
        void showAllRoomFH ()
        {
            FrameLayout topBackView = new FrameLayout () {
                Height = Application.GetRealHeight (150),
                BackgroundColor = 0xFF2f2f2f
            };
            AddChidren (topBackView);
            #region 标题
            var topView = new FrameLayout () {
                Y = Application.GetRealHeight (36),
                Height = Application.GetRealHeight (90),
            };
            AddChidren (topView);
 
            var title = new Button () {
                TextAlignment = TextAlignment.Center,
                Text = Language.StringByID (R.MyInternationalizationString.FoolHeat),
                TextSize = 19,
            };
            topView.AddChidren (title);
 
            var logo = new Button () {
                Width = Application.GetRealWidth (154),
                Height = Application.GetRealHeight (90),
                X = Application.GetRealWidth (486),
                UnSelectedImagePath = MainPage.LogoString,
            };
            topView.AddChidren (logo);
            var back = new Button () {
                Height = Application.GetRealHeight (120),
                Width = Application.GetRealWidth (95),
                UnSelectedImagePath = "Item/Back.png",
                SelectedImagePath = "Item/BackSelected.png",
                Gravity = Gravity.CenterVertical,
            };
            topView.AddChidren (back);
            back.MouseUpEventHandler += (sender, e) => {
                Close ();
                curView = null;
            };
 
            var btnl = new Button () {
                Height = 1,
                BackgroundColor = 0xFF2f2f2f,
                Y = topView.Height - 1
            };
            topView.AddChidren (btnl);
            #endregion
 
            FrameLayout bordorView = new FrameLayout () {
                Width = Application.GetRealWidth (480),
                Height = Application.GetRealHeight (Application.DesignHeight - 150),
                Y = Application.GetRealHeight (150),
                BackgroundColor = 0xFF2f2f2f
            };
            AddChidren (bordorView);
 
 
            #region 全开-全关
            var powerView = new FrameLayout () {
                Height = Application.GetRealHeight (110),
                BackgroundColor = SkinStyle.Current.MainColor,
            };
            bordorView.AddChidren (powerView);
            var btnAllON = new Button () {
                Width = Application.GetRealWidth (240),
                TextSize = 16,
                TextID = R.MyInternationalizationString.ALLON,
                SelectedTextColor = SkinStyle.Current.SelectedColor,
                TextColor = SkinStyle.Current.TextColor1,
            };
            powerView.AddChidren (btnAllON);
            var btnAllOff = new Button () {
                Width = Application.GetRealWidth (240),
                X = btnAllON.Right,
                TextSize = 16,
                TextID = R.MyInternationalizationString.ALLOFF,
                SelectedTextColor = SkinStyle.Current.SelectedColor,
                TextColor = SkinStyle.Current.TextColor1,
            };
            var btnLine = new Button () {
                Width = 1,
                BackgroundColor = 0xFF2f2f2f,
                X = btnAllON.Right,
            };
            powerView.AddChidren (btnLine);
            var btnLine1 = new Button () {
                Height = 1,
                Y = powerView.Height - 1,
                BackgroundColor = 0xFF2f2f2f,
            };
            powerView.AddChidren (btnLine1);
            btnAllON.MouseUpEventHandler += (sender, e) => {
                btnAllON.TextColor = SkinStyle.Current.SelectedColor;
                btnAllOff.TextColor = SkinStyle.Current.TextColor1;
                controlAllFH (1);
            };
            powerView.AddChidren (btnAllOff);
            btnAllOff.MouseUpEventHandler += (sender, e) => {
                btnAllON.TextColor = SkinStyle.Current.TextColor1;
                btnAllOff.TextColor = SkinStyle.Current.SelectedColor;
                controlAllFH (0);
            };
            #endregion
 
 
            RoomListScrolView = new VerticalScrolViewLayout () {
                Width = LayoutParams.MatchParent,
                Height = Application.GetRealHeight (Application.DesignHeight - 300 - 140),
                Y = powerView.Bottom,
            };
            bordorView.AddChidren (RoomListScrolView);
 
 
            bodyScrolView = new FrameLayout () {
                Width = LayoutParams.MatchParent,
                Height = Application.GetRealHeight (Application.DesignHeight - 126),
                Y = powerView.Bottom,
            };
            bordorView.AddChidren (bodyScrolView);
 
            #region 显示全部的地热
            //显示所有
            int devcieCount = 0;
            foreach (var room in Room.Lists) {
                if (room.Name == "") {
                    continue;
                }
                foreach (var common in room.DeviceList.FindAll ((obj) => { return obj.Type == DeviceType.FoolHeat || obj.Type == DeviceType.FoolHeatPanel; })) {
                    var roomFH = common as FoolHeat;
 
                    EventHandler<MouseEventArgs> openFHControlPageEvent = (button, mouseEventArgs) => {
                        for (int i = 0; i < RoomListScrolView.ChildrenCount; i++) {
                            var view = RoomListScrolView.GetChildren (i);
                            if (view.Tag == roomFH) {
                                for (int j = 0; j < (view as FrameLayout).ChildrenCount; j++) {
                                    var btn = (view as FrameLayout).GetChildren (j);
                                    (btn as Button).IsSelected = true;
                                }
                            } else {
                                for (int j = 0; j < (view as FrameLayout).ChildrenCount; j++) {
                                    var btn = (view as FrameLayout).GetChildren (j);
                                    (btn as Button).IsSelected = false;
                                }
                            }
                        }
                        if (ControlBodyView != null) {
                            ControlBodyView.RemoveFromParent ();
                        }
                        ControlBodyView = new UserFHPage (roomFH, room) {
                            Width = Application.GetRealWidth (Application.DesignWidth) - bordorView.Width,
                            Height = Application.GetRealHeight (Application.DesignHeight - 150),
                            X = bordorView.Right,
                            Y = Application.GetRealHeight (150),
                            BackgroundColor = SkinStyle.Current.MainColor
                        };
                        AddChidren (ControlBodyView);
                        ControlBodyView.showRoomFH ();
                    };
 
 
                    FrameLayout fhView = new FrameLayout () {
                        Height = Application.GetRealHeight (140),
                        Tag = roomFH
                    };
                    fhView.Tag = roomFH.CommonLoopID;
                    RoomListScrolView.AddChidren (fhView);
 
                    var tempDeviceName = new Button () {
                        Padding = new Padding (0, 35, 0, 0),
                        Text = room.Name + " - " + common.Name,
                        Height = Application.GetRealHeight (140),
                        TextAlignment = TextAlignment.CenterLeft,
                        SelectedTextColor = SkinStyle.Current.SelectedColor,
                        TextColor = SkinStyle.Current.TextColor1,
                        BackgroundColor = SkinStyle.Current.Transparent,
                        SelectedBackgroundColor = SkinStyle.Current.MainColor
                    };
                    fhView.AddChidren (tempDeviceName);
                    tempDeviceName.MouseUpEventHandler += openFHControlPageEvent;
                    Button btnPoint = new Button () {
                        Width = Application.GetRealWidth (15),
                        Height = Application.GetRealHeight (15),
                        X = Application.GetRealWidth (45),
                        Gravity = Gravity.CenterVertical,
                        UnSelectedImagePath = "Item/Point.png",
                        SelectedImagePath = "Item/PointSelected.png",
                    };
                    fhView.AddChidren (btnPoint);
                    Button btnSelected = new Button () {
                        X = fhView.Width - 5,
                        Width = 5,
                        SelectedBackgroundColor = SkinStyle.Current.SelectedColor,
                        BackgroundColor = SkinStyle.Current.Transparent,
                    };
                    fhView.AddChidren (btnSelected);
                    if (devcieCount == 0) {
                        ControlBodyView = new UserFHPage (roomFH, room) {
                            Width = Application.GetRealWidth (Application.DesignWidth) - bordorView.Width,
                            Height = Application.GetRealHeight (Application.DesignHeight - 150),
                            X = bordorView.Right,
                            Y = Application.GetRealHeight (150),
                            BackgroundColor = SkinStyle.Current.MainColor
                        };
                        AddChidren (ControlBodyView);
                        ControlBodyView.showRoomFH ();
                        tempDeviceName.IsSelected = true;
                        btnPoint.IsSelected = true;
                    }
                    devcieCount++;
                }
            }
            #endregion
        }
 
        /// <summary>
        /// 控制所有地热
        /// </summary>
        /// <param name="b">The blue component.</param>
        void controlAllFH (byte b)
        {
            System.Threading.Tasks.Task.Run (() => {
                foreach (var room in Room.Lists) {
                    if (room == null)
                        continue;
                    if (room.Name == "") {
                        continue;
                    }
                    var list = room.DeviceList.FindAll ((obj) => {
                        return obj.Type == DeviceType.FoolHeat || obj.Type == DeviceType.FoolHeatPanel;
                    });
                    foreach (var common in list) {
                        (common as FoolHeat).Status = b;
 
                        var fh = common as FoolHeat;
 
                        if (fh.Type == DeviceType.FoolHeatPanel) {
                            Control.ControlBytesSend (Command.InstructionPanelKey, fh.SubnetID, fh.DeviceID, new byte [] { 20, fh.Status, fh.LoopID });
                        } else if (fh.Type == DeviceType.FoolHeat) {
                            fh = fh.Serverx_FH_CMD (FoolHeat.CommandType.Switch);
                        }
                    }
                }
            });
        }
 
        /// <summary>
        /// 显示当前多少是开的
        /// </summary>
        void updateFHOnCount ()
        {
            Application.RunOnMainThread (() => {
                for (int i = 0; i < curView.bodyScrolView.ChildrenCount; i++) {
                    if (curView.bodyScrolView.GetChildren (i).GetType () == typeof (RowLayout)) {
                        var roomRow = (RowLayout)curView.bodyScrolView.GetChildren (i);
                        if (roomRow.Tag != null) {
                            foreach (var room in Room.Lists) {
                                if (room.Name == "") {
                                    continue;
                                }
                                if (roomRow.Tag.ToString () == room.Name) {
                                    int oCount = 0;
                                    foreach (var common in room.DeviceList) {
                                        if (common.Type == DeviceType.FoolHeat) {
                                            if ((common as FoolHeat).Status > 0) {
                                                oCount++;
                                            }
                                        } else if (common.Type == DeviceType.FoolHeatPanel) {
                                            if ((common as FoolHeatPanel).Status > 0) {
                                                oCount++;
                                            }
                                        }
                                    }
 
                                    for (int j = 0; j < roomRow.ChildrenCount; j++) {
                                        if (roomRow.GetChildren (j).GetType () == typeof (EditText)) {
                                            var et = (EditText)roomRow.GetChildren (j);
                                            et.Text = oCount.ToString ();
                                        }
                                        if (roomRow.GetChildren (j).GetType () == typeof (Button)) {
                                            var btn = (Button)roomRow.GetChildren (j);
                                            if (oCount > 0) {
                                                btn.IsSelected = true;
                                            } else {
                                                btn.IsSelected = false;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            });
        }
 
        /// <summary>
        /// 读取设备状态
        /// </summary>
        void readAllStatus ()
        {
            System.Threading.Tasks.Task.Run (() => {
                System.Collections.Generic.List<string> readList = new System.Collections.Generic.List<string> ();
                foreach (Room room in Room.Lists) {
                    var list = room.DeviceList.FindAll ((obj) => {
                        return obj.LastUpdateTime.AddMinutes (Common.Time) <= DateTime.Now && (obj.Type == DeviceType.FoolHeat || obj.Type == DeviceType.FoolHeatPanel);
                    });
                    foreach (Common common in list) {
                        var s = common.Type + "_" + common.SubnetID + "_" + common.DeviceID + "_" + common.LoopID;
                        //已经读取过当前设备就不再读取
                        if (readList.Contains (s)) {
                            continue;
                        }
 
                        readList.Add (s);
 
                        var fh = common as FoolHeat;
 
                        if (fh.Type == DeviceType.FoolHeatPanel) {
                            Control.ControlBytesSend (Command.ReadInstructionPanelKey, fh.SubnetID, fh.DeviceID, new byte [] { 20, fh.LoopID, fh.LoopID });
                            Control.ControlBytesSend (Command.ReadInstructionPanelKey, fh.SubnetID, fh.DeviceID, new byte [] { 21, fh.LoopID, fh.LoopID });
                            Control.ControlBytesSend (Command.ReadInstructionPanelKey, fh.SubnetID, fh.DeviceID, new byte [] { 24, fh.LoopID, fh.LoopID });
                            Control.ControlBytesSend (Command.ReadInstructionPanelKey, fh.SubnetID, fh.DeviceID, new byte [] { 25, fh.LoopID, fh.LoopID });
                            Control.ControlBytesSend (Command.ReadInstructionPanelKey, fh.SubnetID, fh.DeviceID, new byte [] { 26, fh.LoopID, fh.LoopID });
                            Control.ControlBytesSend (Command.ReadInstructionPanelKey, fh.SubnetID, fh.DeviceID, new byte [] { 27, fh.LoopID, fh.LoopID });
                            Control.ControlBytesSend (Command.ReadInstructionPanelKey, fh.SubnetID, fh.DeviceID, new byte [] { 28, fh.LoopID, fh.LoopID });
                        } else if (fh.Type == DeviceType.FoolHeat) {
                            fh = fh.Serverx_FH_CMD (FoolHeat.CommandType.Read);
                        }
                    }
                }
            });
        }
 
    }
}