wxr
2020-06-08 b71dfb3ca100340005d56e1298292807da82322d
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
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
using System;
using Shared;
using HDL_ON.Entity;
using HDL_ON.UI.CSS;
using System.Collections.Generic;
using HDL_ON.DAL;
using HDL_ON.DAL.Server;
 
namespace HDL_ON.UI
{
    public class MemberFunctionPermissionPage : FrameLayout
    {
        MemberFunctionPermissionPage bodyView;
 
        Button btnChooseAll;
 
        ResidenceMemberInfo memberInfo;
 
        Room room;
 
        List<Function> funs;
 
 
        public MemberFunctionPermissionPage(ResidenceMemberInfo mInfo, Room r)
        {
            bodyView = this;
            memberInfo = mInfo;
            room = r;
            funs = new List<Function>();
            if (memberInfo.CurShareData.ShareDataBytes != null)
            {
                funs = Newtonsoft.Json.JsonConvert.DeserializeObject<List<Function>>(
                    CommonPage.MyEncodingUTF8.GetString(memberInfo.CurShareData.ShareDataBytes));
            }
        }
        public void LoadPage()
        {
            new TopViewDiv(bodyView, Language.StringByID(StringId.PermissionToUse)).LoadTopView();
 
            var allRoomView = new FrameLayout()
            {
                Y = Application.GetRealHeight(64),
                Height = Application.GetRealHeight(50),
                BackgroundColor = CSS_Color.MainBackgroundColor,
            };
            bodyView.AddChidren(allRoomView);
 
            Button btnAllRoomText = new Button()
            {
                X = Application.GetRealWidth(16),
                Width = Application.GetRealWidth(280),
                TextID = StringId.All,
                TextSize = CSS_FontSize.SubheadingFontSize,
                TextColor = CSS_Color.FirstLevelTitleColor,
                TextAlignment = TextAlignment.CenterLeft,
            };
            allRoomView.AddChidren(btnAllRoomText);
 
            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);
 
            allRoomView.AddChidren(new Button()
            {
                Gravity = Gravity.CenterHorizontal,
                Y = Application.GetRealHeight(49),
                Height = Application.GetMinReal(1),
                Width = Application.GetRealWidth(343),
                BackgroundColor = CSS_Color.DividingLineColor,
            });
 
            var contentView = new VerticalScrolViewLayout()
            {
                Y = Application.GetRealHeight(64+50),
                Height = Application.GetRealHeight(450),
            };
            bodyView.AddChidren(contentView);
 
            foreach (var function in room.functions)
            {
                var roomView = new FrameLayout()
                {
                    Height = Application.GetRealHeight(50),
                    BackgroundColor = CSS_Color.MainBackgroundColor,
                    Tag = "row"
                };
                contentView.AddChidren(roomView);
 
                Button btnRoomText = new Button()
                {
                    X = Application.GetRealWidth(16),
                    Width = Application.GetRealWidth(280),
                    TextSize = CSS_FontSize.SubheadingFontSize,
                    TextColor = CSS_Color.FirstLevelTitleColor,
                    TextAlignment = TextAlignment.CenterLeft,
                    Text = function.name,
                };
                roomView.AddChidren(btnRoomText);
 
                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",
                    Tag = "ChooseIcon"
                };
                roomView.AddChidren(btnChoose);
                if (funs.Find((obj)=>obj.sid == function.sid) != null)
                {
                    btnChoose.IsSelected = true;
                    funs.Add(function);
                }
                else
                {
                    if (btnChooseAll.IsSelected)
                        btnChooseAll.IsSelected = false;
                }
 
                EventHandler<MouseEventArgs> eventHandler = (sender, e) =>
                {
                    btnChoose.IsSelected = !btnChoose.IsSelected;
                    if (btnChoose.IsSelected)
                    {
                        try
                        {
                            funs.Add(function);
                        }
                        catch (Exception ex)
                        {
                            MainPage.Log($"Evhaaa {ex.Message}");
                        }
                    }
                    else
                    {
                        funs.Remove(function);
                    }
                };
 
                btnChoose.MouseUpEventHandler = eventHandler;
                btnRoomText.MouseUpEventHandler = eventHandler;
                roomView.MouseUpEventHandler = eventHandler;
 
