黄学彪
2020-09-22 ade5917841b0fdcb1df7353ef7c56b1a1bdc9282
ZigbeeApp/Shared/Phone/UserCenter/Safety/SafetyManagementMainForm.cs
@@ -1,342 +1,276 @@
using System;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using ZigBee.Device;
namespace Shared.Phone.UserCenter.Safety
{
    /// <summary>
    /// 安防管理的主界面★
    /// </summary>
    public class SafetyManagementMainForm : UserCenterCommonForm
    {
        #region ■ 变量声明___________________________
        /// <summary>
        /// 桌布控件,用于存放或者移除功能块控件(Tab控件专用)
        /// </summary>
        private FrameLayout frameLayoutDraw = null;
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:安防记录Tab  2:传感器状态Tab
        /// </summary>
        private int TabSelectIndex = 2;
        /// <summary>
        /// 在家布防的桌布控件,三个图标(设置了内部防区的)
        /// </summary>
        private StatuFrameLayout frameTableThreeIcon = null;
        /// <summary>
        /// 布防的桌布控件,两个图标(没有设置内部防区的)
        /// </summary>
        private StatuFrameLayout frameTableTwoIcon = null;
        /// <summary>
        /// 布防的图标(没有设置内部防区显示的图标)
        /// </summary>
        private IconViewControl btnAtHomeIconTwo = null;
        /// <summary>
        /// 在家布防的图标(设置了内部防区显示的图标)
        /// </summary>
        private IconViewControl btnAtHomeIconThree = null;
        /// <summary>
        /// 离家布防的图标
        /// </summary>
        private IconViewControl btnRemoveHomeIcon = null;
        private int TabSelectIndex = 2;
        /// <summary>
        /// 在线状态的锁
        /// </summary>
        private object objOnlineLock = new object();
        #endregion
        #endregion
        #region ■ 初始化_____________________________
        /// <summary>
        /// 画面显示(底层会固定调用此方法,借以完成画面创建)
        /// </summary>
        public void ShowForm()
        {
            //设置头部信息
            base.SetTitleText(Language.StringByID(R.MyInternationalizationString.SafetyManagement));
            //初始化中部信息
            this.InitMiddleFrame();
        }
        /// <summary>
        /// 初始化中部信息
        /// </summary>
        private void InitMiddleFrame()
        {
            //初始化头部的那三个图标
            FrameLayout frameLayout = this.InitTopImageControl();
            //初始化Tab控件
            this.InitTabSwitchControl(frameLayout.Bottom);
            if (UserCenterResourse.UserInfo.AuthorityNo == 1 || UserCenterResourse.UserInfo.AuthorityNo == 2)
        /// <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>
        /// 初始化Tab控件
        /// </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 frameLog = new FrameLayoutStatuControl();
            frameLog.UseClickStatu = false;
            frameLog.Height = Application.GetRealHeight(123);
            frameLog.Width = Application.GetRealWidth(273);
            frameLog.X = Application.GetRealWidth(259);
            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.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 = frameLog.Width;
            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.Radius = (uint)Application.GetRealHeight(10) / 2;
            frameSensor.AddChidren(btnSensorLine, ChidrenBindMode.BindEvent);
            //安防记录Tab
            frameLog.ButtonClickEvent += (sender, e) =>
            {
                //初始化右上角图标
                this.InitTopRightIcon();
            }
            //初始化全部内存信息
            this.InitAllMemoryData();
        }
        /// <summary>
        /// 初始化头部的那三个图标
        /// </summary>
        private FrameLayout InitTopImageControl()
        {
            int height = 400;
            //三个图标的各自frameLayout的宽度
            int width = 320;
            //最外层
            var frameLayout = new FrameLayout();
            frameLayout.Height = Application.GetRealHeight(height);
            bodyFrameLayout.AddChidren(frameLayout);
                //字体大小和颜色变更
                btnSensor.TextColor = UserCenterColor.Current.TextGrayColor3;
                btnSensor.TextSize = 14;
                btnSensor.IsBold = false;
                btnLog.TextColor = UserCenterColor.Current.TextColor2;
                btnLog.TextSize = 16;
                btnLog.IsBold = true;
            #region ■ 两个图的(很麻烦的东西)_____
            //包含两个图的桌布 -> 没有设置内部防区(至于底部)
            this.frameTableTwoIcon = new StatuFrameLayout(width * 2, height);
            frameTableTwoIcon.Gravity = Gravity.Center;
            frameTableTwoIcon.Visible = false;
            frameLayout.AddChidren(frameTableTwoIcon);
            //布防的桌布
            var frameGarrison = new StatuFrameLayout(width, height);
            frameTableTwoIcon.AddChidren(frameGarrison);
            //布防的图标
            this.btnAtHomeIconTwo = new IconViewControl(162);
            btnAtHomeIconTwo.Y = Application.GetRealHeight(90);
            btnAtHomeIconTwo.UnSelectedImagePath = "Safeguard/ProtectionAtHome.png";
            btnAtHomeIconTwo.SelectedImagePath = "Safeguard/ProtectionAtHomeSelected.png";
            btnAtHomeIconTwo.Gravity = Gravity.CenterHorizontal;
            frameGarrison.AddChidren(btnAtHomeIconTwo, ChidrenBindMode.BindEventOnly);
            //布防的文字
            var btnAtHomeViewTwo = new ViewNormalControl(width, true);
            btnAtHomeViewTwo.Y = btnAtHomeIconTwo.Bottom;
            btnAtHomeViewTwo.TextID = R.MyInternationalizationString.uAtHomeGarrison;
            btnAtHomeViewTwo.TextAlignment = TextAlignment.Center;
            frameGarrison.AddChidren(btnAtHomeViewTwo, ChidrenBindMode.BindEventOnly);
            //在家布防
            frameGarrison.MouseUpEvent = (sender, e) =>
            {
                if (btnAtHomeIconTwo.IsSelected == false)
                {
                    this.SetSafetyGarrisonModeInAtHome();
                }
            };
                btnLogLine.Visible = true;
                btnSensorLine.Visible = false;
            //撤防的桌布
            var frameReGarrisonTwo = new StatuFrameLayout(width, height);
            frameReGarrisonTwo.X = frameGarrison.Right;
            frameTableTwoIcon.AddChidren(frameReGarrisonTwo);
            //撤防的图标
            var btnReGarrisonIconTwo = new IconViewControl(162);
            btnReGarrisonIconTwo.Y = btnAtHomeIconTwo.Y;
            btnReGarrisonIconTwo.UnSelectedImagePath = "Safeguard/WithdrawGarrison.png";
            btnReGarrisonIconTwo.SelectedImagePath = "Safeguard/WithdrawGarrisonSelected.png";
            btnReGarrisonIconTwo.Gravity = Gravity.CenterHorizontal;
            frameReGarrisonTwo.AddChidren(btnReGarrisonIconTwo);
            //撤防的文字
            var btnReGarrisonTextTwo = new ViewNormalControl(width, true);
            btnReGarrisonTextTwo.Y = btnAtHomeViewTwo.Y;
            btnReGarrisonTextTwo.TextID = R.MyInternationalizationString.uWithdrawGarrison;
            btnReGarrisonTextTwo.TextAlignment = TextAlignment.Center;
            frameReGarrisonTwo.AddChidren(btnReGarrisonTextTwo, ChidrenBindMode.BindEventOnly);
            //撤防
            frameReGarrisonTwo.MouseUpEvent = (sender, e) =>
            {
                this.RemoveSafetyGarrisonMode();
            };
            #endregion
            #region ■ 三个图的(很麻烦的东西)_____
            //包含三个图的 -> 设置了内部防区(至于上部)
            this.frameTableThreeIcon = new StatuFrameLayout(width * 3, height);
            this.frameTableThreeIcon.Visible = false;
            frameTableThreeIcon.Gravity = Gravity.Center;
            frameLayout.AddChidren(frameTableThreeIcon);
            //在家布防的桌布
            var frameAtHome = new StatuFrameLayout(width, height);
            frameTableThreeIcon.AddChidren(frameAtHome);
            //在家布防的图标
            this.btnAtHomeIconThree = new IconViewControl(162);
            btnAtHomeIconThree.Y = Application.GetRealHeight(90);
            btnAtHomeIconThree.UnSelectedImagePath = "Safeguard/ProtectionAtHome.png";
            btnAtHomeIconThree.SelectedImagePath = "Safeguard/ProtectionAtHomeSelected.png";
            btnAtHomeIconThree.Gravity = Gravity.CenterHorizontal;
            frameAtHome.AddChidren(btnAtHomeIconThree, ChidrenBindMode.BindEventOnly);
            //在家布防的文字
            var btnAtHomeView = new ViewNormalControl(width, true);
            btnAtHomeView.Y = btnAtHomeIconThree.Bottom;
            btnAtHomeView.TextID = R.MyInternationalizationString.uAtHomeGarrison;
            btnAtHomeView.TextAlignment = TextAlignment.Center;
            frameAtHome.AddChidren(btnAtHomeView, ChidrenBindMode.BindEventOnly);
            //在家布防
            frameAtHome.MouseUpEvent = (sender, e) =>
            {
                if (btnAtHomeIconThree.IsSelected == false)
                {
                    this.SetSafetyGarrisonModeInAtHome();
                }
            };
            //离家布防的桌布
            var frameRemoveHome = new StatuFrameLayout(width, height);
            frameRemoveHome.X = frameAtHome.Right;
            frameTableThreeIcon.AddChidren(frameRemoveHome);
            //离家布防的图标
            this.btnRemoveHomeIcon = new IconViewControl(162);
            btnRemoveHomeIcon.Y = btnAtHomeIconTwo.Y;
            btnRemoveHomeIcon.UnSelectedImagePath = "Safeguard/ProtectionRemoveHome.png";
            btnRemoveHomeIcon.SelectedImagePath = "Safeguard/ProtectionRemoveHomeSelected.png";
            btnRemoveHomeIcon.Gravity = Gravity.CenterHorizontal;
            frameRemoveHome.AddChidren(btnRemoveHomeIcon, ChidrenBindMode.BindEventOnly);
            //离家布防的文字
            var btnRemoveHomeView = new ViewNormalControl(width, true);
            btnRemoveHomeView.Y = btnAtHomeView.Y;
            btnRemoveHomeView.TextID = R.MyInternationalizationString.uRemoveHomeGarrison;
            btnRemoveHomeView.TextAlignment = TextAlignment.Center;
            frameRemoveHome.AddChidren(btnRemoveHomeView, ChidrenBindMode.BindEventOnly);
            //离家布防
            frameRemoveHome.MouseUpEvent = (sender, e) =>
            {
                if (btnRemoveHomeIcon.IsSelected == false)
                {
                    this.SetSafetyGarrisonModeInRemoveHome();
                }
            };
            //撤防的桌布
            var frameReGarrisonThree = new StatuFrameLayout(width, height);
            frameReGarrisonThree.X = frameRemoveHome.Right;
            frameTableThreeIcon.AddChidren(frameReGarrisonThree);
            //撤防的图标
            var btnReGarrisonIconThree = new IconViewControl(162);
            btnReGarrisonIconThree.Y = btnAtHomeIconTwo.Y;
            btnReGarrisonIconThree.UnSelectedImagePath = "Safeguard/WithdrawGarrison.png";
            btnReGarrisonIconThree.SelectedImagePath = "Safeguard/WithdrawGarrisonSelected.png";
            btnReGarrisonIconThree.Gravity = Gravity.CenterHorizontal;
            frameReGarrisonThree.AddChidren(btnReGarrisonIconThree);
            //撤防的文字
            var btnReGarrisonTextThree = new ViewNormalControl(width, true);
            btnReGarrisonTextThree.Y = btnAtHomeView.Y;
            btnReGarrisonTextThree.TextID = R.MyInternationalizationString.uWithdrawGarrison;
            btnReGarrisonTextThree.TextAlignment = TextAlignment.Center;
            frameReGarrisonThree.AddChidren(btnReGarrisonTextThree, ChidrenBindMode.BindEventOnly);
            //撤防
            frameReGarrisonThree.MouseUpEvent = (sender, e) =>
            {
                this.RemoveSafetyGarrisonMode();
            };
            #endregion
            return frameLayout;
        }
        /// <summary>
        /// 初始化Tab控件
        /// </summary>
        /// <param name="YY">Yy.</param>
        private void InitTabSwitchControl(int YY)
        {
            //Tab切换控件
            var frameSwich = new FrameLayout();
            frameSwich.Y = YY;
            frameSwich.Height = Application.GetRealHeight(150);
            bodyFrameLayout.AddChidren(frameSwich);
            //安防记录
            var btnLog = new ViewNormalControl(frameSwich.Width / 2, Application.GetRealHeight(100))
            {
                Gravity = Gravity.CenterVertical,
                TextID = R.MyInternationalizationString.uSecurityLog,
                TextAlignment = TextAlignment.Center
            };
            frameSwich.AddChidren(btnLog);
            //传感器状态
            var btnSensor = new ViewNormalControl(frameSwich.Width / 2, Application.GetRealHeight(100))
            {
                Gravity = Gravity.CenterVertical,
                X = frameSwich.Width / 2,
                TextID = R.MyInternationalizationString.uSensorStatu,
                TextColor = UserCenterColor.Current.SelectTextColor,
                TextAlignment = TextAlignment.Center
            };
            frameSwich.AddChidren(btnSensor);
            //线
            var btnLine = new ProgressLine();
            btnLine.Gravity = Gravity.BottomLeft;
            frameSwich.AddChidren(btnLine);
            btnLine.SetValue(50, false);
            //桌布控件
            frameLayoutDraw = new FrameLayout();
            frameLayoutDraw.Y = frameSwich.Bottom;
            frameLayoutDraw.Height = bodyFrameLayout.Height - frameSwich.Bottom;
            bodyFrameLayout.AddChidren(frameLayoutDraw);
            //安防记录Tab
            btnLog.MouseUpEventHandler += (sender, e) =>
            {
                btnSensor.TextColor = Common.ZigbeeColor.Current.TextColor;
                btnLog.TextColor = UserCenterColor.Current.SelectTextColor;
                btnLine.SetValue(50);
                this.TabSelectIndex = 1;
                //显示安防记录
                this.SetSafeguardLogToForm();
            };
            //传感器状态Tab
            btnSensor.MouseUpEventHandler += (sender, e) =>
            {
                btnSensor.TextColor = UserCenterColor.Current.SelectTextColor;
                btnLog.TextColor = Common.ZigbeeColor.Current.TextColor;
                btnLine.SetValue(50, false);
                this.TabSelectIndex = 2;
                this.SetSafeguardLogToForm();
            };
            //传感器状态Tab
            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 btnIcon = new TopLayoutMostRightView();
            btnIcon.UnSelectedImagePath = "Item/More.png";
            btnIcon.SelectedImagePath = "Item/MoreSelected.png";
            topFrameLayout.AddChidren(btnIcon);
            btnIcon.MouseUpEventHandler += (sender, e) =>
            {
                //菜单控件
                var frameMenu = new TopRightMenuControl(this, 2);
                //防区列表
                string menu1 = Language.StringByID(R.MyInternationalizationString.uGarrisonAreaList);
                frameMenu.AddRowMenu(menu1, (obj) =>
                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 form = new GarrisonAreaListMenuForm();
                    form.AddForm(form);
                });
                //密码设置
                string menu2 = Language.StringByID(R.MyInternationalizationString.uPasswordSettion);
                frameMenu.AddRowMenu(menu2, (obj) =>
                    //菜单控件
                    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)
                {
                    var form = new PasswordMainForm();
                    form.AddForm(form);
                });
            };
        }
                    //确定取消主页的「安防」捷径?
                    this.ShowMassage(ShowMsgType.Confirm, Language.StringByID(R.MyInternationalizationString.uCancelSafetyShortcutMsg), () =>
                    {
                        UserCenterResourse.ResidenceOption.SafetyShortcut = false;
                        UserCenterResourse.ResidenceOption.Save();
                        btnShortCut.IsSelected = false;
                        //取消主页的「安防」捷径的话,主页需要重新刷新
                        UserView.UserPage.Instance.RefreshForm = true;
                    });
                }
                else
                {
                    //确定创建「安防」捷径到主页?
                    this.ShowMassage(ShowMsgType.Confirm, Language.StringByID(R.MyInternationalizationString.uCreatSafetyShortcutMsg), () =>
                    {
                        UserCenterResourse.ResidenceOption.SafetyShortcut = true;
                        UserCenterResourse.ResidenceOption.Save();
                        btnShortCut.IsSelected = true;
                        //创建主页的「安防」捷径的话,主页需要重新刷新
                        UserView.UserPage.Instance.RefreshForm = true;
                    });
                }
            };
        }
        #endregion
