From 4ce5177289b1d34e467de9d8790836559cc5a09e Mon Sep 17 00:00:00 2001
From: 黄学彪 <hxb@hdlchina.com.cn>
Date: 星期一, 18 十一月 2019 18:06:28 +0800
Subject: [PATCH] 合并了全部的代码

---
 ZigbeeApp/Shared/Phone/UserCenter/UserMain/MessageManagementForm.cs |  211 ++++++++++++++++++++++++++++++++++++++++++++--------
 1 files changed, 177 insertions(+), 34 deletions(-)

diff --git a/ZigbeeApp/Shared/Phone/UserCenter/UserMain/MessageManagementForm.cs b/ZigbeeApp/Shared/Phone/UserCenter/UserMain/MessageManagementForm.cs
index 7b118ad..628bf5d 100755
--- a/ZigbeeApp/Shared/Phone/UserCenter/UserMain/MessageManagementForm.cs
+++ b/ZigbeeApp/Shared/Phone/UserCenter/UserMain/MessageManagementForm.cs
@@ -15,6 +15,10 @@
         /// 鍒楄〃鎺т欢
         /// </summary>
         private VerticalFrameControl listView = null;
+        /// <summary>
+        /// 鍏ㄩ儴鐨勮
+        /// </summary>
+        private Dictionary<string, RowLayoutControl> dicAllRow = null;
 
         #endregion
 
