From 3dcbd186c42c598c0c08d1cd37034cf2baa09e54 Mon Sep 17 00:00:00 2001
From: 黄学彪 <hxb@hdlchina.com.cn>
Date: 星期一, 30 十二月 2019 15:47:51 +0800
Subject: [PATCH] 合并了代码

---
 ZigbeeApp/Shared/Phone/UserCenter/Device/DoorLock/DoorLockHistoryLogForm.cs |  253 +++++++++++++++++++++++++++++++++++---------------
 1 files changed, 178 insertions(+), 75 deletions(-)

diff --git a/ZigbeeApp/Shared/Phone/UserCenter/Device/DoorLock/DoorLockHistoryLogForm.cs b/ZigbeeApp/Shared/Phone/UserCenter/Device/DoorLock/DoorLockHistoryLogForm.cs
index 8b5ba3c..582d120 100755
--- a/ZigbeeApp/Shared/Phone/UserCenter/Device/DoorLock/DoorLockHistoryLogForm.cs
+++ b/ZigbeeApp/Shared/Phone/UserCenter/Device/DoorLock/DoorLockHistoryLogForm.cs
@@ -2,6 +2,7 @@
 using System.Collections.Generic;
 using System.Text;
 using System.Threading.Tasks;
+using ZigBee.Device;
 
 namespace Shared.Phone.UserCenter.DeviceDoorLock
 {
@@ -15,7 +16,7 @@
         /// <summary>
         /// 鍒楄〃鎺т欢
         /// </summary>
-        private VerticalListControl listView = null;
+        private VerticalFrameRefreshControl listView = null;
         /// <summary>
         /// 鏃ユ湡From鎺т欢
         /// </summary>
@@ -29,9 +30,9 @@
         /// </summary>
         private List<MemberInfoRes> listMenberInfo = null;
         /// <summary>
-        /// 璁惧鐨凪ac鍦板潃
+        /// 璁惧瀵硅薄
         /// </summary>
-        private string DeviceMac = string.Empty;
+        private CommonDevice DeviceDoor = null;
         /// <summary>
         /// 妫�绱㈠璞$殑ID(-1:鎵�鏈� 绌哄瓧绗︿覆:鍏朵粬)
         /// </summary>
@@ -40,6 +41,10 @@
         /// 妫�绱㈠紑閿佹柟寮忕殑ID(-1:鎵�鏈� 0:瀵嗙爜 15:鎸囩汗 3:IC鍗�)
         /// </summary>
         private List<int> listSearchLockId = new List<int>() { -1 };
+        /// <summary>
+        /// 鍏朵粬娑堟伅鐨勪富閿�
+        /// </summary>
+        private List<string> listOtherId = new List<string>();
 
         #endregion
 
@@ -50,8 +55,8 @@
         /// </summary>
         /// <param name="i_DeviceMac">闂ㄩ攣鐨凪ac鍦板潃</param>
         public void ShowForm(string i_DeviceMac)
-        {
-            this.DeviceMac = i_DeviceMac;
+        {
+            this.DeviceDoor = Common.LocalDevice.Current.GetDevicesByMac(i_DeviceMac, false)[0];
 
             //璁剧疆澶撮儴淇℃伅
             base.SetTitleText(Language.StringByID(R.MyInternationalizationString.uHistoryLog));
@@ -63,11 +68,11 @@
             btnDelete.InitControl();
             btnDelete.ButtonClickEvent += (sender, e) =>
             {
-                var form = new TopRightMenuControl(1, 449);
+                var form = new TopRightMenuControl(1, 2);
                 //娓呯┖璁板綍
                 form.AddRowMenu(Language.StringByID(R.MyInternationalizationString.uClearLog), "Item/DeleteIcon2.png", "Item/DeleteIcon2Selected.png", () =>
                 {
-                    if (this.listView.ChildrenCount == 0)
+                    if (this.listView.frameTable.ChildrenCount == 0)
                     {
                         //鏃犳暟鎹彲鍒�
                         return;
@@ -94,15 +99,10 @@
             this.ClearBodyFrame();
 
             //鍒濆鍖栧ご閮ㄦ绱㈡帶浠�
-            this.InitTitleSearchControl();
-
-            //涓荤嚎绋嬬殑寮傛浼氶樆濉炰富绾跨▼,瀵艰嚧鐣岄潰鏈夋鏃堕棿浼氱櫧灞�,鎵�浠ヨ繖鏍峰瓙璁╃晫闈㈠厛鍑烘潵
-            //鐒跺悗鍐嶅埛鏂版暟鎹�
-            HdlThreadLogic.Current.RunMainInThread(() =>
-            {
-                //鍒濆鍖栬褰曞垪琛�
-                this.InitLogListInfo();
-            });
+            this.InitTitleSearchControl();
+
+            //鍒濆鍖栬褰曞垪琛�
+            this.InitLogListInfo();
         }
 
         /// <summary>
@@ -173,11 +173,16 @@
             //搴曠嚎
             frameTitle.AddBottomLine();
 
-            this.listView = new VerticalListControl(29);
+            this.listView = new VerticalFrameRefreshControl(29);
             listView.Y = frameTitle.Bottom - Application.GetRealHeight(3);
-            listView.BackgroundColor = UserCenterColor.Current.White;
             listView.Height = bodyFrameLayout.Height - frameTitle.Bottom + Application.GetRealHeight(3);
             bodyFrameLayout.AddChidren(listView);
+            listView.frameTable.BackgroundColor = UserCenterColor.Current.White;
+            listView.BeginHeaderRefreshingAction += () =>
+            {
+                //涓嬫媺鍒锋柊
+                this.InitLogListInfo();
+            };
         }
 
         #endregion
@@ -187,10 +192,10 @@
         /// <summary>
         /// 鍒濆鍖栬褰曞垪琛�
         /// </summary>
-        private async void InitLogListInfo()
+        private void InitLogListInfo()
         {
-            this.listView.RemoveAll();
-            listView.Height = bodyFrameLayout.Height - Application.GetRealHeight(115 - 3);
+            this.listView.frameTable.RemoveAll();
+            listView.frameTable.Height = bodyFrameLayout.Height - Application.GetRealHeight(115 - 3);
 
             //濡傛灉From>To鐨勬椂鍊欙紝涓嶉笩瀹�
             if (Convert.ToInt32(dateFromControl.dateValue) > Convert.ToInt32(dateToControl.dateValue))
@@ -199,51 +204,52 @@
                 this.ShowMassage(ShowMsgType.Tip, Language.StringByID(R.MyInternationalizationString.uFromTimeIsOverToTime));
                 return;
             }
-            //鎵撳紑杩涘害鏉�
-            this.ShowProgressBar();
-            //鎴愬憳鍒楄〃
-            var result = await this.GetMemberListInfo();
-            if (result == false)
+            HdlThreadLogic.Current.RunThread(async () =>
             {
+                //鎵撳紑杩涘害鏉�
+                this.ShowProgressBar();
+                //鎴愬憳鍒楄〃
+                var result = await this.GetMemberListInfo();
+                if (result == false)
+                {
+                    //鍏抽棴杩涘害鏉�
+                    this.CloseProgressBar(ShowReLoadMode.YES);
+                    return;
+                }
+                //鍘嗗彶璁板綍
+                var historyLog = await this.GetHistoryLogInfo();
+                if (historyLog == null)
+                {
+                    //鍏抽棴杩涘害鏉�
+                    this.CloseProgressBar(ShowReLoadMode.YES);
+                    return;
+                }
                 //鍏抽棴杩涘害鏉�
-                this.CloseProgressBar(ShowReLoadMode.YES);
-                return;
-            }
-            //鍘嗗彶璁板綍
-            var historyLog = await this.GetHistoryLogInf();
-            if (historyLog == null)
-            {
-                //鍏抽棴杩涘害鏉�
-                this.CloseProgressBar(ShowReLoadMode.YES);
-                return;
-            }
-            //鍏抽棴杩涘害鏉�
-            this.CloseProgressBar();
+                this.CloseProgressBar();
 
-            var dic = new Dictionary<string, string>();
-            for (int i = 0; i < listMenberInfo.Count; i++)
-            {
-                dic.Add(listMenberInfo[i].SubAccountDistributedMark, string.IsNullOrEmpty(listMenberInfo[i].UserName) == false ? listMenberInfo[i].UserName : listMenberInfo[i].Account);
-            }
-            for (int i = 0; i < historyLog.Count; i++)
-            {
-                //娣诲姞璁板綍琛�
-                this.AddLogInfoRow(historyLog[i], dic, i != historyLog.Count - 1);
-            }
+                var dic = new Dictionary<string, string>();
+                for (int i = 0; i < listMenberInfo.Count; i++)
+                {
+                    dic.Add(listMenberInfo[i].SubAccountDistributedMark, string.IsNullOrEmpty(listMenberInfo[i].UserName) == false ? listMenberInfo[i].UserName : listMenberInfo[i].Account);
+                }
+                HdlThreadLogic.Current.RunMain(() =>
+                {
+                    for (int i = 0; i < historyLog.Count; i++)
+                    {
+                        //娣诲姞璁板綍琛�
+                        this.AddLogInfoRow(historyLog[i], dic, i != historyLog.Count - 1);
+                    }
+                    //闅愯棌涓嬫媺鍒锋柊鐗规晥
+                    listView.EndHeaderRefreshing();
 
-            if (listView.ChildrenCount == 0)
-            {
-                return;
-            }
-
-            //璋冩暣鍒楄〃鎺т欢鐨勯珮搴�
-            var realHeight = listView.ChildrenCount * listView.GetChildren(0).Height;
-            realHeight += Application.GetRealHeight(23 + 3);
-            if (realHeight < listView.Height)
-            {
-                //缂╁皬鎺т欢楂樺害
-                listView.Height = realHeight;
-            }
+                    if (listView.frameTable.ChildrenCount == 0)
+                    {
+                        return;
+                    }
+                    //璋冩暣鍒楄〃鎺т欢鐨勯珮搴�
+                    listView.AdjustTableHeight(Application.GetRealHeight(23));
+                });
+            });
         }
 
         /// <summary>
@@ -306,10 +312,23 @@
         {
             var frameTable = new FrameRowControl(listView.rowSpace / 2);
             frameTable.UseClickStatu = false;
-            this.listView.AddChidren(frameTable);
+            this.listView.AddChidrenFrame2(frameTable);
             //鍥炬爣
             var btnIcon = frameTable.AddLeftIcon();
-            if (historyInfo.UnlockIsSuccess == true)
+            if (historyInfo.OpenLockMode == -1)
+            {
+                //鍏朵粬娑堟伅
+                var device = Common.LocalDevice.Current.GetDevice(historyInfo.DeviceMac, historyInfo.DeviceEpoint);
+                if (device == null)
+                {
+                    btnIcon.UnSelectedImagePath = "Device/IntelligentLocks.png";
+                }
+                else
+                {
+                    Common.LocalDevice.Current.SetDeviceIconToControl(btnIcon, device);
+                }
+            }
+            else if (historyInfo.UnlockIsSuccess == true)
             {
                 btnIcon.UnSelectedImagePath = "Item/UnLockSuccess.png";
             }
@@ -324,7 +343,12 @@
             //杩欎釜鍧愭爣鏈夌偣鐗规畩
             btnMsg.Y = Application.GetRealHeight(12) + frameTable.chidrenYaxis;
             frameTable.AddChidren(btnMsg, ChidrenBindMode.NotBind);
-            if (historyInfo.UnlockIsSuccess == true)
+            if (historyInfo.OpenLockMode == -1)
+            {
+                //鍏朵粬娑堟伅
+                btnMsg.Text = historyInfo.AlarmMsg;
+            }
+            else if (historyInfo.UnlockIsSuccess == true)
             {
                 if (historyInfo.OpenLockMode == 0)
                 {
@@ -371,7 +395,7 @@
             frameTable.AddChidren(btnpersion, ChidrenBindMode.NotBind);
 
             //鏃堕棿
-            frameTable.AddMostRightView(historyInfo.UnlockTime, 400);
+            frameTable.AddMostRightView(Convert.ToDateTime(historyInfo.UnlockTime).ToString("HH:mm:ss"), 400);
             if (addLine == true)
             {
                 //搴曠嚎
@@ -415,7 +439,7 @@
         /// 鑾峰彇鍘嗗彶璁板綍
         /// </summary>
         /// <returns></returns>
-        private async Task<List<HistoryInfo>> GetHistoryLogInf()
+        private async Task<List<HistoryInfo>> GetHistoryLogInfo()
         {
             //鑾峰彇璁块棶浜戠鎺ュ彛鐨勫惎鍔ㄥ弬鏁�
             var pra = this.GetDbInterfacePra();
@@ -431,6 +455,7 @@
                     return null;
                 }
                 var dataInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<GetHistoryDataResult>(result);
+                listLog.AddRange(dataInfo.PageData);
                 if (dataInfo.HasNextPage == false)
                 {
                     break;
@@ -443,8 +468,45 @@
             //鎺掑簭涓�涓�
             var dic = new Dictionary<string, List<HistoryInfo>>();
             var listSort = new List<string>();
+            //娓呯┖涓婁竴娆$殑鍏朵粬ID
+            this.listOtherId = new List<string>();
             //鏄惁鍖呭惈鍏朵粬
             bool flage = this.listSearchUserId.Contains("") || this.listSearchUserId.Contains("-1");
+            if (flage == true)
+            {
+                //鍘昏幏鍙栧叾浠栦俊鎭�
+                var pra2 = new MessageInfoPra();
+                pra2.Topic = "/Alarms/SendAlarmInform";
+                pra2.LoginAccessToken = UserCenterLogic.GetConnectMainToken();
+                var result = await UserCenterLogic.GetResponseDataByRequestHttps("MessageCenter/GetMessageCenterPagger", true, pra2);
+                if (result == null)
+                {
+                    return null;
+                }
+                var dataInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<MessageCentetInfo>(result);
+                foreach (var myInfo in dataInfo.PageData)
+                {
+                    var data = new HistoryInfo();
+                    if (dic.ContainsKey(myInfo.CreatedOnUtc) == false)
+                    {
+                        dic[myInfo.CreatedOnUtc] = new List<HistoryInfo>();
+                        listSort.Add(myInfo.CreatedOnUtc);
+                    }
+                  
+                    //璁惧瀵硅薄
+                    var jobject = Newtonsoft.Json.Linq.JObject.Parse(myInfo.PayloadJson);
+                    data.DeviceMac = jobject.Value<string>("DeviceAddr");
+                    data.DeviceEpoint = jobject.Value<int>("Epoint");
+                    //娑堟伅
+                    var msgInfo = HdlAlarmsLogic.Current.GetDoorLockAlarmInfo(jobject);
+                    data.AlarmMsg = msgInfo != null ? msgInfo.AlarmMsg : Language.StringByID(R.MyInternationalizationString.uDoorLocksAlarmHadTriggered);
+                    dic[myInfo.CreatedOnUtc].Add(data);
+                    //鏃堕棿
+                    data.UnlockTime = myInfo.CreatedOnUtc;
+
+                    this.listOtherId.Add(myInfo.Id);
+                }
+            }
             foreach (var data in listLog)
             {
                 if (flage == false && string.IsNullOrEmpty(data.CloudAccountId) == true)
@@ -485,14 +547,37 @@
             //鎵撳紑杩涘害鏉�
             this.ShowProgressBar();
             var result = await UserCenterLogic.GetResultStatuByRequestHttps("DoorLock/ClearDoorLockHistory", true, pra);
+            if (result == false)
+            {
+                return;
+            }
+
+            //鍒犻櫎鍏朵粬娑堟伅
+            if (listOtherId.Count > 0)
+            {
+                var pra2 = new MessageReadStatuPra();
+                pra2.LoginAccessToken = UserCenterLogic.GetConnectMainToken();
+                for (int i = 0; i < listOtherId.Count; i++)
+                {
+                    pra2.Id = listOtherId[i];
+                    result = await UserCenterLogic.GetResultStatuByRequestHttps("MessageCenter/DelMessageCenterItem", true, pra);
+                    if (result == false)
+                    {
+                        return;
+                    }
+                }
+            }
             //鍏抽棴杩涘害鏉�
             this.CloseProgressBar();
             if (result == false)
             {
                 return;
             }
-            this.listView.RemoveAll();
-            listView.Height = bodyFrameLayout.Height - Application.GetRealHeight(115 - 3);
+            this.listView.frameTable.RemoveAll();
+            listView.frameTable.Height = bodyFrameLayout.Height - Application.GetRealHeight(115 - 3);
+
+            //娓呯┖
+            this.listOtherId = new List<string>();
         }
 
         #endregion
@@ -510,7 +595,13 @@
 
             //鍏ㄩ�夊垯涓簄ull
             List<string> listUser = null;
-            if (listSearchUserId.Contains("-1") == false)
+            if (listSearchUserId.Count == 1 && listSearchUserId[0] == "")
+            {
+                //濡傛灉鍗曠函鐨勫彧鏄�夋嫨鍏朵粬,鍒欒妫�绱㈡潯浠朵笉鎴愮珛鍗冲彲
+                listUser = new List<string>();
+                listUser.Add("鍏朵粬");
+            }
+            else if (listSearchUserId.Contains("-1") == false)
             {
                 listUser = new List<string>();
                 listUser.AddRange(listSearchUserId);
@@ -528,11 +619,11 @@
 
             var pra = new GetHistoryDataPra();
             pra.LoginAccessToken = UserCenterLogic.GetConnectMainToken();
-            pra.DoorLockId = this.DeviceMac;
+            pra.DoorLockId = this.DeviceDoor.DeviceAddr + "_" + this.DeviceDoor.DeviceEpoint;
             pra.CloudAccountIdArr = listUser;
             pra.OpenLockModeArr = listLock;
-            pra.UnlockTimeBegin = dateFrom;
-            pra.UnlockTimeEnd = dateTo;
+            pra.UnlockTimeBegin = dateFrom.ToString();
+            pra.UnlockTimeEnd = dateTo.ToString();
             return pra;
         }
 
@@ -576,11 +667,11 @@
             /// <summary>
             /// 鎼滅储寮�閿佸紑濮嬫椂闂�
             /// </summary>
-            public DateTime UnlockTimeBegin;
+            public string UnlockTimeBegin;
             /// <summary>
             /// 鎼滅储寮�閿佺粨鏉熸椂闂�
             /// </summary>
-            public DateTime UnlockTimeEnd;
+            public string UnlockTimeEnd;
             /// <summary>
             /// 椤垫暟
             /// </summary>
@@ -623,6 +714,18 @@
             /// 璐﹀彿鐨処D
             /// </summary>
             public string CloudAccountId = string.Empty;
+            /// <summary>
+            /// 褰撳紑閿佹柟寮忎负-1鏃朵娇鐢�,瀹冨睘浜庡叾浠栫被
+            /// </summary>
+            public string AlarmMsg = string.Empty;
+            /// <summary>
+            /// 褰撳紑閿佹柟寮忎负-1鏃朵娇鐢�,璁惧Mac
+            /// </summary>
+            public string DeviceMac = string.Empty;
+            /// <summary>
+            /// 褰撳紑閿佹柟寮忎负-1鏃朵娇鐢�,璁惧绔偣
+            /// </summary>
+            public int DeviceEpoint = 0;
         }
 
         #endregion

--
Gitblit v1.8.0