From cc0d80c7d86c6d0167269b3408c4b30c24ce84e9 Mon Sep 17 00:00:00 2001
From: 黄学彪 <hxb@hdlchina.com.cn>
Date: 星期一, 23 三月 2020 16:55:37 +0800
Subject: [PATCH] ???????

---
 ZigbeeApp/Shared/Phone/Device/Category/CategoryAddScene.cs |  165 +++++++++++++++++++++++-------------------------------
 1 files changed, 71 insertions(+), 94 deletions(-)

diff --git a/ZigbeeApp/Shared/Phone/Device/Category/CategoryAddScene.cs b/ZigbeeApp/Shared/Phone/Device/Category/CategoryAddScene.cs
index 518bdb0..ba9b610 100755
--- a/ZigbeeApp/Shared/Phone/Device/Category/CategoryAddScene.cs
+++ b/ZigbeeApp/Shared/Phone/Device/Category/CategoryAddScene.cs
@@ -5,6 +5,7 @@
 using Shared.Phone.Device.CommonForm;
 using Shared.Phone.Device.Room;
 using Shared.Phone.UserCenter;
+using ZigBee.Device;
 using static ZigBee.Device.Scene;
 
 namespace Shared.Phone.Device.Category
@@ -157,15 +158,15 @@
                     string devNameText = string.Empty;
                     if (targetDevice.Type == 0)
                     {
-                        if (targetDevice.DeviceUI == null || targetDevice.DeviceUI.CommonDevice == null) continue;
+                        if (targetDevice.DeviceUI == null ) continue;
                         devImgPath = targetDevice.DeviceUI.IconPath;
-                        devNameText = targetDevice.DeviceUI.CommonDevice.DeviceEpointName;
+                        devNameText = Common.LocalDevice.Current.GetDeviceEpointName(targetDevice.DeviceUI);
 
                         var targetRow = new SceneTargetFunctionRow(13);
                         targetRow.Init();
                         targetRow.SetIcon(devImgPath);
                         targetRow.SetNameText(devNameText);
-                        targetRow.SetZoneText(targetDevice.DeviceUI.GetZone());
+                        targetRow.SetZoneText(HdlRoomLogic.Current.GetRoomNameByDevice(targetDevice.DeviceUI, ","));
                         targetRow.SetStatuText(targetDevice.GetDeviceStatu());
                         targetRowLayout.AddChidren(targetRow);
                         if (i == sceneTargetDevicesList.Count - 1)
@@ -195,7 +196,7 @@
                         targetRow.Init();
                         targetRow.SetIcon(devImgPath);
                         targetRow.SetNameText(devNameText);
-                        targetRow.SetZoneText(targetDevice.SceneUI.GetZone());
+                        targetRow.SetZoneText(HdlSceneLogic.Current.GetZoneById(targetDevice.SceneUI.Id));
                         targetRowLayout.AddChidren(targetRow);
                         if (i == sceneTargetDevicesList.Count - 1)
                         {
@@ -221,7 +222,7 @@
                     {
                         if (targetDevice.Type == 0)
                         {
-                            if (targetDevice.DeviceUI == null || targetDevice.DeviceUI.CommonDevice == null)
+                            if (targetDevice.DeviceUI == null)
                             {
                                 return;
                             }
@@ -354,16 +355,26 @@
             };
             bodyFrameLayout.AddChidren(imgFL);
 
+            var backGround1 = new ImageView()
+            {
+                Y = Application.GetRealHeight(46),
+                Width = Application.GetMinRealAverage(916),
+                Height = Application.GetMinRealAverage(487),
+                Gravity = Gravity.CenterHorizontal,
+                ImagePath = "Room/Room_Rectangle.png"
+            };
+            imgFL.AddChidren(backGround1);
+
             backGround = new ImageView()
             {
-                Width = Application.GetMinRealAverage(930),
-                Height = Application.GetMinRealAverage(464),
-                Gravity = Gravity.Center,
+                Y = Application.GetRealHeight(46),
+                Width = Application.GetMinRealAverage(887),
+                Height = Application.GetMinRealAverage(444),
+                Gravity = Gravity.CenterHorizontal,
                 Radius = (uint)Application.GetMinRealAverage(CommonFormResouce.BigFormRadius),
                 ImagePath = "SceneIcon/3.jpg"
             };
             imgFL.AddChidren(backGround);
-            backGround.SetViewShadow(true);
 
             var infoFL = new FrameLayout
             {
@@ -461,7 +472,7 @@
 
 
             confirmBtn = new CommonForm.CompleteButton(1656, 907, 127);
-            confirmBtn.TextID = R.MyInternationalizationString.Next;
+            confirmBtn.TextID = R.MyInternationalizationString.uFinish;
             AddChidren(confirmBtn);
 
             if (isModify)
@@ -487,7 +498,7 @@
                 }
                 else
                 {
-                    zoneRow.SetTitle($"{Config.Instance.Home.GetFloorNameById(modifyRoom.FloorId)},{modifyRoom.Name}");
+                    zoneRow.SetTitle($"{Config.Instance.Home.GetFloorNameById(modifyRoom.FloorId)}锛寋modifyRoom.Name}");
                 }
                 curRoom = modifyRoom;
                 sceneTargetDevicesList.AddRange(modifySceneTargetDevicesList);
@@ -604,6 +615,10 @@
                     //閫氳繃鐩告満鎷嶇収瑁佸壀
                     CropImage.TakePicture((imagePath) =>
                     {
+                        if (string.IsNullOrEmpty(imagePath))
+                        {
+                            return;
+                        }
                         if (isModify)
                         {
                             if (IconPathType != 0)
@@ -629,6 +644,10 @@
                     //浠庣浉鍐岄�夋嫨鍥剧墖瑁佸壀
                     CropImage.SelectPicture((imagePath) =>
                     {
+                        if (string.IsNullOrEmpty(imagePath))
+                        {
+                            return;
+                        }
                         if (isModify)
                         {
                             if (IconPathType != 0)
@@ -660,53 +679,13 @@
             //鍖哄煙
             EventHandler<MouseEventArgs> zoneHander = (sender, e) =>
             {
-                List<string> floorIds = new List<string> { };
-                List<string> floorNames = new List<string> { };
-                List<List<string>> roomNames = new List<List<string>> { };
-                List<List<Common.Room>> rooms = new List<List<Common.Room>> { };
-                List<Common.Room> rs = new List<Common.Room> { };
-                List<string> rNames = new List<string> { };
-                if (Config.Instance.Home.FloorDics.Count > 0)
+                var zone = new SelectZone();
+                zone.Init();
+                zone.ZoneAction += (selectRoom) =>
                 {
-                    foreach (var floor in Config.Instance.Home.FloorDics)
-                    {
-                        if (Common.Room.CurrentRoom.GetRoomsByFloorId(floor.Key).Count > 0)
-                        {
-                            floorIds.Add(floor.Key);
-                            floorNames.Add(floor.Value);
-
-                            roomNames.Add(Common.Room.CurrentRoom.GetRoomNamesByFloorId(floor.Key));
-                            rooms.Add(Common.Room.CurrentRoom.GetRoomsByFloorId(floor.Key));
-                        }
-                    }
-                    PickerView.ShowSecondary(floorNames, roomNames, (index1, index2) =>
-                    {
-                        curRoom = rooms[index1][index2];
-                        zoneRow.SetTitle($"{Config.Instance.Home.GetFloorNameById(floorIds[index1])} , {rooms[index1][index2].Name}");
-                    }, 0, 0, Language.StringByID(R.MyInternationalizationString.BelongZone),
-                   Language.StringByID(R.MyInternationalizationString.Confrim),
-                   Language.StringByID(R.MyInternationalizationString.Cancel));
-                }
-                else
-                {
-                    for (int i = 0; i < Common.Room.Lists.Count; i++)
-                    {
-                        var r = Common.Room.Lists[i];
-                        if (r.IsLove)
-                        {
-                            continue;
-                        }
-                        rs.Add(r);
-                        rNames.Add(r.Name);
-                    }
-                    PickerView.Show(rNames, (index1) =>
-                    {
-                        curRoom = rs[index1];
-                        zoneRow.SetTitle(rs[index1].Name);
-                    }, 0, Language.StringByID(R.MyInternationalizationString.BelongZone),
-                   Language.StringByID(R.MyInternationalizationString.Confrim),
-                   Language.StringByID(R.MyInternationalizationString.Cancel));
-                }
+                    curRoom = selectRoom;
+                    zoneRow.SetTitle(HdlRoomLogic.Current.GetZoneName(selectRoom));
+                };
             };
             zoneRow.ClickBtn.MouseUpEventHandler += zoneHander;
 
@@ -895,7 +874,7 @@
                             var fileName = $"SceneIcon_{tradeTime}.png";
                             if (modifySceneUI.Name != nameRow.NameText.Text.Trim())
                             {
-                                if (Common.Room.CurrentRoom.GetSameFloorScenes(curRoom.FloorId).Find(s => s.Name == nameRow.NameText.Text.Trim()) != null)
+                                if (HdlSceneLogic.Current.GetSameFloorScenes(curRoom.FloorId).Find(s => s.Name == nameRow.NameText.Text.Trim()) != null)
                                 {
                                     CommonFormResouce.ShowTip(Language.StringByID(R.MyInternationalizationString.TheSceneHadExist));
                                     return;
@@ -919,13 +898,12 @@
                             if (OldIconPathType != 0)
                             {
                                 Shared.IO.FileUtils.DeleteFile(System.IO.Path.Combine(Config.Instance.FullPath, OldBackgroundImagePath));
-                                HdlAutoBackupLogic.DeleteFile(System.IO.Path.Combine(Config.Instance.FullPath, OldBackgroundImagePath));
-
+                                HdlAutoBackupLogic.DeleteFile(OldBackgroundImagePath);
                             }
                             if (IconPathType == 1 || IconPathType == 2)
                             {
                                 Shared.IO.FileUtils.WriteFileByBytes(System.IO.Path.Combine(Config.Instance.FullPath, fileName), backGround.ImageBytes);
-                                HdlAutoBackupLogic.AddOrEditorFile(System.IO.Path.Combine(Config.Instance.FullPath, fileName));
+                                HdlAutoBackupLogic.AddOrEditorFile(fileName);
                                 modifySceneUI.IconPath = fileName;
                             }
                             else
@@ -942,7 +920,7 @@
 
                                 if (sceneTarget.Type == 0)
                                 {
-                                    if (sceneTarget.DeviceUI == null || sceneTarget.DeviceUI.CommonDevice == null)
+                                    if (sceneTarget.DeviceUI == null)
                                     {
                                         continue;
                                     }
@@ -950,8 +928,8 @@
                                     {
                                         Type = 0,
                                         ScenesId = 0,
-                                        DeviceAddr = sceneTarget.DeviceUI.CommonDevice.DeviceAddr,
-                                        Epoint = sceneTarget.DeviceUI.CommonDevice.DeviceEpoint,
+                                        DeviceAddr = sceneTarget.DeviceUI.DeviceAddr,
+                                        Epoint = sceneTarget.DeviceUI.DeviceEpoint,
                                         TaskList = sceneTarget.TaskList,
                                         DelayTime = 0,
                                         MemberNumber = i + 1
@@ -990,15 +968,15 @@
                                 var sceneTarget = modifySceneTargetDevicesList[i];
                                 if (sceneTarget.Type == 0)
                                 {
-                                    if (sceneTarget.DeviceUI == null || sceneTarget.DeviceUI.CommonDevice == null)
+                                    if (sceneTarget.DeviceUI == null)
                                     {
                                         continue;
                                     }
                                     var removeDevice = new RemoveSceneDeviceListInfo
                                     {
                                         Type = 0,
-                                        DeviceAddr = sceneTarget.DeviceUI.CommonDevice.DeviceAddr,
-                                        Epoint = sceneTarget.DeviceUI.CommonDevice.DeviceEpoint,
+                                        DeviceAddr = sceneTarget.DeviceUI.DeviceAddr,
+                                        Epoint = sceneTarget.DeviceUI.DeviceEpoint,
                                         MemberNumber = sceneTarget.DelayTimeSerialNumber
                                     };
                                     removeSceneDeviceListInfoList.Add(removeDevice);
@@ -1026,15 +1004,13 @@
                             }
                             sceneRemoveMemberData.DeviceList = removeSceneDeviceListInfoList;
                             sceneRemoveMemberData.ScenesId = modifySceneUI.Id;
-                            var result = await curRoom.ModifyScene(modifySceneUI, sceneRemoveMemberData, memberDataList);
+                            var result = await HdlSceneLogic.Current.ModifyScene(modifySceneUI, sceneRemoveMemberData, memberDataList);
                             if (result == 1)
                             {
                                 if (modifyRoom != curRoom)
                                 {
-                                    modifyRoom.SceneUIList.Remove(modifySceneUI);
-                                    modifyRoom.SceneUIFilePathList.Remove(modifySceneUI.FileName);
-                                    curRoom.SceneUIList.Add(modifySceneUI);
-                                    curRoom.SceneUIFilePathList.Add(modifySceneUI.FileName);
+                                    modifyRoom.ListSceneId.Remove(modifySceneUI.Id);
+                                    curRoom.ListSceneId.Add(modifySceneUI.Id);
                                     modifyRoom.Save();
                                     curRoom.Save();
                                 }
@@ -1078,6 +1054,7 @@
                             if (IconPathType == 1 || IconPathType == 2)
                             {
                                 Shared.IO.FileUtils.WriteFileByBytes(System.IO.Path.Combine(Config.Instance.FullPath, fileName), backGround.ImageBytes);
+                                HdlAutoBackupLogic.AddOrEditorFile(fileName);
                                 imgPath = fileName;
                             }
                             else
@@ -1097,7 +1074,7 @@
 
                                 if (sceneTarget.Type == 0)
                                 {
-                                    if (sceneTarget.DeviceUI == null || sceneTarget.DeviceUI.CommonDevice == null)
+                                    if (sceneTarget.DeviceUI == null)
                                     {
                                         continue;
                                     }
@@ -1105,8 +1082,8 @@
                                     {
                                         Type = 0,
                                         ScenesId = 0,
-                                        DeviceAddr = sceneTarget.DeviceUI.CommonDevice.DeviceAddr,
-                                        Epoint = sceneTarget.DeviceUI.CommonDevice.DeviceEpoint,
+                                        DeviceAddr = sceneTarget.DeviceUI.DeviceAddr,
+                                        Epoint = sceneTarget.DeviceUI.DeviceEpoint,
                                         TaskList = sceneTarget.TaskList,
                                         DelayTime = 0,
                                         MemberNumber = i+1
@@ -1138,7 +1115,7 @@
                                 }
                             }
 
-                            var result = await curRoom.AddScene(nameRow.NameText.Text, imgPath, memberDataList);
+                            var result = await HdlSceneLogic.Current.AddScene(curRoom, nameRow.NameText.Text, imgPath, memberDataList, IconPathType);
                             if (result == 1)
                             {
                                 AddAction?.Invoke();
@@ -1176,7 +1153,7 @@
         /// ShowSelectAction
         /// </summary>
         /// <param name="device"></param>
-        private void ShowSelectAction(DeviceUI device, SceneTargetDeviceUI sceneTarget)
+        private void ShowSelectAction(CommonDevice device, SceneTargetDeviceUI sceneTarget)
         {
             var dialog = new FrameLayout()
             {
@@ -1189,23 +1166,23 @@
                 dialog.RemoveFromParent();
             };
 
-            if (device.CommonDevice.Type == ZigBee.Device.DeviceType.OnOffOutput)
+            if (device.Type == ZigBee.Device.DeviceType.OnOffOutput)
             {
                 SelectOnoffOutput(dialog, device, sceneTarget);
             }
-            else if (device.CommonDevice.Type == ZigBee.Device.DeviceType.AirSwitch)
+            else if (device.Type == ZigBee.Device.DeviceType.AirSwitch)
             {
                 SelectOnoffOutput(dialog, device, sceneTarget);
             }
-            else if (device.CommonDevice.Type == ZigBee.Device.DeviceType.DimmableLight)
+            else if (device.Type == ZigBee.Device.DeviceType.DimmableLight)
             {
                 SelectDimmableLight(dialog, device, sceneTarget);
             }
-            else if (device.CommonDevice.Type == ZigBee.Device.DeviceType.WindowCoveringDevice)
+            else if (device.Type == ZigBee.Device.DeviceType.WindowCoveringDevice)
             {
                 SelectWindowCoveringDevice(dialog, device, sceneTarget);
             }
-            else if (device.CommonDevice.Type == ZigBee.Device.DeviceType.Thermostat)
+            else if (device.Type == ZigBee.Device.DeviceType.Thermostat)
             {
                 SelectThermostat(dialog, device, sceneTarget);
             }
@@ -1217,7 +1194,7 @@
         /// <param name="dialog"></param>
         /// <param name="device"></param>
         /// <param name="sceneTarget"></param>
-        private void SelectOnoffOutput(FrameLayout dialog, DeviceUI device, SceneTargetDeviceUI sceneTarget)
+        private void SelectOnoffOutput(FrameLayout dialog, CommonDevice device, SceneTargetDeviceUI sceneTarget)
         {
             var selectFL = new FrameLayout
             {
@@ -1266,7 +1243,7 @@
                 Gravity = Gravity.CenterHorizontal,
                 TextColor = ZigbeeColor.Current.GXCTextBlackColor,
                 TextSize = 16,
-                Text = device.CommonDevice.DeviceEpointName
+                Text = Common.LocalDevice.Current.GetDeviceEpointName(device)
             };
             titleFL.AddChidren(deviceName);
 
@@ -1373,7 +1350,7 @@
         /// <param name="dialog"></param>
         /// <param name="device"></param>
         /// <param name="sceneTarget"></param>
-        private void SelectWindowCoveringDevice(FrameLayout dialog, DeviceUI device, SceneTargetDeviceUI sceneTarget)
+        private void SelectWindowCoveringDevice(FrameLayout dialog, CommonDevice device, SceneTargetDeviceUI sceneTarget)
         {
             var selectFL = new FrameLayout
             {
@@ -1422,7 +1399,7 @@
                 Gravity = Gravity.CenterHorizontal,
                 TextColor = ZigbeeColor.Current.GXCTextBlackColor,
                 TextSize = 16,
-                Text = device.CommonDevice.DeviceEpointName
+                Text = Common.LocalDevice.Current.GetDeviceEpointName(device)
             };
             titleFL.AddChidren(deviceName);
 
@@ -1475,7 +1452,7 @@
                 dialog.RemoveFromParent();
             };
 
-            open.SeekBar.ProgressChanged += (sender, e) =>
+            open.SeekBar.OnProgressChangedEvent += (sender, e) =>
             {
                 open.IsSelected = true;
                 shut.IsSelected = false;
@@ -1493,7 +1470,7 @@
                 {
                     open.IsSelected = true;
                     shut.IsSelected = false;
-                    open.SetProgress(sceneTarget.TaskList[0].Data2);
+                    open.SetSeekBarProgress(sceneTarget.TaskList[0].Data2);
                 }
             }
 
@@ -1538,7 +1515,7 @@
         /// <param name="dialog"></param>
         /// <param name="device"></param>
         /// <param name="sceneTarget"></param>
-        private void SelectDimmableLight(FrameLayout dialog, DeviceUI device, SceneTargetDeviceUI sceneTarget)
+        private void SelectDimmableLight(FrameLayout dialog, CommonDevice device, SceneTargetDeviceUI sceneTarget)
         {
             var selectFL = new FrameLayout
             {
@@ -1588,7 +1565,7 @@
                 TextColor = ZigbeeColor.Current.GXCTextBlackColor,
                 TextSize = 16,
                 TextAlignment = TextAlignment.CenterLeft,
-                Text = device.CommonDevice.DeviceEpointName
+                Text = Common.LocalDevice.Current.GetDeviceEpointName(device)
             };
             titleFL.AddChidren(deviceName);
 
@@ -1641,7 +1618,7 @@
                 dialog.RemoveFromParent();
             };
 
-            open.SeekBar.ProgressChanged += (sender, e) =>
+            open.SeekBar.OnProgressChangedEvent += (sender, e) =>
             {
                 open.IsSelected = true;
                 shut.IsSelected = false;
@@ -1659,7 +1636,7 @@
                 {
                     open.IsSelected = true;
                     shut.IsSelected = false;
-                    open.SetProgress(sceneTarget.TaskList[0].Data1);
+                    open.SetSeekBarProgress(sceneTarget.TaskList[0].Data1);
                 }
             }
 
@@ -1704,7 +1681,7 @@
         /// <param name="dialog"></param>
         /// <param name="device"></param>
         /// <param name="sceneTarget"></param>
-        private void SelectThermostat(FrameLayout dialog, DeviceUI device, SceneTargetDeviceUI sceneTarget)
+        private void SelectThermostat(FrameLayout dialog, CommonDevice device, SceneTargetDeviceUI sceneTarget)
         {
         /// 娓╁害
         int tempId=0;
@@ -1761,7 +1738,7 @@
                 TextColor = ZigbeeColor.Current.GXCTextBlackColor,
                 TextSize = 16,
                 TextAlignment = TextAlignment.CenterLeft,
-                Text = device.CommonDevice.DeviceEpointName
+                Text = Common.LocalDevice.Current.GetDeviceEpointName(device)
             };
             titleFL.AddChidren(deviceName);
 

--
Gitblit v1.8.0