CrabtreeOn,印度客户定制APP,迁移2.0平台版本
wxr
2023-01-09 0fafbe4b132d03dc8f1f99de585bfcb5e63ab60a
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
using System;
using System.Collections.Generic;
 
namespace Shared.SimpleControl.Phone
{
    public class GuideSettingInfraredModule : Dialog
    {
        FrameLayout bodyView;
        VerticalScrolViewLayout EquipmentScrolView;
        public GuideSettingInfraredModule ()
        {
            bodyView = new FrameLayout ();
            this.AddChidren (bodyView);
            BackgroundColor = SkinStyle.Current.ViewColor;
        }
 
        public void ShowGuideSettingInfraredModule (InfraredMode infraredMode)
        {
            #region 标题
            var topView = new FrameLayout () {
                Y = Application.GetRealHeight (36),
                Height = Application.GetRealHeight (90),
                Width = Application.GetRealWidth (640),
            };
            AddChidren (topView);
 
            var title = new Button () {
                TextAlignment = TextAlignment.Center,
                Text = infraredMode.Name,
                TextColor = SkinStyle.Current.TextColor1,
                TextSize = 19,
            };
            topView.AddChidren (title);
            #endregion
 
        }
 
 
        void SaveAndReadDevices (Common device)
        {
            MainPage.Loading.Start ();
            System.Threading.Tasks.Task.Run (() => {
                if (hideListCommon != null && hideListCommon.Count != 0) {
                    foreach (Common c in hideListCommon) {
                        if (c.SubnetID == device.SubnetID && c.DeviceID == device.DeviceID) {
                            LoadDevice (c);
                            Application.RunOnMainThread (() => {
                                try {
                                    string ReadStr1 = "_" + c.SubnetID.ToString () + "_" + c.DeviceID.ToString () + "_";
                                    List<string> localEquipmentList1 = new List<string> ();
                                    List<string> files = IO.FileUtils.ReadFiles ().FindAll ((obj) => obj.Split ('_') [0] == "Equipment" && obj.Split ('_').Length == 5);
                                    foreach (string equipment in files) {
                                        if (equipment.Contains (ReadStr1) && c.Type.ToString () == equipment.Split ('_') [1]) {
                                            localEquipmentList1.Add (equipment);
                                        }
                                    }
                                    if (localEquipmentList1.Count > 0)
                                        InitDevicesList (localEquipmentList1, device);
                                } catch {
                                }
                            });
                            Utlis.WriteLine ("loadChildren");
                        }
                    }
                }
                LoadDevice (device);
 
                Application.RunOnMainThread (() => {
                    try {
                        string ReadStr = "_" + device.SubnetID.ToString () + "_" + device.DeviceID.ToString () + "_";
                        List<string> localEquipmentList = new List<string> ();
                        List<string> localFileList = IO.FileUtils.ReadFiles ();
                        foreach (string equipment in localFileList) {
                            if (equipment.Contains (ReadStr) && equipment.Split ('_').Length == 5) {
                                if (device.Type.ToString () == typeof (LightLogic).Name || equipment.Contains (device.Type.ToString ())) {
                                    if (equipment.Split ('_') [0] == "Equipment")
                                        localEquipmentList.Add (equipment);
                                }
                            }
                        }
                        if (localEquipmentList.Count == 0 && device.Type != DeviceType.InfraredMode) {
                            if (device.Type != DeviceType.RCU) {
                                new Alert ("", Language.StringByID (R.MyInternationalizationString.TipEquipmentNotOnline), Language.StringByID (R.MyInternationalizationString.Close)).Show ();
                                return;
                            }
                        }
                        InitDevicesList (localEquipmentList, device);
                    } catch {
                    } finally {
                        MainPage.Loading.Hide ();
                    }
                });
            });
        }
        List<Common> hideListCommon;
        public void EquipmentBaseViewShow (Common device)
        {
             hideListCommon = new List<Common> ();
            List<string> localFileList = IO.FileUtils.ReadFiles ();
            foreach (var deviceFile in localFileList) {
                if (deviceFile.Split ('_') [0] != "Equipment" || deviceFile.Split ('_').Length != 5) {
                    continue;
                }
                string localFileType = deviceFile.Split ('_') [1];
 
                byte [] equipmentUsefullBytes = IO.FileUtils.ReadFile (deviceFile);
                Common common = null;
               var equipmentString = CommonPage.MyEncodingUTF8.GetString (equipmentUsefullBytes);
                common = Newtonsoft.Json.JsonConvert.DeserializeObject<Common> (equipmentString);
                if (common == null) {
                    continue;
                }
                if (common.isMixBox) {
                    hideListCommon.Add (common);
                }
            }
            bodyView.RemoveAll ();
            #region 标题
            var topView = new FrameLayout () {
                Y = Application.GetRealHeight (36),
                Height = Application.GetRealHeight (90),
                Width = Application.GetRealWidth (640),
            };
            bodyView.AddChidren (topView);
 
            var title = new Button () {
                TextAlignment = TextAlignment.Center,
                Text = device.Name,
                TextColor = SkinStyle.Current.TextColor1,
                TextSize = 19,
            };
            topView.AddChidren (title);
            #endregion
 
            EquipmentScrolView = new VerticalScrolViewLayout () {
                Y = topView.Bottom,
                Height = Application.GetRealHeight (1136 - 126 - 91),
            };
            bodyView.AddChidren (EquipmentScrolView);
 
            SaveAndReadDevices (device);
 
            #region bottom
            EventHandler<MouseEventArgs> eHandler = new EventHandler<MouseEventArgs> (delegate (object sender, MouseEventArgs e) {
                Close ();
                return;
                System.Threading.Tasks.Task.Run (() => {
                    Application.RunOnMainThread (() => {
                        MainPage.Loading.Start ();
                    });
                    string delFlag = "_" + device.SubnetID.ToString () + "_" + device.DeviceID.ToString () + "_";
 
                    var delFiles = IO.FileUtils.ReadFiles ().FindAll ((w) => {
                        return w.Contains (delFlag);
                    });
                    for (int i = 0; i < delFiles.Count; i++) {
                        if (delFiles [i].Split ('_').Length == 5) {
                            if (delFiles [i].Split ('_') [0] == "Equipment")
                                IO.FileUtils.DeleteFile (delFiles [i]);
                        }
                    }
                    Random ran = new Random ();
                    CommonPage.RandomHigh = (byte)ran.Next (0, 255);
                    CommonPage.RandomLow = (byte)ran.Next (0, 255);
                    CommonPage.LocalPhoneFindDevice = true;
                    CommonPage.DeviceList.Clear ();
                    Control.ControlBytesSendHasReturn (Command.ReadDeviceModul, device.SubnetID, device.DeviceID, new byte [] { (byte)CommonPage.RandomHigh, (byte)CommonPage.RandomLow });
                    CommonPage.LocalPhoneFindDevice = false;
 
                    Application.RunOnMainThread (() => {
                        bodyView.RemoveAll ();
                        EquipmentBaseViewShow (device);
                    });
                });
            });
            var sysBottomView = new FrameLayout () {
                Height = Application.GetRealHeight (90),
                Y = EquipmentScrolView.Bottom,
            };
            AddChidren (sysBottomView);
 
            Button AddSystemEquipmentButton = new Button () {
                Width = LayoutParams.MatchParent,
                Height = LayoutParams.MatchParent,
                TextID = R.MyInternationalizationString.ReFresh,
                TextAlignment = TextAlignment.Center,
                TextColor = SkinStyle.Current.TextColor1,
                BackgroundColor = SkinStyle.Current.MainColor
            };
            sysBottomView.AddChidren (AddSystemEquipmentButton);
            AddSystemEquipmentButton.MouseUpEventHandler += eHandler;
            sysBottomView.AddChidren (new Button () { Height = 1, BackgroundColor = SkinStyle.Current.White20Transparent });
            #endregion
        }
 
