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 AirFreshControlPage : DeviceFunctionCardCommonForm { #region ■ 变量声明___________________________ /// /// 室内湿度控件 /// private NormalViewControl btnHumidity = null; /// /// %控件 /// private NormalViewControl btnHumidityUnit = null; /// /// 室内温度控件 /// private NormalViewControl btnTemperature = null; /// /// ℃控件 /// private NormalViewControl btnTemperatureUnit = null; /// /// 当前滤网剩余控件 /// private NormalViewControl btnFilterScreen = null; /// /// 滤网使用超时提示 /// FrameLayout filterScreenTipView; /// /// 节能/舒适图标控件 /// private IconViewControl btnMode1 = null; /// /// 节能/舒适文本控件 /// private NormalViewControl btnMode1View = null; /// /// 通风/加湿图标控件 /// private IconViewControl btnMode2 = null; /// /// 通风/加湿文本控件 /// private NormalViewControl btnMode2View = null; /// /// 风速图标控件 /// private IconViewControl btnFan = null; /// /// 风速文本控件 /// private NormalViewControl btnFanView = null; /// /// 湿度设置图标控件 /// private IconViewControl btnSetHumidity = null; /// /// 湿度设置文本控件 /// private NormalViewControl btnSetHumidityView = null; /// /// 开关图标 /// private IconViewControl btnSwitch = null; /// /// 新风数据 /// private AirFreshData airFreshData = new AirFreshData(); /// /// 各种文本 /// private Dictionary dicText = new Dictionary(); #endregion #region ■ 初始化_____________________________ /// /// 初始化白色区域的内容 /// public override void InitFrameWhiteContent() { base.SetTitleText(Language.StringByID(StringId.AirFresh)); //这个东西加个空格 this.dicText["滤网剩余"] = Language.StringByID(StringId.ResidualFilterScreen) + " "; this.dicText["节能"] = Language.StringByID(StringId.Energy); this.dicText["舒适"] = Language.StringByID(StringId.Comfortable); this.dicText["通风"] = Language.StringByID(StringId.Ventilated); this.dicText["加湿"] = Language.StringByID(StringId.Humidification); this.dicText["1档"] = Language.StringByID(StringId.OneGear); this.dicText["2档"] = Language.StringByID(StringId.TwoGear); this.dicText["3档"] = Language.StringByID(StringId.ThreeGear); //刷新当前设备的状态缓存 this.RefreshNowDeviceStatuMemory(this.device); //初始化第一个索引页的内容 this.InitFrameWhiteContent1(); Control.Ins.SendReadCommand(device); } /// /// 初始化第一个索引页的内容 /// private void InitFrameWhiteContent1() { //一个背景图片 var framePic = new FrameLayout(); framePic.Y = Application.GetRealHeight(120); framePic.Width = this.GetPictrueRealSize(303); framePic.Height = this.GetPictrueRealSize(175); framePic.Gravity = Gravity.CenterHorizontal; framePic.BackgroundImagePath = "FunctionIcon/AirFresh/TempAndHumiBack.png"; this.FrameWhiteCentet1.AddChidren(framePic); //室内湿度 的容器(为了重新计算坐标使用) int frameWidth = framePic.Width / 2 - this.GetPictrueRealSize(21); var frameHumidity = new FrameLayout(); frameHumidity.X = this.GetPictrueRealSize(21); frameHumidity.Y = this.GetPictrueRealSize(12); frameHumidity.Width = frameWidth; frameHumidity.Height = frameWidth; framePic.AddChidren(frameHumidity); //室内湿度值 this.btnHumidity = new NormalViewControl(20, this.GetPicChidrenTextHeight(30), false); btnHumidity.Y = this.GetPictrueRealSize(39); btnHumidity.TextSize = 30; btnHumidity.TextColor = CSS_Color.FirstLevelTitleColor; btnHumidity.TextAlignment = TextAlignment.TopCenter; frameHumidity.AddChidren(btnHumidity); //% this.btnHumidityUnit = new NormalViewControl(10, 10, true); btnHumidityUnit.Y = btnHumidity.Y + this.GetPictrueRealSize(8); btnHumidityUnit.TextColor = CSS_Color.TextualColor; btnHumidityUnit.Text = "%"; btnHumidityUnit.TextSize = CSS_FontSize.PromptFontSize_SecondaryLevel; btnHumidityUnit.Width = btnHumidityUnit.GetRealWidthByText(); frameHumidity.AddChidren(btnHumidityUnit); //室内湿度 var btnHumidityView = new NormalViewControl(frameHumidity.Width, this.GetPicChidrenTextHeight(18), false); btnHumidityView.Y = btnHumidity.Bottom + this.GetPictrueRealSize(8); btnHumidityView.TextAlignment = TextAlignment.Center; btnHumidityView.TextColor = CSS_Color.TextualColor; btnHumidityView.TextSize = CSS_FontSize.PromptFontSize_FirstLevel; btnHumidityView.TextID = StringId.IndoorHumidity; frameHumidity.AddChidren(btnHumidityView); //室内温度 的容器(为了重新计算坐标使用) var frameTemperature = new FrameLayout(); frameTemperature.Y = frameHumidity.Y; frameTemperature.X = frameHumidity.Right; frameTemperature.Width = frameWidth; frameTemperature.Height = frameWidth; framePic.AddChidren(frameTemperature); //室内温度值 this.btnTemperature = new NormalViewControl(20, this.GetPicChidrenTextHeight(30), false); btnTemperature.Y = btnHumidity.Y; btnTemperature.TextSize = 30; btnTemperature.TextColor = CSS_Color.FirstLevelTitleColor; btnTemperature.TextAlignment = TextAlignment.TopCenter; btnTemperature.GetRealWidthByText(); frameTemperature.AddChidren(btnTemperature); //℃ this.btnTemperatureUnit = new NormalViewControl(10, 10, true); btnTemperatureUnit.Y = btnTemperature.Y + this.GetPictrueRealSize(8); btnTemperatureUnit.TextColor = CSS_Color.TextualColor; btnTemperatureUnit.Text = "℃"; btnTemperatureUnit.TextSize = CSS_FontSize.PromptFontSize_SecondaryLevel; btnTemperatureUnit.Width = btnTemperatureUnit.GetRealWidthByText(); frameTemperature.AddChidren(btnTemperatureUnit); //室内温度 var btnTemperatureView = new NormalViewControl(frameTemperature.Width, this.GetPicChidrenTextHeight(18), false); btnTemperatureView.Y = btnTemperature.Bottom + this.GetPictrueRealSize(8); btnTemperatureView.TextAlignment = TextAlignment.Center; btnTemperatureView.TextColor = CSS_Color.TextualColor; btnTemperatureView.TextSize = CSS_FontSize.PromptFontSize_FirstLevel; btnTemperatureView.TextID = StringId.IndoorTemp; frameTemperature.AddChidren(btnTemperatureView); //当前滤网剩余0% this.btnFilterScreen = new NormalViewControl(this.FrameWhiteCentet1.Width, Application.GetRealHeight(18), false); btnFilterScreen.Y = framePic.Bottom; btnFilterScreen.TextAlignment = TextAlignment.Center; btnFilterScreen.TextSize = CSS_FontSize.PromptFontSize_FirstLevel; btnFilterScreen.TextColor = CSS_Color.MainColor; this.FrameWhiteCentet1.AddChidren(btnFilterScreen); #region 滤网使用超时提醒 filterScreenTipView = new FrameLayout() { Y = btnFilterScreen.Bottom + Application.GetRealWidth(8), Gravity = Gravity.CenterHorizontal, Width = Application.GetRealWidth(295), Height = Application.GetRealHeight(28), Radius = (uint)Application.GetRealWidth(4), BackgroundColor = 0xFFffE8E8, Visible = false, }; this.FrameWhiteCentet1.AddChidren(filterScreenTipView); Button btnFilterScreenUseTip = new Button() { X = Application.GetRealWidth(8), Gravity = Gravity.CenterVertical, Width = Application.GetRealWidth(20), Height = Application.GetRealWidth(20), UnSelectedImagePath = "FunctionIcon/AirFresh/btnInfoIcon.png" }; filterScreenTipView.AddChidren(btnFilterScreenUseTip); Button btnFilterScreenUseTipText = new Button() { X = Application.GetRealWidth(32), Width = Application.GetRealWidth(340), TextAlignment = TextAlignment.CenterLeft, TextColor = 0xFFFF4747, TextSize = CSS_FontSize.PromptFontSize_FirstLevel, }; if(Language.CurrentLanguage == "Chinese") { btnFilterScreenUseTipText.Text = "过滤网使用超时"; } else { btnFilterScreenUseTipText.Text = "Filter use timeout"; } filterScreenTipView.AddChidren(btnFilterScreenUseTipText); #endregion #region 节能 //节能/舒适图标 this.btnMode1 = new IconViewControl(28); btnMode1.X = Application.GetRealWidth(42); btnMode1.Y = btnFilterScreen.Bottom + Application.GetRealHeight(61); this.FrameWhiteCentet1.AddChidren(btnMode1); btnMode1.ButtonClickEvent += (sender, e) => { //显示节能/舒适选择界面 this.ShowMode1SelectView(); }; //节能/舒适文本 this.btnMode1View = new NormalViewControl(Application.GetRealWidth(72), Application.GetRealHeight(18), false); btnMode1View.X = Application.GetRealWidth(21); btnMode1View.Y = btnMode1.Bottom + Application.GetRealHeight(6); btnMode1View.TextAlignment = TextAlignment.Center; btnMode1View.TextSize = CSS_FontSize.PromptFontSize_FirstLevel; btnMode1View.TextColor = CSS_Color.TextualColor; this.FrameWhiteCentet1.AddChidren(btnMode1View); #endregion #region 模式 //通风/加湿图标 this.btnMode2 = new IconViewControl(28); btnMode2.Y = btnMode1.Y; btnMode2.X = Application.GetRealWidth(114); this.FrameWhiteCentet1.AddChidren(btnMode2); btnMode2.ButtonClickEvent += (sender, e) => { //显示通风/加湿选择界面 this.ShowMode2SelectView(); }; //通风/加湿文本 this.btnMode2View = new NormalViewControl(Application.GetRealWidth(72), Application.GetRealHeight(18), false); btnMode2View.X = btnMode1View.Right; btnMode2View.Y = btnMode2.Bottom + Application.GetRealHeight(6); btnMode2View.TextAlignment = TextAlignment.Center; btnMode2View.TextSize = CSS_FontSize.PromptFontSize_FirstLevel; btnMode2View.TextColor = CSS_Color.TextualColor; this.FrameWhiteCentet1.AddChidren(btnMode2View); #endregion #region 风速 //风速图标 this.btnFan = new IconViewControl(28); //btnFan.X = this.FrameWhiteCentet1.Width - btnMode1.X - btnFan.IconSize; btnFan.X = Application.GetRealWidth(186); btnFan.Y = btnMode1.Y; this.FrameWhiteCentet1.AddChidren(btnFan); btnFan.ButtonClickEvent += (sender, e) => { //显示风速选择界面 this.ShowFanSelectView(); }; //风速文本 this.btnFanView = new NormalViewControl(Application.GetRealWidth(72), Application.GetRealHeight(18), false); btnFanView.X = btnMode2View.Right; 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); #endregion #region 湿度 //湿度图标 this.btnSetHumidity = new IconViewControl(28); btnSetHumidity.X = this.FrameWhiteCentet1.Width - btnMode1.X - btnSetHumidity.IconSize; btnSetHumidity.Y = btnMode1.Y; btnSetHumidity.UnSelectedImagePath = "FunctionIcon/AirFresh/HumiIcon.png"; btnSetHumidity.SelectedImagePath = "FunctionIcon/AirFresh/HumiOnIcon.png"; this.FrameWhiteCentet1.AddChidren(btnSetHumidity); btnSetHumidity.ButtonClickEvent += (sender, e) => { LoadEditDialog_Humi(); }; //湿度文本 this.btnSetHumidityView = new NormalViewControl(Application.GetRealWidth(72), Application.GetRealHeight(18), false); btnSetHumidityView.X = btnFanView.Right; btnSetHumidityView.Y = btnSetHumidity.Bottom + Application.GetRealHeight(6); btnSetHumidityView.TextAlignment = TextAlignment.Center; btnSetHumidityView.TextSize = CSS_FontSize.PromptFontSize_FirstLevel; btnSetHumidityView.TextColor = CSS_Color.TextualColor; btnSetHumidityView.Text = "0%"; this.FrameWhiteCentet1.AddChidren(btnSetHumidityView); #endregion //开关图标 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.ButtonClickEvent += (sender, e) => { //发送开关命令 this.SendSwitchComand(); }; //刷新界面状态 this.RefreshFormStatu(); } #endregion #region ■ 显示节能/舒适选择界面______________ /// /// 显示节能/舒适选择界面 /// private void ShowMode1SelectView() { //整个灰色界面 var frameBack = new Dialog(); var dialogBody = new NormalFrameLayout(); frameBack.AddChidren(dialogBody); dialogBody.ButtonClickEvent = (sender, e) => { frameBack.Close(); }; frameBack.Show(); //菜单控件(模式) var menuContr = new DialogTitleMenuControl(2, Language.StringByID(StringId.Mode)); menuContr.X = Application.GetRealWidth(6); menuContr.Y = Application.GetRealHeight(277); menuContr.Width = Application.GetRealWidth(160); menuContr.Height = Application.GetRealHeight(154); dialogBody.AddChidren(menuContr); //节能 var iconPath = this.airFreshData.Energy == "true" ? "FunctionIcon/AirFresh/EnergySelect.png" : "FunctionIcon/AirFresh/Energy.png"; menuContr.AddRowMenu(this.dicText["节能"], iconPath, this.airFreshData.Energy == "true", () => { frameBack.Close(); //发送节能命令 this.SendOtherComand(this.btnMode1, FunctionAttributeKey.Energy, "true"); }); //舒适 iconPath = this.airFreshData.Energy == "false" ? "FunctionIcon/AirFresh/ComfortableSelect.png" : "FunctionIcon/AirFresh/Comfortable.png"; menuContr.AddRowMenu(this.dicText["舒适"], iconPath, this.airFreshData.Energy == "false", () => { frameBack.Close(); //发送舒适命令 this.SendOtherComand(this.btnMode1, FunctionAttributeKey.Energy, "false"); }); } #endregion #region ■ 显示通风/加湿选择界面______________ /// /// 显示通风/加湿选择界面 /// private void ShowMode2SelectView() { //整个灰色界面 var frameBack = new Dialog(); var dialogBody = new NormalFrameLayout(); frameBack.AddChidren(dialogBody); dialogBody.ButtonClickEvent = (sender, e) => { frameBack.Close(); }; frameBack.Show(); //菜单控件(模式) var menuContr = new DialogTitleMenuControl(2, Language.StringByID(StringId.Mode)); menuContr.Y = Application.GetRealHeight(277); menuContr.X = Application.GetRealWidth(72); menuContr.Width = Application.GetRealWidth(160); menuContr.Height = Application.GetRealHeight(154); dialogBody.AddChidren(menuContr); //通风 var iconPath = this.airFreshData.Mode == "fan" ? "FunctionIcon/AirFresh/VentilateSelect.png" : "FunctionIcon/AirFresh/Ventilate.png"; menuContr.AddRowMenu(this.dicText["通风"], iconPath, this.airFreshData.Mode == "fan", () => { frameBack.Close(); //发送通风命令 this.SendOtherComand(this.btnMode2, FunctionAttributeKey.Mode, "fan"); }); //加湿 iconPath = this.airFreshData.Mode == "humidification" ? "FunctionIcon/AirFresh/HumidificationSelect.png" : "FunctionIcon/AirFresh/Humidification.png"; menuContr.AddRowMenu(this.dicText["加湿"], iconPath, this.airFreshData.Mode == "humidification", () => { frameBack.Close(); //发送加湿命令 this.SendOtherComand(this.btnMode2, FunctionAttributeKey.Mode, "humidification"); }); } #endregion /// /// 加载湿度选择弹窗 /// /// /// void LoadEditDialog_Humi() { List pickerItems = new List(); Dialog dialog = new Dialog(); var pView = new FrameLayout() { BackgroundColor = CSS_Color.DialogTransparentColor1, }; dialog.AddChidren(pView); var optionBaseView = new FrameLayout() { Y = Application.GetRealHeight(456 - 60), Gravity = Gravity.CenterHorizontal, Width = Application.GetRealWidth(343), Height = Application.GetRealHeight(260), AnimateSpeed = 0.3f, Animate = Animate.DownToUp, BackgroundColor = CSS_Color.MainBackgroundColor, Radius = (uint)Application.GetRealWidth(12), }; pView.AddChidren(optionBaseView); var topView = new FrameLayout() { Gravity = Gravity.CenterHorizontal, Width = Application.GetRealWidth(343), Height = Application.GetRealHeight(40), BackgroundColor = CSS_Color.MainBackgroundColor, Radius = (uint)Application.GetRealWidth(12), }; optionBaseView.AddChidren(topView); topView.AddChidren(new Button() { Y = Application.GetRealHeight(39), Height = Application.GetRealHeight(1), BackgroundColor = CSS_Color.DividingLineColor }); var btnTilteText = new Button() { Width = Application.GetRealWidth(200), Gravity = Gravity.CenterHorizontal, TextAlignment = TextAlignment.Center, TextSize = CSS_FontSize.SubheadingFontSize, IsBold = true, TextColor = CSS_Color.FirstLevelTitleColor, }; if(Language.CurrentLanguage == "Chinese") { btnTilteText.Text = "湿度设定"; } else { btnTilteText.Text = "Humidity setting"; } topView.AddChidren(btnTilteText); var btnCancel = new Button() { X = Application.GetRealWidth(21), Width = Application.GetRealWidth(100), TextAlignment = TextAlignment.CenterLeft, TextColor = CSS_Color.PromptingColor1, TextSize = CSS_FontSize.TextFontSize, TextID = StringId.Cancel, }; topView.AddChidren(btnCancel); var btnConfrim = new Button() { Width = Application.GetRealWidth(320), TextAlignment = TextAlignment.CenterRight, TextColor = CSS_Color.MainColor, TextSize = CSS_FontSize.TextFontSize, TextID = StringId.Confirm, }; topView.AddChidren(btnConfrim); UIPickerView uIPickerView = new UIPickerView() { Y = Application.GetRealHeight(40), Height = Application.GetRealHeight(210), Radius = (uint)Application.GetRealWidth(12), }; for (int i = 0; i <= 100; i ++) { pickerItems.Add(i.ToString()); } uIPickerView.setNPicker(pickerItems, null, null); optionBaseView.AddChidren(uIPickerView); //uIPickerView.setCurrentItems(pickerItems.IndexOf(trait.value.ToString()), 4, 5); string selectItem = pickerItems[0]; //if (pickerItems.Contains(trait.value + trait.GetUintString())) //{ // selectItem = trait.value.ToString() + trait.GetUintString(); //} dialog.Show(); pView.MouseUpEventHandler = (sender, e) => { dialog.Close(); }; btnCancel.MouseUpEventHandler = (sender, e) => { dialog.Close(); }; uIPickerView.OnSelectChangeEvent = (int1, int2, int3) => { selectItem = pickerItems[int1]; }; btnConfrim.MouseUpEventHandler = (sender, e) => { dialog.Close(); this.SendOtherComand(this.btnSetHumidity, FunctionAttributeKey.Humidity, selectItem); this.btnSetHumidityView.Text = selectItem + "%"; //btn.Text = selectItem; //sceneFunction.status.Find((obj) => obj.key == FunctionAttributeKey.OnOff).value = trait.value.ToString() ; //trait.value = selectItem.Replace(trait.GetUintString(), ""); }; } #region ■ 显示风速选择界面___________________ /// /// 显示风速选择界面 /// private void ShowFanSelectView() { //整个灰色界面 var frameBack = new Dialog(); var dialogBody = new NormalFrameLayout(); frameBack.AddChidren(dialogBody); dialogBody.ButtonClickEvent = (sender, e) => { frameBack.Close(); }; frameBack.Show(); //菜单控件(风速) var menuContr = new DialogTitleMenuControl(3, Language.StringByID(StringId.FanSpeed)); menuContr.X = Application.GetRealWidth(80+62); menuContr.Y = Application.GetRealHeight(231); menuContr.Width = Application.GetRealWidth(160); menuContr.Height = Application.GetRealHeight(199); dialogBody.AddChidren(menuContr); //1档 var iconPath = this.airFreshData.Fan == "level_1" ? "FunctionIcon/AirFresh/Fan1Select.png" : "FunctionIcon/AirFresh/Fan1.png"; menuContr.AddRowMenu(Language.StringByID(StringId.FanOneGear), iconPath, this.airFreshData.Fan == "level_1", () => { frameBack.Close(); //发送档位命令 this.SendOtherComand(this.btnFan, FunctionAttributeKey.FanSpeed, "level_1"); }); //2档 iconPath = this.airFreshData.Fan == "level_2" ? "FunctionIcon/AirFresh/Fan2Select.png" : "FunctionIcon/AirFresh/Fan2.png"; menuContr.AddRowMenu(Language.StringByID(StringId.FanTwoGear), iconPath, this.airFreshData.Fan == "level_2", () => { frameBack.Close(); //发送档位命令 this.SendOtherComand(this.btnFan, FunctionAttributeKey.FanSpeed, "level_2"); }); //3档 iconPath = this.airFreshData.Fan == "level_3" ? "FunctionIcon/AirFresh/Fan3Select.png" : "FunctionIcon/AirFresh/Fan3.png"; menuContr.AddRowMenu(Language.StringByID(StringId.FanThreeGear), iconPath, this.airFreshData.Fan == "level_3", () => { frameBack.Close(); //发送档位命令 this.SendOtherComand(this.btnFan, FunctionAttributeKey.FanSpeed, "level_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.airFreshData.Open; //滤网剩余 this.btnFilterScreen.Text = this.dicText["滤网剩余"] + this.airFreshData.Filter_remain + "%"; if(this.airFreshData.Filter_timeout) { this.filterScreenTipView.Visible = true; } //室内湿度 if (this.btnHumidity.Text == string.Empty || Convert.ToDecimal(this.btnHumidity.Text) != this.airFreshData.Indoor_humidity) { //变更了才改 this.btnHumidity.Text = this.airFreshData.Indoor_humidity == 0 ? "0.0" : this.airFreshData.Indoor_humidity.ToString(); this.btnHumidity.Width = this.btnHumidity.GetRealWidthByText(); //重新计算坐标,让它们居中 this.btnHumidity.X = (btnHumidity.Parent.Width - btnHumidity.Width - btnHumidityUnit.Width) / 2; this.btnHumidityUnit.X = btnHumidity.Right; } //室内温度 if (this.btnTemperature.Text == string.Empty || Convert.ToDecimal(this.btnTemperature.Text) != this.airFreshData.Indoor_temp) { //变更了才改 this.btnTemperature.Text = this.airFreshData.Indoor_temp == 0 ? "0.0" : this.airFreshData.Indoor_temp.ToString(); this.btnTemperature.Width = this.btnTemperature.GetRealWidthByText(); //重新计算坐标,让它们居中 this.btnTemperature.X = (btnHumidity.Parent.Width - btnTemperature.Width - btnTemperatureUnit.Width) / 2; this.btnTemperatureUnit.X = btnTemperature.Right; } //节能/舒适 if (this.airFreshData.Energy == "true") { this.btnMode1.UnSelectedImagePath = "FunctionIcon/AirFresh/Energy.png"; this.btnMode1.SelectedImagePath = "FunctionIcon/AirFresh/EnergySelect.png"; this.btnMode1View.Text = this.dicText["节能"]; } else { this.btnMode1.UnSelectedImagePath = "FunctionIcon/AirFresh/Comfortable.png"; this.btnMode1.SelectedImagePath = "FunctionIcon/AirFresh/ComfortableSelect.png"; this.btnMode1View.Text = this.dicText["舒适"]; } this.btnMode1.IsSelected = this.airFreshData.Open; this.btnMode1.CanClick = this.airFreshData.Open; //通风/加湿 if (this.airFreshData.Mode == "fan") { this.btnMode2.UnSelectedImagePath = "FunctionIcon/AirFresh/Ventilate.png"; this.btnMode2.SelectedImagePath = "FunctionIcon/AirFresh/VentilateSelect.png"; this.btnMode2View.Text = this.dicText["通风"]; } else { this.btnMode2.UnSelectedImagePath = "FunctionIcon/AirFresh/Humidification.png"; this.btnMode2.SelectedImagePath = "FunctionIcon/AirFresh/HumidificationSelect.png"; this.btnMode2View.Text = this.dicText["加湿"]; } this.btnMode2.IsSelected = this.airFreshData.Open; this.btnMode2.CanClick = this.airFreshData.Open; //风速 if (this.airFreshData.Fan == "level_3") { this.btnFan.UnSelectedImagePath = "FunctionIcon/AirFresh/Fan3.png"; this.btnFan.SelectedImagePath = "FunctionIcon/AirFresh/Fan3Select.png"; this.btnFanView.Text = this.dicText["3档"]; } else if(this.airFreshData.Fan == "level_2") { this.btnFan.UnSelectedImagePath = "FunctionIcon/AirFresh/Fan2.png"; this.btnFan.SelectedImagePath = "FunctionIcon/AirFresh/Fan2Select.png"; this.btnFanView.Text = this.dicText["2档"]; } else { this.btnFan.UnSelectedImagePath = "FunctionIcon/AirFresh/Fan1.png"; this.btnFan.SelectedImagePath = "FunctionIcon/AirFresh/Fan1Select.png"; this.btnFanView.Text = this.dicText["1档"]; } this.btnFan.IsSelected = this.airFreshData.Open; this.btnFan.CanClick = this.airFreshData.Open; this.btnSetHumidityView.Text = this.airFreshData.Humidity.ToString() + "%"; this.btnSetHumidity.Enable = this.airFreshData.Open; this.btnSetHumidity.CanClick = this.airFreshData.Open; this.btnSetHumidity.IsSelected = this.airFreshData.Open; } #endregion #region ■ 发送各种命令_______________________ /// /// 发送其他命令 /// /// 按钮 /// 命令主键 /// 命令 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; }); }); } /// /// 发送开关命令 /// private void SendSwitchComand() { this.btnSwitch.CanClick = false; string statu = this.btnSwitch.IsSelected == true ? "off" : "on"; HdlThreadLogic.Current.RunThread(() => { //获取发送命令的样板(bus协议是需要一次性把全部命令一起发送的) var dic = this.GetSendComandSample(); dic[FunctionAttributeKey.OnOff] = statu; Control.Ins.SendWriteCommand(this.device, dic); HdlThreadLogic.Current.RunMain(() => { this.btnSwitch.CanClick = true; }); }); } /// /// 获取发送命令的样板(bus协议是需要一次性把全部命令一起发送的) /// /// private Dictionary GetSendComandSample() { var dic = new Dictionary(); //开关 dic[FunctionAttributeKey.OnOff] = this.airFreshData.Open == true ? "on" : "off"; //模式 dic[FunctionAttributeKey.Mode] = this.airFreshData.Mode; //节能 dic[FunctionAttributeKey.Energy] = this.airFreshData.Energy; //风速 dic[FunctionAttributeKey.FanSpeed] = this.airFreshData.Fan ; //湿度 dic[FunctionAttributeKey.Humidity] = this.airFreshData.Humidity.ToString(); //室内温度 dic[FunctionAttributeKey.IndoorTemp] = this.airFreshData.Indoor_temp.ToString(); ///室内湿度 dic[FunctionAttributeKey.IndoorHumidity] = this.airFreshData.Indoor_humidity.ToString(); return dic; } #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.airFreshData.Open = data.state == "on"; } //模式 else if (data.key == FunctionAttributeKey.Mode) { this.airFreshData.Mode = data.state; } //节能 else if (data.key == FunctionAttributeKey.Energy) { this.airFreshData.Energy = data.state; } //风速 else if (data.key == FunctionAttributeKey.FanSpeed) { this.airFreshData.Fan = data.state; } //湿度 else if (data.key == FunctionAttributeKey.Humidity) { if (data.state != string.Empty) { this.airFreshData.Humidity = Convert.ToInt32(data.state); } } //室内温度 else if (data.key == FunctionAttributeKey.IndoorTemp) { if (data.state != string.Empty) { this.airFreshData.Indoor_temp = Math.Round(Convert.ToDecimal(data.state), 1); } } //室内湿度 else if (data.key == FunctionAttributeKey.IndoorHumidity) { if (data.state != string.Empty) { this.airFreshData.Indoor_humidity = Math.Round(Convert.ToDecimal(data.state), 1); } } //过滤网剩余量 else if (data.key == FunctionAttributeKey.FilterRemain) { if (data.state != string.Empty) { this.airFreshData.Filter_remain = Convert.ToInt32(data.state); } } //过滤网是否超时警告 else if (data.key == FunctionAttributeKey.FilterTimeout) { if(data.state != string.Empty) { this.airFreshData.Filter_timeout = Convert.ToBoolean(data.state); } } } } #endregion #region ■ 结构体_____________________________ /// /// 新风的数据 /// private class AirFreshData { /// /// 是否打开 /// public bool Open = false; /// /// humidification:加湿 fan:送风 /// public string Mode = string.Empty; /// /// true:节能 false:舒适 这个有问题的 /// public string Energy = string.Empty; /// /// level_1:1档 level_2:2档 level_3:3档 auto:自动(目前这个不用) /// public string Fan = string.Empty; /// /// 湿度(%) /// public int Humidity = 0; /// /// 室内温度(保留一位小数) /// public decimal Indoor_temp = 0; /// /// 室内湿度(保留一位小数) /// public decimal Indoor_humidity = 0; /// /// 剩余滤网(%) /// public int Filter_remain = 0; /// /// 过滤网是否超时警告 /// public bool Filter_timeout = false; } #endregion } }