From dd7e4794fd611de967c6322dd0bb7ffda41c2f7b Mon Sep 17 00:00:00 2001
From: wxr <464027401@qq.com>
Date: 星期一, 29 十一月 2021 16:32:55 +0800
Subject: [PATCH] 增加了安防相关功能

---
 HDL_ON/UI/UI2/FuntionControlView/ArmCenter/ArmCenterPage.cs |  245 ++++++++++++++++++++++++++++++++++++------------
 1 files changed, 184 insertions(+), 61 deletions(-)

diff --git a/HDL_ON/UI/UI2/FuntionControlView/ArmCenter/ArmCenterPage.cs b/HDL_ON/UI/UI2/FuntionControlView/ArmCenter/ArmCenterPage.cs
index 6f1d164..6f549d2 100644
--- a/HDL_ON/UI/UI2/FuntionControlView/ArmCenter/ArmCenterPage.cs
+++ b/HDL_ON/UI/UI2/FuntionControlView/ArmCenter/ArmCenterPage.cs
@@ -1,4 +1,5 @@
 锘縰sing System;
+using System.Collections.Generic;
 using HDL_ON.DriverLayer;
 using HDL_ON.Entity;
 using HDL_ON.UI.CSS;
@@ -35,22 +36,40 @@
         /// </summary>
         FrameLayout disarmView;
 
+        /// <summary>
+        /// 甯冮槻鎺ュ彛
+        /// </summary>
+        SecurityAlarm InDefenseMode = null;
+        /// <summary>
+        /// 鑷畾涔夊竷闃叉帶浠跺垪琛�
+        /// </summary>
+        List<ArmDiyView> armDiyViewList = new List<ArmDiyView>();
+
+
+        Action refreshAction = null;
+
+        public ArmCenterPage(Action action)
+        {
+            refreshAction = action;
+            bodyView = this;
+        }
         public ArmCenterPage()
         {
             bodyView = this;
         }
 
