using System;
using HDL_ON.UI.CSS;
using Shared;
using HDL_ON.Entity;
using System.Collections.Generic;
namespace HDL_ON.UI
{
public partial class RoomBinglingFloorPage : FrameLayout
{
FrameLayout bodyView;
///
/// 楼层显示区域
///
VerticalScrolViewLayout floorsListView;
///
/// 显示区域
///
FrameLayout contentView;
///
/// 楼层标题按钮
///
Button btnFloorTitle;
Room room;
///
/// 标题栏增加楼层之后的回调事件
///
Action addFloorAction;
///
/// 后退回调事件
///
Action backAction;
///
/// 最后一次点击的按钮
///
Button lastButton;
public RoomBinglingFloorPage()
{
bodyView = this;
}
///
/// 从房间进入楼层修改界面,需要回调事件更新房间的楼层信息
///
///
public RoomBinglingFloorPage(Action action, Room r)
{
room = r;
bodyView = this;
backAction = action;
}
///
/// 加载楼层Row
///
void LoadFloorRow(SpatialInfo floor)
{
var row = new RowLayout()
{
Height = Application.GetRealHeight(50),
Tag = floor.roomId,
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.roomName,
Tag = floor.uid,
};
row.AddChidren(btnFloor);
LoadEvent_FloorChoose(btnFloor);
if (room.parentId == floor.uid)
{
lastButton = btnFloor;
btnFloor.IsSelected = true;
}
}
void RefreshFloorsListView(string floorName)
{
var waitPage = new Loading();
MainPage.BaseView.AddChidren(waitPage);
waitPage.Start(Language.StringByID(StringId.PleaseWait));
new System.Threading.Thread(() =>
{
try
{
var f = new SpatialInfo("FLOOR") { roomName = floorName, parentId = DB_ResidenceData.Instance.CurrentRegion.id };
var addResult = SpatialInfo.CurrentSpatial.AddFloor(f, out f);
if (addResult == DAL.Server.StateCode.SUCCESS)
{
Application.RunOnMainThread(() =>
{
LoadFloorRow(f);
});
}
}
catch { }
finally
{
Application.RunOnMainThread(() => {
waitPage.Hide();
waitPage.RemoveFromParent();
int count = SpatialInfo.CurrentSpatial.FloorList.Count > 10 ? 10 : SpatialInfo.CurrentSpatial.FloorList.Count;
floorsListView.Height = Application.GetRealHeight(50 * count);
contentView.Height = Application.GetRealHeight(50 * (count + 1));
});
}
})
{ IsBackground = true }.Start();
//try
//{
// var f = new SpatialInfo("FLOOR") { roomName = floorName, parentId = DB_ResidenceData.Instance.CurrentRegion.RegionID };
// var addResult = SpatialInfo.CurrentSpatial.AddFloor(f,out f);
// if (addResult == DAL.Server.StateCode.SUCCESS)
// {
// LoadFloorRow(f);
// }
//}
//catch (Exception ex)
//{
// MainPage.Log("add floor eroor : " + ex.Message);
//}
//int count = SpatialInfo.CurrentSpatial.FloorList.Count > 10 ? 10 : SpatialInfo.CurrentSpatial.FloorList.Count;
//floorsListView.Height = Application.GetRealHeight(50 * count);
//contentView.Height = Application.GetRealHeight(50 * (count + 1));
}
public void LoadPage()
{
bodyView.BackgroundColor = CSS_Color.BackgroundColor;
addFloorAction = (floorName) =>
{
RefreshFloorsListView(floorName);
};
new TopViewDiv(bodyView, Language.StringByID(StringId.FloorAssignment)).LoadTopView_FloorTopView(addFloorAction, backAction);
int count = SpatialInfo.CurrentSpatial.FloorList.Count > 8 ? 8 : SpatialInfo.CurrentSpatial.FloorList.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 SpatialInfo.CurrentSpatial.FloorList)
{
MainPage.Log($"name:{floor.roomName};id:{floor.roomId}");
LoadFloorRow(floor);
}
//btnConfrim = new Button()
//{
// Gravity = Gravity.CenterHorizontal,
// Y = Application.GetRealHeight(582),
// Width = Application.GetRealWidth(220),
// Height = Application.GetRealWidth(44),
// Radius = (uint)Application.GetRealWidth(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();
}
}
//--------------------------------------------------------------------------------------------
public partial class RoomBinglingFloorPage
{
///
/// 房间绑定楼层,楼层选中事件
///
void LoadEvent_FloorChoose(Button btn)
{
btn.MouseUpEventHandler = (sender, e) =>
{
if (lastButton != null)
{
lastButton.IsSelected = false;
if (lastButton.Text == btn.Text)
{
lastButton = null;
}
}
btn.IsSelected = true;
lastButton = btn;
};
}
///
/// 房间绑定楼层事件
///
void LoadEvent_BindFloor()
{
EventHandler eventHandler = (sender, e) =>
{
if (lastButton == null)
{
return;
}
room.parentId = lastButton.Tag.ToString();
backAction?.Invoke();
bodyView.RemoveFromParent();
};
new BottomViewConfirmButton().LoadView(bodyView, eventHandler, Language.StringByID( StringId.Confirm));
}
}
}