黄学彪
2019-09-30 404cdc88627f942df7944af04ee05b9d527752d6
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
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
using Shared.Common;
using System;
using System.Collections.Generic;
 
namespace Shared.Phone.UserCenter.Residence
{
    /// <summary>
    /// 住宅管理的画面★
    /// </summary>
    public class ResidenceManagementForm : EditorCommonForm
    {
        #region ■ 变量声明___________________________
 
        /// <summary>
        /// 列表控件
        /// </summary>
        private VerticalScrolViewLayout listView = null;
        /// <summary>
        /// 住宅数据
        /// </summary>
        private Dictionary<string, Common.ResponseEntity.ResidenceObj> dicResidenceData = null;
 
        #endregion
 
        #region ■ 初始化_____________________________
 
        /// <summary>
        /// 画面显示(底层会固定调用此方法,借以完成画面创建)
        /// </summary>
        public void ShowForm()
        {
            //设置标题信息
            base.SetTitleText(Language.StringByID(R.MyInternationalizationString.ResidenceManagement));
 
            if (UserCenterResourse.UserInfo.AuthorityNo == 1)
            {
                //右上添加按钮
                var btnTopIcon = new MostRightIconControl(69, 69);
                btnTopIcon.UnSelectedImagePath = "Item/Add.png";
                topFrameLayout.AddChidren(btnTopIcon);
                btnTopIcon.InitControl();
                btnTopIcon.ButtonClickEvent += (sender, e) =>
                {
                    //var info = new Common.ResponseEntity.ResidenceObj();
                    //this.ShowEditorForm(info);
                };
            }
 
            //初始化中部控件
            //this.InitMiddleFrame();
        }
 
        ///// <summary>
        ///// 初始化中部控件
        ///// </summary>
        //private void InitMiddleFrame()
        //{
        //    //清空bodyFrame
        //    this.ClearBodyFrame();
 
        //    listView = new VerticalScrolViewLayout();
        //    listView.Height = bodyFrameLayout.Height;
        //    bodyFrameLayout.AddChidren(listView);
 
        //    new System.Threading.Thread(() =>
        //    {
        //        //设置住宅信息
        //        this.SetResidenceInfo();
        //    })
        //    { IsBackground = true }.Start();
        //}
 
        ///// <summary>
        ///// 设置住宅信息
        ///// </summary>
        //private async void SetResidenceInfo()
        //{
        //    //开启进度条
        //    this.ShowProgressBar();
 
        //    Application.RunOnMainThread(() =>
        //    {
        //        this.listView?.RemoveAll();
        //    });
        //    //获取住宅信息
        //    var Pra = new GetResidenceInfoPra();
        //    string resultData = await UserCenterLogic.GetResponseDataByRequestHttps("App/GetHomePager", false, Pra);
        //    if (resultData == null)
        //    {
        //        //关闭进度条
        //        this.CloseProgressBar(ShowReLoadMode.YES);
        //        return;
        //    }
        //    this.dicResidenceData = new Dictionary<string, Common.ResponseEntity.ResidenceObj>();
 
        //    var pageData = Newtonsoft.Json.JsonConvert.DeserializeObject<Common.ResponseEntity.ResidenceRes>(resultData);
        //    foreach (Common.ResponseEntity.ResidenceObj info in pageData.PageData)
        //    {
        //        if (info.IsOthreShare == false)
        //        {
        //            //收集该账号所拥有的自己的住宅的数据
        //            this.dicResidenceData[info.Id] = info;
        //        }
 
        //        Application.RunOnMainThread(() =>
        //        {
        //            if (this.Parent != null)
        //            {
        //                this.AddRowLayout(info);
        //            }
        //        });
        //    }
        //    //关闭进度条
        //    this.CloseProgressBar();
        //}
 
        #endregion
 
        //#region ■ 添加住宅的行_______________________
 
