wxr
2023-03-22 a91a9388bef8bbc619dee6db5e369f801a2d2864
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
using System;
using System.Collections.Generic;
using HDL_ON.DriverLayer;
using HDL_ON.Entity;
using HDL_ON.Stan;
using HDL_ON.UI.CSS;
using Shared;
 
namespace HDL_ON.UI
{
    /// <summary>
    /// 机械手控制页面
    /// </summary>
    public class MechanicalArmPage : DeviceFunctionCardCommonForm
    {
        #region ■ 变量声明___________________________
        /// <summary>
        /// 图片控件
        /// </summary>
        private PicViewControl btnPictrue = null;
        /// <summary>
        /// 开关状态提示控件
        /// </summary>
        private Button btnTipStatus = null;
 
        /// <summary>
        /// 开关控件
        /// </summary>
        private IconViewControl btnSwitch = null;
        #endregion
 
        #region ■ 初始化_____________________________
 
        /// <summary>
        /// 初始化白色区域的内容
        /// </summary>
        public override void InitFrameWhiteContent()
        {
            base.SetTitleText(Language.StringByID(StringId.WaterValve));
 
            //初始化第一个索引页的内容
            this.InitFrameWhiteContent1();
            //刷新界面状态
            this.RefreshFormStatu();
            //读取状态
            new System.Threading.Thread(() =>
            {
                Control.Ins.ReadFunctionsInfo(new List<string>() { device.deviceId });
            })
            { IsBackground = true }.Start();
        }
 
        /// <summary>
        /// 初始化第一个索引页的内容
        /// </summary>
        private void InitFrameWhiteContent1()
        {
            btnTipStatus = new Button()
            {
                Gravity = Gravity.CenterHorizontal,
                Y = Application.GetRealHeight(79),
                Width = Application.GetRealWidth(100),
                Height = Application.GetRealHeight(34),
                BackgroundColor = 0x171B2D4D,
                TextColor = CSS_Color.FirstLevelTitleColor,
                Radius = (uint)Application.GetRealHeight(17),
                TextID = StringId.ValveClosed,
            };
            FrameWhiteCentet1.AddChidren(btnTipStatus);
 
            //图片控件
            this.btnPictrue = new PicViewControl(327, 327);
            btnPictrue.Y = Application.GetRealHeight(127);
            btnPictrue.Gravity = Gravity.CenterHorizontal;
            btnPictrue.UnSelectedImagePath = "FunctionIcon/Electrical/MechanicalArm/MechanicalArmBg.png";
            btnPictrue.SelectedImagePath = "FunctionIcon/Electrical/MechanicalArm/MechanicalArmOnBg.png";
            FrameWhiteCentet1.AddChidren(btnPictrue);
            btnPictrue.ButtonClickEvent += (sender, e) =>
            {
                //发送开关命令
                this.SendSwitchComand();
            };
 
            //开关图标
            this.btnSwitch = new IconViewControl(40);
            btnSwitch.Gravity = Gravity.CenterHorizontal;
            btnSwitch.Y = Application.GetRealHeight(468);
            btnSwitch.UnSelectedImagePath = "Public/PowerClose.png";
            btnSwitch.SelectedImagePath = "Public/PowerOpen.png";
            FrameWhiteCentet1.AddChidren(btnSwitch);
            btnSwitch.ButtonClickEvent += (sender, e) =>
            {
                //发送开关命令
                this.SendSwitchComand();
            };
 
            var pack = new DAL.Server.HttpServerRequest().GetDeviceInfoList(new List<string>() { base.device.deviceId });
        }
        #endregion
 
        #region ■ 设备状态反馈_______________________
 
        /// <summary>
        /// 设备状态反馈
        /// </summary>
        /// <param name="i_LocalDevice"></param>
        public override void DeviceStatuPush(Function i_LocalDevice)
        {
            //不是同一个东西
            if (this.device.sid != i_LocalDevice.sid) { return; }
 
            //刷新界面状态
            this.RefreshFormStatu();
        }
 
        #endregion
 
        #region ■ 发送各种命令_______________________
 
        /// <summary>
        /// 发送开关命令
        /// </summary>
        private void SendSwitchComand()
        {
            //if (!device.online)
            //{
            //    new Tip()
            //    {
            //        CloseTime = 1,
            //        Text = Language.StringByID(StringId.DeviceOfflineCannotOption),
            //        Direction = AMPopTipDirection.None,
            //    }.Show(MainPage.BaseView);
            //    return;
            //}
            string statu = this.btnSwitch.IsSelected == true ? "off" : "on";
            string tipMsg = "确定打开?";
            if (this.btnSwitch.IsSelected)
            {
                tipMsg = "确定关闭?";
            }
            if (Language.CurrentLanguage != "Chinese")
            {
 
                tipMsg = "Are you sure to close?";
                if (this.btnSwitch.IsSelected)
                    tipMsg = "Are you sure to open it?";
            }
            Action action = () => {
 
                this.btnPictrue.CanClick = false;
                this.btnSwitch.CanClick = false;
 
                HdlThreadLogic.Current.RunThread(() =>
                {
                    var dic = new Dictionary<string, string>();
                    dic.Add(FunctionAttributeKey.OnOff, statu);
                    Control.Ins.SendWriteCommand(this.device, dic, true);
                    HdlThreadLogic.Current.RunMain(() =>
                    {
                        this.btnPictrue.CanClick = true;
                        this.btnSwitch.CanClick = true;
                    });
                });
            };
            new PublicAssmebly().TipOptionMsg(StringId.Tip, tipMsg, action);
 
        }
 
        #endregion
 
        #region ■ 刷新界面状态_______________________
 
        /// <summary>
        /// 刷新界面状态
        /// </summary>
        private void RefreshFormStatu()
        {
            Application.RunOnMainThread(() =>
            {
                var onoffStatu = device.attributes.Find((obj) => obj.key == FunctionAttributeKey.OnOff);
 
                if (onoffStatu != null)
                {
                    if (onoffStatu.state == "on")
                    {
                        btnTipStatus.TextID = StringId.ValveOpened;
                        btnTipStatus.TextColor = 0xFF4BC803;
                        btnTipStatus.BackgroundColor = 0x174BC803;
                    }
                    else
                    {
                        btnTipStatus.TextID = StringId.ValveClosed;
                        btnTipStatus.TextColor = CSS_Color.FirstLevelTitleColor;
                        btnTipStatus.BackgroundColor = 0x171B2D4D;
                    }
                    this.btnSwitch.IsSelected = this.btnPictrue.IsSelected = onoffStatu.state.ToString() == "on";
                }
            });
        }
 
        #endregion
    }
}