New file |
| | |
| | | using System;
|
| | | using System.Collections.Generic;
|
| | | using System.Text;
|
| | | using ZigBee.Device;
|
| | |
|
| | | namespace Shared.Phone.UserCenter.Safety
|
| | | {
|
| | | /// <summary>
|
| | | /// 添加报警目标(设备)的列表界面
|
| | | /// </summary>
|
| | | public class AlarmTargetAddDeviceForm : EditorCommonForm
|
| | | {
|
| | | #region ■ 变量声明___________________________
|
| | |
|
| | | /// <summary>
|
| | | /// 列表控件
|
| | | /// </summary>
|
| | | private VerticalListControl listView = null;
|
| | | /// <summary>
|
| | | /// 防区ID(这个东西似乎是唯一的)
|
| | | /// </summary>
|
| | | private int zoonID = 0;
|
| | | /// <summary>
|
| | | /// 设备列表
|
| | | /// </summary>
|
| | | private List<CommonDevice> 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<CommonDevice> 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 frameBack = new FrameLayout();
|
| | | frameBack.BackgroundColor = UserCenterColor.Current.White;
|
| | | frameBack.Height = Application.GetRealHeight(8);
|
| | | bodyFrameLayout.AddChidren(frameBack);
|
| | |
|
| | | this.listView = new VerticalListControl(12);
|
| | | listView.Y = frameBack.Bottom;
|
| | | listView.BackgroundColor = UserCenterColor.Current.White;
|
| | | listView.Height = bodyFrameLayout.Height - frameBack.Bottom;
|
| | | bodyFrameLayout.AddChidren(listView);
|
| | |
|
| | | //完成
|
| | | var btnfinish = new BottomClickButton();
|
| | | btnfinish.TextID = R.MyInternationalizationString.uFinish;
|
| | | bodyFrameLayout.AddChidren(btnfinish);
|
| | | btnfinish.ButtonClickEvent += (sender, e) =>
|
| | | {
|
| | | //保存选择的设备
|
| | | this.DoSaveSelectDeviceAsync();
|
| | | };
|
| | |
|
| | | HdlThreadLogic.Current.RunMainInThread(() =>
|
| | | {
|
| | | int count = listAllDevice.Count - 1;
|
| | | for (int i = 0; i < listAllDevice.Count; i++)
|
| | | {
|
| | | //如果那个设备已经添加了,则不再显示
|
| | | if (HdlSafeguardLogic.Current.IsAlarmDeviceExist(this.zoonID, listAllDevice[i]) == true)
|
| | | {
|
| | | continue;
|
| | | }
|
| | | //添加行目标
|
| | | this.AddRowLayout(listAllDevice[i], i != count);
|
| | | }
|
| | | //调整真实高度
|
| | | listView.AdjustRealHeightByBottomButton(Application.GetRealHeight(23));
|
| | | });
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
|
| | | #region ■ 添加行目标_________________________
|
| | |
|
| | | /// <summary>
|
| | | /// 添加行目标
|
| | | /// </summary>
|
| | | /// <param name="device"></param>
|
| | | /// <param name="addLine"></param>
|
| | | private void AddRowLayout(CommonDevice device, bool addLine)
|
| | | {
|
| | | string mainKeys = Common.LocalDevice.Current.GetDeviceMainKeys(device);
|
| | |
|
| | | var rowContr = new FrameRowControl(listView.rowSpace / 2);
|
| | | listView.AddChidren(rowContr);
|
| | |
|
| | | //图标
|
| | | var btnIcon = rowContr.AddLeftIcon(81);
|
| | | Common.LocalDevice.Current.SetDeviceIconToControl(btnIcon, device);
|
| | | //设备名
|
| | | var btnName = rowContr.AddLeftCaption(Common.LocalDevice.Current.GetDeviceEpointName(device), 700);
|
| | | btnName.TextSize = 15;
|
| | | //右箭头
|
| | | rowContr.AddRightArrow();
|
| | | if (addLine == true)
|
| | | {
|
| | | //底线
|
| | | rowContr.AddBottomLine();
|
| | | }
|
| | | //状态显示
|
| | | var btnStatu = rowContr.AddMostRightView("", 500);
|
| | | rowContr.ButtonClickEvent += (sender, e) =>
|
| | | {
|
| | | List<Safeguard.TaskListInfo> listTaskinfo = null;
|
| | | if (dicSaveDevice.ContainsKey(mainKeys) == true)
|
| | | {
|
| | | //取缓存中还未保存的数据
|
| | | listTaskinfo = dicSaveDevice[mainKeys].listInfos;
|
| | | }
|
| | |
|
| | | if (device.Type == DeviceType.DimmableLight//调光器
|
| | | || device.Type == DeviceType.ColorDimmableLight)//彩灯
|
| | | {
|
| | | var form = new AlarmTargetStatuSelectLightForm();
|
| | | form.AddForm(device, listTaskinfo);
|
| | | form.FinishSelectEvent += (statuText, listInfo) =>
|
| | | {
|
| | | btnStatu.Text = statuText;
|
| | | //将新的报警目标添加入缓存
|
| | | this.AddAlarmSettionDataToMemory(device, listInfo);
|
| | | };
|
| | | }
|
| | | else if (device.Type == DeviceType.WindowCoveringDevice)//窗帘
|
| | | {
|
| | | var form = new AlarmTargetStatuSelectCurtainForm();
|
| | | form.AddForm(device, listTaskinfo);
|
| | | form.FinishSelectEvent += (statuText, listInfo) =>
|
| | | {
|
| | | btnStatu.Text = statuText;
|
| | | //将新的报警目标添加入缓存
|
| | | this.AddAlarmSettionDataToMemory(device, listInfo);
|
| | | };
|
| | | }
|
| | | else
|
| | | {
|
| | | //其他直接归为开关类
|
| | | var form = new AlarmTargetStatuSelectSwitchForm();
|
| | | form.AddForm(device, listTaskinfo);
|
| | | form.FinishSelectEvent += (statuText, listInfo) =>
|
| | | {
|
| | | btnStatu.Text = statuText;
|
| | | //将新的报警目标添加入缓存
|
| | | this.AddAlarmSettionDataToMemory(device, listInfo);
|
| | | };
|
| | | }
|
| | | };
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 将新的报警目标添加入缓存
|
| | | /// </summary>
|
| | | /// <param name="deviceInfo"></param>
|
| | | /// <param name="listInfo"></param>
|
| | | private void AddAlarmSettionDataToMemory(CommonDevice device, List<Safeguard.TaskListInfo> listInfo)
|
| | | {
|
| | | string mainKeys = Common.LocalDevice.Current.GetDeviceMainKeys(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 = device.DeviceAddr;
|
| | | data.Epoint = device.DeviceEpoint;
|
| | | data.listInfos.AddRange(listInfo);
|
| | | }
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
|
| | | #region ■ 保存选择的设备_____________________
|
| | |
|
| | | /// <summary>
|
| | | /// 保存选择的设备
|
| | | /// </summary>
|
| | | private async void DoSaveSelectDeviceAsync()
|
| | | {
|
| | | if (this.dicSaveDevice.Count == 0)
|
| | | {
|
| | | 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);
|
| | | }
|
| | | //添加报警目标到安防
|
| | | bool success = await HdlSafeguardLogic.Current.AddAlarmTagetToSafety(this.zoonID, listAction);
|
| | | if (success == true)
|
| | | {
|
| | | //关闭自身
|
| | | 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
|
| | | }
|
| | | }
|