From d6fb0646531172f23648441c224cdcccd721b894 Mon Sep 17 00:00:00 2001
From: xm <1271024303@qq.com>
Date: 星期一, 14 十二月 2020 09:59:01 +0800
Subject: [PATCH] 请合并代码,完成晾衣架最终功能。

---
 ZigbeeApp/Shared/Phone/UserCenter/Safety/SafetyManagementMainForm.cs |  802 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 802 insertions(+), 0 deletions(-)

diff --git a/ZigbeeApp/Shared/Phone/UserCenter/Safety/SafetyManagementMainForm.cs b/ZigbeeApp/Shared/Phone/UserCenter/Safety/SafetyManagementMainForm.cs
new file mode 100755
index 0000000..ea700d3
--- /dev/null
+++ b/ZigbeeApp/Shared/Phone/UserCenter/Safety/SafetyManagementMainForm.cs
@@ -0,0 +1,802 @@
+锘縰sing System;
+using System.Collections.Generic;
+using System.Threading.Tasks;
+using ZigBee.Device;
+
+namespace Shared.Phone.UserCenter.Safety
+{
+    /// <summary>
+    /// 瀹夐槻绠$悊鐨勪富鐣岄潰鈽�
+    /// </summary>
+    public class SafetyManagementMainForm : EditorCommonForm
+    {
+        #region 鈻� 鍙橀噺澹版槑___________________________
+
+        /// <summary>
+        /// 妗屽竷鎺т欢锛岀敤浜庡瓨鏀炬垨鑰呯Щ闄ゅ姛鑳藉潡鎺т欢(Tab鎺т欢涓撶敤)
+        /// </summary>
+        private NormalFrameLayout frameLayoutDraw = null;
+        /// <summary>
+        /// 瀹夐槻鎺т欢
+        /// </summary>
+        private SafetyMasterControl garrisonControl = null;
+        /// <summary>
+        /// Tab鐨勯�夋嫨銆�1锛氬畨闃茶褰昑ab  2锛氫紶鎰熷櫒鐘舵�乀ab
+        /// </summary>
+        private int TabSelectIndex = 2;
+        /// <summary>
+        /// 鍦ㄧ嚎鐘舵�佺殑閿�
+        /// </summary>
+        private object objOnlineLock = new object();
+
+        #endregion
+
+        #region 鈻� 鍒濆鍖朹____________________________
+
+        /// <summary>
+        /// 鐢婚潰鏄剧ず(搴曞眰浼氬浐瀹氳皟鐢ㄦ鏂规硶锛屽�熶互瀹屾垚鐢婚潰鍒涘缓)
+        /// </summary>
+        public void ShowForm()
+        {
+            //璁剧疆澶撮儴淇℃伅
+            base.SetTitleText(Language.StringByID(R.MyInternationalizationString.SafetyManagement));
+
+            //鍒濆鍖栦腑閮ㄤ俊鎭�
+            this.InitMiddleFrame();
+        }
+
+        /// <summary>
+        /// 鍒濆鍖栦腑閮ㄤ俊鎭�
+        /// </summary>
+        private void InitMiddleFrame()
+        {
+            //娓呯┖bodyFrame
+            this.ClearBodyFrame();
+
+            //鍒濆鍖栧彸涓婅鍥炬爣
+            this.InitTopRightIcon();
+
+            //鍒濆鍖栧叏閮ㄥ唴瀛樹俊鎭�
+            this.InitAllMemoryData();
+        }
+
+        /// <summary>
+        /// 鍒濆鍖朤ab鎺т欢
+        /// </summary>
+        private void InitTabSwitchControl()
+        {
+            var frameBack = new FrameLayout();
+            frameBack.Height = Application.GetRealHeight(1300);
+            frameBack.Y = Application.GetRealHeight(444);
+            frameBack.BackgroundColor = 0xa1ffffff;
+            frameBack.SetCornerWithSameRadius(Application.GetRealHeight(58), HDLUtils.RectCornerTopLeft | HDLUtils.RectCornerTopRight);
+            bodyFrameLayout.AddChidren(frameBack);
+
+            //妗屽竷鎺т欢
+            frameLayoutDraw = new NormalFrameLayout();
+            frameLayoutDraw.Y = Application.GetRealHeight(181);
+            frameLayoutDraw.Height = frameBack.Height - Application.GetRealHeight(181);
+            frameBack.AddChidren(frameLayoutDraw);
+
+            //璁$畻瀹藉害浣跨敤
+            var btnTemp = new ButtonBase();
+            btnTemp.TextSize = 16;
+            btnTemp.IsBold = true;
+
+            btnTemp.TextID = R.MyInternationalizationString.uSecurityLog;
+            int frameLogWidth = btnTemp.GetRealWidthByText() + Application.GetRealWidth(30);
+
+            btnTemp.TextID = R.MyInternationalizationString.uSensorStatu;
+            int frameSensorWidth = btnTemp.GetRealWidthByText() + Application.GetRealWidth(30);
+
+            //瀹夐槻璁板綍(鐐瑰嚮鑼冨洿鏈夌偣灏忥紝闇�瑕佹墿澶у畠鐨勭偣鍑昏寖鍥�)
+            var frameLog = new FrameLayoutStatuControl();
+            frameLog.UseClickStatu = false;
+            frameLog.Height = Application.GetRealHeight(123);
+            frameLog.Width = frameLogWidth;
+            frameLog.X = (frameBack.Width - frameLogWidth - frameSensorWidth) / 2;
+            frameLog.Y = Application.GetRealHeight(58);
+            frameBack.AddChidren(frameLog);
+            //鏍囬
+            var btnLog = new NormalViewControl(100, 63, true);
+            btnLog.Width = frameLog.Width;
+            btnLog.TextAlignment = TextAlignment.Center;
+            btnLog.TextID = R.MyInternationalizationString.uSecurityLog;
+            btnLog.TextColor = UserCenterColor.Current.TextGrayColor3;
+            frameLog.AddChidren(btnLog, ChidrenBindMode.BindEvent);
+            //搴曠嚎
+            var btnLogLine = new NormalViewControl(40, 10, true);
+            btnLogLine.Y = Application.GetRealHeight(86);
+            //btnLogLine.X = btnLog.X + btnLog.Width / 2 - Application.GetRealWidth(40) / 2;
+            btnLogLine.Gravity = Gravity.CenterHorizontal;
+            btnLogLine.Radius = (uint)Application.GetRealHeight(10) / 2;
+            btnLogLine.BackgroundColor = UserCenterColor.Current.TextOrangeColor;
+            frameLog.AddChidren(btnLogLine, ChidrenBindMode.BindEvent);
+            btnLogLine.Visible = false;
+
+            //浼犳劅鍣ㄧ姸鎬�(鐐瑰嚮鑼冨洿鏈夌偣灏忥紝闇�瑕佹墿澶у畠鐨勭偣鍑昏寖鍥�)
+            var frameSensor = new FrameLayoutStatuControl();
+            frameSensor.UseClickStatu = false;
+            frameSensor.Height = frameLog.Height;
+            frameSensor.Width = frameSensorWidth;
+            frameSensor.X = frameLog.Right;
+            frameSensor.Y = frameLog.Y;
+            frameBack.AddChidren(frameSensor);
+            //鏍囬
+            var btnSensor = new NormalViewControl(100, 63, true);
+            btnSensor.Width = frameSensor.Width;
+            btnSensor.TextID = R.MyInternationalizationString.uSensorStatu;
+            btnSensor.TextSize = 16;
+            btnSensor.TextAlignment = TextAlignment.Center;
+            btnSensor.TextColor = UserCenterColor.Current.TextColor2;
+            btnSensor.IsBold = true;
+            frameSensor.AddChidren(btnSensor, ChidrenBindMode.BindEvent);
+            //搴曠嚎
+            var btnSensorLine = new NormalViewControl(40, 10, true);
+            btnSensorLine.BackgroundColor = UserCenterColor.Current.TextOrangeColor;
+            btnSensorLine.Y = btnLogLine.Y;
+            //btnSensorLine.X = btnSensor.X + btnSensor.Width / 2 - Application.GetRealWidth(40) / 2;
+            btnSensorLine.Gravity = Gravity.CenterHorizontal;
+            btnSensorLine.Radius = (uint)Application.GetRealHeight(10) / 2;
+            frameSensor.AddChidren(btnSensorLine, ChidrenBindMode.BindEvent);
+
+            //瀹夐槻璁板綍Tab
+            frameLog.ButtonClickEvent += (sender, e) =>
+            {
+                //瀛椾綋澶у皬鍜岄鑹插彉鏇�
+                btnSensor.TextColor = UserCenterColor.Current.TextGrayColor3;
+                btnSensor.TextSize = 14;
+                btnSensor.IsBold = false;
+                btnLog.TextColor = UserCenterColor.Current.TextColor2;
+                btnLog.TextSize = 16;
+                btnLog.IsBold = true;
+
+                btnLogLine.Visible = true;
+                btnSensorLine.Visible = false;
+
+                this.TabSelectIndex = 1;
+
+                //鏄剧ず瀹夐槻璁板綍
+                this.SetSafeguardLogToForm();
+            };
+
+            //浼犳劅鍣ㄧ姸鎬乀ab
+            frameSensor.ButtonClickEvent += (sender, e) =>
+            {
+                //瀛椾綋澶у皬鍜岄鑹插彉鏇�
+                btnSensor.TextColor = UserCenterColor.Current.TextColor2;
+                btnSensor.TextSize = 16;
+                btnSensor.IsBold = true;
+                btnLog.TextColor = UserCenterColor.Current.TextGrayColor3;
+                btnLog.TextSize = 14;
+                btnLog.IsBold = false;
+
+                btnLogLine.Visible = false;
+                btnSensorLine.Visible = true;
+
+                this.TabSelectIndex = 2;
+
+                //鏄剧ず浼犳劅鍣ㄥ垪琛�
+                this.SetSensorDataToForm();
+            };
+        }
+
+        /// <summary>
+        /// 鍒濆鍖栧彸涓婅鍥炬爣
+        /// </summary>
+        private void InitTopRightIcon()
+        {
+            //蹇嵎鏂瑰紡
+            var btnShortCut = new MostRightIconControl(69, 69);
+            btnShortCut.UnSelectedImagePath = "Safeguard/SafetyShortcut.png";
+            btnShortCut.SelectedImagePath = "Safeguard/SafetyShortcutSelected.png";
+
+            if (UserCenterResourse.UserInfo.AuthorityNo == 1 || UserCenterResourse.UserInfo.AuthorityNo == 2)
+            {
+                //蹇嵎鏂瑰紡鍚戝乏绉诲姩
+                btnShortCut.X = Application.GetRealWidth(855);
+
+                var btnIcon = new MostRightIconControl(69, 69);
+                btnIcon.UnSelectedImagePath = "Item/More.png";
+                topFrameLayout.AddChidren(btnIcon);
+                btnIcon.InitControl();
+                btnIcon.ButtonClickEvent += (sender, e) =>
+                {
+                    //鑿滃崟鎺т欢
+                    var frameMenu = new TopRightMenuControl(2, 2);
+                    //闃插尯鍒楄〃
+                    string menu1 = Language.StringByID(R.MyInternationalizationString.uGarrisonAreaList);
+                    frameMenu.AddRowMenu(menu1, "Item/GarrisonList.png", "Item/GarrisonListSelected.png", () =>
+                    {
+                        HdlCheckLogic.Current.CheckSecondarySecurity(() =>
+                        { 
+                            //楠岃瘉鎴愬姛
+                            var form = new GarrisonAreaListMenuForm();
+                            form.AddForm(); 
+                        }, 
+                        () =>
+                        {
+                            //璇峰墠寰�涓汉涓績{0}璁剧疆浜屾瀹夊叏楠岃瘉鏂瑰紡
+                            string msg = Language.StringByID(R.MyInternationalizationString.uGotoCenterAndSetSecondAuthentication).Replace("{0}", "\r\n");
+                            this.ShowMassage(ShowMsgType.Confirm, msg, () =>
+                            {
+                                var form = new UserMain.SecondAuthenticationForm();
+                                form.AddForm();
+                            });
+                        });
+                    });
+                    //瀵嗙爜璁剧疆
+                    string menu2 = Language.StringByID(R.MyInternationalizationString.uPasswordSettion);
+                    frameMenu.AddRowMenu(menu2, "Item/PswSettion.png", "Item/PswSettionSelected.png", () =>
+                    {
+                        HdlCheckLogic.Current.CheckSecondarySecurity(() =>
+                        {
+                            //楠岃瘉鎴愬姛
+                            var form = new PasswordMenuForm();
+                            form.AddForm();
+                        },
+                        () =>
+                        {
+                            //璇峰墠寰�涓汉涓績{0}璁剧疆浜屾瀹夊叏楠岃瘉鏂瑰紡
+                            string msg = Language.StringByID(R.MyInternationalizationString.uGotoCenterAndSetSecondAuthentication).Replace("{0}", "\r\n");
+                            this.ShowMassage(ShowMsgType.Confirm, msg, () =>
+                            {
+                                var form = new UserMain.SecondAuthenticationForm();
+                                form.AddForm();
+                            });
+                        });
+                    });
+                };
+            }
+
+            topFrameLayout.AddChidren(btnShortCut);
+            btnShortCut.InitControl();
+            if (UserCenterResourse.ResidenceOption.SafetyShortcut == true)
+            {
+                //浣跨敤蹇嵎鏂瑰紡
+                btnShortCut.IsSelected = true;
+            }
+            btnShortCut.ButtonClickEvent += (sender, e) =>
+            {
+                if (btnShortCut.IsSelected == true)
+                {
+                    //纭畾鍙栨秷涓婚〉鐨勩�屽畨闃层�嶆嵎寰勶紵
+                    this.ShowMassage(ShowMsgType.Confirm, Language.StringByID(R.MyInternationalizationString.uCancelSafetyShortcutMsg), () =>
+                    {
+                        UserCenterResourse.ResidenceOption.SafetyShortcut = false;
+                        UserCenterResourse.ResidenceOption.Save();
+                        btnShortCut.IsSelected = false;
+                        //鍙栨秷涓婚〉鐨勩�屽畨闃层�嶆嵎寰勭殑璇�,涓婚〉闇�瑕侀噸鏂板埛鏂�
+                        UserView.UserPage.Instance.RefreshAllForm = true;
+                    });
+                }
+                else
+                {
+                    //纭畾鍒涘缓銆屽畨闃层�嶆嵎寰勫埌涓婚〉锛�
+                    this.ShowMassage(ShowMsgType.Confirm, Language.StringByID(R.MyInternationalizationString.uCreatSafetyShortcutMsg), () =>
+                    {
+                        UserCenterResourse.ResidenceOption.SafetyShortcut = true;
+                        UserCenterResourse.ResidenceOption.Save();
+                        btnShortCut.IsSelected = true;
+                        //鍒涘缓涓婚〉鐨勩�屽畨闃层�嶆嵎寰勭殑璇�,涓婚〉闇�瑕侀噸鏂板埛鏂�
+                        UserView.UserPage.Instance.RefreshAllForm = true;
+                    });
+                }
+            };
+        }
+
+        #endregion
+
+        #region 鈻� 鍒濆鍖栧叏閮ㄧ紦瀛榑____________________
+
+        /// <summary>
+        /// 鍒濆鍖栧叏閮ㄥ唴瀛樹俊鎭�
+        /// </summary>
+        private async void InitAllMemoryData()
+        {
+            //寮�鍚繘搴︽潯
+            this.ShowProgressBar();
+
+            //姝e湪涓庣綉鍏抽�氳涓�,璇风◢鍚�
+            this.SetProgressValue(Language.StringByID(R.MyInternationalizationString.uConnectToGatewayPleaseWait));
+
+            //妫�娴嬩富缃戝叧
+            var result = await this.CheckMainGateway();
+            if (result == false)
+            {
+                //鍏抽棴杩涘害鏉�
+                this.CloseProgressBar(ShowReLoadMode.YES);
+                //缃戝叧鍥炲瓒呮椂,璇风◢鍚庡啀璇�
+                string msg = Language.StringByID(R.MyInternationalizationString.uGatewayResponseTimeOut);
+                this.ShowMassage(ShowMsgType.Tip, msg);
+
+                return;
+            }
+
+            //瀹夐槻淇℃伅鍒濆鍖栦腑,璇风◢鍚�
+            this.SetProgressValue(Language.StringByID(R.MyInternationalizationString.uGarrisonInfoInittingPleaseWait));
+
+            //鍒锋柊瀹夐槻淇℃伅
+            result = await HdlSafeguardLogic.Current.ReFreshByGateway();
+            if (result == false)
+            {
+                //鍏抽棴杩涘害鏉�
+                this.CloseProgressBar(ShowReLoadMode.YES);
+                return;
+            }
+            //鍏抽棴杩涘害鏉�
+            this.CloseProgressBar();
+
+            //鏁版嵁鍒濆鍖栧畬鎴愬悗
+            HdlThreadLogic.Current.RunMain(() =>
+            {
+                //鍒濆鍖栧ご閮ㄧ殑閭d笁涓浘鏍�
+                garrisonControl = new SafetyMasterControl();
+                garrisonControl.Y = Application.GetRealHeight(46);
+                bodyFrameLayout.AddChidren(garrisonControl);
+                garrisonControl.InitControl();
+                //鍒濆鍖朤ab鎺т欢
+                this.InitTabSwitchControl();
+
+                //璁剧疆浼犳劅鍣ㄦ暟鎹埌鐢婚潰
+                this.SetSensorDataToForm();
+            });
+        }
+
+        /// <summary>
+        /// 妫�娴嬩富缃戝叧
+        /// </summary>
+        /// <returns></returns>
+        private async Task<bool> CheckMainGateway()
+        {
+            int count = 0;
+            //绛夊緟涓荤綉鍏�
+            while (ZbGateway.MainGateWay == null)
+            {
+                await Task.Delay(500);
+                count++;
+                if (count == 10)
+                {
+                    return false;
+                }
+            }
+            return true;
+        }
+
+        #endregion
+
+        #region 鈻� 鐣岄潰鍏抽棴___________________________
+
+        /// <summary>
+        /// 鐢婚潰鍏抽棴
+        /// </summary>
+        public override void CloseFormBefore()
+        {
+            //绉婚櫎鍏ㄩ儴鐩戝惉浜嬩欢
+            this.RemoveAllListenEvent();
+
+            base.CloseFormBefore();
+        }
+
+        /// <summary>
+        /// 绉婚櫎鍏ㄩ儴鐩戝惉浜嬩欢
+        /// </summary>
+        private void RemoveAllListenEvent()
+        {
+            HdlGatewayReceiveLogic.Current.RemoveEvent("SafetyManagementMainFormAlarm");
+            HdlGatewayReceiveLogic.Current.RemoveEvent("SafetyManagementMainFormReceivePushOnline");
+        }
+
+        #endregion
+
+        #region 鈻� 浼犳劅鍣ㄧ浉鍏砡________________________
+
+        /// <summary>
+        /// 浼犳劅鍣ㄧ殑鐘舵�佹帶浠�
+        /// </summary>
+        private Dictionary<string, SafetySensorStatuControl> dicSensorStatuView = new Dictionary<string, SafetySensorStatuControl>();
+
+        #region 娣诲姞浼犳劅鍣ㄨ_
+
+        /// <summary>
+        /// 璁剧疆浼犳劅鍣ㄦ暟鎹埌鐢婚潰
+        /// </summary>
+        private void SetSensorDataToForm()
+        {
+            if (this.TabSelectIndex != 2)
+            {
+                return;
+            }
+            //绉婚櫎鍏ㄩ儴鐩戝惉浜嬩欢
+            this.RemoveAllListenEvent();
+
+            this.dicSensorStatuView.Clear();
+
+            //娣诲姞鍒楄〃鎺т欢 
+            frameLayoutDraw.RemoveAll();
+            var listView = new VerticalFrameControl(35);
+            listView.Height = frameLayoutDraw.Height;
+            frameLayoutDraw.AddChidren(listView);
+
+            HdlThreadLogic.Current.RunThread(() =>
+            {
+                //鑾峰彇瀹夐槻鐨勫叏閮ㄤ紶鎰熷櫒璁惧鐨勪俊鎭�
+                var dicDevice = HdlSafeguardLogic.Current.GetAllSensorDeviceInfo();
+                var listDevice = new List<CommonDevice>();
+
+                HdlThreadLogic.Current.RunMain(() =>
+                {
+                    foreach (var zoneId in dicDevice.Keys)
+                    {
+                        foreach (var Info in dicDevice[zoneId])
+                        {
+                            if (this.Parent == null)
+                            {
+                                return;
+                            }
+                            //娣诲姞琛�
+                            this.AddSensorStatuRow(listView, zoneId, Info);
+
+                            //鏀堕泦浼犳劅鍣�
+                            var tempDevice = Common.LocalDevice.Current.GetDevice(Info.MacAddr, Info.Epoint);
+                            if (tempDevice != null)
+                            {
+                                listDevice.Add(tempDevice);
+                            }
+                        }
+                    }
+                    //璋冩暣鍒楄〃鎺т欢楂樺害
+                    listView.AdjustChidrenFrameHeight(listView.frameTable, Application.GetRealHeight(46));
+                    //寮�鍚紶鎰熷櫒鎶ヨ鐩戣
+                    this.StartCheckDeviceAlarm();
+                    //寮�鍚澶囧湪绾跨洃娴�
+                    this.StartCheckDeviceOnline(listDevice);
+                });
+            });
+        }
+
+        /// <summary>
+        /// 娣诲姞浼犳劅鍣ㄧ姸鎬佺殑琛�
+        /// </summary>
+        /// <param name="listView"></param>
+        /// <param name="zoneID">闃插尯ID</param>
+        /// <param name="sensorInfo">浼犳劅鍣ㄧ殑淇℃伅</param>
+        private void AddSensorStatuRow(VerticalFrameControl listView, int zoneID, Safeguard.ZoneDeviceListData sensorInfo)
+        {
+            CommonDevice device = Common.LocalDevice.Current.GetDevice(sensorInfo.MacAddr, sensorInfo.Epoint);
+            if (device == null)
+            {
+                return;
+            }
+
+            //鑷畾涔変紶鎰熷櫒鐘舵�佹帶浠�
+            var frameDevice = new SafetySensorStatuControl();
+            listView.AddChidren(frameDevice);
+            frameDevice.InitControl(device);
+            //娣诲姞闃村奖鐗规晥
+            frameDevice.SetViewShadow(true);
+
+            string mainkeys = Common.LocalDevice.Current.GetDeviceMainKeys(device);
+            this.dicSensorStatuView[mainkeys] = frameDevice;
+        }
+
+        #endregion
+
+        #region 浼犳劅鍣ㄦ姤璀
+
+        /// <summary>
+        /// 寮�鍚紶鎰熷櫒鎶ヨ鐩戣
+        /// </summary>
+        private void StartCheckDeviceAlarm()
+        {
+            //鏍规嵁鎺ュ彛鎺ㄩ�侊紝璁剧疆鎶ヨ淇℃伅
+            HdlGatewayReceiveLogic.Current.AddAttributeEvent("SafetyManagementMainFormAlarm", ReceiveComandDiv.A浼犳劅鍣ㄤ笂鎶�, (device) =>
+            {
+                if (HdlSafeguardLogic.Current.IsSensorDeviceExist(device) == false)
+                {
+                    //濡傛灉杩欎釜璁惧涓嶅瓨鍦ㄤ簬瀹夐槻锛屽垯涓嶅鐞�
+                    return;
+                }
+
+                //浼犳劅鍣ㄧ姸鎬�
+                string mainkey = Common.LocalDevice.Current.GetDeviceMainKeys(device);
+                if (this.dicSensorStatuView.ContainsKey(mainkey) == false)
+                {
+                    return;
+                }
+                var control = this.dicSensorStatuView[mainkey];
+                //鑾峰彇浼犳劅鍣ㄦ姤璀︿俊鎭殑缈昏瘧鏂囨湰
+                var msgInfo = HdlAlarmsLogic.Current.GetSensorAlarmInfo(device);
+                HdlThreadLogic.Current.RunMain(() =>
+                {
+                    control?.SetSensoReportInfo(msgInfo);
+                });
+            });
+        }
+
+        #endregion
+
+        #region 鍦ㄧ嚎鐘舵�乢
+
+        /// <summary>
+        /// 涓婁竴娆¤幏鍙栬澶囧湪绾跨殑鏃堕棿(涓嶈兘璁╁畠姣忕偣涓�娆¢兘鍘昏幏鍙栬澶囩姸鎬�)
+        /// </summary>
+        private DateTime oldGetOnlineTime = new DateTime(1900, 1, 1);
+
+        /// <summary>
+        /// 寮�鍚澶囧湪绾跨洃娴�
+        /// </summary>
+        /// <param name="listDevice">浼犳劅鍣ㄥ垪琛�</param>
+        private void StartCheckDeviceOnline(List<CommonDevice> listDevice)
+        {
+            if (listDevice.Count == 0)
+            {
+                return;
+            }
+            if (oldGetOnlineTime.Year != 1900)
+            {
+                var timeValue = (DateTime.Now - oldGetOnlineTime).TotalSeconds;
+                if (timeValue < 10)
+                {
+                    //鏈�灏戣闂撮殧鍗佺,鎵嶅幓閲嶆柊鑾峰彇
+                    return;
+                }
+            }
+            oldGetOnlineTime = DateTime.Now;
+
+            //浠庤澶囧垪琛ㄤ腑鑾峰彇鍦ㄧ嚎鐘舵��
+            HdlThreadLogic.Current.RunThread(() =>
+            {
+                foreach (var device in listDevice)
+                {
+                    if (this.Parent == null)
+                    {
+                        //鐣岄潰鍏抽棴
+                        return;
+                    }
+                    var deviceInfo = Common.LocalDevice.Current.ReadDeviceEpointDeviceInfo(device);
+                    if (deviceInfo != null)
+                    {
+                        //璁剧疆璁惧鍦ㄧ嚎鐘舵��
+                        this.ReceiveDeviceStatuPush(device, deviceInfo);
+                    }
+                    System.Threading.Thread.Sleep(50);
+                }
+            }, ShowErrorMode.NO);
+        }
+
+        /// <summary>
+        /// 鎺ュ彈璁惧鍦ㄧ嚎鎺ㄩ��
+        /// </summary>
+        /// <param name="device"></param>
+        private void ReceiveDeviceStatuPush(CommonDevice device, CommonDevice.DeviceInfoData deviceInfo)
+        {
+            if (this.Parent == null)
+            {
+                //鐣岄潰鍏抽棴
+                return;
+            }
+            string mainkeys = Common.LocalDevice.Current.GetDeviceMainKeys(device);
+            if (this.dicSensorStatuView.ContainsKey(mainkeys) == true)
+            {
+                CommonDevice Loacldevice = Common.LocalDevice.Current.GetDevice(mainkeys);
+                if (Loacldevice == null)
+                {
+                    return;
+                }
+                //鍦ㄧ嚎鐘舵�佷竴鏍风殑璇濓紝涓嶉渶瑕佸埛鏂�
+                if (Loacldevice.IsOnline == deviceInfo.IsOnline)
+                {
+                    return;
+                }
+                //淇濆瓨鐘舵��
+                Loacldevice.IsOnline = deviceInfo.IsOnline;
+
+                //鍥犱负杩欐槸鎺ㄩ�佽繃鏉ョ殑锛屾垜涓嶄繚璇侀偅涓�鐬棿杩欎釜涓滆タ浼氫笉浼氳绉婚櫎
+                var control = this.dicSensorStatuView[mainkeys];
+                HdlThreadLogic.Current.RunMain(() =>
+                {
+                    //璁剧疆鎺т欢鐨勫湪绾跨姸鎬佹枃鏈晥鏋�
+                    bool bolOnline = Common.LocalDevice.Current.CheckDeviceIsOnline(device);
+                    control?.SetOnlineStatu(bolOnline);
+                });
+            }
+        }
+
+        #endregion
+
+        #endregion
+
+        #region 鈻� 瀹夐槻璁板綍鐩稿叧_______________________
+
+        /// <summary>
+        /// 褰撴棩鐨勫畨闃茶褰曠殑FrameLayout
+        /// </summary>
+        private SafeguardLogControl TodaySafeguardFrame = null;
+        /// <summary>
+        /// 鍏朵粬鏃ユ湡鐨勫畨闃茶褰曠殑FrameLayout
+        /// </summary>
+        private FrameLayout otherDaySafeguardFrame = null;
+
+        /// <summary>
+        /// 璁剧疆瀹夐槻璁板綍鍒扮晫闈�
+        /// </summary>
+        private void SetSafeguardLogToForm()
+        {
+            if (this.TabSelectIndex != 1)
+            {
+                return;
+            }
+            //绉婚櫎鍏ㄩ儴鐩戝惉浜嬩欢
+            this.RemoveAllListenEvent();
+
+            this.dicSensorStatuView.Clear();
+
+            frameLayoutDraw.RemoveAll();
+            var listView = new VerticalFrameControl(0);
+            listView.Height = frameLayoutDraw.Height;
+            frameLayoutDraw.AddChidren(listView);
+
+            HdlThreadLogic.Current.RunThread(() =>
+            {
+                var dicAlarm = HdlAlarmsLogic.Current.GetSafeguardAlarmInfo();
+                var dicInfo = new Dictionary<string, Dictionary<int, List<SafeguardAlarmInfo>>>();
+                //杩欓噷涓嶆樉绀哄竷闃插拰鎾ら槻鐨勪俊鎭�
+                foreach (var day in dicAlarm.Keys)
+                {
+                    var listInfo = new Dictionary<int, List<SafeguardAlarmInfo>>();
+                    foreach (var info in dicAlarm[day])
+                    {
+                        if (info.AlarmType == SafeguardAlarmType.Sensor)
+                        {
+                            //鍙浼犳劅鍣ㄧ殑
+                            if (listInfo.ContainsKey(info.ZoneId) == false)
+                            {
+                                listInfo[info.ZoneId] = new List<SafeguardAlarmInfo>();
+                            }
+                            listInfo[info.ZoneId].Add(info);
+                        }
+                    }
+                    //濡傛灉娌℃湁浼犳劅鍣ㄧ殑鎶ヨ淇℃伅,鍒欏綋涓嶅瓨鍦ㄥ鐞�
+                    if (listInfo.Count > 0)
+                    {
+                        dicInfo[day] = listInfo;
+                    }
+                }
+                dicAlarm = null;
+
+                HdlThreadLogic.Current.RunMain(() =>
+                {
+                    if (this.Parent == null)
+                    {
+                        return;
+                    }
+                    //鍒濆鍖栧綋鏃ョ殑瀹夐槻璁板綍鎺т欢
+                    string nowDayKey = DateTime.Now.ToString("yyyyMMdd");
+                    Dictionary<int, List<SafeguardAlarmInfo>> nowDayData = null;
+                    if (dicInfo.ContainsKey(nowDayKey) == true)
+                    {
+                        nowDayData = dicInfo[nowDayKey];
+                        //绉婚櫎鎺夊綋鏃ヨ褰�
+                        dicInfo.Remove(nowDayKey);
+                    }
+                    //鎵ц鍒濆鍖�
+                    TodaySafeguardFrame = new SafeguardLogControl();
+                    TodaySafeguardFrame.Y = Application.GetRealHeight(10);
+                    listView.AddChidren(TodaySafeguardFrame);
+                    TodaySafeguardFrame.InitControl(nowDayKey, nowDayData);
+
+                    //鍒濆鍖栧叾浠栨棩鏈熺殑瀹夐槻璁板綍鎺т欢
+                    if (dicInfo.Count > 0)
+                    {
+                        otherDaySafeguardFrame = new FrameLayout();
+                        otherDaySafeguardFrame.Height = Application.GetRealHeight(10);
+                        listView.AddChidren(otherDaySafeguardFrame);
+                        foreach (var dayText in dicInfo.Keys)
+                        {
+                            //鎵ц鍒濆鍖�
+                            var contr = new SafeguardLogControl();
+                            if (otherDaySafeguardFrame.ChildrenCount > 0)
+                            {
+                                contr.Y = otherDaySafeguardFrame.GetChildren(otherDaySafeguardFrame.ChildrenCount - 1).Bottom + Application.GetRealHeight(35);
+                            }
+                            otherDaySafeguardFrame.AddChidren(contr);
+                            contr.InitControl(dayText, dicInfo[dayText]);
+                        }
+                        //璋冩暣楂樺害
+                        otherDaySafeguardFrame.Height = otherDaySafeguardFrame.GetChildren(otherDaySafeguardFrame.ChildrenCount - 1).Bottom;
+                    }
+                    //璋冩暣妗屽竷楂樺害
+                    listView.AdjustTableHeight();
+                    //寮�鍚紶鎰熷櫒鎶ヨ鐩戣
+                    this.StartCheckDeviceAlarm();
+                });
+            });
+        }
+
+        /// <summary>
+        /// 娣诲姞瀹夐槻璁惧涓婃姤鐨勮鎺т欢(瀹夐槻鎺ㄩ�佷細璋冪敤杩欎釜涓滆タ)
+        /// </summary>
+        /// <param name="device">璁惧瀵硅薄</param>
+        public void AddSafeguardLogPushRow(CommonDevice device)
+        {
+            if (this.TabSelectIndex != 1 || HdlAlarmsLogic.Current.listSafetyAlarmInfo.Count == 0)
+            {
+                return;
+            }
+            var info = HdlAlarmsLogic.Current.listSafetyAlarmInfo[0];
+            if (device != null)
+            {
+                string mainkey1 = Common.LocalDevice.Current.GetDeviceMainKeys(info.DeviceAddr, info.DeviceEpoint);
+                string mainkey2 = Common.LocalDevice.Current.GetDeviceMainKeys(device);
+                if (mainkey1 != mainkey2)
+                {
+                    //涓嶆槸鍚屼竴涓笢瑗�
+                    return;
+                }
+            }
+
+            HdlThreadLogic.Current.RunMain(() =>
+            {
+                if (this.TodaySafeguardFrame != null)
+                {
+                    //娣诲姞鎶ヨ淇℃伅
+                    var value = this.TodaySafeguardFrame.AddSafeguardAlarmInfo(info);
+                    if (value > 0)
+                    {
+                        //鍏朵粬鏃ユ湡鐨凢rameLayout寰�涓嬬Щ鍔�
+                        if (this.otherDaySafeguardFrame != null)
+                        {
+                            this.otherDaySafeguardFrame.Y += value;
+                        }
+                        //妗屽竷鎺т欢
+                        var contrTable = (FrameLayout)this.TodaySafeguardFrame.Parent;
+                        //鍒楄〃鎺т欢
+                        var listview = (VerticalFrameControl)contrTable.Parent;
+                        //璋冩暣妗屽竷楂樺害
+                        listview?.AdjustTableHeight();
+                    }
+                }
+            });
+        }
+
+        /// <summary>
+        /// 闃插尯鎺ㄩ��
+        /// </summary>
+        /// <param name="garrison"></param>
+        public void GarrisonModePush(GarrisonMode garrison)
+        {
+            HdlThreadLogic.Current.RunMain(() =>
+            {
+                garrisonControl?.SetIconStatuByGarrisonMode(garrison);
+            });
+        }
+
+        #endregion
+
+        #region 鈻� 鐣岄潰閲嶆柊婵�娲讳簨浠禵__________________
+
+        /// <summary>
+        /// 鑷韩鐨勪笂灞傜晫闈㈠叧闂悗,瀹冭嚜韬浜庢渶涓婂眰鏃�,瑙﹀彂鐨勪簨浠�
+        /// </summary>
+        public override int FormActionAgainEvent()
+        {
+            //璁剧疆甯冮槻鎸夐挳鐨勫彲瑙嗙姸鎬�
+            garrisonControl?.SetButtonVisible();
+
+            if (this.TabSelectIndex == 1)
+            {
+                //璁剧疆瀹夐槻璁板綍鍒扮晫闈�
+                this.SetSafeguardLogToForm();
+            }
+            else if (this.TabSelectIndex == 2)
+            {
+                //璁剧疆浼犳劅鍣ㄦ暟鎹埌鐢婚潰
+                this.SetSensorDataToForm();
+            }
+            return 1;
+        }
+
+        #endregion
+    }
+}

--
Gitblit v1.8.0