using System;
using System.Collections.Generic;
using Shared.Common;
using Shared.Phone.UserCenter.Device.Bind;
using ZigBee.Device;
using static ZigBee.Device.BindObj;
namespace Shared.Phone.UserCenter.DeviceBind
{
public class PanelSimpleMutilfunctionAddTargetsForm : BindCommonLayout
{
#region 构造函数
///
/// 构造函数
///
///
/// 0:场景 1:开关 2:插座 3:灯光 4:遮阳 5:空调 6:新风
public PanelSimpleMutilfunctionAddTargetsForm(string deviceMac, int deviceBindType)
{
curControlDev = new Panel();
var dev = Common.LocalDevice.Current.GetDevice(deviceMac, 62);//简约面板随便一个回路来获取设备
if (dev != null)
{
curControlDev.CurrentGateWayId = dev.CurrentGateWayId;
}
curControlDev.Type = DeviceType.OnOffSwitch;
curControlDev.DeviceAddr = deviceMac;
curBindType = deviceBindType;
}
#endregion
#region 变量申明
///
/// 控制设备
///
Panel curControlDev;
///
/// 当前被绑设备
///
CommonDevice curBindDevice;
///
/// 显示被绑定设备或场景的view
///
VerticalFrameRefreshControl midVerticalScrolViewLayout;
///
/// 显示房间的view
///
HorizontalScrolViewLayout btnHorizontalScrolViewLayout;
///
/// 当前设备绑定类型 0:场景 1:开关 2:插座 3:灯光 4:遮阳 5:空调 6:新风
///
int curBindType = 0;
///
/// 本地房间列表
///
List supportRoomList = new List();
///
/// 保存完成按钮
///
Button btnFinifh;
///
/// 绑定类型提示文本
///
Button btnTipText;
///
/// 楼层文本
///
Button btnFloorText;
///
/// 楼层列表
///
Dictionary dicFloorList = new Dictionary();
///
/// 按键配置的目标列表
///
List targetList = new List();
///
/// 按键配置的目标列表
///
List targetScList = new List();
///
/// 所有房间中支持被绑定的设备列表
///
List currentPanelSupportBindDeviceList = new List();
///
/// 所有房间中支持被绑定的场景列表
///
List currentPanelSupportBindSceneList = new List();
///
/// 当前类型的绑定表
///
List curBindTypeList = new List();
///
/// 未分配的设备列表
///
List undistributeDevList = new List();
///
/// 未分配的设备列表
///
List undistributeScList = new List();
///
/// 当前房间中支持被绑定的设备列表
///
List currentRoomSupportBindDeviceList = new List();
///
/// 当前房间中支持被绑定的设备列表
///
List currentRoomSupportBindSceneList = new List();
///
/// 当前支持的端点绑定表
///
List curSupportBindEpointList = new List();
///
/// 当前被选择目标即将绑定的端点
///
List curSendEpointList = new List();
///
/// 当前支持的调光个数[存调光灯光的设备]
///
List curSupportDimmerEpointList = new List();
///
/// 当前支持的调光开关个数[存继电器的功能类型是灯光的设备]
///
List curSupportLightEpointList = new List();
///
/// 面板中存在的键值
///
List panelBindListKey = null;
///
/// 刷新绑定表页面
///
public Action actionRefreshBindList;
///
/// 是否能刷新
///
private bool canFresh = false;
#endregion
#region UI设计
///
/// 目标页显示
///
public void Show()
{
TitleUI();
MidFrameLayouUI();
//首次初始化数据
CommonPage.Loading.Start("");
InitData();
}
///
/// 标题栏
///
void TitleUI()
{
string titleText = Language.StringByID(R.MyInternationalizationString.Bind);
switch (curBindType)
{
case 0:
titleText += Language.StringByID(R.MyInternationalizationString.scene);
break;
case 1:
titleText += Language.StringByID(R.MyInternationalizationString.uDeviceBelongId13);
break;
case 2:
titleText += Language.StringByID(R.MyInternationalizationString.uDeviceBelongId14);
break;
case 3:
titleText += Language.StringByID(R.MyInternationalizationString.uDeviceBelongId15);
break;
case 4:
titleText += Language.StringByID(R.MyInternationalizationString.uDeviceBelongId200);
break;
case 5:
titleText += Language.StringByID(R.MyInternationalizationString.uDeviceBelongId3600);
break;
case 6:
titleText += Language.StringByID(R.MyInternationalizationString.uDeviceBelongId2310);
break;
}
this.TopFrameLayout(this, titleText);
EventHandler eHandlerBack = (sender, e) =>
{
RemoveFromParent();
};
this.btnTitle.Width = Application.GetRealWidth(1080 - 161 - 300);
this.btnBack.MouseUpEventHandler += eHandlerBack;
this.btnBackFrameLayout.MouseUpEventHandler += eHandlerBack;
this.MidFrameLayout(this);
}
///
/// 中部UI【标题栏下的UI】
///
void MidFrameLayouUI()
{
var btnMidTopLayout = new FrameLayout
{
Height = Application.GetRealHeight(389 - 184),
};
this.midFrameLayout.AddChidren(btnMidTopLayout);
//房间栏
btnHorizontalScrolViewLayout = new HorizontalScrolViewLayout
{
X = Application.GetRealWidth(58),
};
btnMidTopLayout.AddChidren(btnHorizontalScrolViewLayout);
//设备栏
midVerticalScrolViewLayout = new VerticalFrameRefreshControl()
{
Y = btnMidTopLayout.Bottom,
Height = Application.GetRealHeight(1145),
};
this.midFrameLayout.AddChidren(midVerticalScrolViewLayout);
midVerticalScrolViewLayout.BeginHeaderRefreshingAction += () =>
{
midVerticalScrolViewLayout.BeginHeaderRefreshing();
canFresh = true;
InitData();
};
//底部保存栏
var bottomFrameLayout = new FrameLayout()
{
Width = LayoutParams.MatchParent,
Height = Application.GetRealHeight(84 * 2 + 127),
Y = Application.GetRealHeight(1388),
};
this.midFrameLayout.AddChidren(bottomFrameLayout);
btnTipText = new Button()
{
Height = Application.GetRealHeight(84),
TextID = R.MyInternationalizationString.Tip,
TextColor = Shared.Common.ZigbeeColor.Current.XMGray3,
TextSize = 12,
TextAlignment = TextAlignment.Center,
};
bottomFrameLayout.AddChidren(btnTipText);
btnFinifh = new Button()
{
Width = Application.GetRealWidth(907),
Height = Application.GetRealHeight(127),
Y = Application.GetRealHeight(49 + 35),
Gravity = Gravity.CenterHorizontal,
Radius = (uint)Application.GetRealHeight(127) / 2,
TextID = R.MyInternationalizationString.Save,
BackgroundColor = Shared.Common.ZigbeeColor.Current.XMBlack,
TextColor = Shared.Common.ZigbeeColor.Current.XMWhite,
IsBold = true,
TextSize = 16,
};
bottomFrameLayout.AddChidren(btnFinifh);
btnFinifh.MouseUpEventHandler += (sender, e) =>
{
curSendEpointList.Clear();
SaveTarget();
};
}
///
/// 面板绑定目标表显示
///
/// Gateway.
/// Key.
void RefreshRoomList()
{
btnHorizontalScrolViewLayout.RemoveAll();
Room curRoom = null;
Button curentOldRoom = null;
FrameLayout curentOldRoomFrameLayout = null;
int index = 0;
List roomTempList = new List { };
Room slectedRoom = null;
var roomUn = new Room();
roomUn.Name = Language.StringByID(R.MyInternationalizationString.Undistributed);
roomUn.Id = "UndistributedId";
if (supportRoomList.Count != 0)
{
roomTempList = MutilfunctionPanelMethod.GetSupportRoomList(curControlDev, supportRoomList, curBindTypeList, curBindType);
}
if (curBindType == 0)
{
if (undistributeScList != null && undistributeScList.Count != 0)
{
roomTempList.Add(roomUn);
}
}
else
{
if (undistributeDevList.Count != 0)
{
roomTempList.Add(roomUn);
}
}
for (int i = 0; i < roomTempList.Count; i++)
{
var room = roomTempList[i];
bool canSelect = false;
if (curControlDev.currentSelectRoomId == room.Id)
{
slectedRoom = room;
canSelect = true;
}
//房间
var btnRoomFrameLayout = new FrameLayout
{
Height = Application.GetMinReal(159),
Width = Application.GetMinReal(255),
Y = Application.GetRealHeight(23),
X = Application.GetRealWidth(5),
BackgroundImagePath = "Item/RoomIconBackground.png",
BorderWidth = 1,
};
btnHorizontalScrolViewLayout.AddChidren(btnRoomFrameLayout);
var btnRoom = new Button
{
Height = Application.GetRealHeight(66),
Width = Application.GetRealWidth(250),
Y = Application.GetRealHeight(58),
X = Application.GetRealWidth(14),
Text = room.Name,
TextSize = 12,
TextColor = Shared.Common.ZigbeeColor.Current.XMGray3,
Gravity = Gravity.Center,
};
btnRoomFrameLayout.AddChidren(btnRoom);
btnRoom.IsSelected = false;
if (canSelect)
{
btnRoomFrameLayout.BackgroundImagePath = "Item/RoomIconBackgroundSelected.png";
btnRoom.TextColor = Shared.Common.ZigbeeColor.Current.XMWhite;
curentOldRoom = btnRoom;
curentOldRoomFrameLayout = btnRoomFrameLayout;
}
//被绑定的目标还未分配区域,默认是最后一个,未分配房间
if (string.IsNullOrEmpty(curControlDev.currentSelectRoomId))
{
if (index == roomTempList.Count - 1)
{
btnRoomFrameLayout.BackgroundImagePath = "Item/RoomIconBackgroundSelected.png";
btnRoom.TextColor = Shared.Common.ZigbeeColor.Current.XMWhite;
curentOldRoom = btnRoom;
curentOldRoomFrameLayout = btnRoomFrameLayout;
}
}
if (index == roomTempList.Count - 1 && index > 3)
{
var btnRoomFrameLayoutEmpty = new FrameLayout
{
Height = Application.GetMinReal(159),
Width = Application.GetMinReal(50),
Y = Application.GetRealHeight(23),
X = Application.GetRealWidth(5),
//BorderWidth = 1,
};
btnHorizontalScrolViewLayout.AddChidren(btnRoomFrameLayoutEmpty);
}
EventHandler eHandlerRoom = (sender, e) =>
{
if (!btnRoom.IsSelected)
{
if (curentOldRoom != null)
{
curentOldRoom.TextColor = Shared.Common.ZigbeeColor.Current.XMGray3;
}
curentOldRoom = btnRoom;
curentOldRoom.TextColor = Shared.Common.ZigbeeColor.Current.XMWhite;
}
if (btnRoomFrameLayout.BorderWidth == 1)
{
if (curentOldRoomFrameLayout != null)
{
curentOldRoomFrameLayout.BorderWidth = 1;
curentOldRoomFrameLayout.BorderColor = Shared.Common.ZigbeeColor.Current.XMOrange;
curentOldRoomFrameLayout.BackgroundImagePath = "Item/RoomIconBackground.png";
}
curentOldRoomFrameLayout = btnRoomFrameLayout;
curentOldRoomFrameLayout.BorderWidth = 0;
curentOldRoomFrameLayout.BackgroundImagePath = "Item/RoomIconBackgroundSelected.png";
}
curRoom = room;
//新风面板保存使能
btnFinifh.Enable = true;
btnFinifh.BackgroundColor = Shared.Common.ZigbeeColor.Current.XMBlack;
if (curBindType == 0)
{
RefreshSceneList(curRoom);
}
else
{
RefreshDeviceList(curRoom);
}
};
btnRoom.MouseUpEventHandler += eHandlerRoom;
btnRoomFrameLayout.MouseUpEventHandler += eHandlerRoom;
index++;
}
BindInfo.FinishDisplay(roomTempList, btnFinifh);
if (roomTempList.Count == 0)
{
curRoom = new Shared.Common.Room();
}
else
{
if (slectedRoom == null)
{
//未选中默认最后一个“未分配选中”
curRoom = roomTempList[index - 1];
var view = btnHorizontalScrolViewLayout.GetChildren(index - 1);
var frame = (FrameLayout)view;
var btn = (Button)frame.GetChildren(0);
frame.BackgroundImagePath = "Item/RoomIconBackgroundSelected.png";
btn.TextColor = Shared.Common.ZigbeeColor.Current.XMWhite;
curentOldRoom = btn;
curentOldRoomFrameLayout = frame;
}
else
{
curRoom = slectedRoom;
}
}
if (curBindType == 0)
{
RefreshSceneList(curRoom);
}
else
{
RefreshDeviceList(curRoom);
}
switch (curBindType)
{
case 1:
btnTipText.Text = MutilfunctionPanelMethod.MatchTypeBindTextTip(curBindType, MutilfunctionPanelMethod.curSwitchCount + MutilfunctionPanelMethod.curSocketCount + MutilfunctionPanelMethod.curLightFromRelayCount);
break;
case 2:
btnTipText.Text = MutilfunctionPanelMethod.MatchTypeBindTextTip(curBindType, MutilfunctionPanelMethod.curSwitchCount + MutilfunctionPanelMethod.curSocketCount + MutilfunctionPanelMethod.curLightFromRelayCount);
break;
case 3:
btnTipText.Text = MutilfunctionPanelMethod.MatchTypeBindTextTip(curBindType, MutilfunctionPanelMethod.curSwitchCount + MutilfunctionPanelMethod.curSocketCount + MutilfunctionPanelMethod.curLightFromRelayCount + MutilfunctionPanelMethod.curLightCount);
break;
default:
btnTipText.Text = MutilfunctionPanelMethod.MatchTypeBindTextTip(curBindType, curBindTypeList.Count);
break;
}
}
///
/// 按键绑目标表显示
///
///
void RefreshDeviceList(Room curRoom)
{
midVerticalScrolViewLayout.RemoveAll();
Button oldDevice = null;
int curIndex = 0;
if (curRoom.Id == "UndistributedId")
{
currentRoomSupportBindDeviceList = MutilfunctionPanelMethod.GetUndistributeDeviceList(undistributeDevList, curBindTypeList, curBindType);
}
else
{
currentRoomSupportBindDeviceList = MutilfunctionPanelMethod.GetCurRoomSupportDeviceList(curRoom, currentRoomSupportBindDeviceList, curBindTypeList, curBindType);
}
if (currentRoomSupportBindDeviceList.Count == 0)
{
btnFinifh.Enable = false;
btnFinifh.BackgroundColor = Shared.Common.ZigbeeColor.Current.XMUnSelect;
return;
}
foreach (var device in currentRoomSupportBindDeviceList)
{
#region 绑定表UI显(无数据处理)
var rowLayout = new FrameLayout()
{
Height = Application.GetRealHeight(23 + 127),
BackgroundColor = Shared.Common.ZigbeeColor.Current.XMWhite,
};
midVerticalScrolViewLayout.AddChidren(rowLayout);
var devicePic = new Button()
{
X = Application.GetMinRealAverage(58),
Y = Application.GetMinRealAverage(46),
Width = Application.GetMinRealAverage(81),
Height = Application.GetMinRealAverage(81),
UnSelectedImagePath = device.IconPath,
};
rowLayout.AddChidren(devicePic);
var btnBindName = new Button()
{
Width = Application.GetRealWidth(790),
X = devicePic.Right + Application.GetRealWidth(20),
TextAlignment = TextAlignment.CenterLeft,
TextSize = 15,
Text = Common.LocalDevice.Current.GetDeviceEpointName(device),
};
rowLayout.AddChidren(btnBindName);
var btnChoose = new Button()
{
Width = Application.GetMinReal(60),
Height = Application.GetMinReal(60),
X = Application.GetRealWidth(861 + 81),
Y = Application.GetRealHeight(35),
SelectedImagePath = "DoorLock/SelectedIcon.png",
Visible = false,
};
rowLayout.AddChidren(btnChoose);
var line2 = new Button()
{
Y = rowLayout.Height - 1,
X = devicePic.Right + Application.GetRealWidth(20),
Width = Application.GetRealWidth(965 - 116),
Height = 1,
BackgroundColor = Shared.Common.ZigbeeColor.Current.XMRowLine,
};
rowLayout.AddChidren(line2);
if (curIndex == currentRoomSupportBindDeviceList.Count - 1)
{
line2.Visible = false;
}
if (Common.LocalDevice.Current.CheckDeviceIsOnline(device) == true)
{
btnBindName.TextColor = Shared.Common.ZigbeeColor.Current.TextBlack;
}
else
{
btnBindName.TextColor = Shared.Common.ZigbeeColor.Current.XMGray3;
}
switch (curBindType)
{
case 1:
devicePic.UnSelectedImagePath = "BindPic/Switch.png";
break;
case 2:
devicePic.UnSelectedImagePath = "Device/Socket1.png";
break;
case 3:
if (device.Type == DeviceType.DimmableLight)
{
devicePic.UnSelectedImagePath = "Device/Light.png";
}
if (device.Type == DeviceType.OnOffOutput)
{
devicePic.UnSelectedImagePath = "Device/RelayEpoint.png";
}
break;
case 4:
devicePic.UnSelectedImagePath = "Device/AirQualitySensorEpoint.png";
if (device.Type == DeviceType.WindowCoveringDevice)
{
var tempDev = device as Rollershade;
if (tempDev.WcdType == 4)
{
devicePic.UnSelectedImagePath = "BindPic/Curtain.png";
}
else
{
devicePic.UnSelectedImagePath = "BindPic/Roller.png";
}
}
break;
case 5:
devicePic.UnSelectedImagePath = "Device/AirConditionerEpoint.png";
break;
case 6:
devicePic.UnSelectedImagePath = "Device/FreshAirEpoint.png";
break;
}
#endregion
string mianKey = device.DeviceAddr + device.DeviceEpoint;
if (targetList.Count != 0)
{
foreach (var bindedDev in targetList)
{
if (bindedDev.DeviceAddr + bindedDev.DeviceEpoint == mianKey)
{
btnChoose.IsSelected = true;
btnChoose.Visible = true;
oldDevice = btnChoose;
}
}
}
EventHandler hander = (sender, e) =>
{
btnChoose.IsSelected = !btnChoose.IsSelected;
if (curBindType != 6)
{
if (curSupportBindEpointList.Count == 0)
{
new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.BindFull), Direction = AMPopTipDirection.None, CloseTime = 1 }.Show(Common.CommonPage.Instance);
return;
}
if (curBindType == 3)
{
if (device.Type == DeviceType.DimmableLight)
{
if (curSupportDimmerEpointList.Count == 0)
{
new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.CanSelectRelay), Direction = AMPopTipDirection.None, CloseTime = 1 }.Show(Common.CommonPage.Instance);
return;
}
}
if (device.Type == DeviceType.OnOffOutput)
{
if (curSupportLightEpointList.Count == 0)
{
new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.CanSelectDimmer), Direction = AMPopTipDirection.None, CloseTime = 1 }.Show(Common.CommonPage.Instance);
return;
}
}
}
if (!btnChoose.IsSelected)
{
targetList.Remove(device);
btnChoose.IsSelected = false;
btnChoose.Visible = false;
}
else
{
if (targetList.Count >= curSupportBindEpointList.Count)
{
new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.BindFull), Direction = AMPopTipDirection.None, CloseTime = 1 }.Show(Common.CommonPage.Instance);
}
else
{
if (curBindType == 3)
{
//临时记录灯光类型中调光个数和开关个数
var tList1 = new List { };
var tList2 = new List { };
foreach (var tD in targetList)
{
if (tD.Type == DeviceType.DimmableLight)
{
tList1.Add(tD);
}
if (tD.Type == DeviceType.OnOffOutput)
{
tList2.Add(tD);
}
}
if (device.Type == DeviceType.DimmableLight)
{
if (tList1.Count >= curSupportDimmerEpointList.Count)
{
new Tip() { MaxWidth = 310, Text = Language.StringByID(R.MyInternationalizationString.CanSelectRelay), Direction = AMPopTipDirection.None, CloseTime = 2 }.Show(Common.CommonPage.Instance);
return;
}
}
if (device.Type == DeviceType.OnOffOutput)
{
if (tList2.Count >= curSupportLightEpointList.Count)
{
new Tip() { MaxWidth = 310, Text = Language.StringByID(R.MyInternationalizationString.CanSelectDimmer), Direction = AMPopTipDirection.None, CloseTime = 2 }.Show(Common.CommonPage.Instance);
return;
}
}
}
targetList.Add(device);
btnChoose.IsSelected = true;
btnChoose.Visible = true;
}
}
}
else
{
if (curSupportBindEpointList.Count == 0)
{
new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.BindFull), Direction = AMPopTipDirection.None, CloseTime = 1 }.Show(Common.CommonPage.Instance);
return;
}
if (!btnChoose.IsSelected)
{
if (oldDevice != null)
{
oldDevice.IsSelected = false;
oldDevice.Visible = false;
}
oldDevice = btnChoose;
oldDevice.IsSelected = false;
oldDevice.Visible = false;
targetList.Clear();
}
else
{
if (oldDevice != null)
{
oldDevice.IsSelected = false;
oldDevice.Visible = false;
}
oldDevice = btnChoose;
oldDevice.IsSelected = true;
oldDevice.Visible = true;
targetList.Clear();
targetList.Add(device);
}
}
if (targetList.Count == 0)
{
btnFinifh.Enable = false;
btnFinifh.BackgroundColor = Shared.Common.ZigbeeColor.Current.XMUnSelect;
}
else
{
btnFinifh.Enable = true;
btnFinifh.BackgroundColor = Shared.Common.ZigbeeColor.Current.XMBlack;
}
};
rowLayout.MouseUpEventHandler += hander;
devicePic.MouseUpEventHandler += hander;
btnBindName.MouseUpEventHandler += hander;
btnChoose.MouseUpEventHandler += hander;
curIndex++;
}
}
///
/// 按键绑目标表显示
///
///
void RefreshSceneList(Room curRoom)
{
midVerticalScrolViewLayout.RemoveAll();
Button oldScene = null;
int curIndex = 0;
if (curRoom.Id == "UndistributedId")
{
currentRoomSupportBindSceneList = HdlSceneLogic.Current.GetUnalloctedScenes();
}
else
{
currentRoomSupportBindSceneList = MutilfunctionPanelMethod.GetCurRoomSupportSceneList(curRoom, currentRoomSupportBindSceneList, curBindTypeList);
}
if (currentRoomSupportBindSceneList.Count == 0)
{
btnFinifh.Enable = false;
btnFinifh.BackgroundColor = Shared.Common.ZigbeeColor.Current.XMUnSelect;
return;
}
foreach (var scene in currentRoomSupportBindSceneList)
{
#region 绑定表UI显(无数据处理)
var rowLayout = new FrameLayout()
{
Height = Application.GetRealHeight(23 + 127),
BackgroundColor = Shared.Common.ZigbeeColor.Current.XMWhite,
};
midVerticalScrolViewLayout.AddChidren(rowLayout);
var devicePic = new Button()
{
X = Application.GetMinRealAverage(58),
Y = Application.GetMinRealAverage(46),
Width = Application.GetMinRealAverage(81),
Height = Application.GetMinRealAverage(81),
UnSelectedImagePath = "Scene/SceneIcon.png",
};
rowLayout.AddChidren(devicePic);
var btnBindName = new Button()
{
Width = Application.GetRealWidth(790),
X = devicePic.Right + Application.GetRealWidth(20),
TextAlignment = TextAlignment.CenterLeft,
TextSize = 15,
TextColor = Shared.Common.ZigbeeColor.Current.TextBlack,
Text = scene.Name,
};
rowLayout.AddChidren(btnBindName);
var btnChoose = new Button()
{
Width = Application.GetMinReal(60),
Height = Application.GetMinReal(60),
X = Application.GetRealWidth(861 + 81),
Y = Application.GetRealHeight(35),
SelectedImagePath = "DoorLock/SelectedIcon.png",
Visible = false,
};
rowLayout.AddChidren(btnChoose);
var line2 = new Button()
{
Y = rowLayout.Height - 1,
X = devicePic.Right + Application.GetRealWidth(20),
Width = Application.GetRealWidth(965 - 116),
Height = 1,
BackgroundColor = Shared.Common.ZigbeeColor.Current.XMRowLine,
};
rowLayout.AddChidren(line2);
if (curIndex == currentRoomSupportBindDeviceList.Count - 1)
{
line2.Visible = false;
}
#endregion
if (targetScList.Count != 0)
{
foreach (var bindedDev in targetScList)
{
if (bindedDev.Id == scene.Id)
{
btnChoose.IsSelected = true;
btnChoose.Visible = true;
oldScene = btnChoose;
}
}
}
EventHandler hander = (sender, e) =>
{
if (curSupportBindEpointList.Count == 0 || curSupportBindEpointList.Count == targetScList.Count)
{
new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.BindFull), Direction = AMPopTipDirection.None, CloseTime = 1 }.Show(Common.CommonPage.Instance);
return;
}
btnChoose.IsSelected = !btnChoose.IsSelected;
if (!btnChoose.IsSelected)
{
targetScList.Remove(scene);
btnChoose.IsSelected = false;
btnChoose.Visible = false;
}
else
{
if (targetScList.Count >= curSupportBindEpointList.Count)
{
new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.BindFull), Direction = AMPopTipDirection.None, CloseTime = 1 }.Show(Common.CommonPage.Instance);
}
else
{
targetScList.Add(scene);
btnChoose.IsSelected = true;
btnChoose.Visible = true;
}
}
if (targetScList.Count == 0)
{
btnFinifh.Enable = false;
btnFinifh.BackgroundColor = Shared.Common.ZigbeeColor.Current.XMUnSelect;
}
else
{
btnFinifh.Enable = true;
btnFinifh.BackgroundColor = Shared.Common.ZigbeeColor.Current.XMBlack;
}
};
rowLayout.MouseUpEventHandler += hander;
devicePic.MouseUpEventHandler += hander;
btnBindName.MouseUpEventHandler += hander;
btnChoose.MouseUpEventHandler += hander;
curIndex++;
}
}
#endregion
#region 数据处理
///
/// 初始化设备数据
///
void InitData()
{
System.Threading.Tasks.Task.Run(async () =>
{
try
{
//获取楼层
dicFloorList = HdlRoomLogic.Current.GetFloorSortList();
curControlDev.currentSelectFloorId = BindInfo.GetCurrentSelectFloorId();
//获取房间列表
supportRoomList = BindInfo.GetSupportRoomList();
//获取面板已经绑定的匹配类型的列表
curBindTypeList = MutilfunctionPanelMethod.GetMatchBindList(curBindType);
if (curBindType == 0)
{
currentPanelSupportBindSceneList = MutilfunctionPanelMethod.GetAllRoomSupportSceneList(currentPanelSupportBindSceneList, supportRoomList, curBindTypeList);
// 获取本地未分配的支持当前类型的绑定场景列表
undistributeScList = HdlSceneLogic.Current.GetUnalloctedScenes();
}
else
{
//获取所有房间中匹配的能绑的目
currentPanelSupportBindDeviceList = MutilfunctionPanelMethod.GetAllRoomSupportDeviceList(currentPanelSupportBindDeviceList, supportRoomList, curBindTypeList, curBindType);
//获取本地未分配的支持当前类型的绑定设备列表
undistributeDevList = MutilfunctionPanelMethod.GetUndistributeDeviceList(undistributeDevList, curBindTypeList, curBindType);
}
//获取当前支持的端点绑定表
curSupportBindEpointList = MutilfunctionPanelMethod.GetMatchEpointList(curBindType);
if (curBindType == 3)
{
foreach (var ep in curSupportBindEpointList)
{
if (ep >= 22 && ep <= 28)
{
curSupportDimmerEpointList.Add(ep);
}
if (ep >= 52 && ep <= 61)
{
curSupportLightEpointList.Add(ep);
}
}
}
}
catch (Exception ex)
{
var mess = ex.Message;
}
finally
{
Application.RunOnMainThread(() =>
{
if (!canFresh)
{
BindDownFrameLayout(this.midFrameLayout, curControlDev, dicFloorList, ref btnFloorText);
}
ChooseFloorAction += (floorId, btnMethodText) =>
{
btnFloorText.Text = dicFloorList[floorId];
//获取房间列表
supportRoomList.Clear();
supportRoomList = BindInfo.GetSupportRoomList();
if (curBindType == 0)
{
// 获取本地未分配的支持当前类型的绑定场景列表
undistributeScList = HdlSceneLogic.Current.GetUnalloctedScenes();
}
else
{
//获取本地未分配的支持当前类型的绑定设备列表
undistributeDevList = MutilfunctionPanelMethod.GetUndistributeDeviceList(undistributeDevList, curBindTypeList, curBindType);
}
RefreshRoomList();
};
//默认楼层显示
if (BindInfo.GetCurrentSelectFloorIdName() != null)
{
Application.RunOnMainThread(() =>
{
btnFloorText.Text = BindInfo.GetCurrentSelectFloorIdName();
});
}
//获取楼层中房间列表
RefreshRoomList();
CommonPage.Loading.Hide();
canFresh = false;
midVerticalScrolViewLayout.EndHeaderRefreshing();
});
}
});
}
///
/// 保存目标
///
///
void SaveTarget()
{
btnFinifh.Enable = false;
btnFinifh.BackgroundColor = Shared.Common.ZigbeeColor.Current.XMUnSelect;
System.Threading.Tasks.Task.Run(() =>
{
try
{
Application.RunOnMainThread(() =>
{
CommonPage.Loading.Start("");
});
int tempBindCluster = -1;
int targetSendCount = 0;
int targetRecCount = 0;
if (curBindType == 0)
{
targetSendCount = targetScList.Count;
if (targetScList.Count == 0)
{
//没有目标提示
Application.RunOnMainThread(() =>
{
var myTip = new Tip();
myTip.Direction = AMPopTipDirection.None;
myTip.CloseTime = 2;
myTip.Text = Language.StringByID(R.MyInternationalizationString.BindDeviceTargetIsEmpty);
myTip.Show(Common.CommonPage.Instance);
btnFinifh.Enable = true;
btnFinifh.BackgroundColor = Shared.Common.ZigbeeColor.Current.XMBlack;
CommonPage.Loading.Hide();
});
return;
}
for (int i = 0; i < targetScList.Count; i++)
{
//绑定新的数据
var addBindeDev = new AddBindData();
addBindeDev.DeviceAddr = curControlDev.DeviceAddr;
for (int j = 0; j < curSupportBindEpointList.Count; j++)
{
curSendEpointList.Add(curSupportBindEpointList[0]);
addBindeDev.Epoint = curControlDev.DeviceEpoint = curSupportBindEpointList[0];
break;
}
var de = targetScList[i];
var addBindInfo = new AddBindListObj();
addBindInfo.BindType = 1;
addBindInfo.BindCluster = 6;
addBindInfo.BindScenesId = de.Id;
addBindeDev.BindList.Add(addBindInfo);
var resT = AddDeviceBind(addBindeDev, targetSendCount, ref targetRecCount);
if (!resT)
{
break;
}
}
}
else
{
targetSendCount = targetList.Count;
if (targetList.Count == 0)
{
//没有目标提示
Application.RunOnMainThread(() =>
{
var myTip = new Tip();
myTip.Direction = AMPopTipDirection.None;
myTip.CloseTime = 2;
myTip.Text = Language.StringByID(R.MyInternationalizationString.BindDeviceTargetIsEmpty);
myTip.Show(Common.CommonPage.Instance);
btnFinifh.Enable = true;
btnFinifh.BackgroundColor = Shared.Common.ZigbeeColor.Current.XMBlack;
CommonPage.Loading.Hide();
});
return;
}
foreach (var de in targetList)
{
//绑定新的数据
var addBindeDev = new AddBindData();
addBindeDev.DeviceAddr = curControlDev.DeviceAddr;
if (curBindType == 3)
{
if (de.Type == DeviceType.DimmableLight)
{
for (int j = 0; j < curSupportDimmerEpointList.Count; j++)
{
curSendEpointList.Add(curSupportDimmerEpointList[0]);
addBindeDev.Epoint = curControlDev.DeviceEpoint = curSupportDimmerEpointList[0];
break;
}
}
if (de.Type == DeviceType.OnOffOutput)
{
for (int j = 0; j < curSupportLightEpointList.Count; j++)
{
curSendEpointList.Add(curSupportLightEpointList[0]);
addBindeDev.Epoint = curControlDev.DeviceEpoint = curSupportLightEpointList[0];
break;
}
}
}
else
{
for (int j = 0; j < curSupportBindEpointList.Count; j++)
{
curSendEpointList.Add(curSupportBindEpointList[0]);
addBindeDev.Epoint = curControlDev.DeviceEpoint = curSupportBindEpointList[0];
break;
}
}
var addBindInfo = new AddBindListObj();
addBindInfo.BindType = 0;
addBindInfo.BindMacAddr = de.DeviceAddr;
addBindInfo.BindEpoint = de.DeviceEpoint;
switch (curBindType)
{
case 0:
addBindInfo.BindCluster = 6;
break;
case 1:
addBindInfo.BindCluster = 6;
break;
case 2:
addBindInfo.BindCluster = 6;
break;
case 3:
addBindInfo.BindCluster = 6;
break;
case 4:
addBindInfo.BindCluster = 258;
break;
case 5:
addBindInfo.BindCluster = 513;
break;
case 6:
addBindInfo.BindCluster = 514;
break;
}
addBindeDev.BindList.Add(addBindInfo);
//部分目标需要二次绑定第二种功能
var addBindInfo2 = new AddBindListObj();
addBindInfo2.BindType = 0;
addBindInfo2.BindMacAddr = de.DeviceAddr;
addBindInfo2.BindEpoint = de.DeviceEpoint;
switch (curBindType)
{
case 3:
var device = LocalDevice.Current.GetDevice(de.DeviceAddr, de.DeviceEpoint);
if (device != null)
{
if (device.Type == DeviceType.DimmableLight)
{
//灯光为调光时需要绑定6,8
addBindInfo2.BindCluster = 8;
addBindeDev.BindList.Add(addBindInfo2);
}
}
break;
case 5:
//要绑定空调:需要绑定513,514
addBindInfo2.BindCluster = 514;
addBindeDev.BindList.Add(addBindInfo2);
break;
}
var resT = AddDeviceBind(addBindeDev, targetSendCount, ref targetRecCount);
if (!resT)
{
break;
}
}
}
}
catch
{
Application.RunOnMainThread(() =>
{
btnFinifh.Enable = true;
btnFinifh.BackgroundColor = Shared.Common.ZigbeeColor.Current.XMBlack;
CommonPage.Loading.Hide();
});
}
});
}
///
/// AddDeviceBind
///
///
///
///
///
private bool AddDeviceBind(AddBindData addBindeDev, int targetSendCount, ref int targetRecCount)
{
var addSuccess = false;
var dev = HdlDeviceBindLogic.Current.AddDeviceBindAsync(addBindeDev);
if (dev != null && dev.addedDeviceBindResponseData != null)
{
addSuccess = true;
targetRecCount++;
if (dev.addedDeviceBindResponseData.Result == 0)
{
var countTotal = targetRecCount;
var bList = new List();
foreach (var devB in dev.addedDeviceBindResponseData.BindList)
{
var curD = new BindListAllInfo();
curD.KeyMacAddr = curControlDev.DeviceAddr;
curD.KeyEpoint = curControlDev.DeviceEpoint;
curD.BindCluster = devB.BindCluster;
curD.BindScenesId = devB.BindScenesId;
curD.BindMacAddr = devB.BindMacAddr;
curD.BindEpoint = devB.BindEpoint;
curD.ESName = devB.ESName;
curD.BindType = devB.BindType;
bList.Add(curD);
}
if (MutilfunctionPanelMethod.bindTargetsFromMutilfunctionPanelList.ContainsKey(curControlDev.DeviceAddr + curControlDev.DeviceEpoint))
{
MutilfunctionPanelMethod.bindTargetsFromMutilfunctionPanelList[curControlDev.DeviceAddr + curControlDev.DeviceEpoint] = bList;
}
else
{
MutilfunctionPanelMethod.bindTargetsFromMutilfunctionPanelList.Add(curControlDev.DeviceAddr + curControlDev.DeviceEpoint, bList);
}
if (curBindType == 3)
{
if (addBindeDev.Epoint >= 22 && addBindeDev.Epoint <= 28)
{
curSupportDimmerEpointList.RemoveAt(0);
}
if (addBindeDev.Epoint >= 52 && addBindeDev.Epoint <= 61)
{
curSupportLightEpointList.RemoveAt(0);
}
}
else
{
curSupportBindEpointList.RemoveAt(0);
}
Application.RunOnMainThread(() =>
{
if (countTotal == targetSendCount)
{
if (actionRefreshBindList != null)
{
actionRefreshBindList();
}
targetList.Clear();
this.RemoveFromParent();
btnFinifh.Enable = true;
btnFinifh.BackgroundColor = Shared.Common.ZigbeeColor.Current.XMBlack;
CommonPage.Loading.Hide();
}
});
}
else if (dev.addedDeviceBindResponseData.Result == 1)
{
Application.RunOnMainThread(() =>
{
btnFinifh.Enable = true;
btnFinifh.BackgroundColor = Shared.Common.ZigbeeColor.Current.XMBlack;
RefreshRoomList();
CommonPage.Loading.Hide();
new Tip()
{
MaxWidth = 150,
Text = Language.StringByID(R.MyInternationalizationString.BindFailed) + "(" + "5001_1" + ")",
Direction = AMPopTipDirection.Up,
CloseTime = 1
}.Show(btnFinifh);
});
}
else
{
Application.RunOnMainThread(() =>
{
btnFinifh.Enable = true;
btnFinifh.BackgroundColor = Shared.Common.ZigbeeColor.Current.XMBlack;
RefreshRoomList();
CommonPage.Loading.Hide();
new Tip()
{
MaxWidth = 150,
Text = Language.StringByID(R.MyInternationalizationString.BindUnknownError) + "(" + "5001_2" + ")",
Direction = AMPopTipDirection.Up,
CloseTime = 1
}.Show(btnFinifh);
});
}
}
else
{
Application.RunOnMainThread(() =>
{
btnFinifh.Enable = true;
btnFinifh.BackgroundColor = Shared.Common.ZigbeeColor.Current.XMBlack;
RefreshRoomList();
CommonPage.Loading.Hide();
GetEpointData();
});
}
return addSuccess;
}
///
/// 初始化设备数据
///
void GetEpointData()
{
System.Threading.Tasks.Task.Run(() =>
{
try
{
Application.RunOnMainThread(() =>
{
CommonPage.Loading.Start("");
});
int count1 = curSendEpointList.Count;
int count2 = 0;
foreach (var epoint in curSendEpointList)
{
curControlDev.DeviceEpoint = epoint;
var getBindList = HdlDeviceBindLogic.Current.GetDeviceBindAsync(curControlDev);
if (getBindList != null && getBindList.getAllBindResponseData != null)
{
count2++;
var bList = new List();
foreach (var dev in getBindList.getAllBindResponseData.BindList)
{
var curD = new BindListAllInfo();
curD.KeyMacAddr = curControlDev.DeviceAddr;
curD.KeyEpoint = epoint;
curD.BindCluster = dev.BindCluster;
curD.BindScenesId = dev.BindScenesId;
curD.BindMacAddr = dev.BindMacAddr;
curD.BindEpoint = dev.BindEpoint;
curD.ESName = dev.ESName;
curD.BindType = dev.BindType;
bList.Add(curD);
//更新targetScListj or targetList
if (curBindType == 0)
{
for (int i = 0; i < targetScList.Count; i++)
{
if (targetScList[i].Id == dev.BindScenesId)
{
targetScList.RemoveAt(i);
}
}
}
else
{
for (int i = 0; i < targetList.Count; i++)
{
if (targetList[i].DeviceAddr + targetList[i].DeviceEpoint == dev.BindMacAddr + dev.BindEpoint)
{
targetList.RemoveAt(i);
}
}
}
}
//更新bindTargetsFromMutilfunctionPanelList
if (MutilfunctionPanelMethod.bindTargetsFromMutilfunctionPanelList.ContainsKey(curControlDev.DeviceAddr + curControlDev.DeviceEpoint))
{
MutilfunctionPanelMethod.bindTargetsFromMutilfunctionPanelList[curControlDev.DeviceAddr + curControlDev.DeviceEpoint] = bList;
}
else
{
MutilfunctionPanelMethod.bindTargetsFromMutilfunctionPanelList.Add(curControlDev.DeviceAddr + curControlDev.DeviceEpoint, bList);
}
//更新当前支持的端点绑定表
curSupportBindEpointList = MutilfunctionPanelMethod.GetMatchEpointList(curBindType);
if (curBindType == 3)
{
foreach (var ep in curSupportBindEpointList)
{
if (ep >= 22 && ep <= 28)
{
curSupportDimmerEpointList.Remove(ep);
}
if (ep >= 52 && ep <= 61)
{
curSupportLightEpointList.Remove(ep);
}
}
}
if (count1 == count2)
{
Application.RunOnMainThread(() =>
{
if (actionRefreshBindList != null)
{
actionRefreshBindList();
}
RefreshRoomList();
CommonPage.Loading.Hide();
});
}
}
else
{
Application.RunOnMainThread(() =>
{
targetList.Clear();
new Tip() { MaxWidth = 300, Text = Language.StringByID(R.MyInternationalizationString.UpdateBindList), Direction = AMPopTipDirection.None, CloseTime = 3 }.Show(Common.CommonPage.Instance);
btnFinifh.Enable = true;
btnFinifh.BackgroundColor = Shared.Common.ZigbeeColor.Current.XMBlack;
CommonPage.Loading.Hide();
this.RemoveFromParent();
});
break;
}
}
}
catch { }
});
}
#endregion
}
}