From 9c8baf7e7e1169ebdf7d5f7ed33ab29dd5fcbf18 Mon Sep 17 00:00:00 2001
From: JLChen <551775569@qq.com>
Date: 星期一, 14 十二月 2020 17:45:17 +0800
Subject: [PATCH] 2020-12-14 1.解锁设置问题修复,增加面容ID验证。2.错误码对接增加。

---
 HDL_ON/UI/UI2/4-PersonalCenter/MemberManagement/MemberFunctionPermissionPageBLL.cs |  332 +++++++++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 310 insertions(+), 22 deletions(-)

diff --git a/HDL_ON/UI/UI2/4-PersonalCenter/MemberManagement/MemberFunctionPermissionPageBLL.cs b/HDL_ON/UI/UI2/4-PersonalCenter/MemberManagement/MemberFunctionPermissionPageBLL.cs
index 4a1bb7a..eba16f4 100644
--- a/HDL_ON/UI/UI2/4-PersonalCenter/MemberManagement/MemberFunctionPermissionPageBLL.cs
+++ b/HDL_ON/UI/UI2/4-PersonalCenter/MemberManagement/MemberFunctionPermissionPageBLL.cs
@@ -1,4 +1,6 @@
 锘縰sing System;
+using System.Collections.Generic;
+using System.Threading;
 using HDL_ON.DAL;
 using HDL_ON.DAL.Server;
 using HDL_ON.Entity;
@@ -10,45 +12,300 @@
         void LoadEventList()
         {
             LoadEvent_AllSharedDataChange();
+            LoadEvent_OptionClick();
         }
 
