From fe2b566c8d9c097d2568ad211088fa5bc6f8c229 Mon Sep 17 00:00:00 2001
From: wei <kaede@kaededeMacBook-Air.local>
Date: 星期二, 23 三月 2021 13:48:25 +0800
Subject: [PATCH] 2.增加住宅绑定网关判断,没有绑定网关的住宅,ON+不再显示

---
 HDL_ON/UI/UI2/4-PersonalCenter/AddDevice/AddMiniRemoteControlDirection4Page.cs |  180 ++++++++++++++++++++++++++++++++++++++++++++++++++---------
 1 files changed, 151 insertions(+), 29 deletions(-)

diff --git a/HDL_ON/UI/UI2/4-PersonalCenter/AddDevice/AddMiniRemoteControlDirection4Page.cs b/HDL_ON/UI/UI2/4-PersonalCenter/AddDevice/AddMiniRemoteControlDirection4Page.cs
index 490f4a8..ef4bf84 100644
--- a/HDL_ON/UI/UI2/4-PersonalCenter/AddDevice/AddMiniRemoteControlDirection4Page.cs
+++ b/HDL_ON/UI/UI2/4-PersonalCenter/AddDevice/AddMiniRemoteControlDirection4Page.cs
@@ -22,6 +22,10 @@
         /// </summary>
         private string wifiPsw = string.Empty;
         /// <summary>
+        /// 鏂拌澶囩殑sid(鐢ㄦ潵鍖归厤鍝竴涓澶囨槸鏂扮殑)
+        /// </summary>
+        private string newDeviceSid = string.Empty;
+        /// <summary>
         /// 瓒呮椂绾跨▼鏄惁杩愯
         /// </summary>
         private bool timeoutThreadActivity = false;
@@ -61,12 +65,9 @@
             //杩欎釜鐣岄潰鐨勮儗鏅渶瑕佺櫧鑹�
             bodyFrameLayout.BackgroundColor = UI.CSS.CSS_Color.MainBackgroundColor;
 
-#if __IOS__
-#endif
-#if __Android__
             //娣诲姞鎺ユ敹钃濈墮鍙嶉鐨勪簨浠�
-            HdlAndroidBluetoothLogic.Current.AddReceiveEvent(this.BluetoothReceiveEvent);
-#endif
+            HdlBluetoothLogic.Current.AddReceiveEvent(this.BluetoothReceiveEvent);
+
             //娣诲姞浜戠鍙嶉浜嬩欢
             HdlCloudReceiveLogic.Current.AddCloudReceiveEvent("AddMiniRemoteControlDirection4Page", this.CloudReceiveEvent);
 
@@ -179,7 +180,7 @@
         /// <summary>
         /// 鏄剧ず鎴愬姛鐣岄潰
         /// </summary>
-        private void ShowSuccessView()
+        private void ShowSuccessView(Entity.Function newDevice)
         {
             //娓呯┖body
             this.ClearBodyFrame();
@@ -212,6 +213,29 @@
             bodyFrameLayout.AddChidren(btnUse);
             btnUse.ButtonClickEvent += (sender, e) =>
             {
+                if (newDevice == null)
+                {
+                    //鍏抽棴鎺夊叏閮ㄧ殑鐣岄潰,搴旇涓嶄細鍙戠敓
+                    HdlFormLogic.Current.CloseAllOpenForm();
+                    return;
+                }
+                var form = HdlFormLogic.Current.GetFormByName("AddMiniRemoteControlDirection1Page") as AddMiniRemoteControlDirection1Page;
+                //if (form.AddDeviceEvent != null)
+                {
+                    //浠h〃杩欎釜鏄敱娓╂�婚偅杈硅皟鐢ㄧ殑,鐩存帴鍥炶皟鍑芥暟
+                    form.AddDeviceEvent?.Invoke(newDevice);
+                    //鍏抽棴鎺夎繖涓晫闈�
+                    this.CloseForm();
+                    //鍐嶆妸AddMiniRemoteControlDirection1Page鐣岄潰鍏充簡
+                    HdlFormLogic.Current.CloseFormByFormName("AddMiniRemoteControlDirection1Page");
+                }
+                //else
+                //{
+                //    //浠h〃杩欏苟涓嶆槸鐢辨俯鎬荤殑鐣岄潰璋冪敤鐨�,鍒欏叧闂帀鍏ㄩ儴鐨勭晫闈�
+                //    HdlFormLogic.Current.CloseAllOpenForm();
+                //    //鐒跺悗鍐嶆妸娓╂�荤殑鐣岄潰new璧锋潵
+                //    new UI2.PersonalCenter.PirDevice.Method().MainView(this, newDevice,()=> { });
+                //}
             };
         }
 
