From 6d73bf6e816570291865674bef8bce8972e4de3f Mon Sep 17 00:00:00 2001
From: xm <1271024303@qq.com>
Date: 星期三, 01 十二月 2021 16:32:57 +0800
Subject: [PATCH] 2021-12-01-01

---
 HDL_ON/Entity/Function/Scene.cs |  120 ++++++++++++++++++++++++++++++++++++++++++++++++-----------
 1 files changed, 97 insertions(+), 23 deletions(-)

diff --git a/HDL_ON/Entity/Function/Scene.cs b/HDL_ON/Entity/Function/Scene.cs
index cc4379a..684aad0 100644
--- a/HDL_ON/Entity/Function/Scene.cs
+++ b/HDL_ON/Entity/Function/Scene.cs
@@ -77,17 +77,24 @@
         public string group = "1";
         /// <summary>
         /// 鍦烘櫙绫诲瀷
+        /// 0:鏅��
+        /// 1:鐢靛奖
+        /// 2:璋冨厜
         /// </summary>
         public SceneType sceneType = SceneType.OrdinaryScenes;
         /// <summary>
         /// 鏀惰棌鏍囪
         /// </summary>
         public bool collect = false;
+        /// <summary>
+        /// 鏄惁鍏佽鍒犻櫎
+        /// </summary>
+        public bool can_delete = true;
 
         /// <summary>
         /// 鍒涘缓璇ュ満鏅殑鐢ㄦ埛ID
         /// </summary>
-        public string userId = "";
+        public string userId = UserInfo.Current.ID;
 
         ///// <summary>
         ///// 鍦烘櫙鑳屾櫙
@@ -216,6 +223,18 @@
                 return "SceneData_" + sid;
             }
         }
+
+        /// <summary>
+        /// 鎵ц鍊掕鏃�
+        /// </summary>
+        int countdownTime = 0;
+        /// <summary>
+        /// 閲嶇疆鎵ц鍊掕鏃�
+        /// </summary>
+        public void ResetCountdownTime()
+        {
+            countdownTime = 0;
+        }
         /// <summary>
         /// 鍦烘櫙鎵ц\鍊掕鏃�
         /// </summary>
