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/Panel/PanelFangyueButtonSettionForm.cs | 599 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 599 insertions(+), 0 deletions(-) diff --git a/ZigbeeApp/Shared/Phone/UserCenter/Device/Panel/PanelFangyueButtonSettionForm.cs b/ZigbeeApp/Shared/Phone/UserCenter/Device/Panel/PanelFangyueButtonSettionForm.cs new file mode 100755 index 0000000..225a2aa --- /dev/null +++ b/ZigbeeApp/Shared/Phone/UserCenter/Device/Panel/PanelFangyueButtonSettionForm.cs @@ -0,0 +1,599 @@ +锘縰sing Shared.Common; +using System; +using System.Collections.Generic; +using System.Text; +using ZigBee.Device; + +namespace Shared.Phone.UserCenter.DevicePanel +{ + /// <summary> + /// 鏂规偊闈㈡澘鐨勬寜閿缃晫闈� + /// </summary> + public class PanelFangyueButtonSettionForm : 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 InformationEditorControl tableContr = null; + + #endregion + + #region 鈻� 鍒濆鍖朹____________________________ + + /// <summary> + /// 鐢婚潰鏄剧ず(搴曞眰浼氬浐瀹氳皟鐢ㄦ鏂规硶锛屽�熶互瀹屾垚鐢婚潰鍒涘缓) + /// </summary> + /// <param name="i_device">璁惧鐨勬煇涓�鍥炶矾</param> + public void ShowForm(CommonDevice i_device) + { + this.deviceObj = i_device; + + //璁剧疆澶撮儴淇℃伅 + base.SetTitleText(Language.StringByID(R.MyInternationalizationString.uPanelSettion)); + + //鍒濆鍖栦腑閮ㄤ俊鎭� + 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), 1028); + + //鍒濆鍖栬澶囧洖璺浘鏍� + 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 void InitMenuRow() + { + this.listview.RemoveAll(); + + string nameValue = Common.LocalDevice.Current.GetDeviceEpointName(nowSelectDevice); + if (dicDeviceSaveName.ContainsKey(nowSelectDevice.DeviceEpoint) == true) + { + nameValue = dicDeviceSaveName[nowSelectDevice.DeviceEpoint]; + } + + //鎸夐敭澶囨敞 + string caption = Language.StringByID(R.MyInternationalizationString.uPanelButtonNote); + 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.uPanelButtonReNoteSuccess); + 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); + }; + + //娣诲姞缁戝畾鐩爣琛� + this.AddBindRow(); + //娣诲姞鑳屽厜鐏 + 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() + { + var frame = new TopRightMenuControl(1, 1); + //瀹氫綅 + var deviceMenu = Language.StringByID(R.MyInternationalizationString.uFixedPosition); + frame.AddRowMenu(deviceMenu, "Item/FixedPosition.png", "Item/FixedPositionSelected.png", () => + { + //鍙戦�佸畾浣嶅姛鑳� + Common.LocalDevice.Current.SetFixedPositionCommand(nowSelectDevice); + }); + } + + #endregion + + #region 鈻� 缁戝畾鐩爣___________________________ + + /// <summary> + /// 娣诲姞缁戝畾鐩爣琛� + /// </summary> + private void AddBindRow() + { + if (nowSelectDevice.Type == DeviceType.OnOffSwitch) + { + 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() + { + //娌充笢璁惧鎵嶄細寮�鍚閫夐」 + if (Common.LocalDevice.Current.IsHdlDevice(nowSelectDevice) == true) + { + //鑳屽厜鐏� + 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) => + { + List<CommonDevice> listNewDevice = new List<CommonDevice> { }; + listNewDevice.Add((Panel)nowSelectDevice); + var deviceEnumInfo = Common.LocalDevice.Current.GetMyDeviceEnumInfo(listNewDevice); + //濡傛灉璁惧鏄柟鎮﹀紑鎺ц澶囷紝鑳屽厜鐏〉闇�瑕佹粦鍔ㄤ笖鏈夋帴杩戞劅搴斿姛鑳� + if (deviceEnumInfo.ConcreteType == DeviceConcreteType.ButtonPanel_FangyueTwo + || deviceEnumInfo.ConcreteType == DeviceConcreteType.ButtonPanel_FangyueFour + || deviceEnumInfo.ConcreteType == DeviceConcreteType.ButtonPanel_FangyueEight) + { + var form = new PanelBackLighWithSensorForm(); + form.AddForm((Panel)nowSelectDevice); + } + else + { + //涓嶅甫鎺ヨ繎鎰熷簲鐨� + var form = new PanelBackLightSettionForm(); + form.AddForm((Panel)nowSelectDevice); + } + }; + } + } + + #endregion + + #region 鈻� 鍒濆鍖栬澶囧洖璺浘鏍嘷________________ + + /// <summary> + /// 鍒濆鍖栬澶囧洖璺浘鏍� + /// </summary> + private void InitDeviceEpointIcon(VerticalFrameControl listBackControl) + { + bool hadDevice = false; + var listDevice = Common.LocalDevice.Current.GetDevicesByMac(deviceObj.DeviceAddr); + var listOffSwitch = new List<CommonDevice>(); + foreach (var device in listDevice) + { + if (device.Type == DeviceType.OnOffSwitch) + { + //鍙骞叉帴鐐� + listOffSwitch.Add(device); + if (device.DeviceEpoint == deviceObj.DeviceEpoint) + { + //鑳藉鍖归厤寰楀埌杩欎釜鍥炶矾 + hadDevice = true; + } + } + } + //鎺掑簭 + listOffSwitch.Sort((obj1, obj2) => + { + if (obj1.DeviceEpoint > obj2.DeviceEpoint) + { + return 1; + } + return -1; + }); + if (hadDevice == false) + { + //濡傛灉鍖归厤涓嶅埌杩欎釜鍥炶矾,鍒欓粯璁ょ涓�涓� + this.deviceObj = listOffSwitch[0]; + } + + var frameBorder = new FrameLayout(); + frameBorder.Y = Application.GetRealHeight(150); + frameBorder.Gravity = Gravity.CenterHorizontal; + frameBorder.Width = this.GetPictrueRealSize(426); + frameBorder.Height = this.GetPictrueRealSize(426); + listBackControl.frameTable.AddChidren(frameBorder); + + var btnPic = new PicViewControl(frameBorder.Width, frameBorder.Height, false); + + frameBorder.AddChidren(btnPic); + + if (listOffSwitch.Count == 8) + { + //鍏寜閿潰鏉� + btnPic.UnSelectedImagePath = "DeviceItem/PanelFangyueEightButtonTable.png"; + this.InitEightButtonPanelIcon(frameBorder, listOffSwitch); + } + else if (listOffSwitch.Count == 4) + { + //鍥涙寜閿潰鏉� + btnPic.UnSelectedImagePath = "DeviceItem/PanelFangyueFourButtonTable.png"; + this.InitFourButtonPanelIcon(frameBorder, listOffSwitch); + } + else + { + //浜屾寜閿潰鏉� + btnPic.UnSelectedImagePath = "DeviceItem/PanelFangyueTwoButtonTable.png"; + this.InitTwoButtonPanelIcon(frameBorder, listOffSwitch); + } + } + + /// <summary> + /// 鍒濆鍖栨寜閽帶浠� + /// </summary> + /// <param name="frame">瀹瑰櫒</param> + /// <param name="device">璁惧瀵硅薄</param> + /// <returns></returns> + private NormalViewControl InitDeviceButtonControl(FrameLayout frame, CommonDevice device) + { + var btnIcon = new NormalViewControl(this.GetPictrueRealSize(52), this.GetPictrueRealSize(52), false); + btnIcon.Text = "Button" + device.DeviceEpoint; + btnIcon.TextAlignment = TextAlignment.Center; + btnIcon.TextColor = UserCenterColor.Current.TextGrayColor1; + if (frame is FrameLayoutStatuControl) + { + ((FrameLayoutStatuControl)frame).AddChidren(btnIcon, ChidrenBindMode.BindEventOnly); + ((FrameLayoutStatuControl)frame).ButtonClickEvent += (sender, e) => + { + //鎸夐敭鐐瑰嚮 + this.DeviceEpointSelectEvent(btnIcon, null); + }; + } + else + { + frame.AddChidren(btnIcon); + //鐐瑰嚮浜嬩欢 + btnIcon.ButtonClickEvent += (sender, e) => + { + //鎸夐敭鐐瑰嚮 + this.DeviceEpointSelectEvent(btnIcon, null); + }; + } + + if (device.DeviceEpoint == deviceObj.DeviceEpoint) + { + //鍒濆鍖栬彍鍗曡 + this.DeviceEpointSelectEvent(btnIcon, null); + } + return btnIcon; + } + + #endregion + + #region 鈻� 鍒濆鍖栦簩鎸夐敭鍥炬爣___________________ + + /// <summary> + /// 鍒濆鍖栦簩鎸夐敭闈㈡澘鐨勫浘鏍� + /// </summary> + /// <param name="frameBack">瀹瑰櫒</param> + /// <param name="listDevice">璁惧鍒楄〃</param> + private void InitTwoButtonPanelIcon(FrameLayout frameBack, List<CommonDevice> listDevice) + { + //鎸夐敭1 + var btnButton1 = this.InitDeviceButtonControl(frameBack, listDevice[0]); + btnButton1.Height = this.GetPictrueRealSize(175); + btnButton1.Width = this.GetPictrueRealSize(361); + btnButton1.Y = this.GetPictrueRealSize(39); + btnButton1.Gravity = Gravity.CenterHorizontal; + + //鎸夐敭2 + var btnButton2 = this.InitDeviceButtonControl(frameBack, listDevice[1]); + btnButton2.Height = this.GetPictrueRealSize(175); + btnButton2.Width = this.GetPictrueRealSize(361); + btnButton2.Y = btnButton1.Bottom; + btnButton2.Gravity = Gravity.CenterHorizontal; + } + + #endregion + + #region 鈻� 鍒濆鍖栧洓鎸夐敭鍥炬爣___________________ + + /// <summary> + /// 鍒濆鍖栧洓鎸夐敭闈㈡澘鐨勫浘鏍� + /// </summary> + /// <param name="frameBack">瀹瑰櫒</param> + /// <param name="listDevice">璁惧鍒楄〃</param> + private void InitFourButtonPanelIcon(FrameLayout frameBack, List<CommonDevice> listDevice) + { + //鎸夐敭1 + var btnButton1 = this.InitDeviceButtonControl(frameBack, listDevice[0]); + btnButton1.TextSize = 12; + btnButton1.Height = this.GetPictrueRealSize(175); + btnButton1.Width = this.GetPictrueRealSize(183); + btnButton1.X = this.GetPictrueRealSize(34); + btnButton1.Y = this.GetPictrueRealSize(30); + + //鎸夐敭2 + var btnButton2 = this.InitDeviceButtonControl(frameBack, listDevice[1]); + btnButton2.TextSize = 12; + btnButton2.Height = this.GetPictrueRealSize(175); + btnButton2.Width = this.GetPictrueRealSize(183); + btnButton2.X = btnButton1.Right; + btnButton2.Y = btnButton1.Y; + + //鎸夐敭3 + var btnButton3 = this.InitDeviceButtonControl(frameBack, listDevice[2]); + btnButton3.TextSize = 12; + btnButton3.Height = this.GetPictrueRealSize(175); + btnButton3.Width = this.GetPictrueRealSize(183); + btnButton3.X = btnButton1.X; + btnButton3.Y = btnButton1.Bottom + this.GetPictrueRealSize(4); + + //鎸夐敭4 + var btnButton4 = this.InitDeviceButtonControl(frameBack, listDevice[3]); + btnButton4.TextSize = 12; + btnButton4.Height = this.GetPictrueRealSize(175); + btnButton4.Width = this.GetPictrueRealSize(183); + btnButton4.X = btnButton2.X; + btnButton4.Y = btnButton3.Y; + } + + #endregion + + #region 鈻� 鍒濆鍖栧叓鎸夐敭鍥炬爣___________________ + + /// <summary> + /// 鍒濆鍖栧叓鎸夐敭闈㈡澘鐨勫浘鏍� + /// </summary> + /// <param name="frameBack">瀹瑰櫒</param> + /// <param name="listDevice">璁惧鍒楄〃</param> + private void InitEightButtonPanelIcon(FrameLayout frameBack, List<CommonDevice> listDevice) + { + //鎸夐敭1锝炴寜閿�2 + var frame1 = new FrameLayout(); + frame1.X = this.GetPictrueRealSize(34); + frame1.Y = this.GetPictrueRealSize(30); + frame1.Height = this.GetPictrueRealSize(183); + frame1.Width = this.GetPictrueRealSize(183); + frameBack.AddChidren(frame1); + this.InitEightButtonPanelIcon(frame1, listDevice[0], listDevice[1]); + + //鎸夐敭3锝炴寜閿�4 + var frame2 = new FrameLayout(); + frame2.X = frame1.Right; + frame2.Y = frame1.Y; + frame2.Height = frame1.Height; + frame2.Width = frame1.Width; + frameBack.AddChidren(frame2); + this.InitEightButtonPanelIcon(frame2, listDevice[2], listDevice[3]); + + //鎸夐敭5锝炴寜閿�6 + var frame3 = new FrameLayout(); + frame3.X = frame1.X; + frame3.Y = frame1.Bottom + this.GetPictrueRealSize(4); + frame3.Height = frame1.Height; + frame3.Width = frame1.Width; + frameBack.AddChidren(frame3); + this.InitEightButtonPanelIcon(frame3, listDevice[4], listDevice[5]); + + //鎸夐敭7锝炴寜閿�8 + var frame4 = new FrameLayout(); + frame4.X = frame1.Right; + frame4.Y = frame1.Bottom + this.GetPictrueRealSize(4); + frame4.Height = frame1.Height; + frame4.Width = frame1.Width; + frameBack.AddChidren(frame4); + this.InitEightButtonPanelIcon(frame4, listDevice[6], listDevice[7]); + } + + /// <summary> + /// 鍒濆鍖栧叓鎸夐敭闈㈡澘鐨勫浘鏍� + /// </summary> + /// <param name="frameBack">瀹瑰櫒</param> + /// <param name="device1">璁惧1</param> + /// <param name="device2">璁惧2</param> + private void InitEightButtonPanelIcon(FrameLayout frameBack, CommonDevice device1, CommonDevice device2) + { + //鎸夐敭1 + var frameButton1 = new FrameLayoutStatuControl(); + frameButton1.UseClickStatu = false; + frameButton1.Height = this.GetPictrueRealSize(92); + frameButton1.Width = this.GetPictrueRealSize(183); + frameBack.AddChidren(frameButton1); + var btnButton1 = this.InitDeviceButtonControl(frameButton1, device1); + btnButton1.TextSize = 10; + btnButton1.Height = this.GetPictrueRealSize(35); + btnButton1.Width = this.GetPictrueRealSize(183); + btnButton1.Y = this.GetPictrueRealSize(37); + + //鎸夐敭2 + var frameButton2 = new FrameLayoutStatuControl(); + frameButton2.UseClickStatu = false; + frameButton2.Height = frameButton1.Height; + frameButton2.Width = frameButton1.Width; + frameButton2.Y = frameButton1.Bottom; + frameBack.AddChidren(frameButton2); + var btnButton2 = this.InitDeviceButtonControl(frameButton2, device2); + btnButton2.TextSize = 10; + btnButton2.Height = btnButton1.Height; + btnButton2.Width = btnButton1.Width; + btnButton2.Y = this.GetPictrueRealSize(20); + } + + #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.Text == nowContr.Text) + { + return; + } + //涓嶉�夋嫨鐘舵�� + nowSelectControl.TextColor = UserCenterColor.Current.TextGrayColor1; + //璁板綍瀹冪殑鍚嶅瓧 + dicDeviceSaveName[nowSelectDevice.DeviceEpoint] = btnDeviceName.Text.Trim(); + } + //閫夋嫨鐘舵�� + nowContr.TextColor = 0xfffb744a; + + nowSelectControl = nowContr; + nowSelectDevice = Common.LocalDevice.Current.GetDevice(deviceObj.DeviceAddr, Convert.ToInt32(nowContr.Text.Replace("Button", string.Empty))); + + //閲嶆柊鍒濆鍖栬彍鍗曡 + this.InitMenuRow(); + } + + #endregion + } +} -- Gitblit v1.8.0