From f1c3921b08bb22ac6f5db22d620e01d7e8e5c49f Mon Sep 17 00:00:00 2001
From: WJC <wjc@hdlchina.com.cn>
Date: 星期一, 30 十二月 2019 13:32:33 +0800
Subject: [PATCH] 2019-12-30-1

---
 ZigbeeApp/Shared/Phone/Device/Category/CategoryAddScene.cs |   91 ++++++++++++++++++++++++++++++++++-----------
 1 files changed, 68 insertions(+), 23 deletions(-)

diff --git a/ZigbeeApp/Shared/Phone/Device/Category/CategoryAddScene.cs b/ZigbeeApp/Shared/Phone/Device/Category/CategoryAddScene.cs
index 2cbca49..9763cd1 100755
--- a/ZigbeeApp/Shared/Phone/Device/Category/CategoryAddScene.cs
+++ b/ZigbeeApp/Shared/Phone/Device/Category/CategoryAddScene.cs
@@ -57,6 +57,11 @@
         private CommonForm.CompleteButton confirmBtn;
 
         /// <summary>
+        /// backGround
+        /// </summary>
+        private Button backGround;
+
+        /// <summary>
         /// 鏄惁淇敼
         /// </summary>
         public bool isModify;
@@ -127,14 +132,7 @@
                     }
                     else if (targetDevice.Type == 2)
                     {
-                        if(targetDevice.DelayTime<60)
-                        {
-                            devNameText = $"{targetDevice.DelayTime} {Language.StringByID(R.MyInternationalizationString.Second)}";
-                        }
-                        else
-                        {
-                            devNameText = $"{targetDevice.DelayTime / 60} {Language.StringByID(R.MyInternationalizationString.Minute)} {targetDevice.DelayTime % 60} {Language.StringByID(R.MyInternationalizationString.Second)}";
-                        }
+                        devNameText = CommonFormResouce.GetTimeString(targetDevice.DelayTime);
                         devNameText += Language.StringByID(R.MyInternationalizationString.Later);
                         var targetRow = new SceneTargetTimeRow(23);
                         targetRowLayout.AddChidren(targetRow);
@@ -153,7 +151,6 @@
                         targetRow.SetNameText(devNameText);
                         targetRow.SetZoneText(targetDevice.SceneUI.GetZone());
                     }
-                   
                     
                     var editBtn = new Button()
                     {
@@ -327,16 +324,17 @@
             };
             bodyFrameLayout.AddChidren(imgFL);
 
-            var backGround = new Button()
+            backGround = new Button()
             {
-                Width = Application.GetRealWidth(930),
-                Height = Application.GetRealHeight(464),
+                Width = Application.GetMinRealAverage(930),
+                Height = Application.GetMinRealAverage(464),
                 Gravity = Gravity.Center,
-                Radius = (uint)Application.GetRealHeight(CommonFormResouce.BigFormRadius),
+                Radius = (uint)Application.GetMinRealAverage(CommonFormResouce.BigFormRadius),
                 //UnSelectedImagePath = ImagePath
-                UnSelectedImagePath = "SceneIcon/3.png"
+                UnSelectedImagePath = "SceneIcon/3.jpg"
             };
             imgFL.AddChidren(backGround);
