using Shared.SimpleControl.Phone; using System; using System.Collections.Generic; namespace Shared.SimpleControl.Pad { public class SystemFloorHeatingPanel { public SystemFloorHeatingPanel () { } public void ShowSystemFloorHeatingPanel (FoolHeatPanel thp, ButtonPanel bp) { SystemMiddle.ThirdScrolView.RemoveAll (); byte [] thpBytes = null; EditText textButton = new EditText () { X = Application.GetRealWidth (40), Height = Application.GetRealHeight (50), Width = Application.GetRealWidth (400), Text = thp.Name, Gravity = Gravity.CenterVertical, TextAlignment = TextAlignment.CenterLeft, SelectedBackgroundColor = 0xFF000000, Enable = false, TextSize = 15, IsSelected = false, }; SystemMiddle.ThirdScrolView.TitleView.AddChidren (textButton); Button editor = new Button () { Height = Application.GetRealHeight (90), Width = Application.GetRealWidth (70), UnSelectedImagePath = "Item/Editor.png", SelectedImagePath = "Item/EditorSelected.png", Gravity = Gravity.CenterVertical, }; SystemMiddle.ThirdScrolView.TitleView.AddChidren (editor); editor.MouseUpEventHandler += (sender, e) => { if (editor.IsSelected) { MainPage.Loading.Start (); editor.IsSelected = textButton.IsSelected = textButton.Enable = false; byte [] remakeBytes = CommonPage.MyEncodingGB2312.GetBytes (textButton.Text.Trim ()); System.Threading.Tasks.Task.Run (() => { byte [] updateBytes = Control.ControlBytesSendHasReturn (Command.ReadDeviceLoopInfo, thp.SubnetID, thp.DeviceID, new byte [] { thp.BigClass,thp.MinClass,thp.LoopID }); if (updateBytes == null) { Application.RunOnMainThread (() => { new Alert (Language.StringByID (R.MyInternationalizationString.Tip), Language.StringByID (R.MyInternationalizationString.TipEquipmentNotOnline), Language.StringByID (R.MyInternationalizationString.Close)).Show (); MainPage.Loading.Hide (); }); return; } byte [] uBytes = new byte [20]; Array.Copy (remakeBytes, 0, uBytes, 0, remakeBytes.Length < 20 ? remakeBytes.Length : 20); Array.Copy (uBytes, 0, updateBytes, 3, 20 < uBytes.Length ? 20 : uBytes.Length); var reBytes = Control.ControlBytesSendHasReturn (Command.SetDeviceLoopInfo, thp.SubnetID, thp.DeviceID, updateBytes); if (reBytes != null) { Application.RunOnMainThread (() => { thp.Name = textButton.Text.Trim (); IO.FileUtils.SaveEquipmentMessage (thp, thp.LoopID.ToString ()); MainPage.Loading.Hide (); }); } else { Application.RunOnMainThread (() => { new Alert (Language.StringByID (R.MyInternationalizationString.Tip), Language.StringByID (R.MyInternationalizationString.TipEquipmentNotOnline), Language.StringByID (R.MyInternationalizationString.Close)).Show (); MainPage.Loading.Hide (); }); } }); } else { textButton.Enable = textButton.IsSelected = editor.IsSelected = true; } }; Button btnOutput = new Button () { Width = Application.GetRealWidth (503), Height = Application.GetRealHeight (50), X = Application.GetRealWidth (60), Y = Application.GetRealHeight (40), TextID = R.MyInternationalizationString.ChooseFloorHeatingLoop, TextAlignment = TextAlignment.CenterLeft, }; SystemMiddle.ThirdScrolView.AddChidren (btnOutput); VerticalScrolViewLayout verticalScrolView = new VerticalScrolViewLayout { Width = Application.GetRealWidth (480), Height = Application.GetRealHeight (680), Y = btnOutput.Bottom + Application.GetRealHeight (5), Gravity = Gravity.CenterHorizontal, BackgroundColor = SkinStyle.Current.MainColor }; SystemMiddle.ThirdScrolView.AddChidren (verticalScrolView); List willBeShowList = IO.FileUtils.ReadFiles ().FindAll ((fileName) => { return fileName.Contains ("Equipment_") && fileName.Contains (DeviceType.FoolHeat.ToString () + "_") && (fileName.Split ('_').Length == 5); }); int num = 0; foreach (string equipment in willBeShowList)//显示在本地找到的所有设备 { var v = IO.FileUtils.ReadFile (equipment); string data = CommonPage.MyEncodingUTF8.GetString (v); FoolHeat th = Newtonsoft.Json.JsonConvert.DeserializeObject (data); Button btnEquipment = new Button () { Width = LayoutParams.MatchParent, Height = Application.GetRealHeight (90), TextAlignment = TextAlignment.Center, Text = th.Name, Tag = th, SelectedBackgroundColor = 0xFFDBDDDF, BackgroundColor = SkinStyle.Current.MainColor, Gravity = Gravity.CenterHorizontal }; verticalScrolView.AddChidren (btnEquipment); btnEquipment.Y = Application.GetRealHeight (10) + num * (btnEquipment.Height + Application.GetRealHeight (30)); num++; btnEquipment.MouseUpEventHandler += (sender, e) => { Alert alert = new Alert (Language.StringByID (R.MyInternationalizationString.Tip), Language.StringByID (R.MyInternationalizationString.SureBindDevice), Language.StringByID (R.MyInternationalizationString.Cancel), Language.StringByID (R.MyInternationalizationString.Confrim)); alert.Show (); alert.ResultEventHandler += (sender2, e2) => { if (e2) { FoolHeat h = (FoolHeat)btnEquipment.Tag; if (thpBytes [0] == 0xFF) { thpBytes [0] = 0; } for (int li = 0; li < 8; li++) { if (thpBytes [li * 4 + 1] == 0xFF) { thpBytes [li * 4 + 1] = 0; } } int i = 4 * thpBytes [0]; thpBytes [i + 1] = 1; thpBytes [i + 2] = h.SubnetID; thpBytes [i + 3] = h.DeviceID; thpBytes [i + 4] = h.LoopID; byte [] reFalg = Control.ControlBytesSendHasReturn (Command.SetACFloorHeatingSettingEquipment, thp.SubnetID, thp.DeviceID, thpBytes); if (reFalg [0] == 0xF8) { new Alert (Language.StringByID (R.MyInternationalizationString.Tip), Language.StringByID (R.MyInternationalizationString.ThePerationWasSuccessful), Language.StringByID (R.MyInternationalizationString.Close)).Show (); this.ShowSystemFloorHeatingPanel (thp, bp); } } }; }; Button btnLine = new Button () { Width = LayoutParams.MatchParent, Height = 1, BackgroundColor = 0xFF2f2f2f }; verticalScrolView.AddChidren (btnLine); } //--------------bottom-------------- System.Threading.Tasks.Task.Run (() => { //面板可以预设8个地热通道,只能启用一个,1976回的第一个byte表示第几个地热被启用,再截取相应的子网号设备号回路号 thpBytes = Control.ControlBytesSendHasReturn (Command.ReadACFloorHeatingSettingEquipment, thp.SubnetID, thp.DeviceID, new byte [] { }); Application.RunOnMainThread (() => { for (int i = 0; i < verticalScrolView.ChildrenCount; i++) { if (verticalScrolView.GetChildren (i).GetType () == typeof (Button)) { Button btn = (Button)verticalScrolView.GetChildren (i); if (btn.Tag != null) { var th = (FoolHeat)btn.Tag; if (thpBytes != null) { if (thpBytes [0] < 10) { int kik = 4 * thpBytes [0]; if (thpBytes [kik + 2] == th.SubnetID && thpBytes [kik + 3] == th.DeviceID && thpBytes [kik + 4] == th.LoopID) { btn.IsSelected = true; } kik += 4; } } } } } }); }); } } }