JLChen
2020-06-04 6d55af8792cf8fbef0055e677b900fc352dba9a2
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
using System;
namespace Shared.SimpleControl.Phone
{
    public class SystemMusicModel : FrameLayout
    {
        void UpdateOnePorWirelessFR (MusicModel musciModel)
        {
            byte [] bytes = new byte [51];
            bytes [0] = musciModel.BigClass;
            bytes [1] = musciModel.MinClass;
            bytes [2] = musciModel.ChNumberCount;
            string [] mac = musciModel.MAC.Split ('.');
            for (int i = 0; i < mac.Length; i++)
                bytes [i + 3] = Convert.ToByte (mac [i], 16);
            //Remark需要解码
            byte [] ddd = CommonPage.MyEncodingGB2312.GetBytes (musciModel.Name);
            Array.Copy (ddd, 0, bytes, 11, 20 < ddd.Length ? 20 : ddd.Length);
            string [] ipAddress = musciModel.IPAddress.Split ('.');
            for (int i = 0; i < ipAddress.Length; i++)
                bytes [i + 31] = byte.Parse (ipAddress [i]);
            string [] r = musciModel.RouteIPAddress.Split ('.');
            for (int i = 0; i < r.Length; i++)
                bytes [i + 35] = byte.Parse (r [i]);
            string [] ipMac = musciModel.IPMAC.Split ('.');
            //ipMAC前三位HDL  需要特殊处理
            bytes [0 + 39] = (byte)(ipMac [0].ToCharArray () [0]);
            bytes [1 + 39] = (byte)(ipMac [1].ToCharArray () [0]);
            bytes [2 + 39] = (byte)(ipMac [2].ToCharArray () [0]);
            bytes [3 + 39] = byte.Parse (ipMac [3]);
            bytes [4 + 39] = byte.Parse (ipMac [4]);
            bytes [5 + 39] = byte.Parse (ipMac [5]);
            string [] subnetMask = musciModel.SubnetMask.Split ('.');
            for (int i = 0; i < subnetMask.Length; i++)
                bytes [i + 45] = byte.Parse (subnetMask [i]);
            //Control.ControlBytesSend (Command.SetBaseInfo,
            //                          musciModel.SubnetID,
            //                          musciModel.DeviceID,
            //                          bytes);
 
            //IO.FileUtils.SaveEquipmentMessage (musciModel);
        }
 
