xm
2020-07-21 9a4b76398009cf76c508d61f7e48fb6f5cb7ac2d
ZigbeeApp/Shared/Phone/UserCenter/Safety/AlarmTargetStatuSelectSwitchForm.cs
New file
@@ -0,0 +1,265 @@
using System;
using System.Collections.Generic;
using System.Text;
using ZigBee.Device;
namespace Shared.Phone.UserCenter.Safety
{
    /// <summary>
    /// 开关类的安防报警设置界面
    /// </summary>
    public class AlarmTargetStatuSelectSwitchForm : DialogCommonForm
    {
        #region ■ 变量声明___________________________
        /// <summary>
        /// 结束选择的事件(key:全部状态的翻译文本)
        /// </summary>
        public Action<string, List<Safeguard.TaskListInfo>> FinishSelectEvent = null;
        /// <summary>
        /// 动作信息  0关闭/ 1打开
        /// </summary>
        private Dictionary<int, Safeguard.TaskListInfo> dicTaskinfo = new Dictionary<int, Safeguard.TaskListInfo>();
        #endregion
        #region ■ 初始化_____________________________
        /// <summary>
        /// 画面显示(底层会固定调用此方法,借以完成画面创建)
        /// </summary>
        /// <param name="device"></param>
        /// <param name="i_listTaskInfo"></param>
        public void ShowForm(CommonDevice device, List<Safeguard.TaskListInfo> i_listTaskInfo)
        {
            if (i_listTaskInfo != null)
            {
                foreach (var data in i_listTaskInfo)
                {
                    //以防万一,剔除不合法数据
                    if (data.TaskType == 1)
                    {
                        dicTaskinfo[data.Data1] = data;
                    }
                }
            }
            //初始化中部信息
            this.InitMiddleFrame(device);
        }
        /// <summary>
        /// 初始化中部信息
        /// </summary>
        private void InitMiddleFrame(CommonDevice device)
        {
            //弧度的圆的一半的高度(固定)
            int halfRoundHeigth = Application.GetRealHeight(116) / 2;
            //搞一个透明的框
            var frameTransparent = new FrameLayout();
            frameTransparent.Y = Application.GetRealHeight(1391);
            frameTransparent.Height = Application.GetRealHeight(600);//高度就是要它超过,随便搞的
            frameTransparent.BackgroundColor = UserCenterColor.Current.Transparent;
            bodyFrameLayout.AddChidren(frameTransparent);
            //瞎搞的一个白框,用来挡住头部半弧度
            var frameBack = new FrameLayout();
            frameBack.Y = halfRoundHeigth;
            frameBack.BackgroundColor = UserCenterColor.Current.White;
            frameBack.Height = Application.GetRealHeight(300);
            frameTransparent.AddChidren(frameBack);
            //弧度的圆
            var rowRound = new FrameLayout();
            rowRound.Width = bodyFrameLayout.Width;
            rowRound.Height = halfRoundHeigth * 2;
            rowRound.BackgroundColor = UserCenterColor.Current.White;
            rowRound.Radius = (uint)halfRoundHeigth;
            frameTransparent.AddChidren(rowRound);
            //头部信息
            var btnTitle = new NormalViewControl(frameTransparent.Width, Application.GetRealHeight(70), false);
            btnTitle.Y = Application.GetRealHeight(28);
            btnTitle.Text = Common.LocalDevice.Current.GetDeviceEpointName(device);
            btnTitle.TextColor = UserCenterColor.Current.TextColor4;
            btnTitle.TextSize = 16;
            btnTitle.TextAlignment = TextAlignment.Center;
            rowRound.AddChidren(btnTitle);
            //取消
            var btnCancel = new NormalViewControl(200, 60, true);
            btnCancel.X = Application.GetRealWidth(81);
            btnCancel.Y = Application.GetRealHeight(38);
            btnCancel.TextColor = UserCenterColor.Current.TextGrayColor1;
            btnCancel.TextID = R.MyInternationalizationString.uCancel;
            rowRound.AddChidren(btnCancel);
            btnCancel.ButtonClickEvent += (sender, e) =>
            {
                this.CloseForm();
            };
            //完成
            var btnFinish = new NormalViewControl(200, 60, true);
            btnFinish.X = Application.GetRealWidth(800);
            btnFinish.Y = Application.GetRealHeight(38);
            btnFinish.TextAlignment = TextAlignment.CenterRight;
            btnFinish.TextColor = 0xfffb744a;
            btnFinish.TextID = R.MyInternationalizationString.uFinish;
            rowRound.AddChidren(btnFinish);
            //线
            var btnLine1 = new NormalViewControl(frameTransparent.Width, ControlCommonResourse.BottomLineHeight, false);
            btnLine1.Y = Application.GetRealHeight(138);
            btnLine1.BackgroundColor = UserCenterColor.Current.ButtomLine;
            frameTransparent.AddChidren(btnLine1);
            //明细列表的桌布,白色背景
            var detailBackFrame = new FrameLayout();
            detailBackFrame.Y = btnLine1.Bottom;
            detailBackFrame.Height = Application.GetRealHeight(700);//随便定的
            detailBackFrame.BackgroundColor = UserCenterColor.Current.White;
            frameTransparent.AddChidren(detailBackFrame);
            //百分比
            var btnPersent = new NormalViewControl(150, 50, true);
            btnPersent.Y = Application.GetRealHeight(196);
            btnPersent.Gravity = Gravity.CenterHorizontal;
            btnPersent.TextAlignment = TextAlignment.Center;
            btnPersent.TextColor = UserCenterColor.Current.TextGrayColor2;
            btnPersent.TextSize = 12;
            detailBackFrame.AddChidren(btnPersent);
            //开
            var rowOpen = new FrameRowControl();
            rowOpen.Y = Application.GetRealHeight(69);
            rowOpen.LeftOffset = Application.GetRealWidth(81) - ControlCommonResourse.XXLeft;
            rowOpen.RightOffset = ControlCommonResourse.XXLeft - Application.GetRealWidth(81);
            detailBackFrame.AddChidren(rowOpen);
            var btnOpen = rowOpen.AddLeftCaption(Language.StringByID(R.MyInternationalizationString.uSimpleOpen), 400);
            btnOpen.TextColor = UserCenterColor.Current.TextGrayColor3;
            var btnOpenSelect = rowOpen.AddMostRightEmptyIcon(58, 58);
            btnOpenSelect.UnSelectedImagePath = "Item/ItemSelected.png";
            btnOpenSelect.Visible = false;
            //底线
            rowOpen.AddBottomLine();
            //关
            var rowClose = new FrameRowControl();
            rowClose.Y = rowOpen.Bottom + Application.GetRealHeight(12);
            rowClose.LeftOffset = Application.GetRealWidth(81) - ControlCommonResourse.XXLeft;
            rowClose.RightOffset = ControlCommonResourse.XXLeft - Application.GetRealWidth(81);
            detailBackFrame.AddChidren(rowClose);
            var btnClose = rowClose.AddLeftCaption(Language.StringByID(R.MyInternationalizationString.uSimpleClose), 400);
            btnClose.TextColor = UserCenterColor.Current.TextGrayColor3;
            var btnCloseSelect = rowClose.AddMostRightEmptyIcon(58, 58);
            btnCloseSelect.UnSelectedImagePath = "Item/ItemSelected.png";
            btnCloseSelect.Visible = false;
            //点击开
            rowOpen.ButtonClickEvent += (sender, e) =>
            {
                if (btnOpenSelect.Visible == true)
                {
                    //取消,开 不可用
                    btnOpenSelect.Visible = false;
                    btnOpen.TextColor = UserCenterColor.Current.TextGrayColor3;
                    dicTaskinfo.Remove(1);
                }
                else
                {
                    //选择图标切换
                    btnOpenSelect.Visible = true;
                    btnCloseSelect.Visible = false;
                    //开 可用
                    btnOpen.TextColor = UserCenterColor.Current.TextColor1;
                    //关 不可用
                    btnClose.TextColor = UserCenterColor.Current.TextGrayColor3;
                    //移除关闭
                    dicTaskinfo.Remove(0);
                    dicTaskinfo[1] = new Safeguard.TaskListInfo();
                    dicTaskinfo[1].TaskType = 1;
                    dicTaskinfo[1].Data1 = 1;
                }
            };
            //点击关
            rowClose.ButtonClickEvent += (sender, e) =>
            {
                if (btnCloseSelect.Visible == true)
                {
                    //取消,关 不可用
                    btnCloseSelect.Visible = false;
                    btnClose.TextColor = UserCenterColor.Current.TextGrayColor3;
                    dicTaskinfo.Remove(0);
                }
                else
                {
                    //选择图标切换
                    btnCloseSelect.Visible = true;
                    btnOpenSelect.Visible = false;
                    //关 可用
                    btnClose.TextColor = UserCenterColor.Current.TextColor1;
                    //开 不可用
                    btnOpen.TextColor = UserCenterColor.Current.TextGrayColor3;
                    //移除打开
                    dicTaskinfo.Remove(1);
                    dicTaskinfo[0] = new Safeguard.TaskListInfo();
                    dicTaskinfo[0].TaskType = 1;
                    dicTaskinfo[0].Data1 = 0;
                }
            };
            //设置开的默认值
            if (dicTaskinfo.ContainsKey(1) == true)
            {
                rowOpen.ButtonClickEvent?.Invoke(null, null);
            }
            //设置关的默认值
            if (dicTaskinfo.ContainsKey(0) == true)
            {
                rowClose.ButtonClickEvent?.Invoke(null, null);
            }
            //完成事件
            btnFinish.ButtonClickEvent += (sender, e) =>
            {
                var listData = new List<Safeguard.TaskListInfo>();
                foreach (var data in dicTaskinfo.Values)
                {
                    listData.Add(data);
                }
                dicTaskinfo = null;
                //获取状态的显示文本
                string statuText = HdlSafeguardLogic.Current.GetAdjustTargetStatuText(listData);
                this.FinishSelectEvent(statuText, listData);
                this.CloseForm();
            };
        }
        #endregion
        #region ■ 界面关闭___________________________
        /// <summary>
        /// 界面关闭
        /// </summary>
        public override void CloseFormBefore()
        {
            this.FinishSelectEvent = null;
            base.CloseFormBefore();
        }
        #endregion
    }
}