From 9f326f4000847e6167d8166fa2f6a66f53cb3734 Mon Sep 17 00:00:00 2001
From: 黄学彪 <hxb@hdlchina.com.cn>
Date: 星期四, 17 十二月 2020 09:07:13 +0800
Subject: [PATCH] 新云端Ver1.3

---
 ZigbeeApp/Shared/Phone/Category/AddOrEditorSceneForm.cs |  161 ++++++++++++++++++++++++++++++++++++++---------------
 1 files changed, 115 insertions(+), 46 deletions(-)

diff --git a/ZigbeeApp/Shared/Phone/Category/AddOrEditorSceneForm.cs b/ZigbeeApp/Shared/Phone/Category/AddOrEditorSceneForm.cs
index 220a7d5..cc76472 100755
--- a/ZigbeeApp/Shared/Phone/Category/AddOrEditorSceneForm.cs
+++ b/ZigbeeApp/Shared/Phone/Category/AddOrEditorSceneForm.cs
@@ -120,18 +120,31 @@
             //鍒濆鍖栨坊鍔犵洰鏍�
             this.InitAddTargetControl();
 
-            //鍒嗕韩鐨勫満鏅笉鑳戒繚瀛�
-            if (this.editorScene == null || this.editorScene.IsSharedScene == false)
+            //瀹屾垚
+            var btnSave = new BottomClickButton();
+            btnSave.TextID = R.MyInternationalizationString.uFinish;
+            bodyFrameLayout.AddChidren(btnSave);
+            btnSave.ButtonClickEvent += (sender, e) =>
             {
-                //瀹屾垚
-                var btnSave = new BottomClickButton();
-                btnSave.TextID = R.MyInternationalizationString.uFinish;
-                bodyFrameLayout.AddChidren(btnSave);
-                btnSave.ButtonClickEvent += (sender, e) =>
-                {
-                    //淇濆瓨鍦烘櫙鏁版嵁
-                    this.SaveSceneData();
-                };
+                //淇濆瓨鍦烘櫙鏁版嵁
+                this.SaveSceneData();
+            };
+
+            //鍒嗕韩鐨勫満鏅笉鑳戒繚瀛�
+            if (this.editorScene != null && this.editorScene.IsSharedScene == true)
+            {
+                btnSave.CanClick = false;
+            }
+            else if (Config.Instance.Home.IsShowTemplate == true)
+            {
+                //妯℃澘鍦烘櫙涓嶈兘淇濆瓨
+                btnSave.CanClick = false;
+            }
+            //濡傛灉鏄湁妯℃澘,鏈夎澶囩殑鏃跺��,鍦ㄦ病鏈夊彂閫佹垚鍔熶箣鍓�
+            else if (Common.Config.Instance.Home.TemplateMode == 2
+               && Common.Config.Instance.Home.SendTemplateSuccess == false)
+            {
+                btnSave.CanClick = false;
             }
         }
 
@@ -159,8 +172,8 @@
             //鍦烘櫙鍥剧墖
             this.btnScenePic = new ImageView();
             btnScenePic.Y = Application.GetRealHeight(46);
-            btnScenePic.Width = Application.GetMinRealAverage(887);
-            btnScenePic.Height = Application.GetMinRealAverage(444);
+            btnScenePic.Width = this.GetPictrueRealSize(887);
+            btnScenePic.Height = this.GetPictrueRealSize(444);
             btnScenePic.Radius = (uint)Application.GetRealHeight(17);
             btnScenePic.Gravity = Gravity.CenterHorizontal;
             if (this.editorScene == null)
@@ -182,12 +195,18 @@
             btnZhezhao.Height = btnScenePic.Height;
             btnZhezhao.Y = btnScenePic.Y;
             btnZhezhao.Gravity = Gravity.CenterHorizontal;
