From c1de48884fa145a16a0f8bcee93274dcfaa0ff82 Mon Sep 17 00:00:00 2001
From: xm <1271024303@qq.com>
Date: 星期四, 07 五月 2020 10:40:28 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/dev-tzy' into dev-2020xm

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

diff --git a/ZigbeeApp/Shared/Phone/UserCenter/Device/DeviceDryContactSettionForm.cs b/ZigbeeApp/Shared/Phone/UserCenter/Device/DeviceDryContactSettionForm.cs
new file mode 100755
index 0000000..be1e0ef
--- /dev/null
+++ b/ZigbeeApp/Shared/Phone/UserCenter/Device/DeviceDryContactSettionForm.cs
@@ -0,0 +1,639 @@
+锘縰sing Shared.Common;
+using System;
+using System.Collections.Generic;
+using System.Text;
+using System.Threading.Tasks;
+using ZigBee.Device;
+
+namespace Shared.Phone.UserCenter.Device
+{
+    /// <summary>
+    /// 璁惧骞叉帴鐐归厤缃�
+    /// </summary>
+    public class DeviceDryContactSettionForm : EditorCommonForm
+    {
+        #region 鈻� 鍙橀噺澹版槑___________________________
+
+        /// <summary>
+        /// 鍒楄〃鎺т欢
+        /// </summary>
+        private FrameListControl listview = null;
+        /// <summary>
+        /// 褰撳墠閫夋嫨鐨勮澶�
+        /// </summary>
+        private CommonDevice nowSelectDevice = null;
+        /// <summary>
+        /// 褰撳墠閫夋嫨鐨勫洖璺帶浠�
+        /// </summary>
+        private NormalViewControl nowSelectControl = null;
+        /// <summary>
+        /// 璁惧澶囨敞鐨勬帶浠�
+        /// </summary>
+        private FrameCaptionInputControl btnDeviceName = null;
+        /// <summary>
+        /// 璁惧鐨勬煇涓�鍥炶矾
+        /// </summary>
+        private CommonDevice deviceObj = null;
+        /// <summary>
+        /// 璁惧闇�瑕佷繚瀛樼殑璁惧鍚嶅瓧
+        /// </summary>
+        private Dictionary<int, string> dicDeviceSaveName = new Dictionary<int, string>();
+        /// <summary>
+        /// 璁惧鍏蜂綋绫诲瀷鐨勪俊鎭�
+        /// </summary>
+        private DeviceEnumInfo deviceEnumInfo = null;
+        /// <summary>
+        /// 淇℃伅缂栬緫鎺т欢
+        /// </summary>
+        private InformationEditorControl tableContr = null;
+
+        #endregion
+
+        #region 鈻� 鍒濆鍖朹____________________________
+
+        /// <summary>
+        /// 鐢婚潰鏄剧ず(搴曞眰浼氬浐瀹氳皟鐢ㄦ鏂规硶锛屽�熶互瀹屾垚鐢婚潰鍒涘缓)
+        /// </summary>
+        /// <param name="i_device">璁惧鐨勬煇涓�鍥炶矾</param>
+        public void ShowForm(CommonDevice i_device)
+        {
+            this.deviceObj = i_device;
+            var listDevice = Common.LocalDevice.Current.GetDevicesByMac(deviceObj.DeviceAddr);
+            //鑾峰彇杩欎竴鍫嗚澶囨椂灞炰簬浠�涔堢被鍨嬬殑
+            this.deviceEnumInfo = Common.LocalDevice.Current.GetMyDeviceEnumInfo(listDevice);
+
+            //璁剧疆澶撮儴淇℃伅
+            base.SetTitleText(Language.StringByID(R.MyInternationalizationString.uDryContactSettion));
+
+            //鍒濆鍖栦腑閮ㄤ俊鎭�
+            this.InitMiddleFrame();
+
+            //鍒濆鍖栧彸涓婅鑿滃崟
+            this.InitTopRightMenu();
+        }
+
+        /// <summary>
+        /// 鍒濆鍖栦腑閮ㄤ俊鎭�
+        /// </summary>
+        private void InitMiddleFrame()
+        {
+            //娓呯┖bodyFrame
+            this.ClearBodyFrame();
+
+            var listBackControl = new VerticalFrameControl();
+            listBackControl.Height = bodyFrameLayout.Height;
+            bodyFrameLayout.AddChidren(listBackControl);
+
+            //鍒濆鍖栨甯�
+            this.tableContr = new InformationEditorControl();
+            this.listview = tableContr.InitControl(listBackControl.frameTable, Language.StringByID(R.MyInternationalizationString.uDeviceEditor), 1175);
+
+            //鍒濆鍖栬澶囧洖璺浘鏍�
+            this.InitDeviceEpointIcon(listBackControl);
+
+            //淇濆瓨
+            var btnFinish = new BottomClickButton();
+            btnFinish.TextID = R.MyInternationalizationString.uSave;
+            bodyFrameLayout.AddChidren(btnFinish);
+            btnFinish.ButtonClickEvent += async (sender, e) =>
+            {
+                //璁板綍璧峰綋鍓嶆鍦ㄦ搷浣滅殑鍥炶矾鍚嶅瓧
+                dicDeviceSaveName[nowSelectDevice.DeviceEpoint] = btnDeviceName.Text.Trim();
+                //寮�鍚繘搴︽潯
+                this.ShowProgressBar();
+                foreach (var epoint in dicDeviceSaveName.Keys)
+                {
+                    var device = Common.LocalDevice.Current.GetDevice(deviceObj.DeviceAddr, epoint);
+                    if (device == null || dicDeviceSaveName[epoint] == string.Empty)
+                    {
+                        //涓嶈兘鍏佽绌虹櫧鍚嶅瓧
+                        continue;
+                    }
+                    string newName = dicDeviceSaveName[epoint];
+                    string oldName = Common.LocalDevice.Current.GetDeviceEpointName(device);
+                    if (oldName != newName)
+                    {
+                        //璁惧鍚嶇О淇敼
+                        var result = await Common.LocalDevice.Current.ReName(device, newName);
+                        if (result == false)
+                        {
+                            //鍏抽棴
+                            this.CloseProgressBar();
+                            return;
+                        }
+                    }
+                }
+                this.CloseProgressBar();
+                //鍏抽棴鑷韩
+                this.CloseForm();
+            };
+        }
+
+        /// <summary>
+        /// 鍒濆鍖栬彍鍗曡
+        /// </summary>
+        private async void InitMenuRow()
+        {
+            this.listview.RemoveAll();
+
+            //骞叉帴鐐瑰娉�
+            string caption = Language.StringByID(R.MyInternationalizationString.uDryContactNote);
+            string nameValue = Common.LocalDevice.Current.GetDeviceEpointName(nowSelectDevice);
+            if (dicDeviceSaveName.ContainsKey(nowSelectDevice.DeviceEpoint) == true)
+            {
+                nameValue = dicDeviceSaveName[nowSelectDevice.DeviceEpoint];
+            }
+
+            this.btnDeviceName = new FrameCaptionInputControl(caption, nameValue, listview.rowSpace / 2);
+            listview.AddChidren(btnDeviceName);
+            btnDeviceName.InitControl();
+            btnDeviceName.AddBottomLine();
+            btnDeviceName.txtInput.FinishInputEvent += async () =>
+            {
+                string oldName = Common.LocalDevice.Current.GetDeviceEpointName(nowSelectDevice);
+                if (btnDeviceName.Text.Trim() == string.Empty)
+                {
+                    //灏嗗悕瀛楄繕鍘�
+                    btnDeviceName.Text = oldName;
+                }
+                if (oldName != btnDeviceName.Text.Trim())
+                {
+                    //璁惧鍚嶇О淇敼
+                    var result = await Common.LocalDevice.Current.ReName(nowSelectDevice, btnDeviceName.Text.Trim());
+                    if (result == false)
+                    {
+                        return;
+                    }
+                    //骞叉帴鐐瑰娉ㄤ慨鏀规垚鍔�!
+                    string msg = Language.StringByID(R.MyInternationalizationString.uDryContactReNoteSuccess);
+                    this.ShowMassage(ShowMsgType.Tip, msg);
+                }
+            };
+
+            //鎵�灞炲尯鍩�
+            var rowBeloneArea = new BelongAreaControl(listview.rowSpace / 2);
+            listview.AddChidren(rowBeloneArea);
+            rowBeloneArea.InitControl(Language.StringByID(R.MyInternationalizationString.uBelongArea), nowSelectDevice);
+            //搴曠嚎
+            rowBeloneArea.AddBottomLine();
+            rowBeloneArea.SelectRoomEvent += (roomKeys) =>
+            {
+                //鍙樻洿鎴块棿
+                HdlRoomLogic.Current.ChangedRoom(nowSelectDevice, roomKeys);
+            };
+
+            //3璺户鐢靛櫒鎴栬��1璺皟鍏夊櫒绗竷鍥炶矾鐨勯厤缃俊鎭�
+            List<CommonDevice.AttributeDataObj> listRelayInfo7 = null;
+
+            bool isHdlDevice = Common.LocalDevice.Current.IsHdlDevice(nowSelectDevice);
+            //娌充笢璁惧鎵嶄細寮�鍚閫夐」
+            if (isHdlDevice == true)
+            {
+                //濡傛灉鏄�3璺户鐢靛櫒鎴栬��1璺皟鍏夊櫒,骞朵笖鏄涓冨洖璺殑鏃跺��,瀹冨ソ鍍忓彲浠ユ敼鍙樼被鍨�
+                if ((deviceEnumInfo.ConcreteType == DeviceConcreteType.Relay_ThreeLoad && nowSelectDevice.DeviceEpoint == 10)
+                    || (deviceEnumInfo.ConcreteType == DeviceConcreteType.DimmableLight_OneLoad && nowSelectDevice.DeviceEpoint == 7))
+                {
+                    //杩欓噷鍏堝幓鑾峰彇瀹冪殑骞叉帴鐐圭被鍨�
+                    this.ShowProgressBar();
+                    //鑾峰彇绗竷鍥炶矾鐨勯厤缃俊鎭�
+                    listRelayInfo7 = await HdlDevicePanelLogic.Current.GetDryContactConfigureInfo(nowSelectDevice);
+                    if (listRelayInfo7 == null)
+                    {
+                        //鍏抽棴杩涘害鏉�
+                        this.CloseProgressBar(ShowReLoadMode.YES);
+                        return;
+                    }
+                    //鍏抽棴杩涘害鏉�
+                    this.CloseProgressBar();
+                }
+                //娣诲姞骞叉帴鐐瑰姛鑳借
+                this.AddDryContactFunctionRow(listRelayInfo7);
+            }
+
+            //娣诲姞缁戝畾鐩爣琛�
+            this.AddBindRow(listRelayInfo7);
+            //娣诲姞鑳屽厜鐏
+            this.AddBackLightRow();
+            //鍒濆鍖栨甯冨畬鎴�
+            tableContr.FinishInitControl();
+        }
+
+        #endregion
+
+        #region 鈻� 鍙充笂瑙掕彍鍗昣________________________
+
+        /// <summary>
+        /// 鍒濆鍖栧彸涓婅鑿滃崟
+        /// </summary>
+        private void InitTopRightMenu()
+        {
+            //妫�娴嬫鍥炶矾鏄惁鎷ユ湁瀹氫綅鍔熻兘
+            if (Common.LocalDevice.Current.DeviceIsCanFixedPosition(nowSelectDevice) == false)
+            {
+                return;
+            }
+            var btnIcon = new MostRightIconControl(69, 69);
+            btnIcon.UnSelectedImagePath = "Item/More.png";
+            topFrameLayout.AddChidren(btnIcon);
+            btnIcon.InitControl();
+            btnIcon.ButtonClickEvent += ((sender, e) =>
+            {
+                //鏄剧ず鍙充笂瑙掕彍鍗曠晫闈�
+                this.ShowTopRightMenu();
+            });
+        }
+
+        /// <summary>
+        /// 鏄剧ず鍙充笂瑙掕彍鍗曠晫闈�
+        /// </summary>
+        private void ShowTopRightMenu()
+        {
+            int menuCount = 1;
+            string deviceMenu = string.Empty;
+            //妫�娴嬫鍥炶矾鏄惁鎷ユ湁瀹氫綅鍔熻兘
+            bool canTest = Common.LocalDevice.Current.DeviceIsCanFixedPosition(nowSelectDevice);
+            //if (canTest == true)
+            //{
+            //    menuCount = 2;
+            //}
+            var frame = new TopRightMenuControl(menuCount, 1);
+            if (canTest == true)
+            {
+                //瀹氫綅
+                deviceMenu = Language.StringByID(R.MyInternationalizationString.uFixedPosition);
+                frame.AddRowMenu(deviceMenu, "Item/FixedPosition.png", "Item/FixedPositionSelected.png", () =>
+                {
+                    //鍙戦�佸畾浣嶅姛鑳�
+                    Common.LocalDevice.Current.SetFixedPositionCommand(nowSelectDevice);
+                });
+            }
+
+            //鍒犻櫎
+            //deviceMenu = Language.StringByID(R.MyInternationalizationString.uDelete);
+            //frame.AddRowMenu(deviceMenu, "Item/DeleteIcon2.png", "Item/DeleteIcon2Selected.png", () =>
+            //{
+            //});
+        }
+
+        #endregion
+
+        #region 鈻� 骞叉帴鐐瑰姛鑳絖________________________
+
+        /// <summary>
+        /// 娣诲姞骞叉帴鐐瑰姛鑳借
+        /// </summary>
+        /// <param name="listRelayInfo7">3璺户鐢靛櫒鎴栬��1璺皟鍏夊櫒绗竷鍥炶矾鐨勯厤缃俊鎭�</param>
+        private void AddDryContactFunctionRow(List<CommonDevice.AttributeDataObj> listRelayInfo7)
+        {
+            //骞叉帴鐐瑰姛鑳�
+            string caption = Language.StringByID(R.MyInternationalizationString.uDryContactFunction);
+            //榛樿涓猴細閫氱敤骞叉帴鐐�
+            string strType = Language.StringByID(R.MyInternationalizationString.uCommonDryContact);
+            var btnFunction = new FrameCaptionViewControl(caption, strType, listview.rowSpace / 2);
+            btnFunction.UseClickStatu = false;
+            listview.AddChidren(btnFunction);
+            btnFunction.InitControl();
+            //搴曠嚎
+            btnFunction.AddBottomLine();
+
+            //濡傛灉鏄�3璺户鐢靛櫒鎴栬��1璺皟鍏夊櫒,骞朵笖鏄涓冨洖璺殑鏃跺��,瀹冨ソ鍍忓彲浠ユ敼鍙樼被鍨�
+            if (listRelayInfo7 != null)
+            {
+                //鍙崇澶�
+                btnFunction.AddRightArrow();
+
+                int nowSelectNo = 1;
+                foreach (var data in listRelayInfo7)
+                {
+                    if (data.AttributeId == (int)AttriButeId.HdlKey && data.AttriButeData == 65535)
+                    {
+                        //鏈�65535鍗冲畠鏄紶鎰熷櫒杈撳嚭
+                        nowSelectNo = 0;
+                        btnFunction.Text = Language.StringByID(R.MyInternationalizationString.uSensorInput);
+                        break;
+                    }
+                }
+
+                btnFunction.ButtonClickEvent += (sender, e) =>
+                {
+                    //鏄剧ず鍒楄〃
+                    var listText = new List<string>();
+                    listText.Add(Language.StringByID(R.MyInternationalizationString.uSensorInput));//浼犳劅鍣ㄨ緭鍏�
+                    listText.Add(Language.StringByID(R.MyInternationalizationString.uCommonDryContact));//閫氱敤骞叉帴鐐�
+                    //鏍囬:閫夋嫨骞叉帴鐐瑰姛鑳�
+                    var title = Language.StringByID(R.MyInternationalizationString.uSelectDryContactFunction);
+
+                    var form = new BottomItemSelectForm();
+                    form.AddForm(title, listText, nowSelectNo);
+                    form.FinishSelectEvent += async (selectNo) =>
+                    {
+                        if (selectNo == nowSelectNo)
+                        {
+                            //鐩稿悓,涓嶉渶瑕佸鐞�
+                            return;
+                        }
+                        //榛樿涓洪�氱敤骞叉帴鐐�  102:寮�鍏冲垏鎹�
+                        int value = 102;
+                        if (selectNo == 0)
+                        {
+                            //閫夋嫨鐨勬槸浼犳劅鍣ㄨ緭鍏�
+                            value = 65535;
+                        }
+                        var result = await HdlDevicePanelLogic.Current.EditorDryContactThirdFunction((Panel)nowSelectDevice, value);
+                        if (result == true)
+                        {
+                            //閲嶆柊鍒濆鍖栬彍鍗曡,闅愯棌鎴栬�呭紑鏀剧粦瀹氱洰鏍囪彍鍗�
+                            this.InitMenuRow();
+                        }
+                    };
+                };
+            }
+        }
+
+        #endregion
+
+        #region 鈻� 缁戝畾鐩爣___________________________
+
+        /// <summary>
+        /// 娣诲姞缁戝畾鐩爣琛�
+        /// </summary>
+        /// <param name="listRelayInfo7">3璺户鐢靛櫒鎴栬��1璺皟鍏夊櫒绗竷鍥炶矾鐨勯厤缃俊鎭�</param>
+        private void AddBindRow(List<CommonDevice.AttributeDataObj> listRelayInfo7)
+        {
+            if (nowSelectDevice.Type == DeviceType.OnOffSwitch)
+            {
+                //濡傛灉鏄�3璺户鐢靛櫒鎴栬��1璺皟鍏夊櫒,骞朵笖鏄涓冨洖璺殑鏃跺��
+                //濡傛灉瀹冪殑绫诲瀷涓猴細浼犳劅鍣ㄨ緭鍑虹殑鏃跺��,灏变笉瀛樺湪缁戝畾鐩爣杩欎釜姒傚康
+                if (listRelayInfo7 != null)
+                {
+                    foreach (var data in listRelayInfo7)
+                    {
+                        if (data.AttributeId == (int)AttriButeId.HdlKey && data.AttriButeData == 65535)
+                        {
+                            //鏈�65535鍗冲畠鏄紶鎰熷櫒杈撳嚭
+                            return;
+                        }
+                    }
+                }
+
+                string caption = Language.StringByID(R.MyInternationalizationString.uBindTargets);
+                var btnBind = new FrameRowControl(listview.rowSpace / 2);
+                listview.AddChidren(btnBind);
+                btnBind.AddLeftCaption(caption, 600);
+                //搴曠嚎
+                btnBind.AddBottomLine();
+                //鍙崇澶�
+                btnBind.AddRightArrow();
+                btnBind.ButtonClickEvent += (sender, e) =>
+                {
+                    var panel = nowSelectDevice as ZigBee.Device.Panel;
+                    var bindTargetsPage = new Shared.Phone.UserCenter.DeviceBind.BindTargetsPage(panel);
+                    Shared.Phone.UserView.HomePage.Instance.AddChidren(bindTargetsPage);
+                    Shared.Phone.UserView.HomePage.Instance.PageIndex += 1;
+                    bindTargetsPage.Show();
+                };
+            }
+        }
+
+        #endregion
+
+        #region 鈻� 鑳屽厜鐏痏____________________________
+
+        /// <summary>
+        /// 娣诲姞鑳屽厜鐏
+        /// </summary>
+        private void AddBackLightRow()
+        {
+            //涓夎矾缁х數鍣�,鎴栬�呬竴璺皟鍏夊櫒 鐨勬椂鍊欐墠鑳藉紑鍚閫夐」
+            var listDevice = Common.LocalDevice.Current.GetDevicesByMac(deviceObj.DeviceAddr);
+            var myType = Common.LocalDevice.Current.GetMyDeviceEnumInfo(listDevice);
+
+            if (myType.ConcreteType == DeviceConcreteType.Relay_ThreeLoad
+                || myType.ConcreteType == DeviceConcreteType.DimmableLight_OneLoad)
+            {
+                //鑳屽厜鐏�
+                string caption = Language.StringByID(R.MyInternationalizationString.uBackLight);
+                var btnLight = new FrameRowControl(listview.rowSpace / 2);
+                listview.AddChidren(btnLight);
+                btnLight.AddLeftCaption(caption, 600);
+                //搴曠嚎
+                btnLight.AddBottomLine();
+                //鍙崇澶�
+                btnLight.AddRightArrow();
+                btnLight.ButtonClickEvent += (sender, e) =>
+                {
+                    var form = new DeviceRelay.RelayThreeLoadBackLightSettionForm();
+                    form.AddForm(deviceObj.DeviceAddr);
+                };
+            }
+        }
+
+        #endregion
+
+        #region 鈻� 鍒濆鍖栬澶囧洖璺浘鏍嘷________________
+
+        /// <summary>
+        /// 鍒濆鍖栬澶囧洖璺浘鏍�
+        /// </summary>
+        private void InitDeviceEpointIcon(VerticalFrameControl listBackControl)
+        {
+            //鑾峰彇鎸夌粍鍒嗛厤鐨勮澶�
+            var listIcon = this.GetAllDeviceGroup();
+
+            var frameBorder = new FrameLayout();
+            frameBorder.Y = Application.GetRealHeight(81);
+            frameBorder.Gravity = Gravity.CenterHorizontal;
+            frameBorder.Width = Application.GetRealWidth(887);
+            frameBorder.Height = Application.GetRealHeight(423);
+            frameBorder.Radius = (uint)Application.GetRealHeight(6);
+            listBackControl.frameTable.AddChidren(frameBorder);
+
+            var frameBack = new FrameLayout();
+            frameBack.Height = frameBorder.Height;
+
+            if (listIcon.Count > 2)
+            {
+                //闇�瑕佹粦鍔ㄦ帶浠�
+                var listControl = new VerticalScrolViewLayout();
+                listControl.Height = frameBorder.Height;
+                listBackControl.frameTable.AddChidren(listControl);
+
+                listControl.AddChidren(frameBack);
+            }
+            else
+            {
+                //涓嶉渶瑕佹粦鍔ㄦ帶浠�
+                frameBorder.AddChidren(frameBack);
+            }
+
+            int index = 0;
+            for (int i = 0; i < listIcon.Count; i++)
+            {
+                var frame = new FrameLayout();
+                frame.Width = this.GetPictrueRealSize(887);
+                frame.Height = this.GetPictrueRealSize(124);
+                frameBack.AddChidren(frame);
+                //鍒濆鍖栦竴琛岃澶囧浘鏍�
+                this.InitDeviceIconFrame(frame, listIcon[i], ref index);
+
+                if (listIcon.Count == 1)
+                {
+                    frame.Gravity = Gravity.CenterVertical;
+                }
+                else
+                {
+                    frame.Y = this.GetPictrueRealSize(58) + (frameBack.ChildrenCount - 1) * (frame.Height + this.GetPictrueRealSize(60));
+                }
+            }
+
+            if (listIcon.Count > 2)
+            {
+                //璁$畻鐪熷疄楂樺害
+                int realHeight = this.GetPictrueRealSize(58 + 58) + (frameBack.ChildrenCount - 1) * this.GetPictrueRealSize(124 + 60);
+                if (realHeight > frameBack.Height)
+                {
+                    //鍙樻洿楂樺害
+                    frameBack.Height = realHeight;
+                }
+            }
+        }
+
+        /// <summary>
+        /// 鍒濆鍖栦竴琛岃澶囧浘鏍�
+        /// </summary>
+        /// <param name="frame"></param>
+        /// <param name="listDevice"></param>
+        /// <param name="index"></param>
+        /// <returns></returns>
+        private void InitDeviceIconFrame(FrameLayout frame, List<CommonDevice> listDevice, ref int index)
+        {
+            NormalViewControl btnTemp = null;
+            //闂磋窛
+            int space = this.GetPictrueRealSize(84);
+            int defultXX = (frame.Width - frame.Height * listDevice.Count - (listDevice.Count - 1) * space) / 2;
+            for (int i = 0; i < listDevice.Count; i++)
+            {
+                index++;
+                var btnIcon = new NormalViewControl(frame.Height, frame.Height, false);
+                btnIcon.Name = "btn" + listDevice[i].DeviceEpoint;
+                btnIcon.X = defultXX + i * (frame.Height + space);
+                btnIcon.Radius = (uint)frame.Height / 2;
+                btnIcon.BorderWidth = 2;
+                btnIcon.BorderColor = 0xff979797;
+                btnIcon.TextAlignment = TextAlignment.Center;
+                btnIcon.TextColor = UserCenterColor.Current.TextGrayColor3;
+                btnIcon.TextSize = 13;
+                btnIcon.Text = "Dry" + index;
+                frame.AddChidren(btnIcon);
+                //鐐瑰嚮浜嬩欢
+                btnIcon.ButtonClickEvent += this.DeviceEpointSelectEvent;
+
+                if (listDevice[i].DeviceEpoint == deviceObj.DeviceEpoint)
+                {
+                    btnTemp = btnIcon;
+                }
+            }
+            if (btnTemp != null)
+            {
+                //鍒濆鍖栬彍鍗曡
+                this.DeviceEpointSelectEvent(btnTemp, null);
+            }
+        }
+
+        /// <summary>
+        /// 鑾峰彇鎸夌粍鍒嗛厤鐨勮澶�
+        /// </summary>
+        /// <returns></returns>
+        private List<List<CommonDevice>> GetAllDeviceGroup()
+        {
+            bool hadDevice = false;
+            var listDevice = Common.LocalDevice.Current.GetDevicesByMac(deviceObj.DeviceAddr);
+            var listRelay = new List<CommonDevice>();
+            foreach (var device in listDevice)
+            {
+                if (device.Type == DeviceType.OnOffSwitch)
+                {
+                    //鍙骞叉帴鐐�
+                    listRelay.Add(device);
+                    if (device.DeviceEpoint == deviceObj.DeviceEpoint)
+                    {
+                        //鑳藉鍖归厤寰楀埌杩欎釜鍥炶矾
+                        hadDevice = true;
+                    }
+                }
+            }
+            //鎺掑簭
+            listRelay.Sort((obj1, obj2) =>
+            {
+                if (obj1.DeviceEpoint > obj2.DeviceEpoint)
+                {
+                    return 1;
+                }
+                return -1;
+            });
+            if (hadDevice == false)
+            {
+                //濡傛灉鍖归厤涓嶅埌杩欎釜鍥炶矾,鍒欓粯璁ょ涓�涓�
+                this.deviceObj = listRelay[0];
+            }
+
+            //浠庝笅寰�涓�4涓负涓�缁�
+            var listIcon = new List<List<CommonDevice>>();
+            var listTemp = new List<CommonDevice>();
+            for (int i = listRelay.Count - 1; i >= 0; i--)
+            {
+                listTemp.Insert(0, listRelay[i]);
+                if (listTemp.Count == 4)
+                {
+                    listIcon.Insert(0, listTemp);
+                    listTemp = new List<CommonDevice>();
+                }
+            }
+            if (listTemp.Count > 0)
+            {
+                listIcon.Insert(0, listTemp);
+            }
+            return listIcon;
+        }
+
+        #endregion
+
+        #region 鈻� 鍥炶矾閫夋嫨___________________________
+
+        /// <summary>
+        /// 鍥炶矾閫夋嫨浜嬩欢
+        /// </summary>
+        /// <param name="sender"></param>
+        /// <param name="e"></param>
+        private void DeviceEpointSelectEvent(object sender, MouseEventArgs e)
+        {
+            var nowContr = (NormalViewControl)sender;
+            if (nowSelectControl != null)
+            {
+                //鍚屼竴涓笢瑗�,涓嶉笩浠�
+                if (nowSelectControl.Name == nowContr.Name)
+                {
+                    return;
+                }
+                //涓嶉�夋嫨鐘舵��
+                nowSelectControl.BorderColor = 0xff979797;
+                nowSelectControl.TextSize = 13;
+                nowSelectControl.TextColor = UserCenterColor.Current.TextGrayColor3;
+                //璁板綍瀹冪殑鍚嶅瓧
+                dicDeviceSaveName[nowSelectDevice.DeviceEpoint] = btnDeviceName.Text.Trim();
+            }
+            //閫夋嫨鐘舵��
+            nowContr.BorderColor = 0xfffb744a;
+            nowContr.TextSize = 14;
+            nowContr.TextColor = UserCenterColor.Current.TextColor1;
+
+            nowSelectControl = nowContr;
+            nowSelectDevice = Common.LocalDevice.Current.GetDevice(deviceObj.DeviceAddr, Convert.ToInt32(nowContr.Name.Replace("btn", string.Empty)));
+
+            //閲嶆柊鍒濆鍖栬彍鍗曡
+            this.InitMenuRow();
+        }
+
+        #endregion
+    }
+}

--
Gitblit v1.8.0