黄学彪
2020-04-08 4dce704aaf8587cf3f91cf88f2208315a03c4cbb
ZigbeeApp/Shared/Phone/Category/AddOrEditorSceneForm.cs
@@ -3,6 +3,7 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using ZigBee.Device;
namespace Shared.Phone.Category
{
@@ -13,6 +14,10 @@
    {
        #region ■ 变量声明___________________________
        /// <summary>
        /// 场景变更事件(场景,房间ID)
        /// </summary>
        public Action<SceneUI, string> SceneChangedEvent = null;
        /// <summary>
        /// 修改的场景
        /// </summary>
@@ -26,9 +31,33 @@
        /// </summary>
        private string nowRoomId = string.Empty;
        /// <summary>
        /// 当前界面上显示的执行目标
        /// </summary>
        private List<Scene.DeviceListData> listAdjustTarget = null;
        /// <summary>
        /// 整个界面的上下滑动控件
        /// </summary>
        private VerticalFrameControl listBodyControl = null;
        /// <summary>
        /// 添加目标的的容器控件
        /// </summary>
        private FrameListControl frameTargetTableControl = null;
        /// <summary>
        /// 这个是加到【整个界面的上下滑动控件】中,促使界面能够滑动刚好超过【完成按钮】
        /// </summary>
        private FrameLayout frameBottomTemp = null;
        /// <summary>
        /// 场景图片显示控件(生成图片文件使用)
        /// </summary>
        private ImageView btnScenePic = null;
        /// <summary>
        /// 场景图片是否变更(针对编辑模式)
        /// </summary>
        private bool isScenePictrueChanged = false;
        /// <summary>
        /// 执行目标是否改变(针对编辑模式)
        /// </summary>
        private bool isAdjustTargetChanged = false;
        #endregion
@@ -47,6 +76,7 @@
            this.cloneScene = new SceneUI();
            if (i_editorScene != null)
            {
                cloneScene.Id = i_editorScene.Id;
                cloneScene.Name = i_editorScene.Name;
                cloneScene.IconPath = i_editorScene.IconPath;
                cloneScene.IconPathType = i_editorScene.IconPathType;
@@ -61,6 +91,8 @@
            }
            else
            {
                cloneScene.IconPath = "SceneIcon/0.png";
                listAdjustTarget = new List<Scene.DeviceListData>();
                //设置头部信息
                base.SetTitleText(Language.StringByID(R.MyInternationalizationString.AddScence));
            }
@@ -74,10 +106,44 @@
        /// </summary>
        private void InitMiddleFrame()
        {
            //整个界面的上下滑动控件
            this.listBodyControl = new VerticalFrameControl();
            listBodyControl.Height = bodyFrameLayout.Height;
            bodyFrameLayout.AddChidren(listBodyControl);
            //初始化场景图片
            this.InitScenePictureControl();
            //初始化信息编辑控件
            this.InitInfoEditorControl();
            //初始化添加目标
            this.InitAddTargetControl();
            //分享的场景不能保存
            if (this.editorScene == null || this.editorScene.IsSharedScene == false)
            {
                //完成
                var btnSave = new BottomClickButton();
                btnSave.TextID = R.MyInternationalizationString.uFinish;
                bodyFrameLayout.AddChidren(btnSave);
                btnSave.ButtonClickEvent += (sender, e) =>
                {
                    //保存场景数据
                    this.SaveSceneData();
                };
            }
        }
        #endregion
        #region ■ 初始化场景图片_____________________
        /// <summary>
        /// 初始化场景图片
        /// </summary>
        private void InitScenePictureControl()
        {
            //场景图片这部分的白色背景
            var framePicBack = new FrameLayout();
            framePicBack.Height = Application.GetRealHeight(559);
@@ -91,41 +157,43 @@
            btnShadow.UnSelectedImagePath = "Room/Room_Rectangle.png";
            framePicBack.AddChidren(btnShadow);
            //场景图片
            var btnPic = new ImageView();
            btnPic.Y = Application.GetRealHeight(46);
            btnPic.Width = Application.GetMinRealAverage(887);
            btnPic.Height = Application.GetMinRealAverage(444);
            btnPic.Radius = (uint)Application.GetRealHeight(17);
            btnPic.Gravity = Gravity.CenterHorizontal;
            this.btnScenePic = new ImageView();
            btnScenePic.Y = Application.GetRealHeight(46);
            btnScenePic.Width = Application.GetMinRealAverage(887);
            btnScenePic.Height = Application.GetMinRealAverage(444);
            btnScenePic.Radius = (uint)Application.GetRealHeight(17);
            btnScenePic.Gravity = Gravity.CenterHorizontal;
            if (this.editorScene == null)
            {
                btnPic.ImagePath = "SceneIcon/0.png";
                btnScenePic.ImagePath = "SceneIcon/0.png";
            }
            else if (this.editorScene.IconPathType == 0)
            {
                btnPic.ImagePath = this.editorScene.IconPath;
                btnScenePic.ImagePath = this.editorScene.IconPath;
            }
            else
            {
                btnPic.ImageBytes = Global.ReadFileByHomeId(this.editorScene.IconPath);
                btnScenePic.ImageBytes = Global.ReadFileByHomeId(this.editorScene.IconPath);
            }
            framePicBack.AddChidren(btnPic);
            framePicBack.AddChidren(btnScenePic);
            //图片遮罩
            var btnZhezhao = new FrameLayout();
            btnZhezhao.Width = btnPic.Width;
            btnZhezhao.Height = btnPic.Height;
            btnZhezhao.Y = btnPic.Y;
            btnZhezhao.Width = btnScenePic.Width;
            btnZhezhao.Height = btnScenePic.Height;
            btnZhezhao.Y = btnScenePic.Y;
            btnZhezhao.Gravity = Gravity.CenterHorizontal;
            btnZhezhao.Radius = btnPic.Radius;
            btnZhezhao.Radius = btnScenePic.Radius;
            framePicBack.AddChidren(btnZhezhao);
            btnZhezhao.MouseUpEventHandler += (sender, e) =>
            {
                //房间图片选择
                this.ScenePictrueSelect(btnPic);
            };
            //初始化信息编辑控件
            this.InitInfoEditorControl();
            //分享的场景不能编辑
            if (this.editorScene == null || this.editorScene.IsSharedScene == false)
            {
                btnZhezhao.MouseUpEventHandler += (sender, e) =>
                {
                    //房间图片选择
                    this.ScenePictrueSelect(btnScenePic);
                };
            }
        }
        #endregion
@@ -158,12 +226,705 @@
            rowScene.txtInput.PlaceholderText = Language.StringByID(R.MyInternationalizationString.PleaseInputSceneName);
            rowScene.Y = btnTitle.Bottom + Application.GetRealHeight(23);
            frameBack.AddChidren(rowScene);
            rowScene.InitControl();
            //底线
            rowScene.AddBottomLine();
            rowScene.txtInput.TextChangeEventHandler += (sender, value) =>
            {
                this.cloneScene.Name = value;
            };
            //所属区域
            var rowBelong = new BelongAreaControl();
            //rowBelong.Y= rowScene.Bottom+
            rowBelong.Y = rowScene.Bottom + Application.GetRealHeight(14);
            frameBack.AddChidren(rowBelong);
            rowBelong.InitControl(Language.StringByID(R.MyInternationalizationString.uBelongArea), this.nowRoomId);
            //分享的场景不能编辑
            if (this.editorScene == null || this.editorScene.IsSharedScene == false)
            {
                rowBelong.SelectRoomEvent += (selectId) =>
                {
                    this.nowRoomId = selectId;
                };
            }
        }
        #endregion
        #region ■ 初始化添加目标_____________________
        /// <summary>
        /// 初始化添加目标
        /// </summary>
        private void InitAddTargetControl()
        {
            if (this.frameTargetTableControl == null)
            {
                //添加目标的的容器控件
                this.frameTargetTableControl = new FrameListControl();
                frameTargetTableControl.Y = Application.GetRealHeight(1034);
                frameTargetTableControl.BackgroundColor = UserCenterColor.Current.White;
                frameTargetTableControl.Height = Application.GetRealHeight(346);
                this.listBodyControl.frameTable.AddChidren(frameTargetTableControl);
            }
            else
            {
                this.frameTargetTableControl?.RemoveAll();
                frameTargetTableControl.Height = Application.GetRealHeight(346);
            }
            //添加目标
            var rowAddTarget = new FrameRowControl(frameTargetTableControl.rowSpace / 2);
            rowAddTarget.UseClickStatu = false;
            rowAddTarget.Y = Application.GetRealHeight(46 - 12);
            frameTargetTableControl.AddChidren(rowAddTarget);
            rowAddTarget.AddLeftCaption(Language.StringByID(R.MyInternationalizationString.AddScentTargetAction), 600);
            //+号
            var btnAddIcon = rowAddTarget.AddMostRightEmptyIcon(61, 58);
            btnAddIcon.UnSelectedImagePath = "Item/Add.png";
            //底线
            rowAddTarget.AddBottomLine();
            rowAddTarget.ButtonClickEvent += (sender, e) =>
            {
                //显示添加目标菜单
                this.ShowAddTargetMenu();
            };
            HdlThreadLogic.Current.RunThread(async () =>
            {
                //从网关获取场景的执行目标
                var result = await this.GetSceneTargetList();
                //添加【执行目标行】
                this.AddTargetRow();
            });
        }
        #endregion
        #region ■ 获取及添加【目标行】_______________
        /// <summary>
        /// 添加【执行目标行】
        /// </summary>
        private void AddTargetRow()
        {
            //检测网关上的数据是否和本地一致
            for (int i = 0; i < this.listAdjustTarget.Count; i++)
            {
                if (listAdjustTarget[i].Type == 0)
                {
                    //设备
                    var device = Common.LocalDevice.Current.GetDevice(listAdjustTarget[i].DeviceAddr, listAdjustTarget[i].Epoint);
                    if (device == null)
                    {
                        //不显示这个不存在本地的设备
                        listAdjustTarget.RemoveAt(i);
                        i--;
                    }
                    continue;
                }
                else if (listAdjustTarget[i].Type == 1)
                {
                    //场景
                    var scene = HdlSceneLogic.Current.GetSceneUIBySceneId(listAdjustTarget[i].ElseScenesId);
                    if (scene == null)
                    {
                        //不显示这个不存在本地的设备
                        listAdjustTarget.RemoveAt(i);
                        i--;
                    }
                    continue;
                }
            }
            HdlThreadLogic.Current.RunMain(() =>
            {
                for (int i = 0; i < listAdjustTarget.Count; i++)
                {
                    if (listAdjustTarget[i].Type == 0)
                    {
                        //设备
                        this.AddDeviceTargetRow(listAdjustTarget[i], i, i != listAdjustTarget.Count - 1);
                    }
                    else if (listAdjustTarget[i].Type == 1)
                    {
                        //场景
                        this.AddSceneTargetRow(listAdjustTarget[i], i, i != listAdjustTarget.Count - 1);
                    }
                    else if (listAdjustTarget[i].Type == 2)
                    {
                        //延时
                        this.AddDelayTimeTargetRow(listAdjustTarget[i], i, i != listAdjustTarget.Count - 1);
                    }
                }
                //初始化促使界面能够刚好滑动超过保存按钮的控件
                this.InitFrameBottomTempControl();
                //调整执行目标的桌布高度
                this.AdjustTargetTableHeight();
            });
        }
        #endregion
        #region ■ 添加设备执行目标行_________________
        /// <summary>
        /// 添加设备执行目标行
        /// </summary>
        private void AddDeviceTargetRow(Scene.DeviceListData data, int index, bool addLine)
        {
            //设备
            var device = Common.LocalDevice.Current.GetDevice(data.DeviceAddr, data.Epoint);
            var rowDevice = new DeviceRoomControl(device, frameTargetTableControl.rowSpace / 2);
            rowDevice.MainKeys = index.ToString();
            this.frameTargetTableControl.AddChidren(rowDevice);
            //控件向右偏移
            rowDevice.frameTable.LeftOffset = Application.GetRealWidth(104) - ControlCommonResourse.XXLeft;
            rowDevice.InitControl();
            rowDevice.frameTable.UseClickStatu = false;
            //状态文本
            string statuText2 = HdlSafeguardLogic.Current.GetAdjustTargetStatuText(data.TaskList);
            var btnStatu = rowDevice.frameTable.AddMostRightView(statuText2, 400);
            if (addLine == true)
            {
                //底线
                rowDevice.frameTable.AddBottomLine();
            }
            //分享的场景不能编辑
            if (this.editorScene == null || this.editorScene.IsSharedScene == false)
            {
                //编辑
                var btnEditor = rowDevice.AddEditorControl();
                btnEditor.ButtonClickEvent += (sender, e) =>
                {
                    //隐藏右滑菜单
                    rowDevice.HideMenu();
                    if (device.Type == DeviceType.DimmableLight//调光器
                      || device.Type == DeviceType.ColorDimmableLight)//彩灯
                    {
                        var form = new UserCenter.Safety.AlarmTargetStatuSelectLightForm();
                        form.AddForm(device, data.TaskList);
                        form.FinishSelectEvent += (statuText, listInfo) =>
                        {
                            //执行目标已经改变
                            this.isAdjustTargetChanged = true;
                            if (listInfo.Count == 0) { statuText = string.Empty; }
                            btnStatu.Text = statuText;
                            //将新的执行目标添加入缓存
                            data.TaskList.Clear();
                            data.TaskList.AddRange(listInfo);
                        };
                    }
                    else if (device.Type == DeviceType.Thermostat)//空调
                    {
                        var form = new UserCenter.Safety.AlarmTargetStatuSelectAcForm();
                        form.AddForm(device, data.TaskList);
                        form.FinishSelectEvent += (statuText, listInfo) =>
                        {
                            //执行目标已经改变
                            this.isAdjustTargetChanged = true;
                            if (listInfo.Count == 0) { statuText = string.Empty; }
                            btnStatu.Text = statuText;
                            //将新的执行目标添加入缓存
                            data.TaskList.Clear();
                            data.TaskList.AddRange(listInfo);
                        };
                    }
                    else if (device.Type == DeviceType.WindowCoveringDevice)//窗帘
                    {
                        var form = new UserCenter.Safety.AlarmTargetStatuSelectCurtainForm();
                        form.AddForm(device, data.TaskList);
                        form.FinishSelectEvent += (statuText, listInfo) =>
                        {
                            //执行目标已经改变
                            this.isAdjustTargetChanged = true;
                            if (listInfo.Count == 0) { statuText = string.Empty; }
                            btnStatu.Text = statuText;
                            //将新的执行目标添加入缓存
                            data.TaskList.Clear();
                            data.TaskList.AddRange(listInfo);
                        };
                    }
                    else
                    {
                        //其他直接归为开关类
                        var form = new UserCenter.Safety.AlarmTargetStatuSelectSwitchForm();
                        form.AddForm(device, data.TaskList);
                        form.FinishSelectEvent += (statuText, listInfo) =>
                        {
                            //执行目标已经改变
                            this.isAdjustTargetChanged = true;
                            if (listInfo.Count == 0) { statuText = string.Empty; }
                            btnStatu.Text = statuText;
                            //将新的执行目标添加入缓存
                            data.TaskList.Clear();
                            data.TaskList.AddRange(listInfo);
                        };
                    }
                };
                //删除
                var btnDelete = rowDevice.AddDeleteControl();
                btnDelete.ButtonClickEvent += (sender, e) =>
                {
                    //隐藏右滑菜单
                    rowDevice.HideMenu();
                    //确认是否要删除?
                    string msg = Language.StringByID(R.MyInternationalizationString.uShowDoDeleteMsg);
                    this.ShowMassage(ShowMsgType.Confirm, msg, () =>
                    {
                        //执行目标已经改变
                        this.isAdjustTargetChanged = true;
                        //调整执行目标里面的全部坐标(删除的时候使用)
                        this.AdjustTargetLocation(rowDevice.MainKeys);
                        //移除
                        rowDevice.RemoveFromParent();
                        this.listAdjustTarget.Remove(data);
                        //调整执行目标的桌布高度
                        this.AdjustTargetTableHeight();
                    });
                };
            }
        }
        #endregion
        #region ■ 添加场景执行目标行_________________
        /// <summary>
        /// 添加场景执行目标行
        /// </summary>
        private void AddSceneTargetRow(Scene.DeviceListData data, int index, bool addLine)
        {
            //场景
            var scene = HdlSceneLogic.Current.GetSceneUIBySceneId(data.ElseScenesId);
            var rowScene = new SceneRoomControl(scene.Id, scene.Name, frameTargetTableControl.rowSpace / 2);
            rowScene.MainKeys = index.ToString();
            frameTargetTableControl.AddChidren(rowScene);
            //控件向右偏移
            rowScene.frameTable.LeftOffset = Application.GetRealWidth(104) - ControlCommonResourse.XXLeft;
            rowScene.InitControl();
            if (addLine == true)
            {
                //底线
                rowScene.frameTable.AddBottomLine();
            }
            rowScene.frameTable.UseClickStatu = false;
            //分享的场景不能编辑
            if (this.editorScene == null || this.editorScene.IsSharedScene == false)
            {
                //删除
                var btnDelete = rowScene.AddDeleteControl();
                btnDelete.ButtonClickEvent += (sender, e) =>
                {
                    //隐藏右滑菜单
                    rowScene.HideMenu();
                    //确认是否要删除?
                    string msg = Language.StringByID(R.MyInternationalizationString.uShowDoDeleteMsg);
                    this.ShowMassage(ShowMsgType.Confirm, msg, () =>
                    {
                        //执行目标已经改变
                        this.isAdjustTargetChanged = true;
                        //调整执行目标里面的全部坐标(删除的时候使用)
                        this.AdjustTargetLocation(rowScene.MainKeys);
                        //移除
                        rowScene.RemoveFromParent();
                        this.listAdjustTarget.Remove(data);
                        //调整执行目标的桌布高度
                        this.AdjustTargetTableHeight();
                    });
                };
            }
        }
        #endregion
        #region ■ 添加延时行_________________________
        /// <summary>
        /// 添加延时行
        /// </summary>
        private void AddDelayTimeTargetRow(Scene.DeviceListData data, int index, bool addLine)
        {
            string hourText = Language.StringByID(R.MyInternationalizationString.Hour);
            string minuText = Language.StringByID(R.MyInternationalizationString.Minute);
            string secondText = Language.StringByID(R.MyInternationalizationString.Second);
            //行控件
            var rowDelay = new RowLayoutControl(frameTargetTableControl.rowSpace / 2);
            rowDelay.MainKeys = index.ToString();
            frameTargetTableControl.AddChidren(rowDelay);
            //控件向右偏移
            rowDelay.frameTable.LeftOffset = Application.GetRealWidth(104) - ControlCommonResourse.XXLeft;
            rowDelay.frameTable.UseClickStatu = false;
            //图标
            var btnIcon = rowDelay.frameTable.AddLeftIcon();
            btnIcon.UnSelectedImagePath = "Item/Timer.png";
            //延时
            var btnDelay = rowDelay.frameTable.AddLeftCaption(Language.StringByID(R.MyInternationalizationString.Delay), 400);
            btnDelay.TextColor = UserCenterColor.Current.TextGrayColor3;
            //x小时x分钟x秒后
            string timeStr = this.GetTimeString(data.DelayTime, hourText, minuText, secondText);
            timeStr += Language.StringByID(R.MyInternationalizationString.Later);
            var btnStatu = rowDelay.frameTable.AddMostRightView(timeStr, 300);
            if (addLine == true)
            {
                //底线
                rowDelay.frameTable.AddBottomLine();
            }
            //分享的场景不能编辑
            if (this.editorScene == null || this.editorScene.IsSharedScene == false)
            {
                //编辑
                var btnEditor = rowDelay.AddEditorControl();
                btnEditor.ButtonClickEvent += (sender, e) =>
                {
                    //隐藏右滑菜单
                    rowDelay.HideMenu();
                    //延时时间选择
                    var form = new AdjustTargetAddDelayTimeForm();
                    form.AddForm(data.DelayTime);
                    form.FinishSelectEvent += (delayTime) =>
                    {
                        //执行目标已经改变
                        this.isAdjustTargetChanged = true;
                        data.DelayTime = delayTime;
                        //x小时x分钟x秒后
                        timeStr = this.GetTimeString(data.DelayTime, hourText, minuText, secondText);
                        btnStatu.Text = timeStr;
                    };
                };
                //删除
                var btnDelete = rowDelay.AddDeleteControl();
                btnDelete.ButtonClickEvent += (sender, e) =>
                {
                    //隐藏右滑菜单
                    rowDelay.HideMenu();
                    //确认是否要删除?
                    string msg = Language.StringByID(R.MyInternationalizationString.uShowDoDeleteMsg);
                    this.ShowMassage(ShowMsgType.Confirm, msg, () =>
                    {
                        //执行目标已经改变
                        this.isAdjustTargetChanged = true;
                        //调整执行目标里面的全部坐标(删除的时候使用)
                        this.AdjustTargetLocation(rowDelay.MainKeys);
                        //移除
                        rowDelay.RemoveFromParent();
                        this.listAdjustTarget.Remove(data);
                        //调整执行目标的桌布高度
                        this.AdjustTargetTableHeight();
                    });
                };
            }
        }
        /// <summary>
        /// 从网关获取场景的执行目标
        /// </summary>
        /// <returns></returns>
        private async System.Threading.Tasks.Task<bool> GetSceneTargetList()
        {
            if (this.editorScene == null || this.listAdjustTarget != null)
            {
                return true;
            }
            //打开进度条
            this.ShowProgressBar();
            //获取执行目标列表
            var listData = await HdlSceneLogic.Current.GetAdjustTargetList(this.editorScene);
            if (listData == null)
            {
                this.CloseProgressBar(ShowReLoadMode.YES);
                return false;
            }
            this.listAdjustTarget = new List<Scene.DeviceListData>();
            listAdjustTarget.AddRange(listData);
            this.CloseProgressBar();
            return true;
        }
        #endregion
        #region ■ 初始化促使界面滑动控件_____________
        /// <summary>
        /// 初始化促使界面能够刚好滑动超过保存按钮的控件
        /// </summary>
        private void InitFrameBottomTempControl()
        {
            if (this.frameBottomTemp != null)
            {
                return;
            }
            //借用一下控件的Y轴
            var btnTemp = new BottomClickButton();
            //那个特殊的控件
            this.frameBottomTemp = new FrameLayout();
            frameBottomTemp.Height = bodyFrameLayout.Height - btnTemp.Yaxis + Application.GetRealHeight(23);
            this.listBodyControl.AddChidrenFrame(frameBottomTemp);
        }
        #endregion
        #region ■ 显示添加目标菜单___________________
        /// <summary>
        /// 显示添加目标菜单
        /// </summary>
        private void ShowAddTargetMenu()
        {
            var menuContr = new BottomMenuSelectForm();
            menuContr.AddForm(3);
            //功能
            menuContr.AddMenu(Language.StringByID(R.MyInternationalizationString.uFunction), () =>
            {
                var form = new AdjustTargetAddDeviceForm();
                form.AddForm(listAdjustTarget);
                form.FinishSelectEvent += (dicData) =>
                {
                    //执行目标已经改变
                    this.isAdjustTargetChanged = true;
                    foreach (var mainKey in dicData.Keys)
                    {
                        var device = LocalDevice.Current.GetDevice(mainKey);
                        var data = new Scene.DeviceListData();
                        data.Type = 0;
                        data.DeviceAddr = device.DeviceAddr;
                        data.Epoint = device.DeviceEpoint;
                        data.TaskList = dicData[mainKey];
                        this.listAdjustTarget.Add(data);
                    }
                    //刷新列表控件
                    this.InitAddTargetControl();
                };
            });
            //场景
            menuContr.AddMenu(Language.StringByID(R.MyInternationalizationString.uScence), () =>
            {
                var form = new AdjustTargetAddSceneForm();
                form.AddForm(listAdjustTarget);
                form.FinishSelectEvent += (listSceneId) =>
                {
                    //执行目标已经改变
                    this.isAdjustTargetChanged = true;
                    foreach (int sceneId in listSceneId)
                    {
                        var data = new Scene.DeviceListData();
                        data.Type = 1;
                        data.ElseScenesId = sceneId;
                        this.listAdjustTarget.Add(data);
                    }
                    //刷新列表控件
                    this.InitAddTargetControl();
                };
            });
            //延时
            menuContr.AddMenu(Language.StringByID(R.MyInternationalizationString.Delay), () =>
            {
                //延时时间选择
                var form = new AdjustTargetAddDelayTimeForm();
                form.AddForm(0);
                form.FinishSelectEvent += (delayTime) =>
                {
                    //执行目标已经改变
                    this.isAdjustTargetChanged = true;
                    var data = new Scene.DeviceListData();
                    data.Type = 2;
                    data.DelayTime = delayTime;
                    this.listAdjustTarget.Add(data);
                    //刷新列表控件
                    this.InitAddTargetControl();
                };
            });
        }
        #endregion
        #region ■ 保存场景数据_______________________
        /// <summary>
        /// 保存场景数据
        /// </summary>
        private void SaveSceneData()
        {
            //检测能否保存场景
            if (this.CheckCanSaveScene() == false)
            {
                return;
            }
            HdlThreadLogic.Current.RunThread(() =>
            {
                //打开进度条
                this.ShowProgressBar();
                //新建场景
                if (this.editorScene == null)
                {
                    //保存新建的场景
                    this.SaveSceneDataByNewMode();
                }
                //编辑场景
                else
                {
                    //保存编辑的场景
                    this.SaveSceneDataByEditorMode();
                }
            });
        }
        /// <summary>
        /// 保存新建的场景
        /// </summary>
        private async void SaveSceneDataByNewMode()
        {
            //添加场景
            this.editorScene = await HdlSceneLogic.Current.AddNewSceneToGateway(this.cloneScene.Name, this.listAdjustTarget);
            //关闭进度条
            this.CloseProgressBar();
            if (editorScene == null)
            {
                return;
            }
            if (this.nowRoomId != string.Empty)
            {
                //添加房间
                var newRoom = HdlRoomLogic.Current.GetRoomById(this.nowRoomId);
                HdlSceneLogic.Current.AddSceneToRoom(newRoom, this.editorScene);
            }
            if (this.cloneScene.IconPathType != 0)
            {
                //自定义图片
                var tradeTime = DateTime.Now.ToString("yyyyMMddHHmmss");
                var fileName = $"SceneIcon_{tradeTime}.png";
                //生成文件图片
                IO.FileUtils.WriteFileByBytes(System.IO.Path.Combine(Config.Instance.FullPath, fileName), this.btnScenePic.ImageBytes);
                HdlAutoBackupLogic.AddOrEditorFile(fileName);
                this.cloneScene.IconPath = fileName;
            }
            //转移属性
            this.editorScene.Name = this.cloneScene.Name;
            this.editorScene.IconPathType = this.cloneScene.IconPathType;
            this.editorScene.IconPath = this.cloneScene.IconPath;
            this.editorScene.Save();
            HdlThreadLogic.Current.RunMain(() =>
            {
                //调用回调函数
                this.SceneChangedEvent?.Invoke(this.editorScene, this.nowRoomId);
                this.CloseForm();
            });
        }
        /// <summary>
        /// 保存编辑的场景
        /// </summary>
        private async void SaveSceneDataByEditorMode()
        {
            if (this.editorScene.Name != this.cloneScene.Name)
            {
                //修改名称
                var result = await HdlSceneLogic.Current.EditorSceneNameFromGateway(this.editorScene, this.cloneScene.Name);
                if (result == false)
                {
                    return;
                }
            }
            if (isAdjustTargetChanged == true)
            {
                //修改场景
                var result = await HdlSceneLogic.Current.EditorSceneFromGateway(this.editorScene, this.listAdjustTarget);
                //关闭进度条
                this.CloseProgressBar();
                if (result == false)
                {
                    return;
                }
            }
            if (this.nowRoomId != string.Empty)
            {
                //变更房间
                HdlSceneLogic.Current.ChangedSceneRoom(this.editorScene, this.nowRoomId);
            }
            //图片改变了
            if (isScenePictrueChanged == true)
            {
                if (this.editorScene.IconPathType != 0)
                {
                    //删除自定义图片
                    Shared.IO.FileUtils.DeleteFile(System.IO.Path.Combine(Config.Instance.FullPath, this.editorScene.IconPath));
                    HdlAutoBackupLogic.DeleteFile(this.editorScene.IconPath);
                }
                if (this.cloneScene.IconPathType != 0)
                {
                    //自定义图片
                    var tradeTime = DateTime.Now.ToString("yyyyMMddHHmmss");
                    var fileName = $"SceneIcon_{tradeTime}.png";
                    //生成文件图片
                    IO.FileUtils.WriteFileByBytes(System.IO.Path.Combine(Config.Instance.FullPath, fileName), this.btnScenePic.ImageBytes);
                    HdlAutoBackupLogic.AddOrEditorFile(fileName);
                    this.cloneScene.IconPath = fileName;
                }
            }
            //转移属性
            this.editorScene.Name = this.cloneScene.Name;
            this.editorScene.IconPathType = this.cloneScene.IconPathType;
            this.editorScene.IconPath = this.cloneScene.IconPath;
            this.editorScene.Save();
            HdlThreadLogic.Current.RunMain(() =>
            {
                //调用回调函数
                this.SceneChangedEvent?.Invoke(this.editorScene, this.nowRoomId);
                this.CloseForm();
            });
        }
        /// <summary>
        /// 检测能否保存场景
        /// </summary>
        /// <returns></returns>
        private bool CheckCanSaveScene()
        {
            if (this.cloneScene.Name == string.Empty)
            {
                //场景名不能为空
                this.ShowMassage(ShowMsgType.Remind, Language.StringByID(R.MyInternationalizationString.SceneNameCannotBeNull));
                return false;
            }
            bool hadTarget = false;
            foreach (var data in this.listAdjustTarget)
            {
                if (data.Type == 0 || data.Type == 1)
                {
                    //拥有执行目标
                    hadTarget = true;
                    break;
                }
            }
            if (hadTarget == false)
            {
                //请添加执行目标
                this.ShowMassage(ShowMsgType.Remind, Language.StringByID(R.MyInternationalizationString.uPleaseAddAdjustTarget));
                return false;
            }
            return true;
        }
        #endregion
@@ -195,6 +956,8 @@
                    this.cloneScene.IconPath = imgPath;
                    imgPath = IO.FileUtils.GetImageFilePath(imgPath);
                    imageContr.ImageBytes = IO.FileUtils.ReadFile(imgPath);
                    //场景图片已经改变
                    this.isScenePictrueChanged = true;
                };
            });
            //拍照
