HDL Home App 第二版本 旧平台金堂用 正在使用
黄学彪
2019-09-30 404cdc88627f942df7944af04ee05b9d527752d6
ZigbeeApp/Shared/Phone/UserCenter/Safety/AlarmTargetSettionForm.cs
@@ -8,8 +8,10 @@
    /// <summary>
    /// 报警目标设置画面
    /// </summary>
    public class AlarmTargetSettionForm : UserCenterCommonForm
    public class AlarmTargetSettionForm : EditorCommonForm
    {
        #region ■ 变量声明___________________________
        /// <summary>
        /// 防区ID(这个东西似乎是唯一的)
        /// </summary>
@@ -17,11 +19,15 @@
        /// <summary>
        /// 列表控件
        /// </summary>
        private VerticalScrolViewLayout listView = null;
        private VerticalListControl listView = null;
        /// <summary>
        /// 标题控件
        /// 底部的【添加目标】的行
        /// </summary>
        private TitleViewControl btnTitle = null;
        private FrameRowControl frameBottomAddRow = null;
        #endregion
        #region ■ 初始化_____________________________
        /// <summary>
        /// 画面显示(底层会固定调用此方法,借以完成画面创建)
@@ -32,18 +38,7 @@
            this.zoonID = i_zoonID;
            //设置头部信息
            base.SetTitleText(Language.StringByID(R.MyInternationalizationString.uAlarmTargetSettion));
            //右上添加按钮
            var btnAddDeviceIcon = new TopLayoutMostRightView();
            btnAddDeviceIcon.UnSelectedImagePath = "Item/Add.png";
            btnAddDeviceIcon.SelectedImagePath = "Item/AddSelected.png";
            topFrameLayout.AddChidren(btnAddDeviceIcon);
            btnAddDeviceIcon.MouseUpEventHandler += (sender, e) =>
            {
                var form = new AddAlarmTargetTypeListForm();
                this.AddForm(form, this.zoonID);
            };
            base.SetTitleText(Language.StringByID(R.MyInternationalizationString.uAlarmTargetSettion));
            //初始化中部信息
            this.InitMiddleFrame();
@@ -54,44 +49,151 @@
        /// </summary>
        private void InitMiddleFrame()
        {
            //当该防区报警时,以下目标将会响应
            btnTitle = new TitleViewControl();
            btnTitle.TextColor = UserCenterColor.Current.TextGrayColor;
            btnTitle.Visible = false;
            btnTitle.Y = Application.GetRealHeight(40);
            btnTitle.TextID = R.MyInternationalizationString.uTargetViewAlarmAfterZoonAlarm;
            bodyFrameLayout.AddChidren(btnTitle);
            //清空bodyFrame
            this.ClearBodyFrame();
            this.listView = new VerticalScrolViewLayout();
            this.listView.Y = btnTitle.Bottom + Application.GetRealHeight(20);
            this.listView.Height = bodyFrameLayout.Height - btnTitle.Bottom - Application.GetRealHeight(20);
            //根据防区ID获取本地的报警目标列表
            var listData = HdlSafeguardLogic.Current.GetLocalAlarmTargetInfoByZoneId(this.zoonID);
            if (listData.Count == 0)
            {
                //特殊特效,如果没有报警目标的话,则显示的界面效果非常的大
                this.ShowNotAlarmTargetAppeal();
                frameBottomAddRow = null;
                return;
            }
            //当该防区报警时,以下目标将会响应
            var frameBack = new FrameLayout();
            frameBack.Height = Application.GetRealHeight(92);
            frameBack.BackgroundColor = UserCenterColor.Current.White;
            bodyFrameLayout.AddChidren(frameBack);
            var btnTitle = new NormalViewControl(860, 49, true);
            btnTitle.X = ControlCommonResourse.XXLeft;
            btnTitle.Y = Application.GetRealHeight(35);
            btnTitle.TextSize = 12;
            btnTitle.TextColor = UserCenterColor.Current.TextGrayColor2;
            btnTitle.TextID = R.MyInternationalizationString.uTargetViewAlarmAfterZoonAlarm;
            frameBack.AddChidren(btnTitle);
            int maxRowCount = listData.Count;
            if (maxRowCount > 8)
            {
                //特效问题,它只能显示8个,超过8个只能用滑动
                maxRowCount = 8;
            }
            this.listView = new VerticalListControl(29);
            this.listView.Y = frameBack.Bottom;
            this.listView.BackgroundColor = UserCenterColor.Current.White;
            this.listView.Height = (ControlCommonResourse.ListViewRowHeight + Application.GetRealHeight(29)) * maxRowCount;
            bodyFrameLayout.AddChidren(this.listView);
            //设置中间部分信息
            this.SetMiddleInfo();
            //添加底部 添加报警目标的菜单行
            this.AddBottomAlarmTargetMenu();
            new System.Threading.Thread(() =>
            {
                //设置中间部分信息
                this.SetMiddleInfo(listData);
            })
            { IsBackground = true }.Start();
        }
        /// <summary>
        /// 设置中间部分信息
        /// </summary>
        public void SetMiddleInfo()
        public void SetMiddleInfo(List<Safeguard.CatActionResponseObj> listData)
        {
            this.listView.RemoveAll();
            //根据防区ID获取本地的报警目标列表
            var listData = Common.LocalSafeguard.Current.GetLocalAlarmTargetInfoByZoneId(this.zoonID);
            if (listData.Count > 0)
            if (this.Parent == null)
            {
                btnTitle.Visible = true;
                return;
            }
            new System.Threading.Thread(() =>
            //添加报警目标的明细行S
            Application.RunOnMainThread(() =>
            {
                //添加报警目标的明细行
                this.AddAlarmTargetList(listData);
            })
            { IsBackground = true }.Start();
                foreach (var data in listData)
                {
                    //场景
                    if (data.Type == 1)
                    {
                        this.AddSceneRow(data);
                    }
                    //设备
                    if (data.Type == 0)
                    {
                        CommonDevice device = Common.LocalDevice.Current.GetDevice(data.DeviceAddr, data.Epoint);
                        if (device != null)
                        {
                            this.AddDeviceRow(data, device);
                        }
                    }
                }
            });
        }
        #endregion
        #region ■ 报警目标菜单行_____________________
        /// <summary>
        /// 显示无报警目标特效
        /// </summary>
        private void ShowNotAlarmTargetAppeal()
        {
            var frameTemp = new FrameRowControl();
            frameTemp.Height = Application.GetRealHeight(173);
            frameTemp.BackgroundColor = UserCenterColor.Current.White;
            bodyFrameLayout.AddChidren(frameTemp);
            //添加目标
            var btnText = frameTemp.AddLeftCaption(Language.StringByID(R.MyInternationalizationString.uAddTarget), 400);
            btnText.TextSize = 15;
            //加号
            var btnAdd = frameTemp.AddMostRightEmptyIcon(58, 58);
            btnAdd.UnSelectedImagePath = "Item/Add.png";
            frameTemp.ButtonClickEvent += (sender, e) =>
            {
                var form = new AddAlarmTargetTypeListForm();
                form.AddForm(this.zoonID);
            };
        }
        /// <summary>
        /// 添加底部 添加报警目标的菜单行
        /// </summary>
        private void AddBottomAlarmTargetMenu()
        {
            //添加目标
            frameBottomAddRow = new FrameRowControl();
            frameBottomAddRow.Y = this.listView.Bottom;
            frameBottomAddRow.Height = ControlCommonResourse.ListViewRowHeight + Application.GetRealHeight(29 + 29);
            frameBottomAddRow.BackgroundColor = UserCenterColor.Current.White;
            bodyFrameLayout.AddChidren(frameBottomAddRow);
            var frameTemp = new FrameRowControl();
            frameTemp.Gravity = Gravity.CenterVertical;
            frameBottomAddRow.AddChidren(frameTemp);
            var btnText = frameTemp.AddLeftCaption(Language.StringByID(R.MyInternationalizationString.uAddTarget), 400);
            btnText.TextSize = 15;
            //加号
            var btnAdd = frameTemp.AddMostRightEmptyIcon(58, 58);
            btnAdd.UnSelectedImagePath = "Item/Add.png";
            //底线
            frameTemp.AddBottomLine();
            frameTemp.ButtonClickEvent += (sender, e) =>
            {
                var form = new AddAlarmTargetTypeListForm();
                form.AddForm(this.zoonID);
            };
        }
        #endregion
        #region ■ 报警目标明细行_____________________
        /// <summary>
        /// 添加报警目标的明细行
