陈嘉乐
2021-03-01 a469a96ee8c38f7d98366dcd633e3a15f92fec65
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
using System;
using HDL_ON.DAL.Server;
using Shared;
using System.Collections.Generic;
using Newtonsoft.Json.Linq;
 
namespace HDL_ON.UI.UI2.PersonalCenter.PirDevice
{
    public class Method
    {
        /// <summary>
        /// 添加遥控器的方法
        /// </summary>
        public void AddControl()
        {
            View.TipView tipView = new View.TipView();
            tipView.InputBox("", (s, dialog) =>
            {
                ///清除之前列表数据
                Pir.BuottonList.Clear();
                if (!string.IsNullOrEmpty(s))
                {
                    Control control = new Control();
                    control.name = s;
                    control.type = "learn";
 
                    ThreadAddControl(control, dialog);
 
 
 
                }
            }, false);
 
        }
        /// <summary>
        /// 发送遥控器命令方法
        /// </summary>
        /// <param name="control"></param>
        /// <param name="dialog"></param>
        public void ThreadAddControl(Control control, Dialog dialog) {
 
            DAL.Server.ResponsePackNew responsePackNew = null;
            Loading loading = new Loading();
            dialog.AddChidren(loading);
            loading.Start();
            new System.Threading.Thread(() =>
            {
                try
                {
                    responsePackNew = PirSend.Add(control);
                }
                catch { }
                finally
                {
                    Application.RunOnMainThread(() =>
                    {
                        loading.Hide();
                        //if (responsePackNew != null && responsePackNew.Code == "0" && responsePackNew.Data.ToString() != "")
                        //{
                        if (!string.IsNullOrEmpty(Sid("sid"))) { }
                        ///这里:监听MTTP推送下来主题,才知道是否添加成功
                        dialog.Close();//添加成功关闭弹窗
                        AddButton addButton = new AddButton();
                        MainPage.BasePageView.AddChidren(addButton);
                        addButton.Show(control);
                        MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1;
 
                        //监听Mqtt推送下来状态码做提示
                        //View.FailView failView = new View.FailView();
                        //failView.ShouError((view) => {
                        //    view.Close();
                        //    ThreadAddControl(control, dialog);
                        //});
                        //}
                        //else
                        //{
                        //    ErrorShow(responsePackNew);
                        //}
                    });
                }
            })
            { IsBackground = true }.Start();
 
        }
 
        public  List<DD> GetLsit(FrameLayout frameLayout, Action<ResponsePackNew> action, string id, string if_str)
        {
            List<DD> list = new List<DD>();
            ResponsePackNew responsePackNew = null;
           PirSend.GetDeviceTypesList(frameLayout, action, id, if_str);
 
            if (responsePackNew != null && responsePackNew.Code == "0" && responsePackNew.Data.ToString() != "")
            {
                var jArray = JArray.Parse(responsePackNew.Data.ToString());
                for (int a = 0; a < jArray.Count; a++)
                {
                    var jay = jArray[a];
                    var str = Newtonsoft.Json.JsonConvert.SerializeObject(jay);
                    list = Newtonsoft.Json.JsonConvert.DeserializeObject<List<DD>>(str);
                   
 
                }
            }
            else
            {
                Method method = new Method();
                method.ErrorShow(responsePackNew);
            }
            return list;
        }
        /// <summary>
        /// MQTT主题推送下来的数据(遥控器添加)
        /// </summary>
        public static string addcontronsid = "";
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sid"></param>
        /// <returns></returns>
        public string Sid(string sid)
        {
            var dateTime = DateTime.Now;
            while ((DateTime.Now - dateTime).TotalMilliseconds < 5* 1000)
            {
                if (!string.IsNullOrEmpty(addcontronsid) && addcontronsid == sid)
                {
                    break;
                }
 
            }
            return addcontronsid;
        }
        /// <summary>
        /// 错误码提示
        /// </summary>
        /// <param name="responsePackNew"></param>
        public  void ErrorShow(ResponsePackNew responsePackNew)
        {
 
            if (responsePackNew != null && responsePackNew.Code == "14005")
            {
                new Intelligence.Automation.LogicView.TipPopView().FlashingBox(Language.StringByID(StringId.gatewayNotOnline));
 
            }
            else
            {
                new Intelligence.Automation.LogicView.TipPopView().FlashingBox(Language.StringByID(StringId.saveFail));
 
            }
        }
        [Serializable]
        public class DD
        {
            /// <summary>
            /// 设备类型主键Id
            /// </summary>
            public string id=string.Empty;
            /// <summary>
            /// 设备类型(投影仪,风扇,机顶盒...)
            /// </summary>
            public string deviceType = string.Empty;
            /// <summary>
            ///品牌名称
            /// </summary>
            public string brandName = string.Empty;
            /// <summary>
            /// 红外码
            /// </summary>
            public string irCode = string.Empty;
            /// <summary>
            /// 品牌主键Id
            /// </summary>
            public string brandId = string.Empty;
            /// <summary>
            /// 红外码索引序号
            /// </summary>
            public string irIndex = string.Empty;
        }
    }
}