using System;
|
using System.Collections.Generic;
|
using System.Text;
|
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 AirFreshRelayControlPage : DeviceFunctionCardCommonForm
|
{
|
#region ■ 变量声明___________________________
|
/// <summary>
|
/// 风速图标控件
|
/// </summary>
|
private IconViewControl btnFan = null;
|
/// <summary>
|
/// 风速文本控件
|
/// </summary>
|
private NormalViewControl btnFanView = null;
|
/// <summary>
|
/// 开关图标
|
/// </summary>
|
private IconViewControl btnSwitch = null;
|
#endregion
|
|
#region ■ 初始化_____________________________
|
|
/// <summary>
|
/// 初始化白色区域的内容
|
/// </summary>
|
public override void InitFrameWhiteContent()
|
{
|
base.SetTitleText(Language.StringByID(StringId.AirFresh));
|
|
//刷新当前设备的状态缓存
|
this.RefreshNowDeviceStatuMemory(this.device);
|
//初始化第一个索引页的内容
|
this.InitFrameWhiteContent1();
|
|
Control.Ins.SendReadCommand(device);
|
}
|
|
/// <summary>
|
/// 初始化第一个索引页的内容
|
/// </summary>
|
private void InitFrameWhiteContent1()
|
{
|
//一个背景图片
|
var framePic = new FrameLayout();
|
framePic.Y = Application.GetRealHeight(87);
|
framePic.Width = this.GetPictrueRealSize(247);
|
framePic.Height = this.GetPictrueRealSize(247);
|
framePic.Gravity = Gravity.CenterHorizontal;
|
framePic.BackgroundImagePath = "FunctionIcon/AirFresh/AirFreshBgIcon.png";
|
this.FrameWhiteCentet1.AddChidren(framePic);
|
|
//风速图标
|
this.btnFan = new IconViewControl(28);
|
btnFan.Gravity = Gravity.CenterHorizontal;
|
btnFan.Y = Application.GetRealHeight(367);
|
this.FrameWhiteCentet1.AddChidren(btnFan);
|
List<string> fanSpeedList = new List<string>();
|
fanSpeedList = device.GetAttribute(FunctionAttributeKey.FanSpeed).value;
|
btnFan.MouseUpEventHandler += (sender, e) =>
|
{
|
ShowFanSelectView();
|
//return;
|
//if ( !btnSwitch.IsSelected){return;}
|
//var curFanSpeedIndex = fanSpeedList.IndexOf(device.GetAttrState(FunctionAttributeKey.FanSpeed));
|
//var sendFanSpeedIndex = curFanSpeedIndex == fanSpeedList.Count - 1 ? 0 : 1+curFanSpeedIndex;
|
|
//device.SetAttrState(FunctionAttributeKey.FanSpeed, fanSpeedList[sendFanSpeedIndex]);
|
//new System.Threading.Thread(() =>
|
//{
|
// Dictionary<string, string> d = new Dictionary<string, string>();
|
// d.Add(FunctionAttributeKey.FanSpeed, fanSpeedList[sendFanSpeedIndex]);
|
// Control.Ins.SendWriteCommand(device, d);
|
//})
|
//{ IsBackground = true }.Start();
|
//RefreshFanSpeed();
|
};
|
//风速文本
|
this.btnFanView = new NormalViewControl(this.FrameWhiteCentet1.Width / 3, Application.GetRealHeight(18), false);
|
btnFanView.Gravity = Gravity.CenterHorizontal;
|
btnFanView.Y = btnFan.Bottom + Application.GetRealHeight(6);
|
btnFanView.TextAlignment = TextAlignment.Center;
|
btnFanView.TextSize = CSS_FontSize.PromptFontSize_FirstLevel;
|
btnFanView.TextColor = CSS_Color.TextualColor;
|
this.FrameWhiteCentet1.AddChidren(btnFanView);
|
|
//开关图标
|
this.btnSwitch = new IconViewControl(32);
|
btnSwitch.Gravity = Gravity.CenterHorizontal;
|
btnSwitch.Y = Application.GetRealHeight(468);
|
btnSwitch.UnSelectedImagePath = "Public/PowerClose.png";
|
btnSwitch.SelectedImagePath = "Public/PowerOpen.png";
|
FrameWhiteCentet1.AddChidren(btnSwitch);
|
btnSwitch.MouseUpEventHandler = (sender, e) =>
|
{
|
btnSwitch.IsSelected = !btnSwitch.IsSelected;
|
device.trait_on_off.curValue = btnSwitch.IsSelected ? "on" : "off";
|
new System.Threading.Thread(() =>
|
{
|
Dictionary<string, string> d = new Dictionary<string, string>();
|
d.Add(FunctionAttributeKey.OnOff, device.trait_on_off.curValue.ToString());
|
Control.Ins.SendWriteCommand(device, d);
|
})
|
{ IsBackground = true }.Start();
|
};
|
|
//刷新界面状态
|
this.RefreshFormStatu();
|
|
if (fanSpeedList.Count > 0)
|
{
|
this.btnFan.UnSelectedImagePath = "FunctionIcon/AirFresh/Fan1.png";
|
this.btnFan.SelectedImagePath = "FunctionIcon/AirFresh/Fan1Select.png";
|
this.btnFanView.Text = Language.StringByID(StringId.LowWindSpeed);
|
}
|
}
|
|
#endregion
|
|
#region ■ 显示风速选择界面___________________
|
|
/// <summary>
|
/// 显示风速选择界面
|
/// </summary>
|
private void ShowFanSelectView()
|
{
|
//整个灰色界面
|
var frameBack = new Dialog();
|
|
var dialogBody = new NormalFrameLayout();
|
frameBack.AddChidren(dialogBody);
|
dialogBody.ButtonClickEvent = (sender, e) =>
|
{
|
frameBack.Close();
|
};
|
frameBack.Show();
|
|
var fanAttr = device.GetAttribute(FunctionAttributeKey.FanSpeed);
|
if(fanAttr == null)
|
{
|
return;
|
}
|
var valueCount = fanAttr.value.Count;
|
|
//菜单控件(风速)
|
var menuContr = new DialogTitleMenuControl(valueCount, Language.StringByID(StringId.FanSpeed));
|
//menuContr.X = Application.GetRealWidth(209);
|
menuContr.Gravity = Gravity.CenterHorizontal;
|
menuContr.Y = Application.GetRealHeight(231);
|
menuContr.Width = Application.GetRealWidth(160);
|
if (valueCount > 2)
|
{
|
menuContr.Height = Application.GetRealHeight(199);
|
}
|
else
|
{
|
menuContr.Height = Application.GetRealHeight(154);
|
}
|
dialogBody.AddChidren(menuContr);
|
|
foreach(var fanAttrValue in fanAttr.value)
|
{
|
bool isSelecte = false;
|
var iconPath = "FunctionIcon/AirFresh/Fan1.png";
|
string text = Language.StringByID(StringId.FanOneGear);
|
if (fanAttrValue == "low" || fanAttrValue == "level_1")
|
{
|
text = Language.StringByID(StringId.LowWindSpeed);
|
if (this.device.GetAttrState(FunctionAttributeKey.FanSpeed) == "low"|| this.device.GetAttrState(FunctionAttributeKey.FanSpeed) == "level_1")
|
{
|
iconPath = "FunctionIcon/AirFresh/Fan1Select.png";
|
isSelecte = true;
|
}
|
}
|
else if (fanAttrValue == "medium" || fanAttrValue == "level_2")
|
{
|
text = Language.StringByID(StringId.MiddleWindSpeed);
|
iconPath = "FunctionIcon/AirFresh/Fan2.png";
|
if (this.device.GetAttrState(FunctionAttributeKey.FanSpeed) == "medium" || this.device.GetAttrState(FunctionAttributeKey.FanSpeed) == "level_2")
|
{
|
iconPath = "FunctionIcon/AirFresh/Fan2Select.png";
|
isSelecte = true;
|
}
|
}
|
else if (fanAttrValue == "high" || fanAttrValue == "level_3")
|
{
|
text = Language.StringByID(StringId.HighWindSpeed);
|
iconPath = "FunctionIcon/AirFresh/Fan3.png";
|
if (this.device.GetAttrState(FunctionAttributeKey.FanSpeed) == "high" || this.device.GetAttrState(FunctionAttributeKey.FanSpeed) == "level_3")
|
{
|
iconPath = "FunctionIcon/AirFresh/Fan3Select.png";
|
isSelecte = true;
|
}
|
}
|
|
menuContr.AddRowMenu(text, iconPath, isSelecte, () =>
|
{
|
frameBack.Close();
|
//发送档位命令
|
this.SendOtherComand(this.btnFan, FunctionAttributeKey.FanSpeed, fanAttrValue);
|
});
|
}
|
|
//if (fanAttr.value.Contains("low"))
|
//{
|
// //1档
|
// var iconPath = this.device.GetAttrState(FunctionAttributeKey.FanSpeed) == "low" ? "FunctionIcon/AirFresh/Fan1Select.png" : "FunctionIcon/AirFresh/Fan1.png";
|
// menuContr.AddRowMenu(Language.StringByID(StringId.FanOneGear), iconPath, this.device.GetAttrState(FunctionAttributeKey.FanSpeed) == "low", () =>
|
// {
|
// frameBack.Close();
|
// //发送档位命令
|
// this.SendOtherComand(this.btnFan, FunctionAttributeKey.FanSpeed, "low");
|
// });
|
//}
|
|
//if (fanAttr.value.Contains("medium"))
|
//{
|
// //2档
|
// var iconPath = this.device.GetAttrState(FunctionAttributeKey.FanSpeed) == "medium" ? "FunctionIcon/AirFresh/Fan2Select.png" : "FunctionIcon/AirFresh/Fan2.png";
|
// menuContr.AddRowMenu(Language.StringByID(StringId.FanTwoGear), iconPath, this.device.GetAttrState(FunctionAttributeKey.FanSpeed) == "medium", () =>
|
// {
|
// frameBack.Close();
|
// //发送档位命令
|
// this.SendOtherComand(this.btnFan, FunctionAttributeKey.FanSpeed, "medium");
|
// });
|
//}
|
|
//if (fanAttr.value.Contains("high"))
|
//{
|
// //3档
|
// var iconPath = this.device.GetAttrState(FunctionAttributeKey.FanSpeed) == "high" ? "FunctionIcon/AirFresh/Fan3Select.png" : "FunctionIcon/AirFresh/Fan3.png";
|
// menuContr.AddRowMenu(Language.StringByID(StringId.FanThreeGear), iconPath, this.device.GetAttrState(FunctionAttributeKey.FanSpeed) == "high", () =>
|
// {
|
// frameBack.Close();
|
// //发送档位命令
|
// this.SendOtherComand(this.btnFan, FunctionAttributeKey.FanSpeed, "high");
|
// });
|
//}
|
}
|
|
#endregion
|
|
#region ■ 设备状态反馈_______________________
|
|
/// <summary>
|
/// 设备状态反馈
|
/// </summary>
|
/// <param name="i_LocalDevice"></param>
|
public override void DeviceStatuPush(Function i_LocalDevice)
|
{
|
//不是同一个东西
|
if (this.device.sid != i_LocalDevice.sid) { return; }
|
|
//刷新当前设备的状态缓存
|
this.RefreshNowDeviceStatuMemory(i_LocalDevice);
|
//刷新界面状态
|
this.RefreshFormStatu();
|
}
|
|
#endregion
|
|
#region ■ 刷新界面状态_______________________
|
|
/// <summary>
|
/// 刷新界面状态
|
/// </summary>
|
private void RefreshFormStatu()
|
{
|
//开关
|
this.btnSwitch.IsSelected = this.device.GetAttrState(FunctionAttributeKey.OnOff) == "on";
|
|
this.RefreshFanSpeed();
|
}
|
|
/// <summary>
|
/// 刷新风速状态
|
/// </summary>
|
private void RefreshFanSpeed()
|
{
|
//风速
|
if (this.device.GetAttrState(FunctionAttributeKey.FanSpeed) == "low")
|
{
|
this.btnFan.UnSelectedImagePath = "FunctionIcon/AirFresh/Fan1.png";
|
this.btnFan.SelectedImagePath = "FunctionIcon/AirFresh/Fan1Select.png";
|
this.btnFanView.Text = Language.StringByID(StringId.LowWindSpeed);
|
}
|
else if (this.device.GetAttrState(FunctionAttributeKey.FanSpeed) == "medium")
|
{
|
this.btnFan.UnSelectedImagePath = "FunctionIcon/AirFresh/Fan2.png";
|
this.btnFan.SelectedImagePath = "FunctionIcon/AirFresh/Fan2Select.png";
|
this.btnFanView.Text = Language.StringByID(StringId.MiddleWindSpeed);
|
}
|
else if (this.device.GetAttrState(FunctionAttributeKey.FanSpeed) == "high")
|
{
|
this.btnFan.UnSelectedImagePath = "FunctionIcon/AirFresh/Fan3.png";
|
this.btnFan.SelectedImagePath = "FunctionIcon/AirFresh/Fan3Select.png";
|
this.btnFanView.Text = Language.StringByID(StringId.HighWindSpeed);
|
}
|
this.btnFan.CanClick = this.btnFan.IsSelected = this.device.GetAttrState(FunctionAttributeKey.OnOff) == "on";
|
}
|
|
#endregion
|
|
#region ■ 发送各种命令_______________________
|
|
/// <summary>
|
/// 发送其他命令
|
/// </summary>
|
/// <param name="btnIcon">按钮</param>
|
/// <param name="comadKey">命令主键</param>
|
/// <param name="comadValue">命令</param>
|
private void SendOtherComand(IconViewControl btnIcon, string comadKey, string comadValue)
|
{
|
btnIcon.CanClick = false;
|
|
HdlThreadLogic.Current.RunThread(() =>
|
{
|
//获取发送命令的样板(bus协议是需要一次性把全部命令一起发送的)
|
var dic = this.GetSendComandSample();
|
dic[comadKey] = comadValue;
|
Control.Ins.SendWriteCommand(this.device, dic);
|
HdlThreadLogic.Current.RunMain(() =>
|
{
|
btnIcon.CanClick = true;
|
});
|
});
|
}
|
|
/// <summary>
|
/// 获取发送命令的样板(bus协议是需要一次性把全部命令一起发送的)
|
/// </summary>
|
/// <returns></returns>
|
private Dictionary<string, string> GetSendComandSample()
|
{
|
var dic = new Dictionary<string, string>();
|
//开关
|
dic[FunctionAttributeKey.OnOff] = this.device.GetAttrState(FunctionAttributeKey.OnOff);
|
//风速
|
dic[FunctionAttributeKey.FanSpeed] = this.device.GetAttrState(FunctionAttributeKey.FanSpeed);
|
|
return dic;
|
}
|
|
#endregion
|
|
#region ■ 一般方法___________________________
|
|
/// <summary>
|
/// 刷新当前设备的状态缓存
|
/// </summary>
|
private void RefreshNowDeviceStatuMemory(Function i_LocalDevice)
|
{
|
for (int i = 0; i < i_LocalDevice.attributes.Count; i++)
|
{
|
var data = i_LocalDevice.attributes[i];
|
//开关
|
if (data.key == FunctionAttributeKey.OnOff) { this.device.SetAttrState(FunctionAttributeKey.OnOff, data.state); }
|
//风速
|
else if (data.key == FunctionAttributeKey.FanSpeed) { this.device.SetAttrState(FunctionAttributeKey.FanSpeed, data.state); }
|
}
|
}
|
|
#endregion
|
|
|
|
|
}
|
}
|