using System; using System.Collections.Generic; namespace Shared.SimpleControl.Phone { public class SystemFloorHeatingPanel : FrameLayout { public SystemFloorHeatingPanel () { } public void ShowSystemFloorHeatingPanel (FoolHeatPanel thp, ButtonPanel bp) { byte [] thpBytes = null; #region top RowLayout topTitleView = new RowLayout () { Height = Application.GetRealHeight (98), Width = LayoutParams.MatchParent, BackgroundColor = SkinStyle.Current.MainColor }; AddChidren (topTitleView); Button backButton = new Button () { 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; //SystemEquipmentBase.RefreshView (bp); //Animate = Animate.RightToLeft; }; topTitleView.AddChidren (backButton); EditText textButton = new EditText () { X = Application.GetRealWidth (30) + backButton.Right, Height = Application.GetRealHeight (50), Width = Application.GetRealWidth (400), Text = thp.Name, Gravity = Gravity.CenterVertical, TextAlignment = TextAlignment.CenterLeft, TextColor = SkinStyle.Current.TextColor1, SelectedBackgroundColor = SkinStyle.Current.SysEditBox, Enable = false, TextSize = 15, IsSelected = false, }; topTitleView.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, }; topTitleView.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; } }; #endregion Button btnOutput = new Button () { Width = Application.GetRealWidth (503), Height = Application.GetRealHeight (50), X = Application.GetRealWidth (60), Y = Application.GetRealHeight (100), TextID = R.MyInternationalizationString.ChooseFloorHeatingLoop, TextAlignment = TextAlignment.CenterLeft, }; 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.SysSubtitleView }; 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 = SkinStyle.Current.SelectedColor, BackgroundColor = SkinStyle.Current.ButtonColor, Gravity = Gravity.CenterHorizontal }; verticalScrolView.AddChidren (btnEquipment); btnEquipment.Y = Application.GetRealHeight (10) + num * (btnEquipment.Height + Application.GetRealHeight (30)); num++; btnEquipment.MouseUpEventHandler += (sender, e) => { if (btnEquipment.IsSelected) return; 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 == null) return; if (thpBytes.Length == 44) { thpBytes [37] = h.SubnetID; thpBytes [38] = h.DeviceID; thpBytes [39] = h.LoopID; byte [] reFalg = Control.ControlBytesSendHasReturn (Command.Set43FloorHeatingSettingEquipment, thp.SubnetID, thp.DeviceID, thpBytes); if (reFalg == null) { new Alert (Language.StringByID (R.MyInternationalizationString.Tip), Language.StringByID (R.MyInternationalizationString.OperationFailed), Language.StringByID (R.MyInternationalizationString.Close)).Show (); }else{ this.ShowSystemFloorHeatingPanel (thp, bp); } } else { 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; } if (thpBytes [li * 4 + 4] > 0x06) { thpBytes [li * 4 + 4] = 1; } } 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 != null && reFalg [0] == 0xF8) { this.ShowSystemFloorHeatingPanel (thp, bp); } else { new Alert (Language.StringByID (R.MyInternationalizationString.Tip), Language.StringByID (R.MyInternationalizationString.OperationFailed), Language.StringByID (R.MyInternationalizationString.Close)).Show (); } } } }; }; Button btnLine = new Button () { Width = LayoutParams.MatchParent, Height = 1, BackgroundColor = SkinStyle.Current.MainColor }; 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; } } else { thpBytes = Control.ControlBytesSendHasReturn (Command.Read43FloorHeatingSettingEquipment, thp.SubnetID, thp.DeviceID, new byte [] { th.LoopID }); } } } } }); }); } } }