wei
2021-08-21 ec1d7cb35b99f01be0151c5b6f0c0fc2fa30ab95
HDL_ON/UI/UI2/FuntionControlView/ArmCenter/ArmDeploymentSettingPage.cs
@@ -9,12 +9,28 @@
    public class ArmDeploymentSettingPage : FrameLayout
    {
        FrameLayout bodyView;
        SecurityAlarm securityAlarm;
        /// <summary>
        /// 主题界面
        /// </summary>
        VerticalScrolViewLayout contentView;
        /// <summary>
        /// 输入条件列表区域界面
        /// </summary>
        VerticalScrolViewLayout inputTargetView;
        /// <summary>
        /// 告警目标列表区域界面
        /// </summary>
        VerticalScrolViewLayout outputTargetView;
        public ArmDeploymentSettingPage(SecurityAlarm alarm )
        SecurityAlarm securityAlarm;
        Action refreshAction;
        public ArmDeploymentSettingPage(SecurityAlarm alarm, Action action)
        {
            bodyView = this;
            securityAlarm = alarm;
            refreshAction = action;
        }
        public void LoadPage()
@@ -23,9 +39,10 @@
            bodyView.BackgroundColor = CSS_Color.BackgroundColor;
            VerticalScrolViewLayout contentView = new VerticalScrolViewLayout()
            contentView = new VerticalScrolViewLayout()
            {
                Height = Application.GetRealHeight(667 - 64),
                Y = Application.GetRealHeight(64),
                Height = Application.GetRealHeight(527),
            };
            bodyView.AddChidren(contentView);
@@ -44,6 +61,7 @@
                TextAlignment = TextAlignment.CenterLeft,
                TextSize = CSS_FontSize.SubheadingFontSize,
                TextID = StringId.DeploymentInformation,
                IsBold = true,
            };
            deploymentTitleRow.AddChidren(btnDeploymentTitle);