        ///// <summary>
        ///// 添加住宅的行
        ///// </summary>
        ///// <param name="info"></param>
        //private void AddRowLayout(Common.ResponseEntity.ResidenceObj info)
        //{
        //    if (info.IsOthreShare == true)
        //    {
        //        return;
        //    }
        //    var rowLayout = new RowLayout();
        //    rowLayout.Height = ControlCommonResourse.ListViewRowHeight;
        //    this.listView.AddChidren(rowLayout);
 
        //    //图标
        //    var btnIcon = new RowLeftIconView();
        //    btnIcon.ChangedControlInPointMode();
        //    rowLayout.AddChidren(btnIcon);
 
        //    //住宅
        //    var txtResidence = new RowCenterView(true);
        //    txtResidence.Text = info.Name;
        //    rowLayout.AddChidren(txtResidence);
        //    txtResidence.X -= ControlCommonResourse.PointXXLeft;
 
        //    //不是分享过来的住宅
        //    if (info.IsOthreShare == false)
        //    {
        //        //编辑
        //        var btnEditor = new RowEditorButton();
        //        rowLayout.AddRightView(btnEditor);
        //        btnEditor.MouseUpEventHandler += (sender, e) =>
        //        {
        //            this.ShowEditorForm(info);
        //        };
 
        //        //不能删除当前正在操作的住宅
        //        if (Common.Config.Instance.HomeId != info.Id)
        //        {
        //            //删除
        //            var btnDelete = new RowDeleteButton();
        //            rowLayout.AddRightView(btnDelete);
        //            btnDelete.MouseUpEventHandler += (sender, e) =>
        //            {
        //                //检测能否删除住宅
        //                if (this.CheckIsCanDeleteResidence(info) == false)
        //                {
        //                    return;
        //                }
        //                //确认要删除吗?
        //                string msg = Language.StringByID(R.MyInternationalizationString.uShowDoDeleteMsg);
        //                this.ShowConfirmMsg(msg, "DeleteResidence", info);
        //            };
        //        }
        //    }
        //    //成员的管理员权限,只能编辑,不能删除
        //    //if (info.AccountType == 1)
        //    //{
        //    //    //编辑
        //    //    var btnEditor = new RowEditorButton();
        //    //    rowLayout.AddRightView(btnEditor);
        //    //    btnEditor.MouseUpEventHandler += (sender, e) =>
        //    //    {
        //    //        this.ShowEditorForm(info);
        //    //    };
        //    //}
        //}
 
        //#endregion
 
        //#region ■ 显示编辑画面_______________________
 
        ///// <summary>
        ///// 显示编辑画面
        ///// </summary>
        ///// <param name="info"></param>
        //private void ShowEditorForm(Common.ResponseEntity.ResidenceObj info)
        //{
        //    //生成一个弹窗画面
        //    var dialogForm = new DialogInputFrameControl(this, DialogFrameMode.OnlyInput);
 
        //    if (string.IsNullOrEmpty(info.Name) == true)
        //    {
        //        //添加住宅
        //        dialogForm.SetTitleText(Language.StringByID(R.MyInternationalizationString.uAddResidence));
        //    }
        //    else
        //    {
        //        //编辑住宅
        //        dialogForm.SetTitleText(Language.StringByID(R.MyInternationalizationString.uEditorResidence));
        //    }
 
        //    //请输入住宅名称
        //    dialogForm.SetTipText(Language.StringByID(R.MyInternationalizationString.uPleaseInputResidenceName));
        //    if (info.Name != null)
        //    {
        //        dialogForm.InputText = info.Name;
        //    }
           
        //    //按下确认按钮
        //    dialogForm.ComfirmClickEvent += (()=>
        //    {
        //        string resiName = dialogForm.InputText;
        //        if (resiName == string.Empty)
        //        {
        //            //请输入住宅名称
        //            string msg = Language.StringByID(R.MyInternationalizationString.uPleaseInputResidenceName);
        //            this.ShowErrorMsg(msg);
        //            return;
        //        }
        //        //画面关闭
        //        dialogForm.CloseDialog();
 
        //        if (info.Name != resiName)
        //        {
        //            //保存住宅
        //            this.SaveResidence(resiName, info, string.IsNullOrEmpty(info.Name) == false);
        //        }
        //    });
        //}
 
