From 1d1cad99a27c9f644c84eb3d376c70bd30a55879 Mon Sep 17 00:00:00 2001
From: 陈嘉乐 <cjl@hdlchina.com.cn>
Date: 星期三, 10 三月 2021 18:02:13 +0800
Subject: [PATCH] 2021-3-10-1

---
 HDL_ON/UI/UI2/4-PersonalCenter/PirDevice/Method.cs |  221 +++++++++++++++++++++++++++++++++++++++++++++----------
 1 files changed, 180 insertions(+), 41 deletions(-)

diff --git a/HDL_ON/UI/UI2/4-PersonalCenter/PirDevice/Method.cs b/HDL_ON/UI/UI2/4-PersonalCenter/PirDevice/Method.cs
index 3b9cb15..8fd747b 100644
--- a/HDL_ON/UI/UI2/4-PersonalCenter/PirDevice/Method.cs
+++ b/HDL_ON/UI/UI2/4-PersonalCenter/PirDevice/Method.cs
@@ -8,30 +8,67 @@
 {
     public class Method
     {
+
+        /// <summary>
+        /// 绠$悊浣嶇疆
+        /// </summary>
+        /// <param name="control">褰撳墠璁惧</param>
+        /// <param name="action">鍥炶皟鍑芥暟</param>
+        public void ManagementPosition(Entity.Function control, Action action)
+        {
+            var view = new ChooseRoomPage(control, action);
+            MainPage.BasePageView.AddChidren(view);
+            view.LoadPage();
+            MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1;
+        }
+        /// <summary>
+        /// 淇敼鍚嶇О
+        /// </summary>
+        /// <param name="tipText">鎻愮ず鏂囨湰</param>
+        /// <param name="list">褰撳墠瀛樺湪鍚嶇О鍒楄〃</param>
+        /// <param name="currName">褰撳墠鍚嶇О</param>
+        /// <param name="action">鍥炶皟鍑芥暟</param>
+        public void EditControlName(int tipText ,List<string> list, string currName, Action<string, Dialog> action,Action actionCancel, bool tag=false)
+        {
+            new View.TipView().InputBox(StringId.editName, currName, StringId.nameNull, StringId.NameAlreadyExists, list, (text, view
+                ) =>
+            {
+                action(text,view);
+            }, () => { actionCancel(); }, tag);
+        }
         /// <summary>
         /// 娣诲姞閬ユ帶鍣ㄧ殑鏂规硶
         /// </summary>
+        /// <param name="frameLayout">log鍥炬爣鍔犺浇鐣岄潰</param>
+        /// <param name="action">鍥炶皟鍑芥暟</param>
         public void AddControl(FrameLayout frameLayout, Action<Control> action)
         {
             View.TipView tipView = new View.TipView();
             tipView.InputBox(frameLayout, "", (name, frame) =>
              {
-                 ///娓呴櫎涔嬪墠鍒楄〃鏁版嵁
-                 Pir.BuottonList.Clear();
-                 Control control = new Control();
-                 control.name = name;
-                 control.type = "learn";
-                 control.spk = "ir.learn";
-                 control.deviceId = Pir.currPir.deviceId;
-                 ThreadAddControl(control, frame, action);
+                 if (Pir.currPir != null && Pir.currPir.FunctioList.Count < 10)
+                 {
+                     Control control = new Control();
+                     control.name = name;
+                     control.type = "learn";
+                     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);
 
         }
         /// <summary>
         /// 鍙戦�侀仴鎺у櫒鍛戒护鏂规硶
         /// </summary>
-        /// <param name="control"></param>
-        /// <param name="frame"></param>
+        /// <param name="control">鍙戦�佸弬鏁板璞�</param>
+        /// <param name="frame">log鍥炬爣鍔犺浇鐣岄潰</param>
+        /// <param name="action">鍥炶皟鍑芥暟</param>
         public void ThreadAddControl(Control control, FrameLayout frame, Action<Control> action)
         {
             DAL.Server.ResponsePackNew responsePackNew = null;
@@ -42,7 +79,12 @@
             {
                 try
                 {
+                    //鍙戦�佹坊鍔犲懡浠�
                     responsePackNew = PirSend.Add(control);
+
+
+
+
                 }
                 catch { }
                 finally
@@ -53,14 +95,34 @@
                         if (responsePackNew != null && responsePackNew.Code == "0" && responsePackNew.Data.ToString() != "")
                         {
                             string sid = responsePackNew.Data.ToString();
-                            var mqttdate = MqttDate(sid);
-                            if (mqttdate.id!="")
+                            var mqttdate =MqttDate(sid);
+                            ///杩欓噷锛氱洃鍚琈TTP鎺ㄩ�佷笅鏉ヤ富棰橈紝鎵嶇煡閬撴槸鍚︽坊鍔犳垚鍔�
+                            if (mqttdate != null)
                             {
-                                ///杩欓噷锛氱洃鍚琈TTP鎺ㄩ�佷笅鏉ヤ富棰橈紝鎵嶇煡閬撴槸鍚︽坊鍔犳垚鍔�
-                                frame.RemoveFromParent();//娣诲姞鎴愬姛鍏抽棴寮圭獥
-                                control.deviceId = mqttdate.id;
                                 control.sid = sid;
-                                action(control);
+                                //浼戠湢500姣锛屼负绛夊緟浜戠鍒涘缓deviceid锛�
+                                System.Threading.Thread.Sleep(500);
+                                GetControl(frame, control, (device) =>
+                                {
+                                    if (device != null)
+                                    {
+                                        control.deviceId = device.deviceId;
+                                        frame.RemoveFromParent();//娣诲姞鎴愬姛鍏抽棴寮圭獥
+
+                                        action(control);
+                                    }
+                                    else
+                                    {
+                                        //璇诲彇deviceid杩斿洖閿欒鎻愮ず
+                                        View.FailView failView = new View.FailView();
+                                        failView.ShouError((view) =>
+                                        {
+                                            view.Close();
+                                            ThreadAddControl(control, frame, action);
+                                        });
+
+                                    }
+                                });
                             }
                             else
                             {
@@ -72,23 +134,24 @@
                                     ThreadAddControl(control, frame, action);
                                 });
                             }
-
-
                         }
                         else
                         {
                             ErrorShow(responsePackNew);
                         }
                     });
+
+
                 }
             })
             { IsBackground = true }.Start();
 
         }
