From f9181a9c8125136f597add7c30cb2ff508d54ba7 Mon Sep 17 00:00:00 2001
From: mac <user@users-MacBook-Pro.local>
Date: 星期四, 25 七月 2024 17:34:32 +0800
Subject: [PATCH] 2024年07月25日17:33:40

---
 HDL_ON/UI/UI2/3-Intelligence/Scene/SceneEditPage.cs |  376 +++++++++++++++++++++++++++++++++++++++++++++--------
 1 files changed, 315 insertions(+), 61 deletions(-)

diff --git a/HDL_ON/UI/UI2/3-Intelligence/Scene/SceneEditPage.cs b/HDL_ON/UI/UI2/3-Intelligence/Scene/SceneEditPage.cs
index 0196aa6..ae70c7a 100644
--- a/HDL_ON/UI/UI2/3-Intelligence/Scene/SceneEditPage.cs
+++ b/HDL_ON/UI/UI2/3-Intelligence/Scene/SceneEditPage.cs
@@ -98,8 +98,10 @@
 
         public void LoadPage(Action backRefresh)
         {
-             //DB_ResidenceData.Instance.sceneChooseRoomId
-            new TopViewDiv(bodyView, Language.StringByID(StringId.EditScene)).LoadTopView(backRefresh);
+            var topView = new TopViewDiv(bodyView, Language.StringByID(StringId.EditScene));
+            topView.maginY = 10;
+            topView.LoadTopView(backRefresh);
+
             initPage();
         }
 
@@ -109,8 +111,8 @@
 
             VerticalScrolViewLayout contentView = new VerticalScrolViewLayout()
             {
-                Y = Application.GetRealHeight(64),
-                Height = Application.GetRealHeight(603-50),
+                Y = Application.GetRealHeight(64 + 10),
+                Height = Application.GetRealHeight(603-50-10),
             };
             bodyView.AddChidren(contentView);
             contentView.AddChidren(new Button() { Height = Application.GetRealWidth(12) });
@@ -408,9 +410,9 @@
                 Y = Application.GetRealHeight(667 - 50),
                 Height = Application.GetRealHeight(50),
                 TextAlignment = TextAlignment.Center,
-                TextColor =  CSS_Color.WarningColor,
+                TextColor = CSS_Color.WarningColor,
                 TextSize = CSS_FontSize.SubheadingFontSize,
-                TextID =   StringId.Del,
+                TextID = StringId.Del,
                 BackgroundColor = CSS_Color.MainBackgroundColor,
                 //IsBold = true
             };