        //#endregion
 
        //#region ■ 保存住宅___________________________
 
        ///// <summary>
        ///// 保存住宅
        ///// </summary>
        ///// <param name="ResidenceName"></param>
        ///// <param name="info"></param>
        ///// <param name="isEditor"></param>
        ///// <returns></returns>
        //private async void SaveResidence(string ResidenceName, Common.ResponseEntity.ResidenceObj info, bool isEditor)
        //{
        //    //检测能否保存住宅
        //    if (this.CheckIsCanSaveResidence(info.Id, ResidenceName, isEditor) == false)
        //    {
        //        return;
        //    }
        //    //开启进度条
        //    this.ShowProgressBar();
 
        //    if (isEditor == true)
        //    {
        //        var Pra = new EditorResidencePra();
        //        Pra.HomeId = info.Id;
        //        Pra.Name = ResidenceName;
        //        //编辑住宅
        //        bool flage = await UserCenterLogic.GetResultStatuByRequestHttps("App/EditHome", false, Pra);
        //        if (flage == false)
        //        {
        //            //关闭进度条
        //            this.CloseProgressBar();
        //            return;
        //        }
        //        //刷新内存的住宅名
        //        House.EditorHouseByHouseId(info.Id, ResidenceName);
        //        //重新刷新列表
        //        this.SetResidenceInfo();
        //    }
        //    else
        //    {
        //        var Pra = new AddResidencePra();
        //        Pra.Name = ResidenceName;
        //        //添加住宅
        //        string resultData = await UserCenterLogic.GetResponseDataByRequestHttps("App/AddHome", false, Pra);
        //        if (resultData == null)
        //        {
        //            //关闭进度条
        //            this.CloseProgressBar();
        //            return;
        //        }
 
        //        var newInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<List<NewResidenceInfo>>(resultData);
 
        //        House.AddHouse(newInfo[0].Id, ResidenceName, 0);
        //        //重新刷新列表
        //        this.SetResidenceInfo();
        //    }
        //}
 
        //#endregion
 
        //#region ■ 删除住宅___________________________
 
        ///// <summary>
        ///// 删除住宅
        ///// </summary>
        ///// <param name="info"></param>
        //public async void DeleteResidence(Common.ResponseEntity.ResidenceObj info)
        //{
        //    //开启进度条
        //    this.ShowProgressBar();
 
        //    var Pra = new DeleteResidencePra();
        //    Pra.HomeId = info.Id;
 
        //    bool result = await UserCenterLogic.GetResultStatuByRequestHttps("App/DelHome", false, Pra);
        //    if (result == false)
        //    {
        //        //关闭进度条
        //        this.CloseProgressBar();
        //        return;
        //    }
        //    House.DeleteHouseByHouseId(info.Id);
 
        //    this.SetResidenceInfo();
        //}
 
        //#endregion
 
        //#region ■ 一般方法___________________________
 
        ///// <summary>
        ///// 检测能否删除住宅
        ///// </summary>
        ///// <param name="info"></param>
        ///// <returns></returns>
        //private bool CheckIsCanDeleteResidence(Common.ResponseEntity.ResidenceObj info)
        //{
        //    if (this.dicResidenceData.Count == 1)
        //    {
        //        //如果此账号下只剩下唯一一个自己的住宅,当删除这个住宅时,提示不能删除
        //        //因为最少要有一个住宅
        //        if (this.dicResidenceData.ContainsKey(info.Id) == true)
        //        {
        //            //不能删除最后唯一的住宅
        //            string msg = Language.StringByID(R.MyInternationalizationString.uDoNotDeleteLastResidence);
        //            this.ShowErrorMsg(msg);
        //            return false;
        //        }
        //    }
        //    return true;
        //}
 
