From d72ca686a3e262693f8a6e45e747e8e8da43335b Mon Sep 17 00:00:00 2001
From: JLChen <551775569@qq.com>
Date: 星期二, 06 七月 2021 09:39:03 +0800
Subject: [PATCH] 2021-07-06 1.更新

---
 HDL_ON/UI/UI2/4-PersonalCenter/PirDevice/Method.cs |  280 ++++++++++++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 244 insertions(+), 36 deletions(-)

diff --git a/HDL_ON/UI/UI2/4-PersonalCenter/PirDevice/Method.cs b/HDL_ON/UI/UI2/4-PersonalCenter/PirDevice/Method.cs
index f0565fd..064080f 100644
--- a/HDL_ON/UI/UI2/4-PersonalCenter/PirDevice/Method.cs
+++ b/HDL_ON/UI/UI2/4-PersonalCenter/PirDevice/Method.cs
@@ -10,6 +10,40 @@
     {
 
         /// <summary>
+        /// 绾㈠瀹濈▼搴忎富鍏ュ彛
+        /// </summary>
+        /// <param name="frame"></param>
+        /// <param name="function"></param>
+        public void MainView(FrameLayout frame, Entity.Function function, Action action)
+        {
+            Pir pirDevice = new Pir();
+            if (function != null)
+            {//鏁版嵁杞崲
+                pirDevice.name = function.name;
+                pirDevice.deviceId = function.deviceId;
+                pirDevice.sid = function.sid;
+                pirDevice.online = function.online;
+                pirDevice.versions = function.versions;
+            }
+            Pir.currPir = pirDevice;
+            GetControlList(frame, () =>
+            {
+                Application.RunOnMainThread(() =>
+                {
+                    var page = new PirMain();
+                    MainPage.BasePageView.AddChidren(page);
+                    page.Show();
+                    MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1;
+                    PirMain.BackAction += () =>
+                    {
+                        action?.Invoke();
+                        PirMain.BackAction = null;
+                    };
+                });
+            }, Pir.currPir);
+        }
+
+        /// <summary>
         /// 绠$悊浣嶇疆
         /// </summary>
         /// <param name="control">褰撳墠璁惧</param>
@@ -102,14 +136,20 @@
                         ///杩欓噷锛氱洃鍚琈TTP鎺ㄩ�佷笅鏉ヤ富棰�;
                         if (mqttdate != null)
                         {
-                            //浼戠湢500姣锛屼负绛夊緟浜戠鍒涘缓deviceid锛�
-                            System.Threading.Thread.Sleep(500);
+                            //浼戠湢1000姣锛屼负绛夊緟浜戠鍒涘缓deviceid锛�
+                            System.Threading.Thread.Sleep(1000);
                             //璇诲彇娣诲姞閬ユ帶鍣╠eviceID锛屾墠鐭ラ亾鏄惁娣诲姞鎴愬姛锛�
                             GetControl(frame, control, (device) =>
                             {
                                 if (device != null)
                                 {
+
                                     control.deviceId = device.deviceId;
+                                    //閬ユ帶鍣ㄦ坊鍔犲埌鍒楄〃锛�
+                                    if (null == Pir.currPir.FunctioList.Find((c) => c.deviceId == device.deviceId))
+                                    {
+                                        Pir.currPir.FunctioList.Add(device);
+                                    }
                                     frame.RemoveFromParent();//娣诲姞鎴愬姛鍏抽棴寮圭獥
                                     action(control);
                                 }
@@ -181,11 +221,10 @@
                                 var pirJosn = Newtonsoft.Json.JsonConvert.DeserializeObject<Pir>(str);
                                 if (pirJosn != null)
                                 {
-                                    if (null == Pir.pirDeviceList.Find((c) => c.deviceId == pirJosn.deviceId))
-                                    {
 
-                                        Pir.pirDeviceList.Add(pirJosn);
-
+                                    if (null == PirDevice.Pir.pirDeviceList.Find((c) => c.deviceId == pirJosn.deviceId))
+                                    {
+                                        PirDevice.Pir.pirDeviceList.Add(pirJosn);
                                     }
                                 }
                             }
@@ -214,7 +253,7 @@
                             {
                                 loading.Hide();
                                 Method method = new Method();
-                                method.ErrorShow(null,"璇诲彇绾㈠瀹濆垪琛ㄥけ璐�");
+                                method.ErrorShow(null, "璇诲彇绾㈠瀹濆垪琛ㄥけ璐�");
                             }
                         }
                         catch { }
@@ -227,7 +266,7 @@
 
         }
         /// <summary>
-        /// 鑾峰彇閬ユ帶鍣ㄥ垪琛�
+        /// 鑾峰彇鎵�鏈夌孩澶栧疂閬ユ帶鍣ㄥ垪琛�
         /// </summary>
         /// <param name="action">鍥炶皟鍑芥暟</param>
         public static void GetControlList(Action action)
@@ -242,7 +281,7 @@
                         var pirDevice = Pir.pirDeviceList[i];
                         try
                         {
-                            var responsePackNew = PirSend.ControlList(pirDevice);
+                            var responsePackNew = PirSend.ControlList(pirDevice.deviceId);
                             if (responsePackNew != null && responsePackNew.Code == "0" && responsePackNew.Data.ToString() != "")
                             {
                                 var jArray = JArray.Parse(responsePackNew.Data.ToString());
@@ -282,6 +321,34 @@
             { IsBackground = true }.Start();
 
         }
+
+        /// <summary>
+        /// 鑾峰彇鍗曚釜绾㈠瀹濋仴鎺у櫒鍒楄〃
+        /// </summary>
+        /// <param name="action">鍥炶皟鍑芥暟</param>
+        public static void GetControlList(FrameLayout frame, Action action, Pir pirDevice)
+        {
+            ThreadSend(new Control { deviceId = pirDevice.deviceId }, (responsePackNew) =>
+             {
+                 var jArray = JArray.Parse(responsePackNew.Data.ToString());
+                 for (int a = 0; a < jArray.Count; a++)
+                 {
+                     var jay = jArray[a];
+                     //鏁版嵁杩斿簭鍒楀寲涓篖ogic瀵硅薄
+                     var str = Newtonsoft.Json.JsonConvert.SerializeObject(jay);
+                     var pirJosn = Newtonsoft.Json.JsonConvert.DeserializeObject<Entity.Function>(str);
+                     if (pirJosn != null)
+                     {
+                         if (null == pirDevice.FunctioList.Find((c) => c.deviceId == pirJosn.deviceId))
+                         {
+                             pirDevice.FunctioList.Add(pirJosn);
+                         }
+                     }
+                 }
+                 action();
+             }, "鑾峰彇閬ユ帶鍣ㄥ垪琛�", "frame", frame, null);
+
+        }
         /// <summary>
         /// 鑾峰彇璁惧璇︽儏閫氳繃(spk,sid)
         /// </summary>
@@ -290,21 +357,69 @@
         /// <param name="action">鍥炶皟鍑芥暟</param>
         public void GetControl(FrameLayout frame, Control control, Action<Entity.Function> action)
         {
-            Entity.Function function = null;
+            ThreadSend(control, (responsePackNew) =>
+            {
+                var function = Newtonsoft.Json.JsonConvert.DeserializeObject<Entity.Function>(responsePackNew.Data.ToString());
+                action(function);
+            }, "鑾峰彇璁惧璇︽儏", "frame", frame, null);
+        }
+        /// <summary>
+        /// 鍙戦�佸懡浠ょ嚎绋�
+        /// </summary>
+        /// <param name="control">鍙戦�佹暟鎹璞�</param>
+        /// <param name="action">鍥炶皟鍑芥暟</param>
+        /// <param name="str">鍒ゆ柇瀛楃</param>
+        /// <param name="view">鍒ゆ柇log鐖舵帶浠�</param>
+        /// <param name="frame">log鐖舵帶浠�</param>
+        /// <param name="dialog">log鐖舵帶浠�</param>
+        /// <param name="attributesStatus">瀛︿範鎸夐敭</param>
+        public static void ThreadSend(Control control, Action<ResponsePackNew> action, string str, string view, FrameLayout frame, Dialog dialog, Entity.AttributesStatus attributesStatus=null)
+        {
+
             //鍔犺浇log
             Loading loading = new Loading();
-            frame.AddChidren(loading);
+            if (view == "dialog")
+            {
+                dialog.AddChidren(loading);
+            }
+            else
+            {
+                frame.AddChidren(loading);
+            }
             loading.Start();
+            ResponsePackNew responsePackNew = null;
             new System.Threading.Thread(() =>
             {
                 try
                 {
-                    // 鑾峰彇璁惧璇︽儏閫氳繃(spk,sid)
-                    var responsePackNew = PirSend.GetinfoBySid(control);
-                    if (responsePackNew != null && responsePackNew.Code == "0" && responsePackNew.Data.ToString() != "")
+                    if (str == "鍒犻櫎")
                     {
-                        //var str = Newtonsoft.Json.JsonConvert.SerializeObject(responsePackNew.Data.ToString());
-                        function = Newtonsoft.Json.JsonConvert.DeserializeObject<Entity.Function>(responsePackNew.Data.ToString());
+                        responsePackNew = PirSend.DeleteDevice(control.deviceId);
+                    }
+                    else if (str == "淇敼鍚嶇О")
+                    {
+
+                        responsePackNew = PirSend.DeviceRename(control.deviceId, control.name);
+                    }
+                    else if (str == "鍒犻櫎鎸夐敭")
+                    {
+                        if (attributesStatus != null)
+                        {
+                            responsePackNew = PirSend.CodeRemove(attributesStatus, control.deviceId);
+                        }
+                    }
+                    else if (str == "鑾峰彇璁惧璇︽儏")
+                    {
+                        // 鑾峰彇璁惧璇︽儏閫氳繃(spk,sid)
+                        responsePackNew = PirSend.GetinfoBySid(control);
+                    }
+                    else if (str == "鑾峰彇閬ユ帶鍣ㄥ垪琛�")
+                    {
+                        responsePackNew = PirSend.ControlList(control.deviceId);
+                    }
+                    else if (str == "搴撶爜娴嬭瘯")
+                    {
+                        responsePackNew = PirSend.CodeTest(control);
                     }
                 }
                 catch { }
@@ -313,29 +428,45 @@
                     Application.RunOnMainThread(() =>
                     {
                         loading.Hide();
-                        action(function);
+                        if (responsePackNew != null && responsePackNew.Code == "0" && responsePackNew.Data.ToString() != "")
+                        {
+                            action(responsePackNew);
+                        }
+                        else
+                        {
+                            Method method = new Method();
+                            //鑷畾涔夐敊璇彁绀烘枃鏈�
+                            string eorroText = "";
+                            if (str == "鍒犻櫎")
+                            {
+                            }
+                            else if (str == "淇敼鍚嶇О")
+                            {
+
+                            }
+                            else if (str == "鍒犻櫎鎸夐敭")
+                            {
+                            }
+                            else if (str == "鑾峰彇璁惧璇︽儏")
+                            {
+                            }
+                            else if (str == "鑾峰彇閬ユ帶鍣ㄥ垪琛�")
+                            {
+                            }
+                            else if (str == "搴撶爜娴嬭瘯")
+                            {
+                            }
+                            method.ErrorShow(responsePackNew, eorroText);
+                        }
+
                     });
                 }
 
             })
             { IsBackground = true }.Start();
-        }
-        /// <summary>
-        /// 鍙戦�佸懡浠ょ嚎绋�
-        /// </summary>
-        /// <param name="control">鍙戦�佹暟鎹璞�</param>
-        /// <param name="action">鍥炶皟鍑芥暟</param>
-        /// <param name="str">鍒ゆ柇瀛楃</param>
-        /// <param name="frame">log鐖舵帶浠�</param>
-        /// <param name="dialog">log鐖舵帶浠�</param>
-        public void ThreadSend(Control control, Action<HDL_ON.DAL.Server.ResponsePackNew> action, string str, FrameLayout frame, Dialog dialog)
-        {
-
 
 
         }
-
-
         /// <summary>
         /// MQTT涓婚鎺ㄩ�佷笅鏉ョ殑閬ユ帶鍣ㄦ暟鎹�
         /// </summary>
@@ -367,7 +498,7 @@
                     str = buttondata;
                 }
 
-                if (!string.IsNullOrEmpty(controldata))
+                if (!string.IsNullOrEmpty(str))
                 {
                     try
                     {
@@ -407,7 +538,11 @@
             }
             else if (text == "璇诲彇绾㈠瀹濆垪琛ㄥけ璐�")
             {
-                str = "璇诲彇绾㈠瀹濆垪琛ㄥけ璐�"; //Language.StringByID(StringId.delFail);
+                str = Language.StringByID(StringId.huoqushujushibao);
+            }
+            else if (text == "娣诲姞澶辫触")
+            {
+                str = Language.StringByID(StringId.tianjiashibai);
             }
             else
             {
@@ -425,19 +560,19 @@
                             break;
                         case "10807":
                             {
-                                str = "绾㈠瀹濅笅閬ユ帶鍣ㄨ秴杩囨渶澶�(10涓�)鏁伴噺闄愬埗";// Language.StringByID(StringId.gatewayNotOnline);
+                                str = Language.StringByID(StringId.bunengchaoguo10);
 
 
                             }
                             break;
                         case "2":
                             {
-                                str = "绯荤粺缁存姢涓瓇璇风◢鍚庡啀璇晘";
+                                str = Language.StringByID(StringId.xitongweihuzhong);
                             }
                             break;
                         default:
                             {
-                                str ="鑾峰彇鏁版嵁澶辫触" ;// Language.StringByID(StringId.saveFail);
+                                str = Language.StringByID(StringId.huoqushujushibao);
                             }
                             break;
 
@@ -455,6 +590,79 @@
                 case 3: { } break;
             }
         }
+        /// <summary>
+        ///鎸囧畾鍒锋柊鐣岄潰
+        /// </summary>
+        /// <param name="strView">鍒ゆ柇瀛楃</param>
+        public static void RefreshView(string strView)
+        {
+            //鏍囪鏄笉鏄凡缁忓埛鏂板畬鎴�
+            bool if_bool = false;
+            for (int i = MainPage.BasePageView.ChildrenCount - 1; 0 <= i; i--)
+            {
+                var view = MainPage.BasePageView.GetChildren(i);
+                if (strView == "PirMain")
+                {
+                    if (view.GetType() == typeof(PirMain))
+                    {
+                        //寮哄埗杞崲瀵硅薄
+                        var f = (PirMain)view;
+                        //绉婚櫎鎵�鏈夊瓙鎺т欢
+                        f.RemoveAll();
+                        //閲嶆柊鍔犺浇UI
+                        f.Show();
+                        //閫�鍑篺or寰幆
+                        //break;
+                        if_bool = true;
+                    }
+                }
+                if (if_bool)
+                {
+                    //閫�鍑篺or寰幆
+                    break;
+                }
+            }
+        }
+        /// <summary>
+        /// 鎸囧畾鍒犻櫎鐣岄潰
+        /// </summary>
+        /// <param name="strView">鍒ゆ柇瀛楃</param>
+        public static void RemoveView(string strView)
+        {
+
+            for (int i = MainPage.BasePageView.ChildrenCount - 1; 0 <= i; i--)
+            {
+                var view = MainPage.BasePageView.GetChildren(i);
+                if (strView == "PirMain")
+                {
+                    if (view.GetType() == typeof(PirMain))
+                    {
+                        //绉婚櫎鐣岄潰
+                        view.RemoveFromParent();
+                    }
+
+                }
+                else if (strView == "AddControl")
+                {
+
+                    if (view.GetType() == typeof(AddControl))
+                    {
+                        //鎵惧埌绉婚櫎
+                        view.RemoveFromParent();
+                    }
+                }
+                else if (strView == "AddControlComplete")
+                {
+
+                    if (view.GetType() == typeof(AddControlComplete))
+                    {
+                        //鎵惧埌绉婚櫎
+                        view.RemoveFromParent();
+                    }
+                }
+
+            }
+        }
 
     }
     [Serializable]

--
Gitblit v1.8.0