From 83df0ebfbd306d0fb5a51a21a7ef2271c0c507ec Mon Sep 17 00:00:00 2001
From: 陈嘉乐 <cjl@hdlchina.com.cn>
Date: 星期二, 09 三月 2021 19:39:26 +0800
Subject: [PATCH] 2021-3-9-1

---
 HDL_ON/UI/UI2/4-PersonalCenter/PirDevice/Method.cs |  142 ++++++++++++++++++++++++++++++++++-------------
 1 files changed, 102 insertions(+), 40 deletions(-)

diff --git a/HDL_ON/UI/UI2/4-PersonalCenter/PirDevice/Method.cs b/HDL_ON/UI/UI2/4-PersonalCenter/PirDevice/Method.cs
index 0bc89c6..a4a0393 100644
--- a/HDL_ON/UI/UI2/4-PersonalCenter/PirDevice/Method.cs
+++ b/HDL_ON/UI/UI2/4-PersonalCenter/PirDevice/Method.cs
@@ -16,9 +16,7 @@
             View.TipView tipView = new View.TipView();
             tipView.InputBox(frameLayout, "", (name, frame) =>
              {
-                 ///娓呴櫎涔嬪墠鍒楄〃鏁版嵁
-                 Pir.BuottonList.Clear();
-                 if (!string.IsNullOrEmpty(name))
+                 if (Pir.currPir != null && Pir.currPir.FunctioList.Count < 10)
                  {
                      Control control = new Control();
                      control.name = name;
@@ -26,9 +24,11 @@
                      control.spk = "ir.learn";
                      control.deviceId = Pir.currPir.deviceId;
                      ThreadAddControl(control, frame, action);
-
-
-
+                 }
+                 else
+                 {
+                     View.TipView tt = new View.TipView();
+                     tt.TipBox(StringId.tip, StringId.bunengchaoguo10);
                  }
              }, false);
 
