mac
2024-07-25 3f6685c77beeb12baf840733fb890860f4c26e7c
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
using System;
using System.Collections.Generic;
using HDL_ON.Common;
using HDL_ON.DAL.Server;
using HDL_ON.Entity;
using HDL_ON.UI.CSS;
using Newtonsoft.Json;
using Shared;
 
namespace HDL_ON.UI
{
    public class CombinedDimmingListPage : FrameLayout
    {
        FrameLayout bodyView;
        VerticalScrolViewLayout contentView;
 
        public CombinedDimmingListPage()
        {
            bodyView = this;
        }
 
        public void LoadPage()
        {
 
            var topView = new TopViewDiv(bodyView, Language.StringByID(StringId.GroupControl));
            topView.maginY = 10;
            topView.LoadTopView_AddIcon("CombinedDimming",
                (s, c) =>
                {
                    try
                    {
                        var page = new AddGroupControlPage(null,
                            (newGC) =>
                            {
                                Application.RunOnMainThread(() =>
                                {
                                    LoadGroupControlView();
                                });
                            }, () => { });
                        MainPage.BasePageView.AddChidren(page);
                        page.LoadPage();
                        MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1;
                    }
                    catch { }
                });
 
            contentView = new VerticalScrolViewLayout()
            {
                Y = Application.GetRealHeight(64+10),
                Height = Application.GetRealHeight(667 - 64-10),
                BackgroundColor = CSS_Color.MainBackgroundColor,
            };
            bodyView.AddChidren(contentView);
 
            ReadGroupControlList();
 
            #region 
            contentView.AddChidren(new Button() { Height = Application.GetRealHeight(8) });
 
 
 
            #endregion
 
        }
        /// <summary>
        /// 读取组控数据
        /// </summary>
        private void ReadGroupControlList()
        {
 
            new System.Threading.Thread(() =>
            {
                var pack = ApiUtlis.Ins.HttpRequest.GetGroupControlList();
                if (pack != null)
                {
                    if (pack.Code == StateCode.SUCCESS)
                    {
                        try
                        {
                            //FunctionList.List.groupControls.Clear();
                            //FunctionList.List.groupControls = Newtonsoft.Json.JsonConvert.DeserializeObject<List<GroupControl>>(pack.Data.ToString());
 
                            try
                            {
                                var groupControlList = JsonConvert.DeserializeObject<List<GroupControl>>(pack.Data.ToString());
                                var readSidList = new List<string>();
                                foreach (var temp in groupControlList)
                                {
                                    FunctionList.List.groupControls.Clear();
                                    readSidList.Add(temp.userDeviceGroupControlId);
                                    if (readSidList.Count >= 20)
                                    {
                                        var data = ApiUtlis.Ins.HttpRequest.GetGroupControInfo(readSidList);
                                        if (data != null)
                                        {
                                            if (data.Code == StateCode.SUCCESS)
                                            {
                                                var groupControlInfoList = JsonConvert.DeserializeObject<List<GroupControl>>(data.Data.ToString());
                                                FunctionList.List.groupControls.AddRange(groupControlInfoList);
                                            }
                                            else
                                            {
                                                IMessageCommon.Current.ShowErrorInfoAlter(pack.Code);
                                            }
                                        }
                                        readSidList.Clear();
                                    }
                                }
                                if (readSidList.Count > 0)
                                {
                                    var data = ApiUtlis.Ins.HttpRequest.GetGroupControInfo(readSidList);
                                    if (data != null)
                                    {
                                        if (data.Code == StateCode.SUCCESS)
                                        {
                                            var groupControlInfoList = JsonConvert.DeserializeObject<List<GroupControl>>(data.Data.ToString());
                                            FunctionList.List.groupControls.AddRange(groupControlInfoList);
                                        }
                                        else
                                        {
                                            IMessageCommon.Current.ShowErrorInfoAlter(pack.Code);
                                        }
                                    }
                                    readSidList.Clear();
                                }
                            }
                            catch (Exception ex)
                            {
                                MainPage.Log($"读取组控列表失败:{ex.Message}");
                            }
 
                            Application.RunOnMainThread(() =>
                            {
                                LoadGroupControlView();
                            });
                        }
                        catch (Exception ex)
                        {
                            MainPage.Log($"读取组控列表失败:{ex.Message}");
                        }
                    }
                    else
                    {
                        IMessageCommon.Current.ShowErrorInfoAlter(pack.Code);
                    }
                }
            })
            { IsBackground = true }.Start();
 
        }
 
 
        private void LoadGroupControlView()
        {
            contentView.RemoveAll();
 
            foreach (var groupControl in FunctionList.List.groupControls)
            {
                var functionRow = new RowLayout()
                {
                    Height = Application.GetRealHeight(65),
                    BackgroundColor = CSS_Color.MainBackgroundColor,
                    LineColor = 0x00000000
                };
                contentView.AddChidren(functionRow);
 
                var btnRight = new Button()
                {
                    X = Application.GetRealWidth(339),
                    Gravity = Gravity.CenterVertical,
                    Width = Application.GetMinRealAverage(16),
                    Height = Application.GetMinRealAverage(16),
                    UnSelectedImagePath = "Public/Right.png",
                };
                functionRow.AddChidren(btnRight);
 
                var btnFunctionName = new Button()
                {
                    X = Application.GetRealWidth(16),
                    Y = Application.GetRealHeight(10),
                    Width = Application.GetRealWidth(308),
                    Height = Application.GetRealHeight(24),
                    TextAlignment = TextAlignment.CenterLeft,
                    TextSize = CSS_FontSize.SubheadingFontSize,
                    TextColor = CSS_Color.FirstLevelTitleColor,
                    Text = groupControl.name,
                };
                functionRow.AddChidren(btnFunctionName);
 
                var btnFunctionLocationInfo = new Button()
                {
                    X = Application.GetRealWidth(16),
                    Y = btnFunctionName.Bottom,
                    Width = Application.GetRealWidth(308),
                    Height = Application.GetRealHeight(21),
                    TextAlignment = TextAlignment.CenterLeft,
                    TextSize = CSS_FontSize.PromptFontSize_FirstLevel,
                    TextColor = CSS_Color.PromptingColor1,
                    Text = groupControl.GetRoomListName(),
                };
                functionRow.AddChidren(btnFunctionLocationInfo);
 
 
 
                functionRow.AddChidren(
                    new Button()
                    {
                        Gravity = Gravity.CenterHorizontal,
                        Y = Application.GetRealHeight(64),
                        Height = Application.GetRealHeight(1),
                        Width = Application.GetRealWidth(343),
                        BackgroundColor = CSS_Color.DividingLineColor,
                    });
 
                EventHandler<MouseEventArgs> eventHandler = (sender, e) =>
                {
                    var page = new AddGroupControlPage(groupControl,
                       (newGC) =>
                       {
                           try
                           {
                               if (newGC != null)
                               {
                                   Application.RunOnMainThread(() =>
                                   {
                                       var localTemp = FunctionList.List.groupControls.Find((obj) => obj.deviceId == newGC.deviceId);
                                       localTemp.roomIds = newGC.roomIds;
                                       localTemp.uids = newGC.uids;
                                       localTemp.sids = newGC.sids;
                                       localTemp.name = newGC.name;
                                       btnFunctionLocationInfo.Text = newGC.GetUidListName();
                                       btnFunctionName.Text = newGC.name;
                                   });
                               }
                           }
                           catch (Exception ex)
                           {
                               MainPage.Log($"刷新群控房间信息异常:{ex.Message}");
                           }
                       }, () =>
                       {
                           LoadGroupControlView();
                       });
                    MainPage.BasePageView.AddChidren(page);
                    page.LoadPage();
                    MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1;
                };
                functionRow.MouseUpEventHandler = eventHandler;
                btnRight.MouseUpEventHandler = eventHandler;
                btnFunctionName.MouseUpEventHandler = eventHandler;
                btnFunctionLocationInfo.MouseUpEventHandler = eventHandler;
 
                var btnDelGroupControl = new Button()
                {
                    TextColor = CSS_Color.MainBackgroundColor,
                    BackgroundColor = CSS_Color.WarningColor,
                    TextID = StringId.Del,
                    TextAlignment = TextAlignment.Center,
                };
                functionRow.AddRightView(btnDelGroupControl);
                btnDelGroupControl.MouseUpEventHandler = (sender1, e1) =>
                {
                    var waitPage = new Loading();
                    this.AddChidren(waitPage);
                    waitPage.Start("");
                    new System.Threading.Thread(() =>
                    {
                        try
                        {
                            var pack = ApiUtlis.Ins.HttpRequest.DelGroupControl(groupControl.userDeviceGroupControlId);
                            if (pack != null)
                            {
                                Application.RunOnMainThread(() =>
                                {
                                    try
                                    {
                                        if (pack.Code == StateCode.SUCCESS)
                                        {
                                            var delTemp = FunctionList.List.groupControls.Find((obj) => groupControl.sid == obj.sid);
                                            FunctionList.List.groupControls.Remove(delTemp);
                                            LoadGroupControlView();
                                        }
                                        else
                                        {
                                            IMessageCommon.Current.ShowErrorInfoAlter(pack.Code);
                                        }
                                    }
                                    catch (Exception ex)
                                    {
                                        MainPage.Log($"刷新组控数据异常:{ex.Message}");
                                    }
                                });
                            }
                        }
                        catch (Exception ex)
                        {
                            MainPage.Log($"删除组控异常:{ex.Message}");
                        }
                        finally
                        {
                            Application.RunOnMainThread(() =>
                            {
                                if (waitPage != null)
                                {
                                    waitPage.Hide();
                                    waitPage.RemoveFromParent();
                                    waitPage = null;
                                }
                            });
                        }
                    })
                    { IsBackground = true }.Start();
                };
 
            }
 
        }
 
 
    }
}