using System;
|
using System.Collections.Generic;
|
using Shared.Common;
|
using ZigBee.Device;
|
|
namespace Shared.Phone.UserCenter.SmartSound.Forms
|
{
|
public class SmartSoundControlContentForm : EditorCommonForm
|
{
|
/// <summary>
|
/// 临时数据
|
/// </summary>
|
private List<SmartSound.Layer> TempDatas = new List<SmartSound.Layer>();
|
|
/// <summary>
|
/// 列表控件
|
/// </summary>
|
private VerticalListControl listView = null;
|
|
private FrameLayout contentLayout = null;
|
public int CurrentIndex = 0;
|
private BottomClickButton bottomClickButton = null;
|
|
public SmartSoundControlContentForm()
|
{
|
//
|
}
|
|
/// <summary>
|
/// 画面显示(底层会固定调用此方法,借以完成画面创建)
|
/// </summary>
|
public void ShowForm()
|
{
|
IniFloorData();//先加载数据
|
TempDatas.Clear();
|
|
this.ScrollEnabled = false;
|
base.SetTitleText("选择房间");//设置标题信息
|
|
contentLayout = new FrameLayout();
|
this.bodyFrameLayout.AddChidren(contentLayout);
|
|
IniAllDataView();
|
|
}
|
|
#region 加载本地所有数据,生成供用户选择房间的界面
|
|
private void IniAllDataView()
|
{
|
contentLayout.RemoveAll();
|
|
var pullLayout = new MyPullControl(this, SmartSound.LocaData);
|
contentLayout.AddChidren(pullLayout);
|
pullLayout.InitControl();
|
|
LoadAllRoomListView();
|
|
bottomClickButton = new BottomClickButton();
|
this.bodyFrameLayout.AddChidren(bottomClickButton);
|
bottomClickButton.Text = "确认";
|
bottomClickButton.ButtonClickEvent += (sender, e) =>
|
{
|
//保存数据
|
if (SmartSound.CurretnData == null)
|
SmartSound.CurretnData = new List<SmartSound.Layer>();
|
|
SmartSound.CurretnData.Clear();
|
SmartSound.CurretnData = CollateData();
|
this.CloseForm();
|
};
|
|
bottomClickButton.Visible = false;
|
}
|
|
private void LoadAllRoomListView()
|
{
|
try
|
{
|
|
if (SmartSound.LocaData == null || SmartSound.LocaData.Count < 1)
|
return;
|
|
// 加载当前楼层的所有房间 ListView
|
SmartSound.Layer layer = SmartSound.LocaData[CurrentIndex];
|
if (listView == null)
|
{
|
|
listView = new VerticalListControl();
|
contentLayout.AddChidren(listView);
|
listView.Y = Application.GetRealHeight(173);
|
listView.Height = bodyFrameLayout.Height- Application.GetRealHeight(173);
|
|
}
|
|
listView.RemoveAll();
|
|
foreach(SmartSound.Room room in layer.RoomList)
|
{
|
var roomRowLayout = new RoomRowLayout(this, room);
|
listView.AddChidren(roomRowLayout);
|
roomRowLayout.InitControl();
|
}
|
|
}
|
catch { }
|
}
|
|
#endregion
|
|
/// <summary>
|
/// 将数据转换为智能音箱使用的数据
|
/// </summary>
|
private void IniFloorData()
|
{
|
#region//1.从服务器获取的数据,json反序列化得来
|
//2.点击"+"将网关的数据转换为 智能音箱使用的数据
|
/*{
|
|
Dictionary<string, string> ss = Config.Instance.Home.FloorDics;//楼层列表
|
string currentFloor = Config.Instance.Home.CurrentFloorId;//当前楼层的键
|
|
var listRoom = HdlRoomLogic.Current.GetFloorSortRoom("楼层的主键");//获取当前楼层的所有房间
|
var room = listRoom[0];
|
for (int i=0;i<room.ListDevice.Count;i++)
|
{//设备数据
|
var device = LocalDevice.Current.GetDevice(room.ListDevice[i]);
|
var myType = LocalDevice.Current.GetNotHdlMyDeviceEnumInfo(new List<CommonDevice>() { device });
|
|
if (myType.BeloneType == DeviceBeloneType.A灯光)
|
{
|
//这里面的就是灯光了
|
var light = device;
|
// light.DeviceAddr; 设备的地址
|
// light.DeviceEpoint;//设备的端口
|
}
|
}
|
|
for (int i = 0; i < room.ListSceneId.Count; i++)
|
{ //场景数据
|
var device = HdlSceneLogic.Current.GetSceneUIBySceneId(room.ListSceneId[i]);
|
// device.Id;场景 id
|
}
|
}*/
|
#endregion
|
|
if (SmartSound.LocaData == null)
|
SmartSound.LocaData = new List<SmartSound.Layer>();
|
|
SmartSound.LocaData.Clear();
|
|
Dictionary<string, string> floorDictionary = Config.Instance.Home.FloorDics;//楼层列表
|
|
#region 分楼层
|
if (floorDictionary.Count < 1)
|
{
|
//没有楼层,模拟一个
|
SmartSound.Layer layer = new SmartSound.Layer();
|
layer.LayerID = "0000";
|
layer.LayerName = "一楼";
|
layer.RoomList.Clear();
|
SmartSound.LocaData.Add(layer);
|
}
|
else
|
{
|
foreach (string layer_id in floorDictionary.Keys)
|
{
|
SmartSound.Layer layer = new SmartSound.Layer();
|
layer.LayerID = layer_id;
|
layer.LayerName = floorDictionary[layer_id];
|
layer.RoomList.Clear();
|
SmartSound.LocaData.Add(layer);
|
}
|
}
|
#endregion
|
|
#region 房间入住对应的楼层
|
var roomList = HdlRoomLogic.Current.GetAllListRooms();//获取所有房间
|
|
for (int n = 0; n < SmartSound.LocaData.Count; n++)
|
{
|
SmartSound.Layer layer = SmartSound.LocaData[n];
|
|
foreach (Room room in roomList)
|
{
|
try
|
{
|
if (layer.LayerID != room.FloorId && SmartSound.LocaData.Count > 1)
|
continue;
|
|
//添加房间
|
SmartSound.Room smartRoom = new SmartSound.Room();
|
layer.RoomList.Add(smartRoom);
|
|
smartRoom.RoomID = room.Id;
|
smartRoom.RoomName = room.Name;
|
smartRoom.DeviceList.Clear();
|
smartRoom.SceneList.Clear();
|
|
#region 添加设备 灯光、窗帘、场景、空调
|
for (int j = 0; j < room.ListDevice.Count; j++)
|
{
|
string key = room.ListDevice[j].ToString();
|
var device = LocalDevice.Current.GetDevice(key);
|
if (device == null)
|
continue;
|
|
SmartSound.Device smartDevice = new SmartSound.Device();
|
smartDevice.Id = device.DeviceID.ToString();//设备 Id
|
smartDevice.DeviceAddress = device.DeviceAddr;//设备 MAC
|
smartDevice.Epoint = device.DeviceEpoint;//设备端口
|
smartDevice.ClusterID = 0;
|
smartDevice.DeviceName = device.DeviceName;//设备名称
|
smartDevice.NicksName = "";
|
smartDevice.DeviceType = GetDeviceType(device);//设备类型
|
smartDevice.GatewayID = device.CurrentGateWayId;//网关 Id
|
smartDevice.RoomID = room.Id;//房间 Id
|
|
smartRoom.DeviceList.Add(smartDevice);
|
|
}
|
#endregion
|
|
var sceneList = HdlSceneLogic.Current.GetRoomSceneList(room);
|
|
#region //添加场景
|
for (int k = 0; k < sceneList.Count; k++)
|
{
|
SceneUI scene = sceneList[k];
|
if (scene == null) continue;
|
SmartSound.Scene smartScene = new SmartSound.Scene();
|
smartScene.Id = scene.DeviceID.ToString();
|
smartScene.SceneName = scene.Name;
|
smartScene.SceneID = scene.Id;
|
smartScene.DelayTime = scene.DelayTime;
|
smartScene.ClusterID = 0;
|
smartScene.NicksName = "";
|
smartScene.RoomID = room.Id;
|
|
smartRoom.SceneList.Add(smartScene);
|
}
|
#endregion
|
|
}
|
catch (Exception e)
|
{
|
string errpr = e.Message;
|
}
|
}
|
}
|
#endregion
|
|
}
|
|
/// <summary>
|
/// Zigbee设备类型转换为智能音箱使用的类型
|
/// </summary>
|
/// <returns></returns>
|
private int GetDeviceType(ZigBee.Device.CommonDevice device)
|
{
|
int type = 0;//1=开关灯,2=调光灯,3=RGB 灯,4=窗帘模块,5=开合帘,6=卷帘,7=空调,8=面板,9=新风
|
|
if (device.Type == DeviceType.OnOffOutput && device.DfunctionType == DeviceFunctionType.A灯光)
|
{
|
type = 1;//这里面的就是继电器灯光了
|
}
|
else if (device.Type == DeviceType.DimmableLight)
|
{
|
type = 2;//调光
|
}
|
else if (device.Type == DeviceType.ColorDimmableLight)
|
{
|
type = 3;
|
}
|
else if (device.Type == DeviceType.WindowCoveringDevice)
|
{
|
//窗帘
|
if (((Rollershade)device).WcdType == 4)//开合帘
|
{
|
type = 5;
|
}
|
else if (((Rollershade)device).WcdType == 0)//卷帘
|
type = 6;//卷帘
|
}
|
else if (device.Type == DeviceType.Thermostat)
|
{
|
type = 7;
|
}
|
else if (device.Type == DeviceType.FreshAir)
|
{
|
type = 9;
|
}
|
|
return type;
|
}
|
|
/// <summary>
|
/// 将选中的数据添加到临时数据列表中,便于后期的"保存"
|
/// </summary>
|
private void AddData(SmartSound.Room room)
|
{
|
if (TempDatas == null)
|
TempDatas = new List<SmartSound.Layer>();
|
|
SmartSound.Layer tempLayer = SmartSound.LocaData[CurrentIndex];
|
if (tempLayer == null) return;
|
|
|
|
#region 添加楼层
|
|
bool floor_exists = false;
|
// 过滤相同的楼层
|
for (int i = 0; i < TempDatas.Count; i++)
|
{
|
if (tempLayer.LayerID == TempDatas[i].LayerID)
|
{
|
floor_exists = true;
|
break;
|
}
|
}
|
|
if (!floor_exists)
|
{
|
tempLayer.RoomList.Clear();
|
TempDatas.Add(tempLayer);
|
}
|
|
|
#endregion
|
|
#region 添加房间
|
|
for (int i = 0; i < TempDatas.Count; i++)
|
{
|
if (SmartSound.LocaData[CurrentIndex].LayerID != TempDatas[i].LayerID)
|
continue;
|
|
bool room_exists = false;
|
|
for (int n = 0; n < TempDatas[i].RoomList.Count; n++)
|
{
|
if (room.RoomID == TempDatas[i].RoomList[n].RoomID)
|
{
|
room_exists = true;
|
break;
|
}
|
}
|
|
if (!room_exists)
|
{
|
TempDatas[i].RoomList.Add(room);
|
CheckedAll(room);//添加房间成功,默认选中所有设备
|
break;
|
}
|
}
|
|
#endregion
|
|
}
|
|
private void RemoveData(SmartSound.Room room)
|
{
|
try
|
{
|
for (int i = 0; i < TempDatas.Count; i++)
|
{
|
|
for (int j = 0; j < TempDatas[i].RoomList.Count; j++)
|
{
|
if (TempDatas[i].RoomList[j].RoomID == room.RoomID)
|
{
|
TempDatas[i].RoomList.RemoveAt(j);
|
}
|
}
|
}
|
}
|
catch { }
|
}
|
|
/// <summary>
|
/// 默认选择所有设备
|
/// </summary>
|
/// <param name="room"></param>
|
private void CheckedAll(SmartSound.Room room)
|
{
|
// 标记所有场景
|
for (int n = 0; n < room.SceneList.Count; n++)
|
{
|
SmartSound.Scene _scene = room.SceneList[n];
|
_scene.Checked = true;
|
}
|
|
//标记所有设备
|
for (int k = 0; k < room.DeviceList.Count; k++)
|
{
|
|
SmartSound.Device _device = room.DeviceList[k];
|
_device.Checked = true;
|
}
|
}
|
|
/// <summary>
|
/// 重新整理数据,把没有选中的数据都剔除掉
|
/// </summary>
|
private List<SmartSound.Layer> CollateData()
|
{
|
try
|
{
|
//移出未选中的设备、场景
|
for (int i = 0; i < TempDatas.Count; i++)
|
{
|
SmartSound.Layer _layer = TempDatas[i];
|
|
for (int j = 0; j < _layer.RoomList.Count; j++)
|
{
|
SmartSound.Room _room = _layer.RoomList[j];
|
if (_room.Checked)
|
{
|
#region 清除未选中的设备
|
for (int k = 0; k < _room.DeviceList.Count; k++)
|
{
|
SmartSound.Device _device = _room.DeviceList[k];
|
if (!_device.Checked)
|
{
|
_room.DeviceList.Remove(_device);
|
}
|
}
|
#endregion
|
|
#region 清除未选中的场景
|
for (int n = 0; n < _room.SceneList.Count; n++)
|
{
|
SmartSound.Scene _scene = _room.SceneList[n];
|
if (!_scene.Checked)
|
{
|
_room.SceneList.Remove(_scene);
|
}
|
}
|
#endregion
|
}
|
else
|
{
|
_layer.RoomList.Remove(_room);
|
}
|
}
|
}
|
|
//移出没有设备的房间
|
for (int j = 0; j < TempDatas.Count; j++)
|
{
|
SmartSound.Layer _layer = TempDatas[j];
|
if (_layer.RoomList.Count < 1)
|
{
|
TempDatas.Remove(_layer);
|
}
|
}
|
}
|
catch { }
|
|
return TempDatas;
|
}
|
|
#region ■ 自定义楼层选择控件_____________________
|
|
/// <summary>
|
/// 房间列表行
|
/// </summary>
|
private class MyPullControl : FrameRowControl
|
{
|
|
private SmartSoundControlContentForm smartSoundDataAdd = null;
|
private List<SmartSound.Layer> Layers = null;
|
/// <summary>
|
/// 房间列表
|
/// </summary>
|
private NormalViewControl btnName = null;
|
|
/// <summary>
|
/// 房间列表行
|
/// </summary>
|
public MyPullControl(SmartSoundControlContentForm _SmartSoundDataAdd,List<SmartSound.Layer> _layers)
|
{
|
this.smartSoundDataAdd = _SmartSoundDataAdd;
|
this.Layers = _layers;
|
this.UseClickStatu = false;
|
this.BackgroundColor = UserCenterColor.Current.White;
|
this.Height = Application.GetRealHeight(173);
|
}
|
|
/// <summary>
|
/// 初始化控件
|
/// </summary>
|
public void InitControl()
|
{
|
//显示文本
|
btnName = this.AddLeftCaption(string.Empty, 700);
|
btnName.Height = Application.GetRealHeight(60);
|
btnName.TextSize = 17;
|
btnName.Y = Application.GetRealHeight(57);
|
btnName.Text = "房间列表";
|
|
var right_icon=this.AddRightArrow();
|
right_icon.SelectedImagePath = "SmartSound/PullDown.png";
|
right_icon.UnSelectedImagePath = "SmartSound/PullDown.png";
|
right_icon.ButtonClickEvent += (sender, e) =>
|
{
|
ShowPullList();
|
};
|
|
var layout = this.AddMostRightView(Layers[smartSoundDataAdd.CurrentIndex].LayerName, 300, false);
|
layout.Name = "pullLayout";
|
layout.ButtonClickEvent += (sender, e) =>
|
{
|
ShowPullList();
|
};
|
|
}
|
|
private void ShowPullList()
|
{
|
//房间列表行{房间列表 textView,楼层下拉窗}
|
//显示房间{带选择框的;当选中了房间后需要在底部弹出确认按钮,点击确认跳转到新的界面}
|
var pull_frame = new TopRightMenuControl(Layers.Count, 2);
|
pull_frame.Y = this.Height;
|
|
for (int i = 0; i < Layers.Count; i++)
|
{
|
//创建楼层
|
pull_frame.AddRowMenu(Layers[i].LayerName, "Item/CreatFloor.png", "Item/CreatFloorSelected.png", () =>
|
{
|
smartSoundDataAdd.CurrentIndex = i;
|
smartSoundDataAdd.LoadAllRoomListView();
|
});
|
}
|
}
|
}
|
#endregion
|
|
#region ■ 自定义房间选择控件_____________________
|
|
/// <summary>
|
/// 房间列表行
|
/// </summary>
|
private class RoomRowLayout : FrameRowControl
|
{
|
private SmartSoundControlContentForm smartSoundControlContentForm = null;
|
|
private SmartSound.Room mRoom = null;
|
/// <summary>
|
/// 房间名称
|
/// </summary>
|
private NormalViewControl btnName = null;
|
|
private IconViewControl Right_icon = null;
|
|
/// <summary>
|
/// 房间列表行
|
/// </summary>
|
public RoomRowLayout(SmartSoundControlContentForm _smartSoundControlContentForm,SmartSound.Room _room)
|
{
|
this.smartSoundControlContentForm = _smartSoundControlContentForm;
|
this.mRoom = _room;
|
this.UseClickStatu = false;
|
this.BackgroundColor = UserCenterColor.Current.White;
|
this.Height = Application.GetRealHeight(170);
|
}
|
|
/// <summary>
|
/// 初始化控件
|
/// </summary>
|
public void InitControl()
|
{
|
//显示文本
|
btnName = this.AddLeftCaption(string.Empty, 2000);
|
btnName.Height = Application.GetRealHeight(60);
|
btnName.TextSize = 17;
|
btnName.Y = Application.GetRealHeight(57);
|
btnName.Text = mRoom.RoomName;
|
Right_icon = this.AddRightArrow();
|
Right_icon.Width = Application.GetRealWidth(115);
|
Right_icon.Height = Application.GetRealHeight(115);
|
Right_icon.Gravity = Gravity.CenterVertical;
|
Right_icon.X = Right_icon.X - Application.GetRealWidth(60);
|
|
btnName.ButtonClickEvent += (sender, e) =>
|
{
|
mRoom.Checked = true;
|
RefreshRightIconState(mRoom.Checked);
|
SmartSoundContentForDevice deviceForm = new SmartSoundContentForDevice(mRoom);
|
deviceForm.AddForm();
|
};
|
|
this.Right_icon.ButtonClickEvent += (sender, e) =>
|
{
|
mRoom.Checked = !mRoom.Checked;
|
RefreshRightIconState(mRoom.Checked);
|
};
|
|
RefreshRightIconState(mRoom.Checked);
|
AddBottomLine();
|
|
}
|
|
private void RefreshRightIconState(bool bol = false)
|
{
|
try
|
{
|
if (bol)
|
{
|
Right_icon.SelectedImagePath = "SmartSound/CheckBoxSel.png";
|
Right_icon.UnSelectedImagePath = "SmartSound/CheckBoxSel.png";
|
|
smartSoundControlContentForm.AddData(mRoom);
|
}
|
else
|
{
|
Right_icon.SelectedImagePath = "SmartSound/CheckBoxDef.png";
|
Right_icon.UnSelectedImagePath = "SmartSound/CheckBoxDef.png";
|
|
smartSoundControlContentForm.RemoveData(mRoom);
|
}
|
|
bool isShow = false;
|
|
if(smartSoundControlContentForm==null) return;
|
|
foreach (SmartSound.Room _room in SmartSound.LocaData[smartSoundControlContentForm.CurrentIndex].RoomList)
|
{
|
if (_room.Checked)
|
{
|
isShow = true;
|
break;
|
}
|
}
|
|
smartSoundControlContentForm.bottomClickButton.Visible = isShow;
|
}
|
catch(Exception e)
|
{
|
string error = e.Message;
|
}
|
}
|
|
}
|
#endregion
|
}
|
}
|