xm
2020-07-21 9a4b76398009cf76c508d61f7e48fb6f5cb7ac2d
ZigbeeApp/Shared/Phone/Category/Controls/DeviceRow/DeviceCurtainRowControl.cs
New file
@@ -0,0 +1,219 @@
using Shared.Phone.UserCenter;
using System;
using System.Collections.Generic;
using System.Text;
using ZigBee.Device;
namespace Shared.Phone.Category.Controls
{
    /// <summary>
    /// 分类界面的窗帘设备行控件
    /// </summary>
    public class DeviceCurtainRowControl : DeviceRowCommon
    {
        #region ■ 变量声明___________________________
        /// <summary>
        /// 打开控件
        /// </summary>
        private MostRightIconControl btnOpen = null;
        /// <summary>
        /// 停止控件
        /// </summary>
        private MostRightIconControl btnStop = null;
        /// <summary>
        /// 关闭控件
        /// </summary>
        private MostRightIconControl btnClose = null;
        /// <summary>
        /// 窗帘类型 4:开合帘 0:卷帘
        /// </summary>
        private int WcdType = -2;
        #endregion
        #region ■ 初始化_____________________________
        /// <summary>
        /// 初始化控件
        /// </summary>
        /// <param name="i_device"></param>
        public override void InitControl(CommonDevice i_device, Common.Room i_nowSelectRoom)
        {
            base.InitControl(i_device, i_nowSelectRoom);
            //添加跳转深度卡片信息事件
            this.AddDetailInfoEvent(i_device);
            //打开控件
            this.btnOpen = new MostRightIconControl(69, 69);
            btnOpen.btnIcon.UseClickStatu = true;
            this.frameTable.AddChidren(btnOpen, ChidrenBindMode.NotBind);
            btnOpen.InitControl();
            btnOpen.X = Application.GetRealWidth(625) - btnOpen.XOffset;
            btnOpen.ButtonClickEvent += (sender, e) =>
            {
                //如果住宅为虚拟住宅,直接修改缓存
                if (Common.Config.Instance.Home.IsVirtually == true)
                {
                    ((Rollershade)i_device).WcdCurrentPositionLiftPercentage = 100;
                    base.RefreshControlInfo(i_device);
                    return;
                }
                ((Rollershade)i_device).CurtainUpDownStopControl(0);
            };
            //停止控件
            this.btnStop = new MostRightIconControl(69, 69);
            btnStop.btnIcon.UseClickStatu = true;
            btnStop.UnSelectedImagePath = "RollerShade/Stop.png";
            btnStop.SelectedImagePath = "RollerShade/StopSelected.png";
            this.frameTable.AddChidren(btnStop, ChidrenBindMode.NotBind);
            btnStop.InitControl();
            btnStop.X = Application.GetRealWidth(769) - btnOpen.XOffset;
            btnStop.ButtonClickEvent += (sender, e) =>
            {
                //如果住宅为虚拟住宅,此功能无效
                if (Common.Config.Instance.Home.IsVirtually == false)
                {
                    ((Rollershade)i_device).CurtainUpDownStopControl(2);
                }
            };
            //关闭
            this.btnClose = new MostRightIconControl(69, 69);
            btnClose.btnIcon.UseClickStatu = true;
            this.frameTable.AddChidren(btnClose, ChidrenBindMode.NotBind);
            btnClose.InitControl();
            btnClose.X = Application.GetRealWidth(896) - btnOpen.XOffset;
            btnClose.ButtonClickEvent += (sender, e) =>
            {
                //如果住宅为虚拟住宅,直接修改缓存
                if (Common.Config.Instance.Home.IsVirtually == true)
                {
                    ((Rollershade)i_device).WcdCurrentPositionLiftPercentage = 0;
                    base.RefreshControlInfo(i_device);
                    return;
                }
                ((Rollershade)i_device).CurtainUpDownStopControl(1);
            };
            //刷新图标控件的图标
            this.RefreshIconControlImage(i_device);
        }
        #endregion
        #region ■ 深度卡片信息_______________________
        /// <summary>
        /// 添加跳转深度卡片信息事件
        /// </summary>
        private void AddDetailInfoEvent(CommonDevice i_device)
        {
            //深度卡片信息
            this.frameTable.ButtonClickEvent += (sender, e) =>
            {
                //窗帘类型的深度卡片界面
                var form = new MainPage.ControlForm.DeviceCurtainDetailCardForm();
                form.RowOrCardControl = this;
                form.AddForm(i_device, this.nowSelectRoom, 965, 1316);
                form.FormCloseEvent += this.CardDetailInfoBackEvent;
            };
        }
        #endregion
        #region ■ 检测设备打开状态___________________
        /// <summary>
        /// 检测设备打开状态
        /// </summary>
        /// <param name="i_device"></param>
        /// <returns></returns>
        public override bool CheckIsOpenStatu(CommonDevice i_device)
        {
            return ((Rollershade)i_device).WcdCurrentPositionLiftPercentage > 0;
        }
        #endregion
        #region ■ 发送获取状态命令___________________
        /// <summary>
        /// 发送获取状态命令
        /// </summary>
        public override void SendStatuComand()
        {
            //如果住宅为虚拟住宅,此功能无效
            if (Common.Config.Instance.Home.IsVirtually == true)
            {
                return;
            }
            //检测能否发送获取状态命令
            if (this.CheckCanSendStatuComand() == true)
            {
                HdlDeviceAttributeLogic.Current.SendCurtainStatuComand(this.device);
            }
            if (((Rollershade)this.device).WcdType == -1)
            {
                //读取窗帘类型
                ((Rollershade)this.device).ReadWcdType();
            }
        }
        #endregion
        #region ■ 刷新控件状态_______________________
        /// <summary>
        /// 刷新控件状态
        /// </summary>
        /// <param name="i_device"></param>
        public override void RefreshControlInfo(CommonDevice i_device)
        {
            //刷新图标控件的图标
            this.RefreshIconControlImage(i_device);
            base.RefreshControlInfo(i_device);
        }
        #endregion
        #region ■ 一般方法___________________________
        /// <summary>
        /// 刷新图标控件的图标
        /// </summary>
        /// <param name="i_device"></param>
        private void RefreshIconControlImage(CommonDevice i_device)
        {
            //还没有初始化完成
            if (btnOpen == null) { return; }
            int wcdType = ((Rollershade)i_device).WcdType;
            if (this.WcdType == wcdType)
            {
                //无需变更
                return;
            }
            this.WcdType = wcdType;
            if (this.WcdType == 0)
            {
                btnOpen.UnSelectedImagePath = "RollerShade/Up.png";
                btnOpen.SelectedImagePath = "RollerShade/UpSelected.png";
                btnClose.UnSelectedImagePath = "RollerShade/Down.png";
                btnClose.SelectedImagePath = "RollerShade/DownSelected.png";
            }
            else
            {
                btnOpen.UnSelectedImagePath = "RollerShade/Open.png";
                btnOpen.SelectedImagePath = "RollerShade/OpenSelected.png";
                btnClose.UnSelectedImagePath = "RollerShade/Close.png";
                btnClose.SelectedImagePath = "RollerShade/CloseSelected.png";
            }
        }
        #endregion
    }
}