From 4e343aa2d3bba9e1dc5519afa2564a230c556496 Mon Sep 17 00:00:00 2001 From: 陈嘉乐 <cjl@hdlchina.com.cn> Date: 星期五, 05 二月 2021 15:13:14 +0800 Subject: [PATCH] 2021-2-5-1 --- Crabtree/SmartHome/UI/SimpleControl/Phone/Schedule/Method.cs | 279 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 279 insertions(+), 0 deletions(-) diff --git a/Crabtree/SmartHome/UI/SimpleControl/Phone/Schedule/Method.cs b/Crabtree/SmartHome/UI/SimpleControl/Phone/Schedule/Method.cs new file mode 100644 index 0000000..19e74f1 --- /dev/null +++ b/Crabtree/SmartHome/UI/SimpleControl/Phone/Schedule/Method.cs @@ -0,0 +1,279 @@ +锘縰sing System; +using System.Collections.Generic; +using Shared; +using Shared.SimpleControl.R; + +namespace SmartHome +{ + public class Method + { + + /// <summary> + /// 鑾峰彇浜戠璁惧鍒楄〃 + /// </summary> + public static void GetDeviceList () + { + Shared.SimpleControl.MainPage.Loading.Start (Language.StringByID (MyInternationalizationString.load)); + System.Threading.Tasks.Task.Run (() => { + try { + var deviceResult = HttpServerRequest.Current.GetDeviceList (); + + if (deviceResult.Code == StateCode.SUCCESS) { + var deviceList = Newtonsoft.Json.JsonConvert.DeserializeObject<DevcieFunctionRes> (deviceResult.Data.ToString ()); + //Utlis.WriteLine ("deviceList Count" + deviceList.list.Count); + Timer.deviceList.Clear (); + for (int i = 0; i < deviceList.list.Count; i++) { + Timer.deviceList.Add (deviceList.list [i]); + } + } else { + Utlis.ShowTip ("璁惧鍒楄〃"); + } + } catch { + Shared.SimpleControl.MainPage.FailureToServer (); + } finally { + Application.RunOnMainThread (() => { + Shared.SimpleControl.MainPage.Loading.Hide (); + + }); + } + }); + } + #region Utc 鏃堕棿鎴� 鍖椾含鏃堕棿 + + /// <summary> + /// 鏈湴鏃堕棿杞崲utc鏃堕棿 + /// </summary> + /// <param name="s"></param> + /// <returns></returns> + public static string GetUtcTime (string s) + { + int hour = 12; + int Minute = 30; + try { + if (s.Contains (":")) { + string [] str = s.Split (':'); + hour = int.Parse (str [0]); + Minute = int.Parse (str [1]); + } else if (s.Contains ("-")) { + string [] str = s.Split ('-'); + hour = int.Parse (str [0]); + Minute = int.Parse (str [1]); + } + } catch { } + DateTime dateTime = new DateTime (DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, hour, Minute, DateTime.Now.Second, DateTime.Now.Millisecond); + return dateTime.ToUniversalTime ().ToString ("hh") + ":" + dateTime.ToUniversalTime ().ToString ("mm"); + + } + + /// <summary> + /// utc鏃堕棿杞崲鏈湴鏃堕棿 + /// </summary> + /// <param name="s"></param> + /// <returns></returns> + public static string GetLocalUtcTime (string s) + { + int hour = 12; + int Minute = 30; + try { + if (s.Contains (":")) { + string [] str = s.Split (':'); + hour = int.Parse (str [0]); + Minute = int.Parse (str [1]); + } else if (s.Contains ("-")) { + string [] str = s.Split ('-'); + hour = int.Parse (str [0]); + Minute = int.Parse (str [1]); + } + } catch { } + DateTime utcTime = new DateTime (DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, hour, Minute, DateTime.Now.Second, DateTime.Now.Millisecond); + var dateTime = TimeZoneInfo.ConvertTimeFromUtc (utcTime, TimeZoneInfo.Local); + return dateTime.ToString ("hh") + ":" + dateTime.ToString ("mm"); + } + /// <summary> + /// 鑾峰彇鏃堕棿鎴筹紙鏃堕棿鏍煎紡杞崲鏃堕棿鎴筹級 + /// </summary> + /// <param name="s"></param> + /// <returns></returns> + public static long GetUnixTime (string s) + { + int hour = 12; + int Minute = 30; + try { + if (s.Contains (":")) { + string [] str = s.Split (':'); + hour = int.Parse (str [0]); + Minute = int.Parse (str [1]); + } else if (s.Contains ("-")) { + string [] str = s.Split ('-'); + hour = int.Parse (str [0]); + Minute = int.Parse (str [1]); + } + } catch { } + + DateTime dateTime = new DateTime (DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, hour, Minute, DateTime.Now.Second, DateTime.Now.Millisecond); + System.DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime (new System.DateTime (1970, 1, 1)); // 褰撳湴鏃跺尯 + long timeStamp = (long)(dateTime - startTime).TotalSeconds;//鐩稿樊绉掓暟 + return timeStamp; + } + /// <summary> + /// 鏃堕棿鎴宠浆鎹㈡垚鏃堕棿鏍煎紡 + /// </summary> + /// <param name="unixTimeStamp">鏃堕棿鎴�</param> + /// <returns></returns> + public static DateTime GetLocalTime (int unixTimeStamp) + { + System.DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime (new System.DateTime (1970, 1, 1)); // 褰撳湴鏃跺尯 + DateTime dt = startTime.AddMilliseconds (unixTimeStamp); + return dt; + } + #endregion + + /// <summary> + /// 鑾峰彇鎴块棿鍒楄〃 + /// </summary> + /// <returns></returns> + public List<Room> GetRoomList () + { + List<Room> list = new List<Room> (); + list.Add (new Room { Name = "ALL" }); + for (int i = 0; i < Room.Lists.Count; i++) { + var room = Room.Lists [i]; + if (room == null || string.IsNullOrEmpty (room.Name)) { + continue; + } + list.Add (room); + } + return list; + } + /// <summary> + /// 鑾峰彇鎴块棿璁惧鍒楄〃 + /// </summary> + /// <returns></returns> + public List<Function> GetRoomDeviceList (string roomName) + { + List<Function> deviceList = new List<Function> (); + var roomList = GetRoomList (); + if (roomName == "ALL") { + for (int i = 0; i < roomList.Count; i++) { + var room = roomList [i]; + if (room == null || string.IsNullOrEmpty (room.Name)) { + continue; + } + for (int j = 0; j < room.DeviceList.Count; j++) { + var device = room.DeviceList [j]; + if (device == null) { + continue; + } + //浜戠鍖归厤鏈湴鍒楄〃 + var dev = GetloudsDevice (device); + if (dev != null) { + if (deviceList.Find ((c) => c.deviceId == dev.deviceId) == null) { + deviceList.Add (dev); + } + } + } + } + } else { + for (int i = 0; i < roomList.Count; i++) { + var room = roomList [i]; + if (room == null || string.IsNullOrEmpty (room.Name)) { + continue; + } + if (room.Name!= roomName) { + continue; + } + for (int j = 0; j < room.DeviceList.Count; j++) { + var device = room.DeviceList [j]; + if (device == null) { + continue; + } + //浜戠鍖归厤鏈湴鍒楄〃 + var dev = GetloudsDevice (device); + if (dev != null) { + deviceList.Add (dev); + } + } + } + } + + return Spk_Equipment (deviceList); + } + /// <summary> + /// 鑾峰彇鏀寔鐨勮澶囧垪琛� + /// </summary> + /// <param name="list"></param> + /// <returns></returns> + public List<Function> Spk_Equipment (List<Function> list) + { + List<Function> DeviceList = new List<Function> (); + for (int i = 0; i < list.Count; i++) { + var device = list [i]; + switch (device.spk) { + case "light.dimming": + case "light.switch": + case "curtain.roller": + case "curtain.trietex": + case "curtain.switch": + case "electrical.socket": { + //鐩墠鏀寔鐨勮澶� + DeviceList.Add (device); + } + break; + + } + + + + } + return DeviceList; + } + /// <summary> + /// 鍖归厤浜戠璁惧锛岃繑鍥炰簯绔澶� + /// </summary> + /// <param name="common">鏈湴璁惧</param> + /// <returns></returns> + public Function GetloudsDevice (Common common) + { + for (int j = 0; j < Timer.deviceList.Count; j++) { + var cloudsDevice = Timer.deviceList [j]; + if (common.SubnetID == cloudsDevice.bus.SubnetID && + common.DeviceID == cloudsDevice.bus.DeviceID && + common.LoopID == cloudsDevice.bus.LoopId + ) { + return cloudsDevice; + } + } + return null; + } + /// <summary> + //(1)Success 鍒欒皟鐢ㄦ鎺ュ彛鎴愬姛 + //(2)NoRecord 浣忓畢鏈粦瀹氱綉鍏筹紒 + //(3)NoExist 浣忓畢涓嶅瓨鍦紒 + /// </summary> + public void ShowGetTimerListErrorInfo (string stateCodeStr) + { + string mes = ""; + if (stateCodeStr == "NoRecord") { + // 浣忓畢鏈粦瀹氱綉鍏筹紒 + mes = ErrorCode.HomeNoRecord; + } else if (stateCodeStr == "NoExist") { + //浣忓畢涓嶅瓨鍦紒 + mes = ErrorCode.HomeNoExist; + } 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 (Shared.SimpleControl.R.MyInternationalizationString.Close)).Show (); + }); + } + + + + + } + } +} -- Gitblit v1.8.0