using Shared.SimpleControl.Phone;
using System;
///
/// 系统后台配置空调模块的页面类
///
namespace Shared.SimpleControl.Pad
{
public class SystemACHost
{
public EquipmentPublicClass epc;
public SystemACHostMethod acM;
public SystemACHost ()
{
epc = new EquipmentPublicClass ();
acM = new SystemACHostMethod ();
}
///
/// 显示HVAC空调界面
///
/// The ACH ost.
/// Ac host.
/// Ac host device.
public void ShowACHost (HVAC acHost, Common deviceBase)
{
SystemMiddle.ThirdScrolView.RemoveAll ();
#region top
EditText textButton = new EditText () {
X = Application.GetRealWidth (40),
Height = Application.GetRealHeight (50),
Width = Application.GetRealWidth (400),
Text = acHost.Name,
Gravity = Gravity.CenterVertical,
TextAlignment = TextAlignment.CenterLeft,
SelectedBackgroundColor = 0xFF000000,
Enable = false,
TextSize = 15,
};
SystemMiddle.ThirdScrolView.TitleView.AddChidren (textButton);
Button editor = new Button () {
Height = Application.GetRealHeight (90),
Width = Application.GetRealWidth (70),
UnSelectedImagePath = "Item/Editor.png",
SelectedImagePath = "Item/EditorSelected.png",
Gravity = Gravity.CenterVertical,
X = Application.GetRealWidth (550)
};
SystemMiddle.ThirdScrolView.TitleView.AddChidren (editor);
editor.MouseUpEventHandler += (sender, e) => {
if (editor.IsSelected) {
MainPage.Loading.Start ();
editor.IsSelected = textButton.IsSelected = textButton.Enable = false;
acHost.Name = textButton.Text.Trim ();
byte [] remakeBytes = CommonPage.MyEncodingGB2312.GetBytes (textButton.Text.Trim ());
System.Threading.Tasks.Task.Run (() => {
byte [] updateBytes = Control.ControlBytesSendHasReturn (Command.ReadDeviceLoopInfo, acHost.SubnetID, acHost.DeviceID, new byte [] {
acHost.BigClass,acHost.MinClass,acHost.LoopID
});
if (updateBytes == null) {
Application.RunOnMainThread (() => {
new Alert (Language.StringByID (R.MyInternationalizationString.Tip), Language.StringByID (R.MyInternationalizationString.TipEquipmentNotOnline), Language.StringByID (R.MyInternationalizationString.Close)).Show ();
MainPage.Loading.Hide ();
});
return;
}
byte [] uBytes = new byte [20];
Array.Copy (remakeBytes, 0, uBytes, 0, remakeBytes.Length < 20 ? remakeBytes.Length : 20);
Array.Copy (uBytes, 0, updateBytes, 3, 20 < uBytes.Length ? 20 : uBytes.Length);
var reBytes = Control.ControlBytesSendHasReturn (Command.SetDeviceLoopInfo, acHost.SubnetID, acHost.DeviceID, updateBytes);
if (reBytes != null) {
Application.RunOnMainThread (() => {
acHost.Name = textButton.Text.Trim ();
IO.FileUtils.SaveEquipmentMessage (acHost, acHost.LoopID.ToString ());
MainPage.Loading.Hide ();
});
} else {
Application.RunOnMainThread (() => {
new Alert (Language.StringByID (R.MyInternationalizationString.Tip), Language.StringByID (R.MyInternationalizationString.TipEquipmentNotOnline), Language.StringByID (R.MyInternationalizationString.Close)).Show ();
MainPage.Loading.Hide ();
});
}
});
} else {
textButton.Enable = textButton.IsSelected = editor.IsSelected = true;
}
};
#endregion
#region MyRegion
byte [] acHostBytes = new byte [13];
FrameLayout frameLayoutBody = new FrameLayout () {
Height = Application.GetRealHeight (700),
Width = LayoutParams.MatchParent,
};
SystemMiddle.ThirdScrolView.AddChidren (frameLayoutBody);
Button btnSetTemperature = new Button () {
Width = Application.GetRealHeight (450),
Height = Application.GetRealHeight (45),
X = Application.GetRealWidth (40),
Y = Application.GetRealHeight (60),
TextID = R.MyInternationalizationString.SetTemperature,
TextAlignment = TextAlignment.CenterLeft,
Enable = false,
};
frameLayoutBody.AddChidren (btnSetTemperature);
byte temperature = 16;
btnSetTemperature.Text = Language.StringByID (R.MyInternationalizationString.SetTemperature).Replace ("--", (temperature).ToString ());
Button btnReduceTemperature = new Button () {
Width = Application.GetMinRealAverage (94),
Height = Application.GetMinRealAverage (94),
X = Application.GetRealWidth (80),
Y = btnSetTemperature.Bottom + Application.GetRealHeight (60),
UnSelectedImagePath = "AC/AC-.png",
SelectedImagePath = "AC/AC-Selected.png",
};
frameLayoutBody.AddChidren (btnReduceTemperature);
btnReduceTemperature.MouseDownEventHandler += (sender, e) => {
btnReduceTemperature.IsSelected = true;
};
btnReduceTemperature.MouseUpEventHandler += (sender, e) => {
btnReduceTemperature.IsSelected = false;
if (temperature > 16 && acHostBytes [9] != 2) {
btnSetTemperature.Text = Language.StringByID (R.MyInternationalizationString.SetTemperature).Replace ("--", (--temperature).ToString ());
acM.UpdataACTemperature (acHost.SubnetID, acHost.DeviceID, acHostBytes, temperature);
}
};
Button btnSwitchAC = new Button () {
Width = Application.GetMinRealAverage (94),
Height = Application.GetMinRealAverage (94),
X = Application.GetRealWidth ((640 - 94) / 2),
Y = btnReduceTemperature.Y,
UnSelectedImagePath = "AC/ACClose.png",
SelectedImagePath = "AC/ACCloseSelected.png",
};
frameLayoutBody.AddChidren (btnSwitchAC);
btnSwitchAC.MouseUpEventHandler += (sender, e) => {
if (acHostBytes == null) {
return;
}
if (acHostBytes [8] == 0) {
acHostBytes [8] = 1;
btnSwitchAC.IsSelected = true;
} else {
acHostBytes [8] = 0;
btnSwitchAC.IsSelected = false;
}
acM.UpdataACHost (acHost.SubnetID, acHost.DeviceID, acHostBytes, btnSwitchAC);
};
Button btnAddTemperature = new Button () {
Width = Application.GetMinRealAverage (94),
Height = Application.GetMinRealAverage (94),
X = Application.GetRealWidth (640 - 80 - 94),
Y = btnReduceTemperature.Y,
UnSelectedImagePath = "AC/AC+.png",
SelectedImagePath = "AC/AC+Selected.png",
};
frameLayoutBody.AddChidren (btnAddTemperature);
btnAddTemperature.MouseDownEventHandler += (sender, e) => {
btnAddTemperature.IsSelected = true;
};
btnAddTemperature.MouseUpEventHandler += (sender, e) => {
btnAddTemperature.IsSelected = false;
btnReduceTemperature.IsSelected = false;
if (temperature < 30 && acHostBytes [9] != 2) {
btnSetTemperature.Text = Language.StringByID (R.MyInternationalizationString.SetTemperature).Replace ("--", (++temperature).ToString ());
acM.UpdataACTemperature (acHost.SubnetID, acHost.DeviceID, acHostBytes, temperature);
}
};
#region ModeView
FrameLayout acModeView = new FrameLayout () {
Height = Application.GetRealHeight (97),
Width = LayoutParams.MatchParent,
//BackgroundImagePath = "Item/BottomLine.png",
Y = btnReduceTemperature.Bottom + Application.GetRealHeight (30),
};
frameLayoutBody.AddChidren (acModeView);
Button btnACModeLeft = new Button () {
Width = Application.GetMinRealAverage (129),
Height = Application.GetMinRealAverage (129),
X = btnReduceTemperature.X - Application.GetRealWidth (17),
Gravity = Gravity.CenterVertical,
UnSelectedImagePath = "AC/ACLeft.png",
SelectedImagePath = "AC/ACLeft.png",
};
acModeView.AddChidren (btnACModeLeft);
Button btnModeIcon = new Button () {
Width = Application.GetMinRealAverage (94),
Height = Application.GetMinRealAverage (94),
Gravity = Gravity.Center,
UnSelectedImagePath = "AC/ACRefrigeration.png",
Enable = false,
};
acModeView.AddChidren (btnModeIcon);
Button btnACModeRight = new Button () {
Width = Application.GetMinRealAverage (129),
Height = Application.GetMinRealAverage (129),
X = btnAddTemperature.X - Application.GetRealWidth (17),
Gravity = Gravity.CenterVertical,
UnSelectedImagePath = "AC/ACRight.png",
SelectedImagePath = "AC/ACRightSelected.png",
};
acModeView.AddChidren (btnACModeRight);
btnACModeRight.MouseDownEventHandler += (sender, e) => {
btnACModeRight.IsSelected = true;
};
btnACModeRight.MouseUpEventHandler += (sender, e) => {
btnACModeRight.IsSelected = false;
if (++acHostBytes [9] > 4)
acHostBytes [9] = 0;
acM.UpdataACHost (acHost.SubnetID, acHost.DeviceID, acHostBytes, null);
acM.UpdataACHostModeIcon (acHostBytes [9], btnModeIcon);
//temperature = acM.SetACTemperatureText(acHostBytes,btnSetTemperature);
btnSetTemperature.Text = Language.StringByID (R.MyInternationalizationString.SetTemperature).Replace ("--", (temperature).ToString ());
};
btnACModeLeft.MouseDownEventHandler += (sender, e) => {
btnACModeLeft.IsSelected = true;
};
btnACModeLeft.MouseUpEventHandler += (sender, e) => {
btnACModeLeft.IsSelected = false;
try {
acHostBytes [9]--;
if (acHostBytes [9] < 0)
acHostBytes [9] = 4;
} catch {
acHostBytes [9] = 4;
}
acM.UpdataACHost (acHost.SubnetID, acHost.DeviceID, acHostBytes, null);
acM.UpdataACHostModeIcon (acHostBytes [9], btnModeIcon);
//temperature = acM.SetACTemperatureText(acHostBytes,btnSetTemperature);
btnSetTemperature.Text = Language.StringByID (R.MyInternationalizationString.SetTemperature).Replace ("--", (temperature).ToString ());
};
#endregion
#region WindView
FrameLayout acWindView = new FrameLayout () {
Height = Application.GetRealHeight (97),
Width = LayoutParams.MatchParent,
Y = acModeView.Bottom + Application.GetRealHeight (35),
//BackgroundImagePath = "Item/BottomLine.png",
};
frameLayoutBody.AddChidren (acWindView);
Button btnACWindLeft = new Button () {
Width = Application.GetMinRealAverage (129),
Height = Application.GetMinRealAverage (129),
X = btnReduceTemperature.X - Application.GetRealWidth (17),
Gravity = Gravity.CenterVertical,
UnSelectedImagePath = "AC/ACLeft.png",
SelectedImagePath = "AC/ACLeft.png",
};
acWindView.AddChidren (btnACWindLeft);
Button btnWindIcon = new Button () {
Width = Application.GetMinRealAverage (94),
Height = Application.GetMinRealAverage (94),
Gravity = Gravity.Center,
UnSelectedImagePath = "AC/ ACAuto.png",
Enable = false,
};
acWindView.AddChidren (btnWindIcon);
Button btnACWindRight = new Button () {
Width = Application.GetMinRealAverage (129),
Height = Application.GetMinRealAverage (129),
X = btnAddTemperature.X - Application.GetRealWidth (17),
Gravity = Gravity.CenterVertical,
UnSelectedImagePath = "AC/ACRight.png",
SelectedImagePath = "AC/ACRightSelected.png",
};
acWindView.AddChidren (btnACWindRight);
btnACWindLeft.MouseDownEventHandler += (sender, e) => {
btnACWindLeft.IsSelected = true;
};
btnACWindLeft.MouseUpEventHandler += (sender, e) => {
btnACWindLeft.IsSelected = false;
try {
acHostBytes [10]--;
if (acHostBytes [10] < 0) {
acHostBytes [10] = 3;
}
} catch {
acHostBytes [10] = 3;
}
acM.UpdataACHost (acHost.SubnetID, acHost.DeviceID, acHostBytes, null);
acM.UpdataACHostWindIcon (acHostBytes [10], btnWindIcon);
};
btnACWindRight.MouseDownEventHandler += (sender, e) => {
btnACWindRight.IsSelected = true;
};
btnACWindRight.MouseUpEventHandler += (sender, e) => {
btnACWindRight.IsSelected = false;
if (++acHostBytes [10] > 3)
acHostBytes [10] = 0;
acM.UpdataACHost (acHost.SubnetID, acHost.DeviceID, acHostBytes, null);
acM.UpdataACHostWindIcon (acHostBytes [10], btnWindIcon);
};
#endregion
#region ----加载完界面之后读取数据刷新界面----
System.Threading.Tasks.Task.Run (() => {
acHostBytes = Control.ControlBytesSendHasReturn (Command.ReadACMode, acHost.SubnetID, acHost.DeviceID, new byte [] { acHost.LoopID });
if (acHostBytes == null) {
Application.RunOnMainThread (() => {
epc.AlertNotOnline ();
});
} else {
Application.RunOnMainThread (() => {
temperature = acM.SetACTemperatureText (acHostBytes, btnSetTemperature);
btnSetTemperature.Text = Language.StringByID (R.MyInternationalizationString.SetTemperature).Replace ("--", (temperature).ToString ());
if (acHostBytes [8] == 1) {
btnSwitchAC.IsSelected = true;
} else {
btnSwitchAC.IsSelected = false;
}
// mode Icon
acM.UpdataACHostModeIcon (acHostBytes [9], btnModeIcon);
// wind Icon
acM.UpdataACHostWindIcon (acHostBytes [10], btnWindIcon);
});
}
});
#endregion
#endregion
}
}
}