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/PirDevice/Method.cs |  226 ++++++++++++++++++++++++++++++++++++++++++++------------
 1 files changed, 177 insertions(+), 49 deletions(-)

diff --git a/HDL_ON/UI/UI2/4-PersonalCenter/PirDevice/Method.cs b/HDL_ON/UI/UI2/4-PersonalCenter/PirDevice/Method.cs
index d0745a8..e65cb76 100644
--- a/HDL_ON/UI/UI2/4-PersonalCenter/PirDevice/Method.cs
+++ b/HDL_ON/UI/UI2/4-PersonalCenter/PirDevice/Method.cs
@@ -8,6 +8,38 @@
 {
     public class Method
     {
+        /// <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;
+            }
+            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();
+                    };
+                });
+            }, Pir.currPir);
+        }
 
         /// <summary>
         /// 绠$悊浣嶇疆
@@ -84,7 +116,8 @@
                     if (responsePackNew != null && responsePackNew.Code == "0" && responsePackNew.Data.ToString() != "")
                     {
                         string sid = responsePackNew.Data.ToString();
-                        mqttdate = MqttDate(sid);
+                        controldata = "";
+                        mqttdate = MqttDate("閬ユ帶鍣�", sid);
                         if (mqttdate != null)
                         {
                             control.sid = sid;
@@ -180,11 +213,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);
                                     }
                                 }
                             }
@@ -226,7 +258,7 @@
 
         }
         /// <summary>
-        /// 鑾峰彇閬ユ帶鍣ㄥ垪琛�
+        /// 鑾峰彇鎵�鏈夌孩澶栧疂閬ユ帶鍣ㄥ垪琛�
         /// </summary>
         /// <param name="action">鍥炶皟鍑芥暟</param>
         public static void GetControlList(Action action)
@@ -241,7 +273,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());
@@ -281,6 +313,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>
@@ -289,21 +349,61 @@
         /// <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>
+        public static void ThreadSend(Control control, Action<ResponsePackNew> action, string str,string view, FrameLayout frame, Dialog dialog)
+        {
+           
             //鍔犺浇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 == "鍒犻櫎鎸夐敭")
+                    {
+                        // responsePackNew = PirSend.CodeRemove(control.deviceId, control.name);
+                    }
+                    else if (str == "鑾峰彇璁惧璇︽儏")
+                    {
+                        // 鑾峰彇璁惧璇︽儏閫氳繃(spk,sid)
+                        responsePackNew = PirSend.GetinfoBySid(control);
+                    }
+                    else if (str == "鑾峰彇閬ユ帶鍣ㄥ垪琛�")
+                    {
+                        responsePackNew = PirSend.ControlList(control.deviceId);
                     }
                 }
                 catch { }
