From d6fb0646531172f23648441c224cdcccd721b894 Mon Sep 17 00:00:00 2001
From: xm <1271024303@qq.com>
Date: 星期一, 14 十二月 2020 09:59:01 +0800
Subject: [PATCH] 请合并代码,完成晾衣架最终功能。

---
 ZigbeeApp/Shared/Phone/UserCenter/Device/PirSensor/PirSensorTargetSelectForm.cs |  386 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 386 insertions(+), 0 deletions(-)

diff --git a/ZigbeeApp/Shared/Phone/UserCenter/Device/PirSensor/PirSensorTargetSelectForm.cs b/ZigbeeApp/Shared/Phone/UserCenter/Device/PirSensor/PirSensorTargetSelectForm.cs
new file mode 100755
index 0000000..3bf2b16
--- /dev/null
+++ b/ZigbeeApp/Shared/Phone/UserCenter/Device/PirSensor/PirSensorTargetSelectForm.cs
@@ -0,0 +1,386 @@
+锘縰sing System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace Shared.Phone.UserCenter.DevicePirSensor
+{
+    /// <summary>
+    /// PIR浼犳劅鍣ㄧ殑瑙﹀彂鐩爣閫夋嫨鐣岄潰
+    /// </summary>
+    public class PirSensorTargetSelectForm : EditorCommonForm
+    {
+        #region 鈻� 鍙橀噺澹版槑___________________________
+
+        /// <summary>
+        /// 缁撴潫閫夋嫨鐨勪簨浠�(璁惧涓婚敭)
+        /// </summary>
+        public Action<List<string>> FinishSelectEvent = null;
+        /// <summary>
+        /// 褰撳墠閫夋嫨鐨勬ゼ灞侷D
+        /// </summary>
+        private string nowSelectFloorId = string.Empty;
+        /// <summary>
+        /// 妗屽竷鎺т欢
+        /// </summary>
+        private NormalFrameLayout frameTable = null;
+        /// <summary>
+        /// 鎴块棿瀵硅薄
+        /// </summary>
+        private Dictionary<string, List<Common.Room>> dicRoom = new Dictionary<string, List<Common.Room>>();
+        /// <summary>
+        /// 宸茬粡瀛樺湪鐨勭粦瀹氳澶�
+        /// </summary>
+        private List<string> listEsixtDevice = new List<string>();
+
+        #endregion
+
+        #region 鈻� 鍒濆鍖朹____________________________
+
+        /// <summary>
+        /// 鐢婚潰鏄剧ず(搴曞眰浼氬浐瀹氳皟鐢ㄦ鏂规硶锛屽�熶互瀹屾垚鐢婚潰鍒涘缓)
+        /// </summary>
+        /// <param name="i_listEsixtDevice">瀛樺湪鐨勮澶�</param>
+        public void ShowForm(List<string> i_listEsixtDevice)
+        {
+            this.listEsixtDevice.AddRange(i_listEsixtDevice);
+
+            //璁剧疆澶撮儴淇℃伅
+            base.SetTitleText(Language.StringByID(R.MyInternationalizationString.uTriggerTarget));
+
+            //鍒濆鍖栧彸涓婅鐨勬帶浠�
+            this.InitTopRightMenuControl();
+
+            //鍒濆鍖栦腑閮ㄤ俊鎭�
+            this.InitMiddleFrame();
+        }
+
+        /// <summary>
+        /// 鍒濆鍖栦腑閮ㄤ俊鎭�
+        /// </summary>
+        private void InitMiddleFrame()
+        {
+            //娓呯┖bodyFrame
+            this.ClearBodyFrame();
+
+            //鎴块棿鐨勫鍣ㄦ帶浠�
+            var frameBack = new FrameLayout();
+            frameBack.Height = Application.GetRealHeight(204);
+            bodyFrameLayout.AddChidren(frameBack);
+
+            //妗屽竷鎺т欢
+            this.frameTable = new NormalFrameLayout();
+            frameTable.Y = frameBack.Bottom;
+            frameTable.Height = bodyFrameLayout.Height - frameBack.Height;
+            bodyFrameLayout.AddChidren(frameTable);
+
+            //鍏朵粬
+            var tempRoom = new Common.Room();
+            tempRoom.Name = Language.StringByID(R.MyInternationalizationString.uOther);
+            foreach (var mainKeys in this.listEsixtDevice)
+            {
+                var device = Common.LocalDevice.Current.GetDevice(mainKeys);
+                if (device == null)
+                {
+                    continue;
+                }
+                //杩欎釜鎵嬫満寮勫紕,閭d釜鎵嬫満寮勫紕鐨勬儏鍐典笅,
+                //閲囩敤鍚庡鎿嶄綔 -> 鏂板缓涓�涓复鏃舵埧闂村璞″嚭鏉�
+                if (HdlRoomLogic.Current.GetRoomByDevice(device) == null)
+                {
+                    tempRoom.ListDevice.Add(Common.LocalDevice.Current.GetDeviceMainKeys(device));
+                }
+            }
+
+            HdlThreadLogic.Current.RunMainInThread(() =>
+            {
+                if (dicRoom.ContainsKey(nowSelectFloorId) == true && dicRoom[nowSelectFloorId].Count > 0)
+                {
+                    //鍒濆鍖栨埧闂存帶浠�
+                    var listRoom = new List<Common.Room>();
+                    listRoom.AddRange(dicRoom[nowSelectFloorId]);
+                    if (tempRoom.ListDevice.Count > 0)
+                    {
+                        //鏄剧ず鏂板缓鐨勪复鏃舵埧闂村璞�
+                        listRoom.Add(tempRoom);
+                    }
+                    var roomContr = new RoomDeviceGroupMenuControl(listRoom);
+                    frameBack.AddChidren(roomContr);
+                    roomContr.SelectRoomEvent += (myRoom) =>
+                    {
+                        //鍒濆鍖栬澶囪
+                        this.InitDeviceControl(myRoom);
+                    };
+                    roomContr.InitControl();
+
+                    //纭畾鎸夐挳
+                    var btnOk = new BottomClickButton();
+                    btnOk.TextID = R.MyInternationalizationString.uConfirm1;
+                    bodyFrameLayout.AddChidren(btnOk);
+                    btnOk.ButtonClickEvent += (sender, e) =>
+                    {
+                        //璋冪敤鍥炶皟鍑芥暟
+                        this.FinishSelectEvent?.Invoke(listEsixtDevice);
+                        //鐣岄潰鍏抽棴
+                        this.CloseForm();
+                    };
+                    //鏌ョ湅妯℃澘鏃�,涓嶅厑璁哥紪杈�
+                    if (Common.Config.Instance.Home.IsShowTemplate == true)
+                    {
+                        btnOk.CanClick = false;
+                    }
+                }
+                else
+                {
+                    //娌℃湁鍙互娣诲姞鐨勭洰鏍�
+                    this.ShowNotDataImage(bodyFrameLayout, Language.StringByID(R.MyInternationalizationString.uNotHadAddTarget));
+                }
+            });
+        }
+
+        #endregion
+
+        #region 鈻� 鍒濆鍖栧彸涓婅鐨勬帶浠禵________________
+
+        /// <summary>
+        /// 鍒濆鍖栧彸涓婅鐨勬帶浠�
+        /// </summary>
+        private void InitTopRightMenuControl()
+        {
+            //鎴块棿鍒嗙粍
+            var listRoom = HdlRoomLogic.Current.GetAllListRooms();
+            foreach (var room in listRoom)
+            {
+                //妫�娴嬭鎴块棿鑳藉惁鏄剧ず
+                if (this.CheckCanShowRow(room) == false)
+                {
+                    continue;
+                }
+                if (dicRoom.ContainsKey(room.FloorId) == false)
+                {
+                    dicRoom[room.FloorId] = new List<Common.Room>();
+                }
+                dicRoom[room.FloorId].Add(room);
+            }
+            if (dicRoom.Count == 0)
+            {
+                //榛樿涓�涓┖鐨勪笢瑗�
+                dicRoom[string.Empty] = new List<Common.Room>();
+            }
+
+            //鑾峰彇妤煎眰
+            var dicFloor = HdlRoomLogic.Current.GetFloorSortList();
+            if (dicFloor.Count == 0)
+            {
+                return;
+            }
+            int indexTemp = 1;
+            foreach (var floorId in dicRoom.Keys)
+            {
+                if (dicFloor.ContainsKey(floorId) == false)
+                {
+                    //杩欐槸澶氬彴鎵嬫満鐬庢悶涔嬪悗鍑虹幇鐨勫悗澶囪ˉ鏁戞帾鏂�
+                    dicFloor[floorId] = Language.StringByID(R.MyInternationalizationString.uOther) + indexTemp;
+                    indexTemp++;
+                }
+            }
+
+            var btnIconContr = new MostRightIconControl(69, 69);
+            btnIconContr.UnSelectedImagePath = "Item/Drop_Down.png";
+            topFrameLayout.AddChidren(btnIconContr);
+            btnIconContr.InitControl();
+
+            var btnFloor = new NormalViewControl(300, 69, true);
+            btnFloor.Gravity = Gravity.CenterVertical;
+            btnFloor.X = btnIconContr.X + btnIconContr.btnIcon.X - Application.GetRealWidth(300);
+            btnFloor.TextAlignment = TextAlignment.CenterRight;
+            topFrameLayout.AddChidren(btnFloor);
+
+            foreach (var floorId in dicFloor.Keys)
+            {
+                //绗竴涓ゼ灞�
+                this.nowSelectFloorId = floorId;
+                btnFloor.Text = dicFloor[floorId];
+                break;
+            }
+
+            btnIconContr.ButtonClickEvent += (sender, e) =>
+            {
+                //妤煎眰鑿滃崟
+                var contr = new TopRightMenuControl(dicFloor.Count, 2, Language.StringByID(R.MyInternationalizationString.SelectFloor));
+                foreach (var floorId in dicFloor.Keys)
+                {
+                    contr.AddRowMenu(dicFloor[floorId], "Floor/Floor.png", "Floor/FloorSelected.png", () =>
+                    {
+                        //璁板綍璧烽�夋嫨鐨処D
+                        this.nowSelectFloorId = floorId;
+                        btnFloor.Text = dicFloor[this.nowSelectFloorId];
+                        //鍒濆鍖栦腑閮ㄤ俊鎭�
+                        this.InitMiddleFrame();
+                    });
+                }
+            };
+        }
+        #endregion
+
+        #region 鈻� 鍒濆鍖栬澶囨帶浠禵____________________
+
+        /// <summary>
+        /// 鍒濆鍖栬澶囨帶浠�
+        /// </summary>
+        /// <param name="room"></param>
+        private void InitDeviceControl(Common.Room room)
+        {
+            //鍏堟竻绌�
+            this.frameTable.RemoveAll();
+
+            var frameBack = new FrameLayout();
+            frameBack.Height = Application.GetRealHeight(11);
+            frameBack.BackgroundColor = UserCenterColor.Current.White;
+            frameTable.AddChidren(frameBack);
+
+            var listView = new VerticalListControl(12);
+            listView.Y = frameBack.Bottom;
+            listView.Height = frameTable.Height - frameBack.Height;
+            listView.BackgroundColor = UserCenterColor.Current.White;
+            frameTable.AddChidren(listView);
+
+            var listDevice = new List<ZigBee.Device.CommonDevice>();
+            foreach (var deviceKeys in room.ListDevice)
+            {
+                var device = Common.LocalDevice.Current.GetDevice(deviceKeys);
+                //妫�娴嬭澶�
+                if (this.CheckCanShowDevice(device) == true)
+                {
+                    listDevice.Add(device);
+                }
+            }
+
+            for (int i = 0; i < listDevice.Count; i++)
+            {
+                var device = listDevice[i];
+                string mainKey = Common.LocalDevice.Current.GetDeviceMainKeys(device);
+
+                var rowDevice = new FrameRowControl(listView.rowSpace / 2);
+                listView.AddChidren(rowDevice);
+                //鍥炬爣
+                var btnIcon = rowDevice.AddLeftIcon(81);
+                Common.LocalDevice.Current.SetDeviceIconToControl(btnIcon, device);
+                //璁惧鍚嶇О
+                var btnName = rowDevice.AddLeftCaption(Common.LocalDevice.Current.GetDeviceEpointName(device), 700);
+                btnName.TextSize = 15;
+                //閫夋嫨
+                var btnSelect = rowDevice.AddMostRightEmptyIcon(58, 58);
+                if (listEsixtDevice.Contains(mainKey) == false)
+                {
+                    btnSelect.Visible = false;
+                }
+                btnSelect.UnSelectedImagePath = "Item/ItemSelected.png";
+                if (i != listDevice.Count - 1)
+                {
+                    //搴曠嚎
+                    rowDevice.AddBottomLine();
+                }
+
+                rowDevice.ButtonClickEvent += (sender, e) =>
+                {
+                    btnSelect.Visible = !btnSelect.Visible;
+                    if (btnSelect.Visible == true)
+                    {
+                        listEsixtDevice.Add(mainKey);
+                    }
+                    else
+                    {
+                        listEsixtDevice.Remove(mainKey);
+                    }
+                };
+                //鏌ョ湅妯℃澘鏃�,涓嶅厑璁哥紪杈�
+                if (Common.Config.Instance.Home.IsShowTemplate == true)
+                {
+                    rowDevice.CanClick = false;
+                }
+            }
+            listDevice = null;
+            //璋冩暣鎺т欢鐪熷疄楂樺害
+            listView.AdjustRealHeight(Application.GetRealHeight(23));
+            //鍊熺敤杩欎釜涓滆タ杩涜妫�娴�
+            var btnTemp = new BottomClickButton();
+            //濡傛灉鐪熷疄楂樺害宸茬粡瓒呰繃浜嗙‘瀹氭寜閿�
+            if (listView.Bottom + frameTable.Y > btnTemp.Yaxis)
+            {
+                listView.Height = frameTable.Height - frameBack.Height;
+                var frameTemp = new FrameLayout();
+                frameTemp.Height = bodyFrameLayout.Height - btnTemp.Yaxis;
+                listView.AddChidren(frameTemp);
+            }
+        }
+
+        #endregion
+
+        #region 鈻� 涓�鑸柟娉昣__________________________
+
+        /// <summary>
+        /// 妫�娴嬭鎴块棿鑳藉惁鏄剧ず
+        /// </summary>
+        /// <param name="room"></param>
+        /// <returns></returns>
+        private bool CheckCanShowRow(Common.Room room)
+        {
+            if (room.ListDevice.Count == 0)
+            {
+                return false;
+            }
+            if (room.IsLove == true)
+            {
+                return false;
+            }
+            foreach (var deviceKeys in room.ListDevice)
+            {
+                //妫�娴嬭璁惧鑳藉惁鏄剧ず
+                var device = Common.LocalDevice.Current.GetDevice(deviceKeys);
+                if (this.CheckCanShowDevice(device) == false)
+                {
+                    continue;
+                }
+
+                //瀛樺湪璁惧鐨勮瘽锛屾鎴块棿鍙互鏄剧ず
+                return true;
+            }
+            return false;
+        }
+
+        /// <summary>
+        /// 妫�娴嬭璁惧鑳藉惁鏄剧ず
+        /// </summary>
+        /// <param name="device"></param>
+        /// <returns></returns>
+        private bool CheckCanShowDevice(ZigBee.Device.CommonDevice device)
+        {
+            if (device == null)
+            {
+                return false;
+            }
+            //濡傛灉鏄紶鎰熷櫒锛屾垨鑰呮槸娌℃湁寮�鍏崇皣鐨勮瘽(杩欓噷鍒ゆ柇鐨勬槸杈撳叆绨�)
+            if ((device.Type == ZigBee.Device.DeviceType.IASZone) || Common.LocalDevice.Current.InDeviceIsCanOnOff(device) == false)
+            {
+                return false;
+            }
+            return true;
+        }
+
+        #endregion
+
+        #region 鈻� 鐣岄潰鍏抽棴___________________________
+
+        /// <summary>
+        /// 鐣岄潰鍏抽棴
+        /// </summary>
+        public override void CloseFormBefore()
+        {
+            this.FinishSelectEvent = null;
+
+            base.CloseFormBefore();
+        }
+
+        #endregion
+    }
+}

--
Gitblit v1.8.0