-            btnZhezhao.Radius = btnScenePic.Radius;
+            btnZhezhao.Radius = (uint)Application.GetRealHeight(17);
+            btnZhezhao.BackgroundColor = UserCenterColor.Current.PictrueZhezhaoColor;
             framePicBack.AddChidren(btnZhezhao);
 
             //鍒嗕韩鐨勫満鏅笉鑳界紪杈�
             if (this.editorScene == null || this.editorScene.IsSharedScene == false)
             {
+                if (Config.Instance.Home.IsShowTemplate == true)
+                {
+                    //妯℃澘鍦烘櫙涓嶅厑璁哥紪杈�
+                    return;
+                }
                 btnZhezhao.MouseUpEventHandler += (sender, e) =>
                 {
                     //鎴块棿鍥剧墖閫夋嫨
@@ -214,7 +233,7 @@
 
             //淇℃伅缂栬緫
             var btnTitle = new NormalViewControl(300, 60, true);
-            btnTitle.X = ControlCommonResourse.XXLeft;
+            btnTitle.X = HdlControlResourse.XXLeft;
             btnTitle.Y = Application.GetRealHeight(46);
             btnTitle.TextSize = 15;
             btnTitle.TextID = R.MyInternationalizationString.uInfoEditor;
@@ -224,6 +243,7 @@
             //鍦烘櫙鍚嶇О
             var rowScene = new FrameCaptionInputControl(Language.StringByID(R.MyInternationalizationString.SceneName), this.cloneScene.Name);
             rowScene.txtInput.PlaceholderText = Language.StringByID(R.MyInternationalizationString.PleaseInputSceneName);
+            rowScene.txtInput.MaxByte = 32;//闄愬埗鍙兘杈撳叆32涓瓧鑺�
             rowScene.Y = btnTitle.Bottom + Application.GetRealHeight(23);
             frameBack.AddChidren(rowScene);
             rowScene.InitControl();
@@ -247,6 +267,11 @@
                     this.nowRoomId = selectId;
                 };
             }
+            if (Config.Instance.Home.IsShowTemplate == true)
+            {
+                //妯℃澘鍦烘櫙涓嶅厑璁哥紪杈�
+                rowBelong.CanClick = false;
+            }
         }
 
         #endregion