@@ -67,6 +85,7 @@
                TextID = StringId.Name,
            };
            deploymentNameRow.AddChidren(btnDeploymentNameTitle);
            btnDeploymentNameTitle.Text += ":";
            var btnDeploymentName = new Button()
            {
@@ -83,6 +102,7 @@
            LoadEvent_EditSecurityAlarmName(btnDeploymentName);
            #endregion
            /*
            #region 触发延时
            var delayedRow = new FrameLayout()
            {
@@ -98,9 +118,10 @@
                TextAlignment = TextAlignment.CenterLeft,
                TextColor = CSS_Color.FirstLevelTitleColor,
                TextSize = CSS_FontSize.TextFontSize,
                TextID = StringId.Name,
                TextID = StringId.TriggerDelay,
            };
            delayedRow.AddChidren(btnDelayedTitle);
            btnDelayedTitle.Text += ":";
            var btnDelayedText = new Button()
            {
@@ -124,11 +145,111 @@
            delayedRow.AddChidren(btnDelayedRight);
            //delayedRow.AddChidren(new Button() { Gravity = Gravity.CenterHorizontal, Y = Application.GetRealHeight(49), Height = 1, BackgroundColor = CSS_Color.DividingLineColor });
            LoadEvent_EditSecurityAlarmName(btnDelayedTitle);
            #endregion
            */
            #endregion
            contentView.AddChidren(new Button() { Height = Application.GetRealHeight(8), BackgroundColor = CSS_Color.BackgroundColor });
            //布防功能
            iniDefenseView();
            //告警目标
            iniAlarmView();
            #region 底部区域
            var bottomView = new FrameLayout()
            {
                Y = Application.GetRealHeight(591),
                Height = Application.GetRealHeight(100),
                BackgroundColor = CSS_Color.MainBackgroundColor,
                Radius = (uint)Application.GetRealWidth(22),
            };
            this.AddChidren(bottomView);
            var btnConfrim = new Button()
            {
                X = Application.GetRealWidth(78),
                Y = Application.GetRealHeight(12),
                Width = Application.GetRealWidth(220),
                Height = Application.GetRealWidth(44),
                Radius = (uint)Application.GetRealWidth(22),
                BackgroundColor = CSS_Color.MainColor,
                TextID = StringId.Confirm,
                TextSize = CSS_FontSize.SubheadingFontSize,
                TextColor = CSS_Color.MainBackgroundColor,
                TextAlignment = TextAlignment.Center,
            };
            bottomView.AddChidren(btnConfrim);
            btnConfrim.MouseUpEventHandler = (sender, e) =>
            {
                if (securityAlarm.input.Count == 0)
                {
                    var tip = new Tip()
                    {
                        Text = "请选择布防目标",
                        CloseTime = 3,
                        Direction = AMPopTipDirection.None
                    };
                    tip.Show(MainPage.BaseView);
                    return;
                }
                if (securityAlarm.output.Count == 0)
                {
                    var tip = new Tip()
                    {
                        Text = "请选择告警目标",
                        CloseTime = 3,
                        Direction = AMPopTipDirection.None
                    };
                    tip.Show(MainPage.BaseView);
                    return;
                }
                var waitPage = new Loading();
                waitPage.Start();
                new System.Threading.Thread(() =>
                {
                    try
                    {
                        var code = securityAlarm.SaveInfo();
                        if (code == StateCode.SUCCESS)
                        {
                            Common.ApiUtlis.Ins.GetSecurityList();
                            Application.RunOnMainThread(() =>
                            {
                                this.RemoveFromParent();
                                refreshAction?.Invoke();
                            });
                        }
                        else
                        {
                            Application.RunOnMainThread(() =>
                            {
                                IMessageCommon.Current.ShowErrorInfoAlter(code);
                            });
                        }
                    }
                    catch { }
                    finally
                    {
                        Application.RunOnMainThread(() => {
                            waitPage.Hide();
                        });
                    }
                })
                { IsBackground = true }.Start();
            };
            #endregion
        }
        /// <summary>
        /// 初始化部分功能区域
        /// </summary>
        private void iniDefenseView()
        {
            #region 布防功能
            var deploymentFunctionRow = new FrameLayout()
@@ -144,15 +265,179 @@
                TextColor = CSS_Color.MainColor,
                TextAlignment = TextAlignment.CenterLeft,
                TextSize = CSS_FontSize.SubheadingFontSize,
                TextID = StringId.DeploymentInformation,
                TextID = StringId.DefenseFunctionArmState,
                IsBold = true,
            };
            deploymentFunctionRow.AddChidren(btnFunctionTitle);
            var btnAddTarget = new Button()
            {
                X = Application.GetRealWidth(337),
                Y = Application.GetRealHeight(6),
                Width = Application.GetRealWidth(32),
                Height = Application.GetRealWidth(32),
                UnSelectedImagePath = "FunctionIcon/ArmCenter/AddTargetIcon.png",
            };
            deploymentFunctionRow.AddChidren(btnAddTarget);
            ///添加输入目标
            btnAddTarget.MouseUpEventHandler = (sender, e) => {
                Action<SecurityAlarm> action = (outTemp) => {
                    securityAlarm = outTemp;
                    iniInputTargetView();
                };
                var page = new AddInputPage(securityAlarm, action);
                MainPage.BasePageView.AddChidren(page);
                page.LoadPage();
                MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1;
            };
            deploymentFunctionRow.AddChidren(new Button() { Gravity = Gravity.CenterHorizontal, Y = Application.GetRealHeight(43), Height = 1, BackgroundColor = CSS_Color.DividingLineColor });
            inputTargetView = new VerticalScrolViewLayout()
            {
                ScrollEnabled = false,
            };
            contentView.AddChidren(inputTargetView);
            iniInputTargetView();
            #endregion
            contentView.AddChidren(new Button() { Height = Application.GetRealHeight(8), BackgroundColor = CSS_Color.BackgroundColor });
        }
        /// <summary>
        /// 初始化输入条件区域界面
        /// </summary>
        /// <param name=""></param>
        private void iniInputTargetView()
        {
            inputTargetView.RemoveAll();
            if (securityAlarm.input.Count > 0)
            {
                foreach (var target in securityAlarm.input)
                {
                    inputTargetView.AddChidren(new InputRow(target.GetFunction().name, target.GetFunction().GetRoomListName(), target.StateText()));
                }
                inputTargetView.Height = Application.GetRealHeight(65 * securityAlarm.input.Count);
                //if (outputTargetView != null)
                //{
                //    contentView.AddChidren(outputTargetView);
                //}
            }
            else
            {
                inputTargetView.AddChidren(new Button()
                {
                    Height = Application.GetRealHeight(65),
                    TextAlignment = TextAlignment.Center,
                    TextSize = CSS_FontSize.TextFontSize,
                    TextColor = CSS_Color.PromptingColor1,
                    TextID = StringId.ThereIsNoAssociatedTaskDeploymentStatus,
                    IsMoreLines = true,
                    BackgroundColor = CSS_Color.MainBackgroundColor,
                });
                inputTargetView.Height = Application.GetRealHeight(68);
                //if(outputTargetView!= null)
                //{
                //    contentView.AddChidren(outputTargetView);
                //}
            }
        }
        /// <summary>
        /// 初始化告警目标区域
        /// </summary>
        private void iniAlarmView()
        {
            #region 告警目标
            var outputRow = new FrameLayout()
            {
                Height = Application.GetRealHeight(44),
                BackgroundColor = CSS_Color.MainBackgroundColor,
            };
            contentView.AddChidren(outputRow);
            var btnOutputRowTitle = new Button()
            {
                X = Application.GetRealWidth(16),
                TextColor = CSS_Color.MainColor,
                TextAlignment = TextAlignment.CenterLeft,
                TextSize = CSS_FontSize.SubheadingFontSize,
                TextID = StringId.AlarmTargetAfterTriggering,
                IsBold = true,
            };
            outputRow.AddChidren(btnOutputRowTitle);
            var btnAddOutTarget = new Button()
            {
                X = Application.GetRealWidth(337),
                Y = Application.GetRealHeight(6),
                Width = Application.GetRealWidth(32),
                Height = Application.GetRealWidth(32),
                UnSelectedImagePath = "FunctionIcon/ArmCenter/AddTargetIcon.png",
            };
            outputRow.AddChidren(btnAddOutTarget);
            btnAddOutTarget.MouseUpEventHandler = (sender, e) => {
                Action<SecurityAlarm> action = (outTemp) => {
                    securityAlarm = outTemp;
                    iniAlarmListView();
                };
                var page = new AddOutputPage(securityAlarm, action);
                MainPage.BasePageView.AddChidren(page);
                page.LoadPage();
                MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1;
            };
            outputRow.AddChidren(new Button() { Gravity = Gravity.CenterHorizontal, Y = Application.GetRealHeight(43), Height = 1, BackgroundColor = CSS_Color.DividingLineColor });
            outputTargetView = new VerticalScrolViewLayout()
            {
                ScrollEnabled = false,
            };
            contentView.AddChidren(outputTargetView);
            iniAlarmListView();
            #endregion
            contentView.AddChidren(new Button() { Height = Application.GetRealHeight(8), BackgroundColor = CSS_Color.BackgroundColor });
        }
        /// <summary>
        /// 初始化告警列表区域
        /// </summary>
        private void iniAlarmListView()
        {
            outputTargetView.RemoveAll();
            if (securityAlarm.output.Count > 0)
            {
                foreach (var outTarget in securityAlarm.output)
                {
                    outputTargetView.AddChidren(new OutputRow(outTarget.GetFunction().name, outTarget.GetFunction().GetRoomListName(), "打开"));
                }
                outputTargetView.Height = Application.GetRealHeight(65 * securityAlarm.output.Count);
            }
            else
            {
                outputTargetView.AddChidren(new Button()
                {
                    Height = Application.GetRealHeight(65),
                    TextAlignment = TextAlignment.Center,
                    TextSize = CSS_FontSize.TextFontSize,
                    TextColor = CSS_Color.PromptingColor1,
                    TextID = StringId.ThereIsNoAssociatedTaskDeploymentStatus,
                    IsMoreLines = true,
                    BackgroundColor = CSS_Color.MainBackgroundColor,
                });
            }
        }
        /// <summary>
        /// 修改安防名称
