黄学彪
2020-12-16 0d9f64668fd7350d6a21fd157e32009a96d98134
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
using System;
using System.Collections.Generic;
using System.Text;
using ZigBee.Device;
 
namespace Shared.Phone
{
    /// <summary>
    /// 做成一个简单设备选择的行控件
    /// </summary>
    public class DeviceSimpleSelectControl : FrameRowControl
    {
        #region ■ 变量声明___________________________
 
        /// <summary>
        /// 设备对象
        /// </summary>
        public CommonDevice device
        {
            get { return HdlDeviceCommonLogic.Current.GetDevice(MainKeys); }
        }
        /// <summary>
        /// 选择控件
        /// </summary>
        private MostRightIconControl btnSelect = null;
 
        /// <summary>
        /// 选择的状态是否能够取消
        /// </summary>
        public bool SelectCancel = true;
        /// <summary>
        /// 状态
        /// </summary>
        private StatuMode Statu = StatuMode.UN_SELECT;
        /// <summary>
        /// 是否处于选择状态
        /// </summary>
        public bool IsSelected
        {
            get { return Statu == StatuMode.SELECT; }
            set
            {
                if (value == false)
                {
                    if (SelectCancel == true)
                    {
                        this.SetUnselectStatu();
                    }
                }
                else
                {
                    this.SetSelectStatu();
                }
            }
        }
 
        #endregion
 
        #region ■ 初始化_____________________________
 
        /// <summary>
        /// 做成一个简单设备选择的行控件
        /// </summary>
        /// <param name="i_device">设备对象</param>
        /// <param name="autoSelect">当点击此控件时,是否自动设置选择状态</param>
        /// <param name="i_ChidrenYaxis">子控件Y轴偏移量(【列表控件的rowSpace/2】即可,不懂默认为0即可)</param>
        public DeviceSimpleSelectControl(CommonDevice i_device, bool autoSelect, int i_ChidrenYaxis = 0) : base(i_ChidrenYaxis)
        {
            this.MainKeys = HdlDeviceCommonLogic.Current.GetDeviceMainKeys(i_device);
            if (autoSelect == true)
            {
                this.ButtonClickEvent += (sender, e) =>
                {
                    this.IsSelected = Statu == StatuMode.SELECT ? false : true;
                };
            }
        }
 
        /// <summary>
        /// 初始化内部控件
        /// </summary>
        public void InitControl()
        {
            //图标
            var btnIcon = this.AddLeftIcon();
            HdlDeviceCommonLogic.Current.SetDeviceIconToControl(btnIcon, device);
 
            //设备
            string eName = HdlDeviceCommonLogic.Current.GetDeviceEpointName(device);
            this.AddLeftCaption(eName, 850);
 
            btnSelect = this.AddMostRightEmptyIcon(58, 58);
            btnSelect.Visible = false;
            btnSelect.UnSelectedImagePath = "Item/ItemSelected.png";
        }
 
        #endregion
 
        #region ■ 选择状态___________________________
 
        /// <summary>
        /// 设定选择状态
        /// </summary>
        private void SetSelectStatu()
        {
            if (Statu == StatuMode.SELECT)
            {
                return;
            }
            btnSelect.Visible = true;
            //状态变更
            Statu = StatuMode.SELECT;
        }
 
        /// <summary>
        /// 设置非选择状态
        /// </summary>
        private void SetUnselectStatu()
        {
            if (Statu == StatuMode.UN_SELECT)
            {
                return;
            }
            btnSelect.Visible = false;
            //状态变更
            Statu = StatuMode.UN_SELECT;
        }
        #endregion
 
        #region ■ 一般方法___________________________
 
        #endregion
    }
}