using System;
|
using HDL_ON.UI.CSS;
|
using Shared;
|
using HDL_ON.Entity;
|
|
namespace HDL_ON.UI
|
{
|
public partial class FloorsManagementPage : FrameLayout
|
{
|
FrameLayout bodyView;
|
/// <summary>
|
/// 楼层显示区域
|
/// </summary>
|
VerticalScrolViewLayout floorsListView;
|
/// <summary>
|
/// 显示区域
|
/// </summary>
|
FrameLayout contentView;
|
/// <summary>
|
/// 楼层标题按钮
|
/// </summary>
|
Button btnFloorTitle;
|
|
|
/// <summary>
|
/// 房间绑定楼层的确定按钮
|
/// </summary>
|
Button btnConfrim;
|
/// <summary>
|
/// 当页面是编辑楼层时,该变量为空
|
/// 当页面是给房间绑定楼层时,该变量不为空
|
/// </summary>
|
Room room;
|
/// <summary>
|
/// 标题栏修改楼层之后的回调事件
|
/// </summary>
|
Action<string,string> refreshFloorList;
|
/// <summary>
|
/// 后退回调事件
|
/// </summary>
|
Action backAction;
|
/// <summary>
|
/// 最后一次点击的按钮
|
/// </summary>
|
Button lastButton;
|
|
public FloorsManagementPage()
|
{
|
bodyView = this;
|
}
|
|
/// <summary>
|
/// 从房间进入楼层修改界面,需要回调事件更新房间的楼层信息
|
/// </summary>
|
/// <param name="action"></param>
|
public FloorsManagementPage(Action action)
|
{
|
bodyView = this;
|
backAction = action;
|
}
|
/// <summary>
|
/// 加载界面
|
/// </summary>
|
public void LoadPage(int titleId)
|
{
|
|
bodyView.RemoveAll();
|
bodyView.BackgroundColor = CSS_Color.BackgroundColor;
|
refreshFloorList = (type,floorName) => {
|
RefreshFloorsListView(type, floorName);
|
};
|
new TopViewDiv(bodyView, Language.StringByID(titleId)).LoadTopView("floors",refreshFloorList,backAction);
|
|
int count = DB_ResidenceData.residenceData.floors.Count > 8 ? 8 : DB_ResidenceData.residenceData.floors.Count;
|
var contentViewHeight = (count + 1) * Application.GetRealHeight(50);
|
|
contentView = new FrameLayout()
|
{
|
Gravity = Gravity.CenterHorizontal,
|
Y = Application.GetRealHeight(80),
|
Width = Application.GetRealWidth(343),
|
Height = contentViewHeight,
|
Radius = (uint)Application.GetRealHeight(5),
|
BorderColor = 0x00FFFFFF,
|
BorderWidth = 0,
|
BackgroundColor = CSS_Color.MainBackgroundColor,
|
};
|
bodyView.AddChidren(contentView);
|
|
|
btnFloorTitle = new Button()
|
{
|
Height = Application.GetRealHeight(50),
|
TextID = StringId.Floors,
|
TextAlignment = TextAlignment.Center,
|
TextSize = CSS_FontSize.SubheadingFontSize,
|
TextColor = CSS_Color.FirstLevelTitleColor,
|
};
|
contentView.AddChidren(btnFloorTitle);
|
contentView.AddChidren(new Button()
|
{
|
Height = Application.GetRealHeight(1),
|
Y = Application.GetRealHeight(49),
|
BackgroundColor = CSS_Color.DividingLineColor,
|
});
|
|
floorsListView = new VerticalScrolViewLayout()
|
{
|
Y = btnFloorTitle.Bottom,
|
Height = count * Application.GetRealHeight(50),
|
};
|
contentView.AddChidren(floorsListView);
|
|
foreach(var floor in DB_ResidenceData.residenceData.floors)
|
{
|
LoadFloorRow(floor);
|
}
|
}
|
|
/// <summary>
|
/// 加载楼层Row
|
/// </summary>
|
/// <param name="floor"></param>
|
void LoadFloorRow(Floor floor)
|
{
|
var row = new RowLayout()
|
{
|
Height = Application.GetRealHeight(50),
|
Tag = floor.name,
|
LineColor = CSS_Color.DividingLineColor,
|
};
|
floorsListView.AddChidren(row);
|
|
var btnFloor = new Button()
|
{
|
Height = Application.GetRealHeight(50),
|
TextAlignment = TextAlignment.Center,
|
TextSize = CSS_FontSize.SubheadingFontSize,
|
TextColor = CSS_Color.TextualColor,
|
SelectedTextColor = CSS_Color.MainColor,
|
Text = floor.name,
|
Tag = floor.sid,
|
};
|
row.AddChidren(btnFloor);
|
|
if (room == null)
|
{
|
var btnDel = new Button()
|
{
|
TextID = StringId.Del,
|
BackgroundColor = CSS_Color.WarningColor,
|
TextColor = CSS_Color.MainBackgroundColor,
|
Tag = floor.name
|
};
|
row.AddRightView(btnDel);
|
LoadEvent_DelFloor(btnDel);
|
LoadEvent_FloorNamgeChange(btnFloor,btnDel,row,floor);
|
}
|
else {
|
LoadEvent_FloorChoose(btnFloor);
|
if (room.floorId == floor.sid)
|
{
|
lastButton = btnFloor;
|
btnFloor.IsSelected = true;
|
}
|
}
|
}
|
|
void RefreshFloorsListView(string changeType,string floorName)
|
{
|
switch (changeType)
|
{
|
case "add":
|
try
|
{
|
var f = new Floor() { sid = Guid.NewGuid().ToString(), name = floorName };
|
DB_ResidenceData.residenceData.floors.Add(f);
|
LoadFloorRow(f);
|
}
|
catch (Exception ex)
|
{
|
MainPage.Log("add floor eroor : " + ex.Message);
|
}
|
break;
|
case "edit":
|
for(int i=0;i<floorsListView.ChildrenCount;i++)
|
{
|
if(floorsListView.GetChildren(i).GetType() == typeof(Button))
|
{
|
Button btn = floorsListView.GetChildren(i) as Button;
|
if(floorName == "")
|
{
|
btn.Text = floorName;
|
return;
|
}
|
if(btn.Tag.ToString() == floorName|| btn.Tag.ToString() == floorName + "line")
|
{
|
btn.RemoveFromParent();
|
}
|
}
|
}
|
break;
|
case "del":
|
//该楼层删除之后,绑定该楼层的房间要重置绑定的楼层
|
foreach (var r in DB_ResidenceData.rooms)
|
{
|
if (r.floorId == DB_ResidenceData.residenceData.floors.Find((obj) => obj.name == floorName).sid)
|
{
|
r.floorId = "";
|
}
|
}
|
for (int i = 0; i < floorsListView.ChildrenCount; i++)
|
{
|
if (floorsListView.GetChildren(i).GetType() == typeof(Button))
|
{
|
Button btn = floorsListView.GetChildren(i) as Button;
|
if (btn.Tag == null)
|
continue;
|
if (btn.Tag.ToString() == floorName + "line")
|
{
|
btn.RemoveFromParent();
|
}
|
}
|
if (floorsListView.GetChildren(i).GetType() == typeof(RowLayout))
|
{
|
RowLayout row = floorsListView.GetChildren(i) as RowLayout;
|
if (row.Tag == null)
|
continue;
|
if (row.Tag.ToString() == floorName)
|
{
|
row.RemoveFromParent();
|
}
|
}
|
DB_ResidenceData.residenceData.floors.Remove(DB_ResidenceData.residenceData.floors.Find((obj) => obj.name == floorName));
|
}
|
break;
|
}
|
DB_ResidenceData.residenceData.SaveResidenceData();
|
int count = DB_ResidenceData.residenceData.floors.Count > 10 ? 10 : DB_ResidenceData.residenceData.floors.Count;
|
floorsListView.Height = Application.GetRealHeight(50 * count);
|
contentView.Height = Application.GetRealHeight(50 * (count + 1));
|
}
|
|
/// <summary>
|
/// 分配给room楼层关系
|
/// </summary>
|
public void LoadPage(Room r,int titleId)
|
{
|
room = r;
|
LoadPage(titleId);
|
|
btnConfrim = new Button()
|
{
|
Gravity = Gravity.CenterHorizontal,
|
Y = Application.GetRealHeight(582),
|
Width = Application.GetRealWidth(220),
|
Height = Application.GetRealHeight(44),
|
Radius = (uint)Application.GetRealHeight(22),
|
BackgroundColor = CSS_Color .MainColor,
|
TextColor = CSS_Color.MainBackgroundColor,
|
TextSize = CSS_FontSize.SubheadingFontSize,
|
TextAlignment = TextAlignment.Center,
|
IsBold = true,
|
TextID = StringId.Confirm,
|
};
|
bodyView.AddChidren(btnConfrim);
|
|
LoadEvent_BindFloor();
|
}
|
}
|
}
|