From f71e74b5f0d2716fbf05da016cdaa18d64e09f80 Mon Sep 17 00:00:00 2001 From: xm <1271024303@qq.com> Date: 星期四, 31 十二月 2020 17:01:18 +0800 Subject: [PATCH] 又换完成最新门锁。空气质量传感器完成数据和基本配置功能。开发图表和自动化的同事可下载此代码 --- ZigbeeApp/Shared/Phone/Category/Controls/DeviceRow/Base/DeviceRowCommon.cs | 1188 +++++++++++++++++++++++++++++----------------------------- 1 files changed, 595 insertions(+), 593 deletions(-) diff --git a/ZigbeeApp/Shared/Phone/Category/Controls/DeviceRow/Base/DeviceRowCommon.cs b/ZigbeeApp/Shared/Phone/Category/Controls/DeviceRow/Base/DeviceRowCommon.cs old mode 100755 new mode 100644 index 8966fec..b822e12 --- a/ZigbeeApp/Shared/Phone/Category/Controls/DeviceRow/Base/DeviceRowCommon.cs +++ b/ZigbeeApp/Shared/Phone/Category/Controls/DeviceRow/Base/DeviceRowCommon.cs @@ -5,599 +5,601 @@ using ZigBee.Device; namespace Shared.Phone.Category.Controls -{ +{ + /// <summary> + /// 鍒嗙被鐨勮澶囪鎺т欢搴曞眰鍏遍�� + /// </summary> + public class DeviceRowCommon : RowLayoutControl + { + #region 鈻� 鍙橀噺澹版槑___________________________ + /// <summary> - /// 鍒嗙被鐨勮澶囪鎺т欢搴曞眰鍏遍�� + /// 鏄惁鎷ユ湁鐘舵�佸姛鑳�(榛樿鎷ユ湁) /// </summary> - public class DeviceRowCommon : RowLayoutControl - { - #region 鈻� 鍙橀噺澹版槑___________________________ - - /// <summary> - /// 鏄惁鎷ユ湁鐘舵�佸姛鑳�(榛樿鎷ユ湁) - /// </summary> - public bool hadStatuFunction = true; - /// <summary> - /// 鎺т欢闇�瑕佽绉婚櫎鐨勪簨浠� - /// </summary> - public Action RowNeedRemoveEvent = null; - /// <summary> - /// 璁惧瀵硅薄 - /// </summary> - public CommonDevice device; - /// <summary> - /// 璁惧鍥炬爣鑳屾櫙鎺т欢 - /// </summary> - private FrameLayout frameIconBackGroud = null; - /// <summary> - /// 璁惧鍥炬爣鎺т欢 - /// </summary> - private IconViewControl btnDeviceIcon = null; - /// <summary> - /// 璁惧鍚嶅瓧鎺т欢 - /// </summary> - private NormalViewControl btnDeviceName = null; - /// <summary> - /// 鐘舵�佹帶浠� - /// </summary> - private NormalViewControl btnStatu = null; - /// <summary> - /// 寮�鍏虫帶浠� - /// </summary> - private MostRightIconControl btnSwitch = null; - /// <summary> - /// 鐢垫睜鎺т欢 - /// </summary> - private IconViewControl btnBattery = null; - /// <summary> - /// 鏄惁鑾峰彇缃戝叧鍙嶉鐨勭粨鏋� 0:娌℃湁鑾峰彇寰楀埌 1:宸茬粡鑾峰彇寰楀埌 - /// </summary> - private int ResponeResult = 0; - /// <summary> - /// 鍒ゆ柇鏄惁鏈夊紑鍏冲姛鑳� - /// </summary> - private bool isHadOpenSwitch = true; - /// <summary> - /// 褰撳墠閫夋嫨鐨勬埧闂� - /// </summary> - public Common.Room nowSelectRoom = null; - - #endregion - - #region 鈻� 鍒濆鍖朹____________________________ - - /// <summary> - /// 鏈垎閰嶇晫闈㈢殑璁惧閫夋嫨鎺т欢 - /// </summary> - public DeviceRowCommon() - { - this.SetCornerWithSameRadius(Application.GetRealHeight(58), HDLUtils.RectCornerTopLeft); - this.Width = Application.GetRealWidth(1022); - } - - /// <summary> - /// 鍒濆鍖栨帶浠� - /// </summary> - /// <param name="i_device">璁惧瀵硅薄</param> - /// <param name="i_nowSelectRoom">褰撳墠閫夋嫨鐨勬埧闂�(鏈夌偣鐢ㄥ)</param> - public virtual void InitControl(CommonDevice i_device, Common.Room i_nowSelectRoom) - { - this.device = i_device; - this.nowSelectRoom = i_nowSelectRoom; - //璁惧鍥炬爣鑳屾櫙鎺т欢 - this.frameIconBackGroud = new FrameLayout(); - frameIconBackGroud.Height = this.GetPictrueRealSize(112); - frameIconBackGroud.Width = this.GetPictrueRealSize(112); - frameIconBackGroud.Gravity = Gravity.CenterVertical; - frameIconBackGroud.X = Application.GetRealWidth(46); - frameIconBackGroud.Radius = (uint)this.GetPictrueRealSize(112 / 2); - frameIconBackGroud.BackgroundColor = Common.ZigbeeColor.Current.GXCGrayBackgroundColor; - this.frameTable.AddChidren(frameIconBackGroud, ChidrenBindMode.NotBind); - if (chidrenYaxis != 0) - { - frameIconBackGroud.Y += chidrenYaxis; - } - - //璁惧鍥炬爣鎺т欢 - this.btnDeviceIcon = new IconViewControl(78); - btnDeviceIcon.Gravity = Gravity.Center; - Common.LocalDevice.Current.SetDeviceIconToControl(btnDeviceIcon, i_device); - frameIconBackGroud.AddChidren(btnDeviceIcon); - //閲嶆柊缁戝畾浜嬩欢 - this.frameTable.ChangedChidrenBindMode(frameIconBackGroud, ChidrenBindMode.BindEvent); - - //璁惧鍚嶅瓧 - this.btnDeviceName = new NormalViewControl(600, 60, true); - if (this.device.Type == DeviceType.WindowCoveringDevice) - { - //绐楀笜鍥犱负鍙宠竟鏈変笁涓寜閽�,鎵�浠ラ渶瑕佹墍鏈夊悕瀛楃殑瀹藉害 - this.btnDeviceName.Width = Application.GetRealWidth(360); - } - btnDeviceName.X = Application.GetRealWidth(181); - //褰撴寚瀹氬疄闄呭潗鏍囨椂,杩欓噷闇�瑕佺殑鍋忕Щ閲忎负2鍊� - btnDeviceName.Y = Application.GetRealHeight(16) + this.chidrenYaxis * 2; - btnDeviceName.Text = Common.LocalDevice.Current.GetDeviceEpointName(i_device); - btnDeviceName.SelectedTextColor = Common.ZigbeeColor.Current.GXCTextSelectedColor; - this.frameTable.AddChidren(btnDeviceName, ChidrenBindMode.BindEvent); - - if (this.hadStatuFunction == false) - { - //娌℃湁鐘舵�佸姛鑳�,鍒欐妸璁惧鍚嶅瓧鎺т欢涓� - this.btnDeviceName.Gravity = Gravity.CenterVertical; - btnDeviceName.Y += this.chidrenYaxis; - } - //鎷ユ湁鐘舵�佸姛鑳� - if (this.hadStatuFunction == true) - { - //鐘舵�� - this.btnStatu = new NormalViewControl(600, 50, true); - btnStatu.X = Application.GetRealWidth(181); - //褰撴寚瀹氬疄闄呭潗鏍囨椂,杩欓噷闇�瑕佺殑鍋忕Щ閲忎负2鍊� - btnStatu.Y = Application.GetRealHeight(70) + this.chidrenYaxis * 2; - btnStatu.TextSize = 10; - btnStatu.TextColor = UserCenterColor.Current.TextGrayColor1; - this.frameTable.AddChidren(btnStatu, ChidrenBindMode.BindEvent); - } - - //搴曠嚎 - var btnBottomLine = new NormalViewControl(Application.GetRealWidth(841), ControlCommonResourse.BottomLineHeight, false); - btnBottomLine.X = Application.GetRealWidth(181); - btnBottomLine.Y = this.Height - ControlCommonResourse.BottomLineHeight; - btnBottomLine.BackgroundColor = UserCenterColor.Current.ButtomLine; - this.frameTable.AddChidren(btnBottomLine, ChidrenBindMode.NotBind); - - //寮�鍏虫帶浠�(鏆傛椂涓嶅姞鍏ョ埗鎺т欢) - this.btnSwitch = new MostRightIconControl(69, 69); - btnSwitch.UnSelectedImagePath = "Item/Switch.png"; - btnSwitch.SelectedImagePath = "Item/SwitchSelected.png"; - - //鐢垫睜鎺т欢 - if (this.device.Type == DeviceType.IASZone) - { - this.btnBattery = new IconViewControl(69); - btnBattery.X = this.Width - Application.GetRealWidth(69 + 29); - btnBattery.UnSelectedImagePath = "Item/Battery.png"; - btnBattery.Gravity = Gravity.CenterVertical; - this.frameTable.AddChidren(btnBattery, ChidrenBindMode.BindEvent); - if (chidrenYaxis != 0) - { - btnBattery.Y += chidrenYaxis; - } - if (this.device.IsBatteryDown == false) - { - btnBattery.Visible = false; - } - } - - //鍒嗕韩鐨勬埧闂�,鍒欎笉鑳界紪杈戝拰鍒犻櫎 - if (this.nowSelectRoom.IsSharedRoom == false) - { - //缂栬緫 - var btnEditor = this.AddEditorControl(); - btnEditor.ButtonClickEvent += (sender, e) => - { - var detailInfo = new MainPage.DeviceDetailInfoForm(); - detailInfo.AddForm(i_device, this.nowSelectRoom); - detailInfo.FormCloseEvent += () => - { - if (this.nowSelectRoom.IsLove == true) - { - //褰撳墠鏄枩鐖辨埧闂存椂 - if (HdlRoomLogic.Current.IsCollectInRoom(this.device) == false) - { - //鍥炶皟鎺т欢琚Щ闄ょ殑浜嬩欢 - this.RowNeedRemoveEvent?.Invoke(); - //鎴块棿鏀瑰彉浜� - this.RemoveFromParent(); - return; - } - } - var curRoom = HdlRoomLogic.Current.GetRoomByDevice(this.device); - if (curRoom == null || this.nowSelectRoom.Id != curRoom.Id) - { - //鍥炶皟鎺т欢琚Щ闄ょ殑浜嬩欢 - this.RowNeedRemoveEvent?.Invoke(); - //鎴块棿鏀瑰彉浜� - this.RemoveFromParent(); - return; - } - //鍒锋柊鎺т欢鐘舵�� - this.RefreshControlInfo(i_device); - }; - }; - //鍒犻櫎 - var btnDelete = this.AddDeleteControl(); - btnDelete.ButtonClickEvent += (sender, e) => - { - //纭畾瑕佺Щ闄よ鍔熻兘锛� - var alert = new ShowMsgControl(ShowMsgType.Confirm, Language.StringByID(R.MyInternationalizationString.DeleteFunction)); - alert.Show(); - alert.ConfirmClickEvent += () => - { - //绉婚櫎鏀惰棌(涓嶇浠�涔堟儏鍐�,鏀惰棌閮借绉婚櫎) - HdlRoomLogic.Current.DeleteLoveDevice(i_device); - if (this.nowSelectRoom.IsLove == false) - { - //浠庢埧闂翠腑绉婚櫎 - HdlRoomLogic.Current.DeleteDevice(i_device); - } - //鍥炶皟鎺т欢琚Щ闄ょ殑浜嬩欢 - this.RowNeedRemoveEvent?.Invoke(); - this.RemoveFromParent(); - }; - }; - } - //鍒锋柊鎺т欢鐘舵�� - this.RefreshControlInfo(i_device); - } - - #endregion - - #region 鈻� 娣诲姞寮�鍏虫帶浠禵______________________ - - /// <summary> - /// 娣诲姞寮�鍏虫帶浠� - /// </summary> - /// <returns></returns> - public MostRightIconControl AddSwitchControl() - { - this.frameTable.AddChidren(this.btnSwitch, ChidrenBindMode.NotBind); - btnSwitch.InitControl(); - btnSwitch.X -= ControlCommonResourse.XXLeft; - btnSwitch.Y += this.chidrenYaxis; - - return btnSwitch; - } - - #endregion - - #region 鈻� 鍒锋柊鎺т欢鐘舵�乢______________________ - - /// <summary> - /// 鍒锋柊鎺т欢鐘舵�� - /// </summary> - /// <param name="i_device">璁惧瀵硅薄,涓嶆槸鎺ㄩ�佺殑閭d釜</param> - public virtual void RefreshControlInfo(CommonDevice i_device) - { - //璁惧鍥炬爣涔熷埛鏂� - Common.LocalDevice.Current.SetDeviceIconToControl(btnDeviceIcon, i_device); - //璁惧鍚嶅瓧 - this.btnDeviceName.Text = Common.LocalDevice.Current.GetDeviceEpointName(i_device); - //妫�娴嬭澶囨槸鍚︽槸鎵撳紑鐘舵�� - bool isOpen = this.CheckIsOpenStatu(i_device); - if (this.isHadOpenSwitch == true && i_device.HadReadDeviceStatu == false) - { - //濡傛灉杩欎釜鍗$墖鏈夊紑鍏冲姛鑳�,骞朵笖缃戝叧杩樻病鏈夊洖澶嶄箣鍓�,榛樿鏄叧闂姸鎬� - //绛夊緟缃戝叧鍥炲鍚庝細閲嶆柊鍒锋柊,涓嶇劧涓�鐩存槸鍏抽棴鐘舵�� - isOpen = false; - } - //濡傛灉鏄紶鎰熷櫒绫�,鍒欓粯璁ゆ槸鍏崇殑鏁堟灉 - if (this.device.Type == DeviceType.PMSensor || this.device.Type == DeviceType.IASZone - || this.device.Type == DeviceType.TemperatureSensor) - { - isOpen = false; - } - - this.SetRowOpenStatu(isOpen); - } - - /// <summary> - /// 璁剧疆琛屾帶浠剁殑鎵撳紑鎴栬�呭叧闂殑鐘舵�� - /// </summary> - /// <param name="isOpen"></param> - public void SetRowOpenStatu(bool isOpen) - { - //璁惧鐘舵�佸繀椤诲埛鏂� - if (this.btnStatu != null) - { - this.btnStatu.Text = HdlDeviceOtherLogic.Current.GetDeviceStatu(this.device); - } - //寮�鍏虫帶浠� - if (this.btnSwitch != null && this.btnSwitch.IsSelected != isOpen) - { - this.btnSwitch.IsSelected = isOpen; - } - //鍒囨崲鍗$墖鐘舵�佺壒鏁� - this.SwitchRowStatuAppeal(isOpen); - } - - /// <summary> - /// 璁剧疆琛屾帶浠剁殑鍦ㄧ嚎鐘舵�� - /// </summary> - /// <param name="isOnline">鍦ㄧ嚎</param> - public void SetRowOnlineStatu(bool isOnline) - { - if (this.isHadOpenSwitch == true) - { - //濡傛灉杩欎釜璁惧鏈夊紑鍏冲姛鑳�,鍒欏湪绾跨姸鎬佷笉浼氭敼鍙樼姸鎬� - return; - } - this.SetRowOpenStatu(isOnline); - } - - /// <summary> - /// 璁剧疆璁惧鐨勭姸鎬佹枃鏈� - /// </summary> - /// <param name="i_Text">鐘舵�佹枃鏈�</param> - public void SetDeviceStatuText(string i_Text) - { - if (this.btnStatu != null) - { - this.btnStatu.Text = i_Text; - } - } - - #endregion - - #region 鈻� 鍙戦�佽幏鍙栫姸鎬佸懡浠__________________ - - /// <summary> - /// 鍙戦�佽幏鍙栫姸鎬佸懡浠� - /// </summary> - public virtual void SendStatuComand() - { - return; - } - - #endregion - - #region 鈻� 妫�娴嬭澶囨墦寮�鐘舵�乢__________________ - - /// <summary> - /// 妫�娴嬭澶囨槸鍚︽槸鎵撳紑鐘舵�� - /// </summary> - /// <param name="i_device"></param> - /// <returns></returns> - public virtual bool CheckIsOpenStatu(CommonDevice i_device) - { - //濡傛灉杩欎釜鍑芥暟琚噸鍐欑殑璇�,鍒欎唬琛ㄨ繖涓澶囨湁寮�鍏冲姛鑳� - this.isHadOpenSwitch = false; - //榛樿鐢ㄥ湪绾跨姸鎬佹潵鍒ゆ柇 - return Common.LocalDevice.Current.CheckDeviceIsOnline(i_device); - } - - - #endregion - - #region 鈻� 娣卞害鍗$墖淇℃伅鐨勮繑鍥炰簨浠禵____________ - - /// <summary> - /// 娣卞害鍗$墖淇℃伅鐨勮繑鍥炰簨浠�(搴曞眰涓撶敤) - /// </summary> - /// <param name="device">璁惧</param> - public void CardDetailInfoBackEvent(CommonDevice device) - { - if (this.nowSelectRoom.IsLove == true) - { - //宸茬粡鍙栨秷鐨勬敹钘� - if (HdlRoomLogic.Current.IsCollectInRoom(device) == false) - { - //鍥炶皟鎺т欢琚Щ闄ょ殑浜嬩欢 - this.RowNeedRemoveEvent?.Invoke(); - //绉婚櫎杩欎釜鎺т欢 - this.RemoveFromParent(); - return; - } - } - else - { - //濡傛灉杩欎釜璁惧鏀瑰彉浜嗘埧闂寸殑璇�,鍥炶皟鍗$墖琚垹闄ょ殑鍑芥暟 - var nowRoom = HdlRoomLogic.Current.GetRoomByDevice(device); - if (nowRoom == null || nowRoom.Id != this.nowSelectRoom.Id) - { - //鍥炶皟鎺т欢琚Щ闄ょ殑浜嬩欢 - this.RowNeedRemoveEvent?.Invoke(); - //绉婚櫎杩欎釜鎺т欢 - this.RemoveFromParent(); - return; - } - } - //濡傛灉瀹冭繕鍦ㄨ繖涓埧闂寸殑璇�,鍒锋柊鍗$墖淇℃伅 - this.RefreshControlInfo(device); - } - - #endregion - - #region 鈻� 鏄惁鑾峰彇缃戝叧鍙嶉鐨勭粨鏋淿____________ - - /// <summary> - /// <para>妫�娴嬫槸鍚﹁幏鍙栫綉鍏冲弽棣堢殑缁撴灉,濡傛灉缃戝叧娌℃湁鍥炲,鍒欎細寮瑰嚭娑堟伅</para> - /// <para>鑾峰彇鍒板洖澶嶇粨鏋滀箣鍚�,璁板緱璋冪敤SetHadGetResponeResultStatu()鍑芥暟璁剧疆鐘舵��</para> - /// </summary> - /// <param name="oldOpenStatu">璁惧鐩墠鐨勫紑鍏崇姸鎬�</param> - public void StartCheckResponeResult(bool oldOpenStatu) - { - this.ResponeResult = 0; - HdlThreadLogic.Current.RunThread(() => - { - int waitime = 40; - while (waitime > 0) - { - System.Threading.Thread.Sleep(100); - if (this.ResponeResult == 1) - { - //宸茬粡鑾峰彇寰楀埌鏁版嵁 - break; - } - waitime--; - //2绉掔殑鏃跺��,杩樻槸鎺ュ彈涓嶅埌鐨勮瘽,寮哄埗鍐嶆鍒锋柊璁惧鐘舵�� - if (waitime == 20) - { - //浠庢柊鍙戦�佽幏鍙栬澶囩殑鐘舵��(寮哄埗) - this.device.HadReadDeviceStatu = false; - this.SendStatuComand(); - } - } - if (waitime <= 0 && this.Parent != null) - { - //娌℃湁鑾峰彇寰楀埌缁撴灉 - HdlThreadLogic.Current.RunMain(() => - { - var msgContr = new ShowMsgControl(ShowMsgType.Tip, Language.StringByID(R.MyInternationalizationString.FAIL)); - msgContr.Show(); - //鍙樻洿鍥炲師鏉ョ殑鐘舵�� - this.SetRowOpenStatu(oldOpenStatu); - }); - } - }); - } - - /// <summary> - /// 璁剧疆宸茬粡鑾峰彇鍒扮綉鍏崇殑鍙嶉缁撴灉 - /// </summary> - public void SetHadGetResponeResultStatu() - { - this.ResponeResult = 1; - } - - /// <summary> - /// 鎺ユ敹缃戝叧鍥炲鐨勭姸鎬�(true:宸茬粡鎺ユ敹鍒扮綉鍏崇殑鍥炲 false:杩樻病鏈夋帴鏀跺埌缃戝叧鍥炲) - /// </summary> - /// <returns></returns> - public bool ReceiveResponeResultStatu() - { - return this.ResponeResult == 1; - } - - #endregion - - #region 鈻� 鏄剧ず浣庣數閲廮________________________ - - /// <summary> - /// 鍒锋柊鐢垫睜鐢甸噺鐘舵�� - /// </summary> - public void RefreshBatteryStatu() - { - if (this.btnBattery == null) { return; } - if (this.device.IsBatteryDown == true) - { - //鐢甸噺浣�,鏄剧ず鍥炬爣 - if (this.btnBattery.Visible == false) - { - this.btnBattery.Visible = true; - } - } - else - { - //鐢甸噺瓒冲,闅愯棌鍥炬爣 - if (this.btnBattery.Visible == true) - { - this.btnBattery.Visible = false; - } - } - } - - #endregion - - #region 鈻� 涓�鑸柟娉昣__________________________ - - /// <summary> - /// 妫�娴嬭兘鍚﹀彂閫佽幏鍙栫姸鎬佸懡浠� - /// </summary> - /// <returns></returns> - public bool CheckCanSendStatuComand() - { - if (this.device.HadReadDeviceStatu == false) - { - //杩樻病鏈夎鍙栬繃鏁版嵁 - return true; - } - if ((DateTime.Now - this.device.LastDateTime).TotalMinutes >= 10) - { - //10鍒嗛挓鍚庡彲浠ュ啀娆¤幏鍙� - return true; - } - return false; - } - - #endregion - - #region 鈻� 琛岄棯鐑佺壒鏁坃________________________ - - /// <summary> - /// 鏄惁澶勪簬鐗规晥涓� - /// </summary> - private bool isAppeal = false; - /// <summary> - /// 寮�鍚闂儊鐗规晥 - /// </summary> - public void StartRowLightAppeal() - { - //璁惧鐘舵�佸繀椤诲埛鏂� - this.btnStatu.Text = HdlDeviceOtherLogic.Current.GetDeviceStatu(this.device); - - if (this.isAppeal == true) { return; } - this.isAppeal = true; - - HdlThreadLogic.Current.RunThread(() => - { - //闂儊5绉�,闂撮殧400姣 - int count = 5000 / 400; - bool isOpen = false; - while (this.Parent != null && count >= 0) - { - //闂儊鐗规晥 - HdlThreadLogic.Current.RunMain(() => - { - isOpen = !isOpen; - this.SwitchRowStatuAppeal(isOpen); - }); - System.Threading.Thread.Sleep(400); - count--; - } - if (this.Parent != null && isOpen == false) - { - HdlThreadLogic.Current.RunMain(() => - { - //缁撴潫鏃�,榛樿涓烘墦寮�鐗规晥 - this.SwitchRowStatuAppeal(true); - }, ShowErrorMode.NO); - } - this.isAppeal = false; - - }, ShowErrorMode.NO); - } - - /// <summary> - /// 鍒囨崲鍗$墖鐘舵�佺壒鏁� - /// </summary> - public void SwitchRowStatuAppeal(bool isOpen) - { - if (this.btnDeviceName.IsSelected == isOpen) - { - //鐘舵�佷竴鏍�,鍒欎笉闇�瑕佸鐞� - return; - } - //璁惧鍚嶇О鎺т欢 - this.btnDeviceName.IsSelected = isOpen; - this.btnDeviceName.IsBold = isOpen; - //璁惧鐨勮儗鏅渾鍦堝浘 - if (isOpen == true) - { - this.frameIconBackGroud.BackgroundColor = Common.ZigbeeColor.Current.GXCSelectedBackgroundColor; - } - else - { - this.frameIconBackGroud.BackgroundColor = Common.ZigbeeColor.Current.GXCGrayBackgroundColor; - } - //璁惧鍥炬爣鎺т欢 - this.btnDeviceIcon.IsSelected = isOpen; - } - - #endregion - - #region 鈻� 鎺т欢鎽ф瘉___________________________ - - /// <summary> - /// 鎺т欢鎽ф瘉 - /// </summary> - public override void RemoveFromParent() - { - this.RowNeedRemoveEvent = null; - - base.RemoveFromParent(); - } - - #endregion - } + public bool hadStatuFunction = true; + /// <summary> + /// 鎺т欢闇�瑕佽绉婚櫎鐨勪簨浠� + /// </summary> + public Action RowNeedRemoveEvent = null; + /// <summary> + /// 璁惧瀵硅薄 + /// </summary> + public CommonDevice device; + /// <summary> + /// 璁惧鍥炬爣鑳屾櫙鎺т欢 + /// </summary> + private FrameLayout frameIconBackGroud = null; + /// <summary> + /// 璁惧鍥炬爣鎺т欢 + /// </summary> + private IconViewControl btnDeviceIcon = null; + /// <summary> + /// 璁惧鍚嶅瓧鎺т欢 + /// </summary> + private NormalViewControl btnDeviceName = null; + /// <summary> + /// 鐘舵�佹帶浠� + /// </summary> + private NormalViewControl btnStatu = null; + /// <summary> + /// 寮�鍏虫帶浠� + /// </summary> + private MostRightIconControl btnSwitch = null; + /// <summary> + /// 鐢垫睜鎺т欢 + /// </summary> + private IconViewControl btnBattery = null; + /// <summary> + /// 鏄惁鑾峰彇缃戝叧鍙嶉鐨勭粨鏋� 0:娌℃湁鑾峰彇寰楀埌 1:宸茬粡鑾峰彇寰楀埌 + /// </summary> + private int ResponeResult = 0; + /// <summary> + /// 鍒ゆ柇鏄惁鏈夊紑鍏冲姛鑳� + /// </summary> + private bool isHadOpenSwitch = true; + /// <summary> + /// 褰撳墠閫夋嫨鐨勬埧闂� + /// </summary> + public Common.Room nowSelectRoom = null; + + #endregion + + #region 鈻� 鍒濆鍖朹____________________________ + + /// <summary> + /// 鏈垎閰嶇晫闈㈢殑璁惧閫夋嫨鎺т欢 + /// </summary> + public DeviceRowCommon() + { + this.SetCornerWithSameRadius(Application.GetRealHeight(58), HDLUtils.RectCornerTopLeft); + this.Width = Application.GetRealWidth(1022); + } + + /// <summary> + /// 鍒濆鍖栨帶浠� + /// </summary> + /// <param name="i_device">璁惧瀵硅薄</param> + /// <param name="i_nowSelectRoom">褰撳墠閫夋嫨鐨勬埧闂�(鏈夌偣鐢ㄥ)</param> + public virtual void InitControl(CommonDevice i_device, Common.Room i_nowSelectRoom) + { + this.device = i_device; + this.nowSelectRoom = i_nowSelectRoom; + //璁惧鍥炬爣鑳屾櫙鎺т欢 + this.frameIconBackGroud = new FrameLayout(); + frameIconBackGroud.Height = this.GetPictrueRealSize(112); + frameIconBackGroud.Width = this.GetPictrueRealSize(112); + frameIconBackGroud.Gravity = Gravity.CenterVertical; + frameIconBackGroud.X = Application.GetRealWidth(46); + frameIconBackGroud.Radius = (uint)this.GetPictrueRealSize(112 / 2); + frameIconBackGroud.BackgroundColor = Common.ZigbeeColor.Current.GXCGrayBackgroundColor; + this.frameTable.AddChidren(frameIconBackGroud, ChidrenBindMode.NotBind); + if (chidrenYaxis != 0) + { + frameIconBackGroud.Y += chidrenYaxis; + } + + //璁惧鍥炬爣鎺т欢 + this.btnDeviceIcon = new IconViewControl(78); + btnDeviceIcon.Gravity = Gravity.Center; + Common.LocalDevice.Current.SetDeviceIconToControl(btnDeviceIcon, i_device); + frameIconBackGroud.AddChidren(btnDeviceIcon); + //閲嶆柊缁戝畾浜嬩欢 + this.frameTable.ChangedChidrenBindMode(frameIconBackGroud, ChidrenBindMode.BindEvent); + + //璁惧鍚嶅瓧 + this.btnDeviceName = new NormalViewControl(600, 60, true); + if (this.device.Type == DeviceType.WindowCoveringDevice || this.device.Type == DeviceType.Airer) + { + //绐楀笜鍜屾櫨琛f灦鍥犱负鍙宠竟鏈変笁涓寜閽�,鎵�浠ラ渶瑕佹墍鏈夊悕瀛楃殑瀹藉害 + this.btnDeviceName.Width = Application.GetRealWidth(360); + } + btnDeviceName.X = Application.GetRealWidth(181); + //褰撴寚瀹氬疄闄呭潗鏍囨椂,杩欓噷闇�瑕佺殑鍋忕Щ閲忎负2鍊� + btnDeviceName.Y = Application.GetRealHeight(16) + this.chidrenYaxis * 2; + btnDeviceName.Text = Common.LocalDevice.Current.GetDeviceEpointName(i_device); + btnDeviceName.SelectedTextColor = Common.ZigbeeColor.Current.GXCTextSelectedColor; + this.frameTable.AddChidren(btnDeviceName, ChidrenBindMode.BindEvent); + + if (this.hadStatuFunction == false) + { + //娌℃湁鐘舵�佸姛鑳�,鍒欐妸璁惧鍚嶅瓧鎺т欢涓� + this.btnDeviceName.Gravity = Gravity.CenterVertical; + btnDeviceName.Y += this.chidrenYaxis; + } + //鎷ユ湁鐘舵�佸姛鑳� + if (this.hadStatuFunction == true) + { + //鐘舵�� + this.btnStatu = new NormalViewControl(600, 50, true); + btnStatu.X = Application.GetRealWidth(181); + //褰撴寚瀹氬疄闄呭潗鏍囨椂,杩欓噷闇�瑕佺殑鍋忕Щ閲忎负2鍊� + btnStatu.Y = Application.GetRealHeight(70) + this.chidrenYaxis * 2; + btnStatu.TextSize = 10; + btnStatu.TextColor = UserCenterColor.Current.TextGrayColor1; + this.frameTable.AddChidren(btnStatu, ChidrenBindMode.BindEvent); + } + + //搴曠嚎 + var btnBottomLine = new NormalViewControl(Application.GetRealWidth(841), ControlCommonResourse.BottomLineHeight, false); + btnBottomLine.X = Application.GetRealWidth(181); + btnBottomLine.Y = this.Height - ControlCommonResourse.BottomLineHeight; + btnBottomLine.BackgroundColor = UserCenterColor.Current.ButtomLine; + this.frameTable.AddChidren(btnBottomLine, ChidrenBindMode.NotBind); + + //寮�鍏虫帶浠�(鏆傛椂涓嶅姞鍏ョ埗鎺т欢) + this.btnSwitch = new MostRightIconControl(69, 69); + btnSwitch.UnSelectedImagePath = "Item/Switch.png"; + btnSwitch.SelectedImagePath = "Item/SwitchSelected.png"; + + //鐢垫睜鎺т欢 + if (this.device.Type == DeviceType.IASZone) + { + this.btnBattery = new IconViewControl(69); + btnBattery.X = this.Width - Application.GetRealWidth(69 + 29); + btnBattery.UnSelectedImagePath = "Item/Battery.png"; + btnBattery.Gravity = Gravity.CenterVertical; + this.frameTable.AddChidren(btnBattery, ChidrenBindMode.BindEvent); + if (chidrenYaxis != 0) + { + btnBattery.Y += chidrenYaxis; + } + if (this.device.IsBatteryDown == false) + { + btnBattery.Visible = false; + } + } + + //鍒嗕韩鐨勬埧闂�,鍒欎笉鑳界紪杈戝拰鍒犻櫎 + if (this.nowSelectRoom.IsSharedRoom == false) + { + //缂栬緫 + var btnEditor = this.AddEditorControl(); + btnEditor.ButtonClickEvent += (sender, e) => + { + var detailInfo = new MainPage.DeviceDetailInfoForm(); + detailInfo.AddForm(i_device, this.nowSelectRoom); + detailInfo.FormCloseEvent += () => + { + if (this.nowSelectRoom.IsLove == true) + { + //褰撳墠鏄枩鐖辨埧闂存椂 + if (HdlRoomLogic.Current.IsCollectInRoom(this.device) == false) + { + //鍥炶皟鎺т欢琚Щ闄ょ殑浜嬩欢 + this.RowNeedRemoveEvent?.Invoke(); + //鎴块棿鏀瑰彉浜� + this.RemoveFromParent(); + return; + } + } + var curRoom = HdlRoomLogic.Current.GetRoomByDevice(this.device); + if (curRoom == null || this.nowSelectRoom.Id != curRoom.Id) + { + //鍥炶皟鎺т欢琚Щ闄ょ殑浜嬩欢 + this.RowNeedRemoveEvent?.Invoke(); + //鎴块棿鏀瑰彉浜� + this.RemoveFromParent(); + return; + } + //鍒锋柊鎺т欢鐘舵�� + this.RefreshControlInfo(i_device); + }; + }; + //鍒犻櫎 + var btnDelete = this.AddDeleteControl(); + btnDelete.ButtonClickEvent += (sender, e) => + { + //纭畾瑕佺Щ闄よ鍔熻兘锛� + var alert = new ShowMsgControl(ShowMsgType.Confirm, Language.StringByID(R.MyInternationalizationString.DeleteFunction)); + alert.Show(); + alert.ConfirmClickEvent += () => + { + //绉婚櫎鏀惰棌(涓嶇浠�涔堟儏鍐�,鏀惰棌閮借绉婚櫎) + HdlRoomLogic.Current.DeleteLoveDevice(i_device); + if (this.nowSelectRoom.IsLove == false) + { + //浠庢埧闂翠腑绉婚櫎 + HdlRoomLogic.Current.DeleteDevice(i_device); + } + //鍥炶皟鎺т欢琚Щ闄ょ殑浜嬩欢 + this.RowNeedRemoveEvent?.Invoke(); + this.RemoveFromParent(); + //涓婁紶绌洪棿鍖哄煙淇℃伅 + HdlRoomLogic.Current.SetRoomInfoToGateway(); + }; + }; + } + //鍒锋柊鎺т欢鐘舵�� + this.RefreshControlInfo(i_device); + } + + #endregion + + #region 鈻� 娣诲姞寮�鍏虫帶浠禵______________________ + + /// <summary> + /// 娣诲姞寮�鍏虫帶浠� + /// </summary> + /// <returns></returns> + public MostRightIconControl AddSwitchControl() + { + this.frameTable.AddChidren(this.btnSwitch, ChidrenBindMode.NotBind); + btnSwitch.InitControl(); + btnSwitch.X -= ControlCommonResourse.XXLeft; + btnSwitch.Y += this.chidrenYaxis; + + return btnSwitch; + } + + #endregion + + #region 鈻� 鍒锋柊鎺т欢鐘舵�乢______________________ + + /// <summary> + /// 鍒锋柊鎺т欢鐘舵�� + /// </summary> + /// <param name="i_device">璁惧瀵硅薄,涓嶆槸鎺ㄩ�佺殑閭d釜</param> + public virtual void RefreshControlInfo(CommonDevice i_device) + { + //璁惧鍥炬爣涔熷埛鏂� + Common.LocalDevice.Current.SetDeviceIconToControl(btnDeviceIcon, i_device); + //璁惧鍚嶅瓧 + this.btnDeviceName.Text = Common.LocalDevice.Current.GetDeviceEpointName(i_device); + //妫�娴嬭澶囨槸鍚︽槸鎵撳紑鐘舵�� + bool isOpen = this.CheckIsOpenStatu(i_device); + if (this.isHadOpenSwitch == true && i_device.HadReadDeviceStatu == false) + { + //濡傛灉杩欎釜鍗$墖鏈夊紑鍏冲姛鑳�,骞朵笖缃戝叧杩樻病鏈夊洖澶嶄箣鍓�,榛樿鏄叧闂姸鎬� + //绛夊緟缃戝叧鍥炲鍚庝細閲嶆柊鍒锋柊,涓嶇劧涓�鐩存槸鍏抽棴鐘舵�� + isOpen = false; + } + //濡傛灉鏄紶鎰熷櫒绫�,鍒欓粯璁ゆ槸鍏崇殑鏁堟灉 + if (this.device.Type == DeviceType.PMSensor || this.device.Type == DeviceType.IASZone + || this.device.Type == DeviceType.TemperatureSensor) + { + isOpen = false; + } + + this.SetRowOpenStatu(isOpen); + } + + /// <summary> + /// 璁剧疆琛屾帶浠剁殑鎵撳紑鎴栬�呭叧闂殑鐘舵�� + /// </summary> + /// <param name="isOpen"></param> + public void SetRowOpenStatu(bool isOpen) + { + //璁惧鐘舵�佸繀椤诲埛鏂� + if (this.btnStatu != null) + { + this.btnStatu.Text = HdlDeviceOtherLogic.Current.GetDeviceStatu(this.device); + } + //寮�鍏虫帶浠� + if (this.btnSwitch != null && this.btnSwitch.IsSelected != isOpen) + { + this.btnSwitch.IsSelected = isOpen; + } + //鍒囨崲鍗$墖鐘舵�佺壒鏁� + this.SwitchRowStatuAppeal(isOpen); + } + + /// <summary> + /// 璁剧疆琛屾帶浠剁殑鍦ㄧ嚎鐘舵�� + /// </summary> + /// <param name="isOnline">鍦ㄧ嚎</param> + public void SetRowOnlineStatu(bool isOnline) + { + if (this.isHadOpenSwitch == true) + { + //濡傛灉杩欎釜璁惧鏈夊紑鍏冲姛鑳�,鍒欏湪绾跨姸鎬佷笉浼氭敼鍙樼姸鎬� + return; + } + this.SetRowOpenStatu(isOnline); + } + + /// <summary> + /// 璁剧疆璁惧鐨勭姸鎬佹枃鏈� + /// </summary> + /// <param name="i_Text">鐘舵�佹枃鏈�</param> + public void SetDeviceStatuText(string i_Text) + { + if (this.btnStatu != null) + { + this.btnStatu.Text = i_Text; + } + } + + #endregion + + #region 鈻� 鍙戦�佽幏鍙栫姸鎬佸懡浠__________________ + + /// <summary> + /// 鍙戦�佽幏鍙栫姸鎬佸懡浠� + /// </summary> + public virtual void SendStatuComand() + { + return; + } + + #endregion + + #region 鈻� 妫�娴嬭澶囨墦寮�鐘舵�乢__________________ + + /// <summary> + /// 妫�娴嬭澶囨槸鍚︽槸鎵撳紑鐘舵�� + /// </summary> + /// <param name="i_device"></param> + /// <returns></returns> + public virtual bool CheckIsOpenStatu(CommonDevice i_device) + { + //濡傛灉杩欎釜鍑芥暟琚噸鍐欑殑璇�,鍒欎唬琛ㄨ繖涓澶囨湁寮�鍏冲姛鑳� + this.isHadOpenSwitch = false; + //榛樿鐢ㄥ湪绾跨姸鎬佹潵鍒ゆ柇 + return Common.LocalDevice.Current.CheckDeviceIsOnline(i_device); + } + + + #endregion + + #region 鈻� 娣卞害鍗$墖淇℃伅鐨勮繑鍥炰簨浠禵____________ + + /// <summary> + /// 娣卞害鍗$墖淇℃伅鐨勮繑鍥炰簨浠�(搴曞眰涓撶敤) + /// </summary> + /// <param name="device">璁惧</param> + public void CardDetailInfoBackEvent(CommonDevice device) + { + if (this.nowSelectRoom.IsLove == true) + { + //宸茬粡鍙栨秷鐨勬敹钘� + if (HdlRoomLogic.Current.IsCollectInRoom(device) == false) + { + //鍥炶皟鎺т欢琚Щ闄ょ殑浜嬩欢 + this.RowNeedRemoveEvent?.Invoke(); + //绉婚櫎杩欎釜鎺т欢 + this.RemoveFromParent(); + return; + } + } + else + { + //濡傛灉杩欎釜璁惧鏀瑰彉浜嗘埧闂寸殑璇�,鍥炶皟鍗$墖琚垹闄ょ殑鍑芥暟 + var nowRoom = HdlRoomLogic.Current.GetRoomByDevice(device); + if (nowRoom == null || nowRoom.Id != this.nowSelectRoom.Id) + { + //鍥炶皟鎺т欢琚Щ闄ょ殑浜嬩欢 + this.RowNeedRemoveEvent?.Invoke(); + //绉婚櫎杩欎釜鎺т欢 + this.RemoveFromParent(); + return; + } + } + //濡傛灉瀹冭繕鍦ㄨ繖涓埧闂寸殑璇�,鍒锋柊鍗$墖淇℃伅 + this.RefreshControlInfo(device); + } + + #endregion + + #region 鈻� 鏄惁鑾峰彇缃戝叧鍙嶉鐨勭粨鏋淿____________ + + /// <summary> + /// <para>妫�娴嬫槸鍚﹁幏鍙栫綉鍏冲弽棣堢殑缁撴灉,濡傛灉缃戝叧娌℃湁鍥炲,鍒欎細寮瑰嚭娑堟伅</para> + /// <para>鑾峰彇鍒板洖澶嶇粨鏋滀箣鍚�,璁板緱璋冪敤SetHadGetResponeResultStatu()鍑芥暟璁剧疆鐘舵��</para> + /// </summary> + /// <param name="oldOpenStatu">璁惧鐩墠鐨勫紑鍏崇姸鎬�</param> + public void StartCheckResponeResult(bool oldOpenStatu) + { + this.ResponeResult = 0; + HdlThreadLogic.Current.RunThread(() => + { + int waitime = 40; + while (waitime > 0) + { + System.Threading.Thread.Sleep(100); + if (this.ResponeResult == 1) + { + //宸茬粡鑾峰彇寰楀埌鏁版嵁 + break; + } + waitime--; + //2绉掔殑鏃跺��,杩樻槸鎺ュ彈涓嶅埌鐨勮瘽,寮哄埗鍐嶆鍒锋柊璁惧鐘舵�� + if (waitime == 20) + { + //浠庢柊鍙戦�佽幏鍙栬澶囩殑鐘舵��(寮哄埗) + this.device.HadReadDeviceStatu = false; + this.SendStatuComand(); + } + } + if (waitime <= 0 && this.Parent != null) + { + //娌℃湁鑾峰彇寰楀埌缁撴灉 + HdlThreadLogic.Current.RunMain(() => + { + var msgContr = new ShowMsgControl(ShowMsgType.Tip, Language.StringByID(R.MyInternationalizationString.FAIL)); + msgContr.Show(); + //鍙樻洿鍥炲師鏉ョ殑鐘舵�� + this.SetRowOpenStatu(oldOpenStatu); + }); + } + }); + } + + /// <summary> + /// 璁剧疆宸茬粡鑾峰彇鍒扮綉鍏崇殑鍙嶉缁撴灉 + /// </summary> + public void SetHadGetResponeResultStatu() + { + this.ResponeResult = 1; + } + + /// <summary> + /// 鎺ユ敹缃戝叧鍥炲鐨勭姸鎬�(true:宸茬粡鎺ユ敹鍒扮綉鍏崇殑鍥炲 false:杩樻病鏈夋帴鏀跺埌缃戝叧鍥炲) + /// </summary> + /// <returns></returns> + public bool ReceiveResponeResultStatu() + { + return this.ResponeResult == 1; + } + + #endregion + + #region 鈻� 鏄剧ず浣庣數閲廮________________________ + + /// <summary> + /// 鍒锋柊鐢垫睜鐢甸噺鐘舵�� + /// </summary> + public void RefreshBatteryStatu() + { + if (this.btnBattery == null) { return; } + if (this.device.IsBatteryDown == true) + { + //鐢甸噺浣�,鏄剧ず鍥炬爣 + if (this.btnBattery.Visible == false) + { + this.btnBattery.Visible = true; + } + } + else + { + //鐢甸噺瓒冲,闅愯棌鍥炬爣 + if (this.btnBattery.Visible == true) + { + this.btnBattery.Visible = false; + } + } + } + + #endregion + + #region 鈻� 涓�鑸柟娉昣__________________________ + + /// <summary> + /// 妫�娴嬭兘鍚﹀彂閫佽幏鍙栫姸鎬佸懡浠� + /// </summary> + /// <returns></returns> + public bool CheckCanSendStatuComand() + { + if (this.device.HadReadDeviceStatu == false) + { + //杩樻病鏈夎鍙栬繃鏁版嵁 + return true; + } + if ((DateTime.Now - this.device.LastDateTime).TotalMinutes >= 10) + { + //10鍒嗛挓鍚庡彲浠ュ啀娆¤幏鍙� + return true; + } + return false; + } + + #endregion + + #region 鈻� 琛岄棯鐑佺壒鏁坃________________________ + + /// <summary> + /// 鏄惁澶勪簬鐗规晥涓� + /// </summary> + private bool isAppeal = false; + /// <summary> + /// 寮�鍚闂儊鐗规晥 + /// </summary> + public void StartRowLightAppeal() + { + //璁惧鐘舵�佸繀椤诲埛鏂� + this.btnStatu.Text = HdlDeviceOtherLogic.Current.GetDeviceStatu(this.device); + + if (this.isAppeal == true) { return; } + this.isAppeal = true; + + HdlThreadLogic.Current.RunThread(() => + { + //闂儊5绉�,闂撮殧400姣 + int count = 5000 / 400; + bool isOpen = false; + while (this.Parent != null && count >= 0) + { + //闂儊鐗规晥 + HdlThreadLogic.Current.RunMain(() => + { + isOpen = !isOpen; + this.SwitchRowStatuAppeal(isOpen); + }); + System.Threading.Thread.Sleep(400); + count--; + } + if (this.Parent != null && isOpen == false) + { + HdlThreadLogic.Current.RunMain(() => + { + //缁撴潫鏃�,榛樿涓烘墦寮�鐗规晥 + this.SwitchRowStatuAppeal(true); + }, ShowErrorMode.NO); + } + this.isAppeal = false; + + }, ShowErrorMode.NO); + } + + /// <summary> + /// 鍒囨崲鍗$墖鐘舵�佺壒鏁� + /// </summary> + public void SwitchRowStatuAppeal(bool isOpen) + { + if (this.btnDeviceName.IsSelected == isOpen) + { + //鐘舵�佷竴鏍�,鍒欎笉闇�瑕佸鐞� + return; + } + //璁惧鍚嶇О鎺т欢 + this.btnDeviceName.IsSelected = isOpen; + this.btnDeviceName.IsBold = isOpen; + //璁惧鐨勮儗鏅渾鍦堝浘 + if (isOpen == true) + { + this.frameIconBackGroud.BackgroundColor = Common.ZigbeeColor.Current.GXCSelectedBackgroundColor; + } + else + { + this.frameIconBackGroud.BackgroundColor = Common.ZigbeeColor.Current.GXCGrayBackgroundColor; + } + //璁惧鍥炬爣鎺т欢 + this.btnDeviceIcon.IsSelected = isOpen; + } + + #endregion + + #region 鈻� 鎺т欢鎽ф瘉___________________________ + + /// <summary> + /// 鎺т欢鎽ф瘉 + /// </summary> + public override void RemoveFromParent() + { + this.RowNeedRemoveEvent = null; + + base.RemoveFromParent(); + } + + #endregion + } } -- Gitblit v1.8.0