黄学彪
2020-06-18 2450c12c825ad4d78d1572da2fa421706db2df2f
ZigbeeApp/Shared/Phone/UserCenter/Device/Panel/PanelFangyueFreshAirTargetsForm.cs
@@ -38,7 +38,7 @@
        /// <summary>
        /// 显示被绑定设备或场景的view
        /// </summary>
        VerticalFrameRefreshControl midVerticalScrolViewLayout;
        VerticalRefreshLayout midVerticalScrolViewLayout;
        /// <summary>
        /// 显示房间的view
        /// </summary>
@@ -103,6 +103,7 @@
        /// PM绑定目标回调
        /// </summary>
        public Action<string> actionPMTarget = null;
        #endregion
        #region UI设计 
@@ -220,7 +221,7 @@
            btnMidTopLayout.AddChidren(btnHorizontalScrolViewLayout);
            //设备栏
            midVerticalScrolViewLayout = new VerticalFrameRefreshControl()
            midVerticalScrolViewLayout = new VerticalRefreshLayout()
            {
                Y = btnMidTopLayout.Bottom,
                Height = Application.GetRealHeight(1145),
@@ -331,6 +332,19 @@
                        curentOldRoom = btnRoom;
                        curentOldRoomFrameLayout = btnRoomFrameLayout;
                    }
                }
                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) =>
@@ -471,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 +728,7 @@
                    currentPanelSupportBindDeviceList = GetAllRoomSupportDeviceList();
                    //获取面板中存在的绑定目标
                    var panelBindListRes = await this.curControlDev.GetDeviceBindAsync();
                    var panelBindListRes = HdlDeviceBindLogic.Current.GetDeviceBindAsync(curControlDev);
                    if (panelBindListRes != null && panelBindListRes.getAllBindResponseData != null)
                    {
                        curControlDev.bindList.Clear();
@@ -724,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)
@@ -763,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)
@@ -779,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;
                                    }
@@ -864,6 +911,7 @@
        /// <param name="curControlDev"></param>
        void SaveTarget()
        {
            btnFinifh.Enable = false;
            if (targetList.Count == 0)
            {
                //空目标
@@ -897,6 +945,7 @@
                                        break;
                                    case 4:
                                        //PM2.5
                                        removeDevice.BindCluster = 1066;
                                        break;
                                }
                                removeDevice.BindMacAddr = bd.DeviceAddr;
@@ -904,56 +953,128 @@
                                delDevice.RemoveBindList.Add(removeDevice);
                                var delResult = new DelDeviceBindResponseAllData();
                                delResult = await curControlDev.DelDeviceBindAsync(delDevice);
                                if (delResult != null && delResult.removeBindResultResponseData != null)
                                delResult = HdlDeviceBindLogic.Current.DelDeviceBindAsync(delDevice);
                                if (delResult == null)
                                {
                                    if (delResult.removeBindResultResponseData.Result == 0)
                                    Application.RunOnMainThread(() =>
                                    {
                                        switch (curDeviceBindType)
                                        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 (delResult.removeBindResultResponseData == null)
                                    {
                                        if (delResult.delDeviceBindResponseData != null)
                                        {
                                            case 1:
                                                if (actionFreshAirTarget != null)
                                            foreach (var d in delResult.delDeviceBindResponseData.RemoveBindList)
                                            {
                                                if (d.Result == 1)
                                                {
                                                    actionFreshAirTarget("");
                                                    switch (curDeviceBindType)
                                                    {
                                                        case 1:
                                                            if (actionFreshAirTarget != null)
                                                            {
                                                                actionFreshAirTarget("");
                                                            }
                                                            break;
                                                        case 2:
                                                            if (actionTemperatureTarget != null)
                                                            {
                                                                actionTemperatureTarget("");
                                                            }
                                                            break;
                                                        case 3:
                                                            if (actionHumidityTarget != null)
                                                            {
                                                                actionHumidityTarget("");
                                                            }
                                                            break;
                                                        case 4:
                                                            if (actionPMTarget != null)
                                                            {
                                                                actionPMTarget("");
                                                            }
                                                            break;
                                                    }
                                                    Application.RunOnMainThread(() =>
                                                    {
                                                        CommonPage.Loading.Hide();
                                                        btnFinifh.Enable = true;
                                                        btnFinifh.BackgroundColor = Shared.Common.ZigbeeColor.Current.XMBlack;
                                                        this.RemoveFromParent();
                                                    });
                                                }
                                                break;
                                            case 2:
                                                if (actionTemperatureTarget != null)
                                                else
                                                {
                                                    actionTemperatureTarget("");
                                                    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;
                                                }
                                                break;
                                            case 3:
                                                if (actionHumidityTarget != null)
                                                {
                                                    actionHumidityTarget("");
                                                }
                                                break;
                                            case 4:
                                                if (actionPMTarget != null)
                                                {
                                                    actionPMTarget("");
                                                }
                                                break;
                                            }
                                        }
                                        Application.RunOnMainThread(() =>
                                        {
                                            CommonPage.Loading.Hide();
                                            btnFinifh.Enable = true;
                                            btnFinifh.BackgroundColor = Shared.Common.ZigbeeColor.Current.XMBlack;
                                            this.RemoveFromParent();
                                        });
                                    }
                                    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;
                                            switch (curDeviceBindType)
                                            {
                                                case 1:
                                                    if (actionFreshAirTarget != null)
                                                    {
                                                        actionFreshAirTarget("");
                                                    }
                                                    break;
                                                case 2:
                                                    if (actionTemperatureTarget != null)
                                                    {
                                                        actionTemperatureTarget("");
                                                    }
                                                    break;
                                                case 3:
                                                    if (actionHumidityTarget != null)
                                                    {
                                                        actionHumidityTarget("");
                                                    }
                                                    break;
                                                case 4:
                                                    if (actionPMTarget != null)
                                                    {
                                                        actionPMTarget("");
                                                    }
                                                    break;
                                            }
                                            Application.RunOnMainThread(() =>
                                            {
                                                CommonPage.Loading.Hide();
                                                btnFinifh.Enable = true;
                                                btnFinifh.BackgroundColor = Shared.Common.ZigbeeColor.Current.XMBlack;
                                                this.RemoveFromParent();
                                            });
                                        }
                                        else
                                        {
                                            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;
                                        }
                                    }
                                }
                            }
