From 2029e64ec0491f7e511dc15bffaf821bfbabe2de Mon Sep 17 00:00:00 2001
From: 黄学彪 <hxb@hdlchina.com.cn>
Date: 星期一, 20 七月 2020 14:10:22 +0800
Subject: [PATCH] 上传一个很特别的新版本
---
ZigbeeApp/Shared/Phone/UserCenter/Device/Panel/PanelSimpleMutilfunctionTargetsForm.cs | 998 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 997 insertions(+), 1 deletions(-)
diff --git a/ZigbeeApp/Shared/Phone/UserCenter/Device/Panel/PanelSimpleMutilfunctionTargetsForm.cs b/ZigbeeApp/Shared/Phone/UserCenter/Device/Panel/PanelSimpleMutilfunctionTargetsForm.cs
index ddcca6f..58ce04e 100755
--- a/ZigbeeApp/Shared/Phone/UserCenter/Device/Panel/PanelSimpleMutilfunctionTargetsForm.cs
+++ b/ZigbeeApp/Shared/Phone/UserCenter/Device/Panel/PanelSimpleMutilfunctionTargetsForm.cs
@@ -1,10 +1,1006 @@
锘縰sing System;
+using System.Collections.Generic;
+using System.Linq.Expressions;
+using Newtonsoft.Json.Linq;
+using Shared.Common;
+using Shared.Phone.UserCenter.Device.Bind;
+using Shared.Phone.UserCenter.Safety;
+using ZigBee.Device;
+using static ZigBee.Device.BindObj;
+using static ZigBee.Device.Panel;
namespace Shared.Phone.UserCenter.DeviceBind
{
+ /// <summary>
+ /// 绠�绾﹀鍔熻兘闈㈡澘
+ /// 褰撳墠鐣岄潰榛樿閫夋嫨绗竴涓ゼ灞傦紝绗竴涓被鍨�
+ /// </summary>
public class PanelSimpleMutilfunctionTargetsForm : BindCommonLayout
{
- public PanelSimpleMutilfunctionTargetsForm()
+ #region 鏋勯�犲嚱鏁�
+ /// <summary>
+ /// 鏋勯�犲嚱鏁�
+ /// </summary>
+ /// <param name="deviceMac">绠�绾﹀鍔熻兘闈㈡澘Mac</param>
+ public PanelSimpleMutilfunctionTargetsForm(string deviceMac)
{
+ curControlDev = new Panel();
+ var dev = Common.LocalDevice.Current.GetDevice(deviceMac, 62);//绠�绾﹂潰鏉块殢渚夸竴涓洖璺潵鑾峰彇璁惧
+ if (dev != null)
+ {
+ curControlDev.CurrentGateWayId = dev.CurrentGateWayId;
+ }
+ curControlDev.Type = DeviceType.OnOffSwitch;
+ curControlDev.DeviceAddr = deviceMac;
}
+ #endregion
+
+ #region 鍙橀噺鐢虫槑
+ /// <summary>
+ /// 鎺у埗璁惧
+ /// </summary>
+ Panel curControlDev;
+ /// <summary>
+ /// 鏄剧ず琚粦瀹氳澶囨垨鍦烘櫙鐨剉iew
+ /// </summary>
+ VerticalFrameRefreshControl midVerticalScrolViewLayout;
+ /// <summary>
+ /// 鏄剧ず缁戝畾绫诲瀷
+ /// </summary>
+ FrameLayout typeFrameLayout;
+ /// <summary>
+ /// 缁戝畾绫诲瀷鎻愮ず鏂囨湰
+ /// </summary>
+ Button btnTipText;
+ /// <summary>
+ /// 淇濆瓨瀹屾垚鎸夐挳
+ /// </summary>
+ Button btnFinifh;
+ /// <summary>
+ /// 鏈湴璁惧鍒楄〃
+ /// </summary>
+ private System.Collections.Generic.List<CommonDevice> localDeviceList = new System.Collections.Generic.List<CommonDevice>();
+ /// <summary>
+ /// 鏈湴鍦烘櫙鍒楄〃
+ /// </summary>
+ private System.Collections.Generic.List<SceneUI> scList = new System.Collections.Generic.List<SceneUI> { };
+ /// <summary>
+ /// 褰撳墠绫诲瀷鐨勭粦瀹氳〃
+ /// </summary>
+ public List<BindListAllInfo> curBindTypeList = new List<BindListAllInfo>();
+ /// <summary>
+ /// 褰撳墠绫诲瀷
+ /// 0:鍦烘櫙 1:寮�鍏� 2:鎻掑骇 3:鐏厜 4:閬槼 5:绌鸿皟 6:鏂伴
+ /// </summary>
+ int curBindType = 0;
+ /// <summary>
+ /// 鏄惁鏀寔璇诲彇
+ /// </summary>
+ bool IsRead = false;
+ /// <summary>
+ /// 鏄惁鏀寔鍐嶆璇诲彇銆愬綋鐩爣璇诲彇涓嶅叏鎯呭喌涓嬮噸鏂拌鍙栥��
+ /// </summary>
+ bool IsAgain = false;
+ /// <summary>
+ /// 涓婁竴娆¤鍙栫鐐孤�
+ /// </summary>
+ private int oldReadEpoint = 2;
+ /// <summary>
+ /// 鐗规畩绫诲瀷鐨勪釜鏁般�愬紑鍏�/鎻掑骇/鐏厜銆戦渶瑕佽绠楁樉绀虹殑涓暟聽
+ /// </summary>
+ int specialTypeCount = 0;
+
+ private Action bindReceiveAction = null;
+ /// <summary>
+ /// 鍥炶皟缁戝畾鐩爣椤甸潰鍒锋柊
+ /// </summary>
+ public Action<List<BindListResponseObj>> action;
+ #endregion
+
+ #region UI璁捐
+ /// <summary>
+ /// 鐩爣椤垫樉绀�
+ /// </summary>
+ public void Show()
+ {
+ //鏍囬鏍�
+ TitleUI();
+ //涓儴UI銆愭爣棰樻爮涓嬬殑UI銆�
+ MidFrameLayouUI();
+ //绫诲瀷鏍廢I
+ BindTypeUI();
+
+ CommonPage.Loading.Start("");
+ InitLocalDeviceList();
+ if (MutilfunctionPanelMethod.bindTargetsFromMutilfunctionPanelList.Count == 0)
+ {
+ IsRead = true;
+ }
+ else
+ {
+ IsRead = false;
+ }
+ InitData();
+ }
+
+ /// <summary>
+ /// 鏍囬鏍�
+ /// </summary>
+ void TitleUI()
+ {
+ string titleText = "";
+ titleText = Language.StringByID(R.MyInternationalizationString.uBindTargets);
+
+ this.TopFrameLayout(this, titleText);
+ EventHandler<MouseEventArgs> eHandlerBack = (sender, e) =>
+ {
+ RemoveFromParent();
+ };
+ this.btnTitle.Width = Application.GetRealWidth(1080 - 161 - 300);
+ this.btnBack.MouseUpEventHandler += eHandlerBack;
+ this.btnBackFrameLayout.MouseUpEventHandler += eHandlerBack;
+ this.MidFrameLayout(this);
+
+ var btnAddFrameLayout = new FrameLayout()
+ {
+ X = Application.GetRealWidth(772 - 58),
+ Width = Application.GetRealWidth(192),
+ };
+ this.titleFrameLayout.AddChidren(btnAddFrameLayout);
+
+ var btnBindAdd = new Button
+ {
+ X = Application.GetRealWidth(62),
+ Height = Application.GetMinReal(72),
+ Width = Application.GetMinReal(72),
+ UnSelectedImagePath = "BindPic/BindAdd.png",
+ };
+ btnAddFrameLayout.AddChidren(btnBindAdd);
+ EventHandler<MouseEventArgs> eHandlerAdd = (sender, e) =>
+ {
+ var simpleMutilfunctionBindTargetsForm = new Shared.Phone.UserCenter.DeviceBind.PanelSimpleMutilfunctionAddTargetsForm(curControlDev.DeviceAddr, curBindType);
+ Shared.Phone.UserView.HomePage.Instance.AddChidren(simpleMutilfunctionBindTargetsForm);
+ Shared.Phone.UserView.HomePage.Instance.PageIndex += 1;
+ simpleMutilfunctionBindTargetsForm.Show();
+ Action action = () =>
+ {
+ RefreshBindListUI();
+ };
+ simpleMutilfunctionBindTargetsForm.actionRefreshBindList += action;
+ };
+ btnBindAdd.MouseDownEventHandler += eHandlerAdd;
+ btnAddFrameLayout.MouseDownEventHandler += eHandlerAdd;
+ }
+
+ /// <summary>
+ /// 涓儴UI銆愭爣棰樻爮涓嬬殑UI銆�
+ /// </summary>
+ void MidFrameLayouUI()
+ {
+ //绫诲瀷鏍�1
+ typeFrameLayout = new FrameLayout
+ {
+ X = Application.GetRealWidth(58 / 2),
+ Height = Application.GetRealHeight(323),
+ };
+ this.midFrameLayout.AddChidren(typeFrameLayout);
+
+ //璁惧鏍�
+ midVerticalScrolViewLayout = new VerticalFrameRefreshControl()
+ {
+ Y = Application.GetRealHeight(323),
+ Height = Application.GetRealHeight(1065),
+ };
+ this.midFrameLayout.AddChidren(midVerticalScrolViewLayout);
+ midVerticalScrolViewLayout.BeginHeaderRefreshingAction += () =>
+ {
+ midVerticalScrolViewLayout.BeginHeaderRefreshing();
+ IsRead = true;
+ InitData();
+ };
+
+ //搴曢儴淇濆瓨鏍�
+ var bottomFrameLayout = new FrameLayout()
+ {
+ Width = LayoutParams.MatchParent,
+ Height = Application.GetRealHeight(84 * 2 + 127),
+ Y = Application.GetRealHeight(1388),
+ };
+ this.midFrameLayout.AddChidren(bottomFrameLayout);
+
+ btnTipText = new Button()
+ {
+ Height = Application.GetRealHeight(84),
+ TextID = R.MyInternationalizationString.Tip,
+ TextColor = Shared.Common.ZigbeeColor.Current.XMGray3,
+ TextSize = 12,
+ Text = MutilfunctionPanelMethod.MatchTypeBindTextTip(curBindType),
+ TextAlignment = TextAlignment.Center,
+ };
+ bottomFrameLayout.AddChidren(btnTipText);
+
+ btnFinifh = new Button()
+ {
+ Width = Application.GetRealWidth(907),
+ Height = Application.GetRealHeight(127),
+ Y = Application.GetRealHeight(49 + 35),
+ Gravity = Gravity.CenterHorizontal,
+ Radius = (uint)Application.GetRealHeight(127) / 2,
+ TextID = R.MyInternationalizationString.Save,
+ BackgroundColor = Shared.Common.ZigbeeColor.Current.XMBlack,
+ TextColor = Shared.Common.ZigbeeColor.Current.XMWhite,
+ IsBold = true,
+ TextSize = 16,
+ };
+ bottomFrameLayout.AddChidren(btnFinifh);
+ btnFinifh.MouseUpEventHandler += (sender, e) =>
+ {
+ SaveTarget();
+ };
+ }
+
+ /// <summary>
+ /// 绫诲瀷鏍廢I
+ /// </summary>
+ void BindTypeUI()
+ {
+ //鍖归厤鐨勭被鍨嬪垪琛�
+ var typeList = GetTypeList();
+ int index = 0;
+ Button curentOldType = null;
+ FrameLayout curentOldTypeLayout = null;
+ foreach (var typeText in typeList)
+ {
+ var btnTypeLayout = new FrameLayout
+ {
+ Height = Application.GetMinRealAverage(159),
+ Width = Application.GetMinRealAverage(255),
+ Y = Application.GetRealHeight(23),
+ BackgroundImagePath = "Item/RoomIconBackground.png",
+ BorderWidth = 1,
+ };
+ typeFrameLayout.AddChidren(btnTypeLayout);
+
+ var btnType = new Button
+ {
+ Height = Application.GetRealHeight(58),
+ Width = Application.GetRealWidth(127),
+ Y = Application.GetRealHeight(58),
+ X = Application.GetRealWidth(14),
+ Text = typeText,
+ TextSize = 12,
+ TextColor = Shared.Common.ZigbeeColor.Current.XMGray3,
+ Gravity = Gravity.Center,
+ };
+ btnTypeLayout.AddChidren(btnType);
+
+ btnType.IsSelected = false;
+
+ if (index == 0)
+ {
+ btnTypeLayout.Y = Application.GetRealHeight(0);
+ btnTypeLayout.BackgroundImagePath = "Item/RoomIconBackgroundSelected.png";
+ btnType.TextColor = Shared.Common.ZigbeeColor.Current.XMWhite;
+ curentOldType = btnType;
+ curentOldTypeLayout = btnTypeLayout;
+ }
+ else
+ {
+ btnTypeLayout.Y = Application.GetRealHeight(0);
+ btnTypeLayout.X = index * Application.GetRealWidth(260);
+ if (index > 3)
+ {
+ btnTypeLayout.Y = Application.GetRealHeight(58 + 78);
+ if (index == 4)
+ {
+ btnTypeLayout.X = Application.GetRealWidth(0);
+ }
+ else
+ {
+ btnTypeLayout.X = (index - 4) * Application.GetRealWidth(260);
+ }
+ }
+ }
+
+ EventHandler<MouseEventArgs> eHandlerRoom = (sender, e) =>
+ {
+ if (!curentOldType.IsSelected)
+ {
+ if (curentOldType != null)
+ {
+ curentOldType.TextColor = Shared.Common.ZigbeeColor.Current.XMGray3;
+ }
+ curentOldType = btnType;
+ curentOldType.TextColor = Shared.Common.ZigbeeColor.Current.XMWhite;
+ }
+
+ if (btnTypeLayout.BorderWidth == 1)
+ {
+ if (curentOldTypeLayout != null)
+ {
+ curentOldTypeLayout.BorderWidth = 1;
+ curentOldTypeLayout.BorderColor = Shared.Common.ZigbeeColor.Current.XMOrange;
+ curentOldTypeLayout.BackgroundImagePath = "Item/RoomIconBackground.png";
+ }
+ curentOldTypeLayout = btnTypeLayout;
+ curentOldTypeLayout.BorderWidth = 0;
+ curentOldTypeLayout.BackgroundImagePath = "Item/RoomIconBackgroundSelected.png";
+ }
+
+ if (curentOldType.Text == Language.StringByID(R.MyInternationalizationString.scene))
+ {
+ curBindType = 0;
+ RefreshBindListUI();
+ }
+ else if (curentOldType.Text == Language.StringByID(R.MyInternationalizationString.uDeviceBelongId13))
+ {
+ curBindType = 1;
+ RefreshBindListUI();
+ }
+ else if (curentOldType.Text == Language.StringByID(R.MyInternationalizationString.uDeviceBelongId14))
+ {
+ curBindType = 2;
+ RefreshBindListUI();
+ }
+ else if (curentOldType.Text == Language.StringByID(R.MyInternationalizationString.uDeviceBelongId15))
+ {
+ curBindType = 3;
+ RefreshBindListUI();
+ }
+ else if (curentOldType.Text == Language.StringByID(R.MyInternationalizationString.uDeviceBelongId100))
+ {
+ curBindType = 4;
+ RefreshBindListUI();
+ }
+ else if (curentOldType.Text == Language.StringByID(R.MyInternationalizationString.uDeviceBelongId3600))
+ {
+ curBindType = 5;
+ RefreshBindListUI();
+ }
+ else if (curentOldType.Text == Language.StringByID(R.MyInternationalizationString.uDeviceBelongId2310))
+ {
+ curBindType = 6;
+ RefreshBindListUI();
+ }
+ };
+ btnType.MouseUpEventHandler += eHandlerRoom;
+ btnTypeLayout.MouseUpEventHandler += eHandlerRoom;
+ index++;
+ }
+ }
+
+ /// <summary>
+ /// 缁戝畾琛ㄦ樉绀�
+ /// </summary>
+ void RefreshBindListUI()
+ {
+ midVerticalScrolViewLayout.RemoveAll();
+ curBindTypeList = MutilfunctionPanelMethod.GetMatchBindList(curBindType);
+ int curIndex = 0;
+ for (int i = 0; i < curBindTypeList.Count; i++)
+ {
+ curIndex = i;
+ var bindObj = curBindTypeList[i];
+ SceneUI curSceneUI = null;
+
+ var rowLayout = new RowLayoutControl(midVerticalScrolViewLayout.rowSpace / 2);
+ rowLayout.BackgroundColor = ZigbeeColor.Current.XMWhite;
+ midVerticalScrolViewLayout.AddChidren(rowLayout);
+ rowLayout.frameTable.UseClickStatu = false;
+ var devicePic = rowLayout.frameTable.AddLeftIcon();
+ devicePic.Y = Application.GetRealHeight(25);//49
+ devicePic.UnSelectedImagePath = "DoorLock/DoorLockUserPic.png";
+
+ #region 缁戝畾鏁版嵁澶勭悊
+ int currentIndex = i;
+ var btnBindNameText = "";
+ var btnFloorRoomNameText = "";
+ if (currentIndex == curBindTypeList.Count - 1)
+ {
+ rowLayout.LineColor = Shared.Common.ZigbeeColor.Current.XMWhite;
+ }
+
+ if (curBindType == 0)
+ {
+ //Scene
+ curSceneUI = HdlSceneLogic.Current.GetSceneUIBySceneId(bindObj.BindScenesId);
+ devicePic.UnSelectedImagePath = "Scene/SceneIcon.png";
+ if (curSceneUI == null)
+ {
+ if (string.IsNullOrEmpty(bindObj.ESName))
+ {
+ btnBindNameText = Language.StringByID(R.MyInternationalizationString.OffLineScene) + "_" + "ID" + "_" + bindObj.BindScenesId.ToString();
+ }
+ else
+ {
+ btnBindNameText = Language.StringByID(R.MyInternationalizationString.OffLineScene) + "_" + bindObj.ESName;
+ }
+ btnFloorRoomNameText = Language.StringByID(R.MyInternationalizationString.Undistributed);
+ }
+ else
+ {
+ btnBindNameText = curSceneUI.Name;
+ string myName = HdlSceneLogic.Current.GetZoneById(curSceneUI.Id);
+ if (myName != null)
+ {
+ btnFloorRoomNameText = myName;
+ }
+ else
+ {
+ btnFloorRoomNameText = Language.StringByID(R.MyInternationalizationString.Undistributed);
+ }
+ }
+ }
+ else
+ {
+ //琚粦瀹氳澶囧浘鐗囥�愬彲鑳藉拰澶栭潰璁惧绛夊浘鐗囦笉鍚岋紝鍥犱负杩欓噷鏄互鍔熻兘鏉ョ粦瀹氱殑銆�
+ //devicePic.UnSelectedImagePath = tempDev.IconPath;
+ var device = LocalDevice.Current.GetDevice(bindObj.BindMacAddr, bindObj.BindEpoint);
+ switch (curBindType)
+ {
+ case 1:
+ devicePic.UnSelectedImagePath = "BindPic/Switch.png";
+ break;
+ case 2:
+ devicePic.UnSelectedImagePath = "Device/Socket1.png";
+ break;
+ case 3:
+ devicePic.UnSelectedImagePath = "Device/Light.png";
+ break;
+ case 4:
+ if (device != null)
+ {
+ if (device.Type == DeviceType.WindowCoveringDevice)
+ {
+ var tempCur = device as Rollershade;
+ if (tempCur.WcdType == 4)
+ {
+ devicePic.UnSelectedImagePath = "BindPic/Curtain.png";
+ }
+ else
+ {
+ devicePic.UnSelectedImagePath = "BindPic/Roller.png";
+ }
+ }
+ }
+ break;
+ case 5:
+ devicePic.UnSelectedImagePath = "Device/AirConditionerEpoint.png";
+ break;
+ case 6:
+ devicePic.UnSelectedImagePath = "Device/FreshAirEpoint.png";
+ break;
+ }
+
+ if (device != null)
+ {
+ //璁惧鍚嶅瓧
+ btnBindNameText = Common.LocalDevice.Current.GetDeviceEpointName(device);
+
+ //鑾峰彇璁惧鎵�灞炴埧闂�
+ var tempDevRoom = HdlRoomLogic.Current.GetRoomByDevice(device);
+
+ if (tempDevRoom != null)
+ {
+ var tempDevFloorId = tempDevRoom.FloorId;
+ //鑾峰彇鎴块棿鐨勫悕瀛�
+ var tempDevRoomName = tempDevRoom.Name;
+ //鑾峰彇妤煎眰鐨勫悕瀛�
+ var tempDevFloorName = HdlResidenceLogic.Current.GetFloorNameById(tempDevFloorId);
+ if (string.IsNullOrEmpty(tempDevFloorName))
+ {
+ if (string.IsNullOrEmpty(tempDevRoomName))
+ {
+ btnFloorRoomNameText = Language.StringByID(R.MyInternationalizationString.Undistributed);
+ }
+ else
+ {
+ btnFloorRoomNameText = tempDevRoomName;
+ }
+ }
+ else
+ {
+ if (string.IsNullOrEmpty(tempDevRoomName))
+ {
+ btnFloorRoomNameText = Language.StringByID(R.MyInternationalizationString.Undistributed);
+ }
+ else
+ {
+ btnFloorRoomNameText = tempDevFloorName + "," + tempDevRoomName;
+ }
+ }
+ }
+ else
+ {
+ btnFloorRoomNameText = Language.StringByID(R.MyInternationalizationString.Undistributed);
+ }
+ }
+ else
+ {
+ devicePic.TextAlignment = TextAlignment.CenterLeft;
+ devicePic.TextColor = UserCenterColor.Current.Gray;
+ devicePic.Text = Language.StringByID(R.MyInternationalizationString.uOffLine);
+ }
+ }
+
+ var btnBindName = rowLayout.frameTable.AddTopView(btnBindNameText, 800);
+ var btnFloorRoomName = rowLayout.frameTable.AddBottomView(btnFloorRoomNameText, 800);
+ rowLayout.frameTable.AddBottomLine();
+ var btnDel = rowLayout.AddDeleteControl();
+ btnDel.ButtonClickEvent += (sender, e) =>
+ {
+ RemoveTargets(bindObj, btnDel);
+ };
+ #endregion
+ }
+
+ switch (curBindType)
+ {
+ case 1:
+ btnTipText.Text = MutilfunctionPanelMethod.MatchTypeBindTextTip(curBindType, MutilfunctionPanelMethod.curSwitchCount + MutilfunctionPanelMethod.curSocketCount + MutilfunctionPanelMethod.curLightFromRelayCount);
+ break;
+ case 2:
+ btnTipText.Text = MutilfunctionPanelMethod.MatchTypeBindTextTip(curBindType, MutilfunctionPanelMethod.curSwitchCount + MutilfunctionPanelMethod.curSocketCount + MutilfunctionPanelMethod.curLightFromRelayCount);
+ break;
+ case 3:
+ btnTipText.Text = MutilfunctionPanelMethod.MatchTypeBindTextTip(curBindType, MutilfunctionPanelMethod.curSwitchCount + MutilfunctionPanelMethod.curSocketCount + MutilfunctionPanelMethod.curLightFromRelayCount + MutilfunctionPanelMethod.curLightCount);
+ break;
+ default:
+ btnTipText.Text = MutilfunctionPanelMethod.MatchTypeBindTextTip(curBindType, curBindTypeList.Count);
+ break;
+ }
+ midVerticalScrolViewLayout.AdjustTableHeight(Application.GetRealHeight(23));
+ }
+
+ #endregion
+
+ #region 鏁版嵁澶勭悊
+ /// <summary>
+ /// 鑾峰彇鏈湴鍒楄〃
+ /// </summary>
+ void InitLocalDeviceList()
+ {
+ localDeviceList.Clear();
+ scList.Clear();
+ //璁惧
+ foreach (var dev in Shared.Common.LocalDevice.Current.listAllDevice)
+ {
+ localDeviceList.Add(dev);
+ }
+ //鍦烘櫙
+ scList = HdlSceneLogic.Current.GetAllRoomSceneList();
+ }
+ /// <summary>
+ /// 鍒濆鍖栬澶囨暟鎹�
+ /// </summary>
+ void InitData()
+ {
+ System.Threading.Tasks.Task.Run(async () =>
+ {
+ try
+ {
+ //璇诲彇鎸夐敭褰撳墠缁戝畾鐩爣 澶氬姛鑳介潰鏉跨洰鏍囨�诲叡闇�瑕佽鍙栨湰椤电殑鐩爣60涓紝3绉掑乏鍙筹紙3绉�+200姣锛�
+ GetDeviceBindResponseAllData getBindList = null;
+ if (IsRead)
+ {
+ MutilfunctionPanelMethod.bindTargetsFromMutilfunctionPanelList.Clear();
+ var epointList = new List<int>();
+ for (int i = 2; i < 62; i++)
+ {
+ epointList.Add(i);
+ }
+ //璇诲彇涓婃娌¤鍏ㄨ鐩爣
+ if (IsAgain)
+ {
+ epointList.Clear();
+ for (int i = oldReadEpoint; i < 62; i++)
+ {
+ epointList.Add(i);
+ }
+ }
+
+ foreach (var epoint in epointList)
+ {
+ curControlDev.DeviceEpoint = epoint;
+ getBindList = HdlDeviceBindLogic.Current.GetDeviceBindAsync(curControlDev);
+ if (getBindList != null && getBindList.getAllBindResponseData != null)
+ {
+ var bList = new List<BindListAllInfo>();
+ foreach (var dev in getBindList.getAllBindResponseData.BindList)
+ {
+ var curD = new BindListAllInfo();
+ curD.KeyMacAddr = curControlDev.DeviceAddr;
+ curD.KeyEpoint = epoint;
+ curD.BindCluster = dev.BindCluster;
+ curD.BindScenesId = dev.BindScenesId;
+ curD.BindMacAddr = dev.BindMacAddr;
+ curD.BindEpoint = dev.BindEpoint;
+ curD.ESName = dev.ESName;
+ curD.BindType = dev.BindType;
+ bList.Add(curD);
+ }
+ MutilfunctionPanelMethod.bindTargetsFromMutilfunctionPanelList.Add(curControlDev.DeviceAddr + curControlDev.DeviceEpoint, bList);
+
+ oldReadEpoint++;
+ }
+ else
+ {
+ if (oldReadEpoint < 62)
+ {
+ IsAgain = true;
+ }
+ Application.RunOnMainThread(() =>
+ {
+ RefreshBindListUI();
+ midVerticalScrolViewLayout.EndHeaderRefreshing();
+ CommonPage.Loading.Hide();
+ new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.GwResponseOvertime), Direction = AMPopTipDirection.None, CloseTime = 1 }.Show(Common.CommonPage.Instance);
+ });
+ break;
+ }
+ }
+ if (oldReadEpoint >= 61)
+ {
+ IsAgain = false;
+ oldReadEpoint = 2;
+ }
+
+ //鑾峰彇鎵�鏈夌被鍨嬬殑缁戝畾鐩爣涓暟
+ for (int i = 0; i < 7; i++)
+ {
+ curBindTypeList = MutilfunctionPanelMethod.GetMatchBindList(i);
+ }
+
+ Application.RunOnMainThread(() =>
+ {
+ RefreshBindListUI();
+ midVerticalScrolViewLayout.EndHeaderRefreshing();
+ CommonPage.Loading.Hide();
+ });
+ }
+ else
+ {
+ Application.RunOnMainThread(() =>
+ {
+ RefreshBindListUI();
+ CommonPage.Loading.Hide();
+ });
+ }
+ }
+ catch (Exception ex)
+ {
+ var mess = ex.Message;
+ }
+ });
+ }
+
+ /// <summary>
+ /// 淇濆瓨鐩爣
+ /// </summary>
+ /// <param name="curControlDev"></param>
+ void SaveTarget()
+ {
+ RemoveFromParent();
+ }
+
+ /// <summary>
+ /// 鍒犻櫎澶氬姛鑳介潰鏉跨殑鐩爣
+ /// </summary>
+ /// <param name="bindDevice"></param>
+ /// <param name="btnDel"></param>
+ /// <returns></returns>
+ private void RemoveTargets(BindListAllInfo bindDevice, Button btnDel)
+ {
+ var delDevice = new DelDeviceBindData();
+ delDevice.DeviceAddr = bindDevice.KeyMacAddr;
+ delDevice.Epoint = bindDevice.KeyEpoint;
+
+ if (bindDevice.BindType == 0 || bindDevice.BindType == 1)
+ {
+ var removeDevice = new RemoveBindListObj();
+ removeDevice.BindCluster = bindDevice.BindCluster;
+ removeDevice.BindType = 0;
+ removeDevice.BindMacAddr = bindDevice.BindMacAddr;
+ removeDevice.BindEpoint = bindDevice.BindEpoint;
+ delDevice.RemoveBindList.Add(removeDevice);
+
+ //閮ㄥ垎鐩爣闇�瑕佷簩娆$粦瀹氱浜岀鍔熻兘
+ switch (curBindType)
+ {
+ case 3:
+ var device = LocalDevice.Current.GetDevice(bindDevice.BindMacAddr, bindDevice.BindEpoint);
+ if (device != null)
+ {
+ if (device.Type == DeviceType.DimmableLight)
+ {
+ //鐏厜涓鸿皟鍏夋椂闇�瑕佺Щ闄�6锛�8
+ var removeDevice2 = new RemoveBindListObj();
+ removeDevice2.BindCluster = 6;
+ removeDevice2.BindType = 0;
+ removeDevice2.BindMacAddr = bindDevice.BindMacAddr;
+ removeDevice2.BindEpoint = bindDevice.BindEpoint;
+ delDevice.RemoveBindList.Add(removeDevice2);
+ }
+ }
+ break;
+ case 5:
+ //瑕佺Щ闄ょ┖璋冿細闇�瑕佺Щ闄�513锛�514
+ var removeDevice3 = new RemoveBindListObj();
+ removeDevice3.BindCluster = 514;
+ removeDevice3.BindType = 0;
+ removeDevice3.BindMacAddr = bindDevice.BindMacAddr;
+ removeDevice3.BindEpoint = bindDevice.BindEpoint;
+ delDevice.RemoveBindList.Add(removeDevice3);
+ break;
+ }
+ }
+ else if (bindDevice.BindType == 2)
+ {
+ var removeDevice = new RemoveBindListObj();
+ removeDevice.BindCluster = bindDevice.BindCluster;
+ removeDevice.BindType = 1;
+ removeDevice.BindScenesId = bindDevice.BindScenesId;
+ delDevice.RemoveBindList.Add(removeDevice);
+ }
+
+ System.Threading.Tasks.Task.Run(() =>
+ {
+ try
+ {
+ Application.RunOnMainThread(() =>
+ {
+ CommonPage.Loading.Start("");
+ });
+ var delResult = new DelDeviceBindResponseAllData();
+ delResult = HdlDeviceBindLogic.Current.DelDeviceBindAsync(delDevice);
+ if (delResult == null)
+ {
+ Application.RunOnMainThread(() =>
+ {
+ new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.GwResponseOvertime), Direction = AMPopTipDirection.None, CloseTime = 2 }.Show(CommonPage.Instance);
+ CommonPage.Loading.Hide();
+ });
+ return;
+ }
+ else
+ {
+ if (delResult.removeBindResultResponseData == null)
+ {
+ if (delResult.delDeviceBindResponseData != null)
+ {
+ foreach (var d in delResult.delDeviceBindResponseData.RemoveBindList)
+ {
+ if (d.Result == 0 || d.Result == 1)
+ {
+ if (MutilfunctionPanelMethod.bindTargetsFromMutilfunctionPanelList.ContainsKey(bindDevice.KeyMacAddr + bindDevice.KeyEpoint))
+ {
+ MutilfunctionPanelMethod.bindTargetsFromMutilfunctionPanelList.Remove(bindDevice.KeyMacAddr + bindDevice.KeyEpoint);
+ }
+ Application.RunOnMainThread(() =>
+ {
+ RefreshBindListUI();
+ CommonPage.Loading.Hide();
+ });
+ }
+ else
+ {
+ Application.RunOnMainThread(() =>
+ {
+ new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.GwResponseOvertime), Direction = AMPopTipDirection.None, CloseTime = 2 }.Show(CommonPage.Instance);
+ CommonPage.Loading.Hide();
+ });
+ return;
+ }
+ }
+ }
+ else
+ {
+ Application.RunOnMainThread(() =>
+ {
+ new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.GwResponseOvertime), Direction = AMPopTipDirection.None, CloseTime = 2 }.Show(CommonPage.Instance);
+ CommonPage.Loading.Hide();
+ });
+ return;
+ }
+ }
+ else
+ {
+ if (delResult.removeBindResultResponseData.Result == 0)
+ {
+ if (MutilfunctionPanelMethod.bindTargetsFromMutilfunctionPanelList.ContainsKey(bindDevice.KeyMacAddr + bindDevice.KeyEpoint))
+ {
+ MutilfunctionPanelMethod.bindTargetsFromMutilfunctionPanelList.Remove(bindDevice.KeyMacAddr + bindDevice.KeyEpoint);
+ }
+ Application.RunOnMainThread(() =>
+ {
+ RefreshBindListUI();
+ CommonPage.Loading.Hide();
+ });
+ }
+ else
+ {
+ Application.RunOnMainThread(() =>
+ {
+ new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.BindFailed), Direction = AMPopTipDirection.None, CloseTime = 1 }.Show(CommonPage.Instance);
+ CommonPage.Loading.Hide();
+ });
+ return;
+ }
+ }
+ }
+ }
+ catch { }
+ finally
+ {
+ Application.RunOnMainThread(() =>
+ {
+ CommonPage.Loading.Hide();
+ });
+ }
+ });
+ }
+
+
+
+ /// <summary>
+ /// 鍖归厤鐨勭被鍨嬪垪琛�
+ /// </summary>
+ /// <returns></returns>
+ private List<string> GetTypeList()
+ {
+ List<string> textTypelist = new List<string> { };
+ textTypelist.Add(Language.StringByID(R.MyInternationalizationString.scene));
+ textTypelist.Add(Language.StringByID(R.MyInternationalizationString.uDeviceBelongId13));
+ textTypelist.Add(Language.StringByID(R.MyInternationalizationString.uDeviceBelongId14));
+ textTypelist.Add(Language.StringByID(R.MyInternationalizationString.uDeviceBelongId15));
+ textTypelist.Add(Language.StringByID(R.MyInternationalizationString.uDeviceBelongId100));
+ textTypelist.Add(Language.StringByID(R.MyInternationalizationString.uDeviceBelongId3600));
+ textTypelist.Add(Language.StringByID(R.MyInternationalizationString.uDeviceBelongId2310));
+ return textTypelist;
+ }
+
+ #endregion
+
+ #region 鍏朵粬鏂规硶
+ /// <summary>
+ /// 鏄剧ず缁戝畾璁惧绾跨▼鏄惁宸茬粡寮�鍚�
+ /// </summary>
+ private bool isDeviceThreadStart = false;
+ /// <summary>
+ /// 涓婚瓒呮椂鐨勭嚎绋嬫槸鍚﹀紑鍚�
+ /// </summary>
+ private bool isTopicTimeOutThreadStart = false;
+ /// <summary>
+ /// 绛夊緟璁惧鐨勫洖棣堢殑瓒呮椂鏃堕棿(鍗曚綅锛氱櫨姣)
+ /// </summary>
+ private int waitDeviceTimeOut = 20;
+ /// <summary>
+ /// 缃戝叧ID
+ /// </summary>
+ private string gatewayId = string.Empty;
+ /// <summary>
+ /// 鎺ユ敹涓暟
+ /// </summary>
+ private int countBind = 0;
+ /// <summary>
+ /// 鏂颁笂鎶ョ殑璁惧
+ /// </summary>
+ private Dictionary<int, GetPanelBindResponseDataByMac> dicPanelResInfo = new Dictionary<int, GetPanelBindResponseDataByMac>();
+
+ ///<summary >
+ /// 鍙戦�佽幏鍙栭潰鏉垮懡浠閫氳繃DeviceAddr鑾峰彇]
+ /// </summary>
+ private void SendPanelCommand()
+ {
+ var jObject = new JObject { { "DeviceAddr", curControlDev.DeviceAddr }, { "Cluster_ID", 0 }, { "Command", 5009 } };
+ curControlDev.Gateway.Send(("SearchNewDevice"), jObject.ToString());
+ }
+
+ /// <summary>
+ /// 妫�娴嬭澶囩粦瀹氱殑涓婚
+ /// </summary>
+ /// <param name="topic"></param>
+ /// <param name="resultData"></param>
+ /// <returns></returns>
+ public bool CheckIsDeviceBindTopic(string topic)
+ {
+ if (topic == gatewayId + "Bind/GetDeviceLocalBind_Respon")
+ {
+ return true;
+ }
+ return false;
+ }
+
+ /// <summary>
+ /// 澶勭悊闈㈡澘缁戝畾鐨勮澶囷紝鍜岀鐐规病鏈夊叧绯�
+ /// </summary>
+ /// <param name="topic">涓婚</param>
+ /// <param name="resultData">涓婃姤鏁版嵁</param>
+ private void AdjustGatewayResultData(string topic, string resultData)
+ {
+
+ //鎺ユ敹缁戝畾璁惧锛屽紑鍚帴鏀剁粦瀹氳澶囦俊鎭殑绾跨▼(閲岄潰浼氱瓑寰呬笁绉掕繖鏍�)
+ this.ReceiveSuccessFormThread();
+
+ var result = this.CheckIsDeviceBindTopic(topic);
+ if (result)
+ {
+ lock (dicPanelResInfo)
+ {
+ var jobject = Newtonsoft.Json.Linq.JObject.Parse(resultData);
+ var info = Newtonsoft.Json.JsonConvert.DeserializeObject<GetPanelBindResponseDataByMac>(jobject["Data"].ToString());
+ countBind = info.MaxNumItems;
+ if (info != null)
+ {
+ foreach (var bDev in info.BindList)
+ {
+ if (this.dicPanelResInfo.ContainsKey(bDev.ControllerEpoint) == false)
+ {
+ this.dicPanelResInfo[bDev.ControllerEpoint] = info;
+ }
+ }
+ }
+
+ if (this.dicPanelResInfo.Count == countBind)
+ {
+ //鍋滄鎺ユ敹
+ curControlDev.Gateway.GwResDataAction -= this.AdjustGatewayResultData;
+ //鍒锋柊瓒呮椂鏃堕棿
+ this.waitDeviceTimeOut = -1;
+ }
+ else
+ {
+ //鍒锋柊瓒呮椂鏃堕棿
+ this.waitDeviceTimeOut = 20;
+ }
+ }
+ }
+ }
+
+ /// <summary>
+ /// 寮�鍚帴鏀剁粦瀹氳澶囩殑瓒呮椂绾跨▼
+ /// </summary>
+ private void ReceiveSuccessFormThread()
+ {
+ if (this.isDeviceThreadStart == true)
+ {
+ //绾跨▼宸茬粡寮�鍚�
+ return;
+ }
+ this.isDeviceThreadStart = true;
+
+ HdlThreadLogic.Current.RunThread(() =>
+ {
+ System.Console.WriteLine($"1AAAAA");
+ while (this.waitDeviceTimeOut >= 0)
+ {
+ //绛夊緟涓嬩竴涓洖璺�
+ System.Threading.Thread.Sleep(100);
+ this.waitDeviceTimeOut--;
+ System.Console.WriteLine($"2AAAAA");
+ }
+ System.Console.WriteLine($"3AAAAA");
+ //鍋滄鎺ユ敹
+ bindReceiveAction.Invoke();
+ curControlDev.Gateway.GwResDataAction -= this.AdjustGatewayResultData;
+ System.Console.WriteLine($"4AAAAA");
+ System.Threading.Thread.Sleep(200);
+ System.Console.WriteLine($"5AAAAA");
+
+ //鐩墠灏卞紕涓�涓�
+ Application.RunOnMainThread(() =>
+ {
+ if (this.dicPanelResInfo.Count < countBind)
+ {
+ //鍝嶅簲瓒呮椂,璇烽噸鏂颁笅鎷夊埛鏂拌幏鍙栫粦瀹氫俊鎭�
+ new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.uResponseTimeoutsAndReAccessNetwork), Direction = AMPopTipDirection.None, CloseTime = 1 }.Show(Common.CommonPage.Instance);
+ //鍋滄鎺ユ敹
+ curControlDev.Gateway.GwResDataAction -= this.AdjustGatewayResultData;
+ }
+ System.Console.WriteLine($"6AAAAA");
+ });
+ });
+ }
+ #endregion
+
}
}
--
Gitblit v1.8.0