@@ -105,7 +207,10 @@
                {
                    Application.RunOnMainThread(() =>
                    {
                        this.AddDeviceRow(data);
                        if (this.Parent != null)
                        {
                            this.AddSceneRow(data);
                        }
                    });
                }
                //设备
@@ -120,9 +225,55 @@
                    Application.RunOnMainThread(() =>
                    {
                        this.AddSceneRow(data, device);
                        if (this.Parent != null)
                        {
                            this.AddDeviceRow(data, device);
                        }
                    });
                }
            }
        }
        /// <summary>
        /// 添加设备行
        /// </summary>
        /// <param name="data"></param>
        /// <param name="device"></param>
        private void AddDeviceRow(Safeguard.CatActionResponseObj data, CommonDevice device)
        {
            //行控件
            var row = new DeviceRoomControl(device, listView.rowSpace / 2);
            listView.AddChidren(row);
            row.InitControl();
            row.frameTable.UseClickStatu = false;
            //底线
            row.frameTable.AddBottomLine();
            //删除图标
            var btnDelete = row.frameTable.AddMostRightEmptyIcon(58, 58);
            btnDelete.UnSelectedImagePath = "Item/DeleteIcon1.png";
            row.frameTable.ChangedChidrenBindMode(btnDelete, ChidrenBindMode.NotBind);
            btnDelete.ButtonClickEvent += (sender, e) =>
            {
                //删除
                string msg = Language.StringByID(R.MyInternationalizationString.uShowDoDeleteMsg);
                this.ShowMassage(ShowMsgType.Confirm, msg, () =>
                {
                    //删除报警目标
                    this.DeleteAlarmTarget(row, data);
                });
            };
            //状态显示
            var btnStatu = row.frameTable.AddMostRightView("", 400);
            if (data.TaskList.Count > 0)
            {
                btnStatu.Text = HdlSafeguardLogic.Current.GetLightAlarmStatuText(data.TaskList);
            }
            else
            {
                //无动作
                btnStatu.TextID = R.MyInternationalizationString.uNotAction;
            }
        }