-
         /// <summary>
         /// 鑾峰彇绾㈠璁惧鍒楄〃
         /// </summary>
+        /// <param name="frame">log鍥炬爣鍔犺浇鐣岄潰</param>
+        /// <param name="action">鍥炶皟鍑芥暟</param>
         public static void GetPirDeviceList(FrameLayout frame, Action action)
         {
             //娓呴櫎涔嬪墠鍒楄〃;
@@ -160,6 +223,8 @@
         /// <summary>
         /// 鑾峰彇閬ユ帶鍣ㄥ垪琛�
         /// </summary>
+        /// <param name="frame">log鍥炬爣鍔犺浇鐣岄潰</param>
+        /// <param name="action">鍥炶皟鍑芥暟</param>
         public static void GetControlList(FrameLayout frame, Action action)
         {
             //鍔犺浇log
@@ -230,55 +295,121 @@
             { IsBackground = true }.Start();
 
         }
-
         /// <summary>
-        /// MQTT涓婚鎺ㄩ�佷笅鏉ョ殑鏁版嵁(閬ユ帶鍣ㄦ坊鍔�)
+        /// 鑾峰彇璁惧璇︽儏閫氳繃(spk,sid)
         /// </summary>
-        public static string addcontronsid = "";
+        /// <param name="frame">log鍥炬爣鍔犺浇鐣岄潰</param>
+        /// <param name="control">鍙戦�佸弬鏁板璞�</param>
+        /// <param name="action">鍥炶皟鍑芥暟</param>
+        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
+                {
+                    // 鑾峰彇璁惧璇︽儏閫氳繃(spk,sid)
+                    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 mqttdata = ""; 
         /// <summary>
         /// 鍒ゆ柇杩欎釜涓婚鏄惁鏄坊鍔犻仴鎺у櫒涓婚
         /// </summary>
+        /// <param name="sid">鍞竴鏍囪瘑</param>
+        /// <param name="timeValue">绛夊緟鏃堕棿鍊�</param>
         /// <returns></returns>
-        public Cloud MqttDate(string sid)
+        public Cloud MqttDate(string sid, int timeValue = 10)
         {
-            Cloud cloud = new Cloud();
+            Cloud cloud = null;
             var dateTime = DateTime.Now;
-            while ((DateTime.Now - dateTime).TotalMilliseconds < 10 * 1000)
+            while ((DateTime.Now - dateTime).TotalMilliseconds < timeValue * 1000)
             {
-                if (!string.IsNullOrEmpty(addcontronsid))
+                if (!string.IsNullOrEmpty(mqttdata))
                 {
-                    cloud = Newtonsoft.Json.JsonConvert.DeserializeObject<Cloud>(addcontronsid);
-                    for (int i = 0; i < cloud.objects.Count; i++)
+                    try
                     {
-                        var objects = cloud.objects[i];
-                        if (sid == objects.sid)
+                        var cloudjson = Newtonsoft.Json.JsonConvert.DeserializeObject<Cloud>(mqttdata);
+                        for (int i = 0; i < cloudjson.objects.Count; i++)
                         {
-                            break;
+                            var objects = cloudjson.objects[i];
+                            if (sid == objects.sid)
+                            {
+                                cloud = cloudjson;
+                                break;
+                            }
                         }
+                        break;
                     }
-                    break;
+                    catch { }
                 }
 
             }
             return cloud;
         }
-
         /// <summary>
         /// 閿欒鐮佹彁绀�
         /// </summary>
         /// <param name="responsePackNew"></param>
-        public void ErrorShow(ResponsePackNew responsePackNew)
+        /// <param name="str"></param>
+        public void ErrorShow(ResponsePackNew responsePackNew,string str="")
         {
-
-            if (responsePackNew != null && responsePackNew.Code == "14005")
-            {
-                new Intelligence.Automation.LogicView.TipPopView().FlashingBox(Language.StringByID(StringId.gatewayNotOnline));
-
+            if (str == "鍒犻櫎閬ユ帶鍣�") {
+                new Intelligence.Automation.LogicView.TipPopView().FlashingBox(Language.StringByID(StringId.delFail));
             }
             else
             {
-                new Intelligence.Automation.LogicView.TipPopView().FlashingBox(Language.StringByID(StringId.saveFail));
+                if (responsePackNew != null && responsePackNew.Code == "14005")
+                {
+                    new Intelligence.Automation.LogicView.TipPopView().FlashingBox(Language.StringByID(StringId.gatewayNotOnline));
 
+                }
+                else
+                {
+                    new Intelligence.Automation.LogicView.TipPopView().FlashingBox(Language.StringByID(StringId.saveFail));
+
+                }
             }
         }
 
@@ -289,7 +420,7 @@
         /// <summary>
         /// 璁惧id
         /// </summary>
-        public string id ="";
+        public string id = "";
         public List<Objects> objects = new List<Objects>();
         public string time_stamp = string.Empty;
 
@@ -301,6 +432,14 @@
 
         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