From cc1012b077a91793c0edd6001cdf019e6bd9a57d Mon Sep 17 00:00:00 2001
From: lss <316519258@qq.com>
Date: 星期五, 29 五月 2020 18:02:13 +0800
Subject: [PATCH] 2020.05.29

---
 ZigbeeApp/Shared/Phone/UserCenter/SmartSound/Forms/SmartSoundControlForm.cs |  432 ++++++++++++++++++++++++++++++++----------------------
 1 files changed, 256 insertions(+), 176 deletions(-)

diff --git a/ZigbeeApp/Shared/Phone/UserCenter/SmartSound/Forms/SmartSoundControlForm.cs b/ZigbeeApp/Shared/Phone/UserCenter/SmartSound/Forms/SmartSoundControlForm.cs
index 93a5e94..3a049d9 100644
--- a/ZigbeeApp/Shared/Phone/UserCenter/SmartSound/Forms/SmartSoundControlForm.cs
+++ b/ZigbeeApp/Shared/Phone/UserCenter/SmartSound/Forms/SmartSoundControlForm.cs
@@ -1,216 +1,296 @@
 锘縰sing System;
 using System.Collections.Generic;
 using Shared.Common;
+using Shared.Phone.UserCenter.SmartSound.Forms;
 using ZigBee.Device;
 
 namespace Shared.Phone.UserCenter.SmartSound
 {
+
     public class SmartSoundControlForm : EditorCommonForm
     {
-        private SmartSound mSmartSound;
+
+        /// <summary>
+        /// 鍒楄〃鎺т欢
+        /// </summary>
+        private VerticalListControl listView = null;
+        private FrameLayout contentLayout = null;
+        public int CurrentIndex = 0;
+        private MostRightIconControl btnAddDeviceIcon = null;
 
         public SmartSoundControlForm()
         {
         }
 
-        /// <summary>
-        /// 鐢婚潰鏄剧ず(搴曞眰浼氬浐瀹氳皟鐢ㄦ鏂规硶锛屽�熶互瀹屾垚鐢婚潰鍒涘缓)
-        /// </summary>
-        public void ShowForm()
-        {
-            // iniData();//鍏堝姞杞芥ā鎷熸暟鎹�
-
-            this.ScrollEnabled = false;
-           
-            //璁剧疆鏍囬淇℃伅
+        /// <summary>
+        /// 鐢婚潰鏄剧ず(搴曞眰浼氬浐瀹氳皟鐢ㄦ鏂规硶锛屽�熶互瀹屾垚鐢婚潰鍒涘缓)
+        /// </summary>
+        public void ShowForm()
+        {
+            
+            //璁剧疆鏍囬淇℃伅
             base.SetTitleText("璇煶鎺у埗");
 
             //鍙充笂娣诲姞鎸夐挳
-            var btnAddDeviceIcon = new MostRightIconControl(69, 69);
-            btnAddDeviceIcon.UnSelectedImagePath = "Item/Add.png";
-            topFrameLayout.AddChidren(btnAddDeviceIcon);
-            btnAddDeviceIcon.InitControl();
-            btnAddDeviceIcon.ButtonClickEvent += (sender, e) =>
-            {
-                iniView();
-            };
+            if (btnAddDeviceIcon == null)
+            {
+                btnAddDeviceIcon = new MostRightIconControl(69, 69);
+                btnAddDeviceIcon.UnSelectedImagePath = "Item/Add.png";
+                topFrameLayout.AddChidren(btnAddDeviceIcon);
+                btnAddDeviceIcon.InitControl();
+                btnAddDeviceIcon.ButtonClickEvent += (sender, e) =>
+                {
+                    var smartSoundDataAdd = new SmartSoundControlContentForm();
+                    smartSoundDataAdd.AddForm();
+                };
+            }
 
             //鍒濆鍖栦腑閮ㄦ帶浠�
-            //this.InitMiddleFrame();
+            this.InitMiddleFrame();
 
         }
 
-        /// <summary>
-        /// 灏嗘暟鎹浆鎹负鏅鸿兘闊崇浣跨敤鐨勬暟鎹�
-        /// </summary>
-        private void iniData(bool isAdd)
+
+        private void InitMiddleFrame()
         {
-            //1.浠庢湇鍔″櫒鑾峰彇鐨勬暟鎹紝json鍙嶅簭鍒楀寲寰楁潵
-            //2.鐐瑰嚮"+"灏嗙綉鍏崇殑鏁版嵁杞崲涓� 鏅鸿兘闊崇浣跨敤鐨勬暟鎹�
-            /*{
 
-                Dictionary<string, string> ss = Config.Instance.Home.FloorDics;//妤煎眰鍒楄〃
-                string currentFloor = Config.Instance.Home.CurrentFloorId;//褰撳墠妤煎眰鐨勯敭
-
-                var listRoom = HdlRoomLogic.Current.GetFloorSortRoom("妤煎眰鐨勪富閿�");//鑾峰彇褰撳墠妤煎眰鐨勬墍鏈夋埧闂�
-                var room = listRoom[0];
-                for (int i=0;i<room.ListDevice.Count;i++)
-                {//璁惧鏁版嵁
-                    var device = LocalDevice.Current.GetDevice(room.ListDevice[i]);
-                    var myType = LocalDevice.Current.GetNotHdlMyDeviceEnumInfo(new List<CommonDevice>() { device });                                      
+            if (SmartSound.CurretnData == null || SmartSound.CurretnData.Count < 1)
+                return;
 
-                    if (myType.BeloneType == DeviceBeloneType.A鐏厜)
+            // 娣诲姞鏁版嵁
+            if (contentLayout != null)
+            {
+                contentLayout.RemoveAll();
+                contentLayout = null;
+            }
+                
+            contentLayout = new FrameLayout();
+            this.bodyFrameLayout.AddChidren(contentLayout);
+            contentLayout.RemoveAll();
+
+            var pullLayout = new MyPullControl(this, SmartSound.CurretnData);
+            contentLayout.AddChidren(pullLayout);
+            pullLayout.InitControl();
+
+            LoadAllRoomListView();
+
+        }
+
+        private void LoadAllRoomListView()
+        {
+            try
+            {
+
+                if (SmartSound.CurretnData == null || SmartSound.CurretnData.Count < 1)
+                    return;
+
+                // 鍔犺浇褰撳墠妤煎眰鐨勬墍鏈夋埧闂� ListView
+                if (listView == null)
+                {
+
+                    listView = new VerticalListControl();
+                    contentLayout.AddChidren(listView);
+                    listView.Y = Application.GetRealHeight(173);
+                    listView.Height = bodyFrameLayout.Height - Application.GetRealHeight(173);
+
+                }
+                else if (listView.Parent == null)
+                {
+                    listView = new VerticalListControl();
+                    contentLayout.AddChidren(listView);
+                    listView.Y = Application.GetRealHeight(173);
+                    listView.Height = bodyFrameLayout.Height - Application.GetRealHeight(173);
+                }
+
+                listView.RemoveAll();
+
+                SmartSound.Layer layer = SmartSound.CurretnData[CurrentIndex];
+
+                foreach (SmartSound.Room room in layer.RoomList)
+                {
+                    var roomRowLayout = new RoomRowLayout(this, room);
+                    listView.AddChidren(roomRowLayout);
+                    roomRowLayout.InitControl();
+
+                    roomRowLayout.btnDelect.ButtonClickEvent += (sender, e) =>
                     {
-                        //杩欓噷闈㈢殑灏辨槸鐏厜浜�
-                        var light = device;
-                        // light.DeviceAddr;  璁惧鐨勫湴鍧�
-                        // light.DeviceEpoint;//璁惧鐨勭鍙�
-                    }
-                }
+
+                        try
+                        {
+                            var delBtn = sender as NormalViewControl;
+                            var tag = (SmartSound.Room)delBtn.GetTagByKey("obj");
+
+                            if (SmartSound.CurretnData == null)
+                                return;
+
+                            for (int i = 0; i < SmartSound.CurretnData.Count; i++)
+                            {
+                                SmartSound.Layer _layer = SmartSound.CurretnData[i];
+
+                                for (int j = 0; j < _layer.RoomList.Count; j++)
+                                {
+                                    SmartSound.Room _room = _layer.RoomList[j];
+
+                                    if (_room.RoomID == tag.RoomID)
+                                    {
+                                        _layer.RoomList.Remove(_room);
+                                        this.LoadAllRoomListView();
+                                    }
+                                }
+                            }                            
+                        }
+                        catch(Exception ex)
+                        {
+                            string error = ex.Message;
+                        }
+                    };
+                }
+
+            }
+            catch(Exception e)
+            {
+                string error = e.Message;
+            }
+        }
+
+        public override int FormActionAgainEvent()
+        {
+            ShowForm();
+            return base.FormActionAgainEvent();
+        }
+
+        #region 鈻� 鑷畾涔夋ゼ灞傞�夋嫨鎺т欢_____________________
+
+        /// <summary>
+        /// 鎴块棿鍒楄〃琛�
+        /// </summary>
+        private class MyPullControl : FrameRowControl
+        {
+
+            private SmartSoundControlForm smartSoundControlData = null;
+            private List<SmartSound.Layer> Layers = null;
+            /// <summary>
+            /// 鎴块棿鍒楄〃
+            /// </summary>
+            private NormalViewControl btnName = null;
 
-                for (int i = 0; i < room.ListSceneId.Count; i++)
-                {   //鍦烘櫙鏁版嵁
-                    var device = HdlSceneLogic.Current.GetSceneUIBySceneId(room.ListSceneId[i]);
-                    // device.Id;鍦烘櫙 id
-                }
-            }*/
+            /// <summary>
+            /// 鎴块棿鍒楄〃琛�
+            /// </summary>
+            public MyPullControl(SmartSoundControlForm _SmartSoundDataAdd, List<SmartSound.Layer> _layers)
+            {
+                this.smartSoundControlData = _SmartSoundDataAdd;
+                this.Layers = _layers;
+                this.UseClickStatu = false;
+                this.BackgroundColor = UserCenterColor.Current.White;
+                this.Height = Application.GetRealHeight(173);
+            }
 
-            if (isAdd)
+            /// <summary>
+            /// 鍒濆鍖栨帶浠�
+            /// </summary>
+            public void InitControl()
             {
-                mSmartSound = new SmartSound();
-                mSmartSound.HomeID = Config.Instance.Home.Id;
-                mSmartSound.UserID = Config.Instance.Guid;
-
-                Dictionary<string, string> floorDictionary = Config.Instance.Home.FloorDics;//妤煎眰鍒楄〃
-
-                if (floorDictionary.Count < 1)
+                try
                 {
-                    //娌℃湁妤煎眰,妯℃嫙涓�涓�
-                    SmartSound.Layer layer = new SmartSound.Layer();
-                    layer.LayerID = "0000";
-                    layer.LayerName = "涓�妤�";
-                    layer.RoomList.Clear();
+                    //鏄剧ず鏂囨湰
+                    btnName = this.AddLeftCaption(string.Empty, 700);
+                    btnName.Height = Application.GetRealHeight(60);
+                    btnName.TextSize = 17;
+                    btnName.Y = Application.GetRealHeight(57);
+                    btnName.Text = "鎴块棿鍒楄〃";
 
-                    //娣诲姞鎴块棿
-                    SmartSound.Room smartRoom = null;
-                    var roomList = HdlRoomLogic.Current.GetAllListRooms();
-                    for (int i = 0; i < roomList.Count; i++)
+                    var right_icon = this.AddRightArrow();
+                    right_icon.SelectedImagePath = "SmartSound/PullDown.png";
+                    right_icon.UnSelectedImagePath = "SmartSound/PullDown.png";
+                    right_icon.ButtonClickEvent += (sender, e) =>
                     {
-                        Room room = roomList[i];
-                        smartRoom = new SmartSound.Room();
-                        layer.RoomList.Add(smartRoom);
-
-                        smartRoom.RoomID = room.Id;
-                        smartRoom.RoomName = room.Name;
-                        smartRoom.DeviceList.Clear();
-                        smartRoom.SceneList.Clear();
-
-                        //娣诲姞璁惧  // 鐏厜銆佺獥甯樸�佸満鏅�佺┖璋�
-                        for (int j = 0; j < room.ListDevice.Count; j++)
-                        {
-                            string key = room.ListDevice[j].ToString();
-                            var device = LocalDevice.Current.GetDevice(key);
-
-                            SmartSound.Device smartDevice = new SmartSound.Device();
-                            smartDevice.Id = device.DeviceID.ToString();//璁惧 Id
-                            smartDevice.DeviceAddress = device.DeviceAddr;//璁惧 MAC
-                            smartDevice.Epoint = device.DeviceEpoint;//璁惧绔彛
-                            smartDevice.ClusterID = 0;
-                            smartDevice.DeviceName = device.DeviceName;//璁惧鍚嶇О
-                            smartDevice.NicksName = "";
-                            smartDevice.DeviceType = getDeviceType(device);//璁惧绫诲瀷
-                            smartDevice.GatewayID = device.CurrentGateWayId;//缃戝叧 Id
-                            smartDevice.RoomID = room.Id;//鎴块棿 Id
-
-                            smartRoom.DeviceList.Add(smartDevice);
-                                                       
-                        }
-
-                        var sceneList = HdlSceneLogic.Current.GetRoomSceneList(room);
-                        //娣诲姞鍦烘櫙
-                        for (int j = 0; j < sceneList.Count; j++)
-                        {
-                            SceneUI scene = sceneList[j];
-                            SmartSound.Scene smartScene = new SmartSound.Scene();
-                            smartScene.Id = scene.DeviceID.ToString();
-                            smartScene.SceneName = scene.Name;
-                            smartScene.SceneID = scene.Id;
-                            smartScene.DelayTime = scene.DelayTime;
-                            smartScene.ClusterID = 0;
-                            smartScene.NicksName = "";
-                            smartScene.RoomID = room.Id;
-
-                            smartRoom.SceneList.Add(smartScene);
-                        }
-                    }
+                        ShowPullList();
+                    };
+                   
+                    var layout = this.AddMostRightView(Layers[smartSoundControlData.CurrentIndex].LayerName, 300, false);
+                    layout.Name = "pullLayout";
+                    layout.ButtonClickEvent += (sender, e) =>
+                    {
+                        ShowPullList();
+                    };
                 }
-            }
-        }
-
-        /// <summary>
-        /// Zigbee璁惧绫诲瀷杞崲涓烘櫤鑳介煶绠变娇鐢ㄧ殑绫诲瀷
-        /// </summary>
-        /// <returns></returns>
-        private int getDeviceType(ZigBee.Device.CommonDevice device)
-        {
-            int type = 0;//1=寮�鍏崇伅锛�2=璋冨厜鐏紝3=RGB 鐏紝4=绐楀笜妯″潡锛�5=寮�鍚堝笜锛�6=鍗峰笜锛�7=绌鸿皟锛�8=闈㈡澘锛�9=鏂伴
-
-            if (device.Type == DeviceType.OnOffOutput && device.DfunctionType == DeviceFunctionType.A鐏厜)
-            {
-                type = 1;//杩欓噷闈㈢殑灏辨槸缁х數鍣ㄧ伅鍏変簡
-            }
-            else if (device.Type == DeviceType.DimmableLight)
-            {
-                type = 2;//璋冨厜
-            }
-            else if (device.Type == DeviceType.ColorDimmableLight)
-            {
-                type = 3;
-            }
-            else if (device.Type == DeviceType.WindowCoveringDevice)
-            {
-                //绐楀笜
-                if (((Rollershade)device).WcdType == 4)//寮�鍚堝笜
+                catch(Exception e)
                 {
-                    type = 5;
+                    string error = e.Message;
                 }
-                else if (((Rollershade)device).WcdType == 0)//鍗峰笜
-                    type = 6;//鍗峰笜
-            }
-            else if (device.Type == DeviceType.Thermostat)
+            }
+
+            private void ShowPullList()
             {
-                type = 7;
-            }
-            else if (device.Type == DeviceType.FreshAir)
-            {
-                type = 9;
-            }
+                //鎴块棿鍒楄〃琛寋鎴块棿鍒楄〃 textView锛屾ゼ灞備笅鎷夌獥}
+                //鏄剧ず鎴块棿{甯﹂�夋嫨妗嗙殑锛涘綋閫変腑浜嗘埧闂村悗闇�瑕佸湪搴曢儴寮瑰嚭纭鎸夐挳锛岀偣鍑荤‘璁よ烦杞埌鏂扮殑鐣岄潰}
+                var pull_frame = new TopRightMenuControl(Layers.Count, 2);
+                pull_frame.Y = this.Height;
 
-            return type;
-        }
-
-        private void iniView()
-        {
-            //鎴块棿鍒楄〃琛寋鎴块棿鍒楄〃 textView锛屾ゼ灞備笅鎷夌獥}
-            //鏄剧ず鎴块棿{甯﹂�夋嫨妗嗙殑锛涘綋閫変腑浜嗘埧闂村悗闇�瑕佸湪搴曢儴寮瑰嚭纭鎸夐挳锛岀偣鍑荤‘璁よ烦杞埌鏂扮殑鐣岄潰}
-            var frame = new TopRightMenuControl(2, 2);
-            //鍒涘缓妤煎眰
-            frame.AddRowMenu(Language.StringByID(R.MyInternationalizationString.uCreatFloor), "Item/CreatFloor.png", "Item/CreatFloorSelected.png", () =>
-            {
-                //鍒涘缓妤煎眰
-                //this.CreatOrEditorFloor(null, null, string.Empty, string.Empty);
-            });
-            //鍒涘缓鎴块棿
-            frame.AddRowMenu(Language.StringByID(R.MyInternationalizationString.uCreatRoom), "Item/RoomIcon.png", "Item/RoomIconSelected.png", () =>
-            {
-                /*var form = new AddNewRoomForm();
-                form.AddForm(string.Empty);
-                form.FinishEditorEvent += () =>
+                for (int i = 0; i < Layers.Count; i++)
                 {
-                    //鏍规嵁鎸囧畾妯″紡,鍒濆鍖栨甯冩帶浠�
-                    this.InitFrameTableByMode();
-                };*/
-            });
+                    //鍒涘缓妤煎眰
+                    pull_frame.AddRowMenu(Layers[i].LayerName, "Item/CreatFloor.png", "Item/CreatFloorSelected.png", () =>
+                    {
+                        smartSoundControlData.CurrentIndex = i;
+                        smartSoundControlData.LoadAllRoomListView();
+                    });
+                }
+            }
+        }
+        #endregion
+
+        #region 鈻� 鑷畾涔夋櫤鑳介煶绠辨帶浠禵____________________
+
+        /// <summary>
+        /// 璇煶鎺у埗鎴块棿琛�
+        /// </summary>
+        private class RoomRowLayout : RowLayoutControl
+        {
+
+            /// <summary>
+            /// 鎴块棿鍚嶅瓧
+            /// </summary>
+            private NormalViewControl btnName = null;
+
+            /// <summary>
+            /// 鍒犻櫎鎸夐挳
+            /// </summary>
+            public NormalViewControl btnDelect = null;
+
+            private SmartSoundControlForm smartSoundControlForm;
+            private SmartSound.Room room;
+          
+            /// <summary>
+            /// 鑷畾闊崇鍏虫帶浠�
+            /// </summary>
+            public RoomRowLayout(SmartSoundControlForm _smartSoundControlForm, SmartSound.Room _room)
+            {
+                this.smartSoundControlForm = _smartSoundControlForm;
+                this.room = _room;
+                this.BackgroundColor = UserCenterColor.Current.White;
+                this.Height = Application.GetRealHeight(173);
+               
+            }
+
+            /// <summary>
+            /// 鍒濆鍖栧唴閮ㄦ帶浠�
+            /// </summary>
+            public void InitControl()
+            {
+                //璁惧           
+                frameTable.AddLeftCaption(this.room.RoomName, 800);
+                frameTable.AddRightArrow();
+                //搴曠嚎
+                frameTable.AddBottomLine();
+                
+                btnDelect = base.AddDeleteControl();
+                btnDelect.Text = "鍒犻櫎";
+                btnDelect.AddTag("obj", room);
+
+            }
+            #endregion
         }
     }
-}
+}
\ No newline at end of file

--
Gitblit v1.8.0