wxr
2020-03-05 0bdc0a135dbe31761b53f432ed34f347f0a4e36b
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
using System;
using HDL_ON.Entity;
 
namespace HDL_ON.UI
{
    public partial class FunctionDiv
    {
        /// <summary>
        /// 加载事件列表
        /// </summary>
        void LoadEventList()
        {
            LoadCollectionEvent();
        }
 
        /// <summary>
        /// 加载收藏按钮事件
        /// </summary>
        void LoadCollectionEvent()
        {
            btnCollectionIcon.MouseUpEventHandler += (sender, e) => {
                btnCollectionIcon.IsSelected = function.collection = !btnCollectionIcon.IsSelected;
                DB_ResidenceData.residenceData.SaveResidenceData();
            };
        }
        #region 灯光的事件列表
        /// <summary>
        /// 加载灯光控件的事件
        /// </summary>
        void LoadLightEventList()
        {
            LightSwitchEvent();
            LightDivSkipEvent();
            LightDimmingEvent();
        }
        /// <summary>
        /// 灯光开关事件
        /// </summary>
        void LightSwitchEvent()
        {
            btnSwitch.MouseUpEventHandler += (sender, e) => {
                btnSwitch.IsSelected = !btnSwitch.IsSelected;
                new System.Threading.Thread(() =>
                {
                    var light = function as Light;
                    light.state = btnSwitch.IsSelected ? 1 : 0;
                    Control.Send("write", function, 3);
                })
                { IsBackground = true }.Start();
            };
        }
 
        /// <summary>
        /// 灯光亮度调节事件
        /// </summary>
        void LightDimmingEvent()
        {
            if (function.functionType == "Dimmer" || function.functionType == "RGB")
            {
                if (dimmerControlBar == null)
                    return;
 
                var light = function as Light;
                dimmerControlBar.OnProgressChangedEvent += (sender, e) =>
                {
                    dimmerControlBar.Tag = DateTime.Now;
                    if ((DateTime.Now - (DateTime)(dimmerControlBar.Tag)).TotalMilliseconds < 200)//调光命令发送间隔事件
                    {
                        new System.Threading.Thread(() =>
                        {
                            light.dicPropert["brightness"] = (byte)e;
                            Control.Send("write", function, 3);
                            dimmerControlBar.Tag = DateTime.Now;
                        })
                        { IsBackground = true }.Start();
                    }
                };
                dimmerControlBar.MouseUpEventHandler += (sender, e) =>
                {
                    light.dicPropert["brightness"] = (byte)dimmerControlBar.Progress;
                    Control.Send("write", function, 3);
                };
            }
        }
 
        /// <summary>
        /// 灯光控制界面跳转
        /// </summary>
        void LightDivSkipEvent()
        {
            this.MouseUpEventHandler += (sender, e) =>
            {
                //跳转到功能信息设置页面
                switch (function.functionType)
                {
                    case "Relay":
                        var relayView = new RelayPage(function as Light);
                        MainPage.BasePageView.AddChidren(relayView);
                        relayView.LoadPage();
                        MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1;
                        break;
                    case "RGB":
                        var rgbView = new RGBPage(function as Light);
                        MainPage.BasePageView.AddChidren(rgbView);
                        rgbView.LoadPage();
                        MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1;
                        break;
                }
            };
        }
 
        #endregion
    }
}