using System;
|
|
namespace Shared.SimpleControl.Phone
|
{
|
/// <summary>
|
/// 窗帘模块
|
/// </summary>
|
public class SystemCurtainModel : FrameLayout
|
{
|
Button btnOpenCurtain;
|
Button btnStopCurtain;
|
Button btnCloseCurtain;
|
byte cmLoopID;
|
|
/// <summary>
|
/// 显示窗帘模块界面
|
/// </summary>
|
/// <returns>The curtain model show.</returns>
|
/// <param name="curtainModel">Curtain model.</param>
|
/// <param name="curtainDevice">Curtain device.</param>
|
public void SystemCurtainModelShow(CurtainModel curtainModel,Common curtainDevice)
|
{
|
|
#region top
|
FrameLayout frameLayout = new FrameLayout () {
|
Height = Application.GetRealHeight (100),
|
Width = LayoutParams.MatchParent,
|
BackgroundColor = SkinStyle.Current.MainColor,
|
};
|
AddChidren (frameLayout);
|
|
Button backButton = new Button () {
|
X = Application.GetRealWidth (0),
|
Height = Application.GetRealHeight (90),
|
Width = Application.GetRealWidth (85),
|
UnSelectedImagePath = "Item/Back.png",
|
SelectedImagePath = "Item/BackSelected.png",
|
Gravity = Gravity.CenterVertical,
|
};
|
backButton.MouseUpEventHandler+= (sender, e) => {
|
(Parent as PageLayout).PageIndex -= 1;
|
//SystemEquipmentBase.RefreshView(curtainDevice);
|
//SystemMiddle.VerticalScrolViewMiddle.Animate = Animate.RightToLeft;
|
};
|
frameLayout.AddChidren (backButton);
|
|
EditText textButton = new EditText () {
|
X = Application.GetRealWidth (20) + backButton.Right,
|
Height = Application.GetRealHeight (50),
|
Width = Application.GetRealWidth (400),
|
Text = curtainModel.Name,
|
Gravity = Gravity.CenterVertical,
|
TextAlignment = TextAlignment.CenterLeft,
|
BackgroundColor = SkinStyle.Current.Transparent,
|
SelectedBackgroundColor = SkinStyle.Current.SysEditBox,
|
Enable = false,
|
TextColor = SkinStyle.Current.TextColor1
|
};
|
frameLayout.AddChidren (textButton);
|
|
Button editor = new Button () {
|
X = Application.GetRealWidth (520),
|
Height = Application.GetRealHeight (90),
|
Width = Application.GetRealWidth (70),
|
UnSelectedImagePath = "Item/Editor.png",
|
SelectedImagePath="Item/EditorSelected.png",
|
Gravity = Gravity.CenterVertical,
|
};
|
if (curtainDevice.isMixBox == false)
|
frameLayout.AddChidren (editor);
|
editor.MouseUpEventHandler += (sender, e) => {
|
if (editor.IsSelected) {
|
MainPage.Loading.Start ();
|
editor.IsSelected = textButton.IsSelected = textButton.Enable = false;
|
byte [] remakeBytes = CommonPage.MyEncodingGB2312.GetBytes (textButton.Text.Trim ());
|
System.Threading.Tasks.Task.Run (() => {
|
byte [] updateBytes = Control.ControlBytesSendHasReturn (Command.ReadDeviceLoopInfo, curtainModel.SubnetID, curtainModel.DeviceID, new byte [] {
|
curtainModel.BigClass,curtainModel.MinClass,curtainModel.LoopID
|
});
|
if (updateBytes == null) {
|
Application.RunOnMainThread (() => {
|
new Alert ("", 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, curtainModel.SubnetID, curtainModel.DeviceID, updateBytes);
|
if (reBytes != null) {
|
Application.RunOnMainThread (() => {
|
curtainModel.Name = textButton.Text.Trim ();
|
IO.FileUtils.SaveEquipmentMessage (curtainModel, curtainModel.LoopID.ToString ());
|
MainPage.Loading.Hide ();
|
});
|
} else {
|
Application.RunOnMainThread (() => {
|
new Alert ("", Language.StringByID (R.MyInternationalizationString.TipEquipmentNotOnline), Language.StringByID (R.MyInternationalizationString.Close)).Show ();
|
MainPage.Loading.Hide ();
|
});
|
}
|
});
|
} else {
|
textButton.Enable = textButton.IsSelected = editor.IsSelected = true;
|
}
|
};
|
#endregion
|
Control.ControlBytesSend (Command.ReadCurtainStatus, curtainModel.SubnetID, curtainModel.DeviceID, new byte [] {curtainModel.LoopID });
|
#region MyRegion
|
FrameLayout frameLayoutBody = new FrameLayout () {
|
Height = Application.GetRealHeight (700),
|
Width = LayoutParams.MatchParent,
|
Y = Application.GetRealHeight (100),
|
};
|
AddChidren (frameLayoutBody);
|
|
Button btnRuntimeText = new Button () {
|
Width = Application.GetRealHeight (200),
|
Height = Application.GetRealHeight (50),
|
X = textButton.X,
|
Y = Application.GetRealHeight (40),
|
TextID = R.MyInternationalizationString.CurtainRunTime,
|
TextAlignment = TextAlignment.CenterLeft,
|
Enable = false,
|
TextColor = SkinStyle.Current.TextColor1,
|
};
|
frameLayoutBody.AddChidren (btnRuntimeText);
|
EditText etMaxout = new EditText () {
|
X = btnRuntimeText.Right,
|
Y = btnRuntimeText.Y,
|
Width = Application.GetRealWidth (160),
|
Height = btnRuntimeText.Height - Application.GetRealHeight (2),
|
Text = (curtainModel.RunTime / 10).ToString (),
|
TextAlignment = TextAlignment.CenterLeft,
|
TextColor = SkinStyle.Current.TextColor1,
|
};
|
frameLayoutBody.AddChidren (etMaxout);
|
Button btnLine = new Button () {
|
Height = Application.GetRealHeight (2),
|
Width = etMaxout.Width,
|
BackgroundColor = SkinStyle.Current.ViewColor,
|
X = btnRuntimeText.Right,
|
Y = etMaxout.Bottom,
|
};
|
frameLayoutBody.AddChidren (btnLine);
|
|
Button btnSaveTheRunTime = new Button () {
|
X = etMaxout.Right + Application.GetRealWidth (10),
|
Y = etMaxout.Y - Application.GetRealHeight(20),
|
Height = Application.GetRealHeight (90),
|
Width = Application.GetRealWidth (70),
|
UnSelectedImagePath = "Item/Editor.png",
|
SelectedImagePath = "Item/EditorSelected.png",
|
};
|
frameLayoutBody.AddChidren(btnSaveTheRunTime);
|
int runTime = 2;
|
|
btnSaveTheRunTime.MouseUpEventHandler += (sender, e) => {
|
try{
|
if(int.TryParse(etMaxout.Text,out runTime))
|
{
|
runTime = runTime * 10;
|
if(runTime < 0 || runTime > 3600)
|
throw new Exception();
|
}
|
else
|
throw new Exception();
|
|
}catch
|
{
|
new Alert (Language.StringByID(R.MyInternationalizationString.Tip),Language.StringByID(R.MyInternationalizationString.PleaseEnterTheCorrectData) ,
|
Language.StringByID(R.MyInternationalizationString.Close)).Show();
|
return;
|
}
|
int i = 0;
|
while (i < 2) {
|
byte [] usefulBytes = Control.ControlBytesSendHasReturn (Command.UpdataCurtainModelRunTime, curtainModel.SubnetID,
|
curtainModel.DeviceID, new byte [] { (byte)(curtainModel.LoopID * 2-i), (byte)(runTime / 256), (byte)(runTime % 256) });
|
if (usefulBytes == null) {
|
Application.RunOnMainThread (() => {
|
new Alert ("", Language.StringByID (R.MyInternationalizationString.OperationFailed), Language.StringByID (R.MyInternationalizationString.Close)).Show ();
|
});
|
break;
|
} else if(i ==1) {
|
curtainModel.RunTime = runTime;
|
IO.FileUtils.SaveEquipmentMessage (curtainModel, curtainModel.LoopID.ToString ());
|
}
|
i++;
|
}
|
};
|
|
Button btnTestText = new Button () {
|
Width = Application.GetRealWidth (394),
|
Height = Application.GetRealHeight (64),
|
X = btnRuntimeText.X,
|
Y = btnSaveTheRunTime.Bottom + Application.GetRealHeight (60),
|
TextID = R.MyInternationalizationString.CurtainTest,
|
TextAlignment = TextAlignment.CenterLeft
|
};
|
frameLayoutBody.AddChidren (btnTestText);
|
|
btnOpenCurtain = new Button(){
|
Width = Application.GetMinRealAverage (124),
|
Height = Application.GetMinRealAverage (124),
|
X = Application.GetRealWidth(80),
|
Y = btnTestText.Bottom + Application.GetRealHeight(10),
|
UnSelectedImagePath = "Curtain/CurtainOpen.png",
|
SelectedImagePath = "Curtain/CurtainOpenSelected.png",
|
};
|
frameLayoutBody.AddChidren(btnOpenCurtain);
|
Button btnOpenLbl = new Button () {
|
Width = Application.GetMinRealAverage (124),
|
Height = Application.GetRealHeight (30),
|
X = btnOpenCurtain.X,
|
Y = btnOpenCurtain.Bottom + Application.GetRealHeight (5),
|
TextID = R.MyInternationalizationString.Open,
|
TextColor = SkinStyle.Current.TextColor1,
|
};
|
frameLayoutBody.AddChidren (btnOpenLbl);
|
|
btnStopCurtain = new Button(){
|
Width = Application.GetMinRealAverage (124),
|
Height = Application.GetMinRealAverage (124),
|
X = Application.GetRealWidth((640 - 124) / 2),
|
Y = btnOpenCurtain.Y,
|
UnSelectedImagePath = "Curtain/CurtainTimeOut.png",
|
SelectedImagePath = "Curtain/CurtainTimeOutSelected.png",
|
};
|
frameLayoutBody.AddChidren(btnStopCurtain);
|
|
btnCloseCurtain = new Button(){
|
Width = Application.GetMinRealAverage(124),
|
Height = Application.GetMinRealAverage(124),
|
X = Application.GetRealWidth(640 - 80 - 124),
|
Y = btnOpenCurtain.Y,
|
UnSelectedImagePath = "Curtain/CurtainClose.png",
|
SelectedImagePath = "Curtain/CurtainCloseSelected.png",
|
};
|
frameLayoutBody.AddChidren(btnCloseCurtain);
|
|
|
Button btnStopLbl = new Button () {
|
Width = Application.GetMinRealAverage (124),
|
Height = Application.GetRealHeight (30),
|
X = btnStopCurtain.X,
|
Y = btnOpenLbl.Y,
|
TextID = R.MyInternationalizationString.Stop,
|
TextColor = SkinStyle.Current.TextColor1,
|
};
|
frameLayoutBody.AddChidren (btnStopLbl);
|
|
Button btnCloseLbl = new Button () {
|
Width = Application.GetMinRealAverage (124),
|
Height = Application.GetRealHeight (30),
|
X = btnCloseCurtain.X,
|
Y = btnOpenLbl.Y,
|
TextID = R.MyInternationalizationString.Close2,
|
TextColor = SkinStyle.Current.TextColor1,
|
};
|
frameLayoutBody.AddChidren (btnCloseLbl);
|
|
btnOpenCurtain.MouseUpEventHandler += (sender, e) => {
|
btnOpenCurtain.IsSelected = true;
|
btnStopCurtain.IsSelected = false;
|
btnCloseCurtain.IsSelected = false;
|
ControlCurtain (curtainModel,1);
|
};
|
btnStopCurtain.MouseUpEventHandler += (sender, e) => {
|
btnStopCurtain.IsSelected = true;
|
btnCloseCurtain.IsSelected = false;
|
btnOpenCurtain.IsSelected = false;
|
ControlCurtain (curtainModel,0);
|
};
|
btnCloseCurtain.MouseUpEventHandler += (sender, e) => {
|
btnCloseCurtain.IsSelected = true;
|
btnStopCurtain.IsSelected = false;
|
btnOpenCurtain.IsSelected = false;
|
ControlCurtain (curtainModel,2);
|
};
|
if(curtainModel.Status == CurtainStatus.Close)
|
{
|
btnCloseCurtain.IsSelected = true;
|
}
|
else if(curtainModel.Status == CurtainStatus.Open)
|
{
|
btnOpenCurtain.IsSelected = true;
|
}
|
else if(curtainModel.Status == CurtainStatus.Stop)
|
{
|
btnStopCurtain.IsSelected = true;
|
}
|
#endregion
|
}
|
|
|
|
static void ControlCurtain (CurtainModel curtainModel,byte status)
|
{
|
System.Threading.Tasks.Task.Run (() => {
|
byte [] usefulBytes = Control.ControlBytesSendHasReturn (Command.UpdataCurtainModelStutas, curtainModel.SubnetID, curtainModel.DeviceID, new byte [] {
|
curtainModel.LoopID,
|
status
|
});
|
Application.RunOnMainThread (() => {
|
if (usefulBytes == null) {
|
Application.RunOnMainThread (() => {
|
new Alert ("", Language.StringByID (R.MyInternationalizationString.TipEquipmentNotOnline), Language.StringByID (R.MyInternationalizationString.Close)).Show ();
|
});
|
} else {
|
curtainModel.Status = (CurtainStatus)status;
|
//IO.FileUtils.SaveEquipmentMessage (curtainModel, curtainModel.LoopID.ToString ());
|
}
|
});
|
});
|
}
|
}
|
}
|