@@ -40,7 +40,6 @@
         /// <param name="frame"></param>
         public void ThreadAddControl(Control control, FrameLayout frame, Action<Control> action)
         {
-
             DAL.Server.ResponsePackNew responsePackNew = null;
             Loading loading = new Loading();
             frame.AddChidren(loading);
@@ -59,22 +58,22 @@
                         loading.Hide();
                         if (responsePackNew != null && responsePackNew.Code == "0" && responsePackNew.Data.ToString() != "")
                         {
-                            bool bool_if = false;
                             string sid = responsePackNew.Data.ToString();
-                            var mqttdate = MqttDate();
-                            for (int i = 0; i < mqttdate.objects.Count; i++) {
-                                var objects = mqttdate.objects[i];
-                                if (sid == objects.sid) {
-                                    bool_if = true;
-                                    break;
-                                }
-                            }
-                            if (bool_if)
+                            var mqttdate = MqttDate(sid);
+                            if (mqttdate != null)
                             {
-                                control.deviceId = mqttdate.id;
                                 ///杩欓噷锛氱洃鍚琈TTP鎺ㄩ�佷笅鏉ヤ富棰橈紝鎵嶇煡閬撴槸鍚︽坊鍔犳垚鍔�
-                                frame.RemoveFromParent();//娣诲姞鎴愬姛鍏抽棴寮圭獥
-                                action(control);
+                                control.sid = sid;
+                                //浼戠湢500姣锛屼负绛夊緟浜戠鍒涘缓deviceid锛�
+                                System.Threading.Thread.Sleep(500);
+                                GetControl(frame, control,(device)=> {
+                                    if (device != null)
+                                    {
+                                        control.deviceId = device.deviceId;
+                                        frame.RemoveFromParent();//娣诲姞鎴愬姛鍏抽棴寮圭獥
+                                        action(control);
+                                    }
+                                });
                             }
                             else
                             {
@@ -246,40 +245,94 @@
         }
 
         /// <summary>
+        /// 鑾峰彇閬ユ帶鍣ㄨ缁�
+        /// </summary>
+        public void GetControl(FrameLayout frame, Control control, Action<Entity.Function> action)
+        {
+            Entity.Function function = null;
+            //鍔犺浇log
+            Loading loading = new Loading();
+            frame.AddChidren(loading);
+            HDL_ON.DAL.Server.ResponsePackNew responsePackNew = null;
+            loading.Start();
+            new System.Threading.Thread(() =>
+            {
+                try
+                {
+                    responsePackNew = PirSend.GetinfoBySid(control);
+                }
+                catch { }
+                finally
+                {
+                    Application.RunOnMainThread(() =>
+                    {
+                        try
+                        {
+                            if (responsePackNew != null && responsePackNew.Code == "0" && responsePackNew.Data.ToString() != "")
+                            {
+                                var str = Newtonsoft.Json.JsonConvert.SerializeObject(responsePackNew.Data.ToString());
+                                function = Newtonsoft.Json.JsonConvert.DeserializeObject<Entity.Function>(str);
+                            }
+                            else
+                            {
+                                Method method = new Method();
+                                method.ErrorShow(responsePackNew);
+                            }
+                        }
+                        catch { }
+                        finally
+                        {
+                            Application.RunOnMainThread(() =>
+                            {
+                                loading.Hide();
+                                action(function);
+                            });
+                        }
+
+                    });
+                }
+
+            })
+            { IsBackground = true }.Start();
+        }
+
+        /// <summary>
         /// MQTT涓婚鎺ㄩ�佷笅鏉ョ殑鏁版嵁(閬ユ帶鍣ㄦ坊鍔�)
         /// </summary>
-        public static string addcontronsid = "";
+        public static string addcontrondata = "";
         /// <summary>
-        /// 
+        /// MQTT涓婚鎺ㄩ�佷笅鏉ョ殑鏁版嵁(瀛︿範鎸夐敭)
+        /// </summary>
+        public static string studybtndata = "";
+
+        /// <summary>
+        /// 鍒ゆ柇杩欎釜涓婚鏄惁鏄坊鍔犻仴鎺у櫒涓婚
         /// </summary>
         /// <returns></returns>
-        public Cloud MqttDate()
+        public Cloud MqttDate(string sid,int timeValue=10)
         {
+            Cloud cloud=null;
             var dateTime = DateTime.Now;
-            while ((DateTime.Now - dateTime).TotalMilliseconds < 5 * 1000)
+            while ((DateTime.Now - dateTime).TotalMilliseconds < timeValue * 1000)
             {
-                if (!string.IsNullOrEmpty(addcontronsid))
+                if (!string.IsNullOrEmpty(addcontrondata))
                 {
+                   var cloudjson = Newtonsoft.Json.JsonConvert.DeserializeObject<Cloud>(addcontrondata);
+                    for (int i = 0; i < cloudjson.objects.Count; i++)
+                    {
+                        var objects = cloudjson.objects[i];
+                        if (sid == objects.sid)
+                        {
+                            cloud = cloudjson;
+                            break;
+                        }
+                    }
                     break;
                 }
 
             }
-            return PushData();
-        }
-
-        public Cloud PushData()
-        {
-            Cloud cloud = new Cloud();
-            if (addcontronsid != "")
-            {
-                //var date = Newtonsoft.Json.JsonConvert.SerializeObject(addcontronsid);
-                cloud = Newtonsoft.Json.JsonConvert.DeserializeObject<Cloud>(addcontronsid);
-
-            }
             return cloud;
         }
-
-
 
         /// <summary>
         /// 閿欒鐮佹彁绀�
@@ -307,7 +360,7 @@
         /// <summary>
         /// 璁惧id
         /// </summary>
-        public string id = string.Empty;
+        public string id = "";
         public List<Objects> objects = new List<Objects>();
         public string time_stamp = string.Empty;
 
@@ -316,8 +369,17 @@
     [Serializable]
     public class Objects
     {
+
         public string sid = string.Empty;
         public string spk = string.Empty;
+        public List<Attributes> attributes = new List<Attributes>();
     }
+    [Serializable]
+    public class Attributes
+    {
+        public string key = "";
+        public string data_type = "";
+        public List<string> value = new List<string>();
 
+    }
 }

--
Gitblit v1.8.0