wjc
2023-03-30 cae4d4b5b508a666fbd0dff3c2a981fdff841bc8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
 
using System;
using HDL_ON.DAL.Server;
using HDL_ON.Entity;
using HDL_ON.UI.CSS;
using Shared;
 
namespace HDL_ON.UI
{
    /// <summary>
    /// 功能分配房间界面
    /// </summary>
    public partial class GroupChooseRoomPage : FrameLayout
    {
        #region 控件列表
        FrameLayout bodyView;
        /// <summary>
        /// 内容加载区域
        /// </summary>
        VerticalScrolViewLayout contentView;
 
        Button btnAllRoomText;
        Button btnChooseAll;
 
        #endregion
 
        #region 局部变量
 
        GroupControl function
            ;
        /// <summary>
        /// 回调事件
        /// </summary>
        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();
        }
 
        /// <summary>
        /// 加载页面
        /// </summary>
        public void LoadPage()
        {
            bodyView.BackgroundColor = CSS_Color.BackgroundColor;
            new TopViewDiv(bodyView, Language.StringByID(StringId.CombinedDimming)).LoadTopView();
 
        
 
            var contentView = new VerticalScrolViewLayout()
            {
                Y = Application.GetRealHeight(64),
                Height = Application.GetRealHeight(667 - 64),
            };
            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();
        }
    }
    /// <summary>
    /// 功能分配房间BLL
    /// </summary>
    public partial class GroupChooseRoomPage
    {
        /// <summary>
        /// 加载事件列表
        /// </summary>
        void LoadEventLoad()
        {
            LoadMethod_AllElection();
        }
 
        /// <summary>
        /// 全选按钮事件
        /// </summary>
        void LoadMethod_AllElection()
        {
            btnAllRoomText.MouseUpEventHandler += (sender, e) =>
            {
                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);
                        }
                    }
                }
            };
        }
 
        /// <summary>
        /// 房间选中事件
        /// </summary>
        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;
            }
        }
 
    }
}