From 43b0d5870d528f23ecd6aeceb6cfd4325188b46f Mon Sep 17 00:00:00 2001
From: wxr <464027401@qq.com>
Date: 星期四, 01 七月 2021 15:50:43 +0800
Subject: [PATCH] Revert "1"

---
 HDL_ON/Entity/Function/Scene.cs |  471 +++++++++++++++++++++++++++++++++++++++++++++++++---------
 1 files changed, 394 insertions(+), 77 deletions(-)

diff --git a/HDL_ON/Entity/Function/Scene.cs b/HDL_ON/Entity/Function/Scene.cs
index 362a245..e4607ae 100644
--- a/HDL_ON/Entity/Function/Scene.cs
+++ b/HDL_ON/Entity/Function/Scene.cs
@@ -1,6 +1,8 @@
 锘縰sing System;
 using System.Collections.Generic;
+using HDL_ON.Common;
 using HDL_ON.DAL.Server;
+using HDL_ON.UI;
 using Shared;
 
 namespace HDL_ON.Entity
@@ -24,10 +26,18 @@
 
     public class Scene 
     {
+        public Scene()
+        {
+            sid = NewSid();
+            if (!DB_ResidenceData.Instance.CheckWhetherGatewayIdIsNull())
+            {
+                gatewayId = DB_ResidenceData.Instance.HomeGateway.gatewayId;
+            }
+        }
         /// <summary>
         /// 浜戠鍞竴ID
         /// </summary>
-        public string userSceneId = "";
+        public string userSceneId = null;
         /// <summary>
         /// 鍦烘櫙sid
         /// </summary>
@@ -48,44 +58,18 @@
         /// 鎵�灞炴埧闂村垪琛�
         /// </summary>
         public List<string> roomIds = new List<string>();
-        /// <summary>
-        /// 鎵�灞炴埧闂村垪琛�
-        /// </summary>
-        public List<string> uids = new List<string>();
+        ///// <summary>
+        ///// 鎵�灞炴埧闂村垪琛�
+        ///// </summary>
+        //public List<string> uids = new List<string>();
         /// <summary>
         /// 寤舵椂
         /// </summary>
-        public int delay = 0;
+        public string delay = "0";
         /// <summary>
-        /// 寤舵椂鏄剧ず鐨勬枃鏈�
+        /// 鍦烘櫙鐨勬渶鍚庝竴娆℃墽琛屾椂闂�
         /// </summary>
-        [Newtonsoft.Json.JsonIgnore]
-        public string delayText
-        {
-            get
-            {
-                string text = "";
-                switch (delay)
-                {
-                    case 0:
-                        text = Language.StringByID(StringId.NoDelay);
-                        break;
-                    case 30:
-                        text = "30s";
-                        break;
-                    case 60:
-                        text = "1min";
-                        break;
-                    case 120:
-                        text = "2min";
-                        break;
-                    case 300:
-                        text = "5min";
-                        break;
-                }
-                return text;
-            }
-        }
+        public string LastExecutionTime = "";
 
         /// <summary>
         /// 鍦烘櫙鍒嗙粍
@@ -100,10 +84,10 @@
         /// </summary>
         public bool collect = false;
 
-        ///// <summary>
-        ///// 鍦烘櫙鑳屾櫙
-        ///// </summary>
-        //public string ImagePath = "Intelligence/Gallery/scenebg1.png";//"FunctionIcon/Scene/s1.png";
+        /// <summary>
+        /// 鍒涘缓璇ュ満鏅殑鐢ㄦ埛ID
+        /// </summary>
+        public string userId = "";
 
         ///// <summary>
         ///// 鍦烘櫙鑳屾櫙
@@ -159,13 +143,14 @@
                 sTimeSpan = arry[0].ToString("X2") + arry[1].ToString("X2") + arry[2].ToString("X2") + arry[3].ToString("X2");
 
 
-                if (sTimeSpan.Length > 8)
+                if (sTimeSpan.Length >= 8)
                 {
                     sTimeSpan = sTimeSpan.Substring(0, 8);
                 }
                 else
                 {
-                    sTimeSpan = "00000000";
+                    sTimeSpan = Guid.NewGuid().ToString().Substring(0, 8);
+                    //sTimeSpan = "00000000";
                 }
 
                 sceneId = sOidBeginsWith + sTimeSpan;
@@ -202,7 +187,7 @@
             string roomNameList = "";
             foreach (var roomId in roomIds)
             {
-                var findRoom = DB_ResidenceData.residenceData.Rooms.Find(obj => obj.uid == roomId);
+                var findRoom = SpatialInfo.CurrentSpatial.RoomList.Find(obj => obj.roomId == roomId);
                 if (findRoom == null)
                 {
                     continue;
@@ -215,7 +200,7 @@
             }
             if (roomNameList == "" )
             {
-                roomNameList = Shared.Language.StringByID(StringId.WholeHouseScene);
+                roomNameList = Shared.Language.StringByID(StringId.WholeZone);
             }
             return roomNameList;
         }
@@ -231,53 +216,171 @@
                 return "SceneData_" + sid;
             }
         }