@@ -255,7 +279,9 @@
             btnReDo.ButtonClickEvent += (sender, e) =>
             {
                 //閲嶆柊鍒濆鍖栦腑閮ㄤ俊鎭�
-                this.InitMiddleFrame();
+                this.CloseForm();
+                var form = new AddMiniRemoteControlDirection2Page();
+                form.AddForm(this.wifiName, this.wifiPsw);
             };
         }
 
@@ -268,14 +294,107 @@
         /// </summary>
         private void SendAccountAndPswToBluetooth()
         {
-#if __IOS__
-#endif
-#if __Android__
             //鑾峰彇鍙戦�佸埌钃濈墮鐨勬暟鎹�
             var sendData = this.GetSendToBluetoothData();
             //涓嶇瓑寰�
-            HdlAndroidBluetoothLogic.Current.SendData(sendData);
-#endif
+            HdlBluetoothLogic.Current.SendData(sendData);
+        }
+
+        #endregion
+
+        #region 鈻� 绾㈠瀹濈浉鍏虫柟娉昣____________________
+
+        /// <summary>
+        /// 妫�娴嬫槸鍚︽槸鏂扮殑绾㈠瀹�
+        /// </summary>
+        /// <param name="pushEnum">鎺ㄩ�佹灇涓�</param>
+        /// <param name="i_data">鎺ㄩ�佺殑鏁版嵁</param>
+        /// <returns></returns>
+        private bool CheckIsNewMiniRemoteControl(CloudPushEnum pushEnum, string i_data)
+        {
+            if (pushEnum != CloudPushEnum.A鏂拌澶囦笂鎶�) { return false; }
+
+            try
+            {
+                var strSpk = string.Empty;
+                //杞负json
+                var json = Newtonsoft.Json.Linq.JObject.Parse(i_data);
+                var linqArry = json["objects"] as Newtonsoft.Json.Linq.JArray;
+                if (linqArry != null)
+                {
+                    //鏁扮粍绫诲瀷
+                    if (linqArry.Count == 0) { return false; }
+                    strSpk = linqArry[0]["spk"].ToString();
+                    this.newDeviceSid = linqArry[0]["sid"].ToString();
+                }
+                else
+                {
+                    //闈炴暟缁勭被鍨�
+                    strSpk = json["objects"]["spk"].ToString();
+                    this.newDeviceSid = json["objects"]["sid"].ToString();
+                }
+                if (strSpk != Entity.SPK.IrModule)
+                {
+                    //濡傛灉涓嶆槸绾㈠瀹濈殑璇�
+                    return false;
+                }
+                return true;
+            }
+            catch { return false; }
+        }
+
+        /// <summary>
+        /// 鍒锋柊绾㈠瀹濅俊鎭�
+        /// </summary>
+        /// <param name="successEvent">鎴愬姛鐨勫洖璋冧簨浠�</param>
+        private void RefreshMiniRemoteControlInfo(Action<Entity.Function> successEvent)
+        {
+            var pra = new Dictionary<string, object>();
+            pra.Add("homeId", Entity.DB_ResidenceData.Instance.CurrentRegion.RegionID);
+            pra.Add("spk", Entity.SPK.IrModule);
+
+            var requestJson = DAL.Server.HttpUtil.GetSignRequestJson(pra);
+            HdlThreadLogic.Current.RunThread(() =>
+            {
+                int count = 0;
+                while (this.Parent != null)
+                {
+                    try
+                    {
+                        //瓒呰繃5娆¢兘涓嶆垚鍔�,鐪熶笉澶勭悊浜�
+                        count++;
+                        if (count > 5) { return; }
+
+                        //鑾峰彇鍏ㄩ儴绾㈠瀹濆垪琛�
+                        var result = DAL.Server.HttpUtil.RequestHttpsPostFroHome(DAL.Server.NewAPI.Api_Post_GetDevcieList, requestJson);
+                        if (result == null || result.Code != DAL.Server.StateCode.SUCCESS)
+                        {
+                            System.Threading.Thread.Sleep(3000);
+                            continue;
+                        }
+                        var listDevice = Newtonsoft.Json.JsonConvert.DeserializeObject<Entity.DevcieApiPack>(result.Data.ToString());
+                        Entity.Function newDevice = null;
+                        foreach (var newFunction in listDevice.list)
+                        {
+                            //娣诲姞鍒扮紦瀛樺綋涓�
+                            newFunction.SaveFunctionFile();
+                            Entity.FunctionList.List.IniFunctionList(newFunction.savePath, true);
+                            if (newFunction.sid == this.newDeviceSid)
+                            {
+                                //杩欎釜璁惧鏄柊杩藉姞鐨�
+                                newDevice = newFunction;
+                            }
+                        }
+                        //璋冪敤鍥炶皟鍑芥暟
+                        successEvent?.Invoke(newDevice);
+                        return;
+                    }
+                    catch
+                    {
+                        System.Threading.Thread.Sleep(3000);
+                    }
+                }
+            });
         }
 
         #endregion