@@ -130,60 +281,42 @@
        /// 添加场景行
        /// </summary>
        /// <param name="data"></param>
        /// <param name="device"></param>
        private void AddSceneRow(Safeguard.CatActionResponseObj data, CommonDevice device)
        private void AddSceneRow(Safeguard.CatActionResponseObj data)
        {
            //行控件
            var row = new DeviceRoomViewRow(this.listView, device);
            //状态显示
            var btnStatu = new RowSecondRightTextView();
            row.AddChidren(btnStatu);
            if (data.TaskList.Count > 0)
            {
                btnStatu.Text = SafeguardLogic.GetLightAlarmStatuText(data.TaskList);
                btnStatu.TextColor = UserCenterColor.Current.Green;
            }
            else
            {
                //无动作
                btnStatu.TextID = R.MyInternationalizationString.uNotAction;
            }
            var row = new SceneRoomControl(data.ScenesId, data.ESName, listView.rowSpace / 2);
            listView.AddChidren(row);
            row.InitControl();
            row.frameTable.UseClickStatu = false;
            //底线
            row.frameTable.AddBottomLine();
            var btnDelete = new RowDeleteButton();
            row.AddRightView(btnDelete);
            btnDelete.MouseUpEventHandler += (sender, e) =>
            //删除图标
            var btnDelete = row.frameTable.AddMostRightEmptyIcon(58, 58);
            btnDelete.UnSelectedImagePath = "Item/DeleteIcon1.png";
            row.frameTable.ChangedChidrenBindMode(btnDelete, ChidrenBindMode.NotBind);
            btnDelete.ButtonClickEvent += (sender, e) =>
            {
                //删除
                string msg = Language.StringByID(R.MyInternationalizationString.uShowDoDeleteMsg);
                this.ShowConfirmMsg(msg, "DeleteAlarmTarget", row, data);
                this.ShowMassage(ShowMsgType.Confirm, msg, () =>
                {
                    //删除报警目标
                    this.DeleteAlarmTarget(row, data);
                });
            };
        }
        /// <summary>
        /// 添加设备行
        /// </summary>
        /// <param name="data"></param>
        private void AddDeviceRow(Safeguard.CatActionResponseObj data)
        {
            //行控件
            var row = new SceneRoomViewRow(this.listView, data.ScenesId, data.ESName);
        #endregion
            var btnDelete = new RowDeleteButton();
            row.AddRightView(btnDelete);
            btnDelete.MouseUpEventHandler += (sender, e) =>
            {
                //删除
                string msg = Language.StringByID(R.MyInternationalizationString.uShowDoDeleteMsg);
                this.ShowConfirmMsg(msg, "DeleteAlarmTarget", row, data);
            };
        }
        #region ■ 删除指定报警目标___________________
        /// <summary>
        /// 删除指定报警目标
        /// </summary>
        /// <param name="row"></param>
        /// <param name="delObj"></param>
        public async void DeleteAlarmTarget(StatuRowLayout row, Safeguard.CatActionResponseObj delObj)
        private async void DeleteAlarmTarget(RowLayoutControl row, Safeguard.CatActionResponseObj delObj)
        {
            //参数
            var Pra = new List<Safeguard.DelAlarmActionObj>();
@@ -198,7 +331,7 @@
            this.ShowProgressBar();
            //执行删除
            bool result = await Common.LocalSafeguard.Current.DeleteAlarmTaget(this.zoonID, Pra);
            bool result = await HdlSafeguardLogic.Current.DeleteAlarmTaget(this.zoonID, Pra);
            //关闭进度条
            this.CloseProgressBar();
@@ -211,12 +344,36 @@
            Application.RunOnMainThread(() =>
            {
                //行移除
                row.RemoveFromParent();
                if (listView.ChildrenCount == 0)
                row?.RemoveFromParent();
                if (listView != null && listView.ChildrenCount == 0)
                {
                    btnTitle.Visible = false;
                    //重新初始化中部信息
                    this.InitMiddleFrame();
                    return;
                }
                var realHeight = listView.ChildrenCount * listView.GetChildren(listView.ChildrenCount - 1).Height;
                if (realHeight < listView.Height)
                {
                    //缩小控件高度
                    listView.Height = realHeight;
                    //移动行控件
                    frameBottomAddRow.Y = this.listView.Bottom;
                }
            });
        }
        #endregion
        #region ■ 界面重新激活事件___________________
        /// <summary>
        /// 自身的上层界面关闭后,它自身处于最上层时,触发的事件
        /// </summary>
        public override void FormActionAgainEvent()
        {
            //重新刷新界面
            this.InitMiddleFrame();
        }
        #endregion
    }
}