@@ -258,7 +283,7 @@
         /// </summary>
         private void InitAddTargetControl()
         {
-            if (this.frameTargetTableControl == null)
+            if (this.frameTargetTableControl == null || this.frameTargetTableControl.Parent == null)
             {
                 //娣诲姞鐩爣鐨勭殑瀹瑰櫒鎺т欢
                 this.frameTargetTableControl = new FrameListControl();
@@ -289,13 +314,27 @@
                 //鏄剧ず娣诲姞鐩爣鑿滃崟
                 this.ShowAddTargetMenu();
             };
+            if (Config.Instance.Home.IsShowTemplate == true)
+            {
+                //妯℃澘鍦烘櫙涓嶅厑璁哥紪杈�
+                rowAddTarget.CanClick = false;
+            }
+            //濡傛灉鏄湁妯℃澘,鏈夎澶囩殑鏃跺��,鍦ㄦ病鏈夊彂閫佹垚鍔熶箣鍓�
+            if (Common.Config.Instance.Home.TemplateMode == 2
+               && Common.Config.Instance.Home.SendTemplateSuccess == false)
+            {
+                rowAddTarget.CanClick = false;
+            }
 
-            HdlThreadLogic.Current.RunThread(async () =>
+            HdlThreadLogic.Current.RunThread(() =>
             {
                 //浠庣綉鍏宠幏鍙栧満鏅殑鎵ц鐩爣
-                var result = await this.GetSceneTargetList();
-                //娣诲姞銆愭墽琛岀洰鏍囪銆�
-                this.AddTargetRow();
+                var result = this.GetSceneTargetList();
+                if (result == true)
+                {
+                    //娣诲姞銆愭墽琛岀洰鏍囪銆�
+                    this.AddTargetRow();
+                }
             });
         }
 
@@ -314,7 +353,7 @@
                 if (listAdjustTarget[i].Type == 0)
                 {
                     //璁惧
-                    var device = Common.LocalDevice.Current.GetDevice(listAdjustTarget[i].DeviceAddr, listAdjustTarget[i].Epoint);
+                    var device = HdlDeviceCommonLogic.Current.GetDevice(listAdjustTarget[i].DeviceAddr, listAdjustTarget[i].Epoint);
                     if (device == null)
                     {
                         //涓嶆樉绀鸿繖涓笉瀛樺湪鏈湴鐨勮澶�
@@ -375,12 +414,12 @@
         private void AddDeviceTargetRow(Scene.DeviceListData data, int index, bool addLine)
         {
             //璁惧
-            var device = Common.LocalDevice.Current.GetDevice(data.DeviceAddr, data.Epoint);
+            var device = HdlDeviceCommonLogic.Current.GetDevice(data.DeviceAddr, data.Epoint);
             var rowDevice = new DeviceRoomControl(device, frameTargetTableControl.rowSpace / 2);
             rowDevice.MainKeys = index.ToString();
             this.frameTargetTableControl.AddChidren(rowDevice);
             //鎺т欢鍚戝彸鍋忕Щ
-            rowDevice.frameTable.LeftOffset = Application.GetRealWidth(104) - ControlCommonResourse.XXLeft;
+            rowDevice.frameTable.LeftOffset = Application.GetRealWidth(104) - HdlControlResourse.XXLeft;
             rowDevice.InitControl();
             rowDevice.frameTable.UseClickStatu = false;
 
@@ -395,12 +434,15 @@
             //鍒嗕韩鐨勫満鏅笉鑳界紪杈�
             if (this.editorScene == null || this.editorScene.IsSharedScene == false)
             {
+                if (Config.Instance.Home.IsShowTemplate == true)
+                {
+                    //妯℃澘鍦烘櫙涓嶅厑璁哥紪杈�
+                    return;
+                }
                 //缂栬緫
                 var btnEditor = rowDevice.AddEditorControl();
                 btnEditor.ButtonClickEvent += (sender, e) =>
                 {
-                    //闅愯棌鍙虫粦鑿滃崟
-                    rowDevice.HideMenu();
                     if (device.Type == DeviceType.DimmableLight//璋冨厜鍣�
                       || device.Type == DeviceType.ColorDimmableLight)//褰╃伅
                     {
@@ -508,7 +550,7 @@
             rowScene.MainKeys = index.ToString();
             frameTargetTableControl.AddChidren(rowScene);
             //鎺т欢鍚戝彸鍋忕Щ
-            rowScene.frameTable.LeftOffset = Application.GetRealWidth(104) - ControlCommonResourse.XXLeft;
+            rowScene.frameTable.LeftOffset = Application.GetRealWidth(104) - HdlControlResourse.XXLeft;
             rowScene.InitControl();
             if (addLine == true)
             {
@@ -520,6 +562,11 @@
             //鍒嗕韩鐨勫満鏅笉鑳界紪杈�
             if (this.editorScene == null || this.editorScene.IsSharedScene == false)
             {
+                if (Config.Instance.Home.IsShowTemplate == true)
+                {
+                    //妯℃澘鍦烘櫙涓嶅厑璁哥紪杈�
+                    return;
+                }
                 //鍒犻櫎
                 var btnDelete = rowScene.AddDeleteControl();
                 btnDelete.ButtonClickEvent += (sender, e) =>
@@ -563,7 +610,7 @@
             rowDelay.MainKeys = index.ToString();
             frameTargetTableControl.AddChidren(rowDelay);
             //鎺т欢鍚戝彸鍋忕Щ
-            rowDelay.frameTable.LeftOffset = Application.GetRealWidth(104) - ControlCommonResourse.XXLeft;
+            rowDelay.frameTable.LeftOffset = Application.GetRealWidth(104) - HdlControlResourse.XXLeft;
             rowDelay.frameTable.UseClickStatu = false;
             //鍥炬爣
             var btnIcon = rowDelay.frameTable.AddLeftIcon();
@@ -586,12 +633,15 @@
             //鍒嗕韩鐨勫満鏅笉鑳界紪杈�
             if (this.editorScene == null || this.editorScene.IsSharedScene == false)
             {
+                if (Common.Config.Instance.Home.IsShowTemplate == true)
+                {
+                    //妯℃澘鍦烘櫙涓嶅厑璁哥紪杈�
+                    return;
+                }
                 //缂栬緫
                 var btnEditor = rowDelay.AddEditorControl();
                 btnEditor.ButtonClickEvent += (sender, e) =>
                 {
-                    //闅愯棌鍙虫粦鑿滃崟
-                    rowDelay.HideMenu();
                     //寤舵椂鏃堕棿閫夋嫨
                     var form = new AdjustTargetAddDelayTimeForm();
                     form.AddForm(data.DelayTime);
@@ -633,16 +683,17 @@
         /// 浠庣綉鍏宠幏鍙栧満鏅殑鎵ц鐩爣
         /// </summary>
         /// <returns></returns>
-        private async System.Threading.Tasks.Task<bool> GetSceneTargetList()
+        private bool GetSceneTargetList()
         {
             if (this.editorScene == null || this.listAdjustTarget != null)
             {
                 return true;
             }
+
             //鎵撳紑杩涘害鏉�
             this.ShowProgressBar();
             //鑾峰彇鎵ц鐩爣鍒楄〃
-            var listData = await HdlSceneLogic.Current.GetAdjustTargetList(this.editorScene);
+            var listData = HdlSceneLogic.Current.GetAdjustTargetList(this.editorScene);
             if (listData == null)
             {
                 this.CloseProgressBar(ShowReLoadMode.YES);
@@ -675,7 +726,7 @@
             //閭d釜鐗规畩鐨勬帶浠�
             this.frameBottomTemp = new FrameLayout();
             frameBottomTemp.Height = bodyFrameLayout.Height - btnTemp.Yaxis + Application.GetRealHeight(23);
-            this.listBodyControl.AddChidrenFrame(frameBottomTemp);
+            this.listBodyControl.AddChidren(frameBottomTemp);
         }
 
         #endregion
@@ -700,7 +751,7 @@
                     this.isAdjustTargetChanged = true;
                     foreach (var mainKey in dicData.Keys)
                     {
-                        var device = LocalDevice.Current.GetDevice(mainKey);
+                        var device = HdlDeviceCommonLogic.Current.GetDevice(mainKey);
                         var data = new Scene.DeviceListData();
                         data.Type = 0;
                         data.DeviceAddr = device.DeviceAddr;
@@ -788,10 +839,10 @@
         /// <summary>
         /// 淇濆瓨鏂板缓鐨勫満鏅�
         /// </summary>
-        private async void SaveSceneDataByNewMode()
+        private void SaveSceneDataByNewMode()
         {
             //娣诲姞鍦烘櫙
-            this.editorScene = await HdlSceneLogic.Current.AddNewSceneToGateway(this.cloneScene.Name, this.listAdjustTarget);
+            this.editorScene = HdlSceneLogic.Current.AddNewSceneToGateway(this.cloneScene.Name, this.listAdjustTarget);
             //鍏抽棴杩涘害鏉�
             this.CloseProgressBar();
 
@@ -812,7 +863,7 @@
                 var fileName = $"SceneIcon_{tradeTime}.png";
                 //鐢熸垚鏂囦欢鍥剧墖
                 IO.FileUtils.WriteFileByBytes(System.IO.Path.Combine(Config.Instance.FullPath, fileName), this.btnScenePic.ImageBytes);
-                HdlAutoBackupLogic.AddOrEditorFile(fileName);
+                HdlBackupLogic.Current.AddOrEditorAutoBackFileStatu(fileName);
                 this.cloneScene.IconPath = fileName;
             }
             //杞Щ灞炴��
@@ -820,6 +871,9 @@
             this.editorScene.IconPathType = this.cloneScene.IconPathType;
             this.editorScene.IconPath = this.cloneScene.IconPath;
             this.editorScene.Save();
+
+            //鏂板缓鍦烘櫙,涓婚〉闇�瑕侀噸鏂板埛鏂�
+            UserView.UserPage.Instance.RefreshAllForm = true;
 
             HdlThreadLogic.Current.RunMain(() =>
             {
@@ -840,6 +894,8 @@
                 var result = await HdlSceneLogic.Current.EditorSceneNameFromGateway(this.editorScene, this.cloneScene.Name);
                 if (result == false)
                 {
+                    //鍏抽棴杩涘害鏉�
+                    this.CloseProgressBar();
                     return;
                 }
             }
@@ -847,10 +903,10 @@
             {
                 //淇敼鍦烘櫙
                 var result = await HdlSceneLogic.Current.EditorSceneFromGateway(this.editorScene, this.listAdjustTarget);
-                //鍏抽棴杩涘害鏉�
-                this.CloseProgressBar();
                 if (result == false)
                 {
+                    //鍏抽棴杩涘害鏉�
+                    this.CloseProgressBar();
                     return;
                 }
             }
@@ -860,6 +916,15 @@
                 //鍙樻洿鎴块棿
                 HdlSceneLogic.Current.ChangedSceneRoom(this.editorScene, this.nowRoomId);
             }
+            else
+            {
+                //绉婚櫎鍑烘埧闂�
+                var room = HdlRoomLogic.Current.GetRoomBySceneId(this.editorScene.Id);
+                if (room != null)
+                {
+                    HdlSceneLogic.Current.DeleteSceneFromRoom(room, this.editorScene);
+                }
+            }
 
             //鍥剧墖鏀瑰彉浜�
             if (isScenePictrueChanged == true)
@@ -867,8 +932,8 @@
                 if (this.editorScene.IconPathType != 0)
                 {
                     //鍒犻櫎鑷畾涔夊浘鐗�
-                    Shared.IO.FileUtils.DeleteFile(System.IO.Path.Combine(Config.Instance.FullPath, this.editorScene.IconPath));
-                    HdlAutoBackupLogic.DeleteFile(this.editorScene.IconPath);
+                    HdlFileLogic.Current.DeleteFile(System.IO.Path.Combine(Config.Instance.FullPath, this.editorScene.IconPath));
+                    HdlBackupLogic.Current.DeleteAutoBackFileStatu(this.editorScene.IconPath);
                 }
                 if (this.cloneScene.IconPathType != 0)
                 {
@@ -877,7 +942,7 @@
                     var fileName = $"SceneIcon_{tradeTime}.png";
                     //鐢熸垚鏂囦欢鍥剧墖
                     IO.FileUtils.WriteFileByBytes(System.IO.Path.Combine(Config.Instance.FullPath, fileName), this.btnScenePic.ImageBytes);
-                    HdlAutoBackupLogic.AddOrEditorFile(fileName);
+                    HdlBackupLogic.Current.AddOrEditorAutoBackFileStatu(fileName);
                     this.cloneScene.IconPath = fileName;
                 }
             }
@@ -887,6 +952,12 @@
             this.editorScene.IconPathType = this.cloneScene.IconPathType;
             this.editorScene.IconPath = this.cloneScene.IconPath;
             this.editorScene.Save();
+
+            //缂栬緫鍦烘櫙,涓婚〉闇�瑕侀噸鏂板埛鏂�
+            UserView.UserPage.Instance.RefreshAllForm = true;
+
+            //鍏抽棴杩涘害鏉�
+            this.CloseProgressBar();
 
             HdlThreadLogic.Current.RunMain(() =>
             {
@@ -942,11 +1013,9 @@
             //榛樿鍥惧簱
             menuContr.AddMenu(Language.StringByID(R.MyInternationalizationString.LocalPicture), () =>
             {
-                var localPic = new Device.Room.AddRoomSelectPicByLocal();
-                UserView.HomePage.Instance.AddChidren(localPic);
-                UserView.HomePage.Instance.PageIndex += 1;
-                localPic.Show();
-                localPic.action = (imgPath) =>
+                var form = new SelectLocalSceneImageForm();
+                form.AddForm();
+                form.FinishSelectEvent = (imgPath) =>
                 {
                     if (string.IsNullOrEmpty(imgPath) == true)
                     {

--
Gitblit v1.8.0