using Shared.SimpleControl.Phone; using System; namespace Shared.SimpleControl.Pad { /// /// 空调设备房间 /// public class UserDeviceToAC : Shared.Dialog { VerticalScrolViewLayout RoomListScrolView; /// /// 当前界面 /// static UserDeviceToAC curView; static SystemACHostMethod aMC; UserACPage ControlBodyView; /// /// 构造函数 /// public UserDeviceToAC () { curView = this; showAllRoomAC (); readAllStatus (); } /// /// 更新当前空调 /// public static void UpdateStatus (AC ac) { #region 更新用户主界面灯光点亮总数 int acOponeCount = 0; foreach (var room in Room.Lists) { if (room.Name == "") { continue; } foreach (var acTemp in room.DeviceList) { if (acTemp.Type == DeviceType.HVAC || acTemp.Type == DeviceType.ACInfrared) if ((acTemp as AC).Power == 1) { acOponeCount++; } } } UserMiddle.UpdataLightLightingCount (acOponeCount, Language.StringByID (R.MyInternationalizationString.AC)); #endregion Application.RunOnMainThread (() => { if (curView == null) { return; } for (int i = 0; i < curView.RoomListScrolView.ChildrenCount; i++) { if (curView.RoomListScrolView.GetChildren (i).GetType () == typeof (FrameLayout)) { var acRow = (FrameLayout)curView.RoomListScrolView.GetChildren (i); if (acRow.Tag != ac) { continue; } //注意全局变量只能针对同一个空调,这里是多个空调,所以变量不能用全局变量 for (int j = 0; j < acRow.ChildrenCount; j++) { if (acRow.GetChildren (j).GetType () == typeof (Button)) { var btn = (Button)acRow.GetChildren (j); if (btn.Tag == null) { continue; } if (btn.Tag.ToString () == "Switch") { if (ac.Power == 0) { btn.IsSelected = false; } else { btn.IsSelected = true; } } else if (btn.Tag.ToString () == "Temperature") { aMC.UpdataACModeTemperature (ac, ac.SetMode, btn); } else if (btn.Tag.ToString () == "Mode") { aMC.UpdataACHostModeIcon (ac.SetMode, btn); } else if (btn.Tag.ToString () == "Wind") { aMC.UpdataACHostWindIcon (ac.SetFanSpeed, btn); } } } } } }); } /// /// 显示房间的所有空调 /// void showAllRoomAC () { aMC = new SystemACHostMethod (); FrameLayout topBackView = new FrameLayout () { Height = Application.GetRealHeight (150), BackgroundColor = 0xFF2f2f2f }; AddChidren (topBackView); #region 标题 var topView = new FrameLayout () { Y = Application.GetRealHeight (36), Height = Application.GetRealHeight (90), BackgroundColor = 0xFF2f2f2f }; AddChidren (topView); var title = new Button () { TextAlignment = TextAlignment.Center, Text = Language.StringByID (R.MyInternationalizationString.AC), TextSize = 19, TextColor = SkinStyle.Current.TextColor1 }; topView.AddChidren (title); var back = new Button () { Height = Application.GetRealHeight (120), Width = Application.GetRealWidth (95), UnSelectedImagePath = "Item/Back.png", SelectedImagePath = "Item/BackSelected.png", Gravity = Gravity.CenterVertical, }; topView.AddChidren (back); back.MouseUpEventHandler += (sender, e) => { Close (); curView = null; }; var logo = new Button () { Width = Application.GetRealWidth (154), Height = Application.GetRealHeight (90), X = Application.GetRealWidth (486), UnSelectedImagePath = MainPage.LogoString, }; topView.AddChidren (logo); var btnl = new Button () { Height = 1, BackgroundColor = 0xFF2f2f2f, Y = topView.Height - 1 }; topView.AddChidren (btnl); #endregion FrameLayout bordorView = new FrameLayout () { Width = Application.GetRealWidth (480), Height = Application.GetRealHeight (Application.DesignHeight - 150), Y = Application.GetRealHeight (150), BackgroundColor = 0xFF2f2f2f }; AddChidren (bordorView); #region 全开-全关 FrameLayout powerView = new FrameLayout () { Height = Application.GetRealHeight (140), Width = Application.GetRealWidth (480), BackgroundColor = SkinStyle.Current.MainColor, }; bordorView.AddChidren (powerView); var btnAllON = new Button () { Width = Application.GetRealWidth (240), TextSize = 16, TextID = R.MyInternationalizationString.ALLON, SelectedTextColor = SkinStyle.Current.SelectedColor, TextColor = SkinStyle.Current.TextColor1, }; powerView.AddChidren (btnAllON); var btnAllOff = new Button () { Width = Application.GetRealWidth (240), X = btnAllON.Right, TextSize = 16, TextID = R.MyInternationalizationString.ALLOFF, SelectedTextColor = SkinStyle.Current.SelectedColor, TextColor = SkinStyle.Current.TextColor1, }; var btnLine = new Button () { Width = 1, BackgroundColor = 0xFF2f2f2f, X = btnAllON.Right, }; powerView.AddChidren (btnLine); var btnLine1 = new Button () { Height = 1, //Y = powerView.Height - 1, BackgroundColor = 0xFF2f2f2f, }; powerView.AddChidren (btnLine1); btnAllON.MouseUpEventHandler += (sender, e) => { btnAllON.TextColor = SkinStyle.Current.SelectedColor; btnAllOff.TextColor = SkinStyle.Current.TextColor1; controlAllAC (1); }; powerView.AddChidren (btnAllOff); btnAllOff.MouseUpEventHandler += (sender, e) => { btnAllON.TextColor = SkinStyle.Current.TextColor1; btnAllOff.TextColor = SkinStyle.Current.SelectedColor; controlAllAC (0); }; #endregion RoomListScrolView = new VerticalScrolViewLayout () { Width = LayoutParams.MatchParent, Height = Application.GetRealHeight (Application.DesignHeight - 150 - 140), Y = powerView.Bottom, }; bordorView.AddChidren (RoomListScrolView); #region 显示全部的空调 int devcieCount = 0; foreach (var room in Room.Lists) { if (room.Name == "") { continue; } foreach (var common in room.DeviceList.FindAll ((obj) => { return obj.Type == DeviceType.HVAC || obj.Type == DeviceType.ACPanel || obj.Type == DeviceType.ACInfrared; })) { var ac = common as AC; EventHandler openACControlPageEvent = (button, mouseEventArgs) => { for (int i = 0; i < RoomListScrolView.ChildrenCount; i++) { var view = RoomListScrolView.GetChildren (i); if (view.Tag == ac) { for (int j = 0; j < (view as FrameLayout).ChildrenCount; j++) { var btn = (view as FrameLayout).GetChildren (j); (btn as Button).IsSelected = true; } } else { for (int j = 0; j < (view as FrameLayout).ChildrenCount; j++) { var btn = (view as FrameLayout).GetChildren (j); (btn as Button).IsSelected = false; } } } if (ControlBodyView != null) { ControlBodyView.RemoveFromParent (); } ControlBodyView = new UserACPage (ac, room) { Width = Application.GetRealWidth (Application.DesignWidth) - bordorView.Width, Height = Application.GetRealHeight (Application.DesignHeight - 150), X = bordorView.Right, Y = bordorView.Y, BackgroundColor = SkinStyle.Current.MainColor }; AddChidren (ControlBodyView); ControlBodyView.showRoomAC (); }; FrameLayout RoomView = new FrameLayout () { Height = Application.GetRealHeight (140), }; RoomView.Tag = ac; RoomListScrolView.AddChidren (RoomView); RoomView.MouseUpEventHandler += openACControlPageEvent; Button tempDeviceName = new Button () { //X = Application.GetRealWidth (80), //Y = Application.GetRealHeight(3), Padding = new Padding (0, 35, 0, 0), Text = room.Name + " - " + ac.Name, Height = Application.GetRealHeight (140), TextAlignment = TextAlignment.CenterLeft, SelectedTextColor = SkinStyle.Current.SelectedColor, TextColor = SkinStyle.Current.TextColor1, BackgroundColor = SkinStyle.Current.Transparent, SelectedBackgroundColor = SkinStyle.Current.MainColor }; RoomView.AddChidren (tempDeviceName); Button btnPoint = new Button () { Width = Application.GetRealWidth (15), Height = Application.GetRealHeight (15), X = Application.GetRealWidth (45), Gravity = Gravity.CenterVertical, UnSelectedImagePath = "Item/Point.png", SelectedImagePath = "Item/PointSelected.png", }; RoomView.AddChidren (btnPoint); Button btnNull = new Button () { Height = Application.GetRealHeight (5), Y = Application.GetRealHeight (138), BackgroundColor = SkinStyle.Current.MainColor, }; RoomView.AddChidren (btnNull); Button btnSelected = new Button () { X = RoomView.Width - 5, Width = 5, SelectedBackgroundColor = SkinStyle.Current.SelectedColor, BackgroundColor = SkinStyle.Current.Transparent, }; RoomView.AddChidren (btnSelected); tempDeviceName.MouseUpEventHandler += openACControlPageEvent; if (devcieCount == 0) { ControlBodyView = new UserACPage (ac, room) { Width = Application.GetRealWidth (Application.DesignWidth) - bordorView.Width, Height = Application.GetRealHeight (Application.DesignHeight - 150), X = bordorView.Right, Y = bordorView.Y, BackgroundColor = SkinStyle.Current.MainColor }; AddChidren (ControlBodyView); ControlBodyView.showRoomAC (); tempDeviceName.IsSelected = true; btnPoint.IsSelected = true; btnSelected.IsSelected = true; } devcieCount++; } } #endregion } /// /// 控制空调 /// void controlAC (AC ac) { Control.ControlBytesSend (Command.SetACMode, ac.SubnetID, ac.DeviceID, new byte [] {ac.LoopID,ac.TemperatureMode,ac.IndoorTemperature,ac.CoolTemperature,ac.HeatTemperature,ac.AutoTemperature,ac.ChuShiTemperature, ac.RealModeAndFanSpeed,ac.Power,ac.SetMode,ac.SetFanSpeed,ac.SetTemperature,ac.ShaoFanMode}); } /// /// 控制所有空调 /// void controlAllAC (byte b) { System.Threading.Tasks.Task.Run (() => { foreach (var room in Room.Lists) { if (room == null) continue; if (room.Name == "") { continue; } var list = room.DeviceList.FindAll ((obj) => { return obj.Type == DeviceType.ACPanel || obj.Type == DeviceType.ACInfrared || obj.Type == DeviceType.HVAC; }); foreach (var common in list) { (common as AC).Power = b; controlAC (common as AC); } } }); } /// /// 读取设备状态 /// public static void readAllStatus () { System.Threading.Tasks.Task.Run (() => { 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.HVAC || obj.Type == DeviceType.ACPanel || obj.Type == DeviceType.ACInfrared); }); foreach (Common common in list) { var s = common.Type + "_" + common.SubnetID + "_" + common.DeviceID + "_" + common.LoopID; //已经读取过当前设备就不再读取 if (readList.Contains (s)) { continue; } readList.Add (s); Control.ControlBytesSendHasReturn (Command.ReadACMode, common.SubnetID, common.DeviceID, new byte [] { common.LoopID }); } } }); } } }