黄学彪
2020-09-18 c7df85937f73fb347ee0b19e9c052d2d00a6df6c
ZigbeeApp/Shared/Phone/UserCenter/Device/PirSensor/PirSensorBindTargetSettionForm.cs
@@ -52,7 +52,7 @@
        /// <param name="i_iasZone">传感器设备</param>
        public void ShowForm(IASZone i_iasZone)
        {
            UserView.HomePage.Instance.ScrollEnabled = false;
            this.ScrollEnabled = false;
            deviceIASZone = i_iasZone;
            //设置头部信息
@@ -94,11 +94,34 @@
            this.ClearBodyFrame();
            //当前亮度值
            string txtValue = Language.StringByID(R.MyInternationalizationString.uNowBrightnessValue);
            var frameNowLinght = new FrameRowControl();
            frameNowLinght.UseClickStatu = false;
            frameNowLinght.BackgroundColor = UserCenterColor.Current.White;
            bodyFrameLayout.AddChidren(frameNowLinght);
            frameNowLinght.AddLeftCaption(Language.StringByID(R.MyInternationalizationString.uNowBrightnessValue) + ":" + pirLuxValue + "lux", 900);
            var btnLux = frameNowLinght.AddLeftCaption(txtValue + ":" + pirLuxValue + "lux", 900);
            HdlThreadLogic.Current.RunThread(async () =>
            {
                //查看模板时,不允许编辑
                if (Common.Config.Instance.Home.IsShowTemplate == true)
                {
                    return;
                }
                while (this.Parent != null)
                {
                    //他们说这个东西要2秒刷新一次  获取PIR传感器的【lux值】
                    this.pirLuxValue = await HdlDevicePirSensorLogic.Current.GetPirSensorLux(deviceIASZone, ShowErrorMode.NO);
                    if (pirLuxValue != -1)
                    {
                        HdlThreadLogic.Current.RunMain(() =>
                        {
                            btnLux.Text = txtValue + ":" + pirLuxValue + "lux";
                        }, ShowErrorMode.NO);
                    }
                    await Task.Delay(2000);
                }
            }, ShowErrorMode.NO);
            var listView = new VerticalListControl(0);
            listView.Y = Application.GetRealHeight(150);
@@ -215,6 +238,14 @@
                this.pirConfigure.levelSize = seekBar.Progress;
                btnLightValue.Text = this.pirConfigure.levelSize.ToString() + "lux";
            };
            //查看模板时,不允许编辑
            if (Common.Config.Instance.Home.IsShowTemplate == true)
            {
                btnSwitch.CanClick = false;
                seekBar.Enable = false;
                btnMinus.CanClick = false;
                btnPlus.CanClick = false;
            }
            //暗
            var btnDark = new NormalViewControl(120, 50, true);
@@ -351,20 +382,31 @@
                }
            }
            //延时
            string strMinute = pirConfigure.transitionTime / 60 + Language.StringByID(R.MyInternationalizationString.uMinute);
            string strSecond = pirConfigure.transitionTime % 60 + Language.StringByID(R.MyInternationalizationString.uSecond);
            var rowDelay = new FrameRowControl(listView.rowSpace / 2);
            rowDelay.LeftOffset = Application.GetRealWidth(138) - ControlCommonResourse.XXLeft;
            frameResult.AddChidren(rowDelay);
            rowDelay.AddLeftCaption(Language.StringByID(R.MyInternationalizationString.uDelayed), 300);
            rowDelay.AddRightArrow();
            var btnDelayView = rowDelay.AddMostRightView(strMinute + strSecond, 700);
            rowDelay.ButtonClickEvent += (sender, e) =>
            //延时(半自动没有延时的概念)
            if (this.pirConfigure.mode == 1)
            {
                this.ShowDelayListTime(btnDelayView);
            };
                string strMinute = string.Empty;
                if (pirConfigure.transitionTime / 60 > 0)
                {
                    strMinute = pirConfigure.transitionTime / 60 + Language.StringByID(R.MyInternationalizationString.uMinute);
                }
                string strSecond = pirConfigure.transitionTime % 60 + Language.StringByID(R.MyInternationalizationString.uSecond);
                var rowDelay = new FrameRowControl(listView.rowSpace / 2);
                rowDelay.LeftOffset = Application.GetRealWidth(138) - ControlCommonResourse.XXLeft;
                frameResult.AddChidren(rowDelay);
                rowDelay.AddLeftCaption(Language.StringByID(R.MyInternationalizationString.uDelayed), 300);
                rowDelay.AddRightArrow();
                var btnDelayView = rowDelay.AddMostRightView(strMinute + strSecond, 700);
                rowDelay.ButtonClickEvent += (sender, e) =>
                {
                    this.ShowDelayListTime(btnDelayView);
                };
                //查看模板时,不允许编辑
                if (Common.Config.Instance.Home.IsShowTemplate == true)
                {
                    rowDelay.CanClick = false;
                }
            }
            //保存
            var btnSave = new BottomClickButton();
            btnSave.TextID = R.MyInternationalizationString.uSave;
@@ -377,6 +419,11 @@
                    this.SavePirSensorData();
                });
            };
            //查看模板时,不允许编辑
            if (Common.Config.Instance.Home.IsShowTemplate == true)
            {
                btnSave.CanClick = false;
            }
        }
        #endregion