@@ -344,7 +278,7 @@
        /// <summary>
        /// 初始化全部内存信息
        /// </summary>
        /// </summary>
        private async void InitAllMemoryData()
        {
            //开启进度条
@@ -361,7 +295,7 @@
                this.CloseProgressBar(ShowReLoadMode.YES);
                //网关回复超时,请稍后再试
                string msg = Language.StringByID(R.MyInternationalizationString.uGatewayResponseTimeOut);
                this.ShowTip(msg);
                this.ShowMassage(ShowMsgType.Tip, msg);
                return;
            }
@@ -370,34 +304,30 @@
            this.SetProgressValue(Language.StringByID(R.MyInternationalizationString.uGarrisonInfoInittingPleaseWait));
            //刷新安防信息
            result = await this.RefreshSafeguardInfo();
            result = await HdlSafeguardLogic.Current.ReFreshByGateway();
            if (result == false)
            {
                //关闭进度条
                this.CloseProgressBar(ShowReLoadMode.YES);
                //网关回复超时,请稍后再试
                string msg = Language.StringByID(R.MyInternationalizationString.uGatewayResponseTimeOut);
                this.ShowTip(msg);
                return;
            }
            //获取当前的安防模式
            var data = await Common.LocalSafeguard.Current.GetSafetyMode();
            if (data != null)
            {
                //根据布防模式,设置图标的选择状态
                this.SetIconStatuByGarrisonMode((GarrisonMode)data.ModeId);
            }
            //设置按钮可视状态
            this.SetButtonVisible();
            //设置传感器数据到画面
            this.SetSensorDataToForm();
            //关闭进度条
            this.CloseProgressBar();
            //数据初始化完成后
            Application.RunOnMainThread(() =>
            {
                //初始化头部的那三个图标
                garrisonControl = new SafetyMasterControl();
                garrisonControl.Y = Application.GetRealHeight(46);
                bodyFrameLayout.AddChidren(garrisonControl);
                garrisonControl.InitControl();
                //初始化Tab控件
                this.InitTabSwitchControl();
                //设置传感器数据到画面
                this.SetSensorDataToForm();
            });
        }
        /// <summary>
