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
{
///
/// 添加遥控器的方法
///
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);
}
///
/// 发送遥控器命令方法
///
///
///
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
GetLsit(FrameLayout frameLayout, Action action, string id, string if_str)
{
List list = new List();
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>(str);
}
}
else
{
Method method = new Method();
method.ErrorShow(responsePackNew);
}
return list;
}
///
/// MQTT主题推送下来的数据(遥控器添加)
///
public static string addcontronsid = "";
///
///
///
///
///
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;
}
///
/// 错误码提示
///
///
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
{
///
/// 设备类型主键Id
///
public string id=string.Empty;
///
/// 设备类型(投影仪,风扇,机顶盒...)
///
public string deviceType = string.Empty;
///
///品牌名称
///
public string brandName = string.Empty;
///
/// 红外码
///
public string irCode = string.Empty;
///
/// 品牌主键Id
///
public string brandId = string.Empty;
///
/// 红外码索引序号
///
public string irIndex = string.Empty;
}
}
}