        ///// <summary>
        ///// 检测能否保存住宅
        ///// </summary>
        ///// <param name="residenceId">住宅ID</param>
        ///// <param name="residenceName">住宅名</param>
        ///// <param name="isEditor">isEditor</param>
        ///// <returns></returns>
        //private bool CheckIsCanSaveResidence(string residenceId, string residenceName, bool isEditor)
        //{
        //    //住宅名字重复检测
        //    foreach (string strId in this.dicResidenceData.Keys)
        //    {
        //        if (residenceId != strId && residenceName == this.dicResidenceData[strId].Name)
        //        {
        //            //住宅名字已经存在
        //            int msgId = isEditor == true ? R.MyInternationalizationString.EditZigbeeHome_Exist : R.MyInternationalizationString.AddZigbeeHome_Exist;
        //            string msg = Language.StringByID(msgId);
        //            this.ShowErrorMsg(msg);
        //            return false;
        //        }
        //    }
        //    return true;
        //}
 
        //#endregion
 
        //#region ■ 结构体_____________________________
 
        ///// <summary>
        ///// 访问住宅信息接口的启动参数(查询专用)
        ///// </summary>
        //public class GetResidenceInfoPra:IfacePraCommon
        //{
        //    /// <summary>
        //    /// RequestVersion
        //    /// </summary>
        //    public string RequestVersion = Common.CommonPage.RequestVersion;
        //    /// <summary>
        //    /// ReqDto
        //    /// </summary>
        //    public TokenInfo ReqDto = new TokenInfo();
        //}
 
        ///// <summary>
        ///// 访问住宅信息接口的启动参数(查询专用)
        ///// </summary>
        //public class TokenInfo
        //{
        //    /// <summary>
        //    /// LoginAccessToken
        //    /// </summary>
        //    public string LoginAccessToken = Common.Config.Instance.Token;
        //    /// <summary>
        //    /// PageSetting
        //    /// </summary>
        //    public PageSettingInfo PageSetting = new PageSettingInfo()
        //    {
        //        Page = 1,
        //        PageSize = 500
        //    };
        //}
 
        ///// <summary>
        /////  添加住宅的启动参数
        ///// </summary>
        //public class AddResidencePra:IfacePraCommon
        //{
        //    /// <summary>
        //    /// RequestVersion
        //    /// </summary>
        //    public string RequestVersion = Common.CommonPage.RequestVersion;
        //    /// <summary>
        //    /// LoginAccessToken
        //    /// </summary>
        //    public string LoginAccessToken = Common.Config.Instance.Token;
        //    /// <summary>
        //    /// Name
        //    /// </summary>
        //    public string Name = string.Empty;
        //}
 
        ///// <summary>
        ///// 新住宅的信息
        ///// </summary>
        //public class NewResidenceInfo
        //{
        //    /// <summary>
        //    /// ZigbeeHomeGuid
        //    /// </summary>
        //    public string Id = string.Empty;
        //}
 
        ///// <summary>
        /////  编辑住宅的启动参数
        ///// </summary>
        //public class EditorResidencePra : IfacePraCommon
        //{
        //    /// <summary>
        //    /// RequestVersion
        //    /// </summary>
        //    public string RequestVersion = Common.CommonPage.RequestVersion;
        //    /// <summary>
        //    /// LoginAccessToken
        //    /// </summary>
        //    public string LoginAccessToken = Common.Config.Instance.Token;
        //    /// <summary>
        //    /// ZigbeeHomeId
        //    /// </summary>
        //    public string HomeId = "";
        //    /// <summary>
        //    /// Name
        //    /// </summary>
        //    public string Name = string.Empty;
        //}
 
        ///// <summary>
        /////  删除住宅的启动参数
        ///// </summary>
        //public class DeleteResidencePra : IfacePraCommon
        //{
        //    /// <summary>
        //    /// RequestVersion
        //    /// </summary>
        //    public string RequestVersion = Common.CommonPage.RequestVersion;
        //    /// <summary>
        //    /// LoginAccessToken
        //    /// </summary>
        //    public string LoginAccessToken = Common.Config.Instance.Token;
        //    /// <summary>
        //    /// ZigbeeHomeId
        //    /// </summary>
        //    public string HomeId = "";
        //}
        //#endregion
    }
}