using System;
using System.Collections.Generic;
using System.Data;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Linq;
using System.Windows.Forms;
using DevExpress.XtraCharts;
using DevExpress.XtraGrid.Views.Grid;
namespace IStation.WinFrmUI.CalcErQu
{
public partial class BlockTimeListDispCtrl : UserControl
{
public BlockTimeListDispCtrl()
{
InitializeComponent();
this.gridView1.OptionsDetail.ShowDetailTabs = false;//不显示TAB名
this.gridView1.OptionsView.ShowGroupPanel = false;//隐藏最上面的GroupPanel
this.gridView1.OptionsSelection.MultiSelect = false;//单选
//this.gridViewMain.OptionsBehavior.Editable = false;//只读
this.gridView1.IndicatorWidth = 4;
this.gridView1.RowHeight = 30;
this.gridView1.RowClick += new DevExpress.XtraGrid.Views.Grid.RowClickEventHandler(this.GridViewMain_RowClick);
//this.gridViewMain.CustomDrawRowIndicator += new DevExpress.XtraGrid.Views.Grid.RowIndicatorCustomDrawEventHandler(this.GridViewMain_CustomDrawRowIndicator);
//this.gridViewMain.CustomUnboundColumnData += new DevExpress.XtraGrid.Views.Base.CustomColumnDataEventHandler(this.GridViewMain_CustomUnboundColumnData);
//this.gridViewMain.DoubleClick += new System.EventHandler(this.GridViewMain_DoubleClick);
//this.gridView1.RowCellClick += new DevExpress.XtraGrid.Views.Grid.RowCellClickEventHandler(this.GridViewMain_RowCellClick);
//this.gridView1.CellValueChanged += new DevExpress.XtraGrid.Views.Base.CellValueChangedEventHandler(this.gridViewMain_CellValueChanged);
}
///
///
///
///
public void SetBindingData(IStation.CalcModel.AnaPrj anaPrj)
{
if (anaPrj == null)
return;
List gridBidings = new List();
foreach (var item in anaPrj.BlockTimes)
{
//List openTimeSpan = new List();
//List closeTimeSpan = new List();
if (item.OpenPumpCount == 0)
{
continue;
//pd.PumpName = "全关";
}
var pd = new GridBlockTimeViewModel();
{
pd.PumpName = string.Format("{0}台泵", item.OpenPumpCount);
pd.SumFlow = item.SumFlow;
pd.SumPower = item.SumPower;
pd.SumMoney = item.SumMoney;
}
pd.StartTime = item.StartTime.ToString("HH:mm");
pd.EndTime = item.EndTime.ToString("HH:mm");
pd.SpanTime = Math.Round((item.EndTime - item.StartTime).TotalMinutes, 0);
pd.Round();
gridBidings.Add(pd);
}
this.bindingSourceGrid1.DataSource = gridBidings;
this.bindingSourceGrid1.ResetBindings(false);
}
class GridBlockTimeViewModel
{
public string PumpName { get; set; }
public double SumFlow { get; set; }//已经考虑时间段 (累计值)
public double SumPower { get; set; }//已经考虑时间段 (累计值 度)
public double SumMoney { get; set; }//已经考虑时间段 (累计值)
public double SpanTime { get; set; }
public string StartTime { get; set; }
public string EndTime { get; set; }
public List SubItems { get; set; }
public class SubItem
{
public string StartTime { get; set; }
public string EndTime { get; set; }
public double SpanTime { get; set; }
public double SumFlow { get; set; }//已经考虑时间段 (累计值)
public double SumPower { get; set; }//已经考虑时间段 (累计值 度)
public double SumMoney { get; set; }//已经考虑时间段 (累计值)
}
internal void Round()
{
this.SumFlow = Math.Round(this.SumFlow, 0);
this.SumPower = Math.Round(this.SumPower, 0);
this.SumMoney = Math.Round(this.SumMoney, 0);
}
//千吨水能耗
public double QDSLN
{
get
{
if (SumFlow == 0)
return 0;
return Math.Round(SumPower * 1000 / SumFlow, 1);
}
}
}
//class SpanTimeBlock
//{
// public SpanTimeBlock(int pumpIndx, DateTime start, DateTime end)
// {
// this.PumpIndx = pumpIndx;
// this.Start = start;
// this.End = end;
// }
// public SpanTimeBlock(int pumpIndx, DateTime start, DateTime end, double flow, double power, double money)
// {
// this.PumpIndx = pumpIndx;
// this.Start = start;
// this.End = end;
// this.TotalFlow = flow;
// this.TotalPower = power;
// this.TotalMoney = money;
// }
// public int PumpIndx { get; set; }
// public DateTime Start { get; set; }
// public DateTime End { get; set; }
// public double TotalFlow { get; set; }
// public double TotalPower { get; set; }
// public double TotalMoney { get; set; }
//}
private void GridViewMain_RowClick(object sender, RowClickEventArgs e)
{
if (e.RowHandle < 0) return;
if (e.Button == System.Windows.Forms.MouseButtons.Right)
{
//gridViewPrj = gridViewMain.GetRow(e.RowHandle) as AnaPrj;
contextMenuGrid.Show(gridControl运行列表, e.Location);
}
else
{
//SetRibbonButtonDisp(SPump.WinFrmUI.SeriesTreeView.eNodeLevel.Pump);
}
}
private void MenuItemGrid切换模式_Click(object sender, EventArgs e)
{
//if (MenuItemGrid切换模式.Text == "切换成时间段显示")
//{
// _gridDispStyle = 1;
// MenuItemGrid切换模式.Text = "切换成泵分组显示";
// InitialGrid运行时间();
//}
//else
//{
// _gridDispStyle = 0;
// MenuItemGrid切换模式.Text = "切换成时间段显示";
// InitialGrid运行时间();
//}
}
private void MenuItem导出Grid_Click(object sender, EventArgs e)
{
ExportSpanGrid();
}
public void ExportSpanGrid()
{
SaveFileDialog dlg = new SaveFileDialog();
dlg.Title = "导出信息列表";
dlg.FileName = "信息列表.xls";
dlg.Filter = "excel文件 (*.xls)|*.xls";
if (dlg.ShowDialog() == DialogResult.OK)
this.gridControl运行列表.ExportToXls(dlg.FileName);
}
}
}