-
         /// <summary>
-        /// 淇濆瓨鍔熻兘鏁版嵁
+        /// 鍦烘櫙鎵ц\鍊掕鏃�
         /// </summary>
-        public void SaveSceneData(bool upServer)
+        /// <param name="btnShowDelay"></param>
+        public void SceneCountDown(Button btnShowDelay)
         {
-            if (upServer)
+            //鍦烘櫙姝e湪鍊掕鏃舵墽琛屼腑
+            if (LastExecutionTime != "" && Convert.ToDouble(LastExecutionTime) + Convert.ToDouble(delay) > Convert.ToDouble(Utlis.GetTimestamp(false)))
             {
-                UploadScene();
+                int time = 0;
+                int.TryParse(Convert.ToInt32(
+                    Convert.ToDouble(LastExecutionTime) + Convert.ToDouble(delay) - Convert.ToDouble(Utlis.GetTimestamp(false))
+                    ).ToString(), out time);
+                if (time > 0)
+                {
+                    new System.Threading.Thread(() =>
+                    {
+                        if (time > 0)
+                        {
+                            while (time > 0)
+                            {
+                                Application.RunOnMainThread(() =>
+                                {
+                                    if (time > 60)
+                                    {
+                                        btnShowDelay.Text = (time / 60).ToString() + "min" + time % 60 + "s";
+                                    }
+                                    else
+                                    {
+                                        btnShowDelay.Text = time.ToString() + "s";
+                                    }
+                                });
+                                System.Threading.Thread.Sleep(1000);
+                                time--;
+                            }
+                            Application.RunOnMainThread(() =>
+                            {
+                                btnShowDelay.Text = "";
+                            });
+                        }
+                    })
+                    { IsBackground = true, Priority = System.Threading.ThreadPriority.BelowNormal }.Start();
+                }
             }
+        }
+        /// <summary>
+        /// 淇濆瓨鍦烘櫙鏁版嵁鏂囦欢
+        /// </summary>
+        public void SaveSceneFile()
+        {
             var ssd = System.Text.Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(this));
-            FileUtils.WriteFileByBytes(savePath, ssd);
+            FileUtlis.Files.WriteFileByBytes(savePath, ssd);
             MainPage.Log($"Save Scene Data : {savePath}");
         }
 
         /// <summary>
-        /// 涓婁紶鏁版嵁鍒颁簯绔�
+        /// 鏀惰棌鍦烘櫙
         /// </summary>
