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 localEquipmentList1 = new List (); List 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 { } }); Console.WriteLine ("loadChildren"); } } } LoadDevice (device); Application.RunOnMainThread (() => { try { string ReadStr = "_" + device.SubnetID.ToString () + "_" + device.DeviceID.ToString () + "_"; List localEquipmentList = new List (); List 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 hideListCommon; public void EquipmentBaseViewShow (Common device) { hideListCommon = new List (); List 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 (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 eHandler = new EventHandler (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 } /// /// 读取设备信息 /// /// Device. void LoadDevice (Common device) { string ReadStr = "_" + device.SubnetID.ToString () + "_" + device.DeviceID.ToString () + "_"; List localEquipmentList = new List (); 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; } } } /// /// 显示设备列表 /// void LoadInterface (EventHandler 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); } } /// /// 加载设备数据 /// void InitDevicesList (List 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 ( CommonPage.MyEncodingUTF8.GetString (IO.FileUtils.ReadFile (listDevice [i]))); EventHandler clickEventHandler = new EventHandler (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) { Console.WriteLine ("SystemEquipmentBase,AddDevicesList" + ex.ToString ()); } } } }