@@ -225,31 +244,30 @@
             //鍦烘櫙姝e湪鍊掕鏃舵墽琛屼腑
             if (LastExecutionTime != "" && Convert.ToDouble(LastExecutionTime) + Convert.ToDouble(delay) > Convert.ToDouble(Utlis.GetTimestamp(false)))
             {
-                int time = 0;
                 int.TryParse(Convert.ToInt32(
                     Convert.ToDouble(LastExecutionTime) + Convert.ToDouble(delay) - Convert.ToDouble(Utlis.GetTimestamp(false))
-                    ).ToString(), out time);
-                if (time > 0)
+                    ).ToString(), out countdownTime);
+                if (countdownTime > 0)
                 {
                     new System.Threading.Thread(() =>
                     {
-                        if (time > 0)
+                        if (countdownTime > 0)
                         {
-                            while (time > 0)
+                            while (countdownTime > 0)
                             {
                                 Application.RunOnMainThread(() =>
                                 {
-                                    if (time > 60)
+                                    if (countdownTime > 60)
                                     {
-                                        btnShowDelay.Text = (time / 60).ToString() + "min" + time % 60 + "s";
+                                        btnShowDelay.Text = (countdownTime / 60).ToString() + "min" + countdownTime % 60 + "s";
                                     }
                                     else
                                     {
-                                        btnShowDelay.Text = time.ToString() + "s";
+                                        btnShowDelay.Text = countdownTime.ToString() + "s";
                                     }
                                 });
                                 System.Threading.Thread.Sleep(1000);
-                                time--;
+                                countdownTime--;
                             }
                             Application.RunOnMainThread(() =>
                             {
@@ -310,6 +328,13 @@
             var revPack = pm.EditScene(this);
             if (revPack.Code == StateCode.SUCCESS)
             {
+                //閲嶇疆鎵ц鍊掕鏃�
+                this.countdownTime = 0;
+                if(MainPage.NoLoginMode)
+                {
+                    var ssd = System.Text.Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(this));
+                    Common.FileUtlis.Files.WriteFileByBytes(savePath, ssd);
+                }
                 var scenes = Newtonsoft.Json.JsonConvert.DeserializeObject<List<Scene>>(revPack.Data.ToString());
                 var tempScene = scenes.Find((obj) => obj.sid == sid);
                 if (tempScene != null)
@@ -326,10 +351,18 @@
         /// </summary>
         public string UpdateScene()
         {
+            if(MainPage.NoLoginMode)
+            {
+                var ssd = System.Text.Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(this));
+                Common.FileUtlis.Files.WriteFileByBytes(savePath, ssd);
+
+                return "0";
+            }
             var pm = new HttpServerRequest();
             var revPack = pm.EditScene(this);
             if (revPack.Code == StateCode.SUCCESS)
             {
+                this.countdownTime = 0;
                 var scenes = Newtonsoft.Json.JsonConvert.DeserializeObject<List<Scene>>(revPack.Data.ToString());
                 var tempScene = scenes.Find((obj) => obj.sid == sid);
                 if (tempScene != null)
@@ -352,7 +385,14 @@
             {
                 return Language.StringByID(StringId.NoDelay);
             }
-            string text = (delayInt / 60)+Language.StringByID(StringId.m)+(delayInt % 60)+Language.StringByID(StringId.s);
+            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)
             {
@@ -398,6 +438,7 @@
         /// </summary>
         public string delay = "0";
 
+
         Function _localFunction;
         /// <summary>
         /// 鏈湴瀵瑰簲鐨勫姛鑳�
@@ -419,7 +460,7 @@
         /// 杞崲鎴愬姛鑳藉璞�
         /// </summary>
         /// <returns></returns>
-        Function ConvertFunctionObject()
+        private Function ConvertFunctionObject()
         {
             var localFunction = FunctionList.List.GetDeviceFunctionList().Find((obj) => obj.sid == sid);
             return localFunction;
@@ -438,7 +479,9 @@
                 if (sfs.key == FunctionAttributeKey.OnOff)
                 {
                     if (sfs.value == "off")
+                    {
                         return Language.StringByID(StringId.Close);
+                    }
                 }
             }
             sceneFunctionInfo += Language.StringByID(StringId.Open) + " ";
@@ -462,12 +505,22 @@
             var briState = status.Find((obj) => obj.key == FunctionAttributeKey.Brightness);
             if (briState != null)
             {
-                sceneFunctionInfo += briState.value + "%";
+                sceneFunctionInfo += briState.value + "%" + " ";
             }
             var perState = status.Find((obj) => obj.key == FunctionAttributeKey.Percent);
             if (perState != null)
             {
-                sceneFunctionInfo += perState.value + "%";
+                sceneFunctionInfo += perState.value + "%" + " ";
+            }
+            var cctState = status.Find((obj) => obj.key == FunctionAttributeKey.CCT);
+            if(cctState != null)
+            {
+                sceneFunctionInfo += cctState.value + "%" + " ";
+            }
+            var rgbState = status.Find((obj) => obj.key == FunctionAttributeKey.RGB);
+            if(rgbState!=null)
+            {
+                //sceneFunctionInfo += new  cctState.value + "%" + " ";
             }
             return sceneFunctionInfo;
         }
@@ -482,6 +535,9 @@
     {
         public string key = "";
         public string value = "";
+
+        public int max = 0;
+        public int min = 0;
 
         /// <summary>
         /// 灞炴�у悕绉版樉绀烘枃鏈�
@@ -533,10 +589,15 @@
         /// <summary>
         /// 灞炴�у�煎崟浣�
         /// </summary>
-        public string GetUintString()
+        public string GetUintString(string inputKey = "")
         {
             var us = "";
-            switch (key)
+            var swithchString = key;
+            if(!string.IsNullOrEmpty(inputKey))
+            {
+                swithchString = inputKey;
+            }
+            switch (swithchString)
             {
                 case FunctionAttributeKey.SetTemp:
                 case FunctionAttributeKey.RoomTemp:
@@ -545,6 +606,9 @@
                 case FunctionAttributeKey.Percent:
                 case FunctionAttributeKey.Brightness:
                     us = "%";
+                    break;
+                case FunctionAttributeKey.CCT:
+                    us = "K";
                     break;
             }
             return us;
@@ -555,26 +619,35 @@
         /// 鑾峰彇鎸囧畾灞炴�х殑鏄剧ず鏂囨湰
         /// 涓嫳鏂囨樉绀�
         /// </summary>
-        public string GetValueText()
+        public string GetValueText(string temp = "")
         {
+            string catchString = value;
+            if(temp!= "")
+            {
+                catchString = temp;
+            }
             string text = "";
             switch (key)
             {
                 case FunctionAttributeKey.OnOff:
-                    text = value == "on" ? Language.StringByID(StringId.On) : Language.StringByID(StringId.OFF);
+                    text = catchString == "on" ? Language.StringByID(StringId.On) : Language.StringByID(StringId.OFF);
                     break;
                 case FunctionAttributeKey.SetTemp:
                 case FunctionAttributeKey.RoomTemp:
                 case FunctionAttributeKey.Brightness:
                 case FunctionAttributeKey.Percent:
-                    if (value == "")
+                    int outT = 0;
+                    int.TryParse(catchString,out outT);
+                    if (outT < 0)
+                        catchString = "0";
+                    if (catchString == "")
                     {
-                        value = "0";
+                        catchString = "0";
                     }
-                    text = value;
+                    text = catchString;
                     break;
                 case FunctionAttributeKey.Mode:
-                    switch (value)
+                    switch (catchString)
                     {
                         //----绌鸿皟
                         case "auto":
@@ -593,6 +666,7 @@
                             text = Language.StringByID(StringId.AirSupply);
                             break;
                         //-----鍦扮儹
+                        // 1:鏅��,2:鐧藉ぉ,3:澶滄櫄,4:绂诲紑,5:鏃堕棿
                         case "day":
                             text = Language.StringByID(StringId.Day);
                             break;
@@ -611,7 +685,7 @@
                     }
                     break;
                 case FunctionAttributeKey.FanSpeed:
-                    switch (value)
+                    switch (catchString)
                     {
                         case "high":
                             text = Language.StringByID(StringId.HighWindSpeed);

--
Gitblit v1.8.0