using System;
|
using System.Collections.Generic;
|
using System.Text;
|
using ZigBee.Device;
|
|
namespace Shared.Phone.UserCenter.Safety
|
{
|
/// <summary>
|
/// 添加报警目标指定设备类型的设备列表
|
/// </summary>
|
public class AddDeviceAlarmTargetListForm : EditorCommonForm
|
{
|
#region ■ 变量声明___________________________
|
|
/// <summary>
|
/// 列表控件
|
/// </summary>
|
private VerticalListControl listView = null;
|
/// <summary>
|
/// 防区ID(这个东西似乎是唯一的)
|
/// </summary>
|
private int zoonID = 0;
|
/// <summary>
|
/// 设备列表
|
/// </summary>
|
private List<uDeviceInfo> listAllDevice = null;
|
/// <summary>
|
/// 需要添加的报警设备
|
/// </summary>
|
private Dictionary<string, TaskInfoData> dicSaveDevice = new Dictionary<string, TaskInfoData>();
|
|
#endregion
|
|
#region ■ 初始化_____________________________
|
|
/// <summary>
|
/// 画面显示(底层会固定调用此方法,借以完成画面创建)
|
/// </summary>
|
/// <param name="i_zoonID">防区ID</param>
|
/// <param name="i_deviceText">设备类型的名称</param>
|
/// <param name="i_listDevice">设备信息</param>
|
public void ShowForm(int i_zoonID, string i_deviceText, List<uDeviceInfo> i_listDevice)
|
{
|
this.zoonID = i_zoonID;
|
this.listAllDevice = i_listDevice;
|
|
//设置头部信息
|
base.SetTitleText(i_deviceText);
|
|
//初始化中部信息
|
this.InitMiddleFrame(i_deviceText);
|
}
|
|
/// <summary>
|
/// 初始化中部信息
|
/// </summary>
|
/// <param name="titleText">列表头部名称</param>
|
private void InitMiddleFrame(string titleText)
|
{
|
//清空bodyFrame
|
this.ClearBodyFrame();
|
|
//完成
|
var btnfinish = new BottomClickButton();
|
btnfinish.TextID = R.MyInternationalizationString.uFinish;
|
bodyFrameLayout.AddChidren(btnfinish);
|
btnfinish.ButtonClickEvent += (sender, e) =>
|
{
|
//保存选择的设备
|
this.DoSaveSelectDeviceAsync();
|
};
|
|
//XXX列表
|
var frameTemp = new FrameLayout();
|
frameTemp.Height = Application.GetRealHeight(60 + 52);
|
frameTemp.BackgroundColor = UserCenterColor.Current.White;
|
bodyFrameLayout.AddChidren(frameTemp);
|
|
var btnTitle = new NormalViewControl(850, 60, true);
|
btnTitle.X = ControlCommonResourse.XXLeft;
|
btnTitle.Y = Application.GetRealHeight(52);
|
btnTitle.TextColor = UserCenterColor.Current.TextColor2;
|
btnTitle.Text = titleText + Language.StringByID(R.MyInternationalizationString.uList);
|
btnTitle.TextSize = 15;
|
frameTemp.AddChidren(btnTitle);
|
|
this.listView = new VerticalListControl(29);
|
listView.Y = frameTemp.Bottom;
|
listView.BackgroundColor = UserCenterColor.Current.White;
|
listView.Height = btnfinish.Y - ControlCommonResourse.BottomButtonAndListViewSpace - frameTemp.Bottom;
|
bodyFrameLayout.AddChidren(this.listView);
|
|
//设置中部信息
|
this.SetMiddleFrameInfo();
|
}
|
|
/// <summary>
|
/// 设置中部信息
|
/// </summary>
|
private void SetMiddleFrameInfo()
|
{
|
HdlThreadLogic.Current.RunThread(() =>
|
{
|
if (this.Parent == null)
|
{
|
return;
|
}
|
Application.RunOnMainThread(() =>
|
{
|
int count = listAllDevice.Count - 1;
|
for (int i = 0; i < listAllDevice.Count; i++)
|
{
|
//如果那个设备已经添加了,则不再显示
|
if (HdlSafeguardLogic.Current.IsAlarmDeviceExist(this.zoonID, listAllDevice[i].Device) == true)
|
{
|
continue;
|
}
|
//添加行目标
|
this.AddRowLayout(listAllDevice[i], i != count);
|
}
|
if (listView.ChildrenCount > 0)
|
{
|
int realHeight = (listView.GetChildren(listView.ChildrenCount - 1).Height) * listView.ChildrenCount + Application.GetRealHeight(23);
|
if (realHeight < listView.Height)
|
{
|
//调整真实高度
|
listView.Height = realHeight;
|
}
|
}
|
});
|
});
|
}
|
|
#endregion
|
|
#region ■ 添加行目标_________________________
|
|
/// <summary>
|
/// 添加行目标
|
/// </summary>
|
/// <param name="deviceInfo"></param>
|
/// <param name="addLine"></param>
|
private void AddRowLayout(uDeviceInfo deviceInfo, bool addLine)
|
{
|
var row = new DeviceRoomControl(deviceInfo.Device, listView.rowSpace / 2);
|
listView.AddChidren(row);
|
row.InitControl();
|
//添加向右的图标
|
row.frameTable.AddRightArrow();
|
//底线
|
if (addLine == true)
|
{
|
row.frameTable.AddBottomLine();
|
}
|
|
//状态显示
|
var btnStatu = row.frameTable.AddMostRightView("", 400);
|
string mainKeys = Common.LocalDevice.Current.GetDeviceMainKeys(deviceInfo.Device);
|
|
row.frameTable.ButtonClickEvent += (sender, e) =>
|
{
|
List<Safeguard.TaskListInfo> listTaskinfo = null;
|
if (dicSaveDevice.ContainsKey(mainKeys) == true)
|
{
|
//取缓存中还未保存的数据
|
listTaskinfo = dicSaveDevice[mainKeys].listInfos;
|
}
|
|
if (deviceInfo.Device.Type == DeviceType.DimmableLight//调光器
|
|| deviceInfo.Device.Type == DeviceType.ColorDimmableLight)//彩灯
|
{
|
var form = new LightAlarmSettionForm();
|
form.AddForm(deviceInfo.Device, listTaskinfo);
|
form.ActionFormClose += (statuText, listInfo) =>
|
{
|
btnStatu.Text = statuText;
|
//将新的报警目标添加入缓存
|
this.AddAlarmSettionDataToMemory(deviceInfo, listInfo);
|
};
|
}
|
else if (deviceInfo.Device.Type == DeviceType.WindowCoveringDevice)//窗帘
|
{
|
var form = new CurtainAlarmSettionForm();
|
form.AddForm(deviceInfo.Device, listTaskinfo);
|
form.ActionFormClose += (statuText, listInfo) =>
|
{
|
btnStatu.Text = statuText;
|
//将新的报警目标添加入缓存
|
this.AddAlarmSettionDataToMemory(deviceInfo, listInfo);
|
};
|
}
|
else
|
{
|
//其他直接归为开关类
|
var form = new SwitchAlarmSettionForm();
|
form.AddForm(deviceInfo.Device, listTaskinfo);
|
form.ActionFormClose += (statuText, listInfo) =>
|
{
|
btnStatu.Text = statuText;
|
//将新的报警目标添加入缓存
|
this.AddAlarmSettionDataToMemory(deviceInfo, listInfo);
|
};
|
}
|
};
|
}
|
|
/// <summary>
|
/// 将新的报警目标添加入缓存
|
/// </summary>
|
/// <param name="deviceInfo"></param>
|
/// <param name="listInfo"></param>
|
private void AddAlarmSettionDataToMemory(uDeviceInfo deviceInfo, List<Safeguard.TaskListInfo> listInfo)
|
{
|
string mainKeys = Common.LocalDevice.Current.GetDeviceMainKeys(deviceInfo.Device);
|
if (listInfo == null || listInfo.Count == 0)
|
{
|
//指定为无动作模式
|
if (this.dicSaveDevice.ContainsKey(mainKeys) == true)
|
{
|
this.dicSaveDevice.Remove(mainKeys);
|
}
|
}
|
else
|
{
|
//确认添加动作
|
var data = new TaskInfoData();
|
this.dicSaveDevice[mainKeys] = data;
|
data.MacAddress = deviceInfo.Device.DeviceAddr;
|
data.Epoint = deviceInfo.Device.DeviceEpoint;
|
data.listInfos.AddRange(listInfo);
|
|
listInfo = null;
|
}
|
}
|
|
#endregion
|
|
#region ■ 保存选择的设备_______________________
|
|
/// <summary>
|
/// 保存选择的设备
|
/// </summary>
|
private async void DoSaveSelectDeviceAsync()
|
{
|
if (this.dicSaveDevice.Count == 0)
|
{
|
Application.RunOnMainThread(() =>
|
{
|
this.CloseForm();
|
});
|
return;
|
}
|
|
var listAction = new List<Safeguard.AlarmActionObj>();
|
foreach (var data in this.dicSaveDevice.Values)
|
{
|
var actionObj = new Safeguard.AlarmActionObj();
|
actionObj.DeviceAddr = data.MacAddress;
|
actionObj.Epoint = data.Epoint;
|
actionObj.Type = 0;
|
actionObj.TaskList = data.listInfos;
|
listAction.Add(actionObj);
|
}
|
//打开进度条
|
this.ShowProgressBar();
|
|
//添加报警目标到安防
|
bool success = await HdlSafeguardLogic.Current.AddAlarmTagetToSafety(this.zoonID, listAction);
|
//关闭进度条
|
this.CloseProgressBar();
|
|
if (success == true)
|
{
|
Application.RunOnMainThread(() =>
|
{
|
//关闭自身
|
this.CloseForm();
|
});
|
}
|
}
|
|
#endregion
|
|
#region ■ 结构体_______________________________
|
|
/// <summary>
|
/// 报警目标数据
|
/// </summary>
|
private class TaskInfoData
|
{
|
/// <summary>
|
/// MAC地址
|
/// </summary>
|
public string MacAddress = string.Empty;
|
/// <summary>
|
/// 端口号
|
/// </summary>
|
public int Epoint = 0;
|
/// <summary>
|
/// 报警动作
|
/// </summary>
|
public List<Safeguard.TaskListInfo> listInfos = new List<Safeguard.TaskListInfo>();
|
}
|
|
#endregion
|
}
|
}
|