-        void UploadScene()
+        /// <returns></returns>
+        public void CollectScene()
         {
-            var pm = new HttpServerRequest();
-            ResponsePackNew revPack;
-            if (string.IsNullOrEmpty(createTime) && string.IsNullOrEmpty(modifyTime))
+            var result = StateCode.SUCCESS;
+            new System.Threading.Thread(() =>
             {
-                revPack = pm.AddScene(this);
-                if (revPack.Code == StateCode.SUCCESS)
+                if (collect)
                 {
-                    var ssd = System.Text.Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(this));
-                    FileUtils.WriteFileByBytes(savePath, ssd);
+                    result = ApiUtlis.Ins.HttpRequest.CollectScene(userSceneId);
                 }
-            }
-            else if (!string.IsNullOrEmpty(createTime) && !string.IsNullOrEmpty(modifyTime))
-            {
-                revPack = pm.EditScene(this);
-                if (revPack.Code == StateCode.SUCCESS)
+                else
                 {
-                    var scenes = Newtonsoft.Json.JsonConvert.DeserializeObject<List<Scene>>(revPack.Data.ToString());
-                    var tempScene = scenes.Find((obj) => obj.sid == sid);
-                    if (tempScene != null)
+                    result = ApiUtlis.Ins.HttpRequest.CancelCollectScene(userSceneId);
+                }
+                //鎻愮ず閿欒
+                if (result != StateCode.SUCCESS)
+                {
+                    Application.RunOnMainThread(() =>
                     {
-                        var ssd = System.Text.Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(tempScene));
-                        FileUtils.WriteFileByBytes(savePath, ssd);
-                    }
+                        collect = !collect;
+                        IMessageCommon.Current.ShowErrorInfoAlter(result);
+                    });
                 }
-            }
+            })
+            { IsBackground = true }.Start();
         }
 
+        /// <summary>
+        /// 缂栬緫鍦烘櫙
+        /// </summary>
+        public string EditScene()
+        {
+            var pm = new HttpServerRequest();
+            var revPack = pm.EditScene(this);
+            if (revPack.Code == StateCode.SUCCESS)
+            {
+                var scenes = Newtonsoft.Json.JsonConvert.DeserializeObject<List<Scene>>(revPack.Data.ToString());
+                var tempScene = scenes.Find((obj) => obj.sid == sid);
+                if (tempScene != null)
+                {
+                    var ssd = System.Text.Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(tempScene));
+                    Common.FileUtlis.Files.WriteFileByBytes(savePath, ssd);
+                }
+            }
+            return revPack.Code;
+        }
+
+        /// <summary>
+        /// 淇敼鍦烘櫙
+        /// </summary>
+        public string UpdateScene()
+        {
+            var pm = new HttpServerRequest();
+            var revPack = pm.EditScene(this);
+            if (revPack.Code == StateCode.SUCCESS)
+            {
+                var scenes = Newtonsoft.Json.JsonConvert.DeserializeObject<List<Scene>>(revPack.Data.ToString());
+                var tempScene = scenes.Find((obj) => obj.sid == sid);
+                if (tempScene != null)
+                {
+                    var ssd = System.Text.Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(tempScene));
+                    Common.FileUtlis.Files.WriteFileByBytes(savePath, ssd);
+                }
+            }
+            return revPack.Code;
+        }
+
+        /// <summary>
+        /// 寤舵椂鏄剧ず鐨勬枃鏈�
+        /// </summary>
+        public string GetDelayText()
+        {
+            var delayInt = 0;
+            int.TryParse(delay,out delayInt);
+            if(delayInt == 0)
+            {
+                return Language.StringByID(StringId.NoDelay);
+            }
+            string text = "";
+            if (delayInt > 60)
+            {
+                text = (delayInt / 60) + Language.StringByID(StringId.m) + (delayInt % 60) + Language.StringByID(StringId.s);
+            }else
+            {
+                text = delayInt + Language.StringByID(StringId.s);
+            }
+            return text;
+            switch (delay)
+            {
+                case "0":
+                    text = Language.StringByID(StringId.NoDelay);
+                    break;
+                case "30":
+                    text = "30s";
+                    break;
+                case "60":
+                    text = "1min";
+                    break;
+                case "120":
+                    text = "2min";
+                    break;
+                case "300":
+                    text = "5min";
+                    break;
+            }
+            return text;
+        }
         /// <summary>
         /// 浜戠鏁版嵁鍒涘缓鐨勬椂闂�
         /// </summary>
@@ -286,6 +389,8 @@
         /// 浜戠鏁版嵁淇敼鐨勬渶鍚庢椂闂�
         /// </summary>
         public string modifyTime = "";
