using System;
|
using System.Collections.Generic;
|
using HDL_ON.DAL.Server;
|
using HDL_ON.Entity;
|
using HDL_ON.UI.CSS;
|
using HDL_ON.UI.UI2.EchartsOption_Energy;
|
using Shared;
|
namespace HDL_ON.UI
|
{
|
public class EnergyMainPage : FrameLayout
|
{
|
FrameLayout bodyView;
|
|
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"};
|
|
public EnergyMainPage()
|
{
|
bodyView = this;
|
}
|
|
/// <summary>
|
///
|
/// </summary>
|
public void LoadPage()
|
{
|
new TopViewDiv(bodyView, Language.StringByID(StringId.EnergyMonitoring)).LoadTopView();
|
bodyView.BackgroundColor = CSS_Color.BackgroundColor;
|
|
var contentView = new VerticalScrolViewLayout()
|
{
|
Y = Application.GetRealHeight(64),
|
Height = Application.GetRealHeight(603),
|
};
|
bodyView.AddChidren(contentView);
|
|
#region 顶部view
|
var generalTableView = new FrameLayout()
|
{
|
Gravity = Gravity.CenterHorizontal,
|
Y = Application.GetRealHeight(16),
|
Width = Application.GetRealWidth(343),
|
Height = Application.GetRealWidth(148),
|
Radius = (uint)Application.GetRealWidth(5),
|
BackgroundColor = CSS_Color.MainBackgroundColor,
|
};
|
contentView.AddChidren(generalTableView);
|
|
TextButton btnTotalValue = new TextButton()
|
{
|
X = Application.GetRealWidth(18),
|
Y = Application.GetRealWidth(24),
|
Width = Application.GetRealWidth(18),
|
Height = Application.GetRealWidth(52),
|
TextColor = CSS_Color.FirstLevelTitleColor,
|
IsBold = true,
|
TextAlignment = TextAlignment.CenterLeft,
|
TextSize = 40,
|
Text = "000"
|
};
|
generalTableView.AddChidren(btnTotalValue);
|
|
btnTotalValue.Width = btnTotalValue.GetTextWidth();
|
|
var btnTotalValueUint = new Button()
|
{
|
X = btnTotalValue.Right,
|
Y = Application.GetRealWidth(24),
|
Width = Application.GetRealWidth(60),
|
Height = Application.GetRealWidth(28),
|
TextColor = CSS_Color.FirstLevelTitleColor,
|
TextSize = CSS_FontSize.SubheadingFontSize,
|
IsBold = true,
|
Text = "kW‧h",
|
TextAlignment = TextAlignment.CenterLeft,
|
};
|
generalTableView.AddChidren(btnTotalValueUint);
|
|
var btnRealTimeData = new Button()
|
{
|
X = Application.GetRealWidth(18),
|
Y = btnTotalValue.Bottom,
|
Width = Application.GetRealWidth(209),
|
Height = Application.GetRealWidth(28),
|
TextColor = CSS_Color.TextualColor,
|
TextSize = CSS_FontSize.SubheadingFontSize,
|
TextAlignment = TextAlignment.CenterLeft,
|
TextID = StringId.RealTimePowerConsumption,
|
};
|
generalTableView.AddChidren(btnRealTimeData);
|
btnRealTimeData.Text = Language.StringByID(StringId.RealTimePowerConsumption).Replace("{0}", "0");
|
|
var echartsView = new FrameLayout()
|
{
|
Width = Application.GetRealWidth(118),
|
Height = Application.GetRealWidth(118),
|
X = Application.GetRealWidth(227),
|
//Y = Application.GetRealWidth(16),
|
};
|
generalTableView.AddChidren(echartsView);
|
MyEchartsViewOn myEchartsView = new MyEchartsViewOn()
|
{
|
Width = Application.GetRealWidth(118),
|
Height = Application.GetRealWidth(118),
|
};
|
|
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);
|
|
|
var btnDrodDown = new Button()
|
{
|
Y = Application.GetRealWidth(118),
|
Width = Application.GetRealWidth(343),
|
Height = Application.GetRealWidth(30),
|
UnSelectedImagePath = "FunctionIcon/Energy/EnergyDrodDownIcon.png",
|
};
|
generalTableView.AddChidren(btnDrodDown);
|
|
#endregion
|
|
|
var energyList = FunctionList.List.GetEnergyList();
|
var energyListView = new FrameLayout()
|
{
|
Y = generalTableView.Bottom + Application.GetRealWidth(8),
|
Height = Application.GetRealWidth(116 * energyList.Count),
|
};
|
contentView.AddChidren(energyListView);
|
int index = 0;
|
foreach (var energy in energyList)
|
{
|
EnergyRow(energy, energyListView, index);
|
index++;
|
}
|
}
|
FrameLayout diagramView;
|
List<Function> queryList = new List<Function>();
|
string curQueryType = "hour";
|
|
void d1(FrameLayout contentView)
|
{
|
diagramView = new FrameLayout()
|
{
|
Gravity = Gravity.CenterHorizontal,
|
Width = Application.GetRealWidth(343),
|
Height = Application.GetRealWidth(420),
|
BackgroundColor = CSS_Color.MainBackgroundColor,
|
Radius = (uint)Application.GetRealWidth(12),
|
BorderColor = 0x00000000,
|
BorderWidth = 0,
|
};
|
contentView.AddChidren(diagramView);
|
|
#region 选择数据日期范围
|
var showDataTypeView = new FrameLayout()
|
{
|
X = Application.GetRealWidth(183),
|
Y = Application.GetRealHeight(12),
|
Width = Application.GetRealWidth(144),
|
Height = Application.GetRealHeight(24),
|
BackgroundImagePath = "FunctionIcon/EnvironmentalScience/SensorHistoryBg1.png",
|
};
|
diagramView.AddChidren(showDataTypeView);
|
|
var btnShowHistroyData_Day = new Button()
|
{
|
Width = Application.GetRealWidth(48),
|
TextAlignment = TextAlignment.Center,
|
TextColor = CSS_Color.PromptingColor2,
|
SelectedTextColor = CSS_Color.MainColor,
|
TextSize = CSS_FontSize.PromptFontSize_FirstLevel,
|
IsSelected = true,
|
TextID = StringId.day,
|
};
|
showDataTypeView.AddChidren(btnShowHistroyData_Day);
|
|
var btnShowHistroyData_Week = new Button()
|
{
|
X = Application.GetRealWidth(48),
|
Width = Application.GetRealWidth(48),
|
TextAlignment = TextAlignment.Center,
|
TextColor = CSS_Color.PromptingColor2,
|
SelectedTextColor = CSS_Color.MainColor,
|
TextSize = CSS_FontSize.PromptFontSize_FirstLevel,
|
TextID = StringId.week,
|
};
|
showDataTypeView.AddChidren(btnShowHistroyData_Week);
|
|
var btnShowHistroyData_Month = new Button()
|
{
|
X = Application.GetRealWidth(48 * 2),
|
Width = Application.GetRealWidth(48),
|
TextAlignment = TextAlignment.Center,
|
TextColor = CSS_Color.PromptingColor2,
|
SelectedTextColor = CSS_Color.MainColor,
|
TextSize = CSS_FontSize.PromptFontSize_FirstLevel,
|
Text = DateTime.Now.Month.ToString() + Language.StringByID(StringId.month),
|
};
|
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";
|
d2();
|
};
|
|
btnShowHistroyData_Month.MouseUpEventHandler = (sender, e) =>
|
{
|
showDataTypeView.BackgroundImagePath = "FunctionIcon/EnvironmentalScience/SensorHistoryBg3.png";
|
btnShowHistroyData_Day.IsSelected = false;
|
btnShowHistroyData_Month.IsSelected = true;
|
btnShowHistroyData_Week.IsSelected = false;
|
curQueryType = "week";
|
d2();
|
};
|
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";
|
d2();
|
};
|
|
#endregion
|
|
var historyDataView = new FrameLayout()
|
{
|
Gravity = Gravity.CenterHorizontal,
|
Y = Application.GetRealHeight(52),
|
Width = Application.GetRealWidth(343 - 32),
|
Height = Application.GetRealHeight(270),
|
};
|
diagramView.AddChidren(historyDataView);
|
|
var myEchartsView = new MyEchartsViewOn();
|
|
historyDataView.AddChidren(myEchartsView);
|
|
}
|
|
void d2()
|
{
|
int index = 0;
|
var echartRootJson = new EchartsOption_Energy();
|
var seriesList = new List<EchartSeriesItem>();
|
foreach (var function in queryList)
|
{
|
var seriesItem = d3(function, index, echartRootJson.xAxis.data);
|
seriesList.Add(seriesItem);
|
}
|
}
|
/// <summary>
|
/// 查询列表
|
/// </summary>
|
/// <summary>
|
/// 读取传感器历史数据
|
/// </summary>
|
EchartSeriesItem d3(Function function, int index, List<string> xAxisData)
|
{
|
EchartSeriesItem sItem = null;
|
List<string> data = new List<string>();
|
var loadPage = new Loading()
|
{
|
LodingBackgroundColor = 0x88888888,
|
};
|
diagramView.AddChidren(loadPage);
|
|
try
|
{
|
Application.RunOnMainThread(() =>
|
{
|
loadPage.Start(Language.StringByID(StringId.PleaseWait));
|
});
|
var sensorType = function.spk.Split(".")[0];
|
var revertObj = new HttpServerRequest().GetSensorHistory(curQueryType, function.deviceId, sensorType);
|
|
if (revertObj != null)
|
{
|
if (revertObj.Code == StateCode.SUCCESS)
|
{
|
var revertData = Newtonsoft.Json.JsonConvert.DeserializeObject<List<EnvironmentalSensorHistor>>(revertObj.Data.ToString());
|
|
sItem = new EchartSeriesItem
|
{
|
data = new List<int>(),
|
lineStyle = new EchartLineStyle()
|
{
|
color = colorList2[index],
|
#if __IOS__
|
width = 5,
|
#elif __ANDROID__
|
width = 2,
|
#endif
|
},
|
};
|
|
try
|
{
|
foreach (var d in revertData)
|
{
|
if (xAxisData.Count == 0)
|
{
|
data.Add(d.fieldName);
|
}
|
sItem.data.Add(Convert.ToInt32(d.fieldValue));
|
}
|
xAxisData.AddRange(data);
|
}
|
catch (Exception ex)
|
{
|
MainPage.Log($"revertData:{ex.Message}");
|
}
|
}
|
else
|
{
|
Application.RunOnMainThread(() =>
|
{
|
IMessageCommon.Current.ShowErrorInfoAlter("", true, 2, Language.StringByID(StringId.GetSensorHistoryFailed), false);
|
});
|
}
|
}
|
}
|
catch (Exception ex)
|
{
|
MainPage.Log($"sensor history error : {ex.Message}");
|
}
|
finally
|
{
|
Application.RunOnMainThread(() =>
|
{
|
loadPage.Hide();
|
});
|
}
|
return sItem;
|
|
//var echartRootJsonString = Newtonsoft.Json.JsonConvert.SerializeObject(echartRootJson);
|
//myEchartsView.ShowWithOptionJsonString(echartRootJsonString);
|
}
|
|
|
/// <summary>
|
///
|
/// </summary>
|
public void EnergyRow(Function energy, FrameLayout view, int index)
|
{
|
var btnLine = new Button()
|
{
|
Y = Application.GetRealWidth(116 * index),
|
Height = Application.GetRealWidth(16),
|
};
|
view.AddChidren(btnLine);
|
|
var row = new FrameLayout()
|
{
|
Y = btnLine.Bottom,
|
Gravity = Gravity.CenterHorizontal,
|
Width = Application.GetRealWidth(343),
|
Height = Application.GetRealWidth(100),
|
Radius = (uint)Application.GetRealWidth(12),
|
BackgroundColor = CSS_Color.MainBackgroundColor,
|
};
|
view.AddChidren(row);
|
|
var btnColorTip = new Button()
|
{
|
X = Application.GetRealWidth(8),
|
Y = Application.GetRealWidth(16),
|
Width = Application.GetRealWidth(12),
|
Height = Application.GetRealWidth(12),
|
BackgroundColor = colorList[index],
|
};
|
row.AddChidren(btnColorTip);
|
|
var btnName = new Button()
|
{
|
X = Application.GetRealWidth(8 + 10 + 32),
|
Y = Application.GetRealHeight(10),
|
Width = Application.GetRealWidth(200),
|
Height = Application.GetRealHeight(24),
|
Text = energy.name,
|
TextAlignment = TextAlignment.CenterLeft,
|
TextColor = CSS_Color.FirstLevelTitleColor,
|
TextSize = CSS_FontSize.TextFontSize,
|
};
|
row.AddChidren(btnName);
|
|
var btnFromFloor = new Button()
|
{
|
X = Application.GetRealWidth(8 + 10 + 32),
|
Y = Application.GetRealHeight(10 + 24),
|
Width = Application.GetRealWidth(200),
|
Height = Application.GetRealHeight(18),
|
Text = energy.GetRoomListName(),
|
TextAlignment = TextAlignment.CenterLeft,
|
TextColor = CSS_Color.PromptingColor1,
|
TextSize = CSS_FontSize.PromptFontSize_FirstLevel,
|
};
|
row.AddChidren(btnFromFloor);
|
|
var btnValue = new Button()
|
{
|
X = Application.GetRealWidth(28),
|
Y = Application.GetRealWidth(57),
|
Width = Application.GetRealWidth(226),
|
Height = Application.GetRealWidth(43),
|
TextAlignment = TextAlignment.CenterLeft,
|
TextSize = CSS_FontSize.HeadlineFontSize,
|
TextColor = CSS_Color.FirstLevelTitleColor,
|
Text = "---"
|
};
|
row.AddChidren(btnValue);
|
|
|
var btnSetting = new Button()
|
{
|
X = Application.GetRealWidth(291),
|
Y = Application.GetRealWidth(6),
|
Width = Application.GetMinRealAverage(32),
|
Height = Application.GetMinRealAverage(32),
|
UnSelectedImagePath = "Public/FuncInfoSetIcon.png",
|
};
|
row.AddChidren(btnSetting);
|
|
Button btnSeltSensorValue = new Button()
|
{
|
X = Application.GetRealWidth(16),
|
Y = Application.GetRealWidth(47),
|
Width = Application.GetRealWidth(200),
|
Height = Application.GetRealWidth(43),
|
TextAlignment = TextAlignment.CenterLeft,
|
TextColor = CSS_Color.FirstLevelTitleColor,
|
IsBold = true,
|
TextSize = CSS_FontSize.HeadlineFontSize,
|
};
|
row.AddChidren(btnSeltSensorValue);
|
|
Button btnShowData;
|
btnShowData = new Button()
|
{
|
X = Application.GetRealWidth(291),
|
Y = Application.GetRealWidth(62),
|
Width = Application.GetMinRealAverage(32),
|
Height = Application.GetMinRealAverage(32),
|
UnSelectedImagePath = "FunctionIcon/EnvironmentalScience/DiagramIcon.png",
|
SelectedImagePath = "FunctionIcon/EnvironmentalScience/DiagramIconOn.png",
|
IsSelected = true,
|
};
|
row.AddChidren(btnShowData);
|
|
btnSetting.MouseUpEventHandler = (sender, e) =>
|
{
|
Action backAction = () =>
|
{
|
btnName.Text = energy.name;
|
};
|
var infoView = new FunctionBaseInfoSetPage(energy, backAction);
|
MainPage.BasePageView.AddChidren(infoView);
|
infoView.LoadPage();
|
MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1;
|
};
|
|
}
|
}
|
}
|