@@ -420,284 +350,44 @@
            return true;
        }
        /// <summary>
        /// 刷新安防信息
        /// </summary>
        /// <returns></returns>
        private async Task<bool> RefreshSafeguardInfo()
        {
            int count = 0;
            while (true)
            {
                //从网关刷新安防信息,直到能够读取为止
                var result = await Common.LocalSafeguard.Current.ReFreshByGateway(ShowErrorMode.NO);
                if (result == true)
                {
                    break;
                }
                count++;
                if (count == 5)
                {
                    return false;
                }
                await Task.Delay(1000);
            }
            return true;
        }
        #endregion
        #region ■ 布防撤防___________________________
        /// <summary>
        /// 在家布防
        /// </summary>
        private async void SetSafetyGarrisonModeInAtHome()
        {
            //打开进度条
            this.ShowProgressBar();
            //在家布防
            GarrisonMode mode = await Common.LocalSafeguard.Current.SetSafetyGarrisonByModel(GarrisonMode.AtHome);
            //关闭进度条
            this.CloseProgressBar();
            if (mode == GarrisonMode.None)
            {
                return;
            }
            //根据布防模式,设置图标的选择状态
            this.SetIconStatuByGarrisonMode(mode);
            if (mode == GarrisonMode.RemoveGarrison)
            {
                return;
            }
            //如果设置有内部防区
            if (Common.LocalSafeguard.Current.IsHadInternalDefenseArea() == true)
            {
                //在家布防设置成功
                string msg = Language.StringByID(R.MyInternationalizationString.uSetAtHomeGarrisonSuccess);
                this.ShowNormalMsg(msg);
            }
            else
            {
                //布防设置成功
                string msg = Language.StringByID(R.MyInternationalizationString.uSetGarrisonSuccess);
                this.ShowNormalMsg(msg);
            }
            //添加布防上报的行控件
            this.AddSafeguardLogPushRow(null);
        }
        /// <summary>
        /// 离家布防
        /// </summary>
        private async void SetSafetyGarrisonModeInRemoveHome()
        {
            //打开进度条
            this.ShowProgressBar();
            //离家布防
            GarrisonMode mode = await Common.LocalSafeguard.Current.SetSafetyGarrisonByModel(GarrisonMode.RemoveHome);
            //关闭进度条
            this.CloseProgressBar();
            if (mode == GarrisonMode.None)
            {
                return;
            }
            //根据布防模式,设置图标的选择状态
            this.SetIconStatuByGarrisonMode(mode);
            if (mode == GarrisonMode.RemoveGarrison)
            {
                return;
            }
            //离家布防设置成功
            string msg = Language.StringByID(R.MyInternationalizationString.uSetRemoveHomeGarrisonSuccess);
            this.ShowNormalMsg(msg);
            //添加布防上报的行控件
            this.AddSafeguardLogPushRow(null);
        }
        /// <summary>
        /// 撤防
        /// </summary>
        private async void RemoveSafetyGarrisonMode()
        {
            //打开进度条
            this.ShowProgressBar();
            //撤防
            bool result = await Common.LocalSafeguard.Current.RemoveSafetyGarrison(GarrisonMode.RemoveGarrison, false);
            //关闭进度条
            this.CloseProgressBar();
            if (result == false)
            {
                return;
            }
            //根据布防模式,设置图标的选择状态
            this.SetIconStatuByGarrisonMode(GarrisonMode.RemoveGarrison);
            //撤防成功
            string msg = Language.StringByID(R.MyInternationalizationString.uRemoveGarrisonSuccess);
            this.ShowNormalMsg(msg);
            //添加布防上报的行控件
            this.AddSafeguardLogPushRow(null);
        }
        /// <summary>
        /// 根据布防模式,设置图标的选择状态
        /// </summary>
        /// <param name="mode"></param>
        private void SetIconStatuByGarrisonMode(GarrisonMode mode)
        {
            //在家布防
            if (mode == GarrisonMode.AtHome)
            {
                Application.RunOnMainThread(() =>
                {
                    this.btnAtHomeIconTwo.IsSelected = true;
                    this.btnAtHomeIconThree.IsSelected = true;
                    this.btnRemoveHomeIcon.IsSelected = false;
                });
            }
            //离家布防
            else if (mode == GarrisonMode.RemoveHome)
            {
                Application.RunOnMainThread(() =>
                {
                    this.btnAtHomeIconTwo.IsSelected = false;
                    this.btnAtHomeIconThree.IsSelected = false;
                    this.btnRemoveHomeIcon.IsSelected = true;
                });
            }
            //撤防
            else if (mode == GarrisonMode.RemoveGarrison)
            {
                Application.RunOnMainThread(() =>
                {
                    this.btnAtHomeIconTwo.IsSelected = false;
                    this.btnAtHomeIconThree.IsSelected = false;
                    this.btnRemoveHomeIcon.IsSelected = false;
                });
            }
        }
        /// <summary>
        /// 检测是否已经配置有用户密码,如果没有配置有密码,则跳转界面,并且返回false
        /// </summary>
        /// <returns></returns>
        private async Task<bool> CheckHadConfigureUserPsw()
        {
            if (UserCenterResourse.UserInfo.AuthorityNo == 3)
            {
                //成员的时候,不检测这个东西
                return true;
            }
            var result = await Common.LocalSafeguard.Current.CheckHadConfigureUserPsw();
            if (result == -1)
            {
                //出现异常
                return false;
            }
            if (result == 0)
            {
                //请先设置用户密码,再执行操作
                string msg = Language.StringByID(R.MyInternationalizationString.uPleaseConfigurePswBeforeOperation);
                this.ShowTip(msg);
                Application.RunOnMainThread(() =>
                {
                    var form = new PasswordMainForm();
                    form.AddForm(form);
                });
                return false;
            }
            return true;
        }
        #endregion
        #region ■ 界面关闭___________________________
        #region ■ 界面关闭___________________________
        /// <summary>
        /// 画面关闭
        /// </summary>
        /// <param name="isCloseForm">是否关闭界面,false的时候,只会调用关闭函数里面的附加功能</param>
        public override void CloseForm(bool isCloseForm = true)
        public override void CloseFormBefore()
        {
            //移除全部监听事件
            this.RemoveAllListenEvent();
            base.CloseForm(isCloseForm);
        }
            base.CloseFormBefore();
        }
        /// <summary>
        /// 移除全部监听事件
        /// </summary>
        /// </summary>
        private void RemoveAllListenEvent()
        {
            DeviceAttributeLogic.Current.RemoveEvent("SafetyManagementMainFormOnline");
            DeviceAttributeLogic.Current.RemoveEvent("SafetyManagementMainFormAlarm");
            DeviceAttributeLogic.Current.RemoveEvent("SafetyManagementMainFormReceivePushOnline");
        }
        #endregion
        #region ■ 一般方法___________________________
        /// <summary>
        /// 设置布防按钮的可视状态
        /// </summary>
        public void SetButtonVisible()
        {
            //设置有内部防区
            if (Common.LocalSafeguard.Current.IsHadInternalDefenseArea() == true)
            {
                Application.RunOnMainThread(() =>
                {
                    //在家布防显示
                    this.frameTableThreeIcon.Visible = true;
                    this.frameTableTwoIcon.Visible = false;
                });
            }
            else
            {
                Application.RunOnMainThread(() =>
                {
                    //在家布防不显示
                    this.frameTableThreeIcon.Visible = false;
                    this.frameTableTwoIcon.Visible = true;
                });
            }
            HdlGatewayReceiveLogic.Current.RemoveEvent("SafetyManagementMainFormAlarm");
            HdlGatewayReceiveLogic.Current.RemoveEvent("SafetyManagementMainFormReceivePushOnline");
        }
        #endregion
        #region ■ 传感器相关_________________________
        #region ■ 传感器相关_________________________
        /// <summary>
        /// 传感器的状态控件
        /// </summary>
        private Dictionary<string, RowMostRightTextView> dicSensorStatuView = new Dictionary<string, RowMostRightTextView>();
        /// <summary>
        /// 传感器的报警控件
        /// </summary>
        private Dictionary<string, RowMostRightTextView> dicSensorAlertView = new Dictionary<string, RowMostRightTextView>();
        private Dictionary<string, SafetySensorStatuControl> dicSensorStatuView = new Dictionary<string, SafetySensorStatuControl>();
        #region 添加传感器行_
        /// <summary>
        /// 设置传感器数据到画面
        /// </summary>
        /// </summary>
        private void SetSensorDataToForm()
        {
            if (this.TabSelectIndex != 2)
@@ -708,26 +398,29 @@
            this.RemoveAllListenEvent();
            this.dicSensorStatuView.Clear();
            this.dicSensorAlertView.Clear();
            //添加列表控件 
            frameLayoutDraw.RemoveAll();
            var listView = new VerticalScrolViewLayout();
            var listView = new VerticalFrameControl(35);
            listView.Height = frameLayoutDraw.Height;
            frameLayoutDraw.AddChidren(listView);
            new System.Threading.Thread(() =>
            HdlThreadLogic.Current.RunThread(() =>
            {
                //获取安防的全部传感器设备的信息
                var dicDevice = Common.LocalSafeguard.Current.GetAllSensorDeviceInfo();
                var dicDevice = HdlSafeguardLogic.Current.GetAllSensorDeviceInfo();
                var listDevice = new List<CommonDevice>();
                foreach (var zoneId in dicDevice.Keys)
                HdlThreadLogic.Current.RunMain(() =>
                {
                    Application.RunOnMainThread(() =>
                    foreach (var zoneId in dicDevice.Keys)
                    {
                        foreach (var Info in dicDevice[zoneId])
                        {
                            if (this.Parent == null)
                            {
                                return;
                            }
                            //添加行
                            this.AddSensorStatuRow(listView, zoneId, Info);
@@ -738,19 +431,15 @@
                                listDevice.Add(tempDevice);
                            }
                        }
                        //最后一个防区的时候,开启各种监视线程
                        if (zoneId == dicDevice.Count)
                        {
                            //开启传感器报警监视
                            this.StartCheckDeviceAlarm();
                            //开启设备在线监测
                            this.StartCheckDeviceOnline(listDevice);
                        }
                    });
                }
            })
            { IsBackground = true }.Start();
                    }
                    //调整列表控件高度
                    listView.AdjustChidrenFrameHeight(listView.frameTable, Application.GetRealHeight(46));
                    //开启传感器报警监视
                    this.StartCheckDeviceAlarm();
                    //开启设备在线监测
                    this.StartCheckDeviceOnline(listDevice);
                });
            });
        }
        /// <summary>
