using System;
using System.Collections.Generic;
using HDL_ON.DriverLayer;
using HDL_ON.Entity;
using HDL_ON.Stan;
using HDL_ON.UI.CSS;
using Shared;
namespace HDL_ON.UI
{
///
/// 机械手控制页面
///
public class MechanicalArmPage : DeviceFunctionCardCommonForm
{
#region ■ 变量声明___________________________
///
/// 图片控件
///
private PicViewControl btnPictrue = null;
///
/// 开关状态提示控件
///
private Button btnTipStatus = null;
///
/// 开关控件
///
private IconViewControl btnSwitch = null;
#endregion
#region ■ 初始化_____________________________
///
/// 初始化白色区域的内容
///
public override void InitFrameWhiteContent()
{
base.SetTitleText(Language.StringByID(StringId.WaterValve));
//初始化第一个索引页的内容
this.InitFrameWhiteContent1();
//刷新界面状态
this.RefreshFormStatu();
//读取状态
new System.Threading.Thread(() =>
{
Control.Ins.ReadFunctionsInfo(new List() { device.deviceId });
})
{ IsBackground = true }.Start();
}
///
/// 初始化第一个索引页的内容
///
private void InitFrameWhiteContent1()
{
btnTipStatus = new Button()
{
Gravity = Gravity.CenterHorizontal,
Y = Application.GetRealHeight(79),
Width = Application.GetRealWidth(100),
Height = Application.GetRealHeight(34),
BackgroundColor = 0x171B2D4D,
TextColor = CSS_Color.FirstLevelTitleColor,
Radius = (uint)Application.GetRealHeight(17),
TextID = StringId.ValveClosed,
};
FrameWhiteCentet1.AddChidren(btnTipStatus);
//图片控件
this.btnPictrue = new PicViewControl(327, 327);
btnPictrue.Y = Application.GetRealHeight(127);
btnPictrue.Gravity = Gravity.CenterHorizontal;
btnPictrue.UnSelectedImagePath = "FunctionIcon/Electrical/MechanicalArm/MechanicalArmBg.png";
btnPictrue.SelectedImagePath = "FunctionIcon/Electrical/MechanicalArm/MechanicalArmOnBg.png";
FrameWhiteCentet1.AddChidren(btnPictrue);
btnPictrue.ButtonClickEvent += (sender, e) =>
{
//发送开关命令
this.SendSwitchComand();
};
//开关图标
this.btnSwitch = new IconViewControl(40);
btnSwitch.Gravity = Gravity.CenterHorizontal;
btnSwitch.Y = Application.GetRealHeight(468);
btnSwitch.UnSelectedImagePath = "Public/PowerClose.png";
btnSwitch.SelectedImagePath = "Public/PowerOpen.png";
FrameWhiteCentet1.AddChidren(btnSwitch);
btnSwitch.ButtonClickEvent += (sender, e) =>
{
//发送开关命令
this.SendSwitchComand();
};
var pack = new DAL.Server.HttpServerRequest().GetDeviceInfoList(new List() { base.device.deviceId });
}
#endregion
#region ■ 设备状态反馈_______________________
///
/// 设备状态反馈
///
///
public override void DeviceStatuPush(Function i_LocalDevice)
{
//不是同一个东西
if (this.device.sid != i_LocalDevice.sid) { return; }
//刷新界面状态
this.RefreshFormStatu();
}
#endregion
#region ■ 发送各种命令_______________________
///
/// 发送开关命令
///
private void SendSwitchComand()
{
//if (!device.online)
//{
// new Tip()
// {
// CloseTime = 1,
// Text = Language.StringByID(StringId.DeviceOfflineCannotOption),
// Direction = AMPopTipDirection.None,
// }.Show(MainPage.BaseView);
// return;
//}
string statu = this.btnSwitch.IsSelected == true ? "off" : "on";
string tipMsg = "确定打开?";
if (this.btnSwitch.IsSelected)
{
tipMsg = "确定关闭?";
}
if (Language.CurrentLanguage != "Chinese")
{
tipMsg = "Are you sure to close?";
if (this.btnSwitch.IsSelected)
tipMsg = "Are you sure to open it?";
}
Action action = () => {
this.btnPictrue.CanClick = false;
this.btnSwitch.CanClick = false;
HdlThreadLogic.Current.RunThread(() =>
{
var dic = new Dictionary();
dic.Add(FunctionAttributeKey.OnOff, statu);
Control.Ins.SendWriteCommand(this.device, dic, true);
HdlThreadLogic.Current.RunMain(() =>
{
this.btnPictrue.CanClick = true;
this.btnSwitch.CanClick = true;
});
});
};
new PublicAssmebly().TipOptionMsg(StringId.Tip, tipMsg, action);
}
#endregion
#region ■ 刷新界面状态_______________________
///
/// 刷新界面状态
///
private void RefreshFormStatu()
{
Application.RunOnMainThread(() =>
{
var onoffStatu = device.attributes.Find((obj) => obj.key == FunctionAttributeKey.OnOff);
if (onoffStatu != null)
{
if (onoffStatu.state == "on")
{
btnTipStatus.TextID = StringId.ValveOpened;
btnTipStatus.TextColor = 0xFF4BC803;
btnTipStatus.BackgroundColor = 0x174BC803;
}
else
{
btnTipStatus.TextID = StringId.ValveClosed;
btnTipStatus.TextColor = CSS_Color.FirstLevelTitleColor;
btnTipStatus.BackgroundColor = 0x171B2D4D;
}
this.btnSwitch.IsSelected = this.btnPictrue.IsSelected = onoffStatu.state.ToString() == "on";
}
});
}
#endregion
}
}