using DevExpress.XtraGrid.Views.Grid;
|
using IStation.BLL;
|
using System;
|
using System.Collections.Generic;
|
using System.Globalization;
|
using System.Windows.Forms;
|
|
namespace IStation.WinFrmUI.Monitor
|
{
|
public partial class ResultChartControl : DevExpress.XtraEditors.XtraUserControl
|
{
|
public ResultChartControl()
|
{
|
InitializeComponent();
|
}
|
|
private class CurrentModel
|
{
|
/// <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 ElectricityPrice { get; set; }
|
/// <summary>
|
/// 用电量
|
/// </summary>
|
public double Electricity { get; set; }
|
/// <summary>
|
/// 取水量
|
/// </summary>
|
public double Water { get; set; }
|
/// <summary>
|
/// 持续时间
|
/// </summary>
|
public double TimeSpan { get; set; }
|
/// <summary>
|
/// 总取水量
|
/// </summary>
|
public double TotalWater { get; set; }
|
/// <summary>
|
/// 总电费
|
/// </summary>
|
public double TotalElePrice { get; set; }
|
/// <summary>
|
/// 总用电量
|
/// </summary>
|
public double TotalEle { get;set; }
|
}
|
|
DateTime DateTime;
|
DateTime ListDayTime;
|
List<CurrentModel> _currentModel = new List<CurrentModel>();
|
CalcModel.AnaPrj _ana = null;
|
Model.RunParasData _LastYeay = null;
|
|
|
/// <summary>
|
/// 绑定数据
|
/// </summary>
|
/// <param name="datetime"></param>
|
public void SetBindingData(DateTime datetime)
|
{
|
ListDayTime = datetime;
|
if (checkEditCalendar.Checked == false)
|
{
|
DateTime= datetime.AddDays(-366);
|
}
|
else
|
{
|
DateTime = ConvertDateTime(datetime);
|
}
|
_currentModel.Clear();
|
HistoryDataAPiHelper historyDataAPiHelper = new HistoryDataAPiHelper();
|
PumpRunHelper pumpRunHelper = new PumpRunHelper();
|
_ana = IStation.BLL.AnaPrj.GetPrj(datetime);
|
_LastYeay = pumpRunHelper.GetByHistoryOneData(DateTime, out string error);
|
var IsOpen = historyDataAPiHelper.MergeTimeSlots(MergeList(_LastYeay));
|
if (IsOpen != null&& _ana!=null)
|
{
|
foreach (var model in IsOpen)
|
{
|
var LastYear = new CurrentModel
|
{
|
Name = "去年同期",
|
PumpCount = string.Format("{0}台泵", model.Item3.ToString()),
|
Time = model.Item1.ToString("dd日HH:mm") + "-" + model.Item2.ToString("dd日HH:mm"),
|
ElectricityPrice = model.Item4,
|
Water = model.Item5,
|
Electricity = model.Item6,
|
TimeSpan= (model.Item2-model.Item1).TotalMinutes,
|
TotalEle= _LastYeay.Electric,
|
TotalElePrice= _LastYeay.Money,
|
TotalWater=_LastYeay.FlowIn
|
};
|
_currentModel.Add(LastYear);
|
}
|
}
|
if (_ana != null)
|
{
|
foreach (var item in _ana.BlockTimes)
|
{
|
if (item.OpenPumpCount == 0)
|
{
|
continue;
|
}
|
var project = new CurrentModel
|
{
|
Name = "方案",
|
PumpCount = string.Format("{0}台泵", item.OpenPumpCount),
|
Time = item.StartTime.ToString("dd日HH:mm") + "-" + item.EndTime.ToString("dd日HH:mm"),
|
Electricity = item.SumPower,
|
ElectricityPrice=item.SumMoney,
|
Water = item.SumFlow,
|
TimeSpan= (item.EndTime-item.StartTime).TotalMinutes,
|
TotalEle= _ana.SumFlow4Disp,
|
TotalWater= _ana.SumPower4Disp,
|
TotalElePrice= _ana.SumMoney,
|
};
|
_currentModel.Add(project);
|
}
|
}
|
this.bindingSource1.DataSource = _currentModel;
|
this.bindingSource1.ResetBindings(false);
|
}
|
|
|
//合并所有开始时间-结束时间
|
private List<(DateTime, DateTime,double,double,double)> MergeList(Model.RunParasData runParasData)
|
{
|
List<(DateTime, DateTime,double,double,double)> values = new List<(DateTime, DateTime, double, double, double)>();
|
foreach (var item in runParasData.Pump1)
|
{
|
values.Add((item.StartTime, item.EndTime,item.Money, item.FlowIn,item.Electric));
|
}
|
foreach (var item in runParasData.Pump2)
|
{
|
values.Add((item.StartTime, item.EndTime, item.Money, item.FlowIn, item.Electric));
|
}
|
foreach (var item in runParasData.Pump3)
|
{
|
values.Add((item.StartTime, item.EndTime, item.Money, item.FlowIn, item.Electric));
|
}
|
foreach (var item in runParasData.Pump4)
|
{
|
values.Add((item.StartTime, item.EndTime, item.Money, item.FlowIn, item.Electric));
|
}
|
foreach (var item in runParasData.Pump5)
|
{
|
values.Add((item.StartTime, item.EndTime, item.Money, item.FlowIn, item.Electric));
|
}
|
return values;
|
}
|
|
|
//农历阴历日期转换
|
private DateTime ConvertDateTime(DateTime lastYearDay)
|
{
|
|
// 创建一个 ChineseLunisolarCalendar 实例
|
ChineseLunisolarCalendar chineseCalendar = new ChineseLunisolarCalendar();
|
|
// 获取今年的阴历日期
|
int thisYear = chineseCalendar.GetYear(lastYearDay);
|
int thisMonth = chineseCalendar.GetMonth(lastYearDay);
|
int thisDay = chineseCalendar.GetDayOfMonth(lastYearDay);
|
|
|
// 将阴历日期减去一年
|
DateTime lastYearLunarDate = chineseCalendar.ToDateTime(thisYear, thisMonth, thisDay, 0, 0, 0, 0).AddYears(-1);
|
|
// 将去年的阴历日期转换为阳历日期
|
DateTime lastYearSolarDate = ConvertChineseToGregorian(lastYearLunarDate.Year, lastYearLunarDate.Month, lastYearLunarDate.Day);
|
return lastYearSolarDate;
|
}
|
|
// 将农历日期转换为阳历日期的方法
|
static DateTime ConvertChineseToGregorian(int year, int month, int day)
|
{
|
// 创建 ChineseLunisolarCalendar 实例
|
ChineseLunisolarCalendar chineseCalendar = new ChineseLunisolarCalendar();
|
|
// 将农历日期转换为阳历日期
|
DateTime gregorianDate = chineseCalendar.ToDateTime(year, month, day, 0, 0, 0, 0);
|
|
return gregorianDate;
|
}
|
|
//表格点击事件
|
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)
|
{
|
|
}
|
}
|
}
|
}
|
|
private void checkEditCalendar_CheckedChanged(object sender, EventArgs e)
|
{
|
this.SetBindingData(ListDayTime);
|
}
|
|
|
}
|
}
|