+            backGround.SetViewShadow(true);
 
             var infoFL = new FrameLayout
             {
@@ -541,29 +539,56 @@
                     localPic.action = (imgPath) =>
                     {
                         IconPathType = 0;
+                        backGround.ImageBytes = null;
                         backGround.UnSelectedImagePath = imgPath;
                     };
                 };
                 selectPhotographBtn.MouseUpEventHandler += (send, ee) =>
                 {
                     selectFL.RemoveFromParent();
-                    IconPathType = 1;
+                    var tradeTime = DateTime.Now.ToString("yyyyMMddHHmmss", DateTimeFormatInfo.InvariantInfo);
+                    var fileName = $"Scene_{tradeTime}";
                     //閫氳繃鐩告満鎷嶇収瑁佸壀
                     CropImage.TakePicture((imagePath) =>
                     {
-                        Console.WriteLine("SelectPicture 瑁佸壀鍥剧墖杩斿洖璺緞: " + imagePath);
-                    }, "HDLPIC");
+                        if (isModify)
+                        {
+                            if (IconPathType != 0)
+                            {
+                                Global.DeleteFilebyHomeId(backGround.UnSelectedImagePath);
+                            }
+                        }
+
+                        IconPathType = 1;
+                        backGround.ImageBytes = Shared.IO.FileUtils.ReadFile(imagePath);
+                        backGround.UnSelectedImagePath = imagePath;
+                        System.IO.File.Delete(imagePath);
+                        
+                    }, fileName, 2, 1);
                 };
                
                 selectAblumsBtn.MouseUpEventHandler += (send, ee) =>
                 {
                     selectFL.RemoveFromParent();
-                    IconPathType = 2;
+                    var tradeTime = DateTime.Now.ToString("yyyyMMddHHmmss", DateTimeFormatInfo.InvariantInfo);
+                    var fileName = $"Scene_{tradeTime}";
                     //浠庣浉鍐岄�夋嫨鍥剧墖瑁佸壀
                     CropImage.SelectPicture((imagePath) =>
                     {
-                        Console.WriteLine("SelectPicture 瑁佸壀鍥剧墖杩斿洖璺緞: " + imagePath);
-                    }, "HDLPIC");
+                        if (isModify)
+                        {
+                            if (IconPathType != 0)
+                            {
+                                Global.DeleteFilebyHomeId(backGround.UnSelectedImagePath);
+                            }
+                        }
+
+                        IconPathType = 2;
+                        backGround.ImageBytes = Shared.IO.FileUtils.ReadFile(imagePath);
+                        backGround.UnSelectedImagePath = imagePath;
+                        System.IO.File.Delete(imagePath);
+
+                    }, fileName, 2,1);
                 };
 
                 cancelBtn.MouseUpEventHandler += (send, ee) =>
@@ -806,6 +831,8 @@
                     {
                         try
                         {
+                            var tradeTime = DateTime.Now.ToString("yyyyMMddHHmmss", DateTimeFormatInfo.InvariantInfo);
+                            var fileName = $"Scene_{tradeTime}";
                             //鏀瑰悕
                             if (modifySceneUI.Name != nameRow.NameText.Text.Trim())
                             {
@@ -837,9 +864,14 @@
                             //鍥剧墖
                             if(IconPathType==1 || IconPathType ==2)
                             {
-
+                                Shared.IO.FileUtils.WriteFileByBytes(System.IO.Path.Combine(Config.Instance.FullPath, fileName), backGround.ImageBytes);
+                                modifySceneUI.IconPath = System.IO.Path.Combine(Config.Instance.FullPath, fileName);
                             }
-                            modifySceneUI.IconPath = backGround.UnSelectedImagePath;
+                            else
+                            {
+                                modifySceneUI.IconPath = backGround.UnSelectedImagePath;
+                            }
+                            modifySceneUI.IconPathType = IconPathType;
 
                             CommonPage.Loading.Start();
                             var memberDataList = new List<ZigBee.Device.Scene.AddSceneMemberData>();
@@ -985,6 +1017,19 @@
                     {
                         try
                         {
+                            var tradeTime = DateTime.Now.ToString("yyyyMMddHHmmss", DateTimeFormatInfo.InvariantInfo);
+                            var fileName = $"SceneIcon_{tradeTime}.png";
+                            string imgPath;
+                            //鍥剧墖
+                            if (IconPathType == 1 || IconPathType == 2)
+                            {
+                                Shared.IO.FileUtils.WriteFileByBytes(System.IO.Path.Combine(Config.Instance.FullPath, fileName), backGround.ImageBytes);
+                                imgPath = System.IO.Path.Combine(Config.Instance.FullPath, fileName);
+                            }
+                            else
+                            {
+                                imgPath = backGround.UnSelectedImagePath;
+                            }
                             if (Common.Room.CurrentRoom.GetSameFloorScenes(curRoom.FloorId).Find(s => s.Name == nameRow.NameText.Text.Trim()) != null)
                             {
                                 Common.CommonPage.Instance.ShowErrorInfoAlert(R.MyInternationalizationString.TheSceneHadExist);
@@ -1039,7 +1084,7 @@
                                 }
                             }
 
-                            var result = await curRoom.AddScene(nameRow.NameText.Text, backGround.UnSelectedImagePath, memberDataList);
+                            var result = await curRoom.AddScene(nameRow.NameText.Text, imgPath, memberDataList);
                             if (result == 1)
                             {
                                 RemoveFromParent();

--
Gitblit v1.8.0