        /// <summary>
        /// 读取设备信息
        /// </summary>
        /// <param name="device">Device.</param>
        void LoadDevice (Common device)
        {
            string ReadStr = "_" + device.SubnetID.ToString () + "_" + device.DeviceID.ToString () + "_";
            List<string> localEquipmentList = new List<string> ();
            foreach (string equipment in IO.FileUtils.ReadFiles ().FindAll ((obj) => obj.Split ('_') [0] == "Equipment")) {
                if (equipment.Contains (ReadStr) && equipment.Split ('_').Length == 5) {
                    if (device.Type.ToString () == DeviceType.LightLogic.ToString () || (equipment.Contains (device.Type.ToString ())))
                        localEquipmentList.Add (equipment);
                }
            }
 
            if (localEquipmentList.Count != 0) {
                return;
            }
            byte bigClass = device.BigClass;
            byte minClass = device.MinClass;
            int count = device.LoopCount;
            if (bigClass == 254)
                return;
 
            CommonPage.DeviceLoopList.Clear ();
 
            for (int i = 1, j = 0; i <= count; i++) {
                var loopBytes = Control.ControlBytesSendHasReturn (Command.ReadDeviceLoopInfo, device.SubnetID, device.DeviceID, new byte [] { bigClass, minClass, (byte)i });
                if (loopBytes == null) {
                    while (SystemWirelessGateway.Waiting) {
                        System.Threading.Thread.Sleep (100);
                    }
                    j++;
                    //连续两次读取不到数据则跳出该循环
                    if (j == 2 && i == 2)
                        break;
                }
            }
        }
 
