using DevExpress.XtraEditors;
|
using DevExpress.XtraGrid.Views.Grid;
|
using DevExpress.XtraGrid;
|
using DevExpress.XtraPrinting;
|
using IStation.Model;
|
using System;
|
using System.Collections.Generic;
|
using System.ComponentModel;
|
using System.Data;
|
using System.Drawing;
|
using System.Linq;
|
using System.Text;
|
using System.Threading.Tasks;
|
using System.Windows.Forms;
|
using static System.Windows.Forms.VisualStyles.VisualStyleElement.TaskbarClock;
|
|
namespace IStation.WinFrmUI.Monitor
|
{
|
public partial class ResultChartControl : DevExpress.XtraEditors.XtraUserControl
|
{
|
public ResultChartControl()
|
{
|
InitializeComponent();
|
}
|
|
private class CurrentModel : HistoryDataHelper
|
{
|
/// <summary>
|
/// 名称
|
/// </summary>
|
public string Name { get; set; }
|
/// <summary>
|
/// 泵台数
|
/// </summary>
|
public string PumpCount { get; set; }
|
/// <summary>
|
/// 开机时间段
|
/// </summary>
|
public string Time { get; set; }
|
/// <summary>
|
/// 电费
|
/// </summary>
|
public double Electricity { get; set; }
|
}
|
|
|
List<CurrentModel> _currentModel = new List<CurrentModel>();
|
|
/// <summary>
|
/// 绑定数据
|
/// </summary>
|
/// <param name="datetime"></param>
|
public void SetBindingData(DateTime datetime)
|
{
|
_currentModel.Clear();
|
HistoryDataAPiHelper historyDataHelper = new HistoryDataAPiHelper();
|
var result = historyDataHelper.getPumpIsOpen();
|
var time = new DateTime(2022, 11, 6);
|
foreach (var item in result)
|
{
|
var currentmodel = new CurrentModel
|
{
|
Name = "方案",
|
Time = item.Item1.ToString("HH:mm") + "----" + item.Item2.ToString("HH:mm"),
|
PumpCount = item.Item3.ToString() + "台",
|
water = Math.Round(GetWaterdata(item.Item1, item.Item2), 2),
|
electricity = GetElectrityData(item.Item1, item.Item2),
|
Electricity = electricityPirce(item.Item1, item.Item2, GetElectrityData(item.Item1, item.Item2))
|
};
|
_currentModel.Add(currentmodel);
|
}
|
this.bindingSource1.DataSource = _currentModel;
|
}
|
|
|
|
private double GetWaterdata(DateTime Str, DateTime end)
|
{
|
HistoryDataAPiHelper historyDataHelper = new HistoryDataAPiHelper();
|
var waterData = historyDataHelper.GetWaterData();
|
var pump1 = WaterData(waterData.Where(x => x.Tag == "二取水1号主水泵.日累计").ToList(), Str, end);
|
var pump2 = WaterData(waterData.Where(x => x.Tag == "二取水2号主水泵.日累计").ToList(), Str, end);
|
var pump3 = WaterData(waterData.Where(x => x.Tag == "二取水3号主水泵.日累计").ToList(), Str, end);
|
var pump4 = WaterData(waterData.Where(x => x.Tag == "二取水4号主水泵.日累计").ToList(), Str, end);
|
var pump5 = WaterData(waterData.Where(x => x.Tag == "二取水5号主水泵.日累计").ToList(), Str, end);
|
return pump1 + pump2 + pump3 + pump4 + pump5;
|
}
|
|
|
private double WaterData(List<Model.PumpWater> waterData, DateTime Str, DateTime end)
|
{
|
double result = 0;
|
for (int i = 0; i < waterData.Count; i++)
|
{
|
if (waterData[i].Values[0].DateTime == Str)
|
{
|
double startValue;
|
double endValue;
|
startValue = waterData[i].Values[0].SingleWater;
|
for (int j = i + 1; j < waterData.Count; j++)
|
{
|
if (waterData[j].Values[0].DateTime == end)
|
{
|
endValue = waterData[j].Values[0].SingleWater;
|
result = endValue - startValue;
|
return result;
|
}
|
}
|
}
|
}
|
return result;
|
}
|
|
|
//电费计算
|
private double electricityPirce(DateTime startTime, DateTime endTime, double electricity)
|
{
|
var ElePriceSetting = new BLL.ElecPrice().GetAll().First();
|
var MonthList = ElePriceSetting.Settings.MonthList;
|
var FindMonth = MonthList.Find(x => x.StartMonth <= startTime.Month && x.EndMonth >= startTime.Month);
|
foreach (var item in FindMonth.HourList)
|
{
|
if (startTime.Hour >= item.StartHour && endTime.Hour <= item.EndHour)
|
{
|
return Math.Round(item.Price * electricity, 2);
|
}
|
}
|
return 0;
|
}
|
|
|
|
private double GetElectrityData(DateTime Str, DateTime end)
|
{
|
HistoryDataAPiHelper historyDataHelper = new HistoryDataAPiHelper();
|
var Ele = historyDataHelper.GetEleData();
|
var pump1 = ElectricityData(Ele.Where(x => x.Tag == "_0402010204040193046").ToList(), Str, end);
|
var pump2 = ElectricityData(Ele.Where(x => x.Tag == "_0402010204040193047").ToList(), Str, end);
|
var pump3 = ElectricityData(Ele.Where(x => x.Tag == "_0402010204012308007").ToList(), Str, end);
|
var pump4 = ElectricityData(Ele.Where(x => x.Tag == "_0402010204012408007").ToList(), Str, end);
|
var pump5 = ElectricityData(Ele.Where(x => x.Tag == "_0402010204012508007").ToList(), Str, end);
|
return Math.Round(pump1 + pump2 + pump3 + pump4 + pump5, 2);
|
}
|
|
|
private double ElectricityData(List<Model.electricity> EleData, DateTime Str, DateTime end)
|
{
|
double result = 0;
|
for (int i = 0; i < EleData.Count; i++)
|
{
|
if (EleData[i].TotalEle[0].DateTime == Str)
|
{
|
double startValue;
|
double endValue;
|
startValue = EleData[i].TotalEle[0].Value;
|
for (int j = i + 1; j < EleData.Count; j++)
|
{
|
if (EleData[j].TotalEle[0].DateTime == end)
|
{
|
endValue = EleData[j].TotalEle[0].Value;
|
result = endValue - startValue;
|
return result;
|
}
|
}
|
}
|
}
|
return result;
|
}
|
|
|
|
|
//表格点击事件
|
private void gridControl2_MouseDown(object sender, MouseEventArgs e)
|
{
|
GridView gridView = gridControl2.MainView as GridView;
|
if (gridView != null)
|
{
|
// 获取鼠标所在的单元格
|
DevExpress.XtraGrid.Views.Grid.ViewInfo.GridHitInfo hitInfo = gridView.CalcHitInfo(e.Location);
|
|
// 如果点击到单元格上
|
if (hitInfo.InRowCell)
|
{
|
// 获取点击的单元格的行和列
|
int rowHandle = hitInfo.RowHandle;
|
int columnHandle = hitInfo.Column.VisibleIndex;
|
object cellValue = gridView.GetRowCellValue(rowHandle, gridView.Columns[columnHandle]);
|
|
// 处理获取到的单元格数据
|
if (cellValue != null)
|
{
|
|
}
|
}
|
}
|
}
|
}
|
}
|