@@ -163,51 +448,65 @@
            {
                Action<string> callBack = (str) =>
                {
                    var waitPage = new Loading();
                    bodyView.AddChidren(waitPage);
                    waitPage.Start(Language.StringByID(StringId.PleaseWait));
                    new System.Threading.Thread(() =>
                    //名称不能为空
                    if (string.IsNullOrEmpty(str))
                    {
                        try
                        new Tip()
                        {
                            securityAlarm.name = str;
                            var responsePack = new HttpServerRequest().EditSecurity(new List<SecurityAlarm>() { securityAlarm});
                            CloseTime = 1,
                            Text = Language.StringByID(StringId.NameCannotBeEmpty),
                            Direction = AMPopTipDirection.None,
                        }.Show(bodyView);
                        return;
                    }
                            if (responsePack.Code == StateCode.SUCCESS)
                            {
                                Application.RunOnMainThread(() =>
                                {
                                    btnDeploymentName.Text = str;
                                });
                            }
                            else
                            {
                                IMessageCommon.Current.ShowErrorInfoAlter(responsePack.Code);
                            }
                        }
                        catch (Exception ex)
                        {
                            MainPage.Log($"update user name error : {ex.Message}");
                        }
                        finally
                        {
                            Application.RunOnMainThread(() =>
                            {
                                if (waitPage != null)
                                {
                                    waitPage.RemoveFromParent();
                                    waitPage = null;
                                }
                            });
                        }
                    })
                    { IsBackground = true }.Start();
                    btnDeploymentName.Text = securityAlarm.name = str;
                    //var waitPage = new Loading();
                    //bodyView.AddChidren(waitPage);
                    //waitPage.Start(Language.StringByID(StringId.PleaseWait));
                    //new System.Threading.Thread(() =>
                    //{
                    //    try
                    //    {
                    //        securityAlarm.name = str;
                    //        var responsePack = new HttpServerRequest().EditSecurity(new List<SecurityAlarm>() { securityAlarm});
                    //        if (responsePack.Code == StateCode.SUCCESS)
                    //        {
                    //            Application.RunOnMainThread(() =>
                    //            {
                    //                btnDeploymentName.Text = str;
                    //            });
                    //        }
                    //        else
                    //        {
                    //            IMessageCommon.Current.ShowErrorInfoAlter(responsePack.Code);
                    //        }
                    //    }
                    //    catch (Exception ex)
                    //    {
                    //        MainPage.Log($"update user name error : {ex.Message}");
                    //    }
                    //    finally
                    //    {
                    //        Application.RunOnMainThread(() =>
                    //        {
                    //            if (waitPage != null)
                    //            {
                    //                waitPage.RemoveFromParent();
                    //                waitPage = null;
                    //            }
                    //        });
                    //    }
                    //})
                    //{ IsBackground = true }.Start();
                };
                new PublicAssmebly().LoadDialog_EditParater(StringId.Name, securityAlarm.name, callBack, StringId.NameCannotBeEmpty, 0, new List<string>());
            };
            btnDeploymentName.MouseUpEventHandler = eventHandler;
        }
    }
}