-        void EditShareData()
+        /// <summary>
+        /// 搴曢儴鎿嶄綔鎸夐挳鐐瑰嚮浜嬩欢
+        /// </summary>
+        void LoadEvent_OptionClick()
         {
-            if (memberInfo.CurShareData.ShareName == "")
+            btnOption.MouseUpEventHandler = (sender, e) =>
             {
-                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")
+                if (titleId == StringId.PermissionToUse)//浠庝釜浜轰腑蹇冭繘鍏ュ崟鐙垎浜�
                 {
-                    new PublicAssmebly().TipMsgAutoClose(Language.StringByID(StringId.OperationFailed), true);
-                    return;
+                    UploadShareDeviceList();
                 }
                 else
                 {
-                    ssdd.DistributedMark = responePack.ResponseData.ToString();
+                    //var sharedBytes = System.Text.Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(funs_New));
+                    //2020-12-01 灞忚斀椤甸潰
+                    //var page = new ChooseShareMemberTargetListPage(funs_New, memberInfo);
+                    //MainPage.BasePageView.AddChidren(page);
+                    //page.LoadPage();
+                    //MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1;
                 }
-                memberInfo.CurShareData = ssdd;
+            };
+        }
+
+        /// <summary>
+        /// 绠$悊璁惧鍒嗕韩
+        /// 2020-12-08 1.澧炲姞鍒嗕韩璁惧鐨勬椂鍊欙紝鍒ゆ柇褰撳墠鎴块棿鍒嗕韩璁惧鎬绘暟锛屼粠鑰屽喅瀹氭槸鍚﹂渶瑕佸鍔犳垨鑰呯Щ闄ゆ埧闂村垎浜�
+        /// </summary>
+        void UploadShareDeviceList()
+        {
+            new Thread(() =>
+            {
+                try
+                {
+                    bool result = false;
+                    Action act = () => { };
+                    Application.RunOnMainThread(() =>
+                    {
+                        act = new PublicAssmebly().TipLoadingMsgDialog(Language.StringByID(StringId.SavingPleaseWait));
+                    });
+
+                    //1.绠$悊鏈�缁堝睘浜庢埧闂寸殑鍒嗕韩
+                    if (funs_New != null && funs_New.Count > 0)
+                    {
+                        //鏈�缁堝睘浜庢埧闂寸殑鍒嗕韩澶т簬0
+                        var success = ShareRoom();
+                        if (success)
+                        {
+                            Utlis.WriteLine("娣诲姞鎴块棿鍒嗕韩鎴愬姛");
+                        }
+                        else
+                        {
+                            Utlis.WriteLine("娣诲姞鎴块棿鍒嗕韩澶辫触");
+                        }
+                    }
+                    else
+                    {
+                        var success = DeleteShareRoom();
+                        if (success)
+                        {
+                            Utlis.WriteLine("鍒犻櫎鎴块棿鍒嗕韩鎴愬姛");
+                        }
+                        else
+                        {
+                            Utlis.WriteLine("鍒犻櫎鎴块棿鍒嗕韩澶辫触");
+                        }
+                    }
+
+                    //2.鎵归噺鍒犻櫎鍒嗕韩
+                    var deleteShareObj = new DeleteShareObj()
+                    {
+                        shareDatas = funs_Del,
+                        homeId = DB_ResidenceData.Instance.CurrentRegion.RegionID,
+                    };
+                    LoadMethod_DelSharedData(deleteShareObj);
+
+                    //3.鎵归噺涓婁紶
+                    var funs_NeedAdd = new List<ShareData>();
+                    foreach (var f in funs_New)
+                    {
+                        var sd = funs.Find((obj) => obj.shareTypeId == f.shareTypeId);
+                        //濡傛灉璇ュ姛鑳藉凡缁忓垎浜紝涓嶇敤鍒嗕韩
+                        if (null == sd)
+                        {
+                            funs_NeedAdd.Add(f);
+                        }
+                    }
+                    //3.1 鎻愪氦璇锋眰
+                    List<string> childAccountIds = new List<string>();
+                    childAccountIds.Add(memberInfo.childAccountId);
+                    var addShareObj = new AddShareObj()
+                    {
+                        shareDatas = funs_NeedAdd,
+                        childAccountIds = childAccountIds,
+                        homeId = DB_ResidenceData.Instance.CurrentRegion.RegionID,
+                    };
+                    result = LoadMethod_AddShareData(addShareObj);
+
+                    if (!result)
+                    {
+                        Application.RunOnMainThread(() =>
+                        {
+                            new PublicAssmebly().TipMsgAutoClose(Language.StringByID(StringId.FunctionSharingFailed), true);
+                        });
+                    }
+
+                    Application.RunOnMainThread(() =>
+                    {
+                        act();
+                    });
+                    if (result)
+                    {
+                        //4.1绠$悊鏈�缁堢殑鍒嗕韩鍒楄〃
+                        var funs_final = new List<ShareData>();
+                        funs_final.AddRange(funs);
+                        //4.2绉婚櫎鍒犻櫎鐨�
+                        foreach (var share_d in funs_Del)
+                        {
+                            var sd = funs_final.Find((obj) => obj.shareTypeId == share_d.shareTypeId);
+                            //濡傛灉璇ュ姛鑳藉凡缁忓垎浜紝涓嶇敤鍒嗕韩
+                            if (null != sd)
+                            {
+                                funs_final.Remove(share_d);
+                            }
+                        }
+                        //4.3娣诲姞鏂板鐨�
+                        funs_final.AddRange(funs_NeedAdd);
+
+                        Application.RunOnMainThread(() =>
+                        {
+                            new PublicAssmebly().TipMsgAutoClose(Language.StringByID(StringId.FunctionSharingSucceeded), true);
+                            memberInfo.CurResidenceShareDate = funs_final;
+                        });
+                        Thread.Sleep(1600);
+                        Application.RunOnMainThread(() =>
+                        {
+                            //MainPage.BasePageView.RemoveAt(MainPage.BasePageView.ChildrenCount - 1);
+                            MainPage.BasePageView.GetChildren(MainPage.BasePageView.ChildrenCount - 1).RemoveFromParent();
+                            refreshFunctionCount?.Invoke(funs_New.Count.ToString());
+                        });
+                    }
+                }
+                catch { }
+                finally
+                {
+
+                }
+            })
+            { IsBackground = true }.Start();
+        }
+
+        /// <summary>
+        /// 鏂板鍏变韩鏁版嵁鐐瑰嚮浜嬩欢
+        /// </summary>
+        bool LoadMethod_AddShareData(AddShareObj ssdd)
+        {
+            //澧炲姞鍏变韩鏁版嵁鐩綍
+            var responePack = new HttpServerRequest().AddShareData(ssdd);
+            if (responePack.Code != StateCode.SUCCESS)
+            {
+                return false;
             }
             else
             {
-                UpdataShareData();
+                return true;
+                //var responeObj = Newtonsoft.Json.JsonConvert.DeserializeObject<ShareData>(responePack.Data.ToString());
+                //ssdd.id = responeObj.id;
+                //// 鏇存柊鍏变韩鏁版嵁
+                //return EditShareData(ssdd);
+            }
+        }
+        /// <summary>
+        /// 鍒犻櫎鍏变韩鏁版嵁鐐瑰嚮浜嬩欢
+        /// </summary>
+        /// <param name="function"></param>
+        bool LoadMethod_DelSharedData(DeleteShareObj sd)
+        {
+            var responePack = new HttpServerRequest().DeleteShareData(sd);
+            if (responePack.Code != StateCode.SUCCESS)
+            {
+                return false;
+            }
+            else
+            {
+                return true;
             }
         }
 
