HDL Home App 第二版本 旧平台金堂用 正在使用
黄学彪
2019-12-30 3dcbd186c42c598c0c08d1cd37034cf2baa09e54
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>
        /// 设备的Mac地址
        /// 设备对象
        /// </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">门锁的Mac地址</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 @@
            //全选则为null
            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 @@
            /// 账号的ID
            /// </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