From 5b77d9d57a6cddb474a66ca54401ad5ab0892db3 Mon Sep 17 00:00:00 2001
From: wxr <464027401@qq.com>
Date: 星期三, 23 十一月 2022 14:23:42 +0800
Subject: [PATCH] Merge branch 'dev--wxr' into LcSdkV1

---
 HDL_ON/UI/UI2/2-Classification/SceneControlZone.cs |  176 +++++++++++++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 167 insertions(+), 9 deletions(-)

diff --git a/HDL_ON/UI/UI2/2-Classification/SceneControlZone.cs b/HDL_ON/UI/UI2/2-Classification/SceneControlZone.cs
index 5b6e62f..024d8d6 100644
--- a/HDL_ON/UI/UI2/2-Classification/SceneControlZone.cs
+++ b/HDL_ON/UI/UI2/2-Classification/SceneControlZone.cs
@@ -1,4 +1,8 @@
 锘縰sing System;
+using System.Collections.Generic;
+using System.Threading;
+using HDL_ON.Common;
+using HDL_ON.DAL.Server;
 using HDL_ON.Entity;
 using HDL_ON.UI.CSS;
 using Shared;
@@ -77,7 +81,10 @@
                 UnSelectedImagePath = "Collection/CollectionGrayIcon.png",
                 IsSelected = scene.collect
             };
-            this.AddChidren(btnCollectionIcon);
+            if (scene.sceneType != SceneType.LightScene)
+            {
+                this.AddChidren(btnCollectionIcon);
+            }
 
             btnIcon.UnSelectedImagePath = "FunctionIcon/Scene/SceneIcon.png";
             if (scene.sceneType == SceneType.MovieScene)
@@ -116,14 +123,165 @@
         /// </summary>
         void LoadEvent_ControlScene(Button btnName, Button btnFromFloor, Scene scene)
         {
-            EventHandler<MouseEventArgs> upEvent = (sender, e) => {
-                DriverLayer.Control.Ins.ControlScene(scene);
-                string msg = scene.name + Language.StringByID(StringId.AlreadyOpened);
-                new PublicAssmebly().TipMsgAutoClose(msg, false);
-            };
-            btnName.MouseUpEventHandler = upEvent;
-            btnFromFloor.MouseUpEventHandler = upEvent;
-            this.MouseUpEventHandler = upEvent;
+            if (scene.sceneType == SceneType.LightScene)
+            {
+                EventHandler<MouseEventArgs> upEvent = (sender, e) =>
+                {
+                    if (scene.functions.Count == 0)
+                    {
+                        var waitPage = new Loading();
+                        new Thread(() =>
+                        {
+                            try
+                            {
+                                Application.RunOnMainThread(() =>
+                                {
+                                    MainPage.BaseView.AddChidren(waitPage);
+                                    waitPage.Start(Language.StringByID(StringId.PleaseWait));
+                                });
+                                var pm = new HttpServerRequest();
+                                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)
+                                    {
+                                        scene.name = tempScene.name;
+                                        scene.delay = tempScene.delay;
+                                        scene.roomIds = tempScene.roomIds;
+                                        scene.functions = tempScene.functions;
+                                    }
+                                    Application.RunOnMainThread(() =>
+                                    {
+                                        var sceneLishtList = new List<Function>();
+                                        foreach (var light in FunctionList.List.GetLightList())
+                                        {
+                                            var temp = scene.functions.Find((obj) => obj.sid == light.sid);
+                                            if (temp != null)
+                                            {
+                                                sceneLishtList.Add(light);
+                                            }
+                                        }
+                                        Action<Scene> action = (Scene) => { };
+                                        var lightSceneDialog = new LightSceneEditDialog(sceneLishtList, scene, action);
+                                        lightSceneDialog.ShowDialog();
+
+                                        waitPage.Hide();
+                                        waitPage.RemoveFromParent();
+                                    });
+                                }
+                                else
+                                {
+                                    IMessageCommon.Current.ShowErrorInfoAlter(pack.Code);
+                                }
+                            }
+                            catch { }
+                            finally
+                            {
+                                Application.RunOnMainThread(() =>
+                                {
+                                    waitPage.Hide();
+                                    waitPage.RemoveFromParent();
+                                });
+                            }
+                        }).Start();
+                    }
+                    else
+                    {
+                        var sceneLishtList = new List<Function>();
+                        foreach (var light in FunctionList.List.GetLightList())
+                        {
+                            var temp = scene.functions.Find((obj) => obj.sid == light.sid);
+                            if (temp != null)
+                            {
+                                sceneLishtList.Add(light);
+                            }
+                        }
+                        Action<Scene> action = (Scene) => { };
+                        var lightSceneDialog = new LightSceneEditDialog(sceneLishtList, scene, action);
+                        lightSceneDialog.ShowDialog();
+                    }
+                };
+                btnName.MouseUpEventHandler = upEvent;
+                btnFromFloor.MouseUpEventHandler = upEvent;
+                this.MouseUpEventHandler = upEvent;
+
+
+                EventHandler<MouseEventArgs> delEvent = (sender, e) => {
+                    Action action = () =>{
+                        var waitPage = new Loading();
+                        MainPage.BaseView.AddChidren(waitPage);
+                        waitPage.Start("");
+                        new System.Threading.Thread(() =>
+                        {
+                            try
+                            {
+                                var pm = new HttpServerRequest();
+                                var packCode = pm.DeleteScene(scene.userSceneId);
+                                if (packCode == StateCode.SUCCESS)
+                                {
+                                    FileUtlis.Files.DeleteFile(scene.savePath);
+                                    try
+                                    {
+                                        foreach (var sss in FunctionList.List.scenes)
+                                        {
+                                            if (sss.userSceneId == scene.userSceneId)
+                                            {
+                                                FunctionList.List.scenes.Remove(sss);
+                                                break;
+                                            }
+                                        }
+                                    }
+                                    catch { }
+                                    Application.RunOnMainThread(() =>
+                                    {
+                                        this.RemoveFromParent();
+                                    });
+                                }
+                                else
+                                {
+                                    Application.RunOnMainThread(() =>
+                                    {
+                                        IMessageCommon.Current.ShowErrorInfoAlter(packCode);
+                                    });
+                                }
+                            }
+                            catch { }
+                            finally
+                            {
+                                Application.RunOnMainThread(() => {
+                                    if(waitPage!= null)
+                                    {
+                                        waitPage.RemoveFromParent();
+                                        waitPage = null;
+                                    }
+                                });
+                            }
+                        })
+                        { IsBackground = true }.Start();
+
+
+                    };
+                    new PublicAssmebly().TipOptionMsg(StringId.Tip, StringId.DoYouWantDelCombinedDimming, action);
+                };
+                btnName.MouseLongEventHandler = delEvent;
+                btnFromFloor.MouseLongEventHandler = delEvent;
+                this.MouseLongEventHandler = delEvent;
+
+            }
+            else
+            {
+                EventHandler<MouseEventArgs> upEvent = (sender, e) =>
+                {
+                    DriverLayer.Control.Ins.ControlScene(scene);
+                    string msg = scene.name + Language.StringByID(StringId.AlreadyOpened);
+                    new PublicAssmebly().TipMsgAutoClose(msg, false);
+                };
+                btnName.MouseUpEventHandler = upEvent;
+                btnFromFloor.MouseUpEventHandler = upEvent;
+                this.MouseUpEventHandler = upEvent;
+            }
         }
 
 

--
Gitblit v1.8.0