        /// <summary>
        /// 显示设备列表
        /// </summary>
        void LoadInterface (EventHandler<MouseEventArgs> eHandler, string textName, Button btn = null)
        {
            RowLayout frameLayout1 = new RowLayout () {
                Width = LayoutParams.MatchParent,
                Height = Application.GetRealHeight (93),
            };
            frameLayout1.MouseUpEventHandler += eHandler;
            EquipmentScrolView.AddChidren (frameLayout1);
 
            Button pointButton = new Button () {
                Width = Application.GetRealHeight (13),
                Height = Application.GetRealHeight (13),
                X = Application.GetRealWidth (86),
                UnSelectedImagePath = "Item/Point.png",
                SelectedImagePath = "Item/PointSelected.png",
                Gravity = Gravity.CenterVertical,
            };
            frameLayout1.AddChidren (pointButton);
 
            Button nameButton = new Button () {
                Width = Application.GetRealWidth (242),
                Height = LayoutParams.MatchParent,
                Text = textName,
                TextAlignment = TextAlignment.CenterLeft,
                X = Application.GetRealWidth (135),
                TextColor = SkinStyle.Current.TextColor1
            };
            nameButton.MouseUpEventHandler += eHandler;
            frameLayout1.AddChidren (nameButton);
 
            if (eHandler != null) {
                Button rightButton = new Button () {
                    Width = Application.GetRealWidth (28),
                    Height = Application.GetRealHeight (40),
                    Gravity = Gravity.CenterVertical,
                    UnSelectedImagePath = "Item/Right.png",
                    SelectedImagePath = "Item/RightSelected.png",
                };
                rightButton.X = frameLayout1.Width - rightButton.Width - Application.GetRealWidth (30);
                rightButton.MouseUpEventHandler += eHandler;
                frameLayout1.AddChidren (rightButton);
            }
 
            if (btn != null) {
                frameLayout1.AddChidren (btn);
            }
        }
 
        /// <summary>
        /// 加载设备数据
        /// </summary>
        void InitDevicesList (List<string> listDevice, Common device)
        {
            if (listDevice.Count == 0)
                return;
            RowLayout fl = new RowLayout () {
                Height = Application.GetRealHeight (93),
                BackgroundColor = SkinStyle.Current.MainColor
            };
            //if (isMixBox == false)
            EquipmentScrolView.AddChidren (fl);
 
            Button btnDeviceName = new Button () {
                Width = Application.GetRealWidth (303),
                Height = Application.GetRealHeight (55),
                X = Application.GetRealWidth (86),
                Y = Application.GetRealHeight (20),
                TextAlignment = TextAlignment.CenterLeft,
                TextColor = SkinStyle.Current.TextColor1
            };
            fl.AddChidren (btnDeviceName);
 
            try {
                //设备界面要显示的设备,必须在这里添加显示
                for (int i = 0; i < listDevice.Count; i++) {
                    if (listDevice [i].Split ('_').Length == 5) {
                        if (listDevice [i].Split ('_') [1].Contains (DeviceType.InfraredMode.ToString ())) {
                            btnDeviceName.TextID = R.MyInternationalizationString.InfraredEquipments;
                            InfraredMode infrared = Newtonsoft.Json.JsonConvert.DeserializeObject<InfraredMode> (
                                CommonPage.MyEncodingUTF8.GetString (IO.FileUtils.ReadFile (listDevice [i])));
                            EventHandler<MouseEventArgs> clickEventHandler = new EventHandler<MouseEventArgs> (delegate (object sender, MouseEventArgs e) {
                                Dialog dialog = new Dialog ();
                                var systemInfrared = new SystemInfrared ();
                                dialog.AddChidren (systemInfrared);
                                systemInfrared.ShowSystemInfrared (infrared, device);
                                dialog.Show ();
                            });
                            LoadInterface (clickEventHandler, infrared.Name);
                        }
                    }
                }
            } catch (Exception ex) {
                Utlis.WriteLine ("SystemEquipmentBase,AddDevicesList" + ex.ToString ());
            }
        }
 
    }
}