@@ -433,14 +435,20 @@
                     var pack = pm.GetSceneInfo(scene.userSceneId);
                     if (pack.Code == StateCode.SUCCESS)
                     {
-                        var sceneList = Newtonsoft.Json.JsonConvert.DeserializeObject<List<Scene>>(pack.Data.ToString());
-                        var tempScene = sceneList.Find((obj) => obj.userSceneId == scene.userSceneId);
-                        if (tempScene != null)
+                        if (pack.Data != null)
                         {
-                            scene.name = tempScene.name;
-                            scene.delay = tempScene.delay;
-                            scene.roomIds = tempScene.roomIds;
-                            scene.functions = tempScene.functions;
+                            var sceneList = Newtonsoft.Json.JsonConvert.DeserializeObject<List<Scene>>(pack.Data.ToString());
+                            if (sceneList != null)
+                            {
+                                var tempScene = sceneList.Find((obj) => obj.userSceneId == scene.userSceneId);
+                                if (tempScene != null)
+                                {
+                                    scene.name = tempScene.name;
+                                    scene.delay = tempScene.delay;
+                                    scene.roomIds = tempScene.roomIds;
+                                    scene.functions = tempScene.functions;
+                                }
+                            }
                         }
                         Application.RunOnMainThread(() =>
                         {
@@ -473,7 +481,6 @@
         void LoadFunctionRow()
         {
             functionListView.RemoveAll();
-            functionListView.Height = Application.GetRealWidth(65 * scene.functions.Count);
             for(int i =0;i<scene.functions.Count;)
             {
                 var scenefunction = scene.functions[i];
@@ -482,11 +489,32 @@
                     scene.functions.Remove(scenefunction);
                     continue;
                 }
-                //灏唖pk瀹炰綋閲岄潰鐨刴in max鍊兼斁鍏ュ満鏅姛鑳藉疄浣撻噷锛岃涓嶇劧鏁版嵁浼氫涪澶� 2022-06-21 16:06:45
-                foreach (var tt in scenefunction.status) {
-                    tt.min = scenefunction.localFunction.GetAttribute(tt.key).min;
-                    tt.max = scenefunction.localFunction.GetAttribute(tt.key).max;
-                    tt.valueList = scenefunction.localFunction.GetAttribute(tt.key).value;
+                functionListView.Height = Application.GetRealWidth(65 * scene.functions.Count);
+                try
+                {
+                    //灏唖pk瀹炰綋閲岄潰鐨刴in max鍊兼斁鍏ュ満鏅姛鑳藉疄浣撻噷锛岃涓嶇劧鏁版嵁浼氫涪澶� 2022-06-21 16:06:45
+                    foreach (var tt in scenefunction.status)
+                    {
+                        var attr = scenefunction.localFunction.GetAttribute(tt.key);
+                        if(attr == null)
+                        {
+                            continue;
+                        }
+                        tt.min = attr.min;
+                        tt.max = attr.max;
+                        tt.valueList = attr.value;
+                        if(tt.key == FunctionAttributeKey.SetTemp)
+                        {
+                            var tempType = scenefunction.localFunction.GetAttribute(FunctionAttributeKey.TempType);
+                            if(tempType != null)
+                            {
+                                tt.UintString = tempType.unit;
+                            }
+                        }
+                    }
+                }catch(Exception ex)
+                {
+                    MainPage.Log($"鍦烘櫙鍔犺浇鍔熻兘鍒楄〃寮傚父:{ex.Message}");
                 }
 
                 i++;
@@ -526,26 +554,6 @@
                 };
                 row.AddChidren(btnFunctionInfo);
 
-                var btnFunctionDelayInfo = new Button()
-                {
-                    Width = Application.GetRealWidth(327),
-                    Y = Application.GetRealWidth(35),
-                    Height = Application.GetRealWidth(32),
-                    TextAlignment = TextAlignment.TopRight,
-                    TextColor = CSS_Color.PromptingColor1,
-                    TextSize = CSS_FontSize.PromptFontSize_FirstLevel,
-                };
-                row.AddChidren(btnFunctionDelayInfo);
-
-                if (!string.IsNullOrEmpty(scenefunction.delay) && Convert.ToInt32( scenefunction.delay) > 0)
-                {
-                    btnFunctionDelayInfo.Text = Language.StringByID(StringId.Delay) + " " + new Scene() { delay = scenefunction.delay }.GetDelayText();
-                }
-                else
-                {
-                    btnFunctionDelayInfo.Text = Language.StringByID(StringId.NoDelay);
-                }
-
                 var btnFunctionName = new Button()
                 {
                     X = Application.GetRealWidth(16),
@@ -557,28 +565,72 @@
                 };
                 row.AddChidren(btnFunctionName);
 
-                var btnFunctionFloorAndRoom = new Button()
+                if (scenefunction.type == "7")
                 {
-                    X = Application.GetRealWidth(16),
-                    Y = Application.GetRealWidth(24),
-                    Height = Application.GetRealWidth(41),
-                    TextAlignment = TextAlignment.CenterLeft,
-                    TextColor = CSS_Color.PromptingColor1,
-                    TextSize = CSS_FontSize.TextFontSize,
-                    Text = scenefunction.localFunction.GetRoomListName(),
-                };
-                row.AddChidren(btnFunctionFloorAndRoom);
+                    btnFunctionName.Gravity = Gravity.CenterVertical;
+                    btnFunctionInfo.TextAlignment = TextAlignment.CenterRight;
+                    btnFunctionInfo.Gravity = Gravity.CenterVertical;
 
-                EventHandler<MouseEventArgs> skipEvent = (sender, e) =>
+                    btnFunctionName.MouseUpEventHandler = (sender, e) => {
+                        try
+                        {
+                            LoadAutomationSettingDialog(scenefunction, btnFunctionInfo);
+                        }
+                        catch (Exception ex)
+                        {
+                            MainPage.Log($"load automation error : {ex.Message}");
+                        }
+                    };
+                }
+                else
                 {
-                    var ssf = new SceneFunctionInfoEditPage(scene, scenefunction, refreshFunctionRowAction);
-                    MainPage.BasePageView.AddChidren(ssf);
-                    ssf.LoadPage();
-                    MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1;
-                };
-                btnFunctionName.MouseUpEventHandler = skipEvent;
-                btnFunctionFloorAndRoom.MouseUpEventHandler = skipEvent;
+                    var btnFunctionDelayInfo = new Button()
+                    {
+                        Width = Application.GetRealWidth(327),
+                        Y = Application.GetRealWidth(35),
+                        Height = Application.GetRealWidth(32),
+                        TextAlignment = TextAlignment.TopRight,
+                        TextColor = CSS_Color.PromptingColor1,
+                        TextSize = CSS_FontSize.PromptFontSize_FirstLevel,
+                    };
+                    row.AddChidren(btnFunctionDelayInfo);
 
+                    if (!string.IsNullOrEmpty(scenefunction.delay) && Convert.ToInt32(scenefunction.delay) > 0)
+                    {
+                        btnFunctionDelayInfo.Text = Language.StringByID(StringId.Delay) + " " + new Scene() { delay = scenefunction.delay }.GetDelayText();
+                    }
+                    else
+                    {
+                        btnFunctionDelayInfo.Text = Language.StringByID(StringId.NoDelay);
+                    }
+
+
+                    var btnFunctionFloorAndRoom = new Button()
+                    {
+                        X = Application.GetRealWidth(16),
+                        Y = Application.GetRealWidth(24),
+                        Height = Application.GetRealWidth(41),
+                        TextAlignment = TextAlignment.CenterLeft,
+                        TextColor = CSS_Color.PromptingColor1,
+                        TextSize = CSS_FontSize.TextFontSize,
+                        Text = scenefunction.localFunction.GetRoomListName(),
+                    };
+                    row.AddChidren(btnFunctionFloorAndRoom);
+
+                    EventHandler<MouseEventArgs> skipEvent = (sender, e) =>
+                    {
+                        var ssf = new SceneFunctionInfoEditPage(scene, scenefunction, refreshFunctionRowAction);
+                        MainPage.BasePageView.AddChidren(ssf);
+                        ssf.LoadPage();
+                        MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1;
+                    };
+                    btnFunctionName.MouseUpEventHandler = skipEvent;
+                    btnFunctionFloorAndRoom.MouseUpEventHandler = skipEvent;
+                    btnFunctionDelayInfo.MouseUpEventHandler = skipEvent;
+                    btnFunctionInfo.MouseUpEventHandler = skipEvent;
+                    btnRight.MouseUpEventHandler = skipEvent;
+                    row.MouseUpEventHandler = skipEvent;
+                }
 
                 Button btnDelSceneFunction = new Button() {
                     BackgroundColor = CSS_Color.WarningColor,
@@ -683,6 +735,196 @@
         }
 
 
+
+        /// <summary>
+        /// 鍔犺浇鑷姩鍖栭厤缃脊绐�
+        /// </summary>
+        void LoadAutomationSettingDialog(SceneFunction temp, Button btnTipText)
+        {
+            Dialog dialog = new Dialog();
+
+            var pView = new FrameLayout()
+            {
+                BackgroundColor = CSS_Color.DialogTransparentColor1,
+            };
+            dialog.AddChidren(pView);
+
+            var optionBaseView = new FrameLayout()
+            {
+                Y = Application.GetRealHeight(500),
+                Height = Application.GetRealHeight(160),
+                AnimateSpeed = 0.3f,
+                Animate = Animate.DownToUp,
+            };
+            pView.AddChidren(optionBaseView);
+
+            var optionView = new VerticalScrolViewLayout()
+            {
+                Gravity = Gravity.CenterHorizontal,
+                Width = Application.GetRealWidth(343),
+                Height = Application.GetRealHeight(100),
+                BackgroundColor = CSS_Color.MainBackgroundColor,
+                Radius = (uint)Application.GetRealWidth(12),
+                ScrollEnabled = false,
+            };
+            optionBaseView.AddChidren(optionView);
+
+            var btnOn = new Button()
+            {
+                Height = Application.GetRealHeight(50),
+                TextAlignment = TextAlignment.Center,
+                TextColor = CSS_Color.TextualColor,
+                SelectedTextColor = CSS_Color.MainColor,
+                TextSize = CSS_FontSize.SubheadingFontSize,
+                TextID = StringId.OpenArm,
+            };
+            optionView.AddChidren(btnOn);
+
+            optionView.AddChidren(new Button() { Height = Application.GetRealHeight(1), BackgroundColor = CSS_Color.DividingLineColor });
+
+            var btnOff = new Button()
+            {
+                Height = Application.GetRealHeight(50),
+                TextAlignment = TextAlignment.Center,
+                TextColor = CSS_Color.TextualColor,
+                SelectedTextColor = CSS_Color.MainColor,
+                TextSize = CSS_FontSize.SubheadingFontSize,
+                TextID = StringId.Close,
+            };
+            optionView.AddChidren(btnOff);
+
+            var btnCancel = new Button()
+            {
+                Gravity = Gravity.CenterHorizontal,
+                Y = Application.GetRealHeight(8) + optionView.Bottom,
+                Width = Application.GetRealWidth(343),
+                Height = Application.GetRealHeight(50),
+                BackgroundColor = CSS_Color.MainBackgroundColor,
+                Radius = (uint)Application.GetRealWidth(12),
+                TextID = StringId.Cancel,
+                TextColor = CSS_Color.WarningColor,
+                TextSize = CSS_FontSize.SubheadingFontSize,
+            };
+            optionBaseView.AddChidren(btnCancel);
+
+            dialog.Show();
+
+            pView.MouseUpEventHandler = (sender, e) =>
+            {
+                dialog.Close();
+            };
+
+            btnCancel.MouseUpEventHandler = (sender, e) =>
+            {
+                dialog.Close();
+            };
+            btnOn.MouseUpEventHandler = (sender, e) =>
+            {
+                dialog.Close();
+                temp.type = "7";
+                var kv = temp.status.Find((obj) => obj.key == "enable");
+                if (kv != null)
+                {
+                    kv.value = "true";
+                }
+                else
+                {
+                    temp.status.Add(new SceneFunctionStatus()
+                    {
+                        key = "enable",
+                        value = "true",
+                    });
+                }
+
+                var waitPage = new Loading();
+                bodyView.AddChidren(waitPage);
+                waitPage.Start("");
+                new System.Threading.Thread(() => {
+                    try
+                    {
+                        var code = scene.EditScene();
+                        Application.RunOnMainThread(() =>
+                        {
+                            if (code == "0")
+                            {
+                                btnTipText.TextID = StringId.OpenArm;
+                            }
+                            else
+                            {
+                                IMessageCommon.Current.ShowErrorInfoAlter(code);
+                            }
+                        });
+                    }
+                    catch { }
+                    finally
+                    {
+                        Application.RunOnMainThread(() => {
+                            if(waitPage!= null)
+                            {
+                                waitPage.RemoveFromParent();
+                                waitPage = null;
+                            }
+                        });
+                    }
+                })
+                { IsBackground = true }.Start();
+            };
+            btnOff.MouseUpEventHandler = (sender, e) =>
+            {
+                dialog.Close();
+                temp.type = "7";
+
+                var kv = temp.status.Find((obj) => obj.key == "enable");
+                if (kv != null)
+                {
+                    kv.value = "false";
+                }
+                else
+                {
+                    temp.status.Add(new SceneFunctionStatus()
+                    {
+                        key = "enable",
+                        value = "false",
+                    });
+                }
+
+                var waitPage = new Loading();
+                bodyView.AddChidren(waitPage);
+                waitPage.Start("");
+                new System.Threading.Thread(() => {
+                    try
+                    {
+                        var code = scene.EditScene();
+                        Application.RunOnMainThread(() =>
+                        {
+                            if (code == "0")
+                            {
+                                btnTipText.TextID = StringId.Close;
+                            }
+                            else
+                            {
+                                IMessageCommon.Current.ShowErrorInfoAlter(code);
+                            }
+                        });
+                    }
+                    catch { }
+                    finally
+                    {
+                        Application.RunOnMainThread(() => {
+                            if (waitPage != null)
+                            {
+                                waitPage.RemoveFromParent();
+                                waitPage = null;
+                            }
+                        });
+                    }
+                })
+                { IsBackground = true }.Start();
+            };
+
+        }
+
+
     }
     //--------------------------------------
     public partial class SceneEditPage
@@ -730,10 +972,22 @@
         void LoadEvent_ChangeFunctionList()
         {
             btnAddFunctionTitle.MouseUpEventHandler = (sender, e) => {
-                var sefp =new SceneFunctionListChoosePage(scene,refreshFunctionRowAction);
-                MainPage.BasePageView.AddChidren(sefp);
-                sefp.LoadPage();
-                MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1;
+                if (DB_ResidenceData.Instance.HomeGateway.isSupportSceneEnableAutomation)
+                {
+                    //var sefp =new SceneFunctionListChoosePage(scene,refreshFunctionRowAction);
+                    var sefp = new SceneTargetTypeChoosePage(scene, refreshFunctionRowAction);
+                    MainPage.BasePageView.AddChidren(sefp);
+                    sefp.LoadPage();
+                    MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1;
+                }
+                else
+                {
+                    var sefp = new SceneFunctionListChoosePage(scene,refreshFunctionRowAction);
+                    //var sefp = new SceneTargetTypeChoosePage(scene, refreshFunctionRowAction);
+                    MainPage.BasePageView.AddChidren(sefp);
+                    sefp.LoadPage();
+                    MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1;
+                }
             };
         }
 

--
Gitblit v1.8.0