@@ -210,6 +973,9 @@
                    this.cloneScene.IconPathType = 1;
                    imageContr.ImageBytes = Shared.IO.FileUtils.ReadFile(imagePath);
                    System.IO.File.Delete(imagePath);
                    //场景图片已经改变
                    this.isScenePictrueChanged = true;
                }, "HdlPic", 2, 1);
            });
            //我的相册
@@ -225,6 +991,8 @@
                    this.cloneScene.IconPathType = 2;
                    imageContr.ImageBytes = Shared.IO.FileUtils.ReadFile(imagePath);
                    System.IO.File.Delete(imagePath);
                    //场景图片已经改变
                    this.isScenePictrueChanged = true;
                }, "HdlPic", 2, 1);
            });
@@ -232,8 +1000,104 @@
        #endregion
        #region ■ 界面关闭___________________________
        /// <summary>
        /// 界面关闭
        /// </summary>
        public override void CloseFormBefore()
        {
            this.SceneChangedEvent = null;
            base.CloseFormBefore();
        }
        #endregion
        #region ■ 一般方法___________________________
        /// <summary>
        /// 获取时间的翻译文本
        /// </summary>
        /// <param name="second"></param>
        /// <param name="hourText">小时的文本</param>
        /// <param name="minuText">分的文本</param>
        /// <param name="secondText">秒的文本</param>
        /// <returns></returns>
        private string GetTimeString(int second, string hourText, string minuText, string secondText)
        {
            string timeStr = string.Empty;
            int hour = second / 3600;
            int minu = second % 3600 / 60;
            int sec = second % 60;
            if (hour > 0)
            {
                timeStr += hour + hourText;
            }
            if (minu > 0)
            {
                timeStr += minu + minuText;
            }
            if (sec > 0)
            {
                timeStr += sec + secondText;
            }
            return timeStr;
        }
        /// <summary>
        /// 调整执行目标的桌布高度
        /// </summary>
        private void AdjustTargetTableHeight()
        {
            //调整桌布高度
            int minHeight = Application.GetRealHeight(346);
            int realHeight = frameTargetTableControl.GetChildren(frameTargetTableControl.ChildrenCount - 1).Bottom;
            realHeight += Application.GetRealHeight(23);
            if (realHeight > minHeight)
            {
                frameTargetTableControl.Height = realHeight;
            }
            else if (frameTargetTableControl.Height != minHeight)
            {
                frameTargetTableControl.Height = minHeight;
            }
            //这个特殊的东西必须放在执行目标容器的底部
            this.frameBottomTemp.Y = frameTargetTableControl.Bottom;
            //调整全局上下滑动控件的桌布高度
            this.listBodyControl.AdjustTableHeight();
        }
        /// <summary>
        /// 调整执行目标里面的全部坐标(删除的时候使用)
        /// </summary>
        /// <param name="mainKey">删除的主键</param>
        private void AdjustTargetLocation(string mainKey)
        {
            bool canChanged = false;
            int YY = 0;
            for (int i = 0; i < frameTargetTableControl.ChildrenCount; i++)
            {
                var myRow = frameTargetTableControl.GetChildren(i);
                if (canChanged == false && (myRow is RowLayoutControl))
                {
                    if (((RowLayoutControl)myRow).MainKeys == mainKey)
                    {
                        //已经到达要删除的索引
                        canChanged = true;
                        YY = frameTargetTableControl.GetChildren(i).Y;
                    }
                    continue;
                }
                if (canChanged == true)
                {
                    //它下面的行全部往上移
                    myRow.Y = YY;
                    YY = myRow.Bottom;
                }
            }
        }
        #endregion
    }
}