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 ■ 变量声明___________________________ /// /// 风速图标控件 /// private IconViewControl btnFan = null; /// /// 风速文本控件 /// private NormalViewControl btnFanView = null; /// /// 开关图标 /// private IconViewControl btnSwitch = null; #endregion #region ■ 初始化_____________________________ /// /// 初始化白色区域的内容 /// public override void InitFrameWhiteContent() { base.SetTitleText(Language.StringByID(StringId.AirFresh)); //刷新当前设备的状态缓存 this.RefreshNowDeviceStatuMemory(this.device); //初始化第一个索引页的内容 this.InitFrameWhiteContent1(); Control.Ins.SendReadCommand(device); } /// /// 初始化第一个索引页的内容 /// 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 fanSpeedList = new List(); fanSpeedList = device.GetAttribute(FunctionAttributeKey.FanSpeed).value; btnFan.MouseUpEventHandler += (sender, e) => { if (btnSwitch.IsSelected) { ShowFanSelectView(); } }; //风速文本 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 d = new Dictionary(); 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 ■ 显示风速选择界面___________________ /// /// 显示风速选择界面 /// 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.Width = Application.GetRealWidth(160); dialogBody.AddChidren(menuContr); int count = 0; 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; } } else if(fanAttrValue == "auto") { text = Language.StringByID(StringId.Auto); iconPath = "FunctionIcon/AirFresh/Fan2.png"; if (this.device.GetAttrState(FunctionAttributeKey.FanSpeed) == "auto" ) { iconPath = "FunctionIcon/AirFresh/Fan2Select.png"; isSelecte = true; } } else { continue; } count++; menuContr.AddRowMenu(text, iconPath, isSelecte, () => { frameBack.Close(); //发送档位命令 this.SendOtherComand(this.btnFan, FunctionAttributeKey.FanSpeed, fanAttrValue); }); } menuContr.Y = Application.GetRealHeight(231 - (46 * (count-3))); } #endregion #region ■ 设备状态反馈_______________________ /// /// 设备状态反馈 /// /// public override void DeviceStatuPush(Function i_LocalDevice) { //不是同一个东西 if (this.device.sid != i_LocalDevice.sid) { return; } //刷新当前设备的状态缓存 this.RefreshNowDeviceStatuMemory(i_LocalDevice); //刷新界面状态 this.RefreshFormStatu(); } #endregion #region ■ 刷新界面状态_______________________ /// /// 刷新界面状态 /// private void RefreshFormStatu() { //开关 this.btnSwitch.IsSelected = this.device.GetAttrState(FunctionAttributeKey.OnOff) == "on"; this.RefreshFanSpeed(); } /// /// 刷新风速状态 /// 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 ■ 发送各种命令_______________________ /// /// 发送其他命令 /// /// 按钮 /// 命令主键 /// 命令 private void SendOtherComand(IconViewControl btnIcon, string comadKey, string comadValue) { btnIcon.CanClick = false; HdlThreadLogic.Current.RunThread(() => { //获取发送命令的样板(bus协议是需要一次性把全部命令一起发送的) Dictionary dic = new Dictionary(); dic.Add(comadKey, comadValue); Control.Ins.SendWriteCommand(this.device, dic); HdlThreadLogic.Current.RunMain(() => { btnIcon.CanClick = true; }); }); } #endregion #region ■ 一般方法___________________________ /// /// 刷新当前设备的状态缓存 /// 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 } }