wxr
2020-09-01 7d005a7618e3d7a80d8ede3baf6ecc4bf8019cd5
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
using System;
using HDL_ON.Entity;
using Shared;
 
namespace HDL_ON.UI
{
    public partial class SocketPage
    {
        /// <summary>
        /// 更新灯光状态
        /// </summary>
        public static void UpdataState(SwitchSocket uFan)
        {
            Application.RunOnMainThread(() =>
            {
                try
                {
                    if (bodyView == null)
                        return;
                    bodyView.btnSwitch.IsSelected = bodyView.btnSwitchIcon.IsSelected = uFan.trait_on_off.value.ToString() == "on";
                }
                catch (Exception ex)
                {
                    MainPage.Log($"RelayPage error {ex.Message}");
                }
            });
        }
        /// <summary>
        /// 加载事件列表
        /// </summary>
        void LoadEventList()
        {
            LoadSwitchEvent();
            LoadCollectionEvent();
 
            //回退刷新信息事件
            actionRefresh = () => {
                btnFunctionName.Text = btnFunctionName_Out.Text = socketFunction.name;
                btnFromFloor_Out.Text = btnFromFoorAndRoom.Text = socketFunction.GetRoomListName();
            };
        }
 
        /// <summary>
        /// 收藏功能按钮事件
        /// </summary>
        void LoadCollectionEvent()
        {
            btnCollection.MouseUpEventHandler += (sender, e) => {
                btnCollection.IsSelected = socketFunction.collection = btnCollection_Out.IsSelected = !btnCollection.IsSelected;
                socketFunction.SaveFunctionData();
            };
        }
 
        /// <summary>
        /// 加载开关事件
        /// </summary>
        void LoadSwitchEvent()
        {
            btnSwitchIcon.MouseUpEventHandler += (sender, e) =>
            {
                btnSwitchIcon.IsSelected = !btnSwitchIcon.IsSelected;
 
                new System.Threading.Thread(() =>
                {
                    socketFunction.trait_on_off.value = btnSwitch.IsSelected ? "on" : "off";
                    //Control.Send(CommandType_A.write, this.socketFunction);
                    System.Collections.Generic.Dictionary<string, string> d = new System.Collections.Generic.Dictionary<string, string>();
                    d.Add("on_off", socketFunction.trait_on_off.value.ToString());
                    Control.SendWriteCommand(socketFunction, d);
                })
                { IsBackground = true }.Start();
            };
            btnSwitch.MouseUpEventHandler += (sender, e) =>
            {
                btnSwitch.IsSelected = !btnSwitch.IsSelected;
 
                new System.Threading.Thread(() =>
                {
                    socketFunction.trait_on_off.value = btnSwitch.IsSelected ? "on" : "off";
                    //Control.Send(CommandType_A.write, this.socketFunction);
                    System.Collections.Generic.Dictionary<string, string> d = new System.Collections.Generic.Dictionary<string, string>();
                    d.Add("on_off", socketFunction.trait_on_off.value.ToString());
                    Control.SendWriteCommand(socketFunction, d);
                })
                { IsBackground = true }.Start();
            };
 
        }
 
    }
}