From 34b65350abbb8b740b9c3bc0b43254cbbe23fcb5 Mon Sep 17 00:00:00 2001 From: xm <1271024303@qq.com> Date: 星期二, 19 五月 2020 09:31:44 +0800 Subject: [PATCH] 合并代码,更改面板目标信息 --- ZigbeeApp/Shared/Phone/UserCenter/Device/Panel/PanelFangyueFreshAirTargetsForm.cs | 292 ++++++++++++++++++++++++++++++++++++++++++++++++++------- 1 files changed, 253 insertions(+), 39 deletions(-) diff --git a/ZigbeeApp/Shared/Phone/UserCenter/Device/Panel/PanelFangyueFreshAirTargetsForm.cs b/ZigbeeApp/Shared/Phone/UserCenter/Device/Panel/PanelFangyueFreshAirTargetsForm.cs index e52c72f..4a878f5 100644 --- a/ZigbeeApp/Shared/Phone/UserCenter/Device/Panel/PanelFangyueFreshAirTargetsForm.cs +++ b/ZigbeeApp/Shared/Phone/UserCenter/Device/Panel/PanelFangyueFreshAirTargetsForm.cs @@ -103,6 +103,7 @@ /// PM缁戝畾鐩爣鍥炶皟 /// </summary> public Action<string> actionPMTarget = null; + #endregion #region UI璁捐 @@ -333,6 +334,19 @@ } } + if (index == roomTempList.Count - 1 && index > 3) + { + var btnRoomFrameLayoutEmpty = new FrameLayout + { + Height = Application.GetMinReal(159), + Width = Application.GetMinReal(50), + Y = Application.GetRealHeight(23), + X = Application.GetRealWidth(5), + BorderWidth = 1, + }; + btnHorizontalScrolViewLayout.AddChidren(btnRoomFrameLayoutEmpty); + } + EventHandler<MouseEventArgs> eHandlerRoom = (sender, e) => { if (!btnRoom.IsSelected) @@ -358,7 +372,6 @@ curentOldRoomFrameLayout.BackgroundImagePath = "Item/RoomIconBackgroundSelected.png"; } curRoom = room; - curControlDev.RoomId = room.Id; //鏂伴闈㈡澘淇濆瓨浣胯兘 btnFinifh.Enable = true; @@ -472,12 +485,20 @@ break; case 2: devicePic.UnSelectedImagePath = "Device/SensorTemperature.png"; + if (device.Type == DeviceType.PMSensor) + { + btnBindName.Text = Common.LocalDevice.Current.GetDeviceEpointName(device) + "-" + Language.StringByID(R.MyInternationalizationString.TemperatureSensor); + } break; case 3: devicePic.UnSelectedImagePath = "Device/SensorHumidity.png"; + if (device.Type == DeviceType.PMSensor) + { + btnBindName.Text = Common.LocalDevice.Current.GetDeviceEpointName(device) + "-" + Language.StringByID(R.MyInternationalizationString.HumiditySensor); + } break; case 4: - devicePic.UnSelectedImagePath = "Device/FreshAirEpoint.png"; + devicePic.UnSelectedImagePath = "Device/AirQualitySensorEpoint.png"; break; } #endregion @@ -706,7 +727,7 @@ //鑾峰彇鎵�鏈夋埧闂翠腑鍖归厤鐨勮兘缁戠殑鐩爣 currentPanelSupportBindDeviceList = GetAllRoomSupportDeviceList(); - //鑾峰彇闈㈡澘涓瓨鍦ㄧ殑缁戝畾鐩爣 + //鑾峰彇闈㈡澘涓瓨鍦ㄧ殑缁戝畾鐩爣 var panelBindListRes = await this.curControlDev.GetDeviceBindAsync(); if (panelBindListRes != null && panelBindListRes.getAllBindResponseData != null) { @@ -725,17 +746,18 @@ new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.GwResponseOvertime), Direction = AMPopTipDirection.None, CloseTime = 1 }.Show(Common.CommonPage.Instance); }); } + targetList.Clear(); //閫変腑鐩爣鍒楄〃 targetList if (currentPanelSupportBindDeviceList.Count != 0 && curControlDev.bindList.Count != 0) { - foreach (var bindDev in currentPanelSupportBindDeviceList) + foreach (var bindDev in curControlDev.bindList) { - var mainKey = bindDev.DeviceAddr + bindDev.DeviceEpoint; - var dev = curControlDev.bindList.Find(obj => (obj != null) && (obj.BindMacAddr + obj.BindEpoint == mainKey)); + var mainKey = bindDev.BindMacAddr + bindDev.BindEpoint; + var dev = currentPanelSupportBindDeviceList.Find(obj => (obj != null) && (obj.DeviceAddr + obj.DeviceEpoint == mainKey)); if (dev != null) { - var device = LocalDevice.Current.GetDevice(bindDev.DeviceAddr, bindDev.DeviceEpoint); + var device = LocalDevice.Current.GetDevice(dev.DeviceAddr, dev.DeviceEpoint); if (device != null) { switch (curDeviceBindType) @@ -764,6 +786,14 @@ oldTargetList.Add(device); } } + if (device.Type == DeviceType.PMSensor) + { + if (bindDev.BindCluster == 1026) + { + targetList.Add(device); + oldTargetList.Add(device); + } + } break; case 3: if (device.Type == DeviceType.TemperatureSensor) @@ -780,9 +810,25 @@ targetList.Add(device); oldTargetList.Add(device); } + if (device.Type == DeviceType.PMSensor) + { + if (bindDev.BindCluster == 1029) + { + targetList.Add(device); + oldTargetList.Add(device); + } + } break; case 4: //PM2.5 + if (device.Type == DeviceType.PMSensor) + { + if (bindDev.BindCluster == 1066) + { + targetList.Add(device); + oldTargetList.Add(device); + } + } break; } @@ -865,6 +911,7 @@ /// <param name="curControlDev"></param> void SaveTarget() { + btnFinifh.Enable = false; if (targetList.Count == 0) { //绌虹洰鏍� @@ -898,6 +945,7 @@ break; case 4: //PM2.5 + removeDevice.BindCluster = 1066; break; } removeDevice.BindMacAddr = bd.DeviceAddr; @@ -944,6 +992,7 @@ btnFinifh.BackgroundColor = Shared.Common.ZigbeeColor.Current.XMBlack; this.RemoveFromParent(); }); + } else { @@ -956,6 +1005,17 @@ }); return; } + } + else + { + Application.RunOnMainThread(() => + { + new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.OperrateFailed), Direction = AMPopTipDirection.None, CloseTime = 1 }.Show(CommonPage.Instance); + btnFinifh.Enable = true; + btnFinifh.BackgroundColor = Shared.Common.ZigbeeColor.Current.XMBlack; + CommonPage.Loading.Hide(); + }); + return; } } } @@ -979,6 +1039,11 @@ catch (Exception ex) { var mess = ex.Message; + Application.RunOnMainThread(() => + { + CommonPage.Loading.Hide(); + }); + btnFinifh.Enable = true; } }); } @@ -1012,33 +1077,56 @@ { foreach (var bd in oldTargetList) { - var delDevice = new DelDeviceBindData(); - delDevice.DeviceAddr = curControlDev.DeviceAddr; - delDevice.Epoint = curControlDev.DeviceEpoint; - - var removeDevice = new RemoveBindListObj(); - removeDevice.BindType = 0; - switch (curDeviceBindType) - { - case 1: - removeDevice.BindCluster = 514; - break; - case 2: - removeDevice.BindCluster = 1026; - break; - case 3: - removeDevice.BindCluster = 1029; - break; - case 4: - //PM2.5 - break; - } - removeDevice.BindMacAddr = bd.DeviceAddr; - removeDevice.BindEpoint = bd.DeviceEpoint; - delDevice.RemoveBindList.Add(removeDevice); - + var delDevice = DelBindDevice(bd); var delResult = new DelDeviceBindResponseAllData(); delResult = await curControlDev.DelDeviceBindAsync(delDevice); + if (delResult == null || delResult.removeBindResultResponseData == null) + { + Application.RunOnMainThread(() => + { + new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.BindFailed), Direction = AMPopTipDirection.None, CloseTime = 1 }.Show(CommonPage.Instance); + btnFinifh.Enable = true; + btnFinifh.BackgroundColor = Shared.Common.ZigbeeColor.Current.XMBlack; + CommonPage.Loading.Hide(); + }); + return; + } + if (delResult != null && delResult.removeBindResultResponseData != null) + { + if (delResult.removeBindResultResponseData.Result != 0) + { + Application.RunOnMainThread(() => + { + new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.BindFailed), Direction = AMPopTipDirection.None, CloseTime = 1 }.Show(CommonPage.Instance); + btnFinifh.Enable = true; + btnFinifh.BackgroundColor = Shared.Common.ZigbeeColor.Current.XMBlack; + CommonPage.Loading.Hide(); + }); + return; + } + } + } + } + else + { + //妫�娴嬪凡缁忕粦瀹氱殑鐩爣鏄惁涓嶅湪鏈湴鎴栬�呮病鏈夊垎閰嶅埌浠讳綍鎴块棿涓� + //姝ゆ椂闇�瑕佸垹闄ゅ凡缁忚缁戝畾鍒扮洰鏍囷紝鎵嶈兘缁х画缁戝畾鏂扮洰鏍� + if (curBindDevice != null) + { + var delDevice = DelBindDevice(curBindDevice); + var delResult = new DelDeviceBindResponseAllData(); + delResult = await curControlDev.DelDeviceBindAsync(delDevice); + if (delResult == null || delResult.removeBindResultResponseData == null) + { + Application.RunOnMainThread(() => + { + new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.BindFailed), Direction = AMPopTipDirection.None, CloseTime = 1 }.Show(CommonPage.Instance); + btnFinifh.Enable = true; + btnFinifh.BackgroundColor = Shared.Common.ZigbeeColor.Current.XMBlack; + CommonPage.Loading.Hide(); + }); + return; + } if (delResult != null && delResult.removeBindResultResponseData != null) { if (delResult.removeBindResultResponseData.Result != 0) @@ -1077,13 +1165,29 @@ break; case 4: //PM2.5 + addBindInfo.BindCluster = 1066; break; } addBindInfo.BindType = 0; addBindInfo.BindMacAddr = de.DeviceAddr; addBindInfo.BindEpoint = de.DeviceEpoint; + addBindeDev.BindName = de.DeviceEpointName; + switch (curDeviceBindType) + { + case 2: + if (de.Type == DeviceType.PMSensor) + { + addBindeDev.BindName = Common.LocalDevice.Current.GetDeviceEpointName(de) + "-" + Language.StringByID(R.MyInternationalizationString.TemperatureSensor); + } + break; + case 3: + if (de.Type == DeviceType.PMSensor) + { + addBindeDev.BindName = Common.LocalDevice.Current.GetDeviceEpointName(de) + "-" + Language.StringByID(R.MyInternationalizationString.HumiditySensor); + } + break; + } addBindeDev.BindList.Add(addBindInfo); - bindName = de.DeviceEpointName; } var dev = new AddedDeviceBindResponseAllData(); @@ -1103,33 +1207,31 @@ { if (dev.addedDeviceBindResponseData.Result == 0) { - curControlDev.bindList = dev.addedDeviceBindResponseData.BindList; targetList.Clear(); - switch (curDeviceBindType) { case 1: if (actionFreshAirTarget != null) { - actionFreshAirTarget(bindName); + actionFreshAirTarget(addBindeDev.BindName); } break; case 2: if (actionTemperatureTarget != null) { - actionTemperatureTarget(bindName); + actionTemperatureTarget(addBindeDev.BindName); } break; case 3: if (actionHumidityTarget != null) { - actionHumidityTarget(bindName); + actionHumidityTarget(addBindeDev.BindName); } break; case 4: if (actionPMTarget != null) { - actionPMTarget(bindName); + actionPMTarget(addBindeDev.BindName); } break; } @@ -1180,6 +1282,11 @@ } catch (Exception ex) { + Application.RunOnMainThread(() => + { + CommonPage.Loading.Hide(); + }); + btnFinifh.Enable = true; var mess = ex.Message; } }); @@ -1235,6 +1342,40 @@ } /// <summary> + /// 妫�娴嬪凡缁忕粦瀹氱殑鐩爣鏄惁涓嶅湪鏈湴鎴栬�呮病鏈夊垎閰嶅埌浠讳綍鎴块棿涓� + /// </summary> + /// <returns></returns> + private DelDeviceBindData DelBindDevice(CommonDevice bd) + { + var delDevice = new DelDeviceBindData(); + delDevice.DeviceAddr = curControlDev.DeviceAddr; + delDevice.Epoint = curControlDev.DeviceEpoint; + + var removeDevice = new RemoveBindListObj(); + removeDevice.BindType = 0; + switch (curDeviceBindType) + { + case 1: + removeDevice.BindCluster = 514; + break; + case 2: + removeDevice.BindCluster = 1026; + break; + case 3: + removeDevice.BindCluster = 1029; + break; + case 4: + //PM2.5 + removeDevice.BindCluster = 1066; + break; + } + removeDevice.BindMacAddr = bd.DeviceAddr; + removeDevice.BindEpoint = bd.DeviceEpoint; + delDevice.RemoveBindList.Add(removeDevice); + return delDevice; + } + + /// <summary> /// 鑳芥樉绀虹殑鎴块棿鍒楄〃 /// </summary> private List<Room> GetSupportRoomList() @@ -1265,6 +1406,7 @@ foreach (var de in room.ListDevice) { var device = LocalDevice.Current.GetDevice(de); + if (device != null) { //鑾峰彇璁惧绫诲瀷鐨� @@ -1299,6 +1441,17 @@ } break; case 4: + foreach (var de in room.ListDevice) + { + var device = LocalDevice.Current.GetDevice(de); + if (device != null) + { + if (device.Type == DeviceType.PMSensor) + { + roomIncludeMatchDevice.Add(device); + } + } + } break; } @@ -1337,12 +1490,28 @@ var device = LocalDevice.Current.GetDevice(de); if (device != null) { + //鐢垫睜璁惧涓嶆敮鎸佺粦瀹� + if (device.ZigbeeType != 1) + { + continue; + } if (device.Type == DeviceType.TemperatureSensor) { var dev = device as TemperatureSensor; if (dev.SensorDiv == 1) { roomIncludeMatchTempDevice.Add(device); + } + } + else if (device.Type == DeviceType.PMSensor) + { + var dev = device as PMSensor; + foreach (var clu in dev.InClusterList) + { + if (clu.InCluster == 1026) + { + roomIncludeMatchTempDevice.Add(device); + } } } } @@ -1362,12 +1531,28 @@ var device = LocalDevice.Current.GetDevice(de); if (device != null) { + //鐢垫睜璁惧涓嶆敮鎸佺粦瀹� + if (device.ZigbeeType != 1) + { + continue; + } if (device.Type == DeviceType.TemperatureSensor) { var dev = device as TemperatureSensor; if (dev.SensorDiv == 2) { roomIncludeMatchHumpDevice.Add(device); + } + } + else if (device.Type == DeviceType.PMSensor) + { + var dev = device as PMSensor; + foreach (var clu in dev.InClusterList) + { + if (clu.InCluster == 1029) + { + roomIncludeMatchHumpDevice.Add(device); + } } } } @@ -1491,6 +1676,24 @@ } break; case 4: + foreach (var r in supportRoomList) + { + if (r.ListDevice.Count == 0) + { + continue; + } + foreach (var deviceKeys in r.ListDevice) + { + var device = LocalDevice.Current.GetDevice(deviceKeys); + if (device != null) + { + if (device.Type == DeviceType.PMSensor) + { + currentPanelBindSupportDeviceListTemp.Add(device); + } + } + } + } break; } return currentPanelBindSupportDeviceListTemp; @@ -1544,6 +1747,17 @@ } break; case 4: + foreach (var deviceKeys in curRoom.ListDevice) + { + var device = LocalDevice.Current.GetDevice(deviceKeys); + if (device != null) + { + if (device.Type == DeviceType.PMSensor) + { + curRoomDeviceListTemp.Add(device); + } + } + } break; } return curRoomDeviceListTemp; -- Gitblit v1.8.0