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;
|
namespace HDL_ON.UI
|
{
|
/// <summary>
|
/// 三相空开能源界面
|
/// </summary>
|
public class AirSwitchP3EnergyPage : FrameLayout
|
{
|
static AirSwitchP3EnergyPage bodyView;
|
|
/// <summary>
|
/// 总功耗-饼图
|
/// </summary>
|
MyEchartsViewOn myEchartsView_Pie;
|
/// <summary>
|
/// 曲线图数据string
|
/// </summary>
|
EchartsOption_BrokenLine brokenLine;
|
|
|
/// <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;
|
|
//5C62FE
|
|
Function device;
|
/// <summary>
|
/// 主页
|
/// </summary>
|
public AirSwitchP3EnergyPage(Function function)
|
{
|
bodyView = this;
|
device = function;
|
}
|
|
/// <summary>
|
///
|
/// </summary>
|
public void LoadPage()
|
{
|
new TopViewDiv(bodyView, Language.StringByID(StringId.EnergyMonitoring)).LoadTopView(0xFFF7F7F7);
|
bodyView.BackgroundColor = 0xFFF5F7FA;
|
|
var contentView = new VerticalScrolViewLayout()
|
{
|
Y = Application.GetRealHeight(64),
|
Height = Application.GetRealHeight(667-64),
|
BackgroundColor = 0xFFF5F7FA,
|
};
|
bodyView.AddChidren(contentView);
|
|
contentView.AddChidren(new Button()
|
{
|
Height = Application.GetRealHeight(12),
|
});
|
|
|
brokenLine = new EchartsOption_BrokenLine();
|
|
#region 选择数据日期范围
|
var showDataTypeView = new FrameLayout()
|
{
|
X = Application.GetRealWidth(143),
|
Y = Application.GetRealHeight(12),
|
Width = Application.GetRealWidth(216),
|
Height = Application.GetRealHeight(27),
|
//BackgroundImagePath = "FunctionIcon/EnvironmentalScience/SensorHistoryBg1.png",
|
};
|
contentView.AddChidren(showDataTypeView);
|
|
var btnShowHistroyData_Day = new Button()
|
{
|
Width = Application.GetRealWidth(54),
|
Height = Application.GetRealHeight(27),
|
TextAlignment = TextAlignment.Center,
|
TextColor = CSS_Color.PromptingColor1,
|
SelectedTextColor = CSS_Color.MainColor,
|
TextSize = CSS_FontSize.PromptFontSize_FirstLevel,
|
IsSelected = true,
|
TextID = StringId.day,
|
SelectedBackgroundColor = 0x1F5C62FE,
|
BackgroundColor = 0x1F5C62FE,
|
BorderColor = CSS_Color.MainColor,
|
BorderWidth = 2,
|
};
|
showDataTypeView.AddChidren(btnShowHistroyData_Day);
|
btnShowHistroyData_Day.SetCornerWithSameRadius((uint)Application.GetRealHeight(6), HDLUtils.RectCornerTopLeft | HDLUtils.RectCornerBottomLeft);
|
|
|
var btnShowHistroyData_Month = new Button()
|
{
|
X = Application.GetRealWidth(54),
|
Width = Application.GetRealWidth(54),
|
TextAlignment = TextAlignment.Center,
|
TextColor = CSS_Color.PromptingColor1,
|
SelectedTextColor = CSS_Color.MainColor,
|
TextSize = CSS_FontSize.PromptFontSize_FirstLevel,
|
TextID = StringId.month,
|
BorderWidth = 1,
|
BorderColor = CSS_Color.PromptingColor1,
|
};
|
showDataTypeView.AddChidren(btnShowHistroyData_Month);
|
|
var btnShowHistroyData_Year = new Button()
|
{
|
X = Application.GetRealWidth(54 * 2),
|
Width = Application.GetRealWidth(54),
|
TextAlignment = TextAlignment.Center,
|
TextColor = CSS_Color.PromptingColor1,
|
SelectedTextColor = CSS_Color.MainColor,
|
TextSize = CSS_FontSize.PromptFontSize_FirstLevel,
|
TextID = StringId.Years,
|
BorderWidth = 1,
|
BorderColor = CSS_Color.PromptingColor1,
|
};
|
showDataTypeView.AddChidren(btnShowHistroyData_Year);
|
|
var btnShowHistroyData_Total = new Button()
|
{
|
X = Application.GetRealWidth(54 * 3),
|
Width = Application.GetRealWidth(54),
|
TextAlignment = TextAlignment.Center,
|
TextColor = CSS_Color.PromptingColor1,
|
SelectedTextColor = CSS_Color.MainColor,
|
TextSize = CSS_FontSize.PromptFontSize_FirstLevel,
|
TextID = StringId.Total,
|
BorderWidth = 1,
|
BorderColor = CSS_Color.PromptingColor1,
|
};
|
showDataTypeView.AddChidren(btnShowHistroyData_Total);
|
|
|
btnShowHistroyData_Day.MouseUpEventHandler = (sender, e) =>
|
{
|
//showDataTypeView.BackgroundImagePath = "FunctionIcon/EnvironmentalScience/SensorHistoryBg1.png";
|
//btnShowHistroyData_Day.IsSelected = true;
|
//btnShowHistroyData_Year.IsSelected = false;
|
//btnShowHistroyData_Month.IsSelected = false;
|
//curQueryType = "hour";
|
//brokenLine.YvalueText = "";
|
//foreach (var enery in queryList)
|
//{
|
// LoadMothed_GetHistoryData(enery, false);
|
//}
|
};
|
|
btnShowHistroyData_Month.MouseUpEventHandler = (sender, e) =>
|
{
|
//showDataTypeView.BackgroundImagePath = "FunctionIcon/EnvironmentalScience/SensorHistoryBg2.png";
|
//btnShowHistroyData_Day.IsSelected = false;
|
//btnShowHistroyData_Year.IsSelected = false;
|
//btnShowHistroyData_Month.IsSelected = true;
|
//curQueryType = "week";
|
//brokenLine.YvalueText = "";
|
//foreach (var enery in queryList)
|
//{
|
// LoadMothed_GetHistoryData(enery, false);
|
//}
|
};
|
btnShowHistroyData_Year.MouseUpEventHandler = (sender, e) =>
|
{
|
//showDataTypeView.BackgroundImagePath = "FunctionIcon/EnvironmentalScience/SensorHistoryBg3.png";
|
//btnShowHistroyData_Day.IsSelected = false;
|
//btnShowHistroyData_Year.IsSelected = true;
|
//btnShowHistroyData_Month.IsSelected = false;
|
//curQueryType = "month";
|
//brokenLine.YvalueText = "";
|
//foreach (var enery in queryList)
|
//{
|
// LoadMothed_GetHistoryData(enery, false);
|
//}
|
};
|
|
#endregion
|
|
contentView.AddChidren(new Button()
|
{
|
Height = Application.GetRealHeight(12),
|
});
|
|
var historyDataView = new FrameLayout()
|
{
|
Gravity = Gravity.CenterHorizontal,
|
Width = Application.GetRealWidth(343),
|
Height = Application.GetRealWidth(330),
|
};
|
contentView.AddChidren(historyDataView);
|
|
myEchartsView_Line = new MyEchartsViewOn()
|
{
|
Y = Application.GetRealWidth(10),
|
Height = Application.GetRealWidth(280),
|
};
|
historyDataView.AddChidren(myEchartsView_Line);
|
|
//EnergyRow(energy, energyListView, index);
|
|
LoadMothed_GetHistoryData();
|
|
}
|
|
|
|
|
/// <summary>
|
/// 读取历史数据
|
/// </summary>
|
void LoadMothed_GetHistoryData()
|
{
|
|
var loadPage = new Loading()
|
{
|
LodingBackgroundColor = 0x88888888,
|
};
|
bodyView.AddChidren(loadPage);
|
|
new System.Threading.Thread(() =>
|
{
|
try
|
{
|
Application.RunOnMainThread(() =>
|
{
|
loadPage.Start(Language.StringByID(StringId.PleaseWait));
|
});
|
|
var sensorType = device.spk.Split(".")[1];
|
var revertObj = new HttpServerRequest().GetSensorHistory(curQueryType, device.deviceId, "power_a");
|
if (revertObj != null)
|
{
|
if (revertObj.Code == StateCode.SUCCESS)
|
{
|
var revertData = Newtonsoft.Json.JsonConvert.DeserializeObject<List<EnvironmentalSensorHistor>>(revertObj.Data.ToString());
|
if (revertData == null || revertData.Count == 0) {
|
#if DEBUG
|
List<string> vs = new List<string>() {
|
"813","313","213","123",
|
"113","213","183","133",
|
"133","513","133","413",
|
};
|
brokenLine.InitXdataText(vs);
|
revertData = new List<EnvironmentalSensorHistor>()
|
{
|
new EnvironmentalSensorHistor{ fieldValue = "100"},
|
new EnvironmentalSensorHistor{ fieldValue = "200"},
|
new EnvironmentalSensorHistor{ fieldValue = "300"},
|
new EnvironmentalSensorHistor{ fieldValue = "400"},
|
new EnvironmentalSensorHistor{ fieldValue = "500"},
|
new EnvironmentalSensorHistor{ fieldValue = "400"},
|
new EnvironmentalSensorHistor{ fieldValue = "100"},
|
new EnvironmentalSensorHistor{ fieldValue = "200"},
|
new EnvironmentalSensorHistor{ fieldValue = "300"},
|
new EnvironmentalSensorHistor{ fieldValue = "400"},
|
new EnvironmentalSensorHistor{ fieldValue = "500"},
|
new EnvironmentalSensorHistor{ fieldValue = "400"},
|
};
|
if (device.GetAttribute("ydata") == null)
|
{
|
device.attributes.Add(new FunctionAttributes() { key = "ydata" });
|
}
|
device.SetAttrState("ydata", brokenLine.InitYdataText(device.name, revertData, "#5C62FE") + ", ");
|
|
#endif
|
}
|
else
|
{
|
List<string> vs = new List<string>();
|
if (brokenLine.YvalueText == "")
|
{
|
foreach (var data in revertData)
|
{
|
vs.Add(data.fieldName);
|
}
|
brokenLine.InitXdataText(vs);
|
}
|
if (device.GetAttribute("ydata") == null)
|
{
|
device.attributes.Add(new FunctionAttributes() { key = "ydata" });
|
}
|
device.SetAttrState("ydata", brokenLine.InitYdataText(device.name, revertData, "#5C62FE") + ", ");
|
}
|
}
|
}
|
brokenLine.yTitle = Language.StringByID(StringId.EnergyConsumption) + "(kW)";
|
brokenLine.xTitle = Language.StringByID(StringId.timeMode);
|
if (curQueryType != "hour")
|
{
|
brokenLine.xTitle = Language.StringByID(StringId.Date);
|
}
|
var opString = brokenLine.InitOption(30);
|
|
Application.RunOnMainThread(() =>
|
{
|
myEchartsView_Line.ShowWithOption(opString);
|
});
|
}
|
catch (Exception ex)
|
{
|
MainPage.Log($"sensor history error : {ex.Message}");
|
}
|
finally
|
{
|
Application.RunOnMainThread(() =>
|
{
|
loadPage.Hide();
|
});
|
}
|
})
|
{ IsBackground = true }.Start();
|
}
|
|
|
}
|
}
|