using System; using Shared; using HDL_ON.UI.CSS; using HDL_ON.Entity; using HDL_ON.DriverLayer; namespace HDL_ON.UI { public partial class SocketPage : FrameLayout { #region 控件集合 static SocketPage bodyView; /// /// 功能名称按钮 /// Button btnFunctionName; /// /// 房间楼层信息按钮 /// Button btnFromFoorAndRoom; /// /// 收藏按钮 /// Button btnCollection; /// /// 图标按钮 /// Button btnSwitchIcon; Button btnSwitch; #endregion #region 区域变量 SwitchSocket socketTemp; Function function; Button btnCollection_Out; Button btnFunctionName_Out; Button btnFromFloor_Out; /// /// 刷新显示信息 /// Action actionRefresh; #endregion public SocketPage(Function func) { bodyView = this; function = func ; } public void LoadPage(Button btnCollectionIcon, Button btnFunctionNameOut, Button btnFromFloorOut) { bodyView.BackgroundColor = CSS_Color.BackgroundColor; btnCollection_Out = btnCollectionIcon; btnFunctionName_Out = btnFunctionNameOut; btnFromFloor_Out = btnFromFloorOut; FrameLayout controlView = new FrameLayout() { Gravity = Gravity.CenterHorizontal, Y = Application.GetRealHeight(88), Width = Application.GetRealWidth(327), Height = Application.GetRealHeight(526), BackgroundImagePath = "Public/Fragmentbg.png", }; bodyView.AddChidren(controlView); btnFunctionName = new Button() { X = Application.GetRealWidth(16), Y = Application.GetRealHeight(14), Width = Application.GetRealWidth(270), Height = Application.GetRealHeight(37), TextColor = CSS_Color.FirstLevelTitleColor, TextAlignment = TextAlignment.CenterLeft, TextSize = CSS_FontSize.EmphasisFontSize_FirstLevel, Text = function.name, }; controlView.AddChidren(btnFunctionName); btnFromFoorAndRoom = new Button() { X = Application.GetRealWidth(16), Y = btnFunctionName.Bottom, Width = Application.GetRealWidth(270), Height = Application.GetRealHeight(21), TextColor = CSS_Color.PromptingColor1, TextAlignment = TextAlignment.CenterLeft, TextSize = CSS_FontSize.PromptFontSize_FirstLevel, Text = function.GetRoomListName() }; controlView.AddChidren(btnFromFoorAndRoom); btnCollection = new Button() { X = Application.GetRealWidth(273), Y = Application.GetRealHeight(14), Width = Application.GetMinRealAverage(40), Height = Application.GetMinRealAverage(40), SelectedImagePath = "Collection/CollectionIcon.png", UnSelectedImagePath = "Collection/CollectionGrayIcon.png", IsSelected = function.collect }; controlView.AddChidren(btnCollection); //2020-12-16 如果是成员隐藏收藏功能 //if (!DB_ResidenceData.Instance.CurrentRegion.isOtherShare) //{ // controlView.AddChidren(btnCollection); //} btnSwitchIcon = new Button() { Gravity = Gravity.CenterHorizontal, Y = Application.GetRealHeight(100), Width = Application.GetRealWidth(198), Height = Application.GetRealWidth(198), IsSelected = function.trait_on_off.curValue.ToString() == "on", UnSelectedImagePath = "FunctionIcon/Socket/SocketIconBg.png", SelectedImagePath = "FunctionIcon/Socket/SocketIconOnBg.png", }; controlView.AddChidren(btnSwitchIcon); btnSwitch = new Button() { Gravity = Gravity.CenterHorizontal, Y = Application.GetRealHeight(462), Width = Application.GetMinRealAverage(40), Height = Application.GetMinRealAverage(40), UnSelectedImagePath = "Public/PowerClose.png", SelectedImagePath = "Public/PowerOpen.png", IsSelected = function.trait_on_off.curValue.ToString() == "on" }; controlView.AddChidren(btnSwitch); if (function.attributes.Find((obj) => obj.key == "active_power" || obj.key == "voltage" || obj.key == "current") != null) { //加载瞬时值 var btnInstantaneousValue = new Button() { X = Application.GetRealWidth(67), Y = Application.GetRealHeight(377), Width = Application.GetMinRealAverage(32), Height = Application.GetMinRealAverage(32), UnSelectedImagePath = "FunctionIcon/EnvironmentalScience/DiagramIconOn.png", }; controlView.AddChidren(btnInstantaneousValue); var btnInstantaneousValueText = new Button() { X = Application.GetRealWidth(35), Y = btnInstantaneousValue.Bottom, Width = Application.GetRealWidth(96), Height = Application.GetRealHeight(29), TextAlignment = TextAlignment.Center, TextSize = CSS_FontSize.PromptFontSize_FirstLevel, TextColor = CSS_Color.TextualColor, TextID = StringId.InstantaneousValue, IsMoreLines = true }; controlView.AddChidren(btnInstantaneousValueText); EventHandler eventHandler = (sender, e) => { var page = new SocketPage_InstantaneousValue(function); MainPage.BasePageView.AddChidren(page); page.LoadPage(); MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1; }; btnInstantaneousValue.MouseUpEventHandler = eventHandler; btnInstantaneousValueText.MouseUpEventHandler = eventHandler; } if(function.attributes.Find((obj)=>obj.key == "total_electricity") != null) { //加载累计用电 var btnTotalElectricity = new Button() { X = Application.GetRealWidth(200), Y = Application.GetRealHeight(377), Height = Application.GetMinRealAverage(32), TextColor = CSS_Color.MainColor, TextSize = CSS_FontSize.EmphasisFontSize_Secondary, Text = function.GetAttrState("total_electricity"), TextAlignment = TextAlignment.BottomLeft, }; btnTotalElectricity.Width = btnTotalElectricity.GetTextWidth()+ Application.GetRealWidth(5); controlView.AddChidren(btnTotalElectricity); var btnTotalElectricityUnit = new Button() { X = btnTotalElectricity.Right, Y = Application.GetRealHeight(377), Width = Application.GetRealWidth(100), Height = Application.GetMinRealAverage(32), TextColor = CSS_Color.TextualColor, TextSize = CSS_FontSize.PromptFontSize_SecondaryLevel, Text = "kW·h", TextAlignment = TextAlignment.BottomLeft, }; controlView.AddChidren(btnTotalElectricityUnit); var btnTotalElectricityText = new Button() { X = Application.GetRealWidth(200), Y = btnTotalElectricity.Bottom, Width = Application.GetRealWidth(100), Height = Application.GetRealHeight(29), TextAlignment = TextAlignment.CenterLeft, TextSize = CSS_FontSize.PromptFontSize_FirstLevel, TextColor = CSS_Color.TextualColor, TextID = StringId.CumulativePowerConsumption, IsMoreLines = true }; controlView.AddChidren(btnTotalElectricityText); EventHandler eventHandler = (sender, e) => { var page = new SocketPage_CumulativePowerConsumption(function); MainPage.BasePageView.AddChidren(page); page.LoadPage(); MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1; }; btnTotalElectricity.MouseUpEventHandler = eventHandler; btnTotalElectricityUnit.MouseUpEventHandler = eventHandler; btnTotalElectricityText.MouseUpEventHandler = eventHandler; } LoadEventList(); new TopViewDiv(bodyView, Language.StringByID(StringId.Socket)).LoadTopView_FunctionTop(function, actionRefresh); new System.Threading.Thread(() => { DriverLayer.Control.Ins.SendReadCommand(function); }) { IsBackground = true }.Start(); } } public partial class SocketPage { /// /// 更新灯光状态 /// public static void UpdataState(Function uFan) { Application.RunOnMainThread(() => { try { if (bodyView == null) return; bodyView.btnSwitch.IsSelected = bodyView.btnSwitchIcon.IsSelected = uFan.trait_on_off.curValue.ToString() == "on"; } catch (Exception ex) { MainPage.Log($"RelayPage error {ex.Message}"); } }); } /// /// 加载事件列表 /// void LoadEventList() { LoadSwitchEvent(); LoadCollectionEvent(); //回退刷新信息事件 actionRefresh = () => { btnFunctionName.Text = btnFunctionName_Out.Text = function.name; btnFromFloor_Out.Text = btnFromFoorAndRoom.Text = function.GetRoomListName(); function.UpdataFuncitonInfo(); }; } /// /// 收藏功能按钮事件 /// void LoadCollectionEvent() { btnCollection.MouseUpEventHandler += (sender, e) => { btnCollection.IsSelected = function.collect = btnCollection_Out.IsSelected = !btnCollection.IsSelected; function.CollectFunction(); }; } /// /// 加载开关事件 /// void LoadSwitchEvent() { btnSwitchIcon.MouseUpEventHandler += (sender, e) => { if (!function.online) { new Tip() { CloseTime = 1, Text = Language.StringByID(StringId.DeviceOfflineCannotOption), Direction = AMPopTipDirection.None, }.Show(MainPage.BaseView); return; } btnSwitchIcon.IsSelected = btnSwitch.IsSelected = !btnSwitchIcon.IsSelected; new System.Threading.Thread(() => { function.trait_on_off.curValue = btnSwitch.IsSelected ? "on" : "off"; System.Collections.Generic.Dictionary d = new System.Collections.Generic.Dictionary(); d.Add("on_off", function.trait_on_off.curValue.ToString()); if (function.attributes.Find((obj) => obj.key == "on_off_usb") != null) { d.Add("on_off_usb", function.trait_on_off.curValue.ToString()); } Control.Ins.SendWriteCommand(function, d); }) { IsBackground = true }.Start(); }; btnSwitch.MouseUpEventHandler += (sender, e) => { if (!function.online) { new Tip() { CloseTime = 1, Text = Language.StringByID(StringId.DeviceOfflineCannotOption), Direction = AMPopTipDirection.None, }.Show(MainPage.BaseView); return; } btnSwitch.IsSelected = btnSwitchIcon.IsSelected = !btnSwitch.IsSelected; new System.Threading.Thread(() => { function.trait_on_off.curValue = btnSwitch.IsSelected ? "on" : "off"; System.Collections.Generic.Dictionary d = new System.Collections.Generic.Dictionary(); d.Add("on_off", function.trait_on_off.curValue.ToString()); if (function.attributes.Find((obj) => obj.key == "on_off_usb") != null) { d.Add("on_off_usb", function.trait_on_off.curValue.ToString()); } Control.Ins.SendWriteCommand(function, d); }) { IsBackground = true }.Start(); }; } } }