        public void ShowMusicModel (MusicModel musicModel)
        {
            VerticalScrolViewLayout sView = new VerticalScrolViewLayout (){
                Height = Application.GetRealHeight (844),
            };
            AddChidren (sView);
            #region ---------------title---------------
            RowLayout frameLayout = new RowLayout () {
                Height = Application.GetRealHeight (100),
                Width = LayoutParams.MatchParent,
                BackgroundColor = SkinStyle.Current.MainColor
            };
            sView.AddChidren (frameLayout);
 
            Button backButton = new Button () {
                X = Application.GetRealWidth (0),
                Height = Application.GetRealHeight (90),
                Width = Application.GetRealWidth (85),
                UnSelectedImagePath = "Item/Back.png",
                SelectedImagePath = "Item/BackSelected.png",
                Gravity = Gravity.CenterVertical,
            };
            backButton.MouseUpEventHandler += (sender, e) => {
                (Parent as PageLayout).PageIndex -= 1;
                //SystemMiddle.ShowGateWayView ();
            };
            frameLayout.AddChidren (backButton);
            string strOnePortWirelessFRRemark = musicModel.Name.ToString ();
            EditText textButton = new EditText () {
                X = Application.GetRealWidth (11) + backButton.Right,
                Height = Application.GetRealHeight (50),
                Width = Application.GetRealWidth (400),
                Text = strOnePortWirelessFRRemark,
                Gravity = Gravity.CenterVertical,
                BackgroundColor = SkinStyle.Current.Transparent,
                SelectedBackgroundColor = SkinStyle.Current.SysEditBox,
                Enable = false,
                TextColor = SkinStyle.Current.TextColor1,
            };
            frameLayout.AddChidren (textButton);
 
            Button editor = new Button () {
                X = Application.GetRealWidth (520),
                Height = Application.GetRealHeight (90),
                Width = Application.GetRealWidth (70),
                UnSelectedImagePath = "Item/Editor.png",
                SelectedImagePath = "Item/EditorSelected.png",
                Gravity = Gravity.CenterVertical,
            };
            //editor.X = frameLayout.Width - editor.Width - Application.GetRealWidth (30);
            frameLayout.AddChidren (editor);
            editor.MouseUpEventHandler += (sender, e) => {//---------------修改Remark----------------
                if (editor.IsSelected == true) {
                    MainPage.Loading.Start ();
                    musicModel.Name = textButton.Text.Trim ();
 
                    CommonPage.UpdateRemark (musicModel.SubnetID, musicModel.DeviceID, musicModel.Name);
                    IO.FileUtils.SaveEquipmentMessage (musicModel);
                    editor.IsSelected = false;
                    textButton.Enable = false;
                    textButton.IsSelected = false;
                    MainPage.Loading.Hide ();
                    System.Console.WriteLine ("OnePortWirelessFR Remark Update");
                } else {
                    textButton.Enable = true;
                    textButton.IsSelected = true;
                    editor.IsSelected = true;
                }
            };
            textButton.IsSelected = false;
            textButton.Enable = false;
            #endregion
 
            #region GatewayID
            RowLayout frameLayoutGatewayID = new RowLayout () {
                Height = Application.GetRealHeight (98),
                Width = LayoutParams.MatchParent,
                BackgroundColor = SkinStyle.Current.MainColor
            };
            sView.AddChidren (frameLayoutGatewayID);
 
            Button gatewayIDText = new Button () {
                X = Application.GetRealWidth (30),
                Height = Application.GetRealHeight (49),
                Width = Application.GetRealWidth (49),
                UnSelectedImagePath = "Item/Wireless.png",
                SelectedImagePath = "Item/WirelessSelected.png",
                Gravity = Gravity.CenterVertical,
            };
            frameLayoutGatewayID.AddChidren (gatewayIDText);
            Button gatewayIDName = new Button () {
                X = Application.GetRealWidth (11) + gatewayIDText.Right,
                Height = Application.GetRealHeight (41),
                Width = Application.GetRealWidth (150),
                TextID = R.MyInternationalizationString.GatewayID,
                Gravity = Gravity.CenterVertical,
                TextAlignment = TextAlignment.CenterLeft,
                TextColor = SkinStyle.Current.TextColor1,
            };
            frameLayoutGatewayID.AddChidren (gatewayIDName);
            EditText etGatewayID = new EditText () {
                Height = Application.GetRealHeight (42),
                Width = Application.GetRealWidth (62),
                X = gatewayIDName.X + gatewayIDName.Width,
                Gravity = Gravity.CenterVertical,
                TextAlignment = TextAlignment.Center,
                Text = musicModel.SubnetID.ToString (),
                SelectedBackgroundColor = SkinStyle.Current.SysEditBox,
                BackgroundColor = SkinStyle.Current.Transparent,
                Enable = false,
            };
            frameLayoutGatewayID.AddChidren (etGatewayID);
 
            Button gatewayIDEdit = new Button () {
                X = Application.GetRealWidth (520),
                Height = Application.GetRealHeight (90),
                Width = Application.GetRealWidth (70),
                UnSelectedImagePath = "Item/Editor.png",
                SelectedImagePath = "Item/EditorSelected.png",
                Gravity = Gravity.CenterVertical,
            };
            //gatewayIDEdit.X = frameLayout.Width - gatewayIDEdit.Width - Application.GetRealWidth (30);
            #region 更改网关设备号
            byte [] macAddress = Control.ControlBytesSendHasReturn (Command.ReadDeviceMac, musicModel.SubnetID, musicModel.DeviceID, new byte [] { });
            gatewayIDEdit.MouseUpEventHandler += (sender, e) => {
                if (macAddress == null) {
                    Application.RunOnMainThread (() => {
                        new Alert (Language.StringByID (R.MyInternationalizationString.Tip), Language.StringByID (R.MyInternationalizationString.OperationFailed), Language.StringByID (R.MyInternationalizationString.Close)).Show ();
                    });
                    return;
                }
                if (etGatewayID.Enable) {
                    etGatewayID.Enable = etGatewayID.IsSelected = false;
                    byte [] Musics = new byte [10];
                    Array.Copy (macAddress, 0, Musics, 0, 8);
                    try {
                        Musics [8] = Convert.ToByte (Convert.ToInt32 (etGatewayID.Text.Trim ()));
                        if (Musics [8] < 0 || Musics [8] > 255) {
                            return;
                        }
                    } catch {
                        new Alert (Language.StringByID (R.MyInternationalizationString.Tip), Language.StringByID (R.MyInternationalizationString.TipPleaseEnterTheCorrectData), Language.StringByID (R.MyInternationalizationString.Close)).Show ();
                        return;
                    }
                    Control.ControlBytesSendHasReturn (Command.SetDeviceSubnetID, musicModel.SubnetID, musicModel.DeviceID, Musics);
 
                    musicModel.SubnetID = Musics [8];
                    UpdateOnePorWirelessFR (musicModel);
                } else {
                    etGatewayID.IsSelected = etGatewayID.Enable = true;
                }
            };
            #endregion
            frameLayoutGatewayID.AddChidren (gatewayIDEdit);
            #endregion
 
            #region--------------NetWork----------------------
            bool isMusicModu = musicModel.Type == DeviceType.MusicModel ? true : false;
            RowLayout flNetWorkTop = new RowLayout () {
                Height = Application.GetRealHeight (98),
                Width = LayoutParams.MatchParent,
                BackgroundColor = SkinStyle.Current.MainColor
            };
            sView.AddChidren (flNetWorkTop);
 
            Button netParameterSeleted = new Button () {
                X = Application.GetRealWidth (30),
                Height = Application.GetRealHeight (49),
                Width = Application.GetRealWidth (49),
                UnSelectedImagePath = "Item/NetParameter.png",
                SelectedImagePath = "Item/NetParameterSelected.png",
                Gravity = Gravity.CenterVertical,
            };
            flNetWorkTop.AddChidren (netParameterSeleted);
            Button textButton1 = new Button () {
                X = Application.GetRealWidth (11) + netParameterSeleted.Right,
                Height = Application.GetRealHeight (41),
                Width = Application.GetRealWidth (300),
                TextID = R.MyInternationalizationString.NetwordParameters,
                Gravity = Gravity.CenterVertical,
                TextAlignment = TextAlignment.CenterLeft,
                TextColor = SkinStyle.Current.TextColor1,
            };
            flNetWorkTop.AddChidren (textButton1);
            Button btnNetWorkHelp = new Button () {
                X = Application.GetRealWidth (540),
                Height = Application.GetMinRealAverage (98),
                Width = Application.GetMinRealAverage (76),
                UnSelectedImagePath = "Item/Help.png",
                SelectedImagePath = "Item/HelpSelected.png",
                Gravity = Gravity.CenterVertical,
            };
            //btnNetWorkHelp.X = frameLayout.Width - btnNetWorkHelp.Width - Application.GetRealWidth (30);
            btnNetWorkHelp.MouseUpEventHandler += (sender, e) => {
                new Tip () { MaxWidth = 150, Text = Language.StringByID (R.MyInternationalizationString.HelpNetWork), Direction = AMPopTipDirection.Down, CloseTime = 4 }.Show ((View)sender);
            };
            flNetWorkTop.AddChidren (btnNetWorkHelp);
            //---------------------------------------------------------------------------------------------------------------------------------
            FrameLayout frameLayout2 = new FrameLayout () {
                Height = Application.GetRealHeight (798),
                Width = LayoutParams.MatchParent,
            };
            sView.AddChidren (frameLayout2);
 
 
            Button lblIPAddresses = new Button () {
                X = gatewayIDName.X,
                TextAlignment = TextAlignment.CenterLeft,
                Height = Application.GetRealHeight (55),
                Width = Application.GetRealWidth (239),
                TextID = R.MyInternationalizationString.IPAddresses,
                Y = Application.GetRealHeight (10),
                TextColor = SkinStyle.Current.TextColor1,
            };
            frameLayout2.AddChidren (lblIPAddresses);
 
            EditText etIPAddresses = new EditText () {
                X = gatewayIDName.X,
                TextAlignment = TextAlignment.CenterLeft,
                Height = Application.GetRealHeight (55),
                Width = Application.GetRealWidth (440),
                Text = " " + musicModel.IPAddress,
                BackgroundColor = SkinStyle.Current.SysEditBox,
                SelectedImagePath = "Item/TextBoxSelected.png",
                Y = lblIPAddresses.Bottom + Application.GetRealHeight (2),
                Enable = isMusicModu,
                TextColor = SkinStyle.Current.TextColor1,
            };
            frameLayout2.AddChidren (etIPAddresses);
            CommonPage.FindGatewayChilrenIPAddress = musicModel.IPAddress;
 
            Button lblSubnetMask = new Button () {
                X = gatewayIDName.X,
                TextAlignment = TextAlignment.CenterLeft,
                Height = Application.GetRealHeight (55),
                Width = Application.GetRealWidth (440),
                TextID = R.MyInternationalizationString.SubnetMask,
                Y = etIPAddresses.Bottom + Application.GetRealHeight (2),
                TextColor = SkinStyle.Current.TextColor1,
            };
            frameLayout2.AddChidren (lblSubnetMask);
 
            EditText etSubnetMask = new EditText () {
                X = gatewayIDName.X,
                TextAlignment = TextAlignment.CenterLeft,
                Height = Application.GetRealHeight (55),
                Width = Application.GetRealWidth (440),
                Text = " " + musicModel.SubnetMask,
                BackgroundColor = SkinStyle.Current.SysEditBox,
                SelectedImagePath = "Item/TextBoxSelected.png",
                Y = lblSubnetMask.Bottom + Application.GetRealHeight (2),
                Enable = isMusicModu,
                TextColor = SkinStyle.Current.TextColor1,
            };
            frameLayout2.AddChidren (etSubnetMask);
 
            Button lblRoutingIP = new Button () {
                X = gatewayIDName.X,
                TextAlignment = TextAlignment.CenterLeft,
                Height = Application.GetRealHeight (55),
                Width = Application.GetRealWidth (440),
                TextID = R.MyInternationalizationString.RoutingIP,
                Y = etSubnetMask.Bottom + Application.GetRealHeight (2),
                TextColor = SkinStyle.Current.TextColor1,
            };
            frameLayout2.AddChidren (lblRoutingIP);
 
            EditText etRoutingIP = new EditText () {
                X = gatewayIDName.X,
                TextAlignment = TextAlignment.CenterLeft,
                Height = Application.GetRealHeight (55),
                Width = Application.GetRealWidth (440),
                Text = " " + musicModel.RouteIPAddress,
                BackgroundColor = SkinStyle.Current.SysEditBox,
                SelectedImagePath = "Item/TextBoxSelectedd.png",
                Y = lblRoutingIP.Bottom + Application.GetRealHeight (2),
                Enable = isMusicModu,
                TextColor = SkinStyle.Current.TextColor1,
            };
            frameLayout2.AddChidren (etRoutingIP);
 
            Button btnDHCPSave = new Button () {
                X = (Application.CurrentWidth / 2 - 30),
                Height = Application.GetRealHeight (55),
                Width = Application.GetRealWidth (100),
                BackgroundColor = SkinStyle.Current.ButtonColor,
                SelectedBackgroundColor = SkinStyle.Current.SelectedColor,
                BorderWidth = 1,
                Radius = 5,
                BorderColor = SkinStyle.Current.Transparent,
                TextID = R.MyInternationalizationString.SAVE,
                Y = etRoutingIP.Bottom + Application.GetRealHeight (12),
                Visible = isMusicModu
            };
            frameLayout2.AddChidren (btnDHCPSave);
            frameLayout2.Height = btnDHCPSave.Bottom + Application.GetRealHeight (20);
 
 
            btnDHCPSave.MouseUpEventHandler += (sender, e) => {
                musicModel.IPAddress = etIPAddresses.Text.Trim ();
                musicModel.SubnetMask = etSubnetMask.Text.Trim ();
                musicModel.RouteIPAddress = etRoutingIP.Text.Trim ();
                UpdateOnePorWirelessFR (musicModel);
            };
 
            #endregion
 
 
 
            #region --------------bottom--------------
            var sysBottomView = new FrameLayout () {
                Height = Application.GetRealHeight (90),
                Y = Application.GetRealHeight (844)
            };
            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 += (sender, e) => {
                MainPage.Loading.Start ();
                System.Threading.Tasks.Task.Run (() => {
                    CommonPage.GateWayList.Clear ();
                    CommonPage.RandomHigh = (byte)new Random ().Next (255);
                    CommonPage.RandomLow = (byte)new Random ().Next (255);
                    var gatewayInfo = Control.ControlBytesSendHasReturn (Command.ReadGateway, musicModel.SubnetID, musicModel.DeviceID, new byte [] { CommonPage.RandomHigh, CommonPage.RandomLow });
                    var deviceBytes = IO.FileUtils.ReadEquipmentMessage (musicModel);
                    var gatewayDevice1 = Newtonsoft.Json.JsonConvert.DeserializeObject<MusicModel> (deviceBytes);
                    if (gatewayDevice1 != null) {
                        Application.RunOnMainThread (() => {
                            this.ShowMusicModel (musicModel);
                            MainPage.Loading.Hide ();
                        });
                    } else {
                        Application.RunOnMainThread (() => {
                            MainPage.Loading.Hide ();
                        });
                    }
                });
            };
            sysBottomView.AddChidren (new Button () { Height = 1, BackgroundColor = SkinStyle.Current.White20Transparent });
            #endregion
        }
 
 
        public void ControlMusicModel () 
        {
            //指定播放格式: *ZzzsLISTxxxyyya
            byte [] musicDataBytes_read = System.Text.Encoding.ASCII.GetBytes ("S1PLAY");
        }
    }
}