|
using System;
|
using System.Collections.Generic;
|
using System.Threading;
|
using HDL_ON.DAL.Server;
|
using HDL_ON.DriverLayer;
|
using HDL_ON.Entity;
|
using HDL_ON.UI.CSS;
|
using Shared;
|
|
namespace HDL_ON.UI
|
{
|
public class AddGroupControlPage : FrameLayout
|
{
|
#region 控件列表
|
/// <summary>
|
/// 当前窗体
|
/// </summary>
|
FrameLayout bodyView;
|
/// <summary>
|
/// 楼层选择下拉图标
|
/// </summary>
|
Button btnFloorDownIcon;
|
/// <summary>
|
/// 楼层显示
|
/// </summary>
|
Button btnFloor;
|
/// <summary>
|
/// 全选按钮
|
/// </summary>
|
Button btnChooseAll;
|
/// <summary>
|
/// 功能列表集合显示区域
|
/// </summary>
|
VerticalScrolViewLayout functionListView;
|
/// <summary>
|
/// 完成按钮
|
/// </summary>
|
Button btnConfrim;
|
|
#endregion
|
/// <summary>
|
/// 功能列表
|
/// </summary>
|
List<Function> groupControlLightList;
|
/// <summary>
|
/// 本地的灯光列表
|
/// </summary>
|
List<Function> lightList;
|
/// <summary>
|
/// 回调刷新
|
/// </summary>
|
Action backActon;
|
/// <summary>
|
/// 是否新增群控
|
/// </summary>
|
bool isAdd = true;
|
/// <summary>
|
/// 编辑的组控数据
|
/// </summary>
|
string editDataString = "";
|
|
GroupControl groupControl;
|
|
GroupControlType groupControlType = new GroupControlType();
|
|
public AddGroupControlPage(GroupControl groupControl, Action action)
|
{
|
bodyView = this;
|
if(groupControl == null)
|
{
|
this.groupControl = new GroupControl();
|
}
|
else
|
{
|
isAdd = false;
|
this.groupControl = groupControl;
|
editDataString = Newtonsoft.Json.JsonConvert.SerializeObject(this.groupControl);
|
}
|
groupControlLightList = new List<Function>();
|
backActon = action;
|
lightList = FunctionList.List.GetLightList();
|
}
|
|
public void LoadPage()
|
{
|
bodyView.BackgroundColor = CSS_Color.BackgroundColor;
|
new TopViewDiv(bodyView, Language.StringByID(StringId.CombinedDimming)).LoadTopView();
|
|
var contentView = new FrameLayout()
|
{
|
Y = Application.GetRealHeight(64),
|
Height = Application.GetRealHeight(550),
|
};
|
bodyView.AddChidren(contentView);
|
|
#region 组名称
|
FrameLayout groupNameView;
|
groupNameView = new FrameLayout()
|
{
|
Height = Application.GetRealHeight(50),
|
BackgroundColor = CSS_Color.MainBackgroundColor,
|
};
|
contentView.AddChidren(groupNameView);
|
Button btnGroupNameTitle = new Button()
|
{
|
X = Application.GetRealWidth(16),
|
Width = Application.GetRealWidth(78),
|
TextID = StringId.GroupNmae,
|
TextAlignment = TextAlignment.CenterLeft,
|
TextSize = CSS_FontSize.SubheadingFontSize,
|
TextColor = CSS_Color.FirstLevelTitleColor,
|
};
|
groupNameView.AddChidren(btnGroupNameTitle);
|
|
var etGroupName = new EditText()
|
{
|
X = Application.GetRealWidth(155),
|
Width = Application.GetRealWidth(200),
|
PlaceholderText = Language.StringByID(StringId.PlsEntry),
|
TextSize = CSS_FontSize.TextFontSize,
|
TextAlignment = TextAlignment.CenterRight,
|
TextColor = CSS_Color.TextualColor,
|
PlaceholderTextColor = CSS_Color.PromptingColor1,
|
};
|
groupNameView.AddChidren(etGroupName);
|
|
groupNameView.AddChidren(
|
new Button()
|
{
|
Gravity = Gravity.CenterHorizontal,
|
Y = Application.GetRealHeight(49),
|
Height = Application.GetRealHeight(1),
|
Width = Application.GetRealWidth(343),
|
BackgroundColor = CSS_Color.DividingLineColor,
|
});
|
#endregion
|
#region 位置管理
|
var locationMagtView = new FrameLayout()
|
{
|
Y = Application.GetRealHeight(50),
|
Height = Application.GetRealHeight(50),
|
BackgroundColor = CSS_Color.MainBackgroundColor,
|
};
|
contentView.AddChidren(locationMagtView);
|
|
var btnLocationMagtTitle = new Button()
|
{
|
X = Application.GetRealWidth(16),
|
Width = Application.GetRealWidth(160),
|
TextAlignment = TextAlignment.CenterLeft,
|
TextColor = CSS_Color.FirstLevelTitleColor,
|
TextSize = CSS_FontSize.SubheadingFontSize,
|
TextID = StringId.LocationManagement,
|
};
|
locationMagtView.AddChidren(btnLocationMagtTitle);
|
|
var btnLocationValues = new Button()
|
{
|
X = Application.GetRealWidth(86),
|
Width = Application.GetRealWidth(237),
|
TextAlignment = TextAlignment.CenterRight,
|
TextColor = CSS_Color.PromptingColor1,
|
TextSize = CSS_FontSize.TextFontSize,
|
Text = groupControl.GetRoomListName(),
|
};
|
locationMagtView.AddChidren(btnLocationValues);
|
|
var btnLocationInfoRight = new Button()
|
{
|
X = Application.GetRealWidth(339),
|
Gravity = Gravity.CenterVertical,
|
Width = Application.GetMinRealAverage(16),
|
Height = Application.GetMinRealAverage(16),
|
UnSelectedImagePath = "Public/RightIcon.png",
|
};
|
locationMagtView.AddChidren(btnLocationInfoRight);
|
EventHandler<MouseEventArgs> eventHandler = (sender, e) =>
|
{
|
Application.HideSoftInput();
|
//修改功能所属房间之后的回调事件
|
Action chooseRoomBackAction = () => {
|
try
|
{
|
btnLocationValues.Text = groupControl.GetRoomListName();
|
}
|
catch { }
|
};
|
var view = new GroupChooseRoomPage(groupControl, chooseRoomBackAction);
|
MainPage.BasePageView.AddChidren(view);
|
view.LoadPage();
|
MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1;
|
};
|
btnLocationInfoRight.MouseUpEventHandler = eventHandler;
|
btnLocationValues.MouseUpEventHandler = eventHandler;
|
|
|
//locationMagtView.AddChidren(
|
// new Button()
|
// {
|
// Y = Application.GetRealHeight(49),
|
// Gravity = Gravity.CenterHorizontal,
|
// BackgroundColor = CSS_Color.DividingLineColor,
|
// Width = Application.GetRealWidth(343),
|
// Height = Application.GetRealHeight(1)
|
// });
|
#endregion
|
|
//contentView.AddChidren(new Button()
|
//{
|
// Y = Application.GetRealHeight(164),
|
// BackgroundColor = CSS_Color.BackgroundColor,
|
//});
|
|
/// <summary>
|
/// 房间内容显示区域
|
/// </summary>
|
var roomFloorChangeView = new FrameLayout()
|
{
|
Y = Application.GetRealHeight(172),
|
Height = Application.GetRealHeight(52),
|
BackgroundColor = CSS_Color.BackgroundColor,
|
};
|
bodyView.AddChidren(roomFloorChangeView);
|
#region 房间顶部切换显示区域
|
btnFloorDownIcon = new Button()
|
{
|
Width = Application.GetMinRealAverage(16),
|
Height = Application.GetMinRealAverage(16),
|
X = Application.GetRealWidth(16),
|
Y = Application.GetRealHeight(18),
|
UnSelectedImagePath = "Public/DownIcon.png",
|
};
|
roomFloorChangeView.AddChidren(btnFloorDownIcon);
|
|
btnFloor = new Button()
|
{
|
X = btnFloorDownIcon.Right,
|
Width = Application.GetRealWidth(200),
|
TextColor = CSS_Color.FirstLevelTitleColor,
|
TextSize = CSS_FontSize.PromptFontSize_FirstLevel,
|
TextAlignment = TextAlignment.CenterLeft,
|
Text = DB_ResidenceData.Instance.CurFloor.roomName,
|
};
|
roomFloorChangeView.AddChidren(btnFloor);
|
|
btnChooseAll = new Button()
|
{
|
X = Application.GetRealWidth(245),
|
Width = Application.GetRealWidth(109),
|
TextAlignment = TextAlignment.CenterRight,
|
TextSize = CSS_FontSize.TextFontSize,
|
TextColor = CSS_Color.FirstLevelTitleColor,
|
TextID = StringId.SelectedAll,
|
};
|
if (groupControlLightList.Count > 0)
|
{
|
btnChooseAll.TextID = StringId.Cancel;
|
}
|
roomFloorChangeView.AddChidren(btnChooseAll);
|
btnChooseAll.MouseUpEventHandler = (sender, e) => {
|
if (groupControlLightList.Count > 0)
|
{
|
groupControlLightList.Clear();
|
btnChooseAll.TextID = StringId.SelectAll;
|
btnConfrim.IsSelected = false;
|
}
|
else
|
{
|
groupControlLightList.AddRange(lightList);
|
btnChooseAll.TextID = StringId.Cancel;
|
btnConfrim.IsSelected = true;
|
}
|
LoadLightRow(lightList);
|
};
|
|
#endregion
|
|
functionListView = new VerticalScrolViewLayout()
|
{
|
Y = Application.GetRealHeight(220),
|
Height = Application.GetRealHeight(640 - 12 - 52 - 100 -100),
|
};
|
bodyView.AddChidren(functionListView);
|
|
|
functionListView.AddChidren(new Button()
|
{
|
Height = Application.GetRealHeight(10),
|
});
|
|
#region 底部view
|
var bottomView = new FrameLayout()
|
{
|
Y = Application.GetRealHeight(591),
|
Height = Application.GetRealHeight(100),
|
BackgroundColor = CSS_Color.MainBackgroundColor,
|
Radius = (uint)Application.GetRealWidth(12),
|
};
|
this.AddChidren(bottomView);
|
|
btnConfrim = new Button()
|
{
|
Y = Application.GetRealHeight(12),
|
Gravity = Gravity.CenterHorizontal,
|
Width = Application.GetRealWidth(220),
|
Height = Application.GetRealHeight(44),
|
Radius = (uint)Application.GetRealHeight(22),
|
TextAlignment = TextAlignment.Center,
|
TextColor = CSS_Color.MainBackgroundColor,
|
BackgroundColor = CSS_Color.BackgroundColor,
|
TextID = StringId.Confirm,
|
TextSize = CSS_FontSize.SubheadingFontSize,
|
SelectedTextColor = CSS_Color.MainBackgroundColor,
|
SelectedBackgroundColor = CSS_Color.MainColor,
|
IsSelected = !isAdd
|
};
|
bottomView.AddChidren(btnConfrim);
|
btnConfrim.MouseUpEventHandler = (sender, e) => {
|
if (btnConfrim.IsSelected)
|
{
|
//保存群控数据
|
var name = etGroupName.Text.Trim();
|
if (string.IsNullOrEmpty(name))
|
{
|
new PublicAssmebly().TipMsg(StringId.Tip, StringId.PlsEntryGroupName);
|
return;
|
}
|
if (groupControlLightList.Count < 2)
|
{
|
new PublicAssmebly().TipMsg(StringId.Tip, StringId.PlsSelectMoreData);
|
return;
|
}
|
if (isAdd)
|
{
|
groupControl.name = name;
|
groupControl.sids.Clear();
|
foreach (var light in groupControlLightList)
|
{
|
try
|
{
|
var gc = new GroupControlFunction();
|
gc.sid = light.sid;
|
gc.spk = light.spk;
|
groupControl.sids.Add(gc);
|
}
|
catch (Exception ex)
|
{
|
MainPage.Log($"新增群控转换数据异常:{ex.Message}");
|
}
|
}
|
try
|
{
|
groupControl.type = groupControlType.type;
|
groupControl.sid = groupControl.NewGroupControlSid();
|
var pack = Common.ApiUtlis.Ins.HttpRequest.AddGroupControl(new List<GroupControl>() { groupControl });
|
if (pack != null)
|
{
|
if (pack.Code == StateCode.SUCCESS)
|
{
|
backActon?.Invoke();
|
this.RemoveFromParent();
|
}
|
else
|
{
|
IMessageCommon.Current.ShowErrorInfoAlter(pack.Code);
|
}
|
}
|
}
|
catch (Exception ex)
|
{
|
MainPage.Log($"新增群控异常:{ex.Message}");
|
}
|
}
|
else
|
{
|
try
|
{
|
var newEditDataString = Newtonsoft.Json.JsonConvert.SerializeObject(this.groupControl);
|
//没有更新数据则直接退出
|
if (newEditDataString == editDataString)
|
{
|
this.RemoveFromParent();
|
return;
|
}
|
groupControl.sids.Clear();
|
foreach (var light in groupControlLightList)
|
{
|
try
|
{
|
var gc = new GroupControlFunction();
|
gc.sid = light.sid;
|
gc.spk = light.spk;
|
groupControl.sids.Add(gc);
|
}
|
catch (Exception ex)
|
{
|
MainPage.Log($"新增群控转换数据异常:{ex.Message}");
|
}
|
}
|
|
var pack = Common.ApiUtlis.Ins.HttpRequest.EditGroupControl(new List<GroupControl>() { groupControl });
|
if (pack != null)
|
{
|
if (pack.Code == StateCode.SUCCESS)
|
{
|
backActon?.Invoke();
|
this.RemoveFromParent();
|
}
|
else
|
{
|
IMessageCommon.Current.ShowErrorInfoAlter(pack.Code);
|
}
|
}
|
}
|
catch (Exception ex)
|
{
|
MainPage.Log($"编辑群控异常:{ex.Message}");
|
}
|
|
}
|
}
|
};
|
|
#endregion
|
|
|
LoadDialog_ChangeFloor();
|
|
|
new Thread(() => {
|
if (isAdd)
|
{
|
var pack = Common.ApiUtlis.Ins.HttpRequest.GetGroupControlTypes("light.switch");
|
if (pack != null)
|
{
|
if (pack.Code == StateCode.SUCCESS)
|
{
|
try
|
{
|
|
var groupControlTypes = Newtonsoft.Json.JsonConvert.DeserializeObject<List<GroupControlType>>(pack.Data.ToString());
|
if (groupControlTypes != null && groupControlTypes.Count > 0)
|
{
|
groupControlType = groupControlTypes[0];
|
Application.RunOnMainThread(() => {
|
LoadLightRow(lightList);
|
});
|
}
|
}
|
catch (Exception ex)
|
{
|
MainPage.Log($"读取组控类型失败:{ex.Message}");
|
}
|
}
|
else
|
{
|
IMessageCommon.Current.ShowErrorInfoAlter(pack.Code);
|
}
|
}
|
}
|
else
|
{
|
var pack = Common.ApiUtlis.Ins.HttpRequest.GetGroupControInfo(groupControl.userDeviceGroupControlId);
|
if (pack != null)
|
{
|
if (pack.Code == StateCode.SUCCESS)
|
{
|
try
|
{
|
|
var groupControlTemps = Newtonsoft.Json.JsonConvert.DeserializeObject<List<GroupControl>>(pack.Data.ToString());
|
if (groupControlTemps != null && groupControlTemps.Count > 0)
|
{
|
groupControl = groupControlTemps[0];
|
Application.RunOnMainThread(() =>
|
{
|
LoadLightRow(lightList);
|
});
|
}
|
}
|
catch (Exception ex)
|
{
|
MainPage.Log($"读取组控信息失败:{ex.Message}");
|
}
|
}
|
else
|
{
|
IMessageCommon.Current.ShowErrorInfoAlter(pack.Code);
|
}
|
}
|
}
|
}) { IsBackground = true }.Start();
|
|
if (!isAdd)
|
{
|
etGroupName.Text = groupControl.name;
|
btnLocationValues.Text = groupControl.GetRoomListName();
|
}
|
}
|
|
/// <summary>
|
/// 显示的设备的总数
|
/// </summary>
|
int showCount = 0;
|
|
/// <summary>
|
/// 加载功能row
|
/// </summary>
|
/// <param name="lightList"></param>
|
void LoadLightRow(List<Function> functions, bool isAppend = false)
|
{
|
var waitPage = new Loading();
|
bodyView.AddChidren(waitPage);
|
waitPage.Start("");
|
|
new Thread(() =>
|
{
|
try
|
{
|
Application.RunOnMainThread(() =>
|
{
|
if (!isAppend)
|
{
|
showCount = 0;
|
functionListView.RemoveAll();
|
}
|
int i = 0;
|
foreach (var function in functions)
|
{
|
i++;
|
if (i > 100)
|
{
|
break;
|
}
|
showCount++;
|
var functionDiv = new LightRow(function)
|
{
|
Gravity = Gravity.CenterHorizontal,
|
Height = Application.GetRealHeight(62),
|
BorderColor = 0x00FFFFFF,
|
BorderWidth = 1,
|
BackgroundColor = CSS_Color.MainBackgroundColor,
|
Tag = function.spk + function.sid
|
};
|
functionDiv.AddChidren(new Button()
|
{
|
Y = Application.GetRealHeight(61),
|
Gravity = Gravity.CenterHorizontal,
|
Width = Application.GetRealWidth(343),
|
Height = Application.GetRealWidth(1),
|
BackgroundColor = CSS_Color.DividingLineColor,
|
});
|
|
Action setAction = () =>
|
{
|
if (groupControlLightList.Count > 0)
|
{
|
btnConfrim.IsSelected = true;
|
}
|
else
|
{
|
btnConfrim.IsSelected = false;
|
}
|
};
|
if (groupControl.sids.Find((obj) => obj.sid == function.sid) != null)
|
{
|
groupControlLightList.Add(function);
|
}
|
|
functionDiv.LoadDiv(groupControlLightList, setAction);
|
functionListView.AddChidren(functionDiv);
|
}
|
|
if (functions.Count > showCount)
|
{
|
var btnAppend = new Button()
|
{
|
Height = Application.GetRealHeight(60),
|
TextAlignment = TextAlignment.Center,
|
TextSize = CSS_FontSize.SubheadingFontSize,
|
TextColor = CSS_Color.FirstLevelTitleColor,
|
TextID = StringId.LoadMore,
|
};
|
functionListView.AddChidren(btnAppend);
|
btnAppend.MouseUpEventHandler = (sender, e) =>
|
{
|
btnAppend.RemoveFromParent();
|
LoadLightRow(functions, true);
|
};
|
}
|
});
|
}
|
catch (Exception ex)
|
{
|
MainPage.Log("ShowFunctionRowError : " + ex.Message);
|
}
|
finally
|
{
|
Application.RunOnMainThread(() =>
|
{
|
if (waitPage != null)
|
{
|
waitPage.RemoveFromParent();
|
waitPage = null;
|
}
|
});
|
}
|
})
|
{ IsBackground = true }.Start();
|
|
}
|
|
|
/// <summary>
|
/// 住宅列表点击事件
|
/// </summary>
|
void LoadDialog_ChangeFloor()
|
{
|
string nowSelectId = null;
|
btnFloor.MouseUpEventHandler += (sender, e) =>
|
{
|
Application.HideSoftInput();
|
//显示下拉列表
|
var form = new FloorRoomSelectPopupView();
|
form.ShowDeviceFunctionView(btnFloor, this.lightList, (selectId, listFunc) =>
|
{
|
btnChooseAll.MouseUpEventHandler = (sender2, e2) => {
|
if (groupControlLightList.Count > 0)
|
{
|
groupControlLightList.Clear();
|
btnChooseAll.TextID = StringId.SelectAll;
|
btnConfrim.IsSelected = false;
|
}
|
else
|
{
|
groupControlLightList.AddRange(listFunc);
|
btnChooseAll.TextID = StringId.Cancel;
|
btnConfrim.IsSelected = true;
|
}
|
LoadLightRow(listFunc);
|
};
|
nowSelectId = selectId;
|
//重新加载界面
|
LoadLightRow(listFunc);
|
}, nowSelectId,100);
|
};
|
}
|
|
}
|
|
|
}
|