using Shared.SimpleControl.Phone;
|
using System;
|
namespace Shared.SimpleControl.Pad
|
{
|
|
/// <summary>
|
/// 地热设备房间
|
/// </summary>
|
public class UserDeviceToFH : Shared.Dialog
|
{
|
|
/// <summary>
|
/// 当前界面
|
/// </summary>
|
static UserDeviceToFH curView;
|
UserFHPage ControlBodyView;
|
|
FrameLayout bodyScrolView;
|
VerticalScrolViewLayout RoomListScrolView;
|
|
/// <summary>
|
/// 构造函数
|
/// </summary>
|
public UserDeviceToFH ()
|
{
|
curView = this;
|
showAllRoomFH ();
|
readAllStatus ();
|
}
|
|
/// <summary>
|
/// 更新当前地热
|
/// </summary>
|
public static void UpdateStatus (Common updataFH)
|
{
|
if (curView == null) {
|
return;
|
}
|
Application.RunOnMainThread (() => {
|
for (int i = 0; i < curView.RoomListScrolView.ChildrenCount; i++) {
|
if (curView.RoomListScrolView.GetChildren (i).GetType () == typeof (RowLayout)) {
|
var fhRow = (RowLayout)curView.RoomListScrolView.GetChildren (i);
|
if (fhRow.Tag.ToString () != updataFH.CommonLoopID) {
|
continue;
|
}
|
for (int j = 0; j < fhRow.ChildrenCount; j++) {
|
if (fhRow.GetChildren (j).GetType () == typeof (Button)) {
|
var btn = (Button)fhRow.GetChildren (j);
|
if (btn.Tag == null) {
|
continue;
|
}
|
if (btn.Tag.ToString () == "Switch") {
|
if ((updataFH as FoolHeat).Status == 0) {
|
btn.IsSelected = false;
|
} else {
|
btn.IsSelected = true;
|
}
|
} else if (btn.Tag.ToString () == "Temperature") {
|
btn.Text = (updataFH as FoolHeat).WorkingTemperature.ToString () + "°C";
|
}
|
}
|
}
|
}
|
}
|
});
|
}
|
|
/// <summary>
|
/// 显示房间的所有地热
|
/// </summary>
|
void showAllRoomFH ()
|
{
|
FrameLayout topBackView = new FrameLayout () {
|
Height = Application.GetRealHeight (150),
|
BackgroundColor = 0xFF2f2f2f
|
};
|
AddChidren (topBackView);
|
#region 标题
|
var topView = new FrameLayout () {
|
Y = Application.GetRealHeight (36),
|
Height = Application.GetRealHeight (90),
|
};
|
AddChidren (topView);
|
|
var title = new Button () {
|
TextAlignment = TextAlignment.Center,
|
Text = Language.StringByID (R.MyInternationalizationString.FoolHeat),
|
TextSize = 19,
|
};
|
topView.AddChidren (title);
|
|
var logo = new Button () {
|
Width = Application.GetRealWidth (154),
|
Height = Application.GetRealHeight (90),
|
X = Application.GetRealWidth (486),
|
UnSelectedImagePath = MainPage.LogoString,
|
};
|
topView.AddChidren (logo);
|
var back = new Button () {
|
Height = Application.GetRealHeight (120),
|
Width = Application.GetRealWidth (95),
|
UnSelectedImagePath = "Item/Back.png",
|
SelectedImagePath = "Item/BackSelected.png",
|
Gravity = Gravity.CenterVertical,
|
};
|
topView.AddChidren (back);
|
back.MouseUpEventHandler += (sender, e) => {
|
Close ();
|
curView = null;
|
};
|
|
var btnl = new Button () {
|
Height = 1,
|
BackgroundColor = 0xFF2f2f2f,
|
Y = topView.Height - 1
|
};
|
topView.AddChidren (btnl);
|
#endregion
|
|
FrameLayout bordorView = new FrameLayout () {
|
Width = Application.GetRealWidth (480),
|
Height = Application.GetRealHeight (Application.DesignHeight - 150),
|
Y = Application.GetRealHeight (150),
|
BackgroundColor = 0xFF2f2f2f
|
};
|
AddChidren (bordorView);
|
|
|
#region 全开-全关
|
var powerView = new FrameLayout () {
|
Height = Application.GetRealHeight (110),
|
BackgroundColor = SkinStyle.Current.MainColor,
|
};
|
bordorView.AddChidren (powerView);
|
var btnAllON = new Button () {
|
Width = Application.GetRealWidth (240),
|
TextSize = 16,
|
TextID = R.MyInternationalizationString.ALLON,
|
SelectedTextColor = SkinStyle.Current.SelectedColor,
|
TextColor = SkinStyle.Current.TextColor1,
|
};
|
powerView.AddChidren (btnAllON);
|
var btnAllOff = new Button () {
|
Width = Application.GetRealWidth (240),
|
X = btnAllON.Right,
|
TextSize = 16,
|
TextID = R.MyInternationalizationString.ALLOFF,
|
SelectedTextColor = SkinStyle.Current.SelectedColor,
|
TextColor = SkinStyle.Current.TextColor1,
|
};
|
var btnLine = new Button () {
|
Width = 1,
|
BackgroundColor = 0xFF2f2f2f,
|
X = btnAllON.Right,
|
};
|
powerView.AddChidren (btnLine);
|
var btnLine1 = new Button () {
|
Height = 1,
|
Y = powerView.Height - 1,
|
BackgroundColor = 0xFF2f2f2f,
|
};
|
powerView.AddChidren (btnLine1);
|
btnAllON.MouseUpEventHandler += (sender, e) => {
|
btnAllON.TextColor = SkinStyle.Current.SelectedColor;
|
btnAllOff.TextColor = SkinStyle.Current.TextColor1;
|
controlAllFH (1);
|
};
|
powerView.AddChidren (btnAllOff);
|
btnAllOff.MouseUpEventHandler += (sender, e) => {
|
btnAllON.TextColor = SkinStyle.Current.TextColor1;
|
btnAllOff.TextColor = SkinStyle.Current.SelectedColor;
|
controlAllFH (0);
|
};
|
#endregion
|
|
|
RoomListScrolView = new VerticalScrolViewLayout () {
|
Width = LayoutParams.MatchParent,
|
Height = Application.GetRealHeight (Application.DesignHeight - 300 - 140),
|
Y = powerView.Bottom,
|
};
|
bordorView.AddChidren (RoomListScrolView);
|
|
|
bodyScrolView = new FrameLayout () {
|
Width = LayoutParams.MatchParent,
|
Height = Application.GetRealHeight (Application.DesignHeight - 126),
|
Y = powerView.Bottom,
|
};
|
bordorView.AddChidren (bodyScrolView);
|
|
#region 显示全部的地热
|
//显示所有
|
int devcieCount = 0;
|
foreach (var room in Room.Lists) {
|
if (room.Name == "") {
|
continue;
|
}
|
foreach (var common in room.DeviceList.FindAll ((obj) => { return obj.Type == DeviceType.FoolHeat || obj.Type == DeviceType.FoolHeatPanel; })) {
|
var roomFH = common as FoolHeat;
|
|
EventHandler<MouseEventArgs> openFHControlPageEvent = (button, mouseEventArgs) => {
|
for (int i = 0; i < RoomListScrolView.ChildrenCount; i++) {
|
var view = RoomListScrolView.GetChildren (i);
|
if (view.Tag == roomFH) {
|
for (int j = 0; j < (view as FrameLayout).ChildrenCount; j++) {
|
var btn = (view as FrameLayout).GetChildren (j);
|
(btn as Button).IsSelected = true;
|
}
|
} else {
|
for (int j = 0; j < (view as FrameLayout).ChildrenCount; j++) {
|
var btn = (view as FrameLayout).GetChildren (j);
|
(btn as Button).IsSelected = false;
|
}
|
}
|
}
|
if (ControlBodyView != null) {
|
ControlBodyView.RemoveFromParent ();
|
}
|
ControlBodyView = new UserFHPage (roomFH, room) {
|
Width = Application.GetRealWidth (Application.DesignWidth) - bordorView.Width,
|
Height = Application.GetRealHeight (Application.DesignHeight - 150),
|
X = bordorView.Right,
|
Y = Application.GetRealHeight (150),
|
BackgroundColor = SkinStyle.Current.MainColor
|
};
|
AddChidren (ControlBodyView);
|
ControlBodyView.showRoomFH ();
|
};
|
|
|
FrameLayout fhView = new FrameLayout () {
|
Height = Application.GetRealHeight (140),
|
Tag = roomFH
|
};
|
fhView.Tag = roomFH.CommonLoopID;
|
RoomListScrolView.AddChidren (fhView);
|
|
var tempDeviceName = new Button () {
|
Padding = new Padding (0, 35, 0, 0),
|
Text = room.Name + " - " + common.Name,
|
Height = Application.GetRealHeight (140),
|
TextAlignment = TextAlignment.CenterLeft,
|
SelectedTextColor = SkinStyle.Current.SelectedColor,
|
TextColor = SkinStyle.Current.TextColor1,
|
BackgroundColor = SkinStyle.Current.Transparent,
|
SelectedBackgroundColor = SkinStyle.Current.MainColor
|
};
|
fhView.AddChidren (tempDeviceName);
|
tempDeviceName.MouseUpEventHandler += openFHControlPageEvent;
|
Button btnPoint = new Button () {
|
Width = Application.GetRealWidth (15),
|
Height = Application.GetRealHeight (15),
|
X = Application.GetRealWidth (45),
|
Gravity = Gravity.CenterVertical,
|
UnSelectedImagePath = "Item/Point.png",
|
SelectedImagePath = "Item/PointSelected.png",
|
};
|
fhView.AddChidren (btnPoint);
|
Button btnSelected = new Button () {
|
X = fhView.Width - 5,
|
Width = 5,
|
SelectedBackgroundColor = SkinStyle.Current.SelectedColor,
|
BackgroundColor = SkinStyle.Current.Transparent,
|
};
|
fhView.AddChidren (btnSelected);
|
if (devcieCount == 0) {
|
ControlBodyView = new UserFHPage (roomFH, room) {
|
Width = Application.GetRealWidth (Application.DesignWidth) - bordorView.Width,
|
Height = Application.GetRealHeight (Application.DesignHeight - 150),
|
X = bordorView.Right,
|
Y = Application.GetRealHeight (150),
|
BackgroundColor = SkinStyle.Current.MainColor
|
};
|
AddChidren (ControlBodyView);
|
ControlBodyView.showRoomFH ();
|
tempDeviceName.IsSelected = true;
|
btnPoint.IsSelected = true;
|
}
|
devcieCount++;
|
}
|
}
|
#endregion
|
}
|
|
/// <summary>
|
/// 控制所有地热
|
/// </summary>
|
/// <param name="b">The blue component.</param>
|
void controlAllFH (byte b)
|
{
|
System.Threading.Tasks.Task.Run (() => {
|
foreach (var room in Room.Lists) {
|
if (room == null)
|
continue;
|
if (room.Name == "") {
|
continue;
|
}
|
var list = room.DeviceList.FindAll ((obj) => {
|
return obj.Type == DeviceType.FoolHeat || obj.Type == DeviceType.FoolHeatPanel;
|
});
|
foreach (var common in list) {
|
(common as FoolHeat).Status = b;
|
|
var fh = common as FoolHeat;
|
|
if (fh.Type == DeviceType.FoolHeatPanel) {
|
Control.ControlBytesSend (Command.InstructionPanelKey, fh.SubnetID, fh.DeviceID, new byte [] { 20, fh.Status, fh.LoopID });
|
} else if (fh.Type == DeviceType.FoolHeat) {
|
fh = fh.Serverx_FH_CMD (FoolHeat.CommandType.Switch);
|
}
|
}
|
}
|
});
|
}
|
|
/// <summary>
|
/// 显示当前多少是开的
|
/// </summary>
|
void updateFHOnCount ()
|
{
|
Application.RunOnMainThread (() => {
|
for (int i = 0; i < curView.bodyScrolView.ChildrenCount; i++) {
|
if (curView.bodyScrolView.GetChildren (i).GetType () == typeof (RowLayout)) {
|
var roomRow = (RowLayout)curView.bodyScrolView.GetChildren (i);
|
if (roomRow.Tag != null) {
|
foreach (var room in Room.Lists) {
|
if (room.Name == "") {
|
continue;
|
}
|
if (roomRow.Tag.ToString () == room.Name) {
|
int oCount = 0;
|
foreach (var common in room.DeviceList) {
|
if (common.Type == DeviceType.FoolHeat) {
|
if ((common as FoolHeat).Status > 0) {
|
oCount++;
|
}
|
} else if (common.Type == DeviceType.FoolHeatPanel) {
|
if ((common as FoolHeatPanel).Status > 0) {
|
oCount++;
|
}
|
}
|
}
|
|
for (int j = 0; j < roomRow.ChildrenCount; j++) {
|
if (roomRow.GetChildren (j).GetType () == typeof (EditText)) {
|
var et = (EditText)roomRow.GetChildren (j);
|
et.Text = oCount.ToString ();
|
}
|
if (roomRow.GetChildren (j).GetType () == typeof (Button)) {
|
var btn = (Button)roomRow.GetChildren (j);
|
if (oCount > 0) {
|
btn.IsSelected = true;
|
} else {
|
btn.IsSelected = false;
|
}
|
}
|
}
|
}
|
}
|
}
|
}
|
}
|
});
|
}
|
|
/// <summary>
|
/// 读取设备状态
|
/// </summary>
|
void readAllStatus ()
|
{
|
System.Threading.Tasks.Task.Run (() => {
|
System.Collections.Generic.List<string> readList = new System.Collections.Generic.List<string> ();
|
foreach (Room room in Room.Lists) {
|
var list = room.DeviceList.FindAll ((obj) => {
|
return obj.LastUpdateTime.AddMinutes (Common.Time) <= DateTime.Now && (obj.Type == DeviceType.FoolHeat || obj.Type == DeviceType.FoolHeatPanel);
|
});
|
foreach (Common common in list) {
|
var s = common.Type + "_" + common.SubnetID + "_" + common.DeviceID + "_" + common.LoopID;
|
//已经读取过当前设备就不再读取
|
if (readList.Contains (s)) {
|
continue;
|
}
|
|
readList.Add (s);
|
|
var fh = common as FoolHeat;
|
|
if (fh.Type == DeviceType.FoolHeatPanel) {
|
Control.ControlBytesSend (Command.ReadInstructionPanelKey, fh.SubnetID, fh.DeviceID, new byte [] { 20, fh.LoopID, fh.LoopID });
|
Control.ControlBytesSend (Command.ReadInstructionPanelKey, fh.SubnetID, fh.DeviceID, new byte [] { 21, fh.LoopID, fh.LoopID });
|
Control.ControlBytesSend (Command.ReadInstructionPanelKey, fh.SubnetID, fh.DeviceID, new byte [] { 24, fh.LoopID, fh.LoopID });
|
Control.ControlBytesSend (Command.ReadInstructionPanelKey, fh.SubnetID, fh.DeviceID, new byte [] { 25, fh.LoopID, fh.LoopID });
|
Control.ControlBytesSend (Command.ReadInstructionPanelKey, fh.SubnetID, fh.DeviceID, new byte [] { 26, fh.LoopID, fh.LoopID });
|
Control.ControlBytesSend (Command.ReadInstructionPanelKey, fh.SubnetID, fh.DeviceID, new byte [] { 27, fh.LoopID, fh.LoopID });
|
Control.ControlBytesSend (Command.ReadInstructionPanelKey, fh.SubnetID, fh.DeviceID, new byte [] { 28, fh.LoopID, fh.LoopID });
|
} else if (fh.Type == DeviceType.FoolHeat) {
|
fh = fh.Serverx_FH_CMD (FoolHeat.CommandType.Read);
|
}
|
}
|
}
|
});
|
}
|
|
}
|
}
|