From 642fcdaeb496d9a8f3154e17fd76005be3fcf197 Mon Sep 17 00:00:00 2001
From: gxc <guoxuecheng@guoxuechengdeMacBook-Pro.local>
Date: 星期二, 03 十二月 2019 12:00:24 +0800
Subject: [PATCH] 2019.12.3

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

diff --git a/ZigbeeApp/Shared/Phone/UserCenter/UserMain/MessageManagementForm.cs b/ZigbeeApp/Shared/Phone/UserCenter/UserMain/MessageManagementForm.cs
new file mode 100755
index 0000000..7197147
--- /dev/null
+++ b/ZigbeeApp/Shared/Phone/UserCenter/UserMain/MessageManagementForm.cs
@@ -0,0 +1,530 @@
+锘縰sing System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace Shared.Phone.UserCenter.UserMain
+{
+    /// <summary>
+    /// 娑堟伅涓績
+    /// </summary>
+    public class MessageManagementForm : EditorCommonForm
+    {
+        #region 鈻� 鍙橀噺澹版槑___________________________
+
+        /// <summary>
+        /// 鍒楄〃鎺т欢
+        /// </summary>
+        private VerticalFrameRefreshControl listView = null;
+        /// <summary>
+        /// 鍏ㄩ儴鐨勮
+        /// </summary>
+        private Dictionary<string, RowLayoutControl> dicAllRow = null;
+
+        #endregion
+
+        #region 鈻� 鍒濆鍖朹____________________________
+
+        /// <summary>
+        /// 鐢婚潰鏄剧ず(搴曞眰浼氬浐瀹氳皟鐢ㄦ鏂规硶锛屽�熶互瀹屾垚鐢婚潰鍒涘缓)
+        /// </summary>
+        public void ShowForm()
+        {
+            //璁剧疆澶撮儴淇℃伅
+            base.SetTitleText(Language.StringByID(R.MyInternationalizationString.uMessageCenter));
+
+            //鍒濆鍖栧彸涓婅鑿滃崟
+            this.InitTopRightMenu();
+
+            listView = new VerticalFrameRefreshControl(35);
+            listView.Height = bodyFrameLayout.Height;
+            bodyFrameLayout.AddChidren(listView);
+            listView.BeginHeaderRefreshingAction += () =>
+            {
+                HdlThreadLogic.Current.RunThread(() =>
+                {
+                    //鍒濆鍖栦腑閮ㄤ俊鎭�
+                    this.InitMiddleData(false);
+                });
+            };
+
+            HdlThreadLogic.Current.RunThread(() =>
+            {
+                //鎵撳紑杩涘害鏉�
+                this.ShowProgressBar();
+
+                //鍒濆鍖栦腑閮ㄤ俊鎭�
+                this.InitMiddleData(true);
+            });
+        }
+
+        /// <summary>
+        /// 鍒濆鍖栦腑閮ㄤ俊鎭�
+        /// </summary>
+        private async void InitMiddleData(bool showReload)
+        {
+            //鑾峰彇鏁版嵁
+            var dicData = await this.GetMessageData();
+            //鍏抽棴杩涘害鏉�
+            this.CloseProgressBar(dicData == null && showReload == true ? ShowReLoadMode.YES : ShowReLoadMode.NO);
+
+            HdlThreadLogic.Current.RunMain(() =>
+            {
+                //鍏抽棴鍒锋柊鐗规晥
+                listView?.EndHeaderRefreshing();
+            });
+            if (dicData == null)
+            {
+                //鏁版嵁寮傚父
+                return;
+            }
+            HdlThreadLogic.Current.RunMain(() =>
+            {
+                //鍒濆鍖栦腑閮ㄦ帶浠�
+                this.InitMiddleFrame(dicData);
+            });
+        }
+
+        /// <summary>
+        /// 鍒濆鍖栦腑閮ㄦ帶浠�
+        /// </summary>
+        /// <param name="dicData"></param>
+        private void InitMiddleFrame(Dictionary<string, List<MessageRecordInfo>> dicData)
+        {
+            //娓呯┖
+            listView.RemoveAll();
+
+            int index = 0;
+            foreach (var keys in dicData.Keys)
+            {
+                var listData = dicData[keys];
+                index++;
+                //瀹瑰櫒
+                var framBack = new FrameListControl(23);
+                framBack.Name = index.ToString();
+                framBack.Height = Application.GetRealHeight(100);
+                framBack.BackgroundColor = UserCenterColor.Current.White;
+                listView.AddChidrenFrame(framBack);
+
+                //鏃ユ湡
+                string strMonth = Language.StringByID(R.MyInternationalizationString.Month);
+                string strDate = Language.StringByID(R.MyInternationalizationString.Day);
+                var frameDate = new FrameLayout();
+                frameDate.Height = Application.GetRealHeight(118);
+                framBack.AddChidren(frameDate);
+                var btnDate = new NormalViewControl(500, 60, true);
+                btnDate.TextSize = 15;
+                btnDate.X = ControlCommonResourse.XXLeft;
+                btnDate.Y = Application.GetRealHeight(35);
+                btnDate.Text = Convert.ToDateTime(listData[0].MsgTime).ToString("MM" + strMonth + "dd" + strDate);
+                frameDate.AddChidren(btnDate);
+
+                for (int i = 0; i < listData.Count; i++)
+                {
+                    //娣诲姞淇℃伅琛�
+                    this.AddMsgRowControl(framBack, listData[i], i != listData.Count - 1);
+                }
+                //璋冩暣楂樺害
+                listView.AdjustChidrenFrameHeight(framBack, Application.GetRealHeight(23));
+                if (index == dicData.Count)
+                {
+                    listView.AdjustTableHeight();
+                }
+            }
+        }
+
+        #endregion
+
+        #region 鈻� 鍙充笂瑙掕彍鍗昣________________________
+
+        /// <summary>
+        /// 鍒濆鍖栧彸涓婅鑿滃崟
+        /// </summary>
+        private void InitTopRightMenu()
+        {
+            var btnIcon = new MostRightIconControl(69, 69);
+            btnIcon.UnSelectedImagePath = "Item/More.png";
+            topFrameLayout.AddChidren(btnIcon);
+            btnIcon.InitControl();
+            btnIcon.ButtonClickEvent += ((sender, e) =>
+            {
+                //鏄剧ず搴曢儴鑿滃崟鐣岄潰
+                this.ShowBottomMenu();
+            });
+        }
+
+        /// <summary>
+        /// 鏄剧ず搴曢儴鑿滃崟鐣岄潰
+        /// </summary>
+        private void ShowBottomMenu()
+        {
+            var menuContr = new BottomMenuSelectForm();
+            menuContr.AddForm(2);
+            //鍏ㄩ儴宸茶
+            menuContr.AddMenu(Language.StringByID(R.MyInternationalizationString.uAllRead), () =>
+            {
+                //璁剧疆鍏ㄩ儴涓哄凡璇�
+                this.SetAllTickIsRead();
+            });
+            //鍏ㄩ儴鍒犻櫎
+            menuContr.AddMenu(Language.StringByID(R.MyInternationalizationString.uAllDelete), () =>
+            {
+                //鍒犻櫎鍏ㄩ儴鐨勬秷鎭�
+                this.DeleteAllMsg();
+            });
+        }
+
+        #endregion
+
+        #region 鈻� 娣诲姞淇℃伅琛宊________________________
+
+        /// <summary>
+        /// 娣诲姞淇℃伅琛�
+        /// </summary>
+        /// <param name="frameList"></param>
+        /// <param name="recordInfo"></param>
+        /// <param name="addLine"></param>
+        private void AddMsgRowControl(FrameListControl frameList, MessageRecordInfo recordInfo, bool addLine)
+        {
+            var rowControl = new RowLayoutControl(frameList.rowSpace / 2);
+            frameList.AddChidren(rowControl);
+            rowControl.Name = frameList.ChildrenCount.ToString();
+            rowControl.MainKeys = recordInfo.Id;
+            this.dicAllRow[frameList.Name + "-" + rowControl.Name] = rowControl;
+
+            //鍥炬爣(鐜板湪娴嬭瘯)
+            var btnIcon = rowControl.frameTable.AddLeftIcon(81);
+            btnIcon.UnSelectedImagePath = "Item/Safety.png";
+
+            //娑堟伅绫诲瀷
+            var btnMsgObject = rowControl.frameTable.AddLeftCaption("鎶ヨ娑堟伅", 600);
+            PicViewControl btnNewTip = null;
+            if (recordInfo.IsRead == 0)
+            {
+                btnNewTip = new PicViewControl(78, 55);
+                btnNewTip.UnSelectedImagePath = "Item/NewVersion.png";
+                btnNewTip.Y = Application.GetRealHeight(9) + rowControl.frameTable.chidrenYaxis;
+                btnNewTip.X = btnMsgObject.X + btnMsgObject.GetRealWidthByText(14);
+                rowControl.frameTable.AddChidren(btnNewTip, ChidrenBindMode.BindEventOnly);
+            }
+
+            //娑堟伅
+            var btnMsg = rowControl.frameTable.AddMostRightView(recordInfo.MsgContent, 600, 60);
+            btnMsg.TextColor = UserCenterColor.Current.TextGrayColor3;
+            btnMsg.Y = Application.GetRealHeight(5) + rowControl.frameTable.chidrenYaxis;
+            rowControl.frameTable.AddChidren(btnMsg, ChidrenBindMode.BindEventOnly);
+            //鏃堕棿
+            var btnTime = rowControl.frameTable.AddMostRightView(recordInfo.MsgContent, 200, 50);
+            btnTime.TextColor = UserCenterColor.Current.TextGrayColor1;
+            btnTime.Y = btnMsg.Bottom + Application.GetRealHeight(12);
+            btnTime.Text = Convert.ToDateTime(recordInfo.MsgTime).ToString("HH锛歮m");
+            rowControl.frameTable.AddChidren(btnTime, ChidrenBindMode.BindEventOnly);
+            //搴曠嚎
+            if (addLine == true)
+            {
+                rowControl.frameTable.AddBottomLine();
+            }
+            //宸茶
+            if (recordInfo.IsRead == 1)
+            {
+                rowControl.frameTable.UseClickStatu = false;
+                //娑堟伅绫诲瀷
+                btnMsgObject.TextColor = UserCenterColor.Current.TextGrayColor1;
+                //娑堟伅
+                btnMsg.TextColor = UserCenterColor.Current.TextGrayColor1;
+            }
+            //鍒犻櫎
+            var btnDelete = rowControl.AddDeleteControl();
+            btnDelete.ButtonClickEvent += (sender, e) =>
+            {
+                //纭鍒犻櫎娑堟伅?
+                string msg = Language.StringByID(R.MyInternationalizationString.uDeleteMessageMsg);
+                this.ShowMassage(ShowMsgType.Confirm, msg, async () =>
+                {
+                    await this.DeleteMsg(recordInfo.Id, frameList, rowControl);
+                });
+            };
+
+            //鐐瑰嚮
+            rowControl.frameTable.ButtonClickEvent += async (sender, e) =>
+            {
+                if (recordInfo.IsRead == 1)
+                {
+                    return;
+                }
+                recordInfo.IsRead = 1;
+                rowControl.frameTable.UseClickStatu = false;
+                //娑堟伅绫诲瀷
+                btnMsgObject.TextColor = UserCenterColor.Current.TextGrayColor1;
+                //娑堟伅
+                btnMsg.TextColor = UserCenterColor.Current.TextGrayColor1;
+                btnNewTip.RemoveFromParent();
+                if (sender != null)
+                {
+                    //鏍囪宸茶(涓嶇瀹冩垚鍔熶笉鎴愬姛)
+                    await this.SetTickIsRead(recordInfo.Id);
+                }
+            };
+        }
+
+        #endregion
+
+        #region 鈻� 鏍囪宸茶___________________________
+
+        /// <summary>
+        /// 鏍囪宸茶
+        /// </summary>
+        /// <param name="strId"></param>
+        private async System.Threading.Tasks.Task<bool> SetTickIsRead(string strId)
+        {
+            string strUrl = "ZigbeeUsers/TickIsRead?Id=" + strId;
+
+            var result = await Common.CommonPage.Instance.RequestHttpsZigbeeBytesResultAsync(strUrl, null, "GET");
+            if (result == null)
+            {
+                return UserCenterLogic.CheckNotEorrorMsg(null, "ZigbeeUsers/TickIsRead", null, null);
+            }
+            //浜戠鏄笉浼氳繑鍥炰笢瑗跨殑
+            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
+
+        #region 鈻� 鍒犻櫎淇℃伅___________________________
+
+        /// <summary>
+        /// 鍒犻櫎淇℃伅
+        /// </summary>
+        /// <param name="strId"></param>
+        /// <param name="frameList"></param>
+        /// <param name="rowContr"></param>
+        private async System.Threading.Tasks.Task<bool> DeleteMsg(string strId, FrameListControl frameList, RowLayoutControl rowContr)
+        {
+            string strUrl = "ZigbeeUsers/DeletePushMessage?Id=" + strId;
+
+            var result = await Common.CommonPage.Instance.RequestHttpsZigbeeBytesResultAsync(strUrl, null, "GET");
+            if (result == null)
+            {
+                return UserCenterLogic.CheckNotEorrorMsg(null, "ZigbeeUsers/DeletePushMessage", null, null);
+            }
+            //浜戠鏄笉浼氳繑鍥炰笢瑗跨殑
+            if (frameList != null)
+            {
+                HdlThreadLogic.Current.RunMain(() =>
+                {
+                    //绉婚櫎缂撳瓨
+                    this.dicAllRow.Remove(frameList.Name + "-" + rowContr.Name);
+                    //璋冩暣鎺т欢浣嶇疆
+                    this.AdjustControlLocation(frameList, rowContr);
+                });
+            }
+            return true;
+        }
+
+        /// <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.InitMiddleData(true);
+                });
+            });
+        }
+
+        #endregion
+
+        #region 鈻� 璋冩暣鎺т欢浣嶇疆_______________________
+
+        /// <summary>
+        /// 璋冩暣鎺т欢浣嶇疆
+        /// </summary>
+        /// <param name="frameList"></param>
+        private void AdjustControlLocation(FrameListControl frameList, RowLayoutControl removeRow)
+        {
+            int changedHeight = frameList.GetChildren(frameList.ChildrenCount - 1).Height;
+            if (frameList.ChildrenCount <= 2)
+            {
+                //宸茬粡鍒犲畬浜�,鍙墿涓嬫爣棰樻棩鏈熶簡
+                changedHeight = frameList.Height;
+            }
+            //鍏堣皟鏁村悇鑷鍣ㄧ殑Y杞村潗鏍�
+            bool canChangedLoaction = false;
+            for (int i = 0; i < this.listView.frameTable.ChildrenCount; i++)
+            {
+                var myView = this.listView.frameTable.GetChildren(i);
+                if (myView.Name == frameList.Name)
+                {
+                    //瀹冧箣鍚庣殑鎺т欢鍏ㄩ儴寰�涓婄Щ鍔�
+                    canChangedLoaction = true;
+                    continue;
+                }
+                if (canChangedLoaction == true)
+                {
+                    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;
+            }
+        }
+
+        #endregion
+
+        #region 鈻� 鑾峰彇鏁版嵁___________________________
+
+        /// <summary>
+        /// 鑾峰彇娑堟伅璁板綍
+        /// </summary>
+        /// <returns></returns>
+        private async System.Threading.Tasks.Task<Dictionary<string, List<MessageRecordInfo>>> GetMessageData()
+        {
+            this.dicAllRow = new Dictionary<string, RowLayoutControl>();
+
+            var result = await UserCenterLogic.GetResponseDataByRequestHttps("ZigbeeUsers/GetPushMessageRecord", false, "");
+            if (result == null)
+            {
+                return null;
+            }
+            var dataInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<List<MessageRecordInfo>>(result);
+            //鍚堝苟鏁版嵁
+            return this.MergeMessageRecordData(dataInfo);
+        }
+
+        /// <summary>
+        /// 鍚堝苟鏁版嵁
+        /// </summary>
+        /// <param name="dataInfo"></param>
+        /// <returns></returns>
+        private Dictionary<string, List<MessageRecordInfo>> MergeMessageRecordData(List<MessageRecordInfo> dataInfo)
+        {
+            var dicData = new Dictionary<string, List<MessageRecordInfo>>();
+
+            //棣栧厛鍏堟帓搴忎竴涓�,鏃堕棿澶х殑鏀惧湪鍓嶉潰
+            var dicTemp = new Dictionary<string, List<MessageRecordInfo>>();
+            var listSortKeys = new List<string>();
+            foreach (var data in dataInfo)
+            {
+                if (dicTemp.ContainsKey(data.MsgTime) == false)
+                {
+                    dicTemp[data.MsgTime] = new List<MessageRecordInfo>();
+                    listSortKeys.Add(data.MsgTime);
+                }
+                dicTemp[data.MsgTime].Add(data);
+            }
+            listSortKeys.Sort();
+            for (int i = listSortKeys.Count - 1; i >= 0; i--)
+            {
+                var listData = dicTemp[listSortKeys[i]];
+                foreach (var data2 in listData)
+                {
+                    string[] myArry = data2.MsgTime.Split(new string[] { "T" }, StringSplitOptions.RemoveEmptyEntries);
+                    if (myArry.Length != 2)
+                    {
+                        continue;
+                    }
+                    if (dicData.ContainsKey(myArry[0]) == false)
+                    {
+                        dicData[myArry[0]] = new List<MessageRecordInfo>();
+                    }
+                    dicData[myArry[0]].Add(data2);
+                }
+            }
+            return dicData;
+        }
+
+        #endregion
+    }
+}

--
Gitblit v1.8.0