using System; using HDL_ON.DAL.Server; using HDL_ON.Entity; using HDL_ON.UI.CSS; using Shared; namespace HDL_ON.UI { /// /// 功能分配房间界面 /// public partial class GroupChooseRoomPage : FrameLayout { #region 控件列表 FrameLayout bodyView; /// /// 内容加载区域 /// VerticalScrolViewLayout contentView; Button btnAllRoomText; Button btnChooseAll; #endregion #region 局部变量 GroupControl function ; /// /// 回调事件 /// Action backAction; #endregion public GroupChooseRoomPage(GroupControl groupControl, Action action) { bodyView = this; this.function = groupControl; backAction = action; } public override void RemoveFromParent() { new System.Threading.Thread(() => { Application.RunOnMainThread(() => { backAction?.Invoke(); }); }) { IsBackground = true }.Start(); base.RemoveFromParent(); } /// /// 加载页面 /// public void LoadPage() { bodyView.BackgroundColor = CSS_Color.BackgroundColor; var topView = new TopViewDiv(bodyView, Language.StringByID(StringId.CombinedDimming)); topView.maginY = 10; topView.LoadTopView(); contentView = new VerticalScrolViewLayout() { Y = Application.GetRealHeight(64+10), Height = Application.GetRealHeight(667 - 64-10), }; bodyView.AddChidren(contentView); var allRoomView = new FrameLayout() { Height = Application.GetRealHeight(50), BackgroundColor = CSS_Color.MainBackgroundColor, }; contentView.AddChidren(allRoomView); btnChooseAll = new Button() { X = Application.GetRealWidth(331), Gravity = Gravity.CenterVertical, Width = Application.GetMinRealAverage(28), Height = Application.GetMinRealAverage(28), UnSelectedImagePath = "Public/ChooseIcon.png", SelectedImagePath = "Public/ChooseOnIcon.png", IsSelected = true }; allRoomView.AddChidren(btnChooseAll); btnAllRoomText = new Button() { X = Application.GetRealWidth(16), TextID = StringId.All, TextSize = CSS_FontSize.SubheadingFontSize, TextColor = CSS_Color.FirstLevelTitleColor, TextAlignment = TextAlignment.CenterLeft, }; allRoomView.AddChidren(btnAllRoomText); foreach (var room in SpatialInfo.CurrentSpatial.RoomList) { var roomView = new FrameLayout() { Height = Application.GetRealHeight(50), BackgroundColor = CSS_Color.MainBackgroundColor, Tag = "row" }; contentView.AddChidren(roomView); var btnLine = new Button() { Gravity = Gravity.CenterHorizontal, Height = Application.GetMinReal(1), Width = Application.GetRealWidth(343), BackgroundColor = CSS_Color.DividingLineColor, }; roomView.AddChidren(btnLine); Button btnChoose = new Button() { X = Application.GetRealWidth(331), Gravity = Gravity.CenterVertical, Width = Application.GetMinRealAverage(28), Height = Application.GetMinRealAverage(28), UnSelectedImagePath = "Public/ChooseIcon.png", SelectedImagePath = "Public/ChooseOnIcon.png", IsSelected = function.roomIds.Contains(room.roomId), Tag = "ChooseIcon" }; roomView.AddChidren(btnChoose); Button btnRoomText = new Button() { X = Application.GetRealWidth(16), //Width = Application.GetRealWidth(280), TextSize = CSS_FontSize.SubheadingFontSize, TextColor = CSS_Color.FirstLevelTitleColor, TextAlignment = TextAlignment.CenterLeft, Text = room.floorName + room.roomName, }; roomView.AddChidren(btnRoomText); btnRoomText.MouseUpEventHandler = (sender, e) => { btnChoose.IsSelected = !btnChoose.IsSelected; LoadEvent_RoomSelected(room, btnChoose.IsSelected); }; if (!function.roomIds.Contains(room.roomId) && btnChooseAll.IsSelected) { btnChooseAll.IsSelected = false; } } LoadEventLoad(); } } /// /// 功能分配房间BLL /// public partial class GroupChooseRoomPage { /// /// 加载事件列表 /// void LoadEventLoad() { LoadMethod_AllElection(); } /// /// 全选按钮事件 /// void LoadMethod_AllElection() { btnAllRoomText.MouseUpEventHandler = (sender, e) => { try { btnChooseAll.IsSelected = !btnChooseAll.IsSelected; for (int i = 0; i < contentView.ChildrenCount; i++) { var view = contentView.GetChildren(i); if (view.GetType() == typeof(FrameLayout)) { if (view.Tag != null && view.Tag.ToString() == "row") { for (int j = 0; j < (view as FrameLayout).ChildrenCount; j++) { var btn = (view as FrameLayout).GetChildren(j); if (btn.GetType() == typeof(Button)) { if (btn.Tag != null && btn.Tag.ToString() == "ChooseIcon") { (btn as Button).IsSelected = btnChooseAll.IsSelected; } } } } } } function.roomIds.Clear(); if (btnChooseAll.IsSelected) { foreach (var room in Entity.SpatialInfo.CurrentSpatial.RoomList) { if (btnChooseAll.IsSelected) { function.roomIds.Add(room.roomId); } } } }catch(Exception ex) { MainPage.Log($"GroupChooseRoom 全选按钮事件 error : {ex.Message}"); Application.RunOnMainThread(() => { this.RemoveFromParent(); }); } }; } /// /// 房间选中事件 /// void LoadEvent_RoomSelected(Entity.Room room, bool isAdd) { if (isAdd) { function.roomIds.Add(room.roomId); } else { function.roomIds.Remove(room.roomId); } if (function.roomIds.Count == SpatialInfo.CurrentSpatial.RoomList.Count) { btnChooseAll.IsSelected = true; } else { btnChooseAll.IsSelected = false; } } } }