From a4924de3136289d10cabbf2f61a228387d44ded7 Mon Sep 17 00:00:00 2001
From: gxc <guoxuecheng@guoxuechengdeMacBook-Pro.local>
Date: 星期四, 07 十一月 2019 13:48:36 +0800
Subject: [PATCH] Merge branch 'dev-tzy' into DEV_GXC

---
 ZigbeeApp/Shared/Phone/UserCenter/Device/PirSensor/PirSensorBindTargetSettionForm.cs |  467 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 467 insertions(+), 0 deletions(-)

diff --git a/ZigbeeApp/Shared/Phone/UserCenter/Device/PirSensor/PirSensorBindTargetSettionForm.cs b/ZigbeeApp/Shared/Phone/UserCenter/Device/PirSensor/PirSensorBindTargetSettionForm.cs
new file mode 100755
index 0000000..9fd6a4f
--- /dev/null
+++ b/ZigbeeApp/Shared/Phone/UserCenter/Device/PirSensor/PirSensorBindTargetSettionForm.cs
@@ -0,0 +1,467 @@
+锘縰sing System;
+using System.Collections.Generic;
+using System.Text;
+using System.Threading.Tasks;
+using ZigBee.Device;
+
+namespace Shared.Phone.UserCenter.DevicePirSensor
+{
+    /// <summary>
+    /// PIR浼犳劅鍣ㄧ粦瀹氱晫闈⑩槄
+    /// </summary>
+    public class PirSensorBindTargetSettionForm : EditorCommonForm
+    {
+        #region 鈻� 鍙橀噺澹版槑___________________________
+
+        /// <summary>
+        /// 浼犳劅鍣ㄨ澶�
+        /// </summary>
+        private IASZone deviceIASZone = null;
+        /// <summary>
+        /// 宸茬粡瀛樺湪鐨勭粦瀹氳澶�
+        /// </summary>
+        private List<string> listEsixtDevice = new List<string>();
+        /// <summary>
+        /// 闇�瑕佷繚瀛樼殑璁惧瀵硅薄
+        /// </summary>
+        private List<string> listSaveDevice = null;
+        /// <summary>
+        /// PIR浼犳劅鍣ㄥ厜鐓х瓑绾ф�诲埢搴�
+        /// </summary>
+        private int lightLevelCount = -1;
+        /// <summary>
+        /// 鐏厜鐨勯厤缃�
+        /// </summary>
+        private IASZone.ConfigureParamates Lightconfigure = null;
+        /// <summary>
+        /// 鏃ф暟鎹�
+        /// </summary>
+        private List<int> listOldData = new List<int>();
+
+        #endregion
+
+        #region 鈻� 鍒濆鍖朹____________________________
+
+        /// <summary>
+        /// 鐢婚潰鏄剧ず(搴曞眰浼氬浐瀹氳皟鐢ㄦ鏂规硶锛屽�熶互瀹屾垚鐢婚潰鍒涘缓)
+        /// </summary>
+        /// <param name="i_iasZone">浼犳劅鍣ㄨ澶�</param>
+        public void ShowForm(IASZone i_iasZone)
+        {
+            deviceIASZone = i_iasZone;
+
+            //璁剧疆澶撮儴淇℃伅
+            base.SetTitleText(Language.StringByID(R.MyInternationalizationString.uBindTargets));
+
+            HdlThreadLogic.Current.RunThread(() =>
+            {
+                //鍒濆鍖栦腑閮ㄤ俊鎭�
+                this.InitMiddleFrame();
+            });
+        }
+
+        /// <summary>
+        /// 鍒濆鍖栦腑閮ㄤ俊鎭�
+        /// </summary>
+        private async void InitMiddleFrame()
+        {
+            this.listEsixtDevice.Clear();
+
+            var result = await this.GetDeviceAllDefultData();
+            if (result == false)
+            {
+                //鏄剧ず閲嶆柊鍔犺浇鐨勭晫闈�
+                this.ShowReLoadView();
+                return;
+            }
+
+            HdlThreadLogic.Current.RunMain(() =>
+            {
+                //鍒濆鍖栨帶浠�
+                this.InitMiddleControl();
+            });
+        }
+
+        /// <summary>
+        /// 鍒濆鍖栨帶浠�
+        /// </summary>
+        private void InitMiddleControl()
+        {
+            //娓呯┖bodyFrame
+            this.ClearBodyFrame();
+
+            var listView = new VerticalListControl(23);
+            listView.Height = bodyFrameLayout.Height;
+            listView.BackgroundColor = UserCenterColor.Current.White;
+            bodyFrameLayout.AddChidren(listView);
+
+            //鐓ф槑绛夌骇Frame(鍥犲睍寮�鎶樺彔,浼樺厛澹版槑)
+            var frameLight = new FrameLayout();
+            frameLight.Height = Application.GetRealHeight(363);
+
+            //濡傛灉婊¤冻-----------------------------------------------------------
+            var frameIfRow = new FrameRowControl(listView.rowSpace / 2);
+            frameIfRow.UseClickStatu = false;
+            listView.AddChidren(frameIfRow);
+            frameIfRow.AddLeftCaption(Language.StringByID(R.MyInternationalizationString.uIfSatisfied), 600);
+            //鍙崇澶�
+            var btnIfRinght = frameIfRow.AddMostRightEmptyIcon(58, 58);
+            frameIfRow.ChangedChidrenBindMode(btnIfRinght, ChidrenBindMode.NotBind);
+            btnIfRinght.UseClickStatu = false;
+            btnIfRinght.UnSelectedImagePath = "Item/Next.png";
+            btnIfRinght.SelectedImagePath = "Item/Down.png";
+            btnIfRinght.IsSelected = true;
+            btnIfRinght.ButtonClickEvent += (sender, e) =>
+            {
+                btnIfRinght.IsSelected = !btnIfRinght.IsSelected;
+                //灞曞紑鎶樺彔
+                frameLight.Height = frameLight.Height > 10 ? 0 : Application.GetRealHeight(363);
+            };
+            //搴曠嚎
+            frameIfRow.AddBottomLine();
+
+            listView.AddChidren(frameLight);
+            //鐓ф槑绛夌骇
+            var btnLight = new NormalViewControl(500, 50, true);
+            btnLight.TextID = R.MyInternationalizationString.uLightLevel;
+            btnLight.TextSize = 12;
+            btnLight.TextColor = UserCenterColor.Current.TextGrayColor1;
+            btnLight.X = Application.GetRealWidth(138);
+            btnLight.Y = Application.GetRealHeight(58);
+            frameLight.AddChidren(btnLight);
+            //杩涘害鏉�
+            var seekBar = new HorizontalSeekBar();
+            seekBar.X = Application.GetRealWidth(138);
+            seekBar.Y = Application.GetRealHeight(152);
+            seekBar.Width = Application.GetRealWidth(884);
+            seekBar.Height = Application.GetRealHeight(84);
+            seekBar.Max = lightLevelCount - 1;
+            seekBar.BackgroundColor = 0xfff5f5f5;
+            seekBar.ThumbColor = Common.ZigbeeColor.Current.GXCButtonBlueColor;
+            seekBar.ProgressColor = 0xfffdb500;
+            seekBar.Progress = lightLevelCount - Lightconfigure.levelSize;
+            frameLight.AddChidren(seekBar);
+            seekBar.ProgressChanged += (sender, value) =>
+            {
+                //鍥犱负瀹冪殑绛夌骇鍒诲害浠庡乏寰�鍙虫槸浠庡ぇ鍒板皬鐨�
+                this.Lightconfigure.levelSize = lightLevelCount - value;
+            };
+
+            //浣�
+            var btnDown = new NormalViewControl(300, 50, true);
+            btnDown.TextID = R.MyInternationalizationString.uLow;
+            btnDown.TextSize = 12;
+            btnDown.TextColor = UserCenterColor.Current.TextGrayColor3;
+            btnDown.X = Application.GetRealWidth(138);
+            btnDown.Y = btnLight.Bottom + Application.GetRealHeight(115);
+            frameLight.AddChidren(btnDown);
+            //楂�
+            var btnUp = new NormalViewControl(300, 50, true);
+            btnUp.TextID = R.MyInternationalizationString.uHigh;
+            btnUp.TextSize = 12;
+            btnUp.TextColor = UserCenterColor.Current.TextGrayColor3;
+            btnUp.TextAlignment = TextAlignment.CenterRight;
+            btnUp.X = frameLight.Width - ControlCommonResourse.XXLeft - Application.GetRealWidth(300);
+            btnUp.Y = btnDown.Y;
+            frameLight.AddChidren(btnUp);
+            //搴曠嚎
+            var btnIfLine = new NormalViewControl(seekBar.Width, ControlCommonResourse.BottomLineHeight, false);
+            btnIfLine.X = btnDown.X;
+            btnIfLine.Y = btnDown.Bottom + Application.GetRealHeight(69);
+            btnIfLine.BackgroundColor = UserCenterColor.Current.ButtomLine;
+            frameLight.AddChidren(btnIfLine);
+
+            //鎵ц瀵硅薄鐨凢rame(鍥犲睍寮�鎶樺彔,浼樺厛澹版槑)
+            var frameResult = new FrameListControl(23);
+            frameResult.Height = Application.GetRealHeight(310);
+
+            //灏变細--------------------------------------------------
+            var frameDo = new FrameRowControl(listView.rowSpace / 2);
+            frameDo.UseClickStatu = false;
+            listView.AddChidren(frameDo);
+            frameDo.AddLeftCaption(Language.StringByID(R.MyInternationalizationString.uResultDo), 600);
+            //鍙崇澶�
+            var btnResultRight = frameDo.AddMostRightEmptyIcon(58, 58);
+            frameDo.ChangedChidrenBindMode(btnResultRight, ChidrenBindMode.NotBind);
+            btnResultRight.UseClickStatu = false;
+            btnResultRight.UnSelectedImagePath = "Item/Next.png";
+            btnResultRight.SelectedImagePath = "Item/Down.png";
+            btnResultRight.IsSelected = true;
+            btnResultRight.ButtonClickEvent += (sender, e) =>
+            {
+                btnResultRight.IsSelected = !btnResultRight.IsSelected;
+                //灞曞紑鎶樺彔
+                frameResult.Height = frameResult.Height > 10 ? 0 : Application.GetRealHeight(310);
+            };
+            //搴曠嚎
+            frameDo.AddBottomLine();
+
+            listView.AddChidren(frameResult);
+            //瑙﹀彂鐩爣
+            var rowTarget = new FrameRowControl(listView.rowSpace / 2);
+            rowTarget.LeftOffset = Application.GetRealWidth(138) - ControlCommonResourse.XXLeft;
+            frameResult.AddChidren(rowTarget);
+            rowTarget.AddLeftCaption(Language.StringByID(R.MyInternationalizationString.uTriggerTarget), 600);
+            rowTarget.AddRightArrow();
+            var btnTargetView = rowTarget.AddMostRightView("", 700);
+            rowTarget.ButtonClickEvent += (sender, e) =>
+            {
+                var form = new PirSensorTargetSelectForm();
+                form.AddForm(listSaveDevice == null ? listEsixtDevice : listSaveDevice);
+                form.FinishSelectEvent += (listSelect) =>
+                {
+                    listSaveDevice = new List<string>();
+                    listSaveDevice.AddRange(listSelect);
+                    if (listSaveDevice.Count > 0)
+                    {
+                        //闅忎究涓竴涓悕瀛椾笂鍘�
+                        var device = Common.LocalDevice.Current.GetDevice(listSaveDevice[0]);
+                        btnTargetView.Text = Common.LocalDevice.Current.GetDeviceEpointName(device);
+                    }
+                    else
+                    {
+                        btnTargetView.Text = string.Empty;
+                    }
+                };
+            };
+
+            foreach (string mainkey in this.listEsixtDevice)
+            {
+                var device = Common.LocalDevice.Current.GetDevice(mainkey);
+                if (device != null)
+                {
+                    //闅忎究涓竴涓悕瀛椾笂鍘�
+                    btnTargetView.Text = Common.LocalDevice.Current.GetDeviceEpointName(device);
+                    break;
+                }
+            }
+
+            //寤舵椂
+            string strMinute = Lightconfigure.transitionTime / 60 + Language.StringByID(R.MyInternationalizationString.uMinute);
+            string strSecond = Lightconfigure.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);
+            };
+
+            //淇濆瓨
+            var btnSave = new BottomClickButton();
+            btnSave.TextID = R.MyInternationalizationString.uSave;
+            bodyFrameLayout.AddChidren(btnSave);
+            btnSave.ButtonClickEvent += (sender, e) =>
+            {
+                HdlThreadLogic.Current.RunThread(() =>
+                {
+                    //淇濆瓨Pir浼犳劅鍣ㄦ暟鎹�
+                    this.SavePirSensorData();
+                });
+            };
+        }
+
+        #endregion
+
+        #region 鈻� 鑾峰彇鍒濆鏁版嵁_______________________
+
+        /// <summary>
+        /// 鑾峰彇鍒濆鏁版嵁
+        /// </summary>
+        /// <returns></returns>
+        private async Task<bool> GetDeviceAllDefultData()
+        {
+            //鎵撳紑杩涘害鏉�
+            this.ShowProgressBar();
+            this.listOldData.Clear();
+
+            //鑾峰彇缁戝畾鐩爣璁惧
+            List<CommonDevice> listDevice = await HdlDeviceBindLogic.Current.GetBindTargetDevice(this.deviceIASZone);
+            if (listDevice == null)
+            {
+                //鍏抽棴杩涘害鏉�
+                this.CloseProgressBar(ShowReLoadMode.YES);
+                return false;
+            }
+            foreach (var device in listDevice)
+            {
+                this.listEsixtDevice.Add(Common.LocalDevice.Current.GetDeviceMainKeys(device));
+            }
+            //鑾峰彇PIR浼犳劅鍣ㄧ殑銆愬厜鎰熺瓑绾ф�诲埢搴︺��
+            this.lightLevelCount = await HdlDevicePirSensorLogic.Current.GetPirLightAbilitySize(this.deviceIASZone);
+            if (lightLevelCount == -1)
+            {
+                //鍏抽棴杩涘害鏉�
+                this.CloseProgressBar(ShowReLoadMode.YES);
+                return false;
+            }
+            //鑾峰彇鐏厜鐨勯厤缃俊鎭�
+            this.Lightconfigure = await HdlDevicePirSensorLogic.Current.GetPirSensorLightSettion(deviceIASZone);
+            if (Lightconfigure == null)
+            {
+                //鍏抽棴杩涘害鏉�
+                this.CloseProgressBar(ShowReLoadMode.YES);
+                return false;
+            }
+            //璁板綍鏃ф暟鎹�
+            this.listOldData.Add(Lightconfigure.levelSize);
+            this.listOldData.Add(Lightconfigure.transitionTime);
+            //鍏抽棴杩涘害鏉�
+            this.CloseProgressBar();
+
+            return true;
+        }
+
+        #endregion
+
+        #region 鈻� 鏄剧ず寤舵椂鏃堕棿_______________________
+
+        /// <summary>
+        /// 鏄剧ず寤舵椂鏃堕棿鍒楄〃
+        /// </summary>
+        /// <param name="btnTime"></param>
+        private void ShowDelayListTime(NormalViewControl btnTime)
+        {
+            //鍒�
+            string strMinute = Language.StringByID(R.MyInternationalizationString.uMinute);
+            //绉�
+            string strSecond = Language.StringByID(R.MyInternationalizationString.uSecond);
+            var listfirst = new List<string>();
+            var listSecond = new List<List<string>>();
+            for (int i = 0; i <= 29; i++)
+            {
+                listfirst.Add(i.ToString().PadLeft(2, '0') + strMinute);
+                var listTemp = new List<string>();
+                for (int j = 0; j <= 59; j++)
+                {
+                    if (i == 0 && j == 0)
+                    {
+                        continue;
+                    }
+                    listTemp.Add(j.ToString().PadLeft(2, '0') + strSecond);
+                }
+                listSecond.Add(listTemp);
+            }
+            //鍔犱竴涓�30鍒嗛挓鍚�
+            listfirst.Add("30" + strMinute);
+            var listTemp2 = new List<string>() { "00" + strSecond };
+            listSecond.Add(listTemp2);
+
+            string value = (this.Lightconfigure.transitionTime / 60).ToString().PadLeft(2, '0') + strMinute;
+            int index1 = listfirst.IndexOf(value);
+            if (index1 == -1)
+            {
+                index1 = 0;
+            }
+            value = (this.Lightconfigure.transitionTime % 60).ToString().PadLeft(2, '0') + strSecond;
+            int index2 = listSecond[index1].IndexOf(value);
+            if (index2 == -1)
+            {
+                index2 = 0;
+            }
+
+            PickerView.ShowSecondary(listfirst, listSecond, (value1, value2) =>
+             {
+                 btnTime.Text = listfirst[value1] + listSecond[value1][value2];
+                 int minute = Convert.ToInt32(listfirst[value1].Substring(0, 2));
+                 int second = Convert.ToInt32(listSecond[value1][value2].Substring(0, 2));
+                 int delaySecond = minute * 60 + second;
+                 //鏇存敼鏁板��
+                 this.Lightconfigure.transitionTime = delaySecond;
+             },
+             index1, index2,
+             Language.StringByID(R.MyInternationalizationString.uDelayed),
+             Language.StringByID(R.MyInternationalizationString.uFinish),
+             Language.StringByID(R.MyInternationalizationString.uCancel));
+        }
+
+        #endregion
+
+        #region 鈻� 鏁版嵁淇濆瓨___________________________
+
+        /// <summary>
+        /// 淇濆瓨Pir浼犳劅鍣ㄦ暟鎹�
+        /// </summary>
+        private async void SavePirSensorData()
+        {
+            if (listOldData[0] == Lightconfigure.levelSize && listOldData[1] == Lightconfigure.transitionTime
+                && listSaveDevice == null)
+            {
+                HdlThreadLogic.Current.RunMain(() =>
+                {
+                    //鏁版嵁娌℃湁鍙樻洿杩�,鍏抽棴鐣岄潰
+                    this.CloseForm();
+                });
+                return;
+            }
+
+            //鎵撳紑杩涘害鏉�
+            this.ShowProgressBar();
+
+            if (listSaveDevice != null)
+            {
+                //鍒犻櫎缁戝畾鐩爣
+                var listDelDevice = new List<CommonDevice>();
+                foreach (string mainKey in listEsixtDevice)
+                {
+                    if (this.listSaveDevice.Contains(mainKey) == false)
+                    {
+                        listDelDevice.Add(Common.LocalDevice.Current.GetDevice(mainKey));
+                    }
+                }
+                if (listDelDevice.Count > 0)
+                {
+                    //鍒犻櫎鐩爣
+                    var listSucess = await HdlDeviceBindLogic.Current.DeleteDeviceTarget(deviceIASZone, listDelDevice);
+                    if (listSucess == null || listSucess.Count == 0)
+                    {
+                        //鍏抽棴杩涘害鏉�
+                        this.CloseProgressBar();
+                        return;
+                    }
+                }
+                //缁戝畾鐩爣
+                var listBind = new List<CommonDevice>();
+                foreach (var mainKey in listSaveDevice)
+                {
+                    listBind.Add(Common.LocalDevice.Current.GetDevice(mainKey));
+                }
+                if (listSaveDevice.Count > 0)
+                {
+                    //缁戝畾鐩爣
+                    var listSucess = await HdlDeviceBindLogic.Current.BindDeviceTarget(deviceIASZone, listBind);
+                    if (listSucess == null || listSucess.Count == 0)
+                    {
+                        //鍏抽棴杩涘害鏉�
+                        this.CloseProgressBar();
+                        return;
+                    }
+                }
+            }
+            if (listOldData[0] != Lightconfigure.levelSize || listOldData[1] != Lightconfigure.transitionTime)
+            {
+                //淇濆瓨鐏厜閰嶇疆
+                var result = await HdlDevicePirSensorLogic.Current.SetPirSensorLightSettion(this.deviceIASZone, this.Lightconfigure);
+                if (result == false)
+                {
+                    //鍏抽棴杩涘害鏉�
+                    this.CloseProgressBar();
+                    return;
+                }
+            }
+            //鍏抽棴杩涘害鏉�
+            this.CloseProgressBar();
+
+            HdlThreadLogic.Current.RunMain(() =>
+            {
+                //鐣岄潰鍏抽棴
+                this.CloseForm();
+            });
+        }
+
+        #endregion
+    }
+}

--
Gitblit v1.8.0