-        void LoadEvent_SharedDataChange(Button btnChoose, Button btn2, FrameLayout btn3, Entity.Function function)
+        /// <summary>
+        /// 鍒嗕韩鎴块棿
+        /// </summary>
+        /// <returns></returns>
+        bool ShareRoom()
+        {
+            var roomList = new List<ShareData>();
+            roomList.Add(new ShareData()
+            {
+                shareType = ShareType.ROOM.ToString(),
+                shareTypeId = room.roomId
+            });
+            List<string> childAccountIds = new List<string>();
+            childAccountIds.Add(memberInfo.childAccountId);
+            var addShareObj = new AddShareObj()
+            {
+                childAccountIds = childAccountIds,
+                homeId = DB_ResidenceData.Instance.CurrentRegion.RegionID,
+                shareDatas = roomList
+            };
+            var responePack = new HttpServerRequest().AddShareData(addShareObj);
+            if (responePack.Code != StateCode.SUCCESS)
+            {
+                return false;
+            }
+            else
+            {
+                return true;
+            }
+        }
+
+        /// <summary>
+        /// 鍒犻櫎鎴块棿鍒嗕韩
+        /// </summary>
+        /// <returns></returns>
+        bool DeleteShareRoom()
+        {
+            var roomList = new List<ShareData>();
+            roomList.Add(new ShareData()
+            {
+                shareType = ShareType.ROOM.ToString(),
+                shareTypeId = room.roomId
+            });
+
+            var deleteShareObj = new DeleteShareObj()
+            {
+                shareDatas = roomList,
+                homeId = DB_ResidenceData.Instance.CurrentRegion.RegionID,
+            };
+            var responePack = new HttpServerRequest().DeleteShareData(deleteShareObj);
+            if (responePack.Code != StateCode.SUCCESS)
+            {
+                return false;
+            }
+            else
+            {
+                return true;
+            }
+        }
+
+        /// <summary>
+        /// LoadMethod_SharedDataChange
+        /// </summary>
+        /// <param name="btnChoose"></param>
+        /// <param name="btn2"></param>
+        /// <param name="btn3"></param>
+        /// <param name="function"></param>
+        void LoadMethod_SharedDataChange(Button btnChoose, Button btn2, FrameLayout btn3, Function function)
         {
             EventHandler<MouseEventArgs> eventHandler = (sender, e) =>
             {
                 btnChoose.IsSelected = !btnChoose.IsSelected;
+                var sd = funs.Find((obj) => obj.shareTypeId == function.deviceId);
                 if (btnChoose.IsSelected)
                 {
                     try
                     {
-                        funs.Add(function);
+                        if (null != sd)
+                        {
+                            if (!funs_New.Contains(sd))
+                            {
+                                funs_New.Add(sd);
+                            }
+                            if (funs_Del.Contains(sd))
+                            {
+                                funs_Del.Remove(sd);
+                            }
+                        }
+                        else
+                        {
+                            var newSd = new ShareData();
+                            newSd.shareTypeId = function.deviceId;
+
+                            funs_New.Add(newSd);
+                        }
+                        btnChooseAll.IsSelected = true;
+                        foreach (var f in room.GetRoomFunctions(false))
+                        {
+                            if (funs_New.Find((obj) => obj.shareTypeId == f.deviceId) == null)
+                            {
+                                btnChooseAll.IsSelected = false;
+                                break;
+                            }
+                        }
                     }
                     catch (Exception ex)
                     {
@@ -57,7 +314,20 @@
                 }
                 else
                 {
-                    funs.Remove(function);
+                    var onFuns = funs_New.Find((obj) => obj.shareTypeId == function.deviceId);
+                    if (funs_New.Contains(onFuns))
+                    {
+                        funs_New.Remove(onFuns);
+                    }
+
+                    if (null != sd)
+                    {
+                        if (!funs_Del.Contains(sd))
+                        {
+                            funs_Del.Add(sd);
+                        }
+                    }
+                    btnChooseAll.IsSelected = false;
                 }
             };
             btnChoose.MouseUpEventHandler = eventHandler;
@@ -65,23 +335,41 @@
             btn3.MouseUpEventHandler = eventHandler;
         }
 
+        /// <summary>
+        /// 鍏ㄩ�夋寜閽偣鍑讳簨浠�
+        /// </summary>
         void LoadEvent_AllSharedDataChange()
         {
             EventHandler<MouseEventArgs> eventHandler = (sender, e) =>
             {
                 btnChooseAll.IsSelected = !btnChooseAll.IsSelected;
-                funs.Clear();
-                funs = new System.Collections.Generic.List<Function>();
+                funs_Del = new List<ShareData>();
+                funs_New = new List<ShareData>();
                 if (btnChooseAll.IsSelected)
                 {
-                    funs.AddRange( room.functions);
+                    foreach (var f in room.GetRoomFunctions(false))
+                    {
+                        var ssdd = new ShareData();
+                        ssdd.shareTypeId = f.deviceId;
+                        funs_New.Add(ssdd);
+                    }
                 }
-                LoadFunctionRow();
+                else
+                {
+                    foreach (var f in room.GetRoomFunctions(false))
+                    {
+                        var sd = funs.Find((obj) => obj.shareTypeId == f.deviceId);
+                        if (sd != null)
+                        {
+                            funs_Del.Add(sd);
+                        }
+                    }
+                }
+                LoadFunctionRow(funs_New);
             };
             btnChooseAll.MouseUpEventHandler = eventHandler;
             allRoomView.MouseUpEventHandler = eventHandler;
 
         }
-
     }
 }

--
Gitblit v1.8.0