using System;
using HDL_ON.UI.CSS;
using Shared;
using HDL_ON.Entity;
using System.Collections.Generic;
using HDL_ON.DAL;
using HDL_ON.DAL.Server;
namespace HDL_ON.UI
{
///
/// 成员权限管理页面
///
public partial class MemberPermissionPage : FrameLayout
{
MemberPermissionPage bodyView;
Button btnDelMember;
VerticalScrolViewLayout roomListView;
ResidenceMemberInfo memberInfo;
Action backAction;
public MemberPermissionPage(ResidenceMemberInfo mInfo,Action action)
{
bodyView = this;
memberInfo = mInfo;
backAction = action;
}
public void LoadPage()
{
bodyView.BackgroundColor = CSS_Color.BackgroundColor;
new TopViewDiv(bodyView, Language.StringByID(StringId.MemberPermissionManagement)).LoadTopView();
FrameLayout headPortraitView = new FrameLayout()
{
Y = Application.GetRealHeight(64),
Height = Application.GetRealHeight(66),
BackgroundColor = CSS_Color.MainBackgroundColor,
};
bodyView.AddChidren(headPortraitView);
ImageView userHeadImageView = new ImageView()
{
X = Application.GetRealWidth(16),
Gravity = Gravity.CenterVertical,
Width = Application.GetRealWidth(42),
Height = Application.GetRealWidth(42),
Radius = (uint)Application.GetRealWidth(21),
ImagePath = memberInfo.headImagePagePath
};
headPortraitView.AddChidren(userHeadImageView);
Button btnMemberName = new Button()
{
X = Application.GetRealWidth(70),
Width = Application.GetRealWidth(300),
TextAlignment = TextAlignment.CenterLeft,
TextColor = CSS_Color.FirstLevelTitleColor,
TextSize = CSS_FontSize.TextFontSize,
//Text = memberInfo.nickName + "(" + memberInfo.UserName + ")",
};
headPortraitView.AddChidren(btnMemberName);
string username = HDLCommon.Current.GetUserName(memberInfo.memberName);
btnMemberName.Text = memberInfo.nickName + "(" + username + ")";
#region RoomList
roomListView = new VerticalScrolViewLayout()
{
Y = Application.GetRealHeight(138),
Height = Application.GetRealHeight(471),
//BackgroundColor = CSS_Color.MainBackgroundColor,
};
bodyView.AddChidren(roomListView);
#endregion
btnDelMember = new Button()
{
Y = Application.GetRealHeight(617),
//Height = MainPage.Increase ? Application.GetRealHeight(70) : Application.GetRealHeight(50),
Height = Application.GetRealHeight(50),
TextAlignment = TextAlignment.Center,
TextSize = CSS_FontSize.SubheadingFontSize,
TextColor = CSS_Color.WarningColor,
TextID = StringId.RemoveTheMember,
BackgroundColor = CSS_Color.MainBackgroundColor,
};
bodyView.AddChidren(btnDelMember);
LoadEventList();
GetShareDataByAccount();
}
///
/// 加载房间列表,统计分享的数据
///
void ShowRoomListView()
{
roomListView.RemoveAll();
var titleView = new FrameLayout()
{
BackgroundColor = CSS_Color.MainBackgroundColor,
Height = Application.GetRealWidth(44),
};
roomListView.AddChidren(titleView);
var btnTitle = new Button()
{
X = Application.GetRealWidth(16),
TextAlignment = TextAlignment.CenterLeft,
TextColor = CSS_Color.FirstLevelTitleColor,
TextSize = CSS_FontSize.SubheadingFontSize,
TextID = StringId.UseArea,
};
titleView.AddChidren(btnTitle);
var btnLine = new Button()
{
X = Application.GetRealWidth(16),
Y = titleView.Height - Application.GetRealHeight(2),
Width = Application.GetRealWidth(360),
Height = Application.GetRealHeight(1),
BackgroundColor = CSS_Color.DividingLineColor,
};
titleView.AddChidren(btnLine);
//---------------------------------------------
//未分配区域的功能
List allFunctionList = FunctionList.List.GetDeviceFunctionList();
//未分配区域的功能
List unallocatedList = new List();
//
foreach (var function in allFunctionList)
{
function.roomIds.Remove(null);
if (function.roomIds.Count > 0)
{
//allocatedList.Add(function);
}
else
{
unallocatedList.Add(function);
}
}
//所有场景
List allSceneList = FunctionList.List.scenes;
//全局场景场景
List globalSceneList = new List();
//找出所有的全局场景
foreach (var mScene in allSceneList)
{
//roomIds大于0 代表分配到房间
mScene.roomIds.Remove(null);
if (mScene.roomIds.Count > 0)
{
//allocatedList.Add(function);
}
else
{
globalSceneList.Add(mScene);
}
}
////移除当前住宅已经不存在的功能
//for (int i = 0; i < memberInfo.CurResidenceShareData.Count;)
//{
// var sd = memberInfo.CurResidenceShareData[i];
// if (allFunctionList.Find((obj) => obj.deviceId == sd.shareTypeId) == null)
// {
// //new DAL.Server.HttpServerRequest().DeleteShareData(sd);
// //待确认是否同步云端删除分享
// memberInfo.CurResidenceShareData.Remove(sd);
// }
// else
// {
// i++;
// }
//}
try
{
//遍历加载房间分享个数统计状态RowLayout
foreach (var room in SpatialInfo.CurrentSpatial.RoomList)
{
AddRoomFunctionRowLayout(room);
}
//2020-12-16 加载未分配区域功能RowLayout
AddNoAreaFunctionRowLayout(unallocatedList, globalSceneList);
}
catch
{
Utlis.WriteLine("AddRoomFunctionRowLayout error");
}
}
///
/// 添加房间分享个数统计状态的RowLayout
///
///
void AddRoomFunctionRowLayout(Room mRoom)
{
ShowBaseRoomFunOrNoAreaFunRowLayout(mRoom, null, null);
}
///
///
///
/// 未分配的所有功能列表
/// 全区域的场景
void AddNoAreaFunctionRowLayout(List unallocatedList, List globalSceneList)
{
ShowBaseRoomFunOrNoAreaFunRowLayout(null, unallocatedList, globalSceneList);
}
///
/// 2020-12-17 重新调整
/// 添加房间分享或者无区域分配 个数统计状态的RowLayout
///
/// 如果房间为空,代表管理无分配区域
/// 管理无分配区域才有效
/// 全局场景
void ShowBaseRoomFunOrNoAreaFunRowLayout(Room mRoom, List unallocatedList, List globalSceneList)
{
/// 当前房间或者无分配区域分享列表
List funs_RoomAll = new List();
/// 房间所有功能和者场景列表
List roomFunctionOrSceneList = new List();
/// 房间ID
string roomId = "";
var roomView = new RowLayout()
{
Height = Application.GetRealWidth(50),
BackgroundColor = CSS_Color.MainBackgroundColor,
LineColor = CSS_Color.MainBackgroundColor,
};
roomListView.AddChidren(roomView);
var btnRoomName = new Button()
{
X = Application.GetRealWidth(16),
Y = Application.GetRealWidth(4),
Width = Application.GetRealWidth(330),
Height = Application.GetRealWidth(24),
TextAlignment = TextAlignment.CenterLeft,
TextColor = CSS_Color.FirstLevelTitleColor,
TextSize = CSS_FontSize.TextFontSize,
//Text = room.roomName,
};
roomView.AddChidren(btnRoomName);
var btnFunctionCount = new Button()
{
X = Application.GetRealWidth(16),
Y = btnRoomName.Bottom,
Width = Application.GetRealWidth(330),
Height = Application.GetRealWidth(18),
TextAlignment = TextAlignment.CenterLeft,
TextColor = CSS_Color.PromptingColor1,
TextSize = CSS_FontSize.PromptFontSize_SecondaryLevel,
//Text = addCount + "/" + room.GetRoomFunctions(false).Count.ToString(),
};
roomView.AddChidren(btnFunctionCount);
var btnRight = new Button()
{
X = Application.GetRealWidth(351),
Gravity = Gravity.CenterVertical,
Width = Application.GetMinRealAverage(16),
Height = Application.GetMinRealAverage(16),
UnSelectedImagePath = "Public/Right.png",
};
roomView.AddChidren(btnRight);
//如果房间为空,代表管理无分配区域
if (mRoom != null)
{
//显示房间名
btnRoomName.Text = mRoom.roomName;
var mRoomFunctionList = mRoom.GetRoomFunctions(false);
var mRoomSceneList = mRoom.GetRoomScenes(true);
//遍历所有功能列表
if (mRoomFunctionList != null)
{
foreach (var fun in mRoomFunctionList)
{
roomFunctionOrSceneList.Add(new RoomData()
{
shareTypeId = fun.deviceId,
shareType = ShareType.DEVICE.ToString(),
name = fun.name,
});
}
}
//遍历所有场景列表
if (mRoomSceneList != null)
{
foreach (var roomScene in mRoomSceneList)
{
roomFunctionOrSceneList.Add(new RoomData()
{
shareTypeId = roomScene.userSceneId,
shareType = ShareType.SCENE.ToString(),
name = roomScene.name,
});
}
}
roomId = mRoom.roomId;
//添加分割线
var lineView = new LineView(roomView.Height - Application.GetRealHeight(1));
roomView.AddChidren(lineView);
}
else
{
//显示无区域功能
btnRoomName.TextID = StringId.NoAreaFunction;
roomId = null;
//遍历所有功能列表
if (unallocatedList != null)
{
foreach (var fun in unallocatedList)
{
roomFunctionOrSceneList.Add(new RoomData()
{
shareTypeId = fun.deviceId,
shareType = ShareType.DEVICE.ToString(),
name = fun.name,
});
}
}
//遍历所有场景列表
if (globalSceneList != null)
{
foreach (var roomScene in globalSceneList)
{
roomFunctionOrSceneList.Add(new RoomData()
{
shareTypeId = roomScene.userSceneId,
shareType = ShareType.SCENE.ToString(),
name = roomScene.name,
});
}
}
}
//删除按钮
var deleteBtn = new Button()
{
TextID = StringId.Del,
BackgroundColor = CSS_Color.AuxiliaryColor2,
TextColor = CSS_Color.MainBackgroundColor,
TextSize = CSS_FontSize.TextFontSize,
};
roomView.AddRightView(deleteBtn);
deleteBtn.MouseUpEventHandler = (sender, e) =>
{
//一键删除所有分享
DeleteRoomAllShare(funs_RoomAll, roomFunctionOrSceneList, roomId, btnFunctionCount, roomView);
};
//计算已经加入房间的设备数量的Action事件
Action RefreshAction = () => {
funs_RoomAll = new List();
int addCount = 0;
foreach (var sd in memberInfo.CurResidenceShareData)
{
if (roomFunctionOrSceneList.Find((obj) => obj.shareTypeId == sd.shareTypeId) != null)
{
addCount++;
funs_RoomAll.Add(sd);
}
}
btnFunctionCount.Text = addCount + "/" + roomFunctionOrSceneList.Count.ToString();
//Utlis.WriteLine("刷新成功");
};
//点击调整事件
EventHandler eHandler = (sender, e) =>
{
var mmp = new MemberFunctionPermissionPage(memberInfo, roomFunctionOrSceneList, funs_RoomAll, roomId, RefreshAction);
MainPage.BasePageView.AddChidren(mmp);
mmp.LoadPage(StringId.MemberPermissionManagement);
MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1;
};
roomView.MouseUpEventHandler = eHandler;
btnRoomName.MouseUpEventHandler = eHandler;
btnRight.MouseUpEventHandler = eHandler;
btnFunctionCount.MouseUpEventHandler = eHandler;
RefreshAction?.Invoke();
}
}
}