@@ -393,7 +440,7 @@
            this.ShowProgressBar();
            //获取绑定目标设备
            List<CommonDevice> listDevice = await HdlDeviceBindLogic.Current.GetBindTargetDevice(this.deviceIASZone);
            List<CommonDevice> listDevice = HdlDeviceBindLogic.Current.GetBindTargetDevice(this.deviceIASZone);
            if (listDevice == null)
            {
                //关闭进度条
@@ -403,7 +450,11 @@
            this.listEsixtDevice.Clear();
            foreach (var device in listDevice)
            {
                this.listEsixtDevice.Add(Common.LocalDevice.Current.GetDeviceMainKeys(device));
                string mainKeys = Common.LocalDevice.Current.GetDeviceMainKeys(device);
                if (listEsixtDevice.Contains(mainKeys) == false)
                {
                    listEsixtDevice.Add(mainKeys);
                }
            }
            //获取PIR传感器的【光感等级总刻度】
            this.lightLevelCount = await HdlDevicePirSensorLogic.Current.GetPirLightAbilitySize(this.deviceIASZone);
@@ -419,7 +470,7 @@
            }
            //获取pir的配置信息
            this.pirConfigure = await HdlDevicePirSensorLogic.Current.GetPirSensorLightSettion(deviceIASZone);
            this.pirConfigure = HdlDevicePirSensorLogic.Current.GetPirSensorLightSettion(deviceIASZone);
            if (pirConfigure == null)
            {
                //关闭进度条
@@ -491,7 +542,13 @@
            PickerView.ShowSecondary(listfirst, listSecond, (value1, value2) =>
             {
                 btnTime.Text = listfirst[value1] + listSecond[value1][value2];
                 string textValue = listSecond[value1][value2];
                 if (value1 != 0)
                 {
                     textValue = listfirst[value1].TrimStart('0') + textValue;
                 }
                 btnTime.Text = textValue;
                 int minute = Convert.ToInt32(listfirst[value1].Substring(0, 2));
                 int second = Convert.ToInt32(listSecond[value1][value2].Substring(0, 2));
                 int delaySecond = minute * 60 + second;
@@ -512,7 +569,7 @@
        /// <summary>
        /// 保存Pir传感器数据
        /// </summary>
        private async void SavePirSensorData()
        private void SavePirSensorData()
        {
            if (this.isDataChanged == false)
            {
@@ -531,44 +588,80 @@
            {
                //删除绑定目标
                var listDelDevice = new List<CommonDevice>();
                var listLightDevice = new List<CommonDevice>();
                foreach (string mainKey in listEsixtDevice)
                {
                    if (this.listSaveDevice.Contains(mainKey) == false)
                    {
                        listDelDevice.Add(Common.LocalDevice.Current.GetDevice(mainKey));
                        var myDevice = Common.LocalDevice.Current.GetDevice(mainKey);
                        listDelDevice.Add(myDevice);
                        if (myDevice.Type == DeviceType.DimmableLight)
                        {
                            //如果是调光器的话,特殊一点
                            listLightDevice.Add(myDevice);
                        }
                    }
                }
                if (listDelDevice.Count > 0)
                {
                    //删除目标
                    var listSucess = await HdlDeviceBindLogic.Current.DeleteDeviceTarget(deviceIASZone, listDelDevice);
                    var listSucess = HdlDeviceBindLogic.Current.DeleteDeviceTarget(deviceIASZone, listDelDevice);
                    if (listSucess == null || listSucess.Count == 0)
                    {
                        //关闭进度条
                        this.CloseProgressBar();
                        return;
                    }
                    if (listLightDevice.Count > 0)
                    {
                        //删除调光器镞
                        listSucess = HdlDeviceBindLogic.Current.DeleteDeviceTarget(deviceIASZone, listLightDevice, 8);
                        if (listSucess == null || listSucess.Count == 0)
                        {
                            //关闭进度条
                            this.CloseProgressBar();
                            return;
                        }
                    }
                }
                //绑定目标
                var listBind = new List<CommonDevice>();
                listLightDevice = new List<CommonDevice>();
                foreach (var mainKey in listSaveDevice)
                {
                    listBind.Add(Common.LocalDevice.Current.GetDevice(mainKey));
                    var myDevice = Common.LocalDevice.Current.GetDevice(mainKey);
                    listBind.Add(myDevice);
                    if (myDevice.Type == DeviceType.DimmableLight)
                    {
                        //如果是调光器的话,特殊一点
                        listLightDevice.Add(myDevice);
                    }
                }
                if (listSaveDevice.Count > 0)
                {
                    //绑定目标
                    var listSucess = await HdlDeviceBindLogic.Current.BindDeviceTarget(deviceIASZone, listBind);
                    var listSucess = HdlDeviceBindLogic.Current.BindDeviceTarget(deviceIASZone, listBind);
                    if (listSucess == null || listSucess.Count == 0)
                    {
                        //关闭进度条
                        this.CloseProgressBar();
                        return;
                    }
                    if (listLightDevice.Count > 0)
                    {
                        //绑定调光镞
                        listSucess = HdlDeviceBindLogic.Current.BindDeviceTarget(deviceIASZone, listLightDevice, 8);
                        if (listSucess == null || listSucess.Count == 0)
                        {
                            //关闭进度条
                            this.CloseProgressBar();
                            return;
                        }
                    }
                }
            }
            //保存pir配置信息
            var result = await HdlDevicePirSensorLogic.Current.SetPirSensorSettion(this.deviceIASZone, this.pirConfigure);
            var result = HdlDevicePirSensorLogic.Current.SetPirSensorSettion(this.deviceIASZone, this.pirConfigure);
            if (result == false)
            {
                //关闭进度条
@@ -588,15 +681,6 @@
        #endregion
        #region ■ 一般方法___________________________
        /// <summary>
        /// 界面关闭
        /// </summary>
        public override void CloseFormBefore()
        {
            UserView.HomePage.Instance.ScrollEnabled = true;
            base.CloseFormBefore();
        }
        #endregion
    }