+
+
     }
     /// <summary>
     /// 鍦烘櫙鍔熻兘瀵硅薄
@@ -305,10 +410,11 @@
         /// 鏈湴瀵瑰簲鐨勫姛鑳�
         /// </summary>
         [Newtonsoft.Json.JsonIgnore]
-        public Function localFunction {
+        public Function localFunction
+        {
             get
             {
-                if(_localFunction == null)
+                if (_localFunction == null)
                 {
                     _localFunction = ConvertFunctionObject();
                 }
@@ -322,14 +428,60 @@
         /// <returns></returns>
         Function ConvertFunctionObject()
         {
-            var localFunction = DB_ResidenceData.functionList.GetAllDeviceFunctionList().Find((obj) => obj.sid == sid);
-            foreach (var s in status)
-            {
-                localFunction.attributes.Add(new FunctionAttributes() { key = s.key, curValue = s.value, value = new List<string>() { s.value } });
-            }
+            var localFunction = FunctionList.List.GetDeviceFunctionList().Find((obj) => obj.sid == sid);
             return localFunction;
         }
-      
+
+
+        /// <summary>
+        /// 瑙f瀽鍦烘櫙鍔熻兘鏁版嵁
+        /// </summary>
+        /// <param name="sceneFunction"></param>
+        public string GetFunctionScnenInfo()
+        {
+            var sceneFunctionInfo = "";
+            foreach (var sfs in status)
+            {
+                if (sfs.key == FunctionAttributeKey.OnOff)
+                {
+                    if (sfs.value == "off")
+                    {
+                        return Language.StringByID(StringId.Close);
+                    }
+                }
+            }
+            sceneFunctionInfo += Language.StringByID(StringId.Open) + " ";
+
+            var modeState = status.Find((obj) => obj.key == FunctionAttributeKey.Mode);
+            var tempState = status.Find((obj) => obj.key == FunctionAttributeKey.SetTemp);
+            var fanState = status.Find((obj) => obj.key == FunctionAttributeKey.FanSpeed);
+            if (modeState != null)
+            {
+                sceneFunctionInfo += modeState.GetValueText() + " ";
+            }
+            if (tempState != null)
+            {
+                sceneFunctionInfo += tempState.GetValueText() + " ";
+                sceneFunctionInfo += tempState.GetUintString();
+            }
+            if (fanState != null)
+            {
+                sceneFunctionInfo += fanState.GetValueText() + " ";
+            }
+            var briState = status.Find((obj) => obj.key == FunctionAttributeKey.Brightness);
+            if (briState != null)
+            {
+                sceneFunctionInfo += briState.value + "%";
+            }
+            var perState = status.Find((obj) => obj.key == FunctionAttributeKey.Percent);
+            if (perState != null)
+            {
+                sceneFunctionInfo += perState.value + "%";
+            }
+            return sceneFunctionInfo;
+        }
+
+
     }
 
     /// <summary>
@@ -339,6 +491,171 @@
     {
         public string key = "";
         public string value = "";
+
+        /// <summary>
+        /// 灞炴�у悕绉版樉绀烘枃鏈�
+        /// 涓嫳鏂囨樉绀�
+        /// </summary>
+        public string GetNameText()
+        {
+            string text = "";
+            switch (key)
+            {
+                case FunctionAttributeKey.OnOff:
+                    text = Language.StringByID(StringId.OnOff);
+                    break;
+                case FunctionAttributeKey.Brightness:
+                    text = Language.StringByID(StringId.Brightness);
+                    break;
+                case FunctionAttributeKey.RGB:
+                    text = Language.StringByID(StringId.ColorValue);
+                    break;
+                case FunctionAttributeKey.Mode:
+                    text = Language.StringByID(StringId.Mode);
+                    break;
+                case FunctionAttributeKey.FanSpeed:
+                    text = Language.StringByID(StringId.FanSpeed);
+                    break;
+                case FunctionAttributeKey.SetTemp:
+                    text = Language.StringByID(StringId.Temp);
+                    break;
+                case FunctionAttributeKey.RoomTemp:
+                    text = Language.StringByID(StringId.IndoorTemp);
+                    break;
+                case FunctionAttributeKey.Delay:
+                    text = Language.StringByID(StringId.Delay);
+                    break;
+                case FunctionAttributeKey.CCT:
+                    text = "CCT";
+                    break;
+                case FunctionAttributeKey.Percent:
+                    text = Language.StringByID(StringId.PercentAdjustment);
+                    break;
+                case FunctionAttributeKey.FadeTime:
+                    text = Language.StringByID(StringId.FadeSpeed);
+                    break;
+            }
+            return text;
+        }
+
+
+        /// <summary>
+        /// 灞炴�у�煎崟浣�
+        /// </summary>
+        public string GetUintString()
+        {
+            var us = "";
+            switch (key)
+            {
+                case FunctionAttributeKey.SetTemp:
+                case FunctionAttributeKey.RoomTemp:
+                    us = "掳C";
+                    break;
+                case FunctionAttributeKey.Percent:
+                case FunctionAttributeKey.Brightness:
+                    us = "%";
+                    break;
+            }
+            return us;
+        }
+
+
+        /// <summary>
+        /// 鑾峰彇鎸囧畾灞炴�х殑鏄剧ず鏂囨湰
+        /// 涓嫳鏂囨樉绀�
+        /// </summary>
+        public string GetValueText()
+        {
+            string text = "";
+            switch (key)
+            {
+                case FunctionAttributeKey.OnOff:
+                    text = value == "on" ? Language.StringByID(StringId.On) : Language.StringByID(StringId.OFF);
+                    break;
+                case FunctionAttributeKey.SetTemp:
+                case FunctionAttributeKey.RoomTemp:
+                case FunctionAttributeKey.Brightness:
+                case FunctionAttributeKey.Percent:
+                    if (value == "")
+                    {
+                        value = "0";
+                    }
+                    text = value;
+                    break;
+                case FunctionAttributeKey.Mode:
+                    switch (value)
+                    {
+                        //----绌鸿皟
+                        case "auto":
+                            text = Language.StringByID(StringId.Auto);
+                            break;
+                        case "cool":
+                            text = Language.StringByID(StringId.Cool);
+                            break;
+                        case "heat":
+                            text = Language.StringByID(StringId.Heat);
+                            break;
+                        case "dry":
+                            text = Language.StringByID(StringId.Dry);
+                            break;
+                        case "fan":
+                            text = Language.StringByID(StringId.AirSupply);
+                            break;
+                        //-----鍦扮儹
+                        case "day":
+                            text = Language.StringByID(StringId.Day);
+                            break;
+                        case "night":
+                            text = Language.StringByID(StringId.Night);
+                            break;
+                        case "away":
+                            text = Language.StringByID(StringId.Away);
+                            break;
+                        case "normal":
+                            text = Language.StringByID(StringId.Normal);
+                            break;
+                        case "timer":
+                            text = Language.StringByID(StringId.Timer);
+                            break;
+                    }
+                    break;
+                case FunctionAttributeKey.FanSpeed:
+                    switch (value)
+                    {
+                        case "high":
+                            text = Language.StringByID(StringId.HighWindSpeed);
+                            break;
+                        case "medium":
+                            text = Language.StringByID(StringId.MiddleWindSpeed);
+                            break;
+                        case "low":
+                            text = Language.StringByID(StringId.LowWindSpeed);
+                            break;
+                        case "auto":
+                            text = Language.StringByID(StringId.Auto);
+                            break;
+                        default:
+                            text = "low";
+                            break;
+                    }
+                    break;
+                case "high":
+                    text = Language.StringByID(StringId.HighWindSpeed);
+                    break;
+                case "medium":
+                    text = Language.StringByID(StringId.MiddleWindSpeed);
+                    break;
+                case "low":
+                    text = Language.StringByID(StringId.LowWindSpeed);
+                    break;
+                case "auto":
+                    text = Language.StringByID(StringId.Auto);
+                    break;
+            }
+            return text;
+        }
+
+
     }
     /// <summary>
     /// 鍦烘櫙鎺ㄩ�侀厤缃�

--
Gitblit v1.8.0