xm
2021-12-01 6d73bf6e816570291865674bef8bce8972e4de3f
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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
using HDL_ON.DAL.Server;
using HDL_ON.Entity;
using HDL_ON.Stan;
using Shared;
using System;
 
namespace HDL_ON.UI
{
    /// <summary>
    /// 添加环境传感器步骤1界面
    /// </summary>
    public class AddSensorEnvironmentPage : EditorCommonForm
    {
        #region ■ 变量声明___________________________
 
        /// <summary>
        /// 添加设备完成之后的回调事件
        /// </summary>
        public Action<Function> AddDeviceEvent = null;
 
        IntegratedBrandDevice integratedDevice = null;
 
        #endregion
 
        #region ■ 初始化_____________________________
        /// <summary>
        /// 画面显示(底层会固定调用此方法,借以完成画面创建)
        /// </summary>
        public void ShowForm(IntegratedBrandDevice device)
        {
            integratedDevice = device;
            if (Language.CurrentLanguage == "Chinese")
            {
                //设置头部信息
                base.SetTitleText(Language.StringByID(StringId.Add) + device.productName);
            }
            else
            {
                base.SetTitleText(Language.StringByID(StringId.Add) + " " + device.productName);
            }
            //这个界面的背景需要白色
            bodyFrameLayout.BackgroundColor = UI.CSS.CSS_Color.MainBackgroundColor;
 
            //初始化中部信息
            this.InitMiddleFrame();
        }
 
