陈嘉乐
2020-05-18 5da99fed2eb0d08b6338064da5f998891252c7b8
ZigbeeApp/Shared/Phone/UserView/UserPage.cs
@@ -1,15 +1,14 @@
using System;
using System.Collections.Generic;
using Shared.Common;
using ZigBee.Device;
using Shared.Phone.Device.AC;
using System.Text;
namespace Shared.Phone.UserView
{
    /// <summary>
    /// User page.
    /// </summary>
    public class UserPage : FrameLayout,ZigBee.Common.IStatus
    public class UserPage : FrameLayout
    {
        #region ◆ 变量_______________________
        /// <summary>
@@ -39,317 +38,7 @@
        /// <summary>
        /// 底部按钮文字的Y值
        /// </summary>
        private static readonly int tabBarEnumName_Y = 104;
        #endregion
        #region ◆ 接口____________________________
        /// <summary>
        /// 该接口将弃用 !!!!!!
        /// 改用DeviceInfoChange()
        /// </summary>
        /// <returns>The changed.</returns>
        /// <param name="common">Common.</param>
        public void Changed(CommonDevice common)
        {
        }
        /// <summary>
        /// 设备状态更新接口
        /// <para>type:如果为 DeviceInComingRespon:设备新上报</para>
        /// <para>type:如果为 IASInfoReport:RemoveDeviceRespon</para>
        /// <para>type:如果为 DeviceStatusReport:设备上报</para>
        /// <para>type:如果为 IASInfoReport:IAS安防信息上报</para>
        /// <para>type:如果为 OnlineStatusChange: 设备在线状态更新</para>
        /// </summary>
        /// <param name="common">Common.</param>
        /// <param name="typeTag">Type tag.</param>
        public void DeviceInfoChange(CommonDevice common, string typeTag)
        {
            //设备上报状态中 当CluterID=3,就证明该设备在线,直接标记
            if (typeTag == "DeviceStatusReport")
            {
                try
                {
                    for (int i = 0; i < Room.AllRoomDeviceUIList.Count; i++)
                    {
                        var deviceUI = Room.AllRoomDeviceUIList[i];
                        if (deviceUI.CommonDevice == null)
                        {
                            //设备为空
                            continue;
                        }
                        if (common.DeviceAddr != deviceUI.CommonDevice.DeviceAddr || common.DeviceEpoint != deviceUI.CommonDevice.DeviceEpoint)
                        {
                            //判断是否为当前设备
                            continue;
                        }
                        switch (deviceUI.CommonDevice.Type)
                        {
                            case DeviceType.OnOffOutput:
                                //开关功能
                                if ((common as ZigBee.Device.ToggleLight).DeviceStatusReport.CluterID == 6)
                                {
                                    var onOffOutputLight = deviceUI.CommonDevice as ZigBee.Device.ToggleLight;
                                    onOffOutputLight.DeviceStatusReport = (common as ZigBee.Device.ToggleLight).DeviceStatusReport;
                                    //记录、更新状态
                                    if (onOffOutputLight.DeviceStatusReport.AttriBute == null || onOffOutputLight.DeviceStatusReport.AttriBute.Count == 0)
                                    {
                                        continue;
                                    }
                                    onOffOutputLight.OnOffStatus = onOffOutputLight.DeviceStatusReport.AttriBute[0].AttriButeData;
                                    //记录回复时间
                                    onOffOutputLight.LastDateTime = DateTime.Now;
                                }
                                //当CluterID=3,就证明该设备在线,直接标记
                                if ((common as ZigBee.Device.ToggleLight).DeviceStatusReport.CluterID == 3)
                                {
                                    var onOffOutputLight = deviceUI.CommonDevice as ToggleLight;
                                    onOffOutputLight.IsOnline = 1;
                                    //记录回复时间
                                    onOffOutputLight.LastDateTime = DateTime.Now;
                                }
                                break;
                            case DeviceType.AirSwitch:
                                //开关功能
                                if ((common as ZigBee.Device.AirSwitch).DeviceStatusReport.CluterID == 6)
                                {
                                    var airSwitch = deviceUI.CommonDevice as ZigBee.Device.AirSwitch;
                                    airSwitch.DeviceStatusReport = (common as ZigBee.Device.AirSwitch).DeviceStatusReport;
                                    //记录、更新状态
                                    if (airSwitch.DeviceStatusReport.AttriBute == null || airSwitch.DeviceStatusReport.AttriBute.Count == 0)
                                    {
                                        return;
                                    }
                                    airSwitch.OnOffStatus = airSwitch.DeviceStatusReport.AttriBute[0].AttriButeData;
                                    //记录回复时间
                                    airSwitch.LastDateTime = DateTime.Now;
                                }
                                //当CluterID=3,就证明该设备在线,直接标记
                                if ((common as ZigBee.Device.AirSwitch).DeviceStatusReport.CluterID == 3)
                                {
                                    var airSwitch = deviceUI.CommonDevice as AirSwitch;
                                    airSwitch.IsOnline = 1;
                                    //记录回复时间
                                    airSwitch.LastDateTime = DateTime.Now;
                                }
                                break;
                            case DeviceType.WindowCoveringDevice:
                                if ((common as ZigBee.Device.Rollershade).DeviceStatusReport.CluterID == 258)
                                {
                                    var rollershade = deviceUI.CommonDevice as ZigBee.Device.Rollershade;
                                    rollershade.DeviceStatusReport = (common as ZigBee.Device.Rollershade).DeviceStatusReport;
                                    var attriButeList = rollershade.DeviceStatusReport.AttriBute;
                                    if (attriButeList == null || attriButeList.Count == 0)
                                    {
                                        continue;
                                    }
                                    switch (attriButeList[0].AttributeId)
                                    {
                                        case 0:
                                            rollershade.WcdType = attriButeList[0].AttriButeData;
                                            rollershade.LastDateTime = DateTime.Now;
                                            break;
                                    }
                                }
                                if ((common as ZigBee.Device.Rollershade).DeviceStatusReport.CluterID == 3)
                                {
                                    var rollershade = deviceUI.CommonDevice as ZigBee.Device.Rollershade;
                                    rollershade.IsOnline = 1;
                                    //记录回复时间
                                    rollershade.LastDateTime = DateTime.Now;
                                }
                                break;
                            case DeviceType.Thermostat:
                                //AC功能
                                if ((common as ZigBee.Device.AC).DeviceStatusReport.CluterID == 513)
                                {
                                    var ac = deviceUI.CommonDevice as ZigBee.Device.AC;
                                    ac.DeviceStatusReport = (common as ZigBee.Device.AC).DeviceStatusReport;
                                    var attriButeList = ac.DeviceStatusReport.AttriBute;
                                    if (attriButeList == null || attriButeList.Count == 0)
                                    {
                                        continue;
                                    }
                                    switch (attriButeList[0].AttributeId)
                                    {
                                        case 0:
                                            //此属性表明室内当前的温度 * 100,实际温度为“LocalTemperature / 100”,单位:℃
                                            ac.currentLocalTemperature = attriButeList[0].AttriButeData / 100;
                                            ac.LastDateTime = DateTime.Now;
                                            break;
                                        case 17:
                                            //此属性表明此设备当前的制冷温度,实际温度为“CoolingSetpoint / 100”,单位:℃。
                                            ac.currentCoolingSetpoint = attriButeList[0].AttriButeData / 100;
                                            ac.LastDateTime = DateTime.Now;
                                            break;
                                        case 18:
                                            //此属性表明此设备当前的制热温度,实际温度为“HeatingSetpoint / 100”,单位:℃。
                                            ac.currentHeatingSetpoint = attriButeList[0].AttriButeData / 100;
                                            ac.LastDateTime = DateTime.Now;
                                            break;
                                        case 4096:
                                            //此属性表明此设备当前的自动温度,实际温度为“AutoSetpoint / 100”,单位:℃。
                                            ac.currentAutoSetpoint = (attriButeList[0].AttriButeData / 100 > ACControlBase.Temperature_High || attriButeList[0].AttriButeData / 100 < ACControlBase.Temperature_Low) ? attriButeList[0].AttriButeData / 100 : ACControlBase.Temperature_Default;
                                            ac.LastDateTime = DateTime.Now;
                                            break;
                                        case 28:
                                            //此属性描述恒温设备正处于哪种模式
                                            //Off = 0  Auto = 1 Cool = 3 Heat = 4 FanOnly = 7  Dry = 8
                                            ac.currentSystemMode = attriButeList[0].AttriButeData;
                                            ac.LastDateTime = DateTime.Now;
                                            break;
                                    }
                                }
                                //当CluterID=3,就证明该设备在线,直接标记
                                if ((common as ZigBee.Device.AC).DeviceStatusReport.CluterID == 3)
                                {
                                    var ac = deviceUI.CommonDevice as AC;
                                    ac.IsOnline = 1;
                                    //记录回复时间
                                    ac.LastDateTime = DateTime.Now;
                                }
                                break;
                            case DeviceType.DimmableLight:
                                //调光灯功能
                                //开关功能
                                if ((common as ZigBee.Device.DimmableLight).DeviceStatusReport.CluterID == 6)
                                {
                                    var dimmableLight = deviceUI.CommonDevice as ZigBee.Device.DimmableLight;
                                    dimmableLight.DeviceStatusReport = (common as ZigBee.Device.DimmableLight).DeviceStatusReport;
                                    //记录、更新状态
                                    if (dimmableLight.DeviceStatusReport.AttriBute == null || dimmableLight.DeviceStatusReport.AttriBute.Count == 0)
                                    {
                                        return;
                                    }
                                    dimmableLight.OnOffStatus = dimmableLight.DeviceStatusReport.AttriBute[0].AttriButeData;
                                    //记录回复时间
                                    dimmableLight.LastDateTime = DateTime.Now;
                                }
                                //亮度
                                if ((common as ZigBee.Device.DimmableLight).DeviceStatusReport.CluterID == 8)
                                {
                                    var dimmableLight = deviceUI.CommonDevice as ZigBee.Device.DimmableLight;
                                    dimmableLight.DeviceStatusReport = (common as ZigBee.Device.DimmableLight).DeviceStatusReport;
                                    var attriButeList = dimmableLight.DeviceStatusReport.AttriBute;
                                    if (attriButeList == null || attriButeList.Count == 0)
                                    {
                                        continue;
                                    }
                                    switch (attriButeList[0].AttributeId)
                                    {
                                        case 0:
                                            //此属性表明当前亮度程度
                                            dimmableLight.Level = attriButeList[0].AttriButeData;
                                            dimmableLight.LastDateTime = DateTime.Now;
                                            break;
                                    }
                                }
                                //当CluterID=3,就证明该设备在线,直接标记
                                if ((common as ZigBee.Device.DimmableLight).DeviceStatusReport.CluterID == 3)
                                {
                                    var dimmableLight = deviceUI.CommonDevice as DimmableLight;
                                    dimmableLight.IsOnline = 1;
                                    //记录回复时间
                                    dimmableLight.LastDateTime = DateTime.Now;
                                }
                                break;
                        }
                    }
                }
                catch (Exception ex)
                {
                    System.Console.WriteLine($"Error:{ex.Message}");
                }
            }
            //设备在线状态上报
            else if (typeTag == "OnlineStatusChange")
            {
                try
                {
                    for (int i = 0; i < Room.AllRoomDeviceUIList.Count; i++)
                    {
                        var deviceUI = Room.AllRoomDeviceUIList[i];
                        if (deviceUI.CommonDevice == null)
                        {
                            //设备为空或者控件为空
                            continue;
                        }
                        if (common.DeviceAddr != deviceUI.CommonDevice.DeviceAddr || common.DeviceEpoint != deviceUI.CommonDevice.DeviceEpoint)
                        {
                            //判断是否为当前设备
                            continue;
                        }
                        switch (deviceUI.CommonDevice.Type)
                        {
                            case DeviceType.OnOffOutput:
                                var onOffOutputLight = deviceUI.CommonDevice as ToggleLight;
                                onOffOutputLight.IsOnline = (common as ToggleLight).IsOnline;
                                //记录回复时间
                                onOffOutputLight.LastDateTime = DateTime.Now;
                                break;
                            case DeviceType.AirSwitch:
                                var airSwitch = deviceUI.CommonDevice as AirSwitch;
                                airSwitch.IsOnline = (common as AirSwitch).IsOnline;
                                //记录回复时间
                                airSwitch.LastDateTime = DateTime.Now;
                                break;
                            case DeviceType.WindowCoveringDevice:
                                var rollershade = deviceUI.CommonDevice as ZigBee.Device.Rollershade;
                                rollershade.IsOnline = (common as Rollershade).IsOnline;
                                //记录回复时间
                                rollershade.LastDateTime = DateTime.Now;
                                break;
                            case DeviceType.Thermostat:
                                var ac = deviceUI.CommonDevice as ZigBee.Device.AC;
                                ac.IsOnline = (common as ZigBee.Device.AC).IsOnline;
                                //记录回复时间
                                ac.LastDateTime = DateTime.Now;
                                break;
                            case DeviceType.DimmableLight:
                                var dimmableLight = deviceUI.CommonDevice as ZigBee.Device.DimmableLight;
                                dimmableLight.IsOnline = (common as ZigBee.Device.DimmableLight).IsOnline;
                                //记录回复时间
                                dimmableLight.LastDateTime = DateTime.Now;
                                break;
                        }
                    }
                }
                catch (Exception ex)
                {
                    System.Console.WriteLine($"userpage功能刷新-Error:{ex.Message}");
                }
            }
        }
        /// <summary>
        /// Changeds the IL ogic status.
        /// </summary>
        /// <param name="logic">Logic.</param>
        public void ChangedILogicStatus(ZigBee.Device.Logic logic)
        {
            //throw new NotImplementedException();
        }
        /// <summary>
        /// Changeds the IS cene status.
        /// </summary>
        /// <param name="scene">Scene.</param>
        public void ChangedISceneStatus(Scene scene)
        {
            //throw new NotImplementedException();
        }
        private static readonly int tabBarEnumName_Y = 98;
        #endregion
        /// <summary>
@@ -374,7 +63,10 @@
        public UserPage()
        {
            BackgroundColor = Shared.Common.ZigbeeColor.Current.MainColor;
            ZbGateway.StatusList.Add(this);
            Shared.Application.LocationAction += (lon, lat) =>
            {
                Login.AccountLogic.Instance.ReceiveAppLatAndLon(lon.ToString(), lat.ToString());
            };
        }
        /// <summary>
@@ -421,11 +113,10 @@
        public Button homePageIMG = new Button
        {
            Y = Application.GetRealHeight(tabBarEnumIMG_Y),
            Height = Application.GetMinRealAverage(tabBarEnumIMG_Height),
            Width = Application.GetMinRealAverage(tabBarEnumIMG_Width),
            Height = UserCenter.HdlControlLogic.Current.GetPictrueRealSize(tabBarEnumIMG_Height),
            Width = UserCenter.HdlControlLogic.Current.GetPictrueRealSize(tabBarEnumIMG_Width),
            UnSelectedImagePath = "Navigation/Home.png",
            SelectedImagePath = "Navigation/HomeSelected.png",
            IsSelected = true,
            Gravity = Gravity.CenterHorizontal
        };
        /// <summary>
@@ -438,7 +129,6 @@
            TextID = R.MyInternationalizationString.HomePage,
            TextColor = Shared.Common.ZigbeeColor.Current.GXCTextBottomUnSelectedColor,
            SelectedTextColor = Shared.Common.ZigbeeColor.Current.GXCTextBlackColor2,
            IsSelected = true,
            Gravity = Gravity.CenterHorizontal,
            TextSize = 10
        };
@@ -450,7 +140,7 @@
        /// </summary>
        public FrameLayout categoryFL = new FrameLayout
        {
            X=Application.GetRealWidth(tabBarEnum_Width),
            X = Application.GetRealWidth(tabBarEnum_Width),
            Width = Application.GetRealWidth(tabBarEnum_Width),
            Height = Application.GetRealHeight(CommonPage.TabbarHeight)
        };
@@ -460,8 +150,8 @@
        public Button categoryIMG = new Button
        {
            Y = Application.GetRealHeight(tabBarEnumIMG_Y),
            Height = Application.GetMinRealAverage(tabBarEnumIMG_Height),
            Width = Application.GetMinRealAverage(tabBarEnumIMG_Width),
            Height = UserCenter.HdlControlLogic.Current.GetPictrueRealSize(tabBarEnumIMG_Height),
            Width = UserCenter.HdlControlLogic.Current.GetPictrueRealSize(tabBarEnumIMG_Width),
            UnSelectedImagePath = "Navigation/Category.png",
            SelectedImagePath = "Navigation/CategorySelected.png",
            Gravity = Gravity.CenterHorizontal
@@ -476,9 +166,8 @@
            TextID = R.MyInternationalizationString.Category,
            TextColor = Shared.Common.ZigbeeColor.Current.GXCTextBottomUnSelectedColor,
            SelectedTextColor = Shared.Common.ZigbeeColor.Current.GXCTextBlackColor2,
            IsSelected = false,
            Gravity = Gravity.CenterHorizontal,
            TextSize=10
            TextSize = 10
        };
        #endregion
@@ -488,7 +177,7 @@
        /// </summary>
        public FrameLayout settingFL = new FrameLayout
        {
            X = Application.GetRealWidth(tabBarEnum_Width*2),
            X = Application.GetRealWidth(tabBarEnum_Width * 2),
            Width = Application.GetRealWidth(tabBarEnum_Width),
            Height = Application.GetRealHeight(CommonPage.TabbarHeight)
        };
@@ -498,8 +187,8 @@
        public Button settingIMG = new Button
        {
            Y = Application.GetRealHeight(tabBarEnumIMG_Y),
            Height = Application.GetMinRealAverage(tabBarEnumIMG_Height),
            Width = Application.GetMinRealAverage(tabBarEnumIMG_Width),
            Height = UserCenter.HdlControlLogic.Current.GetPictrueRealSize(tabBarEnumIMG_Height),
            Width = UserCenter.HdlControlLogic.Current.GetPictrueRealSize(tabBarEnumIMG_Width),
            UnSelectedImagePath = "Navigation/Setting.png",
            SelectedImagePath = "Navigation/SettingSelected.png",
            Gravity = Gravity.CenterHorizontal
@@ -514,50 +203,95 @@
            TextID = R.MyInternationalizationString.Me,
            TextColor = Shared.Common.ZigbeeColor.Current.GXCTextBottomUnSelectedColor,
            SelectedTextColor = Shared.Common.ZigbeeColor.Current.GXCTextBlackColor2,
            IsSelected = false,
            Gravity = Gravity.CenterHorizontal,
            TextSize = 10
        };
        #endregion
        #region 强制显示自动化界面
        /// <summary>
        /// 强制显示自动化列表界面
        /// </summary>
        public void ShowCategoryAutoListForm()
        {
            //关闭全部界面,直到主页为止
            UserCenter.UserCenterLogic.CloseAllOpenForm();
            //强制显示自动化列表界面
            UserCenter.UserCenterResourse.ResidenceOption.CategoryPageSwitchIndex = 2;
            BottomEventHandler(Instance.categoryIMG, null);
        }
        #endregion
        EventHandler<MouseEventArgs> BottomEventHandler = (sender, e) =>
        {
            Room.GetAllRoomDeviceUIList();
            Instance.homePageName.IsSelected = false;
            Instance.homePageIMG.IsSelected = false;
            Instance.categoryName.IsSelected = false;
            Instance.categoryIMG.IsSelected = false;
            Instance.settingName.IsSelected = false;
            Instance.settingIMG.IsSelected = false;
            Instance.BodyView.RemoveAll();
            if (sender == Instance.homePageIMG || sender == Instance.homePageName)
            {
                if (Instance.homePageName.IsSelected == true && e != null)
                {
                    //只有是手动点击的时候才处理
                    return;
                }
                Instance.BodyView.RemoveAll();
                //主页
                CommonPage.Instance.IsDrawerLockMode = false;
                Instance.homePageName.IsSelected = true;
                Instance.homePageIMG.IsSelected = true;
                var home = new UserHomeView { };
                Instance.categoryName.IsSelected = false;
                Instance.categoryIMG.IsSelected = false;
                Instance.settingName.IsSelected = false;
                Instance.settingIMG.IsSelected = false;
                var home = new MainPage.HomeMainPageForm();
                Instance.BodyView.AddChidren(home);
                home.Show();
                home.ShowForm();
            }
            else if (sender == Instance.categoryIMG || sender==Instance.categoryName)
            else if (sender == Instance.categoryIMG || sender == Instance.categoryName)
            {
                if (Instance.categoryName.IsSelected == true && e != null)
                {
                    //只有是手动点击的时候才处理
                    return;
                }
                Instance.BodyView.RemoveAll();
                //分类
                CommonPage.Instance.IsDrawerLockMode = true;
                Instance.categoryName.IsSelected = true;
                Instance.categoryIMG.IsSelected = true;
                var category = new Phone.Device.Category.Category { };
                Instance.homePageName.IsSelected = false;
                Instance.homePageIMG.IsSelected = false;
                Instance.settingName.IsSelected = false;
                Instance.settingIMG.IsSelected = false;
                var category = new Category.CategoryMainForm { };
                Instance.BodyView.AddChidren(category);
                category.Show();
                category.ShowForm();
            }
            else if (sender == Instance.settingIMG || sender==Instance.settingName)
            else if (sender == Instance.settingIMG || sender == Instance.settingName)
            {
                 //个人中心
                if (Instance.settingName.IsSelected == true && e != null)
                {
                    return;
                }
                Instance.BodyView.RemoveAll();
                //个人中心
                CommonPage.Instance.IsDrawerLockMode = true;
                Instance.settingName.IsSelected = true;
                Instance.settingIMG.IsSelected = true;
                Instance.homePageName.IsSelected = false;
                Instance.homePageIMG.IsSelected = false;
                Instance.categoryName.IsSelected = false;
                Instance.categoryIMG.IsSelected = false;
                var form = new UserCenter.UserMain.UserMainForm();
                Instance.BodyView.AddChidren(form);
                form.ShowForm();