using System;
using Shared;
using HDL_ON.Entity;
using HDL_ON.UI.CSS;
using System.Collections.Generic;
using HDL_ON.DAL;
using HDL_ON.DAL.Server;
namespace HDL_ON.UI
{
public partial class MemberFunctionPermissionPage : FrameLayout
{
MemberFunctionPermissionPage bodyView;
FrameLayout allRoomView;
///
/// 全选按钮
///
Button btnChooseAll;
///
/// 功能显示区域
///
VerticalScrolViewLayout contentView;
ResidenceMemberInfo memberInfo;
Room room;
List funs;
public MemberFunctionPermissionPage(ResidenceMemberInfo mInfo, Room r)
{
bodyView = this;
memberInfo = mInfo;
room = r;
funs = new List();
if (memberInfo.CurShareData.ShareDataBytes != null)
{
funs = Newtonsoft.Json.JsonConvert.DeserializeObject>(
CommonPage.MyEncodingUTF8.GetString(memberInfo.CurShareData.ShareDataBytes));
}
}
public void LoadPage()
{
new TopViewDiv(bodyView, Language.StringByID(StringId.PermissionToUse)).LoadTopView();
allRoomView = new FrameLayout()
{
Y = Application.GetRealHeight(64),
Height = Application.GetRealHeight(50),
BackgroundColor = CSS_Color.MainBackgroundColor,
};
bodyView.AddChidren(allRoomView);
Button btnAllRoomText = new Button()
{
X = Application.GetRealWidth(16),
Width = Application.GetRealWidth(280),
TextID = StringId.All,
TextSize = CSS_FontSize.SubheadingFontSize,
TextColor = CSS_Color.FirstLevelTitleColor,
TextAlignment = TextAlignment.CenterLeft,
};
allRoomView.AddChidren(btnAllRoomText);
btnChooseAll = new Button()
{
X = Application.GetRealWidth(331),
Gravity = Gravity.CenterVertical,
Width = Application.GetMinRealAverage(28),
Height = Application.GetMinRealAverage(28),
UnSelectedImagePath = "Public/ChooseIcon.png",
SelectedImagePath = "Public/ChooseOnIcon.png",
IsSelected = true,
};
allRoomView.AddChidren(btnChooseAll);
allRoomView.AddChidren(new Button()
{
Gravity = Gravity.CenterHorizontal,
Y = Application.GetRealHeight(49),
Height = Application.GetMinReal(1),
Width = Application.GetRealWidth(343),
BackgroundColor = CSS_Color.DividingLineColor,
});
contentView = new VerticalScrolViewLayout()
{
Y = Application.GetRealHeight(64+50),
Height = Application.GetRealHeight(450),
};
bodyView.AddChidren(contentView);
var btnOption = new Button()
{
Y = Application.GetRealHeight(519+64),
Gravity = Gravity.CenterHorizontal,
Width = Application.GetRealWidth(220),
Height = Application.GetRealHeight(44),
BackgroundColor = CSS_Color.MainColor,
TextAlignment = TextAlignment.Center,
TextColor = CSS_Color.MainBackgroundColor,
TextID = StringId.Confirm,
TextSize = CSS_FontSize.SubheadingFontSize,
IsBold = true,
Radius = (uint) Application.GetRealWidth(22),
BorderColor = 0x00000000,
BorderWidth = 0,
};
bodyView.AddChidren(btnOption);
btnOption.MouseUpEventHandler = (sender, e) => {
var act = TipLoadingMsg(Language.StringByID(StringId.SavingPleaseWait));
memberInfo.CurShareData.ShareDataBytes = CommonPage.MyEncodingUTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(funs));
EditShareData();
act();
};
LoadFunctionRow();
LoadEventList();
}
///
/// 加载功能列表
///
void LoadFunctionRow()
{
contentView.RemoveAll();
foreach (var function in room.functions)
{
var roomView = new FrameLayout()
{
Height = Application.GetRealHeight(50),
BackgroundColor = CSS_Color.MainBackgroundColor,
Tag = "row"
};
contentView.AddChidren(roomView);
Button btnRoomText = new Button()
{
X = Application.GetRealWidth(16),
Width = Application.GetRealWidth(280),
TextSize = CSS_FontSize.SubheadingFontSize,
TextColor = CSS_Color.FirstLevelTitleColor,
TextAlignment = TextAlignment.CenterLeft,
Text = function.name,
};
roomView.AddChidren(btnRoomText);
Button btnChoose = new Button()
{
X = Application.GetRealWidth(331),
Gravity = Gravity.CenterVertical,
Width = Application.GetMinRealAverage(28),
Height = Application.GetMinRealAverage(28),
UnSelectedImagePath = "Public/ChooseIcon.png",
SelectedImagePath = "Public/ChooseOnIcon.png",
Tag = "ChooseIcon"
};
roomView.AddChidren(btnChoose);
if (funs.Find((obj) => obj.sid == function.sid) != null)
{
btnChoose.IsSelected = true;
funs.Add(function);
}
else
{
if (btnChooseAll.IsSelected)
btnChooseAll.IsSelected = false;
}
LoadEvent_SharedDataChange(btnChoose, btnRoomText, roomView, function);
var btnLine = new Button()
{
Gravity = Gravity.CenterHorizontal,
Y = Application.GetRealHeight(49),
Height = Application.GetMinReal(1),
Width = Application.GetRealWidth(343),
BackgroundColor = CSS_Color.DividingLineColor,
};
roomView.AddChidren(btnLine);
}
}
void UpdataShareData()
{
ResponsePack responePack = new HttpServerRequest().EditShareData(memberInfo.CurShareData);
if (responePack.StateCode.ToUpper() == "SUCCESS")
{
new PublicAssmebly().TipMsgAutoClose(Language.StringByID(StringId.SavedSuccessfully), true);
}
else
{
new PublicAssmebly().TipMsgAutoClose(Language.StringByID(StringId.OperationFailed), true);
}
}
Action TipLoadingMsg(string msg)
{
Dialog dialog = new Dialog()
{
X = Application.GetRealWidth(89),
Y = Application.GetRealHeight(285),
Width = Application.GetRealWidth(198),
Height = Application.GetRealHeight(98),
};
FrameLayout frame = new FrameLayout()
{
BackgroundColor = CSS_Color.DialogTransparentColor1,
Radius = (uint)Application.GetRealWidth(12),
};
dialog.AddChidren(frame);
Button btnTipIcon = new Button()
{
Gravity = Gravity.CenterHorizontal,
Y = Application.GetRealHeight(15),
Width = Application.GetRealWidth(32),
Height = Application.GetRealWidth(32),
UnSelectedImagePath = "Public/MsgIcon/LoadingIcon.png",
};
frame.AddChidren(btnTipIcon);
Button btnTipMsg = new Button()
{
Y = Application.GetRealHeight(47),
Height = Application.GetRealHeight(50),
TextAlignment = TextAlignment.Center,
TextSize = CSS_FontSize.TextFontSize,
TextColor = CSS_Color.MainBackgroundColor,
Text = msg,
};
frame.AddChidren(btnTipMsg);
//new System.Threading.Thread(() =>{
//});
dialog.Show();
return new Action(() => {
dialog.Close();
});
}
}
}