xm
2020-07-13 412e0af11df2b1d7986adf002e7997d82344ab3e
ZigbeeApp/Shared/Phone/UserCenter/Device/Bind/PaneTargetsBaseForm.cs
@@ -732,7 +732,7 @@
                        });
                    }
                    targetList.Clear();
                    oldTargetList.Clear();
                    //选中目标列表 targetList
                    if (curControlDev.bindList.Count != 0)
                    {
@@ -901,50 +901,18 @@
                        Application.RunOnMainThread(() => { CommonPage.Loading.Start(""); });
                        if (btnTipPic.IsSelected)
                        {
                            //绑定空目标必须取消按键中已经存在的目标
                            //删除情况1:绑定空目标必须取消按键中已经存在的目标
                            if (oldTargetList.Count != 0)
                            {
                                //删除取消的目标
                                //删除按键中已经绑定的目标个数【删除成功个数】
                                int sOldTargetListCount = 0;
                                foreach (var bd in oldTargetList)
                                {
                                    var delDevice = new DelDeviceBindData();
                                    delDevice.DeviceAddr = curControlDev.DeviceAddr;
                                    delDevice.Epoint = curControlDev.DeviceEpoint;
                                    var delDevice = DelBindDevice(bd);
                                    var removeDevice = new RemoveBindListObj();
                                    removeDevice.BindType = 0;
                                    switch (curDeviceBindType)
                                    {
                                        case BindInfo.BindType.FreshAir:
                                            removeDevice.BindCluster = 514;
                                            break;
                                        case BindInfo.BindType.Temperature:
                                            removeDevice.BindCluster = 1026;
                                            break;
                                        case BindInfo.BindType.Humidity:
                                            removeDevice.BindCluster = 1029;
                                            break;
                                        case BindInfo.BindType.PM:
                                            removeDevice.BindCluster = 1066;
                                            break;
                                        case BindInfo.BindType.AC:
                                            removeDevice.BindCluster = 513;//Ac需要绑定2个簇513和514
                                            break;
                                    }
                                    removeDevice.BindMacAddr = bd.DeviceAddr;
                                    removeDevice.BindEpoint = bd.DeviceEpoint;
                                    delDevice.RemoveBindList.Add(removeDevice);
                                    if (curDeviceBindType == BindInfo.BindType.AC)
                                    {
                                        //要移除空调:需要移除513,514
                                        var removeDevice3 = new RemoveBindListObj();
                                        removeDevice3.BindCluster = 514;
                                        removeDevice3.BindType = 0;
                                        removeDevice3.BindMacAddr = bd.DeviceAddr;
                                        removeDevice3.BindEpoint = bd.DeviceEpoint;
                                        delDevice.RemoveBindList.Add(removeDevice3);
                                    }
                                    //此次按键中需要移除的目标个数【同一个目标携带的多个功能删除成功的个数】
                                    int sRemoveBindListCount = 0;
                                    var delResult = new DelDeviceBindResponseAllData();
                                    delResult = HdlDeviceBindLogic.Current.DelDeviceBindAsync(delDevice);
@@ -977,14 +945,24 @@
                                                {
                                                    if (d.Result == 0 || d.Result == 1)
                                                    {
                                                        TargesBindName();
                                                        Application.RunOnMainThread(() =>
                                                        sRemoveBindListCount++;
                                                        if (sRemoveBindListCount == delDevice.RemoveBindList.Count)
                                                        {
                                                            CommonPage.Loading.Hide();
                                                            btnFinifh.Enable = true;
                                                            btnFinifh.BackgroundColor = Shared.Common.ZigbeeColor.Current.XMBlack;
                                                            this.RemoveFromParent();
                                                        });
                                                            sOldTargetListCount++;
                                                        }
                                                        //按键目标中的该类型个数都删除成功
                                                        if (sOldTargetListCount == oldTargetList.Count)
                                                        {
                                                            TargesBindName();
                                                            Application.RunOnMainThread(() =>
                                                            {
                                                                CommonPage.Loading.Hide();
                                                                btnFinifh.Enable = true;
                                                                btnFinifh.BackgroundColor = Shared.Common.ZigbeeColor.Current.XMBlack;
                                                                this.RemoveFromParent();
                                                            });
                                                        }
                                                    }
                                                    else
                                                    {
@@ -1004,14 +982,19 @@
                                        {
                                            if (delResult.removeBindResultResponseData.Result == 0)
                                            {
                                                TargesBindName();
                                                Application.RunOnMainThread(() =>
                                                sOldTargetListCount++;
                                                //按键目标中的该类型个数都删除成功
                                                if (sOldTargetListCount == oldTargetList.Count)
                                                {
                                                    CommonPage.Loading.Hide();
                                                    btnFinifh.Enable = true;
                                                    btnFinifh.BackgroundColor = Shared.Common.ZigbeeColor.Current.XMBlack;
                                                    this.RemoveFromParent();
                                                });
                                                    TargesBindName();
                                                    Application.RunOnMainThread(() =>
                                                    {
                                                        CommonPage.Loading.Hide();
                                                        btnFinifh.Enable = true;
                                                        btnFinifh.BackgroundColor = Shared.Common.ZigbeeColor.Current.XMBlack;
                                                        this.RemoveFromParent();
                                                    });
                                                }
                                            }
                                            else
                                            {
@@ -1080,11 +1063,17 @@
                    {
                        Application.RunOnMainThread(() => { CommonPage.Loading.Start(""); });
                        //删除按键已经存在的目标
                        //删除情况2:按键之前已经存在的目标
                        if (oldTargetList.Count != 0)
                        {
                            //删除按键中已经绑定的目标个数【删除成功个数】
                            int sOldTargetListCount = 0;
                            foreach (var bd in oldTargetList)
                            {
                                //此次按键中需要移除的目标个数【同一个目标携带的多个功能删除成功的个数】
                                int sRemoveBindListCount = 0;
                                var delDevice = DelBindDevice(bd);
                                var delResult = new DelDeviceBindResponseAllData();
                                delResult = HdlDeviceBindLogic.Current.DelDeviceBindAsync(delDevice);
@@ -1127,91 +1116,43 @@
                                                    });
                                                    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 = HdlDeviceBindLogic.Current.DelDeviceBindAsync(delDevice);
                                if (delResult == null)
                                {
                                    Application.RunOnMainThread(() =>
                                    {
                                        new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.BindFailed), Direction = AMPopTipDirection.None, CloseTime = 1 }.Show(CommonPage.Instance);
                                        CommonPage.Loading.Hide();
                                        ShowReLoadView();
                                        ReLoadAction += () =>
                                        {
                                            this.midFrameLayout.RemoveAll();
                                            //初始化设备数据
                                            CommonPage.Loading.Start("");
                                            MidFrameLayoutContent();
                                            InitData(true);
                                        };
                                    });
                                    return;
                                }
                                else
                                {
                                    if (delResult.removeBindResultResponseData == null)
                                    {
                                        if (delResult.delDeviceBindResponseData != null)
                                        {
                                            foreach (var d in delResult.delDeviceBindResponseData.RemoveBindList)
                                            {
                                                if (d.Result != 0 && d.Result != 1)
                                                sRemoveBindListCount++;
                                                if (sRemoveBindListCount == delDevice.RemoveBindList.Count)
                                                {
                                                    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;
                                                    sOldTargetListCount++;
                                                }
                                            }
                                        }
                                    }
                                }
                                if (delResult != null && delResult.removeBindResultResponseData != null)
                                {
                                    if (delResult.removeBindResultResponseData.Result != 0)
                                    else
                                    {
                                        Application.RunOnMainThread(() =>
                                        if (delResult.removeBindResultResponseData.Result != 0)
                                        {
                                            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;
                                            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;
                                        }
                                        sOldTargetListCount++;
                                    }
                                }
                            }
                            if (sOldTargetListCount != oldTargetList.Count)
                            {
                                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;
                            }
                        }
@@ -1460,7 +1401,6 @@
                    {
                        if (device.Type == DeviceType.FreshAir)
                        {
                            targetList.Add(device);
                            oldTargetList.Add(device);
                        }
                    }
@@ -1471,7 +1411,6 @@
                        var bDev = device as TemperatureSensor;
                        if (bDev.SensorDiv == 1)
                        {
                            targetList.Add(device);
                            oldTargetList.Add(device);
                        }
                    }
@@ -1479,7 +1418,6 @@
                    {
                        if (bindDev.BindCluster == 1026)
                        {
                            targetList.Add(device);
                            oldTargetList.Add(device);
                        }
                    }
@@ -1490,20 +1428,17 @@
                        var bDev = device as TemperatureSensor;
                        if (bDev.SensorDiv == 2)
                        {
                            targetList.Add(device);
                            oldTargetList.Add(device);
                        }
                    }
                    if (device.Type == DeviceType.FreshAirHumiditySensor)
                    {
                        targetList.Add(device);
                        oldTargetList.Add(device);
                    }
                    if (device.Type == DeviceType.PMSensor)
                    {
                        if (bindDev.BindCluster == 1029)
                        {
                            targetList.Add(device);
                            oldTargetList.Add(device);
                        }
                    }
@@ -1513,7 +1448,6 @@
                    {
                        if (bindDev.BindCluster == 1066)
                        {
                            targetList.Add(device);
                            oldTargetList.Add(device);
                        }
                    }
@@ -1523,12 +1457,18 @@
                    {
                        if (bindDev.BindCluster == 513)
                        {
                            targetList.Add(device);
                            oldTargetList.Add(device);
                        }
                    }
                    break;
            }
            targetList.Clear();
            if (oldTargetList.Count != 0)
            {
                targetList.Add(oldTargetList[0]);
            }
            targetListTemp.Clear();
            foreach (var d in targetList)
            {
@@ -1588,14 +1528,26 @@
                    removeDevice.BindCluster = 1066;
                    break;
                case BindInfo.BindType.AC:
                    removeDevice.BindCluster = 513;
                    removeDevice.BindCluster = 513;//Ac需要绑定2个簇513和514
                    break;
            }
            removeDevice.BindMacAddr = bd.DeviceAddr;
            removeDevice.BindEpoint = bd.DeviceEpoint;
            delDevice.RemoveBindList.Add(removeDevice);
            if (curDeviceBindType == BindInfo.BindType.AC)
            {
                //要移除空调:需要移除513,514
                var removeDevice3 = new RemoveBindListObj();
                removeDevice3.BindCluster = 514;
                removeDevice3.BindType = 0;
                removeDevice3.BindMacAddr = bd.DeviceAddr;
                removeDevice3.BindEpoint = bd.DeviceEpoint;
                delDevice.RemoveBindList.Add(removeDevice3);
            }
            return delDevice;
        }
        #endregion
        #region 移除方法