using System; using System.Threading; namespace Shared.SimpleControl.Phone { /// /// 地热设备房间 /// public class UserDeviceToFH : FrameLayout { static UserDeviceToFH curView; VerticalScrolViewLayout bodyScrolView; /// /// 构造函数 /// public UserDeviceToFH () { curView = this; BackgroundColor = SkinStyle.Current.MainColor; showAllRoomFH (); readAllStatus (); } /// /// 更新当前地热开关 - 针对单一属性更新 /// public static void UpdatePower (string updataFalg,byte power) { Application.RunOnMainThread (() => { if (curView == null) { return; } for (int i = 0; i < curView.bodyScrolView.ChildrenCount; i++) { if (curView.bodyScrolView.GetChildren (i).GetType () == typeof (FrameLayout)) { var fhRow = (FrameLayout)curView.bodyScrolView.GetChildren (i); if (fhRow.Tag.ToString () != updataFalg) { continue; } for (int j = 0; j < fhRow.ChildrenCount; j++) { if (fhRow.GetChildren (j).GetType () == typeof (Button)) { var btn = (Button)fhRow.GetChildren (j); if (btn.Tag == null) { continue; } if (btn.Tag.ToString () == "Switch") { if (power == 0) { btn.IsSelected = false; } else { btn.IsSelected = true; } } } } } } }); } /// /// 更新当前地热工作温度 - 针对单一属性更新 /// public static void UpdateWorkingTemp (string updataFalg, byte workingTemp) { Application.RunOnMainThread (() => { if (curView == null) { return; } for (int i = 0; i < curView.bodyScrolView.ChildrenCount; i++) { if (curView.bodyScrolView.GetChildren (i).GetType () == typeof (FrameLayout)) { var fhRow = (FrameLayout)curView.bodyScrolView.GetChildren (i); if (fhRow.Tag.ToString () != updataFalg) { continue; } for (int j = 0; j < fhRow.ChildrenCount; j++) { if (fhRow.GetChildren (j).GetType () == typeof (Button)) { var btn = (Button)fhRow.GetChildren (j); if (btn.Tag == null) { continue; } if (btn.Tag.ToString () == "Temperature") { btn.Text = workingTemp + "°"; } } } } } }); } /// /// 更新当前地热 /// public static void UpdateStatus (Common updataFH) { Application.RunOnMainThread (() => { if (curView == null) { return; } for (int i = 0; i < curView.bodyScrolView.ChildrenCount; i++) { if (curView.bodyScrolView.GetChildren (i).GetType () == typeof (FrameLayout)) { var fhRow = (FrameLayout)curView.bodyScrolView.GetChildren (i); if (fhRow.Tag.ToString () != updataFH.CommonLoopID) { continue; } for (int j = 0; j < fhRow.ChildrenCount; j++) { if (fhRow.GetChildren (j).GetType () == typeof (Button)) { var btn = (Button)fhRow.GetChildren (j); if (btn.Tag == null) { continue; } if (btn.Tag.ToString () == "Switch") { if ((updataFH as FoolHeat).Status == 0) { btn.IsSelected = false; } else { btn.IsSelected = true; } } else if (btn.Tag.ToString () == "Temperature") { btn.Text = (updataFH as FoolHeat).WorkingTemperature.ToString () + "°"; } } } } } }); } /// /// 显示房间的所有地热 /// public void showAllRoomFH () { #region 标题 var topView = new FrameLayout () { Y = Application.GetRealHeight (36), Height = Application.GetRealHeight (90), }; AddChidren (topView); var title = new Button () { TextAlignment = TextAlignment.Center, Text = Language.StringByID (R.MyInternationalizationString.FoolHeat), TextSize = 19, TextColor = SkinStyle.Current.TextColor1, }; topView.AddChidren (title); var logo = new Button () { Width = Application.GetRealWidth (154), Height = Application.GetRealHeight (90), X = Application.GetRealWidth (486), UnSelectedImagePath = MainPage.LogoString, }; topView.AddChidren (logo); var back = new Button () { Height = Application.GetRealHeight (90), Width = Application.GetRealWidth (85), UnSelectedImagePath = "Item/Back.png", SelectedImagePath = "Item/BackSelected.png", }; topView.AddChidren (back); back.MouseUpEventHandler += (sender, e) => { (Parent as PageLayout).PageIndex -= 1; try { curView = null; } catch { base.RemoveFromParent (); } }; #endregion #region 全开-全关 var powerView = new FrameLayout () { Height = Application.GetRealHeight (110), BackgroundColor = SkinStyle.Current.TitileView, Y = topView.Bottom }; AddChidren (powerView); var btnAllON = new Button () { Width = Application.GetRealWidth (320), TextSize = 16, TextID = R.MyInternationalizationString.ALLON, TextColor = SkinStyle.Current.TextColor1 }; powerView.AddChidren (btnAllON); var btnAllOff = new Button () { Width = Application.GetRealWidth (320), X = btnAllON.Right, TextSize = 16, TextID = R.MyInternationalizationString.ALLOFF, TextColor = SkinStyle.Current.TextColor1 }; var btnLine = new Button () { Width = 1, Height = Application.GetRealHeight (110) - 1, BackgroundColor = SkinStyle.Current.White20Transparent, X = btnAllON.Right, Y = 1, }; powerView.AddChidren (btnLine); btnAllON.MouseUpEventHandler += (sender, e) => { btnAllON.TextColor = SkinStyle.Current.SelectedColor; btnAllOff.TextColor = SkinStyle.Current.TextColor1; controlAllFH (1); }; powerView.AddChidren (btnAllOff); btnAllOff.MouseUpEventHandler += (sender, e) => { btnAllON.TextColor = SkinStyle.Current.TextColor1; btnAllOff.TextColor = SkinStyle.Current.SelectedColor; controlAllFH (0); }; #endregion bodyScrolView = new VerticalScrolViewLayout () { Width = LayoutParams.MatchParent, Height = Application.GetRealHeight (Application.DesignHeight - 126 - 110), Y = powerView.Bottom, BackgroundColor = SkinStyle.Current.ViewColor }; AddChidren (bodyScrolView); #region 显示全部的地热 foreach (var room in Room.Lists) { if (string.IsNullOrEmpty(room.Name)) { continue; } foreach (var common in room.DeviceList.FindAll ((obj) => { return obj.Type == DeviceType.FoolHeat || obj.Type == DeviceType.FoolHeatPanel; })) { var roomFH = common as FoolHeat; FrameLayout fhView = new FrameLayout () { Height = Application.GetRealHeight (130), }; fhView.Tag = roomFH.CommonLoopID; bodyScrolView.AddChidren (fhView); var tempDeviceName = new Button () { X = Application.GetRealWidth (20), Width = Application.GetRealWidth (400), TextAlignment = TextAlignment.CenterLeft, Text = room.Name + "-" + roomFH.Name, TextColor = SkinStyle.Current.TextColor1, }; fhView.AddChidren (tempDeviceName); tempDeviceName.MouseUpEventHandler += (sender2, e2) => { var userFHPageView = new UserFHPage (roomFH, room); UserMiddle.DevicePageView.AddChidren (userFHPageView); userFHPageView.ShowRoomFH (); UserMiddle.DevicePageView.PageIndex = 2; }; var btnSetTemperature = new Button () { Width = Application.GetRealWidth (310), Height = Application.GetRealHeight (200), X = Application.GetRealWidth (280), Gravity = Gravity.CenterVertical, Text = roomFH.WorkingTemperature.ToString () + "°", TextSize = 28, TextAlignment = TextAlignment.Center, Enable = false, Tag = "Temperature" }; fhView.AddChidren (btnSetTemperature); var tempSiwtch = new Button () { Width = Application.GetMinRealAverage (90), Height = Application.GetMinRealAverage (53), X = Application.GetRealWidth (640 - 90 - 20), Gravity = Gravity.CenterVertical, UnSelectedImagePath = "Item/SwitchClose.png", SelectedImagePath = "Item/SwitchOpen.png", Tag = "Switch" }; fhView.AddChidren (tempSiwtch); if (roomFH.Status == 1) { tempSiwtch.IsSelected = true; } else { tempSiwtch.IsSelected = false; } UpdateStatus (roomFH); tempSiwtch.MouseUpEventHandler += (sender3, e3) => { tempSiwtch.IsSelected = !tempSiwtch.IsSelected; roomFH.Status = tempSiwtch.IsSelected ? (byte)1 : (byte)0; System.Threading.Tasks.Task.Run (() => { if (roomFH.Type == DeviceType.FoolHeatPanel) { Control.ControlBytesSend (Command.InstructionPanelKey, roomFH.SubnetID, roomFH.DeviceID, new byte [] { 20, roomFH.Status, roomFH.LoopID }); } else if (roomFH.Type == DeviceType.FoolHeat) { roomFH = roomFH.Serverx_FH_CMD (FoolHeat.CommandType.Switch); } }); }; if (0 < roomFH.Status) { tempSiwtch.IsSelected = true; } Button btnFHNull = new Button () { Y = Application.GetRealHeight (127), Height = Application.GetRealHeight (3), BackgroundColor = SkinStyle.Current.MainColor, SelectedBackgroundColor = SkinStyle.Current.MainColor, }; fhView.AddChidren (btnFHNull); } } #endregion } /// /// 控制所有地热 /// /// The blue component. void controlAllFH (byte b) { System.Threading.Tasks.Task.Run (() => { foreach (var room in Room.Lists) { if (room == null) continue; if (string.IsNullOrEmpty(room.Name)) { continue; } var list = room.DeviceList.FindAll ((obj) => { return obj.Type == DeviceType.FoolHeat || obj.Type == DeviceType.FoolHeatPanel; }); foreach (var common in list) { var fh = common as FoolHeat; fh.Status = b; if (fh.Type == DeviceType.FoolHeatPanel) { Control.ControlBytesSend (Command.InstructionPanelKey, fh.SubnetID, fh.DeviceID, new byte [] { 20, fh.Status, fh.LoopID }); } else if (fh.Type == DeviceType.FoolHeat) { fh = fh.Serverx_FH_CMD (FoolHeat.CommandType.Switch); } } } }); } static System.Threading.Thread thread; /// /// 读取设备状态 /// public static void readAllStatus (bool isRead = false) { if (isRead) { foreach (Room room in Room.Lists) { if (room == null) { continue; } var list = room.DeviceList.FindAll ((obj) => { return (obj.Type == DeviceType.FoolHeat || obj.Type == DeviceType.FoolHeatPanel); }); foreach (Common common in list) { common.LastUpdateTime = DateTime.MinValue; } } } if (thread != null) { thread.Abort (); } thread = new Thread (() => { try { System.Collections.Generic.List readList = new System.Collections.Generic.List (); foreach (Room room in Room.Lists) { var list = room.DeviceList.FindAll ((obj) => { return obj.LastUpdateTime.AddMinutes (Common.Time) <= DateTime.Now && (obj.Type == DeviceType.FoolHeat || obj.Type == DeviceType.FoolHeatPanel); }); foreach (Common common in list) { var s = common.Type + "_" + common.SubnetID + "_" + common.DeviceID + "_" + common.LoopID; //已经读取过当前设备就不再读取 if (readList.Contains (s)) { continue; } readList.Add (s); var fh = common as FoolHeat; Thread.Sleep (500); if (fh.Type == DeviceType.FoolHeatPanel) { Control.ControlBytesSend (Command.ReadInstructionPanelKey, fh.SubnetID, fh.DeviceID, new byte [] { 20, fh.LoopID, fh.LoopID }); Control.ControlBytesSend (Command.ReadInstructionPanelKey, fh.SubnetID, fh.DeviceID, new byte [] { 21, fh.LoopID, fh.LoopID }); Control.ControlBytesSend (Command.ReadInstructionPanelKey, fh.SubnetID, fh.DeviceID, new byte [] { 24, fh.LoopID, fh.LoopID }); Control.ControlBytesSend (Command.ReadInstructionPanelKey, fh.SubnetID, fh.DeviceID, new byte [] { 25, fh.LoopID, fh.LoopID }); Control.ControlBytesSend (Command.ReadInstructionPanelKey, fh.SubnetID, fh.DeviceID, new byte [] { 26, fh.LoopID, fh.LoopID }); Control.ControlBytesSend (Command.ReadInstructionPanelKey, fh.SubnetID, fh.DeviceID, new byte [] { 27, fh.LoopID, fh.LoopID }); Control.ControlBytesSend (Command.ReadInstructionPanelKey, fh.SubnetID, fh.DeviceID, new byte [] { 28, fh.LoopID, fh.LoopID }); Control.ControlBytesSend (Command.ReadPanleTemp, fh.SubnetID, fh.DeviceID, new byte [] { fh.LoopID }, SendCount.Zero); //Control.ControlBytesSend (Command.Read_Floor_Heat_State, fh.SubnetID, fh.DeviceID, new byte [] { (byte)(fh.LoopID - 1) }); //Control.ControlBytesSend (Command.ReadInstructionPanelKey, fh.SubnetID, fh.DeviceID, new byte [] { 20, fh.LoopID, fh.LoopID }); //Control.ControlBytesSend (Command.ReadInstructionPanelKey, fh.SubnetID, fh.DeviceID, new byte [] { 21, fh.LoopID, fh.LoopID }); //Control.ControlBytesSend (Command.ReadInstructionPanelKey, fh.SubnetID, fh.DeviceID, new byte [] { 24, fh.LoopID, fh.LoopID }); //switch (fh.TemperatureType) { //case 1: // Control.ControlBytesSend (Command.InstructionPanelKey, fh.SubnetID, fh.DeviceID, new byte [] { 25, fh.LoopID, fh.LoopID }); // break; //case 2: // Control.ControlBytesSend (Command.InstructionPanelKey, fh.SubnetID, fh.DeviceID, new byte [] { 26, fh.LoopID, fh.LoopID }); // break; //case 3: // Control.ControlBytesSend (Command.InstructionPanelKey, fh.SubnetID, fh.DeviceID, new byte [] { 27, fh.LoopID, fh.LoopID }); // break; //case 4: // Control.ControlBytesSend (Command.InstructionPanelKey, fh.SubnetID, fh.DeviceID, new byte [] { 28, fh.LoopID, fh.LoopID }); // break; //default: // break; //} Control.ControlBytesSend (Command.ReadPanleTemp, fh.SubnetID, fh.DeviceID, new byte [] { fh.LoopID }, SendCount.Zero); Control.ControlBytesSend (Command.Read_Floor_Heat_State, fh.SubnetID, fh.DeviceID, new byte [] { (byte)(fh.LoopID - 1) }); } else if (fh.Type == DeviceType.FoolHeat) { fh = fh.Serverx_FH_CMD (FoolHeat.CommandType.Read); } } } } catch { } finally { thread = null; } }); thread.Start (); } } }