                var btnLine = new Button()
                {
                    Gravity = Gravity.CenterHorizontal,
                    Y = Application.GetRealHeight(49),
                    Height = Application.GetMinReal(1),
                    Width = Application.GetRealWidth(343),
                    BackgroundColor = CSS_Color.DividingLineColor,
                };
                roomView.AddChidren(btnLine);
            }
 
            var btnOption = new Button()
            {
                Y = Application.GetRealHeight(519+64),
                Gravity = Gravity.CenterHorizontal,
                Width = Application.GetRealWidth(220),
                Height = Application.GetRealHeight(44),
                BackgroundColor = CSS_Color.MainColor,
                TextAlignment = TextAlignment.Center,
                TextColor = CSS_Color.MainBackgroundColor,
                TextID = StringId.Confirm,
                TextSize = CSS_FontSize.SubheadingFontSize,
                IsBold = true,
                Radius = (uint) Application.GetRealWidth(22),
                BorderColor = 0x00000000,
                BorderWidth = 0,
            };
            bodyView.AddChidren(btnOption);
            btnOption.MouseUpEventHandler = (sender, e) => {
                var act = TipLoadingMsg(Language.StringByID(StringId.SavingPleaseWait));
                memberInfo.CurShareData.ShareDataBytes = CommonPage.MyEncodingUTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(funs));
                EditShareData();
                act();
            };
        }
 
        void EditShareData()
        {
            if (memberInfo.CurShareData.ShareName == "")
            {
                var ssdd = new ShareData();
                ssdd.ShareName = DB_ResidenceData.residenceData.residecenInfo.RegionID;
                ssdd.HouseDistributedMark = DB_ResidenceData.residenceData.residecenInfo.RegionID;
                ssdd.ShareDataBytes = CommonPage.MyEncodingUTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(funs));
                ssdd.SubAccountDistributedMark = memberInfo.SubAccountDistributedMark;
                ResponsePack responePack = new HttpServerRequest().AddShareData(ssdd);
                if (responePack.StateCode.ToUpper() != "SUCCESS")
                {
                    new PublicAssmebly().TipMsgAutoClose(Language.StringByID(StringId.OperationFailed), true);
                    return;
                }
                else
                {
                    ssdd.DistributedMark = responePack.ResponseData.ToString();
                }
                memberInfo.CurShareData = ssdd;
            }
            else
            {
                UpdataShareData();
            }
        }
 
        void UpdataShareData()
        {
            ResponsePack responePack = new HttpServerRequest().EditShareData(memberInfo.CurShareData);
            if (responePack.StateCode.ToUpper() == "SUCCESS")
            {
                new PublicAssmebly().TipMsgAutoClose(Language.StringByID(StringId.SavedSuccessfully), true);
            }
            else
            {
                new PublicAssmebly().TipMsgAutoClose(Language.StringByID(StringId.OperationFailed), true);
            }
        }
 
        Action TipLoadingMsg(string msg)
        {
            Dialog dialog = new Dialog()
            {
                X = Application.GetRealWidth(89),
                Y = Application.GetRealHeight(285),
                Width = Application.GetRealWidth(198),
                Height = Application.GetRealHeight(98),
            };
 
            FrameLayout frame = new FrameLayout()
            {
                BackgroundColor = CSS_Color.DialogTransparentColor1,
                Radius = (uint)Application.GetRealWidth(12),
            };
            dialog.AddChidren(frame);
 
            Button btnTipIcon = new Button()
            {
                Gravity = Gravity.CenterHorizontal,
                Y = Application.GetRealHeight(15),
                Width = Application.GetRealWidth(32),
                Height = Application.GetRealWidth(32),
                UnSelectedImagePath = "Public/MsgIcon/LoadingIcon.png",
            };
            frame.AddChidren(btnTipIcon);
 
            Button btnTipMsg = new Button()
            {
                Y = Application.GetRealHeight(47),
                Height = Application.GetRealHeight(50),
                TextAlignment = TextAlignment.Center,
                TextSize = CSS_FontSize.TextFontSize,
                TextColor = CSS_Color.MainBackgroundColor,
                Text = msg,
            };
            frame.AddChidren(btnTipMsg);
 
            //new System.Threading.Thread(() =>{
            //});
 
            dialog.Show();
            return new Action(() => {
                dialog.Close();
            });
        }
 
    }
}