From c7698e163e43cea9e7f8ee45f8e3f91c9265cca4 Mon Sep 17 00:00:00 2001 From: 黄学彪 <hxb@hdlchina.com.cn> Date: 星期一, 04 十一月 2019 19:11:41 +0800 Subject: [PATCH] 合并了全部的代码 --- ZigbeeApp/Shared/Phone/UserCenter/Device/Bind/ChooseKeyModePage.cs | 432 +++++++++++++++++++++++++++++++++-------------------- 1 files changed, 268 insertions(+), 164 deletions(-) diff --git a/ZigbeeApp/Shared/Phone/UserCenter/Device/Bind/ChooseKeyModePage.cs b/ZigbeeApp/Shared/Phone/UserCenter/Device/Bind/ChooseKeyModePage.cs index 1815322..215a333 100755 --- a/ZigbeeApp/Shared/Phone/UserCenter/Device/Bind/ChooseKeyModePage.cs +++ b/ZigbeeApp/Shared/Phone/UserCenter/Device/Bind/ChooseKeyModePage.cs @@ -1,5 +1,6 @@ 锘縰sing System; using System.Collections.Generic; +using Com.Amap.Api.Location; using Shared.Common; using ZigBee.Device; using static ZigBee.Device.BindObj; @@ -45,6 +46,10 @@ /// 鎸夐敭閰嶇疆鐨勭洰鏍囧垪琛� /// </summary> List<CommonDevice> targetList = new List<CommonDevice>(); + /// <summary> + /// 鏂扮殑鎸夐敭閰嶇疆鐩爣鍒楄〃涓紝鐩爣瀹為檯瀛樺湪鎸夐敭涓紝姝ゆ椂瑕佸垹鎺夌殑鏁版嵁 + /// </summary> + List<CommonDevice> oldTargetList = new List<CommonDevice>(); List<Room> roomList = new List<Room>(); int currentClusterID = 6; public Action<List<BindListResponseObj>> action; @@ -106,207 +111,306 @@ btnFinifh.MouseUpEventHandler += async (sender, e) => { + oldTargetList.Clear(); + bool isFinish = false; btnFinifh.Enable = false; btnFinifh.BackgroundColor = Shared.Common.ZigbeeColor.Current.XMUnSelect; - if (oldModeID != 65535 && oldModeID != currentModeID) + try { - var bindResult = await currentKey.ClearBindInfoAsync(); - if (bindResult.clearBindInfoResponseData != null) + CommonPage.Loading.Start(""); + //1銆佹竻绌烘墍鏈夌洰鏍� + if (currentKey.bindList != null) { - if (bindResult.clearBindInfoResponseData.Result != 0) + var bindResult = await currentKey.ClearBindInfoAsync(); + + if (bindResult != null && bindResult.clearBindInfoResponseData != null) { - new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.BindFailed), Direction = AMPopTipDirection.Up, CloseTime = 1 }.Show(btnFinifh); - CommonPage.Loading.Hide(); - this.RemoveFromParent(); - btnFinifh.Enable = true; - return; + if (bindResult.clearBindInfoResponseData.Result != 0) + { + Application.RunOnMainThread(() => + { + new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.BindFailed), Direction = AMPopTipDirection.Up, CloseTime = 1 }.Show(btnFinifh); + }); + CommonPage.Loading.Hide(); + this.RemoveFromParent(); + btnFinifh.Enable = true; + btnFinifh.BackgroundColor = Shared.Common.ZigbeeColor.Current.XMBlack; + return; + } + else + { + currentKey.bindList.Clear(); + } } else { - currentKey.bindList.Clear(); + Application.RunOnMainThread(() => + { + new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.GwResponseOvertime), Direction = AMPopTipDirection.Up, CloseTime = 1 }.Show(btnFinifh); + }); + CommonPage.Loading.Hide(); + btnFinifh.Enable = true; + btnFinifh.BackgroundColor = Shared.Common.ZigbeeColor.Current.XMBlack; + return; } } - } - else - { - foreach (var bindedDev in currentKey.bindList) + //if (oldModeID != 65535 && oldModeID != currentModeID) + //{ + //var bindResult = await currentKey.ClearBindInfoAsync(); + //if (bindResult.clearBindInfoResponseData != null) + //{ + // if (bindResult.clearBindInfoResponseData.Result != 0) + // { + // Application.RunOnMainThread(() => + // { + // new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.BindFailed), Direction = AMPopTipDirection.Up, CloseTime = 1 }.Show(btnFinifh); + // }); + // CommonPage.Loading.Hide(); + // this.RemoveFromParent(); + // btnFinifh.Enable = true; + // return; + // } + // else + // { + // currentKey.bindList.Clear(); + // } + //} + //} + //else + //{ + // foreach (var bindedDev in currentKey.bindList) + // { + // for (int i = 0; i < targetList.Count; i++) + // { + // var de = targetList[i]; + // if (de.DeviceAddr == bindedDev.BindMacAddr && de.DeviceEpoint == bindedDev.BindEpoint) + // { + // oldTargetList.Add(de); + // targetList.RemoveAt(i); + // i--; + // } + // } + // } + //} + + //2銆侀厤缃ā寮� + Panel.SetWritableValueResponAllData temp = null; + switch (currentModeID) { - for (int i = 0; i < targetList.Count; i++) + case 100: + temp = await currentKey.ConfigureHdlKeyValueAsync(Panel.KeyMode.OnOff_On); + break; + case 101: + temp = await currentKey.ConfigureHdlKeyValueAsync(Panel.KeyMode.OnOff_oFF); + break; + case 102: + temp = await currentKey.ConfigureHdlKeyValueAsync(Panel.KeyMode.OnOff_OnOff); + break; + case 200: + temp = await currentKey.ConfigureHdlKeyValueAsync(Panel.KeyMode.Level_Step_Up); + break; + case 201: + temp = await currentKey.ConfigureHdlKeyValueAsync(Panel.KeyMode.Level_Step_Down); + break; + case 203: + temp = await currentKey.ConfigureHdlKeyValueAsync(Panel.KeyMode.Level_Up); + break; + case 204: + temp = await currentKey.ConfigureHdlKeyValueAsync(Panel.KeyMode.Level_Down); + break; + case 205: + temp = await currentKey.ConfigureHdlKeyValueAsync(Panel.KeyMode.Level_Up_Down); + break; + case 300: + temp = await currentKey.ConfigureHdlKeyValueAsync(Panel.KeyMode.Wcd_Up); + break; + case 301: + temp = await currentKey.ConfigureHdlKeyValueAsync(Panel.KeyMode.Wcd_Down); + break; + case 302: + temp = await currentKey.ConfigureHdlKeyValueAsync(Panel.KeyMode.Wcd_Stop); + break; + case 303: + temp = await currentKey.ConfigureHdlKeyValueAsync(Panel.KeyMode.Wcd_Up_Stop); + break; + case 304: + temp = await currentKey.ConfigureHdlKeyValueAsync(Panel.KeyMode.Wcd_Down_Stop); + break; + } + if (temp != null && temp.setWritableValueResponData != null && temp.setWritableValueResponData.Status == 0) + { + ////鍒犻櫎琚嬀鎺夌殑鏁版嵁 + //foreach (var delDev in oldTargetList) + //{ + // var delDev1 = new BindObj.BindListResponseObj(); + // delDev1.BindType = 0; + // delDev1.BindCluster = currentClusterID; + // delDev1.BindMacAddr = delDev.DeviceAddr; + // delDev1.BindEpoint = delDev.DeviceEpoint; + // var result = await BindInfo.RemoveTargets(delDev1, currentKey); + + // if (result == 0) + // { + // var bindSc = currentKey.bindList.Find(obj => + // (obj.BindType == 0 + // && obj.BindCluster == currentClusterID + // && obj.BindMacAddr == delDev.DeviceAddr + // && obj.BindEpoint == delDev.DeviceEpoint + // )); + // currentKey.bindList.Remove(bindSc); + // } + //} + + //3銆佺粦瀹氭柊鐨勬暟鎹� + var addBindeDev = new AddBindData(); + addBindeDev.DeviceAddr = currentKey.DeviceAddr; + addBindeDev.Epoint = currentKey.DeviceEpoint; + + foreach (var de in targetList) { - var de = targetList[i]; - if (de.DeviceAddr == bindedDev.BindMacAddr && de.DeviceEpoint == bindedDev.BindEpoint) + if (de.DeviceAddr != null) { - targetList.RemoveAt(i); - i--; + var addBindInfo = new AddBindListObj(); + addBindInfo.BindType = 0; + addBindInfo.BindCluster = currentClusterID; + addBindInfo.BindMacAddr = de.DeviceAddr; + addBindInfo.BindEpoint = de.DeviceEpoint; + addBindeDev.BindList.Add(addBindInfo); } } - } - } - var temp = new Panel.SetWritableValueResponAllData(); - switch (currentModeID) - { - case 100: - temp = await currentKey.ConfigureHdlKeyValueAsync(Panel.KeyMode.OnOff_On); - break; - case 101: - temp = await currentKey.ConfigureHdlKeyValueAsync(Panel.KeyMode.OnOff_oFF); - break; - case 102: - temp = await currentKey.ConfigureHdlKeyValueAsync(Panel.KeyMode.OnOff_OnOff); - break; - case 200: - temp = await currentKey.ConfigureHdlKeyValueAsync(Panel.KeyMode.Level_Step_Up); - break; - case 201: - temp = await currentKey.ConfigureHdlKeyValueAsync(Panel.KeyMode.Level_Step_Down); - break; - case 203: - temp = await currentKey.ConfigureHdlKeyValueAsync(Panel.KeyMode.Level_Up); - break; - case 204: - temp = await currentKey.ConfigureHdlKeyValueAsync(Panel.KeyMode.Level_Down); - break; - case 205: - temp = await currentKey.ConfigureHdlKeyValueAsync(Panel.KeyMode.Level_Up_Down); - break; - case 300: - temp = await currentKey.ConfigureHdlKeyValueAsync(Panel.KeyMode.Wcd_Up); - break; - case 301: - temp = await currentKey.ConfigureHdlKeyValueAsync(Panel.KeyMode.Wcd_Down); - break; - case 302: - temp = await currentKey.ConfigureHdlKeyValueAsync(Panel.KeyMode.Wcd_Stop); - break; - case 303: - temp = await currentKey.ConfigureHdlKeyValueAsync(Panel.KeyMode.Wcd_Up_Stop); - break; - case 304: - temp = await currentKey.ConfigureHdlKeyValueAsync(Panel.KeyMode.Wcd_Down_Stop); - break; - } - if (temp.setWritableValueResponData?.Status != 0) - { - new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.ChangeBindMode), Direction = AMPopTipDirection.Up, CloseTime = 2 }.Show(btnFinifh); - btnFinifh.Enable = true; - btnFinifh.BackgroundColor = Shared.Common.ZigbeeColor.Current.XMBlack; - return; - } - else - { - var addBindeDev = new AddBindData(); - addBindeDev.DeviceAddr = currentKey.DeviceAddr; - addBindeDev.Epoint = currentKey.DeviceEpoint; - - foreach (var de in targetList) - { - if (de.DeviceAddr != null) - { - var addBindInfo = new AddBindListObj(); - addBindInfo.BindType = 0; - addBindInfo.BindCluster = currentClusterID; - addBindInfo.BindMacAddr = de.DeviceAddr; - addBindInfo.BindEpoint = de.DeviceEpoint; - addBindeDev.BindList.Add(addBindInfo); - } - } - bool isFinish = false; - try - { - CommonPage.Loading.Start(""); var dev = new AddedDeviceBindResponseAllData(); dev = await currentKey.AddDeviceBindAsync(addBindeDev); - foreach (var ab in dev.addedDeviceBindResponseData?.BindList) + if (dev.addedDeviceBindResponseData == null) { - switch (ab.Result) + Application.RunOnMainThread(() => { - case 0: - currentKey.bindList.Add((BindListResponseObj)ab); + new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.GwResponseOvertime), Direction = AMPopTipDirection.Up, CloseTime = 1 }.Show(btnFinifh); + }); + btnFinifh.Enable = true; + btnFinifh.BackgroundColor = Shared.Common.ZigbeeColor.Current.XMBlack; + } + else + { + foreach (var ab in dev.addedDeviceBindResponseData?.BindList) + { + switch (ab.Result) + { + case 0: + currentKey.bindList.Add((BindListResponseObj)ab); - for (int i = 0; i < targetList.Count; i++) - { - var de = targetList[i]; - var sc1 = new SceneUI(); - if (de.DeviceAddr == null) + for (int i = 0; i < targetList.Count; i++) { - sc1 = (SceneUI)de; + var de = targetList[i]; + var sc1 = new SceneUI(); + if (de.DeviceAddr == null) + { + sc1 = (SceneUI)de; - if (sc1.Id == ab.BindScenesId) - { - targetList.RemoveAt(i); - i--; - } - } - } - isFinish = true; - break; - case 1: - new Tip() - { - MaxWidth = 150, - Text = Language.StringByID(R.MyInternationalizationString.BindErrorAbsence), - Direction = AMPopTipDirection.Up, - CloseTime = 1 - }.Show(btnFinifh); - break; - case 2: - var abr = dev.addBindResultResponseData?.Result; - switch (dev.addBindResultResponseData?.Result) - { - case 0: - currentKey.bindList.Add((BindListResponseObj)ab); - for (int i = 0; i < targetList.Count; i++) - { - var de = targetList[i]; - if (de.DeviceAddr == ab.BindMacAddr && de.DeviceEpoint == ab.BindEpoint) + if (sc1.Id == ab.BindScenesId) { targetList.RemoveAt(i); i--; } } - isFinish = true; - break; - case 140: - new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.BindFull), Direction = AMPopTipDirection.Up, CloseTime = 1 }.Show(btnFinifh); - break; - default: - new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.BindFailed), Direction = AMPopTipDirection.Up, CloseTime = 1 }.Show(btnFinifh); - break; - } - break; - case 3: - new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.BindErrorExisted), Direction = AMPopTipDirection.Up, CloseTime = 1 }.Show(btnFinifh); - break; - case 4: - new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.BindFailed), Direction = AMPopTipDirection.Up, CloseTime = 1 }.Show(btnFinifh); - break; - default: - break; + } + isFinish = true; + break; + case 1: + Application.RunOnMainThread(() => + { + new Tip() + { + MaxWidth = 150, + Text = Language.StringByID(R.MyInternationalizationString.BindErrorAbsence), + Direction = AMPopTipDirection.Up, + CloseTime = 1 + }.Show(btnFinifh); + }); + break; + case 2: + var abr = dev.addBindResultResponseData?.Result; + switch (dev.addBindResultResponseData?.Result) + { + case 0: + currentKey.bindList.Add((BindListResponseObj)ab); + for (int i = 0; i < targetList.Count; i++) + { + var de = targetList[i]; + if (de.DeviceAddr == ab.BindMacAddr && de.DeviceEpoint == ab.BindEpoint) + { + targetList.RemoveAt(i); + i--; + } + } + isFinish = true; + break; + case 140: + Application.RunOnMainThread(() => + { + new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.BindFull), Direction = AMPopTipDirection.Up, CloseTime = 1 }.Show(btnFinifh); + }); + break; + default: + Application.RunOnMainThread(() => + { + new Tip() { MaxWidth = 150, Text = ab.ESName + Language.StringByID(R.MyInternationalizationString.BindFailed), Direction = AMPopTipDirection.Up, CloseTime = 1 }.Show(btnFinifh); + }); + break; + } + break; + case 3: + Application.RunOnMainThread(() => + { + new Tip() { MaxWidth = 150, Text = ab.ESName + Language.StringByID(R.MyInternationalizationString.BindErrorExisted), Direction = AMPopTipDirection.Up, CloseTime = 1 }.Show(btnFinifh); + }); + break; + case 4: + Application.RunOnMainThread(() => + { + new Tip() { MaxWidth = 150, Text = ab.ESName + Language.StringByID(R.MyInternationalizationString.BindFailed), Direction = AMPopTipDirection.Up, CloseTime = 1 }.Show(btnFinifh); + }); + break; + default: + Application.RunOnMainThread(() => + { + new Tip() { MaxWidth = 150, Text = ab.ESName + Language.StringByID(R.MyInternationalizationString.BindFailed), Direction = AMPopTipDirection.Up, CloseTime = 1 }.Show(btnFinifh); + }); + break; + } } } } - catch { } - finally + else { - if (isFinish) + Application.RunOnMainThread(() => { - if (action != null) - { - action(currentKey.bindList); - - } - this.RemoveFromParent(); - } - else - { - this.RemoveFromParent(); - } - CommonPage.Loading.Hide(); + new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.ChangeBindMode), Direction = AMPopTipDirection.Up, CloseTime = 2 }.Show(btnFinifh); + }); btnFinifh.Enable = true; btnFinifh.BackgroundColor = Shared.Common.ZigbeeColor.Current.XMBlack; } } + catch { } + finally + { + if (isFinish) + { + if (action != null) + { + action(currentKey.bindList); + + } + this.RemoveFromParent(); + } + else + { + this.RemoveFromParent(); + } + CommonPage.Loading.Hide(); + btnFinifh.Enable = true; + btnFinifh.BackgroundColor = Shared.Common.ZigbeeColor.Current.XMBlack; + } }; #endregion } -- Gitblit v1.8.0