@@ -312,61 +412,70 @@
                     Application.RunOnMainThread(() =>
                     {
                         loading.Hide();
-                        action(function);
+                        if (responsePackNew != null && responsePackNew.Code == "0" && responsePackNew.Data.ToString() != "")
+                        {
+                            action(responsePackNew);
+                        }
+                        else
+                        {
+                            Method method = new Method();
+                            method.ErrorShow(responsePackNew, "");
+                        }
+
                     });
                 }
 
             })
             { 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涓婚鎺ㄩ�佷笅鏉ョ殑鏁版嵁
+        /// MQTT涓婚鎺ㄩ�佷笅鏉ョ殑閬ユ帶鍣ㄦ暟鎹�
         /// </summary>
-        public static string mqttdata = ""; 
+        public static string controldata = "";
+        /// <summary>
+        /// MQTT涓婚鎺ㄩ�佷笅鏉ユ寜閿殑鏁版嵁
+        /// </summary>
+        public static string buttondata = "";
         /// <summary>
         /// 鍒ゆ柇杩欎釜涓婚鏄惁鏄坊鍔犻仴鎺у櫒涓婚
         /// </summary>
+        /// <param name="text">琛ㄧず涓嶅悓涓婚鏁版嵁</param>
         /// <param name="sid">鍞竴鏍囪瘑</param>
         /// <param name="timeValue">绛夊緟鏃堕棿鍊�</param>
         /// <returns></returns>
-        public Cloud MqttDate(string sid, int timeValue = 10)
+        public Cloud MqttDate(string text, string sid, int timeValue = 10)
         {
             Cloud cloud = null;
             var dateTime = DateTime.Now;
             while ((DateTime.Now - dateTime).TotalMilliseconds < timeValue * 1000)
             {
-                if (!string.IsNullOrEmpty(mqttdata))
+                string str = "";
+                if (text == "閬ユ帶鍣�")
+                {
+                    str = controldata;
+                }
+                else if (text == "鎸夐敭")
+                {
+                    str = buttondata;
+                }
+
+                if (!string.IsNullOrEmpty(str))
                 {
                     try
                     {
-                        var cloudjson = Newtonsoft.Json.JsonConvert.DeserializeObject<Cloud>(mqttdata);
+                        var cloudjson = Newtonsoft.Json.JsonConvert.DeserializeObject<Cloud>(str);
                         for (int i = 0; i < cloudjson.objects.Count; i++)
                         {
                             var objects = cloudjson.objects[i];
                             if (sid == objects.sid)
                             {
                                 cloud = cloudjson;
-                                mqttdata = "";
                                 break;
                             }
                         }
-                        if (cloud!=null)
+                        if (cloud != null)
                         {
                             break;
                         }
@@ -381,44 +490,63 @@
         /// 閿欒鐮佹彁绀�
         /// </summary>
         /// <param name="responsePackNew"></param>
-        /// <param name="str"></param>
-        public void ErrorShow(ResponsePackNew responsePackNew=null, string str = "")
+        /// <param name="text">鑷畾涔夐敊璇枃鏈�</param>
+        /// <param name="popValue">寮规绫诲瀷锛�1=闂儊寮规锛�</param>
+        public void ErrorShow(ResponsePackNew responsePackNew, string text, int popValue = 1)
         {
-            if (str == "鍒犻櫎閬ユ帶鍣�")
+            string str = "";
+            if (text == "鍒犻櫎閬ユ帶鍣�")
             {
-                new Intelligence.Automation.LogicView.TipPopView().FlashingBox(Language.StringByID(StringId.delFail));
-            } else if (str == "璇诲彇绾㈠瀹濆垪琛ㄥけ璐�") {
-
-                new Intelligence.Automation.LogicView.TipPopView().FlashingBox("璇诲彇绾㈠瀹濆垪琛ㄥけ璐�");
+                str = Language.StringByID(StringId.delFail);
+            }
+            else if (text == "璇诲彇绾㈠瀹濆垪琛ㄥけ璐�")
+            {
+                str = "璇诲彇绾㈠瀹濆垪琛ㄥけ璐�"; //Language.StringByID(StringId.delFail);
             }
             else
             {
-
                 if (responsePackNew != null)
                 {
+
                     switch (responsePackNew.Code)
                     {
 
                         case "14005":
                             {
-                                new Intelligence.Automation.LogicView.TipPopView().FlashingBox(Language.StringByID(StringId.gatewayNotOnline));
+                                str = Language.StringByID(StringId.gatewayNotOnline);
+
                             }
                             break;
                         case "10807":
                             {
-                                //绾㈠瀹濅笅閬ユ帶鍣ㄨ秴杩囨渶澶�(10涓�)鏁伴噺闄愬埗
-                                new Intelligence.Automation.LogicView.TipPopView().FlashingBox("绾㈠瀹濅笅閬ユ帶鍣ㄨ秴杩囨渶澶�(10涓�)鏁伴噺闄愬埗");
+                                str = "绾㈠瀹濅笅閬ユ帶鍣ㄨ秴杩囨渶澶�(10涓�)鏁伴噺闄愬埗";// Language.StringByID(StringId.gatewayNotOnline);
+
+
+                            }
+                            break;
+                        case "2":
+                            {
+                                str = "绯荤粺缁存姢涓瓇璇风◢鍚庡啀璇晘";
                             }
                             break;
                         default:
                             {
-                                new Intelligence.Automation.LogicView.TipPopView().FlashingBox(Language.StringByID(StringId.saveFail));
+                                str ="鑾峰彇鏁版嵁澶辫触" ;// Language.StringByID(StringId.saveFail);
                             }
                             break;
 
                     }
                 }
-
+            }
+            switch (popValue)
+            {
+                case 1:
+                    {
+                        new Intelligence.Automation.LogicView.TipPopView().FlashingBox(str);
+                    }
+                    break;
+                case 2: { } break;
+                case 3: { } break;
             }
         }
 

--
Gitblit v1.8.0