@@ -758,8 +447,8 @@
        /// </summary>
        /// <param name="listView"></param>
        /// <param name="zoneID">防区ID</param>
        /// <param name="sensorInfo">传感器的信息</param>
        private void AddSensorStatuRow(VerticalScrolViewLayout listView, int zoneID, Safeguard.ZoneDeviceListData sensorInfo)
        /// <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)
@@ -767,96 +456,60 @@
                return;
            }
            //设备控件
            var rowDevice = new DeviceRoomViewRow(listView, device);
            rowDevice.ChangedChidrenBindMode(rowDevice.btnIcon, ChidrenBindMode.BindEventOnly);
            rowDevice.ChangedChidrenBindMode(rowDevice.btnDevie, ChidrenBindMode.BindEventOnly);
            rowDevice.ChangedChidrenBindMode(rowDevice.btnRoom, ChidrenBindMode.BindEventOnly);
            string GarrisonText = Common.LocalSafeguard.Current.GetGarrisonText(zoneID);
            rowDevice.btnDevie.Text = rowDevice.btnDevie.Text + "(" + GarrisonText + ")";
            //状态(初始值:离线)
            var btnStatu = new RowMostRightTextView();
            btnStatu.Gravity = Gravity.Frame;
            btnStatu.Y = rowDevice.btnDevie.Y;
            if (device.IsOnline == 0)
            {
                //离线
                btnStatu.TextID = R.MyInternationalizationString.uOffLine;
                btnStatu.TextColor = UserCenterColor.Current.Gray;
            }
            else
            {
                //在线
                btnStatu.TextID = R.MyInternationalizationString.uOnline;
                btnStatu.TextColor = UserCenterColor.Current.Green;
            }
            rowDevice.AddChidren(btnStatu, ChidrenBindMode.BindEventOnly);
            //报警信息
            var btnAlert = new RowMostRightTextView();
            btnAlert.TextColor = UserCenterColor.Current.Red;
            btnAlert.Gravity = Gravity.Frame;
            btnAlert.Y = rowDevice.btnRoom.Y;
            rowDevice.AddChidren(btnAlert);
            //扩大控件宽度
            btnAlert.Width += Application.GetRealWidth(200);
            btnAlert.X -= Application.GetRealWidth(200);
            //自定义传感器状态控件
            var frameDevice = new SafetySensorStatuControl();
            listView.AddChidren(frameDevice);
            frameDevice.InitControl(device);
            //添加阴影特效
            frameDevice.SetViewShadow(true);
            string mainkeys = Common.LocalDevice.Current.GetDeviceMainKeys(device);
            this.dicSensorStatuView[mainkeys] = btnStatu;
            this.dicSensorAlertView[mainkeys] = btnAlert;
        }
            this.dicSensorStatuView[mainkeys] = frameDevice;
        }
        #endregion
        #region 传感器报警_
        #region 传感器报警_
        /// <summary>
        /// 开启传感器报警监视
        /// </summary>
        /// </summary>
        private void StartCheckDeviceAlarm()
        {
            DeviceAttributeLogic.Current.AddSafetyAlarmEvent("SafetyManagementMainFormAlarm", this.SetAlarmInfoByInterfaceResult);
        }
        /// <summary>
        /// 根据接口推送,设置报警信息
        /// </summary>
        /// <param name="common"></param>
        /// <param name="safetyDevice">是否是安防设备报警</param>
        private void SetAlarmInfoByInterfaceResult(CommonDevice common, bool safetyDevice)
        {
            if (safetyDevice == false)
            //根据接口推送,设置报警信息
            HdlGatewayReceiveLogic.Current.AddAttributeEvent("SafetyManagementMainFormAlarm", ReceiveComandDiv.A传感器上报, (device) =>
            {
                return;
            }
            //添加安防设备上报的行控件
            this.AddSafeguardLogPushRow(common);
                if (HdlSafeguardLogic.Current.IsSensorDeviceExist(device) == false)
                {
                    //如果这个设备不存在于安防,则不处理
                    return;
                }
            string mainkey = Common.LocalDevice.Current.GetDeviceMainKeys(common);
            if (this.dicSensorAlertView.ContainsKey(mainkey) == false)
            {
                return;
            }
            var control = this.dicSensorAlertView[mainkey];
            //获取传感器报警信息的翻译文本
            var msgInfo = Common.LocalSafeguard.Current.GetSensorAlarmInfo(common);
            if (msgInfo == null)
            {
                return;
            }
            Application.RunOnMainThread(() =>
            {
                control.Text = msgInfo.AlarmMsg;
                //传感器状态
                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 在线状态_
        #endregion
        #region 在线状态_
        /// <summary>
        /// 上一次获取设备在线的时间(不能让它每点一次都去获取设备状态)
        /// </summary>
        private DateTime oldGetOnlineTime = new DateTime(1900, 1, 1);
        /// <summary>
        /// 开启设备在线监测
        /// </summary>
@@ -867,116 +520,90 @@
            {
                return;
            }
            //添加接受网关自动推送的事件
            DeviceAttributeLogic.Current.AddReceiveDeviceOnlinePushEvent("SafetyManagementMainFormReceivePushOnline", this.ReceiveDeviceStatuPush);
            //从设备列表中获取在线状态
            new System.Threading.Thread(async () =>
            if (oldGetOnlineTime.Year != 1900)
            {
                //首先获取这些传感器所在的网关
                var listWay = new List<ZbGateway>();
                foreach (var device in listDevice)
                var timeValue = (DateTime.Now - oldGetOnlineTime).TotalSeconds;
                if (timeValue < 10)
                {
                    ZbGateway realWay = null;
                    //是否存在真实物理网关
                    if (Common.LocalGateway.Current.GetRealGateway(ref realWay, device.CurrentGateWayId) == false)
                    {
                        continue;
                    }
                    listWay.Add(realWay);
                    //最少要间隔十秒,才去重新获取
                    return;
                }
                foreach (var zbway in listWay)
            }
            oldGetOnlineTime = DateTime.Now;
            //从设备列表中获取在线状态
            HdlThreadLogic.Current.RunThread(() =>
            {
                foreach (var device in listDevice)
                {
                    if (this.Parent == null)
                    {
                        //界面关闭
                        return;
                    }
                    await Common.LocalDevice.Current.GetDeviceListFromGateway(zbway, this.ReceiveDeviceStatuPush, ShowErrorMode.NO);
                    var deviceInfo = Common.LocalDevice.Current.ReadDeviceEpointDeviceInfo(device);
                    if (deviceInfo != null)
                    {
                        //设置设备在线状态
                        this.ReceiveDeviceStatuPush(device, deviceInfo);
                    }
                    System.Threading.Thread.Sleep(50);
                }
            })
            { IsBackground = true }.Start();
            }, ShowErrorMode.NO);
        }
        /// <summary>
        /// 接受设备在线推送(不要忘记最后它会推送一个Null的东西过来)
        /// 接受设备在线推送
        /// </summary>
        /// <param name="device"></param>
        private void ReceiveDeviceStatuPush(CommonDevice device)
        private void ReceiveDeviceStatuPush(CommonDevice device, CommonDevice.DeviceInfoData deviceInfo)
        {
            if (this.Parent == null || device == null)
            if (this.Parent == null)
            {
                //界面关闭
                return;
            }
            lock (objOnlineLock)
            string mainkeys = Common.LocalDevice.Current.GetDeviceMainKeys(device);
            if (this.dicSensorStatuView.ContainsKey(mainkeys) == true)
            {
                string mainkeys = Common.LocalDevice.Current.GetDeviceMainKeys(device);
                if (this.dicSensorStatuView.ContainsKey(mainkeys) == true)
                CommonDevice Loacldevice = Common.LocalDevice.Current.GetDevice(mainkeys);
                if (Loacldevice == null)
                {
                    //因为这是推送过来的,我不保证那一瞬间这个东西会不会被移除
                    var control = this.dicSensorStatuView[mainkeys];
                    CommonDevice Loacldevice = Common.LocalDevice.Current.GetDevice(mainkeys);
                    if (Loacldevice != null)
                    {
                        //在线状态一样的话,不需要刷新
                        if (Loacldevice.IsOnline == device.IsOnline)
                        {
                            return;
                        }
                        //保存状态
                        Loacldevice.IsOnline = device.IsOnline;
                        Loacldevice.ReSave();
                    }
                    Application.RunOnMainThread(() =>
                    {
                        //设置控件的在线状态文本效果
                        this.SetControlOnlineStatu(control, device.IsOnline == 1);
                    });
                    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);
                });
            }
        }
        /// <summary>
        /// 设置控件的在线状态文本效果
        /// </summary>
        /// <param name="button"></param>
        /// <param name="IsOnline"></param>
        private void SetControlOnlineStatu(ButtonCommon button, bool IsOnline)
        {
            if (IsOnline == true)
            {
                //在线
                button.TextID = R.MyInternationalizationString.uOnline;
                button.TextColor = UserCenterColor.Current.Green;
            }
            else
            {
                //离线
                button.TextID = R.MyInternationalizationString.uOffLine;
                button.TextColor = UserCenterColor.Current.Gray;
            }
        }
        #endregion
        #endregion
        #endregion
        #endregion
        #region ■ 安防记录相关_______________________
        /// <summary>
        /// 当日的安防记录的FrameLayout
        /// </summary>
        private SpecialFrameLayout TodaySafeguardFrame = null;
        private SafeguardLogControl TodaySafeguardFrame = null;
        /// <summary>
        /// 其他日期的安防记录的FrameLayout
        /// </summary>
        private SpecialFrameLayout otherDaySafeguardFrame = null;
        /// <summary>
        /// 当日的安防记录的行
        /// </summary>
        private List<SafeguardLogRowView> listNowDayLogRow = new List<SafeguardLogRowView>();
        private FrameLayout otherDaySafeguardFrame = null;
        /// <summary>
        /// 设置安防记录到界面
