wjc
2022-01-19 07b0239f824ddb5a0cadf93f20ff6247f72baca2
HDL_ON/UI/UI2/FuntionControlView/Electrical/SocketPage.cs
@@ -2,6 +2,7 @@
using Shared;
using HDL_ON.UI.CSS;
using HDL_ON.Entity;
using HDL_ON.DriverLayer;
namespace HDL_ON.UI
{
@@ -132,6 +133,94 @@
            };
            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<MouseEventArgs> 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();
                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<MouseEventArgs> 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);
@@ -143,4 +232,98 @@
        }
    }
    public partial class SocketPage
    {
        /// <summary>
        /// 更新灯光状态
        /// </summary>
        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}");
                }
            });
        }
        /// <summary>
        /// 加载事件列表
        /// </summary>
        void LoadEventList()
        {
            LoadSwitchEvent();
            LoadCollectionEvent();
            //回退刷新信息事件
            actionRefresh = () => {
                btnFunctionName.Text = btnFunctionName_Out.Text = function.name;
                btnFromFloor_Out.Text = btnFromFoorAndRoom.Text = function.GetRoomListName();
                function.UpdataFuncitonInfo();
            };
        }
        /// <summary>
        /// 收藏功能按钮事件
        /// </summary>
        void LoadCollectionEvent()
        {
            btnCollection.MouseUpEventHandler += (sender, e) => {
                btnCollection.IsSelected = function.collect = btnCollection_Out.IsSelected = !btnCollection.IsSelected;
                function.CollectFunction();
            };
        }
        /// <summary>
        /// 加载开关事件
        /// </summary>
        void LoadSwitchEvent()
        {
            btnSwitchIcon.MouseUpEventHandler += (sender, e) =>
            {
                btnSwitchIcon.IsSelected = btnSwitch.IsSelected = !btnSwitchIcon.IsSelected;
                new System.Threading.Thread(() =>
                {
                    function.trait_on_off.curValue = btnSwitch.IsSelected ? "on" : "off";
                    System.Collections.Generic.Dictionary<string, string> d = new System.Collections.Generic.Dictionary<string, string>();
                    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) =>
            {
                btnSwitch.IsSelected = btnSwitchIcon.IsSelected = !btnSwitch.IsSelected;
                new System.Threading.Thread(() =>
                {
                    function.trait_on_off.curValue = btnSwitch.IsSelected ? "on" : "off";
                    System.Collections.Generic.Dictionary<string, string> d = new System.Collections.Generic.Dictionary<string, string>();
                    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();
            };
        }
    }
}