@@ -47,6 +51,8 @@
         /// </summary>
         private async void InitMiddleData()
         {
+            this.dicAllRow = new Dictionary<string, RowLayoutControl>();
+
             //鎵撳紑杩涘害鏉�
             this.ShowProgressBar();
             var result = await UserCenterLogic.GetResponseDataByRequestHttps("ZigbeeUsers/GetPushMessageRecord", false, "");
@@ -62,7 +68,7 @@
             //鍏抽棴杩涘害鏉�
             this.CloseProgressBar();
             
-            HdlThreadLogic.Current.RunMain(() =>
+            HdlThreadLogic.Current.RunMainInThread(() =>
             {
                 //鍒濆鍖栦腑閮ㄦ帶浠�
                 this.InitMiddleFrame(dicData);
@@ -75,16 +81,19 @@
         /// <param name="dicData"></param>
         private void InitMiddleFrame(Dictionary<string, List<MessageRecordInfo>> dicData)
         {
+            int index = 0;
             foreach (var keys in dicData.Keys)
             {
                 var listData = dicData[keys];
                 HdlThreadLogic.Current.RunMain(() =>
                 {
+                    index++;
                     //瀹瑰櫒
                     var framBack = new FrameListControl(23);
-                    framBack.Name = keys;
+                    framBack.Name = index.ToString();
                     framBack.Height = Application.GetRealHeight(100);
                     framBack.BackgroundColor = UserCenterColor.Current.White;
+                    listView.AddChidrenFrame(framBack);
 
                     //鏃ユ湡
                     string strMonth = Language.StringByID(R.MyInternationalizationString.Month);
@@ -103,6 +112,12 @@
                     {
                         //娣诲姞淇℃伅琛�
                         this.AddMsgRowControl(framBack, listData[i], i != listData.Count - 1);
+                    }
+                    //璋冩暣楂樺害
+                    listView.AdjustChidrenFrameHeight(framBack, Application.GetRealHeight(23));
+                    if (index == dicData.Count)
+                    {
+                        listView.AdjustTableHeight();
                     }
                 });
             }
@@ -138,10 +153,14 @@
             //鍏ㄩ儴宸茶
             menuContr.AddMenu(Language.StringByID(R.MyInternationalizationString.uAllRead), () =>
             {
+                //璁剧疆鍏ㄩ儴涓哄凡璇�
+                this.SetAllTickIsRead();
             });
             //鍏ㄩ儴鍒犻櫎
             menuContr.AddMenu(Language.StringByID(R.MyInternationalizationString.uAllDelete), () =>
             {
+                //鍒犻櫎鍏ㄩ儴鐨勬秷鎭�
+                this.DeleteAllMsg();
             });
         }
 
@@ -159,11 +178,13 @@
         {
             var rowControl = new RowLayoutControl(frameList.rowSpace / 2);
             frameList.AddChidren(rowControl);
-           
+            rowControl.Name = frameList.ChildrenCount.ToString();
+            rowControl.MainKeys = recordInfo.RegId;
+            this.dicAllRow[frameList.Name + "-" + rowControl.Name] = rowControl;
 
             //鍥炬爣(鐜板湪娴嬭瘯)
             var btnIcon = rowControl.frameTable.AddLeftIcon(81);
-            btnIcon.UnSelectedImagePath = "Item/Satety.png";
+            btnIcon.UnSelectedImagePath = "Item/Safety.png";
 
             //娑堟伅绫诲瀷
             var btnMsgObject = rowControl.frameTable.AddLeftCaption("娴嬭瘯:娑堟伅绫诲瀷", 600);
@@ -180,7 +201,7 @@
             //娑堟伅
             var btnMsg = rowControl.frameTable.AddMostRightView(recordInfo.MsgContent, 600, 60);
             btnMsg.TextColor = UserCenterColor.Current.TextGrayColor3;
-            btnMsg.Y = Application.GetRealHeight(6) + rowControl.frameTable.chidrenYaxis;
+            btnMsg.Y = Application.GetRealHeight(5) + rowControl.frameTable.chidrenYaxis;
             rowControl.frameTable.AddChidren(btnMsg, ChidrenBindMode.BindEventOnly);
             //鏃堕棿
             var btnTime = rowControl.frameTable.AddMostRightView(recordInfo.MsgContent, 200, 50);
@@ -207,7 +228,7 @@
             btnDelete.ButtonClickEvent += (sender, e) =>
             {
                 //纭鍒犻櫎娑堟伅?
-                string msg = Language.StringByID(R.MyInternationalizationString.uDeleteRoomMsg);
+                string msg = Language.StringByID(R.MyInternationalizationString.uDeleteMessageMsg);
                 this.ShowMassage(ShowMsgType.Confirm, msg, async () =>
                 {
                     await this.DeleteMsg(recordInfo.RegId, frameList, rowControl);
@@ -215,7 +236,7 @@
             };
 
             //鐐瑰嚮
-            rowControl.frameTable.ButtonClickEvent += (sender, e) =>
+            rowControl.frameTable.ButtonClickEvent += async (sender, e) =>
             {
                 if (recordInfo.IsRead == 1)
                 {
@@ -228,8 +249,11 @@
                 //娑堟伅
                 btnMsg.TextColor = UserCenterColor.Current.TextGrayColor1;
                 btnNewTip.RemoveFromParent();
-                //鏍囪宸茶(涓嶇瀹冩垚鍔熶笉鎴愬姛)
-                this.SetTickIsRead(recordInfo.RegId);
+                if (sender != null)
+                {
+                    //鏍囪宸茶(涓嶇瀹冩垚鍔熶笉鎴愬姛)
+                    await this.SetTickIsRead(recordInfo.RegId);
+                }
             };
         }
 
@@ -241,10 +265,53 @@
         /// 鏍囪宸茶
         /// </summary>
         /// <param name="strId"></param>
-        private async void SetTickIsRead(string strId)
+        private async System.Threading.Tasks.Task<bool> SetTickIsRead(string strId)
         {
             var pra = new { Id = strId };
-            //await UserCenterLogic.GetResultStatuByRequestHttps("ZigbeeUsers/TickIsRead", true, pra);
+            await UserCenterLogic.GetResultStatuByRequestHttps("ZigbeeUsers/TickIsRead", true, pra);
+            return true;
+        }
+
+        /// <summary>
+        /// 璁剧疆鍏ㄩ儴涓哄凡璇�
+        /// </summary>
+        private void SetAllTickIsRead()
+        {
+            if (dicAllRow.Count == 0)
+            {
+                return;
+            }
+            //纭鏍囪鍏ㄩ儴娑堟伅涓哄凡璇�?
+            this.ShowMassage(ShowMsgType.Confirm, Language.StringByID(R.MyInternationalizationString.uUnTipAllMessageMsg), () =>
+            {
+                HdlThreadLogic.Current.RunThread(async () =>
+                {
+                    //鎵撳紑杩涘害鏉�
+                    this.ShowProgressBar();
+                    foreach (var contr in this.dicAllRow.Values)
+                    {
+                        //鏍囪瘑鍏ㄩ儴涓哄凡璇�
+                        var result = await this.SetTickIsRead(contr.MainKeys);
+                        if (result == false)
+                        {
+                            //鍏抽棴杩涘害鏉�
+                            this.CloseProgressBar();
+                            return;
+                        }
+                    }
+                    //鍏抽棴杩涘害鏉�
+                    this.CloseProgressBar();
+
+                    HdlThreadLogic.Current.RunMain(() =>
+                    {
+                        //璁剧疆鍏ㄩ儴鐘舵��
+                        foreach (var contr in this.dicAllRow.Values)
+                        {
+                            contr.frameTable.ButtonClickEvent?.Invoke(null, null);
+                        }
+                    });
+                });
+            });
         }
 
         #endregion
@@ -260,18 +327,64 @@
         private async System.Threading.Tasks.Task<bool> DeleteMsg(string strId, FrameListControl frameList, RowLayoutControl rowContr)
         {
             var pra = new { Id = strId };
-            //var result = await UserCenterLogic.GetResultStatuByRequestHttps("ZigbeeUsers/DeletePushMessage", true, pra);
-            //if (result == true && frameList != null)
+            var result = await UserCenterLogic.GetResultStatuByRequestHttps("ZigbeeUsers/DeletePushMessage", true, pra);
+            if (result == true && frameList != null)
             {
                 HdlThreadLogic.Current.RunMain(() =>
                 {
-                    rowContr.RemoveFromParent();
+                    //绉婚櫎缂撳瓨
+                    this.dicAllRow.Remove(frameList.Name + "-" + rowContr.Name);
                     //璋冩暣鎺т欢浣嶇疆
-                    this.AdjustControlLocation(frameList);
+                    this.AdjustControlLocation(frameList, rowContr);
                 });
             }
-            //return result;
-            return true;
+            return result;
+        }
+
+        /// <summary>
+        /// 鍒犻櫎鍏ㄩ儴鐨勬秷鎭�
+        /// </summary>
+        private void DeleteAllMsg()
+        {
+            if (dicAllRow.Count == 0)
+            {
+                return;
+            }
+            //纭鍒犻櫎鍏ㄩ儴娑堟伅?
+            this.ShowMassage(ShowMsgType.Confirm, Language.StringByID(R.MyInternationalizationString.uDeleteAllMessageMsg), () =>
+            {
+                HdlThreadLogic.Current.RunThread(async () =>
+                {
+                    //鎵撳紑杩涘害鏉�
+                    this.ShowProgressBar();
+                    foreach (var contr in this.dicAllRow.Values)
+                    {
+                        //鍒犻櫎鍏ㄩ儴娑堟伅
+                        var result = await this.DeleteMsg(contr.MainKeys, null, null);
+                        if (result == false)
+                        {
+                            //鍏抽棴杩涘害鏉�
+                            this.CloseProgressBar();
+                            return;
+                        }
+                    }
+                    //鍏抽棴杩涘害鏉�
+                    this.CloseProgressBar();
+
+                    HdlThreadLogic.Current.RunMain(() =>
+                    {
+                        bodyFrameLayout.RemoveAll();
+                        listView = new VerticalFrameControl(35);
+                        listView.Height = bodyFrameLayout.Height;
+                        bodyFrameLayout.AddChidren(listView);
+                        HdlThreadLogic.Current.RunThread(() =>
+                        {
+                            //鍒濆鍖栦腑閮ㄤ俊鎭�
+                            this.InitMiddleData();
+                        });
+                    });
+                });
+            });
         }
 
         #endregion
@@ -282,25 +395,19 @@
         /// 璋冩暣鎺т欢浣嶇疆
         /// </summary>
         /// <param name="frameList"></param>
-        private void AdjustControlLocation(FrameListControl frameList)
+        private void AdjustControlLocation(FrameListControl frameList, RowLayoutControl removeRow)
         {
-            int nowHeight = frameList.Height;
-            int changedHeight = 0;
-            if (frameList.ChildrenCount <= 1)
+            int changedHeight = frameList.GetChildren(frameList.ChildrenCount - 1).Height;
+            if (frameList.ChildrenCount <= 2)
             {
                 //宸茬粡鍒犲畬浜�,鍙墿涓嬫爣棰樻棩鏈熶簡
-                frameList.RemoveFromParent();
-                changedHeight = nowHeight;
+                changedHeight = frameList.Height;
             }
-            else
-            {
-                frameList.Height = frameList.GetChildren(frameList.ChildrenCount - 1).Bottom;
-                changedHeight = nowHeight - frameList.Height;
-            }
+            //鍏堣皟鏁村悇鑷鍣ㄧ殑Y杞村潗鏍�
             bool canChangedLoaction = false;
-            for (int i = 0; i < this.listView.ChildrenCount; i++)
+            for (int i = 0; i < this.listView.frameTable.ChildrenCount; i++)
             {
-                var myView = this.listView.GetChildren(i);
+                var myView = this.listView.frameTable.GetChildren(i);
                 if (myView.Name == frameList.Name)
                 {
                     //瀹冧箣鍚庣殑鎺т欢鍏ㄩ儴寰�涓婄Щ鍔�
@@ -311,6 +418,38 @@
                 {
                     myView.Y -= changedHeight;
                 }
+            }
+            //璋冩暣鐖跺鍣ㄥぇ灏�
+            this.listView.AdjustTableHeight();
+
+
+            if (frameList.ChildrenCount <= 2)
+            {
+                //宸茬粡鍒犲畬浜�,鍙墿涓嬫爣棰樻棩鏈熶簡
+                frameList.RemoveFromParent();
+            }
+            else
+            {
+                //杩欎釜瀹瑰櫒閲岄潰琚Щ闄ょ殑琛岀殑涓嬮潰鐨勫叏閮ㄨ,寰�涓婄Щ鍔�
+                bool changedFlage = false;
+                for (int i = 0; i < frameList.ChildrenCount; i++)
+                {
+                    var myView = frameList.GetChildren(i);
+                    if (myView.Name == removeRow.Name)
+                    {
+                        //瀹冧箣鍚庣殑鎺т欢鍏ㄩ儴寰�涓婄Щ鍔�
+                        changedFlage = true;
+                        continue;
+                    }
+                    if (changedFlage == true)
+                    {
+                        myView.Y -= changedHeight;
+                    }
+                }
+                //绉婚櫎鎸囧畾鐨勮
+                removeRow.RemoveFromParent();
+                //瀹瑰櫒澶у皬鍑忓皯
+                frameList.Height -= changedHeight;
             }
         }
 
@@ -345,12 +484,16 @@
                 var listData = dicTemp[listSortKeys[i]];
                 foreach (var data2 in listData)
                 {
-                    string[] myArry = data2.MsgTime.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries);
-                    if (dicData.ContainsKey(myArry[1]) == false)
+                    string[] myArry = data2.MsgTime.Split(new string[] { "T" }, StringSplitOptions.RemoveEmptyEntries);
+                    if (myArry.Length != 2)
                     {
-                        dicData[myArry[1]] = new List<MessageRecordInfo>();
+                        continue;
                     }
-                    dicData[myArry[1]].Add(data2);
+                    if (dicData.ContainsKey(myArry[0]) == false)
+                    {
+                        dicData[myArry[0]] = new List<MessageRecordInfo>();
+                    }
+                    dicData[myArry[0]].Add(data2);
                 }
             }
             return dicData;

--
Gitblit v1.8.0