@@ -289,21 +408,28 @@
         /// <param name="i_data">鎺ㄩ�佺殑鍐呭</param>
         private void CloudReceiveEvent(CloudPushEnum pushEnum, string i_data)
         {
-            if (pushEnum != CloudPushEnum.A鏂拌澶囦笂鎶�) { return; }
+            //妫�娴嬫槸鍚︽槸鏂扮殑绾㈠瀹�
+            if (this.CheckIsNewMiniRemoteControl(pushEnum, i_data) == false)
+            {
+                return;
+            }
+            //鍒锋柊绾㈠瀹濅俊鎭�
+            this.RefreshMiniRemoteControlInfo((Entity.Function newDevice) =>
+            {
+                //绉婚櫎杩欎釜浜嬩欢
+                HdlCloudReceiveLogic.Current.RemoveCloudReceiveEvent("AddMiniRemoteControlDirection4Page");
+                //鍋滄绾跨▼
+                this.timeoutThreadActivity = false;
 
-            //鎺ユ敹鍒板氨绉婚櫎杩欎釜浜嬩欢
-            HdlCloudReceiveLogic.Current.RemoveCloudReceiveEvent("AddMiniRemoteControlDirection4Page");
-            //鍋滄绾跨▼
-            this.timeoutThreadActivity = false;
-
-            //娣诲姞璁惧鎴愬姛涔嬪悗,澶勭悊涓�浜涗笢瑗�
-            this.DoSomethingAfterAddDeviceSuccess();
+                //娣诲姞璁惧鎴愬姛涔嬪悗,澶勭悊涓�浜涗笢瑗�
+                this.DoSomethingAfterAddDeviceSuccess(newDevice);
+            });
         }
 
         /// <summary>
         /// 娣诲姞璁惧鎴愬姛涔嬪悗,澶勭悊涓�浜涗笢瑗�
         /// </summary>
-        private void DoSomethingAfterAddDeviceSuccess()
+        private void DoSomethingAfterAddDeviceSuccess(Entity.Function newDevice)
         {
             HdlThreadLogic.Current.RunThread(() =>
             {
@@ -334,7 +460,7 @@
                         HdlThreadLogic.Current.RunMain(() =>
                         {
                             //鏄剧ず鎴愬姛鐣岄潰
-                            this.ShowSuccessView();
+                            this.ShowSuccessView(newDevice);
                         });
                     }
                 }
@@ -367,8 +493,8 @@
         {
             HdlThreadLogic.Current.RunThread(() =>
             {
-                //300绉掕秴鏃�
-                int timeout = 300;
+                //360绉掕秴鏃�
+                int timeout = 360;
                 while (this.timeoutThreadActivity == false && this.Parent != null)
                 {
                     System.Threading.Thread.Sleep(1000);
@@ -399,11 +525,7 @@
         public override void CloseFormBefore()
         {
             //鎽ф瘉钃濈墮
-#if __IOS__
-#endif
-#if __Android__
-            HdlAndroidBluetoothLogic.Current.Dispone();
-#endif
+            HdlBluetoothLogic.Current.Dispone();
             HdlCloudReceiveLogic.Current.RemoveCloudReceiveEvent("AddMiniRemoteControlDirection4Page");
 
             base.CloseFormBefore();

--
Gitblit v1.8.0