@@ -991,143 +618,100 @@
            this.RemoveAllListenEvent();
            this.dicSensorStatuView.Clear();
            this.dicSensorAlertView.Clear();
            this.listNowDayLogRow.Clear();
            frameLayoutDraw.RemoveAll();
            var listView = new VerticalScrolViewLayout();
            var listView = new VerticalFrameControl(0);
            listView.Height = frameLayoutDraw.Height;
            frameLayoutDraw.AddChidren(listView);
            var frame = new SpecialFrameLayout(listView.Height, 0);
            listView.AddChidren(frame);
            new System.Threading.Thread(() =>
            HdlThreadLogic.Current.RunThread(() =>
            {
                var dicInfo = Common.LocalSafeguard.Current.GetSafeguardAlarmInfo();
                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;
                Application.RunOnMainThread(() =>
                {
                    if (this.Parent == null)
                    {
                        return;
                    }
                    //初始化当日的安防记录控件
                    this.InitTodaySafeguardLogControl(frame, dicInfo);
                    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);
                    //初始化其他日期的安防记录控件
                    this.InitOtherDaySafeguardLogControl(frame, dicInfo);
                    //控件内部bug对应
                    frame.RemoveFromParent();
                    listView.AddChidren(frame);
                    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();
                });
            })
            { IsBackground = true }.Start();
            });
        }
        /// <summary>
        /// 初始化当日的安防记录控件
        /// 添加安防设备上报的行控件(安防推送会调用这个东西)
        /// </summary>
        /// <param name="frameLayout"></param>
        /// <param name="dicInfo"></param>
        private void InitTodaySafeguardLogControl(SpecialFrameLayout frameLayout, Dictionary<string, List<SafeguardAlarmInfo>> dicInfo)
        /// <param name="device">设备对象</param>
        public void AddSafeguardLogPushRow(CommonDevice device)
        {
            string nowDayKey = DateTime.Now.ToString("yyyyMMdd");
            string month = nowDayKey.Substring(4, 2);
            string day = nowDayKey.Substring(6, 2);
            //日期
            var btnDayTitle = new ViewNormalControl(800, true);
            btnDayTitle.TextSize = 18;
            btnDayTitle.Y = Application.GetRealHeight(30);
            btnDayTitle.X = ControlCommonResourse.XXLeft;
            btnDayTitle.Text = month + Language.StringByID(R.MyInternationalizationString.Month) + day + Language.StringByID(R.MyInternationalizationString.Day);
            frameLayout.AddChidren(btnDayTitle);
            //记录容器
            this.TodaySafeguardFrame = new SpecialFrameLayout(100, 0);
            this.TodaySafeguardFrame.Y = btnDayTitle.Bottom;
            frameLayout.AddChidren(this.TodaySafeguardFrame);
            //没有记录
            if (dicInfo.ContainsKey(nowDayKey) == false)
            {
                //今日无任何报警记录
                var btnView = new ViewNormalControl(800, true);
                btnView.TextSize = 16;
                btnView.TextAlignment = TextAlignment.Center;
                btnView.TextID = R.MyInternationalizationString.uNowDayNotHadAlarmLog;
                btnView.TextColor = UserCenterColor.Current.TextGrayColor;
                btnView.Gravity = Gravity.CenterHorizontal;
                this.TodaySafeguardFrame.AddChidren(btnView, HeightAutoMode.IncreaseOnly);
                return;
            }
            //添加记录行
            foreach (var info in dicInfo[nowDayKey])
            {
                var row = new SafeguardLogRowView(this.TodaySafeguardFrame, info);
                this.listNowDayLogRow.Add(row);
            }
            //调整控件高度
            this.TodaySafeguardFrame.IncreaseHeightByMode(null);
            frameLayout.IncreaseHeightByMode(null);
            //移除当日
            dicInfo.Remove(nowDayKey);
        }
        /// <summary>
        /// 初始化其他日期的安防记录控件
        /// </summary>
        /// <param name="frameLayout"></param>
        /// <param name="dicInfo"></param>
        private void InitOtherDaySafeguardLogControl(SpecialFrameLayout frameLayout, Dictionary<string, List<SafeguardAlarmInfo>> dicInfo)
        {
            //记录容器
            this.otherDaySafeguardFrame = new SpecialFrameLayout(100, 0);
            this.otherDaySafeguardFrame.Y = this.TodaySafeguardFrame.Bottom;
            frameLayout.AddChidren(this.otherDaySafeguardFrame);
            if (dicInfo.Count == 0)
            if (this.TabSelectIndex != 1 || HdlAlarmsLogic.Current.listSafetyAlarmInfo.Count == 0)
            {
                return;
            }
            foreach (string dayText in dicInfo.Keys)
            {
                string month = dayText.Substring(4, 2);
                string day = dayText.Substring(6, 2);
                //日期
                var btnDayTitle = new ViewNormalControl(800, true);
                btnDayTitle.X = ControlCommonResourse.XXLeft;
                btnDayTitle.TextSize = 18;
                btnDayTitle.Text = month + Language.StringByID(R.MyInternationalizationString.Month) + day + Language.StringByID(R.MyInternationalizationString.Day);
                var view = this.otherDaySafeguardFrame.GetChildren(this.otherDaySafeguardFrame.ChildrenCount - 1);
                if (view != null)
                {
                    btnDayTitle.Y = view.Bottom;
                }
                this.otherDaySafeguardFrame.AddChidren(btnDayTitle);
                //添加记录行
                foreach (var info in dicInfo[dayText])
                {
                    var row = new SafeguardLogRowView(this.otherDaySafeguardFrame, info);
                }
            }
            //调整控件高度
            this.otherDaySafeguardFrame.IncreaseHeightByMode(null);
            frameLayout.IncreaseHeightByMode(null);
        }
        /// <summary>
        /// 添加安防设备上报的行控件
        /// </summary>
        /// <param name="device">设备对象,为null时是布防</param>
        private void AddSafeguardLogPushRow(CommonDevice device)
        {
            if (this.TabSelectIndex != 1 || Common.LocalSafeguard.Current.listAlarmInfo.Count == 0)
            {
                return;
            }
            var info = Common.LocalSafeguard.Current.listAlarmInfo[0];
            var info = HdlAlarmsLogic.Current.listSafetyAlarmInfo[0];
            if (device != null)
            {
                string mainkey1 = Common.LocalDevice.Current.GetDeviceMainKeys(info.DeviceAddr, info.DeviceEpoint);
@@ -1141,46 +725,52 @@
            Application.RunOnMainThread(() =>
            {
                if (this.listNowDayLogRow.Count == 0)
                if (this.TodaySafeguardFrame != null)
                {
                    //清空msg
                    this.TodaySafeguardFrame.RemoveAll();
                    //添加报警信息
                    var value = this.TodaySafeguardFrame.AddSafeguardAlarmInfo(info);
                    if (value > 0)
                    {
                        //其他日期的FrameLayout往下移动
                        if (this.otherDaySafeguardFrame != null)
                        {
                            this.otherDaySafeguardFrame.Y += value;
                        }
                        //桌布控件
                        var contrTable = (FrameLayout)this.TodaySafeguardFrame.Parent;
                        //列表控件
                        var listview = (VerticalFrameControl)contrTable.Parent;
                        //调整桌布高度
                        listview?.AdjustTableHeight();
                    }
                }
                //添加行(置顶)
                var row = new SafeguardLogRowView(null, info);
                this.TodaySafeguardFrame.AddChidren(row);
                row.InitControl();
                int height = row.Height;
                //原有控件往下移动
                for (int i = 0; i < this.listNowDayLogRow.Count; i++)
                {
                    this.listNowDayLogRow[i].Y += height;
                }
                //变更大小
                this.TodaySafeguardFrame.IncreaseHeightByMode(null);
                //其他日期往下移动
                this.otherDaySafeguardFrame.Y = this.TodaySafeguardFrame.Bottom;
                //变更父容器大小
                var fatherFrame = (SpecialFrameLayout)this.otherDaySafeguardFrame.Parent;
                fatherFrame.IncreaseHeightByMode(null);
                this.listNowDayLogRow.Add(row);
            });
        }
        #endregion
        /// <summary>
        /// 防区推送
        /// </summary>
        /// <param name="garrison"></param>
        public void GarrisonModePush(GarrisonMode garrison)
        {
            HdlThreadLogic.Current.RunMain(() =>
            {
                garrisonControl?.SetIconStatuByGarrisonMode(garrison);
            });
        }
        #region ■ 界面重新激活事件___________________
        #endregion
        #region ■ 界面重新激活事件___________________
        /// <summary>
        /// 自身的上层界面关闭后,它自身处于最上层时,触发的事件
        /// </summary>
        public override void FormActionAgainEvent()
        /// </summary>
        public override int FormActionAgainEvent()
        {
            //设置布防按钮的可视状态
            this.SetButtonVisible();
            garrisonControl?.SetButtonVisible();
            if (this.TabSelectIndex == 1)
            {
                //设置安防记录到界面
@@ -1191,8 +781,9 @@
                //设置传感器数据到画面
                this.SetSensorDataToForm();
            }
            return 1;
        }
        #endregion
    }
}
        #endregion
    }
}