using System; using System.Threading; namespace Shared.SimpleControl.Phone { public class UserFresAirList : FrameLayout { static UserFresAirList curView; VerticalScrolViewLayout equipmentListScrolView; FreshAirBLL bll; public UserFresAirList () { curView = this; bll = new FreshAirBLL (); } /// /// 更新当前空调 /// public static void UpdateStatus (FreshAir receFreshAir) { #region 更新用户主界面点亮总数 int oponeCount = 0; foreach (var room in Room.Lists) { if (string.IsNullOrEmpty (room.Name)) { continue; } foreach (var acTemp in room.DeviceList) { if (acTemp.Type == DeviceType.FreshAir) if ((acTemp as FreshAir).SwitchStatus == 1) { oponeCount++; } } } UserDeviceView.UpdataDeviceCountNumber (oponeCount, R.MyInternationalizationString.FreshAir); #endregion Application.RunOnMainThread (() => { oponeCount = 0; if (curView == null) { return; } for (int i = 0; i < curView.equipmentListScrolView.ChildrenCount; i++) { if (curView.equipmentListScrolView.GetChildren (i).GetType () == typeof (RowLayout)) { var faRow = (RowLayout)curView.equipmentListScrolView.GetChildren (i); if (faRow.Tag != receFreshAir) { continue; } //注意全局变量只能针对同一个空调,这里是多个空调,所以变量不能用全局变量 for (int j = 0; j < faRow.ChildrenCount; j++) { if (faRow.GetChildren (j).GetType () == typeof (Button)) { var btn = (Button)faRow.GetChildren (j); if (btn.Tag == null) { continue; } if (btn.Tag.ToString () == "Switch") { if (receFreshAir.SwitchStatus == 0) { btn.IsSelected = false; } else { btn.IsSelected = true; } } else if (btn.Tag.ToString () == "Temperature") { btn.Text = receFreshAir.InTemp.ToString () + "°"; } else if (btn.Tag.ToString () == "Mode") { btn.UnSelectedImagePath = new FreshAirBLL ().GetModeIcon (receFreshAir.SetPattern); } else if (btn.Tag.ToString () == "Wind") { btn.UnSelectedImagePath = new FreshAirBLL ().GetWindIcon (receFreshAir.WindSpeed); } } } } } }); } public void ShowAllRoomFreshAir () { #region 标题 var topView = new FrameLayout () { Y = Application.GetRealHeight (36), Height = Application.GetRealHeight (90), BackgroundColor = SkinStyle.Current.MainColor, }; AddChidren (topView); var title = new Button () { TextAlignment = TextAlignment.Center, TextID = R.MyInternationalizationString.FreshAir, 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; curView = null; }; #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, BackgroundColor = SkinStyle.Current.White20Transparent, X = btnAllON.Right, }; powerView.AddChidren (btnLine); btnAllON.MouseUpEventHandler += (sender, e) => { btnAllON.TextColor = SkinStyle.Current.SelectedColor; btnAllOff.TextColor = SkinStyle.Current.TextColor1; //controlAllAC (1); foreach (var room in Room.Lists) { if (string.IsNullOrEmpty(room.Name)) { continue; } foreach (var common in room.DeviceList.FindAll ((obj) => { return obj.Type == DeviceType.FreshAir; })) { var fa = common as FreshAir; fa.SwitchStatus = 1; bll.ControlFreshAir (fa); } } }; powerView.AddChidren (btnAllOff); btnAllOff.MouseUpEventHandler += (sender, e) => { btnAllON.TextColor = SkinStyle.Current.TextColor1; btnAllOff.TextColor = SkinStyle.Current.SelectedColor; //controlAllAC (0); foreach (var room in Room.Lists) { if (string.IsNullOrEmpty(room.Name)) { continue; } foreach (var common in room.DeviceList.FindAll ((obj) => { return obj.Type == DeviceType.FreshAir; })) { var fa = common as FreshAir; fa.SwitchStatus = 0; bll.ControlFreshAir (fa); } } }; #endregion equipmentListScrolView = new VerticalScrolViewLayout () { Width = LayoutParams.MatchParent, Height = Application.GetRealHeight (Application.DesignHeight - 126 - 110), Y = powerView.Bottom, BackgroundColor = SkinStyle.Current.ViewColor }; AddChidren (equipmentListScrolView); #region 显示全部的空调 int devcieCount = 0; foreach (var room in Room.Lists) { if (string.IsNullOrEmpty(room.Name)) { continue; } foreach (var common in room.DeviceList.FindAll ((obj) => { return obj.Type == DeviceType.FreshAir; })) { var fa = common as FreshAir; EventHandler openACControlPageEvent = (button, mouseEventArgs) => { UserFreshAirPage faView = new UserFreshAirPage (fa, room); UserMiddle.DevicePageView.AddChidren (faView); faView.ShowRoomFreshAir (); UserMiddle.DevicePageView.PageIndex = 2; }; RowLayout acView = new RowLayout () { Height = Application.GetRealHeight (140), Tag = fa }; equipmentListScrolView.AddChidren (acView); acView.MouseUpEventHandler += openACControlPageEvent; Button btnACViewBottomNull = new Button () { Y = Application.GetRealHeight (135), Height = Application.GetRealHeight (5), BackgroundColor = SkinStyle.Current.MainColor, SelectedBackgroundColor = SkinStyle.Current.MainColor, }; acView.AddChidren (btnACViewBottomNull); var tempDeviceName = new Button () { X = Application.GetRealWidth (30), Height = Application.GetRealHeight (60), TextAlignment = TextAlignment.CenterLeft, Text = room.Name + " - " + fa.Name, TextColor = SkinStyle.Current.TextColor1 }; acView.AddChidren (tempDeviceName); tempDeviceName.MouseUpEventHandler += openACControlPageEvent; Button btnMode = new Button () { X = Application.GetRealWidth (40), Y = Application.GetRealHeight (40), Width = Application.GetRealWidth (100), Height = Application.GetRealHeight (100), UnSelectedImagePath = bll.GetWindIcon(fa.WindSpeed), Tag = "Mode" }; acView.AddChidren (btnMode); btnMode.MouseUpEventHandler += openACControlPageEvent; Button btnWind = new Button () { X = btnMode.Right + Application.GetRealWidth (20), Y = Application.GetRealHeight (40), Width = Application.GetRealWidth (100), Height = Application.GetRealHeight (100), UnSelectedImagePath = bll.GetModeIcon(fa.SetPattern), Tag = "Wind" }; acView.AddChidren (btnWind); btnWind.MouseUpEventHandler += openACControlPageEvent; var btnSetTemperature = new Button () { Width = Application.GetRealWidth (310), X = Application.GetRealWidth (280), Y = Application.GetRealHeight (20), TextSize = 26, TextAlignment = TextAlignment.Center, Tag = "Temperature", TextColor = SkinStyle.Current.TextColor1 }; acView.AddChidren (btnSetTemperature); btnSetTemperature.MouseUpEventHandler += openACControlPageEvent; var tempSiwtch = new Button () { Width = Application.GetMinRealAverage (90), Height = Application.GetMinRealAverage (53), X = Application.GetRealWidth (640 - 90 - 20), Y = Application.GetRealHeight (67), UnSelectedImagePath = "Item/SwitchClose.png", SelectedImagePath = "Item/SwitchOpen.png", Tag = "Switch" }; acView.AddChidren (tempSiwtch); tempSiwtch.MouseUpEventHandler += (sender3, e3) => { tempSiwtch.IsSelected = !tempSiwtch.IsSelected; fa.SwitchStatus = tempSiwtch.IsSelected ? (byte)1 : (byte)0; //controlAC (ac); bll.ControlFreshAir (fa); }; if (0 < fa.SwitchStatus) { tempSiwtch.IsSelected = true; } devcieCount++; } } #endregion } 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.FreshAir; }); 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.FreshAir); }); foreach (Common fa in list) { var s = fa.Type + "_" + fa.SubnetID + "_" + fa.DeviceID + "_" + fa.LoopID; //已经读取过当前设备就不再读取 if (readList.Contains (s)) { continue; } Thread.Sleep (500); Control.ControlBytesSend (Command.FreshAirRead, fa.SubnetID, fa.DeviceID, new byte [] { fa.LoopID }); } } } catch { } finally { thread = null; } }); thread.Start (); } } }