        /// <summary>
        /// 初始化中部信息
        /// </summary>
        private void InitMiddleFrame()
        {
            //图片
            var btnPic = new PicViewControl(132, 132);
            btnPic.Y = Application.GetRealHeight(69);
            btnPic.Gravity = Gravity.CenterHorizontal;
            if (integratedDevice.spk == SPK.SensorEnvironment3)
            {
                btnPic.UnSelectedImagePath = "PersonalCenter/AddDevice/EnvirSensorQingpingLitebg.png";
            }
            else if (integratedDevice.spk == SPK.SensorEnvironment2)
            {
                btnPic.UnSelectedImagePath = "PersonalCenter/AddDevice/EnvirSensorQingpingCGS1bg.png";
            }
            else
            {
                btnPic.UnSelectedImagePath = "PersonalCenter/AddDevice/EnvironmentalSensorbg.png";
            }
            bodyFrameLayout.AddChidren(btnPic);
 
            //请输入设备机上的sn码
            var textView = new FrameLayout()
            {
                Y = Application.GetRealHeight(309 - 64),
                Gravity = Gravity.CenterHorizontal,
                Width = Application.GetRealWidth(319),
                Height = Application.GetRealHeight(44),
            };
            bodyFrameLayout.AddChidren(textView);
            textView.AddChidren(new Button() { Y = Application.GetRealHeight(43), Height = 1, BackgroundColor = CSS.CSS_Color.DividingLineColor });
 
            EditText editText = new EditText()
            {
                TextAlignment = TextAlignment.Center,
                TextColor = CSS.CSS_Color.FirstLevelTitleColor,
                PlaceholderText = Language.StringByID(StringId.PlsEntrySNCode),
                PlaceholderTextColor = CSS.CSS_Color.PromptingColor1,
                TextSize = CSS.CSS_FontSize.TextFontSize,
            };
            textView.AddChidren(editText);
 
            string pairString = "";
            if (integratedDevice.spk == SPK.SensorEnvironment2)
            {
                //请输入设备机上的配对码
                var pairView = new FrameLayout()
                {
                    Y = Application.GetRealHeight(309),
                    Gravity = Gravity.CenterHorizontal,
                    Width = Application.GetRealWidth(319),
                    Height = Application.GetRealHeight(44),
                };
                bodyFrameLayout.AddChidren(pairView);
                pairView.AddChidren(new Button() { Y = Application.GetRealHeight(43), Height = 1, BackgroundColor = CSS.CSS_Color.DividingLineColor });
 
                EditText pairText = new EditText()
                {
                    TextAlignment = TextAlignment.Center,
                    TextColor = CSS.CSS_Color.FirstLevelTitleColor,
                    PlaceholderText = Language.StringByID(StringId.PlsEntryPairCode),
                    PlaceholderTextColor = CSS.CSS_Color.PromptingColor1,
                    TextSize = CSS.CSS_FontSize.TextFontSize,
                };
                pairView.AddChidren(pairText);
 
                pairText.TextChangeEventHandler = (sender, e) => {
                    pairString = e;
                };
            }
 
 
            if (integratedDevice.spk == SPK.SensorEnvironment2 || integratedDevice.spk == SPK.SensorEnvironment3)
            {
                editText.PlaceholderText = Language.StringByID(StringId.PlsEntryMacCode);
            }
            if (integratedDevice.spk == SPK.SensorEnvironment)
            {
                Button btnScan = new Button()
                {
                    Width = Application.GetRealWidth(32),
                    Height = Application.GetRealWidth(32),
                    Gravity = Gravity.CenterVertical,
                    X = Application.GetRealWidth(275),
                    UnSelectedImagePath = "Public/Scan.png"
                };
                textView.AddChidren(btnScan);
                btnScan.MouseUpEventHandler = (sender, e) =>
                {
                    Scan.OpenScan((scanString) =>
                    {
                        editText.Text = scanString;
                    });
                };
            }
            //下一步
            var btnNext = this.AddBottomClickButton(Language.StringByID(StringId.Next));
            btnNext.ButtonClickEvent += (sender, e) =>
            {
                var snCode = editText.Text.Trim();
                if (string.IsNullOrEmpty(snCode))
                {
                    editText.PlaceholderTextColor = CSS.CSS_Color.WarningColor;
                }
                else
                {
 
                    var waitPage = new Loading();
                    waitPage.Start();
                    new System.Threading.Thread(() => {
                        try
                        {
                            var pm = new HttpServerRequest();
                            var pack = pm.IndependentRegister3TyDevcie(integratedDevice.spk, snCode,integratedDevice.productName,pairString);// Language.StringByID(StringId.SensorEnvironment)
                            if (pack.Code == StateCode.SUCCESS)
                            {
                                //var revData = Newtonsoft.Json.JsonConvert.DeserializeObject<List<IntegratedBrandDevice>>(pack.Data.ToString());
                                Application.RunOnMainThread(() =>
                                {
                                    waitPage.Hide();
                                    var tipDialog = new OperationResultDisPalyPage();
                                    tipDialog.LoadPage(true, Language.StringByID(StringId.AddSuccess), "", Language.StringByID(StringId.CanStartUsingEnvironmentalSensor), Language.StringByID(StringId.Next));
                                    tipDialog.Show();
                                    AddDeviceEvent?.Invoke(new Function());
                                    this.CloseForm();
                                });
                            }
                            else if (pack.Code == "10801" || pack.Code == "9")
                            {
                                var mes = "";
                                if (Language.CurrentLanguage == "Chinese")
                                {
                                    mes = "该设备已经被添加。";
                                }
                                else
                                {
                                    mes = "This device has been added.";
                                }
                                Application.RunOnMainThread(() =>
                                {
                                    var tip = new Tip()
                                    {
                                        Text = mes,
                                        CloseTime = 2,
                                        Direction = AMPopTipDirection.None
                                    };
                                    tip.Show(MainPage.BaseView);
                                });
                            }
                            else
                            {
                                IMessageCommon.Current.ShowErrorInfoAlter(pack.Code);
                            }
                        }
                        catch (Exception ex)
                        {
                            MainPage.Log("2--::" + ex.Message);
                        }
                        finally
                        {
                            Application.RunOnMainThread(() =>
                            {
                                if (waitPage != null)
                                {
                                    waitPage.RemoveFromParent();
                                    waitPage = null;
                                }
                            });
                        }
                    })
                    { IsBackground = true }.Start();
                }
            };
        }
 
        #endregion
 
        #region ■ 关闭界面___________________________
 
        /// <summary>
        /// 关闭界面
        /// </summary>
        public override void CloseFormBefore()
        {
            this.AddDeviceEvent = null;
            base.CloseFormBefore();
        }
 
        #endregion
    }
}