From 365eadb33ee86b05ac74d408025d102a758c2efd Mon Sep 17 00:00:00 2001
From: 陈嘉乐 <cjl@hdlchina.com.cn>
Date: 星期五, 10 一月 2020 15:27:17 +0800
Subject: [PATCH] 2020-01-10 2020-01-10 1.修改切换本地和远程问题。 2.修改判断住宅网关方案。 3.其它优化修改。

---
 Crabtree/SmartHome/UI/SimpleControl/Phone/Schedule/AddSchedule.cs |   57 ++++++++++++++++++++++++++++++++++++++++++++++++---------
 1 files changed, 48 insertions(+), 9 deletions(-)

diff --git a/Crabtree/SmartHome/UI/SimpleControl/Phone/Schedule/AddSchedule.cs b/Crabtree/SmartHome/UI/SimpleControl/Phone/Schedule/AddSchedule.cs
index 9e042ca..e3c9da0 100644
--- a/Crabtree/SmartHome/UI/SimpleControl/Phone/Schedule/AddSchedule.cs
+++ b/Crabtree/SmartHome/UI/SimpleControl/Phone/Schedule/AddSchedule.cs
@@ -25,7 +25,7 @@
         public void ShowPage (Timer timerTemp, List<Timer> listTimer, bool isEdit = false)
         {
             UserMiddle.SettingPageView.ScrollEnabled = false;
-            timerTemp.RegionID = UserConfig.Instance.CurrentRegion.RegionID;
+            timerTemp.RegionID = UserConfig.Instance.CurrentRegion.Id;
             #region topview
             var topView = new RowLayout () {
                 Y = Application.GetRealHeight (36),
@@ -431,11 +431,16 @@
                 timerTemp.RoomName = roomNameList [0];
             }
             btnRoomChoose.Text = timerTemp.RoomName;
-       
+
             #endregion
 
             #region Devices
-            timerControlDeviceList = Newtonsoft.Json.JsonConvert.DeserializeObject<List<DeviceInfo>> (timerTemp.ControlDeviceData);//devicesControlDataList
+            try { 
+                timerControlDeviceList = Newtonsoft.Json.JsonConvert.DeserializeObject<List<DeviceInfo>> (timerTemp.ControlDeviceData);//devicesControlDataList
+            } catch {
+                timerControlDeviceList = null;
+            }
+
             if (timerControlDeviceList == null)
                 timerControlDeviceList = new List<DeviceInfo> ();
 
@@ -572,7 +577,7 @@
                     //new Alert ("", "璇峰~鍐欏畾鏃跺櫒鍚嶇О!", "Close").Show ();
                     new Alert ("", "Please set name for the timer!", "Close").Show ();
                     return;
-                } else if (listTimer.Find ((obj) => obj.TimerName == timerTemp.TimerName) != null && !isEdit) {
+                } else if (listTimer.Find ((obj) => obj.TimerName == timerTemp.TimerName) != null) {//2020-01-09 缂栬緫鐨勬椂鍊欎篃鎻愮ず閲嶅鍚嶅瓧
                     new Alert ("", "The timer name already exists. Please change it before saving it.", "Close").Show ();
                     return;
                 }
@@ -617,8 +622,8 @@
                     timerTemp.Periodicity = timerTemp.Periodicity.Remove (timerTemp.Periodicity.Length - 1, 1);
                 }
                 timerTemp.IsStart = true;
-                if (string.IsNullOrEmpty (timerTemp.Guid)) {
-                    timerTemp.Guid = Guid.NewGuid ().ToString ();
+                if (string.IsNullOrEmpty (timerTemp.Id)) {
+                    timerTemp.Id = Guid.NewGuid ().ToString ();
                 }
                 timerTemp.ControlDeviceData = Newtonsoft.Json.JsonConvert.SerializeObject (timerControlDeviceList);
                 MainPage.Loading.Start ("Saving...");
@@ -630,17 +635,19 @@
                         var requestJson = Newtonsoft.Json.JsonConvert.SerializeObject (timerTemp);
                         ResponsePack revertObj = null;
                         if (isEdit) {
-                            revertObj = MainPage.RequestHttps ("EditTimer", requestJson);
+                            revertObj = MainPage.RequestHttps (API.EditTimer, requestJson);
                         } else {
-                            revertObj = MainPage.RequestHttps ("AddTimer", requestJson);
+                            revertObj = MainPage.RequestHttps (API.AddTimer, requestJson);
                         }
 
                         Application.RunOnMainThread (() => {
                             if (revertObj == null) {
                                 new Alert ("", "Unable to save data, please check the network.", "Close").Show ();
-                            } else if (revertObj.StateCode == "SUCCESS") {
+                            } else if (revertObj.StateCode.ToUpper() == "SUCCESS") {
                                 this.RemoveFromParent ();
                                 action (timerTemp);
+                            } else {
+                                ShowErrorInfo (revertObj.StateCode);
                             }
                         });
                     } catch (Exception ex) {
@@ -655,6 +662,38 @@
 
         }
 
+        /// <summary>
+        //(1)Success 鍒欒皟鐢ㄦ鎺ュ彛鎴愬姛
+        //(2)NoRecord 浣忓畢鏈粦瀹氱綉鍏筹紒
+        //(3)NoExist 浣忓畢涓嶅瓨鍦紒
+        //(4)Exist 鐢熸垚鐨凣uid宸插瓨鍦紒
+        /// </summary>
+        void ShowErrorInfo (string stateCodeStr)
+        {
+            string mes = "";
+            if (stateCodeStr == "NoRecord") {
+                // 浣忓畢鏈粦瀹氱綉鍏筹紒
+                mes = ErrorCode.HomeNoRecord;
+            } else if (stateCodeStr == "NoExist") {
+                //浣忓畢涓嶅瓨鍦紒
+                mes = ErrorCode.HomeNoExist;
+            } else if (stateCodeStr == "Exist") {
+                //鐢熸垚鐨凣uid宸插瓨鍦紒
+                mes = ErrorCode.GuidExist;
+            }  else if (stateCodeStr == ErrorCode.NetworkError) {
+                mes = ErrorCode.NetworkError;
+            } else {
+                mes = ErrorCode.OperationFailed + ErrorCode.Reason + stateCodeStr;
+
+            }
+            if (!string.IsNullOrEmpty (mes)) {
+                //Application.RunOnMainThread (() => {
+                new Alert ("", mes, Language.StringByID (R.MyInternationalizationString.Close)).Show ();
+                //});
+            }
+
+        }
+
         private static void InitDeviceListView (List<Common> roomDeviceList, List<DeviceInfo> timerControlDeviceList, FrameLayout devicesListView)
         {
             devicesListView.RemoveAll ();

--
Gitblit v1.8.0