| | |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using HDL_ON.DAL.Server; |
| | | using HDL_ON.DriverLayer; |
| | | using HDL_ON.Entity; |
| | | using HDL_ON.UI.CSS; |
| | | using Shared; |
| | |
| | | { |
| | | public class EnergyMainPage : FrameLayout |
| | | { |
| | | FrameLayout bodyView; |
| | | static EnergyMainPage bodyView; |
| | | |
| | | /// <summary> |
| | | /// 顶部区域 |
| | | /// </summary> |
| | | FrameLayout generalTableView; |
| | | |
| | | /// <summary> |
| | | /// 实时功耗 |
| | | /// </summary> |
| | | Button btnRealTimeData; |
| | | /// <summary> |
| | | /// 实时功耗单位 |
| | | /// </summary> |
| | | Button btnTotalValueUint; |
| | | /// <summary> |
| | | /// 总功耗 |
| | | /// </summary> |
| | | TextButton btnTotalValue; |
| | | /// <summary> |
| | | /// 总功耗-饼图 |
| | | /// </summary> |
| | | MyEchartsViewOn myEchartsView_Pie; |
| | | /// <summary> |
| | | /// 历史数据区域 |
| | | /// </summary> |
| | | FrameLayout diagramView; |
| | | /// <summary> |
| | | /// 曲线图数据string |
| | | /// </summary> |
| | | EchartsOption_BrokenLine brokenLine; |
| | | /// <summary> |
| | | /// 曲线图下拉按钮 |
| | | /// </summary> |
| | | Button btnDrodDown; |
| | | |
| | | |
| | | /// <summary> |
| | | /// 插查询的能源列表 |
| | | /// </summary> |
| | | List<Function> queryList = new List<Function>(); |
| | | /// <summary> |
| | | /// 查询条件 |
| | | /// hour、week、month |
| | | /// </summary> |
| | | string curQueryType = "hour"; |
| | | |
| | | |
| | | /// <summary> |
| | | /// 能源列表区域 |
| | | /// </summary> |
| | | FrameLayout energyListView; |
| | | /// <summary> |
| | | /// 历史数据图表 |
| | | /// </summary> |
| | | MyEchartsViewOn myEchartsView_Line; |
| | | /// <summary> |
| | | /// 曲线图是否展开 |
| | | /// </summary> |
| | | bool isUnfoldOrStow = false; |
| | | |
| | | List<Function> energyList = new List<Function>(); |
| | | |
| | | List<uint> colorList = new List<uint>(){0xFF80AEFF, 0xFFFFD154, 0xFFFF9D54, 0xFFFE6A6A, 0xFFB183C3, 0xFFADE764, |
| | | 0xFFD7504B, 0xFFC6E579, 0xFFF4E001, 0xFFF0805A, 0xFF26C0C0}; |
| | | List<string> colorList2 = new List<string>() { |
| | | "#80AEFF", "#FFD154", "#FF9D54", "#FE6A6A", "#B183C3", "#ADE764", |
| | | "#D7504B", "#C6E579", "#F4E001", "#F0805A", "#26C0C0"}; |
| | | |
| | | /// <summary> |
| | | /// 主页 |
| | | /// </summary> |
| | | public EnergyMainPage() |
| | | { |
| | | bodyView = this; |
| | | energyList = FunctionList.List.GetEnergyList(); |
| | | var breaker = FunctionList.List.Functions.FindAll((obj) => obj.spk == SPK.AirSwitch); |
| | | var energyBreker = breaker.FindAll((obj) => obj.GetAttribute("power") != null); |
| | | energyList.AddRange(energyBreker); |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | bodyView.AddChidren(contentView); |
| | | |
| | | #region 顶部view |
| | | var generalTableView = new FrameLayout() |
| | | generalTableView = new FrameLayout() |
| | | { |
| | | Gravity = Gravity.CenterHorizontal, |
| | | Y = Application.GetRealHeight(16), |
| | | Y = Application.GetRealWidth(16), |
| | | Width = Application.GetRealWidth(343), |
| | | Height = Application.GetRealWidth(148), |
| | | Height = Application.GetRealWidth(148),//419//148 |
| | | Radius = (uint)Application.GetRealWidth(5), |
| | | BackgroundColor = CSS_Color.MainBackgroundColor, |
| | | }; |
| | | contentView.AddChidren(generalTableView); |
| | | |
| | | TextButton btnTotalValue = new TextButton() |
| | | btnTotalValue = new TextButton() |
| | | { |
| | | X = Application.GetRealWidth(18), |
| | | Y = Application.GetRealWidth(24), |
| | |
| | | }; |
| | | generalTableView.AddChidren(btnTotalValue); |
| | | |
| | | btnTotalValue.Width = btnTotalValue.GetTextWidth(); |
| | | |
| | | var btnTotalValueUint = new Button() |
| | | btnTotalValueUint = new Button() |
| | | { |
| | | X = btnTotalValue.Right, |
| | | Y = Application.GetRealWidth(24), |
| | |
| | | }; |
| | | generalTableView.AddChidren(btnTotalValueUint); |
| | | |
| | | var btnRealTimeData = new Button() |
| | | btnRealTimeData = new Button() |
| | | { |
| | | X = Application.GetRealWidth(18), |
| | | Y = btnTotalValue.Bottom, |
| | |
| | | TextID = StringId.RealTimePowerConsumption, |
| | | }; |
| | | generalTableView.AddChidren(btnRealTimeData); |
| | | btnRealTimeData.Text = Language.StringByID(StringId.RealTimePowerConsumption).Replace("{0}", "0"); |
| | | |
| | | |
| | | var echartsView = new FrameLayout() |
| | | { |
| | |
| | | //Y = Application.GetRealWidth(16), |
| | | }; |
| | | generalTableView.AddChidren(echartsView); |
| | | MyEchartsViewOn myEchartsView = new MyEchartsViewOn() { |
| | | myEchartsView_Pie = new MyEchartsViewOn() |
| | | { |
| | | Width = Application.GetRealWidth(118), |
| | | Height = Application.GetRealWidth(118), |
| | | }; |
| | | echartsView.AddChidren(myEchartsView_Pie); |
| | | |
| | | echartsView.AddChidren(myEchartsView); |
| | | Dictionary<string, string> list = new Dictionary<string, string>(); |
| | | list.Add("电冰箱", "12"); |
| | | list.Add("电风扇", "2"); |
| | | list.Add("空调", "9"); |
| | | list.Add("洗衣机", "3"); |
| | | list.Add("电脑", "33"); |
| | | var echartsPie = new EchartsOption_Pie(); |
| | | var echartRootJson = echartsPie.InitDateJson(list); |
| | | //var echartRootJsonString = Newtonsoft.Json.JsonConvert.SerializeObject(echartRootJson); |
| | | myEchartsView.ShowWithOption(echartRootJson); |
| | | foreach(var ene in energyList) |
| | | { |
| | | double tt = 0; |
| | | double.TryParse(ene.GetAttrState(FunctionAttributeKey.TotalElectricity), out tt); |
| | | tt *= 100;//乘以100,小于1无法加载echart |
| | | tt = Math.Round(tt, 2); |
| | | list.Add(ene.name, tt.ToString()); |
| | | } |
| | | myEchartsView_Pie.ShowWithOption(new EchartsOption_Pie().InitDateJson(list)); |
| | | |
| | | |
| | | var btnDrodDown = new Button() |
| | | btnDrodDown = new Button() |
| | | { |
| | | Y = Application.GetRealWidth(118), |
| | | Width = Application.GetRealWidth(343), |
| | | Height = Application.GetRealWidth(30), |
| | | UnSelectedImagePath = "FunctionIcon/Energy/EnergyDrodDownIcon.png", |
| | | SelectedImagePath = "FunctionIcon/Energy/EnergyDrodUpIcon.png", |
| | | }; |
| | | initDiagramView(); |
| | | generalTableView.AddChidren(btnDrodDown); |
| | | btnDrodDown.MouseUpEventHandler = (sender, e) => { |
| | | isUnfoldOrStow = btnDrodDown.IsSelected = !btnDrodDown.IsSelected; |
| | | showDiagramView(); |
| | | }; |
| | | |
| | | UpdataValue(); |
| | | #endregion |
| | | |
| | | |
| | | var energyList = FunctionList.List.GetEnergyList(); |
| | | var energyListView = new FrameLayout() |
| | | energyListView = new FrameLayout() |
| | | { |
| | | Y = generalTableView.Bottom + Application.GetRealWidth(8), |
| | | Height = Application.GetRealWidth(116 * energyList.Count) , |
| | | Height = Application.GetRealWidth(116 * energyList.Count + 50), |
| | | }; |
| | | contentView.AddChidren(energyListView); |
| | | int index = 0; |
| | | foreach(var energy in energyList) |
| | | foreach (var energy in energyList) |
| | | { |
| | | EnergyRow(energy, energyListView, index); |
| | | index++; |
| | | new System.Threading.Thread(() => |
| | | { |
| | | Control.Ins.SendReadCommand(energy); |
| | | }) |
| | | { IsBackground = true }.Start(); |
| | | } |
| | | |
| | | |
| | | } |
| | | |
| | | public void ddd(FrameLayout contentView) |
| | | /// <summary> |
| | | /// |
| | | /// </summary> |
| | | void showDiagramView() |
| | | { |
| | | |
| | | FrameLayout diagramView = new FrameLayout() |
| | | if (isUnfoldOrStow)//展开 |
| | | { |
| | | generalTableView.Height = Application.GetRealWidth(419); |
| | | btnDrodDown.Y = Application.GetRealWidth(389); |
| | | btnDrodDown.IsSelected = true; |
| | | } |
| | | else |
| | | { |
| | | generalTableView.Height = Application.GetRealWidth(148); |
| | | btnDrodDown.Y = Application.GetRealWidth(118); |
| | | btnDrodDown.IsSelected = false; |
| | | } |
| | | |
| | | energyListView.Y = generalTableView.Bottom + Application.GetRealWidth(8); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 加载曲线图 |
| | | /// </summary> |
| | | /// <param name="contentView"></param> |
| | | void initDiagramView() |
| | | { |
| | | brokenLine = new EchartsOption_BrokenLine(); |
| | | |
| | | |
| | | diagramView = new FrameLayout() |
| | | { |
| | | Y = Application.GetRealWidth(136), |
| | | Gravity = Gravity.CenterHorizontal, |
| | | Width = Application.GetRealWidth(343), |
| | | Height = Application.GetRealWidth(420), |
| | | Height = Application.GetRealWidth(281), |
| | | BackgroundColor = CSS_Color.MainBackgroundColor, |
| | | Radius = (uint)Application.GetRealWidth(12), |
| | | BorderColor = 0x00000000, |
| | | BorderWidth = 0, |
| | | }; |
| | | contentView.AddChidren(diagramView); |
| | | generalTableView.AddChidren(diagramView); |
| | | |
| | | #region 选择数据日期范围 |
| | | var showDataTypeView = new FrameLayout() |
| | |
| | | TextColor = CSS_Color.PromptingColor2, |
| | | SelectedTextColor = CSS_Color.MainColor, |
| | | TextSize = CSS_FontSize.PromptFontSize_FirstLevel, |
| | | Text = DateTime.Now.Month.ToString() + Language.StringByID(StringId.month), |
| | | Text = Language.StringByID(StringId.month),//DateTime.Now.Month.ToString() + |
| | | }; |
| | | showDataTypeView.AddChidren(btnShowHistroyData_Month); |
| | | |
| | | |
| | | btnShowHistroyData_Day.MouseUpEventHandler = (sender, e) => |
| | | { |
| | | showDataTypeView.BackgroundImagePath = "FunctionIcon/EnvironmentalScience/SensorHistoryBg1.png"; |
| | | btnShowHistroyData_Day.IsSelected = true; |
| | | btnShowHistroyData_Month.IsSelected = false; |
| | | btnShowHistroyData_Week.IsSelected = false; |
| | | curQueryType = "hour"; |
| | | brokenLine.YvalueText = ""; |
| | | foreach (var enery in queryList) |
| | | { |
| | | LoadMothed_GetHistoryData(enery,false); |
| | | } |
| | | }; |
| | | |
| | | btnShowHistroyData_Week.MouseUpEventHandler = (sender, e) => |
| | | { |
| | | showDataTypeView.BackgroundImagePath = "FunctionIcon/EnvironmentalScience/SensorHistoryBg2.png"; |
| | | btnShowHistroyData_Day.IsSelected = false; |
| | | btnShowHistroyData_Month.IsSelected = false; |
| | | btnShowHistroyData_Week.IsSelected = true; |
| | | curQueryType = "week"; |
| | | brokenLine.YvalueText = ""; |
| | | foreach (var enery in queryList) |
| | | { |
| | | LoadMothed_GetHistoryData(enery, false); |
| | | } |
| | | }; |
| | | btnShowHistroyData_Month.MouseUpEventHandler = (sender, e) => |
| | | { |
| | | showDataTypeView.BackgroundImagePath = "FunctionIcon/EnvironmentalScience/SensorHistoryBg3.png"; |
| | | btnShowHistroyData_Day.IsSelected = false; |
| | | btnShowHistroyData_Month.IsSelected = true; |
| | | btnShowHistroyData_Week.IsSelected = false; |
| | | curQueryType = "month"; |
| | | brokenLine.YvalueText = ""; |
| | | foreach (var enery in queryList) |
| | | { |
| | | LoadMothed_GetHistoryData(enery, false); |
| | | } |
| | | }; |
| | | |
| | | #endregion |
| | | |
| | | var historyDataView = new FrameLayout() |
| | | { |
| | | Gravity = Gravity.CenterHorizontal, |
| | | Y = Application.GetRealHeight(52), |
| | | Width = Application.GetRealWidth(343 - 32), |
| | | Height = Application.GetRealHeight(270), |
| | | Y = Application.GetRealWidth(52), |
| | | Height = Application.GetRealWidth(190), |
| | | }; |
| | | diagramView.AddChidren(historyDataView); |
| | | |
| | | var myEchartsView = new MyEchartsViewOn(); |
| | | |
| | | historyDataView.AddChidren(myEchartsView); |
| | | |
| | | myEchartsView_Line = new MyEchartsViewOn() |
| | | { |
| | | Y = Application.GetRealWidth(10), |
| | | Height = Application.GetRealWidth(180), |
| | | }; |
| | | historyDataView.AddChidren(myEchartsView_Line); |
| | | } |
| | | /// <summary> |
| | | /// 读取传感器历史数据 |
| | | /// </summary> |
| | | void ddd2(string curQueryType,Function function,int index) |
| | | |
| | | /// <summary> |
| | | /// 读取历史数据 |
| | | /// </summary> |
| | | void LoadMothed_GetHistoryData(Function sr,bool isDel) |
| | | { |
| | | if(isDel)//删除数据现实 |
| | | { |
| | | var seriesList = new List<EchartSeriesItem>(); |
| | | var loadPage = new Loading() |
| | | brokenLine.YvalueText = ""; |
| | | foreach (var ene in queryList) |
| | | { |
| | | LodingBackgroundColor = 0x88888888, |
| | | }; |
| | | historyDataView.AddChidren(loadPage); |
| | | brokenLine.YvalueText += ene.GetAttrState("ydata"); |
| | | } |
| | | var opString = brokenLine.InitOption(); |
| | | |
| | | new System.Threading.Thread(() => |
| | | Application.RunOnMainThread(() => |
| | | { |
| | | try |
| | | myEchartsView_Line.ShowWithOption(opString); |
| | | }); |
| | | |
| | | return; |
| | | } |
| | | |
| | | var loadPage = new Loading() |
| | | { |
| | | LodingBackgroundColor = 0x88888888, |
| | | }; |
| | | diagramView.AddChidren(loadPage); |
| | | |
| | | new System.Threading.Thread(() => |
| | | { |
| | | try |
| | | { |
| | | Application.RunOnMainThread(() => |
| | | { |
| | | Application.RunOnMainThread(() => |
| | | { |
| | | loadPage.Start(Language.StringByID(StringId.PleaseWait)); |
| | | }); |
| | | int i = 0; |
| | | loadPage.Start(Language.StringByID(StringId.PleaseWait)); |
| | | }); |
| | | |
| | | var sensorType = sr.spk.Split(".")[1]; |
| | | var revertObj = new HttpServerRequest().GetSensorHistory(curQueryType, sr.deviceId, "total_electricity"); |
| | | if (revertObj != null) |
| | | { |
| | | if (revertObj.Code == StateCode.SUCCESS) |
| | | { |
| | | var sensorType = function.spk.Split(".")[0]; |
| | | var revertObj = new HttpServerRequest().GetSensorHistory(curQueryType, function.deviceId, sensorType); |
| | | var revertData = Newtonsoft.Json.JsonConvert.DeserializeObject<List<EnvironmentalSensorHistor>>(revertObj.Data.ToString()); |
| | | |
| | | if (revertObj != null) |
| | | List<string> vs = new List<string>(); |
| | | if (brokenLine.YvalueText == "") |
| | | { |
| | | if (revertObj.Code == StateCode.SUCCESS) |
| | | foreach (var data in revertData) |
| | | { |
| | | var revertData = Newtonsoft.Json.JsonConvert.DeserializeObject<List<EnvironmentalSensorHistor>>(revertObj.Data.ToString()); |
| | | |
| | | var sItem = new EchartSeriesItem |
| | | { |
| | | data = new List<int>(), |
| | | lineStyle = new EchartLineStyle() |
| | | { |
| | | color = colorList2[i], |
| | | #if __IOS__ |
| | | width = 5, |
| | | #elif __ANDROID__ |
| | | width = 2, |
| | | #endif |
| | | }, |
| | | }; |
| | | |
| | | foreach (var d in revertData) |
| | | { |
| | | echartRootJson.xAxis.data.Add(d.fieldName); |
| | | echartRootJson.yAxis.data.Add(d.fieldValue); |
| | | } |
| | | seriesList.Add(sItem); |
| | | vs.Add(data.fieldName); |
| | | } |
| | | else |
| | | { |
| | | Application.RunOnMainThread(() => |
| | | { |
| | | IMessageCommon.Current.ShowErrorInfoAlter("", true, 2, Language.StringByID(StringId.GetSensorHistoryFailed), false); |
| | | }); |
| | | } |
| | | brokenLine.InitXdataText(vs); |
| | | } |
| | | i++; |
| | | if (sr.GetAttribute("ydata") == null) |
| | | { |
| | | sr.attributes.Add(new FunctionAttributes() { key = "ydata" }); |
| | | } |
| | | sr.SetAttrState("ydata", brokenLine.InitYdataText(sr.name, revertData, sr.GetAttrState("color")) + ","); |
| | | } |
| | | |
| | | } |
| | | catch (Exception ex) |
| | | brokenLine.yTitle = Language.StringByID(StringId.EnergyConsumption) + "(kW)"; |
| | | brokenLine.xTitle = Language.StringByID(StringId.timeMode); |
| | | if(curQueryType != "hour") |
| | | { |
| | | MainPage.Log($"sensor history error : {ex.Message}"); |
| | | brokenLine.xTitle = Language.StringByID(StringId.Date); |
| | | } |
| | | finally |
| | | var opString = brokenLine.InitOption(); |
| | | |
| | | Application.RunOnMainThread(() => |
| | | { |
| | | Application.RunOnMainThread(() => |
| | | { |
| | | loadPage.Hide(); |
| | | }); |
| | | } |
| | | }) |
| | | { IsBackground = true }.Start(); |
| | | EchartsOption echartRootJson = new EchartsOption(); |
| | | echartRootJson.series = seriesList; |
| | | |
| | | |
| | | #if __IOS__ |
| | | echartRootJson.xAxis.axisLabel.fontSize = 22; |
| | | echartRootJson.yAxis.axisLabel.fontSize = 22; |
| | | #else |
| | | echartRootJson.xAxis.axisLabel.fontSize = 8; |
| | | echartRootJson.yAxis.axisLabel.fontSize = 8; |
| | | #endif |
| | | var echartRootJsonString = Newtonsoft.Json.JsonConvert.SerializeObject(echartRootJson); |
| | | myEchartsView.ShowWithOptionJsonString(echartRootJsonString); |
| | | |
| | | } |
| | | |
| | | var curQueryType = ""; |
| | | |
| | | void LoadEvent_ChangeSensorHistoryShowType() |
| | | { |
| | | btnShowHistroyData_Day.MouseUpEventHandler = (sender, e) => |
| | | myEchartsView_Line.ShowWithOption(opString); |
| | | }); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | showDataTypeView.BackgroundImagePath = "FunctionIcon/EnvironmentalScience/SensorHistoryBg1.png"; |
| | | btnShowHistroyData_Day.IsSelected = true; |
| | | btnShowHistroyData_Month.IsSelected = false; |
| | | btnShowHistroyData_Week.IsSelected = false; |
| | | curQueryType = "hour"; |
| | | LoadMothed_GetSensorHistoryData(); |
| | | }; |
| | | |
| | | btnShowHistroyData_Month.MouseUpEventHandler = (sender, e) => |
| | | MainPage.Log($"sensor history error : {ex.Message}"); |
| | | } |
| | | finally |
| | | { |
| | | showDataTypeView.BackgroundImagePath = "FunctionIcon/EnvironmentalScience/SensorHistoryBg3.png"; |
| | | btnShowHistroyData_Day.IsSelected = false; |
| | | btnShowHistroyData_Month.IsSelected = true; |
| | | btnShowHistroyData_Week.IsSelected = false; |
| | | curQueryType = "week"; |
| | | LoadMothed_GetSensorHistoryData(); |
| | | }; |
| | | btnShowHistroyData_Week.MouseUpEventHandler = (sender, e) => |
| | | { |
| | | showDataTypeView.BackgroundImagePath = "FunctionIcon/EnvironmentalScience/SensorHistoryBg2.png"; |
| | | btnShowHistroyData_Day.IsSelected = false; |
| | | btnShowHistroyData_Month.IsSelected = false; |
| | | btnShowHistroyData_Week.IsSelected = true; |
| | | curQueryType = "month"; |
| | | LoadMothed_GetSensorHistoryData(); |
| | | }; |
| | | |
| | | } |
| | | |
| | | Application.RunOnMainThread(() => |
| | | { |
| | | loadPage.Hide(); |
| | | }); |
| | | } |
| | | }) |
| | | { IsBackground = true }.Start(); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// |
| | |
| | | }; |
| | | view.AddChidren(btnLine); |
| | | |
| | | var row = new FrameLayout() |
| | | //定义代表色 |
| | | energy.attributes.Add(new FunctionAttributes() { key = "color", state = colorList2[index] }); |
| | | |
| | | var row = new EnergyRow(energy, colorList[index]); |
| | | |
| | | row.SetHistory_Action = (isAdd) => |
| | | { |
| | | Y = btnLine.Bottom, |
| | | Gravity = Gravity.CenterHorizontal, |
| | | Width = Application.GetRealWidth(343), |
| | | Height = Application.GetRealWidth(100), |
| | | Radius = (uint)Application.GetRealWidth(12), |
| | | BackgroundColor = CSS_Color.MainBackgroundColor, |
| | | if (isAdd) |
| | | { |
| | | if(!isUnfoldOrStow)//如果曲线图没有加载出来,则自动加载出来 |
| | | { |
| | | isUnfoldOrStow = true; |
| | | showDiagramView(); |
| | | } |
| | | queryList.Add(row.function); |
| | | LoadMothed_GetHistoryData(row.function, false); |
| | | } |
| | | else |
| | | { |
| | | queryList.Remove(row.function); |
| | | LoadMothed_GetHistoryData(row.function, true); |
| | | if (queryList.Count == 0)//如果查询列表为0,自动收起曲线图 |
| | | { |
| | | isUnfoldOrStow = false; |
| | | showDiagramView(); |
| | | } |
| | | } |
| | | }; |
| | | |
| | | |
| | | row.Y = btnLine.Bottom; |
| | | view.AddChidren(row); |
| | | //记录需要更新的更新按钮 |
| | | listButton_value.Add(row.btnValue); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 记录需要更新的更新按钮 |
| | | /// </summary> |
| | | public List<Button> listButton_value = new List<Button>(); |
| | | |
| | | /// <summary> |
| | | /// 更新功能状态 |
| | | /// </summary> |
| | | public static void UpdataStatus(Function updataTemp) |
| | | { |
| | | Application.RunOnMainThread(() => |
| | | { |
| | | try |
| | | { |
| | | if (bodyView == null) |
| | | return; |
| | | foreach (var btn in bodyView.listButton_value) |
| | | { |
| | | if (btn.Tag.ToString() == updataTemp.sid) |
| | | { |
| | | var newValue = updataTemp.GetAttrState(FunctionAttributeKey.Power); |
| | | //if (newValue != btn.Text) |
| | | { |
| | | btn.Text = Math.Round(double.Parse(newValue), 2).ToString();// +"W"; |
| | | UpdataValue(); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | MainPage.Log($"{bodyView.GetType().Name } UpdataStates error : {ex.Message}"); |
| | | } |
| | | }); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 更新数据 |
| | | /// </summary> |
| | | static void UpdataValue() |
| | | { |
| | | double totalValue = 0; |
| | | double realtimeValue = 0; |
| | | Dictionary<string, string> list = new Dictionary<string, string>();//饼图数据 |
| | | foreach (var ene in bodyView.energyList) |
| | | { |
| | | double power = 0.00; |
| | | double.TryParse(ene.GetAttrState(FunctionAttributeKey.TotalElectricity), out power); |
| | | power = Math.Round(power, 2); |
| | | totalValue += power; |
| | | |
| | | double realTimePower = 0; |
| | | double.TryParse(ene.GetAttrState(FunctionAttributeKey.Power), out realTimePower); |
| | | realtimeValue += realTimePower; |
| | | realtimeValue = Math.Round(realtimeValue, 2); |
| | | |
| | | #region 饼图数据 |
| | | double tt = 0.00; |
| | | double.TryParse(ene.GetAttrState(FunctionAttributeKey.TotalElectricity), out tt); |
| | | tt = Math.Round(tt, 2); |
| | | tt *= 100;//乘以100,小于1无法加载echart |
| | | list.Add(ene.name, tt.ToString()); |
| | | #endregion |
| | | } |
| | | bodyView.btnTotalValue.Text = totalValue.ToString(); |
| | | realtimeValue /= 1000; |
| | | bodyView.btnRealTimeData.Text = Language.StringByID(StringId.RealTimePowerConsumption).Replace("{0}", realtimeValue.ToString()); |
| | | ///动态获取文本宽度 |
| | | bodyView.btnTotalValue.Width = bodyView.btnTotalValue.GetTextWidth() + Application.GetRealWidth(5); |
| | | bodyView.btnTotalValueUint.X = bodyView.btnTotalValue.Right; |
| | | //刷新饼图 |
| | | bodyView.myEchartsView_Pie.ShowWithOption(new EchartsOption_Pie().InitDateJson(list)); |
| | | |
| | | } |
| | | } |
| | | |
| | | |
| | | public class EnergyRow : FrameLayout |
| | | { |
| | | public Button btnValue; |
| | | Button btnShowData; |
| | | public Function function; |
| | | public Action<bool> SetHistory_Action; |
| | | public EnergyRow(Function energy, uint color) |
| | | { |
| | | function = energy; |
| | | Gravity = Gravity.CenterHorizontal; |
| | | Width = Application.GetRealWidth(343); |
| | | Height = Application.GetRealWidth(100); |
| | | Radius = (uint)Application.GetRealWidth(12); |
| | | BackgroundColor = CSS_Color.MainBackgroundColor; |
| | | Tag = energy.sid; |
| | | |
| | | var btnColorTip = new Button() |
| | | { |
| | |
| | | Y = Application.GetRealWidth(16), |
| | | Width = Application.GetRealWidth(12), |
| | | Height = Application.GetRealWidth(12), |
| | | BackgroundColor = colorList[index], |
| | | BackgroundColor = color |
| | | }; |
| | | row.AddChidren(btnColorTip); |
| | | AddChidren(btnColorTip); |
| | | |
| | | var btnName = new Button() |
| | | { |
| | | X = Application.GetRealWidth(8 + 10 + 32), |
| | | X = Application.GetRealWidth(28), |
| | | Y = Application.GetRealHeight(10), |
| | | Width = Application.GetRealWidth(200), |
| | | Height = Application.GetRealHeight(24), |
| | |
| | | TextColor = CSS_Color.FirstLevelTitleColor, |
| | | TextSize = CSS_FontSize.TextFontSize, |
| | | }; |
| | | row.AddChidren(btnName); |
| | | AddChidren(btnName); |
| | | |
| | | var btnFromFloor = new Button() |
| | | { |
| | | X = Application.GetRealWidth(8 + 10 + 32), |
| | | X = Application.GetRealWidth(28), |
| | | Y = Application.GetRealHeight(10 + 24), |
| | | Width = Application.GetRealWidth(200), |
| | | Height = Application.GetRealHeight(18), |
| | |
| | | TextColor = CSS_Color.PromptingColor1, |
| | | TextSize = CSS_FontSize.PromptFontSize_FirstLevel, |
| | | }; |
| | | row.AddChidren(btnFromFloor); |
| | | AddChidren(btnFromFloor); |
| | | |
| | | var btnValue = new Button() |
| | | btnValue = new Button() |
| | | { |
| | | X = Application.GetRealWidth(28), |
| | | Y = Application.GetRealWidth(57), |
| | |
| | | TextAlignment = TextAlignment.CenterLeft, |
| | | TextSize = CSS_FontSize.HeadlineFontSize, |
| | | TextColor = CSS_Color.FirstLevelTitleColor, |
| | | Text = "---" |
| | | Text = energy.GetAttrState(FunctionAttributeKey.Power), |
| | | Tag = energy.sid, |
| | | IsBold = true, |
| | | }; |
| | | row.AddChidren(btnValue); |
| | | AddChidren(btnValue); |
| | | |
| | | |
| | | var btnSetting = new Button() |
| | |
| | | Height = Application.GetMinRealAverage(32), |
| | | UnSelectedImagePath = "Public/FuncInfoSetIcon.png", |
| | | }; |
| | | row.AddChidren(btnSetting); |
| | | AddChidren(btnSetting); |
| | | |
| | | Button btnSeltSensorValue = new Button() |
| | | var btnSeltSensorValue = new Button() |
| | | { |
| | | X = Application.GetRealWidth(16), |
| | | Y = Application.GetRealWidth(47), |
| | |
| | | IsBold = true, |
| | | TextSize = CSS_FontSize.HeadlineFontSize, |
| | | }; |
| | | row.AddChidren(btnSeltSensorValue); |
| | | AddChidren(btnSeltSensorValue); |
| | | |
| | | Button btnShowData; |
| | | btnShowData = new Button() |
| | | { |
| | | X = Application.GetRealWidth(291), |
| | |
| | | Height = Application.GetMinRealAverage(32), |
| | | UnSelectedImagePath = "FunctionIcon/EnvironmentalScience/DiagramIcon.png", |
| | | SelectedImagePath = "FunctionIcon/EnvironmentalScience/DiagramIconOn.png", |
| | | IsSelected = true, |
| | | IsSelected = false, |
| | | }; |
| | | row.AddChidren(btnShowData); |
| | | AddChidren(btnShowData); |
| | | |
| | | btnSetting.MouseUpEventHandler = (sender, e) => |
| | | { |
| | | Action backAction = () => |
| | | { |
| | | btnName.Text = energy.name; |
| | | btnFromFloor.Text = energy.GetRoomListName(); |
| | | }; |
| | | var infoView = new FunctionBaseInfoSetPage(energy, backAction); |
| | | MainPage.BasePageView.AddChidren(infoView); |
| | |
| | | MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1; |
| | | }; |
| | | |
| | | btnShowData.MouseUpEventHandler = (sender, e) => { |
| | | btnShowData.IsSelected = !btnShowData.IsSelected; |
| | | SetHistory_Action(btnShowData.IsSelected); |
| | | }; |
| | | } |
| | | |
| | | } |
| | | } |
| | | } |