wjc
2023-03-28 a9d1161b1df96e7ddad566335989a1444e433ef5
HDL_ON/UI/UI2/2-Classification/ClassificationPage.cs
@@ -1,8 +1,12 @@
using System;
using System.Collections.Generic;
using HDL_ON.DAL.Server;
using HDL_ON.DriverLayer;
using HDL_ON.Entity;
using HDL_ON.UI;
using HDL_ON.UI.CSS;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Shared;
namespace HDL_ON.UI
@@ -645,12 +649,19 @@
            var lastY2 = Application.GetRealWidth(16);
            var functionContentViewHeight = Application.GetRealWidth(16);
            foreach (var item in DB_ResidenceData.Instance.functionTypeList)
            foreach (var item in DB_ResidenceData.Instance.ShowFunctionTypeList)
            {
                int functionCount = 0;
                int functionOnCount = 0;
                switch (item)
                {
                    case ShowFunction.IpCam:
                        functionCount = FunctionList.List.GetIpCamImouList().Count;
                        break;
                    case ShowFunction.MechanicalArm:
                        functionCount = FunctionList.List.GetMechanicalArmList().Count;
                        functionOnCount = FunctionList.List.GetMechanicalArmList().FindAll((obj) => obj.trait_on_off.curValue.ToString() == "on").Count;
                        break;
                    case ShowFunction.Light:
                        #region Light
                        functionCount = FunctionList.List.GetLightList().Count;
@@ -730,10 +741,15 @@
                        //    functionCount = 1;
                        //}
                        break;
                    case ShowFunction.Acst:
                        functionCount = FunctionList.List.GetAcstParentList().Count;
                        functionOnCount = FunctionList.List.GetAcstParentList().FindAll((obj) => obj.trait_on_off.curValue.ToString() == "on").Count;
                        break;
                }
                if(functionCount == 0)
                if (functionCount == 0)
                {
                    continue;
                }
@@ -787,6 +803,7 @@
                if (item != ShowFunction.Environmental && item != ShowFunction.Sensor && item != ShowFunction.VideoIntercom
                    && item != ShowFunction.SecurityMonitoring && item != ShowFunction.FreshAir && item != ShowFunction.Music
                    && item != ShowFunction.EnergyMonitoring && item != ShowFunction.SecurityCenter
                    && item != ShowFunction.Acst && item != ShowFunction.IpCam
                    && functionCount != 0)
                {
                    Button btnFunctionCount = new Button()
@@ -852,6 +869,36 @@
                        functionPageTitleId = StringId.Lights;
                        #endregion
                        break;
                    case ShowFunction.IpCam:
                        btnName.TextID = StringId.SecurityMonitoring;
                        btnFunctionViewBg.UnSelectedImagePath = "FunctionIcon/FunctionBg/SecurityMonitoringFunctionBg.png";
                        functionPageTitleId = StringId.SecurityMonitoring;
                        break;
                    case ShowFunction.MechanicalArm:
                        btnName.TextID = StringId.MechanicalArm;
                        Button btnMaPower = new Button()
                        {
                            X = Application.GetRealWidth(120),
                            Y = specialList.Contains(index) ? Application.GetRealWidth(160) : Application.GetRealWidth(117),
                            Width = Application.GetRealWidth(32),
                            Height = Application.GetRealWidth(32),
                            SelectedImagePath = "Public/PowerOpen.png",
                            UnSelectedImagePath = "Public/PowerClose.png",
                            IsSelected = functionOnCount > 0,
                            Tag = item + "_AllControl",
                        };
                        functionView.AddChidren(btnMaPower);
                        btnMaPower.MouseUpEventHandler = (sender, e) =>
                        {
                            LoadEvent_SwitchFunction(btnMaPower, item, functionView);
                        };
                        functionPageTitleId = StringId.MechanicalArm;
                        break;
                    case ShowFunction.AC:
                        #region AC
@@ -932,7 +979,8 @@
                        break;
                    case ShowFunction.DoorLock:
                        btnName.TextID = StringId.DoorLock;
                        btnFunctionViewBg.MouseUpEventHandler = (sende, e) => {
                        btnFunctionViewBg.MouseUpEventHandler = (sende, e) =>
                        {
                            var form = new DoorLockListPage();
                            form.AddForm(FunctionList.List.GetDoorLockList());
                        };
@@ -962,7 +1010,8 @@
                    case ShowFunction.EnergyMonitoring:
                        #region 能源监测
                        btnName.TextID = StringId.EnergyMonitoring;
                        btnFunctionViewBg.MouseUpEventHandler = (sender, e) => {
                        btnFunctionViewBg.MouseUpEventHandler = (sender, e) =>
                        {
                            var skipView = new EnergyMainPage();
                            MainPage.BasePageView.AddChidren(skipView);
                            skipView.LoadPage();
@@ -1021,7 +1070,7 @@
                        btnName.TextID = StringId.Panel;
                        break;
                    case ShowFunction.SecurityMonitoring:
                        btnName.TextID = StringId.SecurityMonitoring;
                        btnName.TextID = StringId.EZVIZ;
                        btnFunctionViewBg.MouseUpEventHandler = (sender, e) =>
                        {
                            HDLCommon.Current.Go2EZvizMonitor(bodyView);
@@ -1049,11 +1098,58 @@
                            MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1;
                        };
                        break;
                    case ShowFunction.Acst:
                        btnName.TextID = StringId.Acst;
                        Button btnJMLogo = new Button()
                        {
                            Y = specialList.Contains(index) ? Application.GetRealWidth(147) : Application.GetRealWidth(104),
                            UnSelectedImagePath = "FunctionIcon/Acst/LvJianLogo.png",
                            Width = Application.GetRealWidth(105),
                            Height = Application.GetRealWidth(57),
                        };
                        functionView.AddChidren(btnJMLogo);
                        //Button btnAcstPower = new Button()
                        //{
                        //    X = Application.GetRealWidth(120),
                        //    Y = specialList.Contains(index) ? Application.GetRealWidth(160) : Application.GetRealWidth(117),
                        //    Width = Application.GetRealWidth(32),
                        //    Height = Application.GetRealWidth(32),
                        //    SelectedImagePath = "Public/PowerOpen.png",
                        //    UnSelectedImagePath = "Public/PowerClose.png",
                        //    IsSelected = functionOnCount > 0,
                        //    Tag = item + "_AllControl",
                        //};
                        //functionView.AddChidren(btnAcstPower);
                        //btnAcstPower.MouseUpEventHandler = (sender, e) =>
                        //{
                        //    btnAcstPower.IsSelected = !btnAcstPower.IsSelected;
                        //    string onoff = btnAcstPower.IsSelected ? "on" : "off";
                        //    Dictionary<string, string> d = new Dictionary<string, string>();
                        //    d.Add(FunctionAttributeKey.OnOff, onoff);
                        //    foreach (var temp in FunctionList.List.GetAcstParentList())
                        //    {
                        //        Control.Ins.SendWriteCommand(temp, d);
                        //    }
                        //};
                        btnFunctionViewBg.MouseUpEventHandler = (sender, e) =>
                        {
                            var page = new AcstParentPage();
                            MainPage.BasePageView.AddChidren(page);
                            page.LoadPage();
                            MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1;
                        };
                        break;
                }
                //界面跳转--音乐跳转自己的界面--环境跳转自己的界面
                if (item != ShowFunction.Music && item != ShowFunction.Environmental && item != ShowFunction.SecurityMonitoring && item != ShowFunction.DoorLock
                    && ShowFunction.EnergyMonitoring!= item && ShowFunction.VideoIntercom != item && ShowFunction.SecurityCenter != item)
                    && ShowFunction.EnergyMonitoring != item && ShowFunction.VideoIntercom != item && ShowFunction.SecurityCenter != item
                    && ShowFunction.Acst != item)
                {
                    btnFunctionViewBg.MouseUpEventHandler = (sender, e) =>
                    {
@@ -1065,22 +1161,17 @@
                }
                index++;
            }
            bool debugFlag = false;
            #if DEBUG
            debugFlag = true;
            #endif
            //光伏数据
            if (FunctionList.List.InverterList.Count > 0|| debugFlag)
            if (FunctionList.List.InverterList().Count > 0)
            {
                FrameLayout inverterListView = new FrameLayout()
                {
                    Height = Application.GetRealHeight(223),
                    Height = Application.GetRealHeight(204),
                    Radius = (uint)Application.GetRealWidth(6),
                    BackgroundColor = CSS_Color.MainBackgroundColor,
                    Tag =  "inverterList_View",
                    Tag = "inverterList_View",
                    Y = index % 2 == 1 ? lastY2 : lastY1
                };
                if (index % 2 == 1)
@@ -1106,7 +1197,7 @@
                Button btnName = new Button()
                {
                    X = Application.GetRealWidth(16),
                    Y = Application.GetRealHeight(22),//14),//
                    Y = Application.GetRealHeight(16),//14),//
                    Width = Application.GetRealWidth(140),
                    Height = Application.GetRealHeight(20),
                    TextColor = CSS_Color.FirstLevelTitleColor,
@@ -1118,24 +1209,77 @@
                };
                inverterListView.AddChidren(btnName);
                Button btnWorkStatus = new Button()
                Button btnFunctionCount = new Button()
                {
                    Y = Application.GetRealHeight(24),
                    Width = Application.GetRealWidth(148),
                    Height = Application.GetRealHeight(18),
                    TextAlignment = TextAlignment.CenterRight,
                    TextColor = 0xFF0BAF31,
                    TextID = StringId.NormalOperation,
                    TextSize = CSS_FontSize.TextFontSize
                    X = Application.GetRealWidth(17) + Application.GetRealWidth(7 * FunctionList.List.InverterList().Count.ToString().Length),
                    Y = btnName.Bottom,
                    Width = Application.GetRealWidth(120),
                    Height = Application.GetRealHeight(24),
                    TextColor = CSS_Color.PromptingColor1,
                    TextSize = CSS_FontSize.PromptFontSize_FirstLevel,
                    TextAlignment = TextAlignment.CenterLeft,
                    Text = "/" + FunctionList.List.InverterList().Count,
                };
                inverterListView.AddChidren(btnWorkStatus);
                inverterListView.AddChidren(btnFunctionCount);
                int count = 0;
                foreach (var temp in FunctionList.List.InverterList())
                {
                    if (temp.online)
                    {
                        if (temp.trait_on_off.state.ToString() == "on")
                        {
                            ++count;
                        }
                    }
                }
                Button btnOpenCount = new Button()
                {
                    X = Application.GetRealWidth(16),
                    Y = btnName.Bottom,
                    Width = Application.GetRealWidth(14 * count.ToString().Length),
                    Height = Application.GetRealHeight(24),
                    TextColor = CSS_Color.MainColor,
                    TextSize = CSS_FontSize.PromptFontSize_FirstLevel,
                    TextAlignment = TextAlignment.CenterLeft,
                    Text = count.ToString(),
                    Tag = "inverter_onCount",
                    BorderWidth = 0,
                };
                inverterListView.AddChidren(btnOpenCount);
                //Button btnWorkStatus = new Button()
                //{
                //    Y = Application.GetRealHeight(24),
                //    Width = Application.GetRealWidth(148),
                //    Height = Application.GetRealHeight(18),
                //    TextAlignment = TextAlignment.CenterRight,
                //    TextColor = 0xFF0BAF31,
                //    TextID = StringId.NormalOperation,
                //    TextSize = CSS_FontSize.TextFontSize
                //};
                //inverterListView.AddChidren(btnWorkStatus);
                Button btnWorkingModeIcon = new Button()
                {
                    X = Application.GetRealWidth(16),
                    Y = btnOpenCount.Bottom + Application.GetRealHeight(5),
                    Width = Application.GetRealWidth(14),
                    Height = Application.GetRealWidth(14),
                    UnSelectedImagePath = "FunctionIcon/Inverter/Icon1.png"
                };
                inverterListView.AddChidren(btnWorkingModeIcon);
                Button btnWorkingMode = new Button()
                {
                    X = Application.GetRealWidth(16),
                    Y = btnWorkStatus.Bottom + Application.GetRealHeight(16),
                    X = Application.GetRealWidth(37),
                    Y = btnOpenCount.Bottom + Application.GetRealHeight(5),// + Application.GetRealHeight(16),
                    Width = Application.GetRealWidth(148),
                    Height = Application.GetRealHeight(18),
                    Height = Application.GetRealHeight(14),
                    TextColor = CSS_Color.FirstLevelTitleColor,
                    TextSize = CSS_FontSize.PromptFontSize_FirstLevel,
                    TextID = StringId.WorkingMode,
@@ -1143,12 +1287,23 @@
                };
                inverterListView.AddChidren(btnWorkingMode);
                Button btnPowerTenerationToday = new Button()
                Button btnPowerTenerationTodayIcon = new Button()
                {
                    X = Application.GetRealWidth(16),
                    Y = btnWorkingMode.Bottom + Application.GetRealHeight(16),
                    Y = btnWorkingMode.Bottom + Application.GetRealHeight(10),
                    Width = Application.GetRealWidth(14),
                    Height = Application.GetRealWidth(14),
                    UnSelectedImagePath = "FunctionIcon/Inverter/Icon2.png"
                };
                inverterListView.AddChidren(btnPowerTenerationTodayIcon);
                Button btnPowerTenerationToday = new Button()
                {
                    X = Application.GetRealWidth(37),
                    Y = btnWorkingMode.Bottom + Application.GetRealHeight(10),
                    Width = Application.GetRealWidth(148),
                    Height = Application.GetRealHeight(18),
                    Height = Application.GetRealHeight(14),
                    TextColor = CSS_Color.FirstLevelTitleColor,
                    TextSize = CSS_FontSize.PromptFontSize_FirstLevel,
                    TextID = StringId.PowerTenerationToday,
@@ -1156,13 +1311,22 @@
                };
                inverterListView.AddChidren(btnPowerTenerationToday);
                Button btnCurrentPowerGenerationIcon = new Button()
                {
                    X = Application.GetRealWidth(16),
                    Y = btnPowerTenerationToday.Bottom + Application.GetRealHeight(10),
                    Width = Application.GetRealWidth(14),
                    Height = Application.GetRealWidth(14),
                    UnSelectedImagePath = "FunctionIcon/Inverter/Icon3.png"
                };
                inverterListView.AddChidren(btnCurrentPowerGenerationIcon);
                Button btnCurrentPowerGeneration = new Button()
                {
                    X = Application.GetRealWidth(16),
                    Y = btnPowerTenerationToday.Bottom + Application.GetRealHeight(16),
                    X = Application.GetRealWidth(37),
                    Y = btnPowerTenerationToday.Bottom + Application.GetRealHeight(10),
                    Width = Application.GetRealWidth(148),
                    Height = Application.GetRealHeight(18),
                    Height = Application.GetRealHeight(14),
                    TextColor = CSS_Color.FirstLevelTitleColor,
                    TextSize = CSS_FontSize.PromptFontSize_FirstLevel,
                    TextID = StringId.CurrentPowerGeneration,
@@ -1170,51 +1334,182 @@
                };
                inverterListView.AddChidren(btnCurrentPowerGeneration);
                Button btnBatterySOC = new Button()
                {
                    X = Application.GetRealWidth(16),
                    Y = btnCurrentPowerGeneration.Bottom + Application.GetRealHeight(16),
                    Width = Application.GetRealWidth(148),
                    Height = Application.GetRealHeight(18),
                    TextColor = CSS_Color.FirstLevelTitleColor,
                    TextSize = CSS_FontSize.PromptFontSize_FirstLevel,
                    TextID = StringId.BatterySOC,
                    TextAlignment = TextAlignment.CenterLeft,
                };
                inverterListView.AddChidren(btnBatterySOC);
                //Button btnBatterySOC = new Button()
                //{
                //    X = Application.GetRealWidth(37),
                //    Y = btnCurrentPowerGeneration.Bottom,
                //    Width = Application.GetRealWidth(148),
                //    Height = Application.GetRealHeight(18),
                //    TextColor = CSS_Color.FirstLevelTitleColor,
                //    TextSize = CSS_FontSize.PromptFontSize_FirstLevel,
                //    TextID = StringId.BatterySOC,
                //    TextAlignment = TextAlignment.CenterLeft,
                //};
                //inverterListView.AddChidren(btnBatterySOC);
                Button btnOperationDataTotalData = new Button()
                {
                    X = Application.GetRealWidth(16),
                    Y = btnBatterySOC.Bottom + Application.GetRealHeight(16),
                    Width = Application.GetRealWidth(148),
                    Height = Application.GetRealHeight(18),
                    TextColor = CSS_Color.FirstLevelTitleColor,
                    TextSize = CSS_FontSize.PromptFontSize_FirstLevel,
                    TextID = StringId.OperationDataTotalData,
                    TextAlignment = TextAlignment.CenterLeft,
                };
                inverterListView.AddChidren(btnOperationDataTotalData);
                //Button btnOperationDataTotalData = new Button()
                //{
                //    X = Application.GetRealWidth(16),
                //    Y = btnBatterySOC.Bottom + Application.GetRealHeight(16),
                //    Width = Application.GetRealWidth(148),
                //    Height = Application.GetRealHeight(18),
                //    TextColor = CSS_Color.FirstLevelTitleColor,
                //    TextSize = CSS_FontSize.PromptFontSize_FirstLevel,
                //    TextID = StringId.OperationDataTotalData,
                //    TextAlignment = TextAlignment.CenterLeft,
                //};
                //inverterListView.AddChidren(btnOperationDataTotalData);
                var clickButton = new Button();
                inverterListView.AddChidren(clickButton);
                clickButton.MouseUpEventHandler = (sender2, e2) => {
                    var h5BasePage = new FrameLayout();
                clickButton.MouseUpEventHandler = (sender2, e2) =>
                {
                    var h5BasePage = new FrameLayout() {
                        BackgroundColor = CSS_Color.MainBackgroundColor,
                    };
//#if __Android__
                    //适配沉浸式导航栏
                    h5BasePage.Y = Application.GetRealHeight(20);
                    h5BasePage.Height = Application.GetRealHeight(646);
//#endif
                    MainPage.BasePageView.AddChidren(h5BasePage);
                    MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1;
                    h5BasePage.AddChidren(Inverter.Ins.H5Page);
                    Inverter.Ins.ShowWebviewFormUrl("h5/index");
                    h5BasePage.AddChidren(Inverter.Ins.H5Page);//000
                    string lz = "zh";
                    if (Language.CurrentLanguage != "Chinese")
                    {
                        lz = "en";
                    }
                    string url = $"h5/index.html?homeId={DB_ResidenceData.Instance.CurrentRegion.id}&token={UserInfo.Current.AccessToken}&refresh_token={UserInfo.Current.RefreshToken}&url={OnAppConfig.Instance.RequestHttpsHost}&language={lz}";
                    Inverter.Ins.ShowWebviewFormUrl(url);
                    Inverter.Ins.H5Page.JSToNativeAction = (dictionary) =>
                    {
                        JObject jObj = JObject.Parse(Newtonsoft.Json.JsonConvert.SerializeObject(dictionary));
                        if (!jObj.ContainsKey("method") || !jObj.ContainsKey("data"))
                        {
                            return;
                        }
                        if (jObj["method"].ToString() == "control" && jObj["data"].Type == JTokenType.Object)
                        {//控制
                            var data = JObject.FromObject(jObj["data"]);
                            if (!data.ContainsKey("sid") || !data.ContainsKey("on_off"))
                            {
                                return;
                            }
                            var function = new Function();
                            function.sid = data["sid"].ToString();
                            var inObj = FunctionList.List.InverterList().Find((obj) => obj.sid == function.sid);
                            if (inObj == null)
                            {
                                return;
                            }
                            function.deviceId = inObj.deviceId;
                            //function.spk = inObj.spk;
                            var status = new Dictionary<string, string>() { ["on_off"] = data["on_off"].ToString() };
                            Control.Ins.SendWriteCommand(function, status);
                        }
                        else if (jObj["method"].ToString() == "back")
                        {
                            Application.RunOnMainThread(() =>
                            {
                                h5BasePage.RemoveFromParent();
                            });
                            refreshInverterInfo(btnPowerTenerationToday, btnWorkingMode, btnCurrentPowerGeneration);
                        }
                        else if (jObj["method"].ToString() == "setPageIndex")
                        {
                            var data = jObj["data"].ToString();
                            Inverter.Ins.PageIndex = data.ToString();
                        }
                    };
                };
                refreshInverterInfo(btnPowerTenerationToday, btnWorkingMode, btnCurrentPowerGeneration);
                index++;
            }
            s1View.Height = s2View.Height = functionContentView.Height = functionContentViewHeight+ Application.GetRealWidth(40);
            s1View.Height = s2View.Height = functionContentView.Height = functionContentViewHeight + Application.GetRealWidth(40);
#endregion
            #endregion
        }
        void refreshInverterInfo(Button btnPowerTenerationToday, Button btnWorkingMode, Button btnCurrentPowerGeneration)
        {
            new System.Threading.Thread(() =>
            {
                var http = new HttpServerRequest();
                var pack = http.GetInverterStatisticsInfo();
                if (pack != null)
                {
                    if(pack.Data == null)
                    {
                        return;
                    }
                    var info = JsonConvert.DeserializeObject<StatisticsInfo>(pack.Data?.ToString());
                    if (info == null)
                    {
                        return;
                    }
                    try
                    {
                        Application.RunOnMainThread(() =>
                        {
                            btnPowerTenerationToday.Text = info.totalElectricityPvToday + "kW·h";// Language.StringByID(StringId.PowerTenerationToday).Replace("----", info.totalElectricityPvToday);
                            string workModeString = "";
                            if (Language.CurrentLanguage == "Chinese") {
                                switch (info.workMode)
                                {
                                    case "self_use":
                                        workModeString = "自发自用";
                                        break;
                                    case "peak_load_shifting":
                                        workModeString = "削峰填谷";
                                        break;
                                    case "battery_priority":
                                        workModeString = "电池优先";
                                        break;
                                }
                            }
                            else
                            {
                                switch (info.workMode)
                                {
                                    case "self_use":
                                        workModeString = "Self Consume";
                                        break;
                                    case "peak_load_shifting":
                                        workModeString = "Peak Shift";
                                        break;
                                    case "battery_priority":
                                        workModeString = "Battery Priority";
                                        break;
                                }
                            }
                            btnWorkingMode.Text = workModeString;// Language.StringByID(StringId.WorkingMode).Replace("----", workModeString);
                            btnCurrentPowerGeneration.Text = info.powerPvNow + "w";// Language.StringByID(StringId.CurrentPowerGeneration).Replace("----", info.powerPvNow);
                            //btnBatterySOC.Text = Language.StringByID(StringId.BatterySOC).Replace("--", info.batterySoc);
                        });
                    }
                    catch (Exception ex)
                    {
                        MainPage.Log($"获取家庭光伏统计数据异常:{ex.Message}");
                    }
                }
            })
            { IsBackground = true }.Start();
        }
#region 切换楼层
@@ -1313,7 +1608,7 @@
                foreach (var floor in chooseList)
                {
                    if (!string.IsNullOrEmpty( floor.roomId))// != Language.StringByID(StringId.All))
                    if (!string.IsNullOrEmpty( floor.roomId))
                    {
                        //---分割线
                        contentView.AddChidren(new Button()
@@ -1376,4 +1671,4 @@
        }
#endregion
    }
}
}