-        public void LoadPage()
+        public void LoadPage(bool addNav = true)
         {
             Action skipAction = () => {
 
             };
-
-            new TopViewDiv(bodyView, Language.StringByID(StringId.SecurityCenter)).LoadTopView_ArmCenter(skipAction);
-
+            if (addNav)
+            {
+                new TopViewDiv(bodyView, Language.StringByID(StringId.SecurityCenter)).LoadTopView_ArmCenter(skipAction);
+            }
             VerticalScrolViewLayout contentView = new VerticalScrolViewLayout()
             {
-                Y = Application.GetRealHeight(64),
+                Y = addNav? Application.GetRealHeight(64):0,
                 Height = Application.GetRealHeight(667 - 64),
                 BackgroundColor = CSS_Color.MainBackgroundColor,
                 ScrollEnabled = false,
@@ -84,16 +103,20 @@
             {
                 Width = Application.GetRealWidth(198),
                 Height = Application.GetRealWidth(198),
+                UnSelectedImagePath = "FunctionIcon/ArmCenter/InAlarmBigIcon.png",
             };
             btnInalarmIcon.MouseUpEventHandler = (sender, e) => {
-                if(SecurityCenter.Ins.InDefenseMode!= null)
+                if(InDefenseMode!= null)
                 {
-                    SecurityCenter.Ins.InDefenseMode.alarm = false;
-                    Control.Ins.ControlSecurity(SecurityCenter.Ins.InDefenseMode, "enable");
+                    Action action = () =>
+                    {
+                        InDefenseMode.alarm = false;
+                        Control.Ins.ControlSecurity(InDefenseMode, "enable");
+                    };
+                    new PublicAssmebly().TipOptionMsg(StringId.Tip, StringId.ClearTheSecurityAlarmTip, action);
+
                 }
             };
-            InitAlarmStatus(SecurityCenter.Ins.InAlarm);
-
 
             btnDefenseName = new Button()
             {
@@ -127,31 +150,24 @@
                 BackgroundColor = CSS_Color.MainColor,
                 TextAlignment = TextAlignment.Center,
                 TextColor = CSS_Color.MainBackgroundColor,
-                Text = "鎾ら槻",
+                TextID = StringId.chefang,// = "鎾ら槻",
                 Radius = (uint)Application.GetRealWidth(20),
                 Gravity = Gravity.CenterHorizontal,
             };
             disarmView.AddChidren(btnDisarm);
+            
             btnDisarm.MouseUpEventHandler = (sender, e) => {
-                //foreach (var temp in FunctionList.List.securities)
-                //{
-                //    if (temp.status == "enable")
-                //    {
-                //        Control.Ins.ControlSecurity(temp, "disable");
-                //        break;
-                //    }
-                //}
-                if(SecurityCenter.Ins.InDefenseMode!= null)
+                if(InDefenseMode!= null)
                 {
-                    Control.Ins.ControlSecurity(SecurityCenter.Ins.InDefenseMode, "disable");
+                    Control.Ins.ControlSecurity(InDefenseMode, "disable");
                 }
             };
 
-                #endregion
+            #endregion
 
-                #region 鑷畾涔夊竷闃�
-                //鑷畾涔夊竷闃叉爣棰�
-                Button btnCustomDeploymentTitle = new Button()
+            #region 鑷畾涔夊竷闃�
+            //鑷畾涔夊竷闃叉爣棰�
+            Button btnCustomDeploymentTitle = new Button()
             {
                 X = Application.GetRealWidth(24),
                 Height = Application.GetRealWidth(54),
@@ -178,6 +194,8 @@
             {
                 Height = Application.GetRealHeight(20),
             });
+
+
 
             #region 鍥哄畾甯冮槻鍖哄煙
             /*
@@ -224,11 +242,26 @@
                 Width = Application.GetRealWidth(24),
             });
 
-            #endregion
 
 
             //鐏惧鎶ヨ
             var disasterAlarmView = new FixedArmView("FunctionIcon/ArmCenter/DisasterAlarmIcon.png", Language.StringByID(StringId.DisasterDefense), Language.StringByID(StringId.Defense24Hour));
+            EventHandler<MouseEventArgs> disasterAlarmViewClick = (sender, e) => {
+                var disasterAlarm = FunctionList.List.securities.Find((obj) => obj.type == "all_day");
+                if (disasterAlarm == null)
+                {
+                    disasterAlarm = new SecurityAlarm() { name = "alldaydefense", type = "all_day" };
+                }
+                else
+                {
+                    disasterAlarm = disasterAlarm.RefeshData();
+                }
+                var addDefensePage = new AddAlarmDeploymentPage(disasterAlarm, null);
+                MainPage.BasePageView.AddChidren(addDefensePage);
+                addDefensePage.LoadPage(Language.StringByID(StringId.DisasterDefense));
+                MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1;
+            };
+            disasterAlarmView.SetClick(disasterAlarmViewClick);
             fixedDeploymentTypeView.AddChidren(disasterAlarmView);
 
             fixedDeploymentTypeView.AddChidren(new Button()
@@ -238,29 +271,52 @@
 
             //闃茬洍鎶ヨ
             var burglarAlarmView = new FixedArmView("FunctionIcon/ArmCenter/BurglarAlarmIcon.png", Language.StringByID(StringId.BurglarAlarm), Language.StringByID(StringId.AlarmMute));
+            EventHandler<MouseEventArgs> burglarAlarmViewClick = (sender, e) => {
+                var burglarAlarm = FunctionList.List.securities.Find((obj) => obj.type == "mute");
+                if (burglarAlarm == null)
+                {
+                    burglarAlarm = new SecurityAlarm() { name = "mutedefense", type = "mute" };
+                }
+                else
+                {
+                    burglarAlarm = burglarAlarm.RefeshData();
+                }
+                var addDefensePage = new AddAlarmDeploymentPage(burglarAlarm, null);
+                MainPage.BasePageView.AddChidren(addDefensePage);
+                addDefensePage.LoadPage(Language.StringByID(StringId.BurglarAlarm));
+                MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1;
+            };
+            disasterAlarmView.SetClick(disasterAlarmViewClick);
             fixedDeploymentTypeView.AddChidren(burglarAlarmView);
             */
             #endregion
 
 
-
-
-            ///鍒锋柊鐣岄潰
-            LoadEvent_RefreshSecurityStatus();
+            iniCustomDeploymentView();
 
         }
 
+        /// <summary>
+        /// 鍒濆鍖栨姤璀︾姸鎬�
+        /// </summary>
+        /// <param name="inAlarm"></param>
         public void InitAlarmStatus(bool inAlarm)
         {
             try
             {
                 if (inAlarm)
                 {
-                    alarmIconBgView.AddChidren(btnInalarmIcon);
+                    if (btnInalarmIcon.Parent == null)
+                    {
+                        alarmIconBgView.AddChidren(btnInalarmIcon);
+                    }
                 }
                 else
                 {
-                    btnInalarmIcon.RemoveFromParent();
+                    if (btnInalarmIcon.Parent != null)
+                    {
+                        btnInalarmIcon.RemoveFromParent();
+                    }
                 }
             }
             catch { }
@@ -272,11 +328,11 @@
         private void iniCustomDeploymentView()
         {
             customDeploymentView.RemoveAll();
-
+            armDiyViewList.Clear();
             foreach (var mode in FunctionList.List.securities)
             {
                 var armDiyView = new ArmDiyView("FunctionIcon/ArmCenter/AtHomeDefenseIcon.png", "FunctionIcon/ArmCenter/AtHomeDefenseIconOn.png",
-                mode.name);
+                mode.name,mode.sid);
                 customDeploymentView.AddChidren(armDiyView);
                 EventHandler<MouseEventArgs> event2 = (sender, e) =>
                 {
@@ -286,22 +342,27 @@
                 if (mode.status == "enable")
                 {
                     armDiyView.LightingView(true);
+                    InDefenseMode = mode;
+
+                    ///鍒锋柊鐣岄潰
+                    LoadEvent_RefreshSecurityStatus(InDefenseMode);
                 }
+                armDiyViewList.Add(armDiyView);
             }
 
             if (FunctionList.List.securities.Count < 4)
             {
                 var view = new ArmDiyView("FunctionIcon/ArmCenter/AddDefenseIcon.png", "FunctionIcon/ArmCenter/AddDefenseIcon.png",
-                  Language.StringByID(StringId.Custom));
+                  Language.StringByID(StringId.Custom),"customSid");
                 customDeploymentView.AddChidren(view);
                 EventHandler<MouseEventArgs> event1 = (sender, e) =>
                 {
-                    Action refreshAction = () =>
+                    Action addDefenseRefreshAction = () =>
                     {
                         iniCustomDeploymentView();
                     };
 
-                    var addDefensePage = new AddAlarmDeploymentPage(new SecurityAlarm(), refreshAction);
+                    var addDefensePage = new AddAlarmDeploymentPage(new SecurityAlarm(), addDefenseRefreshAction);
                     MainPage.BasePageView.AddChidren(addDefensePage);
                     addDefensePage.LoadPage();
                     MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1;
@@ -381,13 +442,12 @@
             }
 
             btnOpen.MouseUpEventHandler = (sender, e) => {
-                if (alarm.status == "disable")
+                string controlStatus = alarm.status == "disable" ? "enable" : "disable";
+                new System.Threading.Thread(() =>
                 {
-                    Control.Ins.ControlSecurity(alarm, "enable");
-                }else
-                {
-                    Control.Ins.ControlSecurity(alarm, "disable");
-                }
+                    Control.Ins.ControlSecurity(alarm, controlStatus);
+                })
+                { IsBackground = true }.Start();
                 dialog.Close();  
             };
 
@@ -398,6 +458,8 @@
                 {
                     iniCustomDeploymentView();
                 };
+
+                    alarm = alarm.RefeshData();
                 var armSetPage = new AddAlarmDeploymentPage(alarm,refreshAction);
                 MainPage.BasePageView.AddChidren(armSetPage);
                 armSetPage.LoadPage();
@@ -411,28 +473,70 @@
 
         }
 
-        public static void LoadEvent_RefreshSecurityStatus()
+        public static void LoadEvent_RefreshSecurityStatus(SecurityAlarm updataTemp)
         {
             Application.RunOnMainThread(() =>
             {
-                if (bodyView != null)
+                try
                 {
-                    bodyView.iniCustomDeploymentView();
-                    bodyView.disarmView.Height = 0;
-                    bodyView.btnArmTipIcon.IsSelected = false;
-                    bodyView.btnDefenseName.Text = "";
-                    foreach (var temp in FunctionList.List.securities)
+                    if (bodyView != null)
                     {
-                        if (temp.status == "enable")
-                        {
-                            bodyView.disarmView.Height = Application.GetRealHeight(68);
-                            bodyView.btnArmTipIcon.IsSelected = true;
-                            bodyView.btnDefenseName.Text = temp.name;
+                        bodyView.refreshAction?.Invoke();
 
-                            bodyView.InitAlarmStatus(temp.alarm);
-                            break;
+                        //甯冮槻
+                        if (updataTemp.status == "enable")
+                        {
+                            bodyView.InDefenseMode = updataTemp;
+                            foreach (var tempView in bodyView.armDiyViewList)
+                            {
+                                tempView.LightingView(false);
+                                if (tempView.sid == updataTemp.sid)
+                                {
+                                    tempView.LightingView(updataTemp.status == "enable");
+                                }
+                            }
                         }
+                        else
+                        {
+                            //鎾ら槻
+                            if(bodyView.InDefenseMode.sid == updataTemp.sid)
+                            {
+                                foreach (var tempView in bodyView.armDiyViewList)
+                                {
+                                    tempView.LightingView(false);
+                                }
+                            }
+                        }
+
+
+                        //foreach(var tempView in bodyView.armDiyViewList)
+                        //{
+                        //    tempView.LightingView(false);
+                        //    if(tempView.sid == updataTemp.sid)
+                        //    {
+                        //        tempView.LightingView(updataTemp.status == "enable");
+                        //    }
+                        //}
+
+                        //娌℃湁甯冮槻鐨勬儏鍐�
+                        if (bodyView.InDefenseMode ==null|| bodyView.InDefenseMode.status == "disable")
+                        {
+                            bodyView.disarmView.Height = 0;   
+                            bodyView.btnArmTipIcon.IsSelected = false;   
+                            bodyView.btnDefenseName.Text = "";   
+                        }
+                        else
+                        {
+                            bodyView.disarmView.Height = Application.GetRealHeight(68); 
+                            bodyView.btnArmTipIcon.IsSelected = true; 
+                            bodyView.btnDefenseName.Text = bodyView.InDefenseMode.name; 
+                        }
+                        bodyView.InitAlarmStatus(bodyView.InDefenseMode.alarm);
                     }
+                }
+                catch (Exception ex)
+                {
+                    MainPage.Log($"瀹夐槻鐣岄潰鏇存柊寮傚父锛歿ex.Message}");
                 }
             });
         }
@@ -446,14 +550,16 @@
     {
         Button btnIcon;
         Button btnText;
+        public string sid;
         /// <summary>
         /// 鑷畾涔夊竷闃茬晫闈�
         /// </summary>
         /// <param name="UnSelectedIconPath">鍥剧墖璺緞</param>
         /// <param name="SelectedIconPath">鍥剧墖璺緞</param>
         /// <param name="Text">鏄剧ず鏂囨湰</param>
-        public ArmDiyView(string UnSelectedIconPath, string SelectedIconPath, string Text)
+        public ArmDiyView(string UnSelectedIconPath, string SelectedIconPath, string Text,string inSid)
         {
+            sid = inSid;
             this.Width = Application.GetRealWidth(82);
             this.Height = Application.GetRealWidth(80);
 
@@ -497,8 +603,15 @@
 
     }
 
+    /// <summary>
+    /// 鍥哄畾甯冮槻鎺т欢
+    /// </summary>
     public class FixedArmView : FrameLayout
     {
+        Button btnIcon;
+        Button btnTitle;
+        Button btnTitleTip;
+
         /// <summary>
         /// 鍥哄畾甯冮槻鎺т欢
         /// </summary>
@@ -513,7 +626,7 @@
             this.BorderColor = CSS_Color.MainColor;
             this.BorderWidth = 1;
 
-            var btnIcon = new Button()
+            btnIcon = new Button()
             {
                 X = Application.GetRealWidth(15),
                 Width = Application.GetRealWidth(24),
@@ -523,7 +636,7 @@
             };
             this.AddChidren(btnIcon);
 
-            var btnTitle = new Button()
+            btnTitle = new Button()
             {
                 X = Application.GetRealWidth(55),
                 Width = Application.GetRealWidth(89),
@@ -536,7 +649,7 @@
             };
             this.AddChidren(btnTitle);
 
-            var btnTitleTip = new Button()
+            btnTitleTip = new Button()
             {
                 X = Application.GetRealWidth(55),
                 Y = Application.GetRealHeight(23),
@@ -546,10 +659,20 @@
                 TextColor = CSS_Color.PromptingColor1,
                 TextSize = CSS_FontSize.PromptFontSize_FirstLevel,
                 Text = titleTip,
+                IsMoreLines = true,
             };
             this.AddChidren(btnTitleTip);
 
         }
+
+        /// <summary>
+        /// 璁剧疆鐐瑰嚮浜嬩欢
+        /// </summary>
+        /// <param name="handler"></param>
+        public void  SetClick(EventHandler<MouseEventArgs> handler)
+        {
+            btnTitleTip.MouseUpEventHandler = btnIcon.MouseUpEventHandler = handler;
+        }
     }
 
 }

--
Gitblit v1.8.0