@@ -978,6 +1099,11 @@
                    catch (Exception ex)
                    {
                        var mess = ex.Message;
                        Application.RunOnMainThread(() =>
                        {
                            CommonPage.Loading.Hide();
                        });
                        btnFinifh.Enable = true;
                    }
                });
            }
@@ -1013,7 +1139,42 @@
                            {
                                var delDevice = DelBindDevice(bd);
                                var delResult = new DelDeviceBindResponseAllData();
                                delResult = await curControlDev.DelDeviceBindAsync(delDevice);
                                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);
                                        btnFinifh.Enable = true;
                                        btnFinifh.BackgroundColor = Shared.Common.ZigbeeColor.Current.XMBlack;
                                        CommonPage.Loading.Hide();
                                    });
                                    return;
                                }
                                else
                                {
                                    if (delResult.removeBindResultResponseData == null)
                                    {
                                        if (delResult.delDeviceBindResponseData != null)
                                        {
                                            foreach (var d in delResult.delDeviceBindResponseData.RemoveBindList)
                                            {
                                                if (d.Result != 1)
                                                {
                                                    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)
@@ -1038,7 +1199,42 @@
                            {
                                var delDevice = DelBindDevice(curBindDevice);
                                var delResult = new DelDeviceBindResponseAllData();
                                delResult = await curControlDev.DelDeviceBindAsync(delDevice);
                                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);
                                        btnFinifh.Enable = true;
                                        btnFinifh.BackgroundColor = Shared.Common.ZigbeeColor.Current.XMBlack;
                                        CommonPage.Loading.Hide();
                                    });
                                    return;
                                }
                                else
                                {
                                    if (delResult.removeBindResultResponseData == null)
                                    {
                                        if (delResult.delDeviceBindResponseData != null)
                                        {
                                            foreach (var d in delResult.delDeviceBindResponseData.RemoveBindList)
                                            {
                                                if (d.Result != 1)
                                                {
                                                    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,17 +1273,33 @@
                                    break;
                                case 4:
                                    //PM2.5
                                    addBindInfo.BindCluster = 1066;
                                    break;
                            }
                            addBindInfo.BindType = 0;
                            addBindInfo.BindMacAddr = de.DeviceAddr;
                            addBindInfo.BindEpoint = de.DeviceEpoint;
                            addBindeDev.BindName = Common.LocalDevice.Current.GetDeviceEpointName(de);
                            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();
                        dev = await curControlDev.AddDeviceBindAsync(addBindeDev);
                        dev = HdlDeviceBindLogic.Current.AddDeviceBindAsync(addBindeDev);
                        if (dev == null || dev.addedDeviceBindResponseData == null)
                        {
                            Application.RunOnMainThread(() =>
@@ -1103,33 +1315,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 +1390,11 @@
                    }
                    catch (Exception ex)
                    {
                        Application.RunOnMainThread(() =>
                        {
                            CommonPage.Loading.Hide();
                        });
                        btnFinifh.Enable = true;
                        var mess = ex.Message;
                    }
                });
@@ -1259,6 +1474,7 @@
                    break;
                case 4:
                    //PM2.5
                    removeDevice.BindCluster = 1066;
                    break;
            }
            removeDevice.BindMacAddr = bd.DeviceAddr;
@@ -1298,6 +1514,7 @@
                            foreach (var de in room.ListDevice)
                            {
                                var device = LocalDevice.Current.GetDevice(de);
                                if (device != null)
                                {
                                    //获取设备类型的
@@ -1332,6 +1549,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;
                    }
@@ -1369,13 +1597,29 @@
            {
                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);
                            }
                        }
                    }
                }
@@ -1394,13 +1638,29 @@
            {
                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);
                            }
                        }
                    }
                }
@@ -1524,6 +1784,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;
@@ -1577,6 +1855,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;