using System;
namespace Shared.Phone.UserCenter.Member
{
///
/// 成员信息管理
///
public class MemberManagementForm : UserCenterCommonForm
{
#region ■ 变量声明___________________________
///
/// 成员的信息
///
private MemberInfoRes memberInfo = null;
///
/// TopFrameLayout
///
private SpecialFrameLayout specialTopFrame = null;
///
/// 管理员权限图标控件
///
private TopLayoutMostRightView btnTopIcon = null;
///
/// 权限的翻译名控件
///
private ViewNormalControl btnAuthority = null;
#endregion
#region ■ 初始化_____________________________
///
/// 画面显示(底层会固定调用此方法,借以完成画面创建)
///
/// 成员信息
public void ShowForm(MemberInfoRes info)
{
this.memberInfo = info;
//设置标题信息
base.SetTitleText(Language.StringByID(R.MyInternationalizationString.MenberManagement));
//为了能够显示模块图样
bodyFrameLayout.BackgroundColor = UserCenterColor.Current.TopFrameLayout;
//初始化右上角的图标
this.InitTopRightIcon();
//初始化中部控件
this.InitMiddleFrame();
}
///
/// 初始化右上角的图标
///
private void InitTopRightIcon()
{
if (UserCenterResourse.UserInfo.AuthorityNo != 1)
{
return;
}
//管理员权限图标
btnTopIcon = new TopLayoutMostRightView();
if (memberInfo.AccountType == 1)
{
btnTopIcon.UnSelectedImagePath = "Account/HadAuthority.png";
}
else
{
btnTopIcon.UnSelectedImagePath = "Account/NotAuthority.png";
}
topFrameLayout.AddChidren(btnTopIcon);
btnTopIcon.MouseUpEventHandler += (sender, e) =>
{
string msg = Language.StringByID(R.MyInternationalizationString.uDownSubAccountLevel);
if (memberInfo.AccountType != 1)
{
msg = Language.StringByID(R.MyInternationalizationString.uUpSubAccountLevel);
}
this.ShowConfirmMsg(msg, "UpOrDownSubAccountLevel");
};
}
///
/// 初始化中部控件
///
private void InitMiddleFrame()
{
//初始化用户图标
this.InitMenberIconControl();
//初始化信息列表
this.InitInfoList();
}
///
/// 初始化用户图标
///
private void InitMenberIconControl()
{
this.specialTopFrame = new SpecialFrameLayout(400, 10);
specialTopFrame.BackgroundColor = UserCenterColor.Current.BodyFrameLayout;
bodyFrameLayout.AddChidren(specialTopFrame);
//用户图标
var btnUserIcon = new ProfilePhotoControl();
btnUserIcon.Y = Application.GetRealHeight(40);
btnUserIcon.Gravity = Gravity.CenterHorizontal;
btnUserIcon.UnSelectedImagePath = "Account/Admin.png";
this.specialTopFrame.AddChidren(btnUserIcon);
//权限
btnAuthority = new ViewNormalControl(800, true);
btnAuthority.TextAlignment = TextAlignment.Center;
btnAuthority.Y = btnUserIcon.Bottom + Application.GetRealHeight(10);
btnAuthority.Gravity = Gravity.CenterHorizontal;
btnAuthority.TextColor = UserCenterColor.Current.TextGrayColor;
btnAuthority.TextID = R.MyInternationalizationString.uMember;
if (memberInfo.AccountType == 1)
{
//拥有管理员权限
btnAuthority.TextID = R.MyInternationalizationString.uMemberHadActionAuthority;
}
this.specialTopFrame.AddChidren(btnAuthority);
//昵称
var btnName = new ViewNormalControl(800, true);
btnName.TextAlignment = TextAlignment.Center;
btnName.Y = btnAuthority.Bottom + Application.GetRealHeight(10);
btnName.Text = memberInfo.UserName;
btnName.Gravity = Gravity.CenterHorizontal;
this.specialTopFrame.AddChidren(btnName, HeightAutoMode.IncreaseOnly);
if (string.IsNullOrEmpty(memberInfo.UserName) == true)
{
btnName.Text = memberInfo.Account;
}
}
#endregion
#region ■ 初始化信息列表_____________________
///
/// 初始化信息列表
///
private void InitInfoList()
{
//创建一个FrameLayout
var frameLayout = new FrameLayout();
frameLayout.Height = bodyFrameLayout.Height - specialTopFrame.Height - Application.GetRealHeight(50);
frameLayout.BackgroundColor = UserCenterColor.Current.BodyFrameLayout;
frameLayout.Y = specialTopFrame.Bottom + Application.GetRealHeight(50);
bodyFrameLayout.AddChidren(frameLayout);
//标题:成员权限
var btnMenberTile = new ViewNormalControl(800, true);
btnMenberTile.X = ControlCommonResourse.XXLeft;
btnMenberTile.Y = Application.GetRealHeight(20);
btnMenberTile.TextID = R.MyInternationalizationString.MenberAuthority;
frameLayout.AddChidren(btnMenberTile);
//添加远程操作行
var rowLayout = new RowLayout();
rowLayout.Y = btnMenberTile.Bottom + Application.GetRealHeight(10);
rowLayout.Height = ControlCommonResourse.ListViewRowHeight;
frameLayout.AddChidren(rowLayout);
this.AddRemoteRow(rowLayout);
//添加已共享内容行
var rowDevice = new StatuRowLayout();
rowDevice.Y = rowLayout.Bottom;
frameLayout.AddChidren(rowDevice);
this.AddShardContentRow(rowDevice);
//添加画面底部的说明
var frameNote = new FrameLayout();
frameNote.Height = ControlCommonResourse.NormalControlHeight * 2;
frameNote.Y = Application.GetRealHeight(680);
frameLayout.AddChidren(frameNote);
//一旦移除该家庭成员,他/她将无法使用该网关下所绑定的设备
Button btnNote1 = new ViewNormalControl(Application.GetRealWidth(800), ControlCommonResourse.NormalControlHeight * 2, false);
btnNote1.TextID = R.MyInternationalizationString.RemoveMenberAndDonotUserBindGatewayDevice;
btnNote1.IsMoreLines = true;
btnNote1.TextColor = UserCenterColor.Current.Gray;
btnNote1.Gravity = Gravity.CenterHorizontal;
btnNote1.TextAlignment = TextAlignment.Center;
frameNote.AddChidren(btnNote1);
var btnIcon = new IconViewControl(80);
btnIcon.X = btnNote1.X - Application.GetRealWidth(80);
btnIcon.UnSelectedImagePath = "Item/Tips.png";
btnIcon.Gravity = Gravity.CenterVertical;
frameNote.AddChidren(btnIcon);
//添加移除按钮
var btnDelete = new BottomClickButton();
btnDelete.TextID = R.MyInternationalizationString.RemoveBotton;
btnDelete.Y = frameNote.Bottom + Application.GetRealHeight(100);
btnDelete.BackgroundColor = UserCenterColor.Current.Red;
frameLayout.AddChidren(btnDelete);
btnDelete.MouseUpEventHandler += (sender, e) =>
{
//确定要移除该家庭成员吗?
string msg = Language.StringByID(R.MyInternationalizationString.uConfirmRemoveMember);
this.ShowConfirmMsg(msg, "DeleteSubAccount");
};
}
#endregion
#region ■ 远程操作行_________________________
///
/// 添加远程操作行
///
/// Row.
private void AddRemoteRow(RowLayout row)
{
//图标
var btnIcon = new RowLeftIconView();
btnIcon.UnSelectedImagePath = "Item/Remote.png";
btnIcon.SelectedImagePath = "Item/RemoteSelected.png";
row.AddChidren(btnIcon);
//文字:远程操作
var btnName = new RowCenterView(true);
btnName.TextID = R.MyInternationalizationString.RemoteManipulation;
row.AddChidren(btnName);
//开关
var btnSwitch = new SwichControl();
row.AddChidren(btnSwitch);
btnSwitch.MouseUpEventHandler += (sender, e) =>
{
btnSwitch.IsSelected = !btnSwitch.IsSelected;
};
}
#endregion
#region ■ 已共享内容行_______________________
///
/// 添加已共享内容行
///
/// Row.
private void AddShardContentRow(StatuRowLayout row)
{
//图标
var btnIcon = new RowLeftIconView();
btnIcon.UnSelectedImagePath = "Item/ShardDevice.png";
btnIcon.SelectedImagePath = "Item/ShardDeviceSelected.png";
row.AddChidren(btnIcon);
//文字:已共享内容行
var btnName = new RowCenterView(true);
btnName.TextID = R.MyInternationalizationString.uHadSharedContent;
row.AddChidren(btnName);
//右图标
row.AddRightIconControl();
var memberShardInfo = new MemberShardInfoData();
row.MouseUpEvent += (sender, e) =>
{
var form = new SharedContent.SearchConfigureSharedListRoomForm();
this.AddForm(form, memberInfo, memberShardInfo);
};
}
#endregion
#region ■ 升级或者降级子账号_________________
///
/// 升级或者降级子账号
///
public async void UpOrDownSubAccountLevel()
{
//开启进度条
this.ShowProgressBar();
var pra = new UpOrDownLevelPra();
pra.DistributedMark = memberInfo.DistributedMark;
bool result = await UserCenterLogic.GetResultStatuByRequestHttps("ZigbeeUsers/UpSubAccount", pra);
if (result == false)
{
this.CloseProgressBar();
return;
}
this.CloseProgressBar();
//变更权限
memberInfo.AccountType = memberInfo.AccountType == 1 ? 0 : 1;
Application.RunOnMainThread(() =>
{
//变更权限图标
if (memberInfo.AccountType == 1)
{
btnTopIcon.UnSelectedImagePath = "Account/HadAuthority.png";
}
else
{
btnTopIcon.UnSelectedImagePath = "Account/NotAuthority.png";
}
//变更权限文字
btnAuthority.TextID = memberInfo.AccountType == 1 ? R.MyInternationalizationString.uMemberHadActionAuthority : R.MyInternationalizationString.uMember;
//打开显示成功的画面
if (memberInfo.AccountType == 1)
{
var form = new SubAccountLevelUpSuccessForm();
this.AddForm(form, memberInfo);
}
});
}
#endregion
#region ■ 删除子账号_________________________
///
/// 删除子账号
///
public async void DeleteSubAccount()
{
//开启进度条
this.ShowProgressBar();
var pra = new DeleteSubAccountPra();
pra.SubAccount = memberInfo.SubAccountDistributedMark;
bool result = await UserCenterLogic.GetResultStatuByRequestHttps("ZigbeeUsers/DeletedSubAccount", pra);
//关闭进度条
this.CloseProgressBar();
if (result == false)
{
return;
}
Application.RunOnMainThread(() =>
{
//从成员一览画面移除
this.LoadFormMethodByName("MemberListForm", "DeleteRowByAccount", memberInfo.Account);
//自身关闭
this.CloseForm();
});
}
#endregion
#region ■ 结构体_____________________________
///
/// 升级或者降级子账号的启动参数
///
private class UpOrDownLevelPra : IfacePraCommon
{
///
/// 通过《住宅的Guid查询住宅下面的子账号》接口时,返回的DistributedMark字段
///
public string DistributedMark = string.Empty;
}
///
/// 删除子账号的启动参数
///
private class DeleteSubAccountPra : IfacePraCommon
{
///
/// 通过《住宅的Guid查询住宅下面的子账号》接口时,返回的DistributedMark字段
///
public string SubAccount = string.Empty;
///
/// HouseDistributedMark
///
public string HouseDistributedMark = Common.Config.Instance.HomeId;
}
#endregion
}
}