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.XtraBars.ViewInfo; using DevExpress.XtraCharts; using DevExpress.XtraGrid.Views.Grid; namespace IStation.WinFrmUI.CalcErQu { public partial class AnaResultInfoCtrl定水量 : UserControl { DevExpress.XtraCharts.XYDiagram mainDiagram; //计算时间跨度 protected int _calcSpaceMinute = 2; public int CalcSpaceMinute { get { return _calcSpaceMinute; } set { _calcSpaceMinute = value; } } DevExpress.XtraCharts.ConstantLine _moveConstantLineIn实时数据 = null; public AnaResultInfoCtrl定水量() { 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.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); this.chartControl实时数据.CustomPaint += new DevExpress.XtraCharts.CustomPaintEventHandler(this.ChartControl实时数据_CustomPaint); mainDiagram = this.chartControl实时数据.Diagram as DevExpress.XtraCharts.XYDiagram; _moveConstantLineIn实时数据 = mainDiagram.AxisX.ConstantLines[0]; _moveConstantLineIn实时数据.Visible = false; } List _waterLevels长江; public void SetRiverWaterLevels(List waterLevels长江) { this._waterLevels长江 = waterLevels长江; } IStation.CalcModel.AnaPrj _anaPrj = null; DateTime _startTime, _endTime; #region 泵信息 private List _allPumpInfo = null; public void SetPumpInfo(List allPumpInfo) { this._allPumpInfo = allPumpInfo; } #endregion /// /// /// /// /// /// /// public void SetBindingData( DateTime startTime, DateTime endTime, IStation.CalcModel.AnaPrj anaPrj) { if (anaPrj == null) return; this.CalcSpaceMinute = IStation.WinFrmUI.CalcErQu.Properties.Settings.Default.CalcSpaceMinute; this._startTime = startTime; this._endTime = endTime; this._anaPrj = anaPrj; InitialRealTimeData(anaPrj); InitialGrid运行时间(); InitialChart实时数据(anaPrj); InitialChart累计数据(anaPrj); } #region 累计数据 private void InitialChart累计数据(IStation.CalcModel.AnaPrj anaPrj) { var series累计流量 = chartControl累计数据.Series[0]; var series累计电量 = chartControl累计数据.Series[1]; var series累计电费 = chartControl累计数据.Series[2]; series累计流量.Points.Clear(); series累计电量.Points.Clear(); series累计电费.Points.Clear(); for (int i = 0; i < realTimeDataList.Count - 1; i++) { var time = realTimeDataList[i].Time; series累计流量.Points.Add(new SeriesPoint(time, new double[] { realTimeDataList[i].TotalFlow })); series累计电量.Points.Add(new SeriesPoint(time, new double[] { realTimeDataList[i].TotalEle })); series累计电费.Points.Add(new SeriesPoint(time, new double[] { realTimeDataList[i].TotalMoney })); } var diagram = chartControl累计数据.Diagram as DevExpress.XtraCharts.XYDiagram; var axis = diagram.AxisX; axis.VisualRange.Auto = false; axis.WholeRange.Auto = false; axis.WholeRange.SideMarginsValue = 0; axis.VisualRange.SideMarginsValue = 0; axis.WholeRange.SetMinMaxValues(_startTime, _endTime); axis.VisualRange.SetMinMaxValues(_startTime, _endTime); axis.WholeRange.AlwaysShowZeroLevel = false; } #endregion //实时数据 List realTimeDataList; private void InitialRealTimeData(IStation.CalcModel.AnaPrj anaPrj) { //List splitTimeList = new List(); //splitTimeList.Add(this._startTime); //splitTimeList.Add(this._endTime); //foreach (var item in anaPrj.BlockTimes) //{ // if (!splitTimeList.Contains(item.StartTime)) // splitTimeList.Add(item.StartTime); // if (!splitTimeList.Contains(item.EndTime)) // splitTimeList.Add(item.EndTime); //} //splitTimeList = splitTimeList.Distinct().ToList(); //splitTimeList.Sort(); //realTimeDataList = new List(); //double total_flow = 0; //double total_power = 0; //double total_money = 0; //for (int i = 0; i < splitTimeList.Count - 1; i++) //{ // bool isClosePump = true; // DateTime startTime = splitTimeList[i]; // DateTime endTime = splitTimeList[i + 1]; // foreach (var item in anaPrj.BlockTimes) // { // if (startTime >= item.StartTime && startTime < item.EndTime) // { // isClosePump = false; // foreach (var sd in item.SumData) // { // if (sd.Time <= endTime) // { // IStation.ViewModel.RealTimeData rtd = new IStation.ViewModel.RealTimeData(); // rtd.Time = sd.Time; // rtd.OpenPumpCount = item.OpenPumpCount; // rtd.Head = sd.Head; // rtd.Flow = sd.Flow; // rtd.Power = sd.Power; // rtd.WaterLevelQ = sd.WaterLevelQ; // rtd.WaterLevelC = IStation.Calc.ErQuCalcBaseHelper.GetRiverWaterLevelByTime(_waterLevels长江, rtd.Time); // total_flow += sd.SFlow; // total_power += sd.Power; // total_money += sd.Money; // rtd.TotalFlow = total_flow; // rtd.TotalEle = total_power; // rtd.TotalMoney = total_money; // //rtd.PumpDatas = sd.PumpDatas; // realTimeDataList.Add(rtd); // } // } // break; // } // } // if (isClosePump) // { // for (var time = startTime; time < endTime; time = time.AddMinutes(this._calcSpaceMinute)) // { // IStation.ViewModel.RealTimeData rtd = new IStation.ViewModel.RealTimeData(); // rtd.Time = time; // rtd.OpenPumpCount = 0; // rtd.Flow = 0; // rtd.Power = 0; // rtd.WaterLevelC = IStation.Calc.ErQuCalcBaseHelper.GetRiverWaterLevelByTime(_waterLevels长江, rtd.Time); // rtd.WaterLevelQ = rtd.WaterLevelC; // rtd.TotalFlow = total_flow; // rtd.TotalEle = total_power; // rtd.TotalMoney = total_money; // realTimeDataList.Add(rtd); // } // } //} } #region 实时数据 private void InitialChart实时数据(IStation.CalcModel.AnaPrj anaPrj) { DevExpress.XtraCharts.Series seriesCJSW = this.chartControl实时数据.Series[0]; DevExpress.XtraCharts.Series series前池液位 = this.chartControl实时数据.Series[1]; DevExpress.XtraCharts.Series series流量 = this.chartControl实时数据.Series[2]; DevExpress.XtraCharts.Series series功率 = this.chartControl实时数据.Series[3]; seriesCJSW.Points.Clear(); series流量.Points.Clear(); series功率.Points.Clear(); series前池液位.Points.Clear(); double min_flow = double.MaxValue, max_flow = 0; double min_power = double.MaxValue, max_power = 0; for (int i = 0; i < realTimeDataList.Count; i++) { var time = realTimeDataList[i].Time; seriesCJSW.Points.Add(new SeriesPoint(time, new double[] { Math.Round( realTimeDataList[i].WaterLevelC, 2) })); series流量.Points.Add(new SeriesPoint(time, new double[] { 100 * ((int)( realTimeDataList[i].Flow/100 )) })); series功率.Points.Add(new SeriesPoint(time, new double[] { 10 * ((int)( realTimeDataList[i].Power / 10)) })); series前池液位.Points.Add(new SeriesPoint(time, new double[] { Math.Round(realTimeDataList[i].WaterLevelQ, 2) })); if (realTimeDataList[i].Flow > 1000) { min_power = Math.Min(min_power, realTimeDataList[i].Power); max_power = Math.Max(max_power, realTimeDataList[i].Power); min_flow = Math.Min(min_flow, realTimeDataList[i].Flow); max_flow = Math.Max(max_flow, realTimeDataList[i].Flow); } } SetChartCoord实时数据(min_flow, max_flow, min_power, max_power); } double rang_up_flow = 0; double rang_down_flow = 0; private void SetChartCoord实时数据(double min_flow,double max_flow,double min_power,double max_power) { if (this.mainDiagram == null) return; var axis_time = this.mainDiagram.AxisX; axis_time.VisualRange.Auto = false; axis_time.WholeRange.Auto = false; axis_time.WholeRange.SideMarginsValue = 0; axis_time.VisualRange.SideMarginsValue = 0; axis_time.WholeRange.SetMinMaxValues(_startTime, _endTime); axis_time.VisualRange.SetMinMaxValues(_startTime, _endTime); axis_time.WholeRange.AlwaysShowZeroLevel = false; double coord_min_flow = 5000 * ((int)(min_flow / 5000 - 2)); double coord_max_flow = 5000 * ((int)(max_flow / 5000 + 2)); int coord_space_flow = (int)((coord_max_flow - coord_min_flow) / 1000) * 100; var coord_flows = new List(); double disp_flow = coord_min_flow; for (int i = 0; i < 20; i++) { coord_flows.Add(new CustomAxisLabel(disp_flow.ToString(), disp_flow)); disp_flow = disp_flow + coord_space_flow; if (disp_flow > coord_max_flow) break; } rang_up_flow = Convert.ToDouble( coord_flows[coord_flows.Count - 1].AxisValue); rang_down_flow = Convert.ToDouble( coord_flows[coord_flows.Count - 2].AxisValue); rang_down_flow = rang_up_flow + (rang_up_flow - rang_down_flow) / 3; double coord_min_power = 500 * ((int)(min_power / 500 )); double coord_max_power = 500 * ((int)(max_power / 500 + 2)); int coord_space_power = (int)((coord_max_power - coord_min_power) / 10); List coord_powers = new List(); double disp_power = coord_min_power; for (int i = 0; i < 20; i++) { coord_powers.Add(new CustomAxisLabel(disp_power.ToString(), disp_power)); disp_power = disp_power + coord_space_power; if (disp_power > coord_max_power) break; } int grid_num = Math.Max(coord_powers.Count, coord_flows.Count); List coord_sw = new List(); for (int i = 0; i < grid_num; i++) { var h = i * 0.5; coord_sw.Add(new CustomAxisLabel(h.ToString(), h)); } var axis_flow = this.mainDiagram.AxisY; axis_flow.CustomLabels.Clear(); axis_flow.CustomLabels.AddRange(coord_flows.ToArray()); axis_flow.NumericScaleOptions.AutoGrid = false; axis_flow.VisualRange.Auto = false; axis_flow.WholeRange.Auto = false; axis_flow.WholeRange.SideMarginsValue = 0; axis_flow.VisualRange.SideMarginsValue = 0; axis_flow.WholeRange.AutoSideMargins = false; axis_flow.VisualRange.AutoSideMargins = false; axis_flow.WholeRange.SetMinMaxValues(coord_min_flow, coord_min_flow + (grid_num - 1)* coord_space_flow); axis_flow.VisualRange.SetMinMaxValues(coord_min_flow, coord_min_flow + (grid_num - 1) * coord_space_flow); axis_flow.WholeRange.AlwaysShowZeroLevel = false; var axis_sw = mainDiagram.SecondaryAxesY.GetAxisByName("SecondarySW"); axis_sw.CustomLabels.Clear(); axis_sw.CustomLabels.AddRange(coord_sw.ToArray()); axis_sw.VisualRange.Auto = false; axis_sw.WholeRange.Auto = false; axis_sw.WholeRange.SideMarginsValue = 0; axis_sw.VisualRange.SideMarginsValue = 0; axis_sw.WholeRange.AutoSideMargins = false; axis_sw.VisualRange.AutoSideMargins = false; axis_sw.WholeRange.SetMinMaxValues(0, 11); axis_sw.VisualRange.SetMinMaxValues(0, 11); axis_sw.WholeRange.AlwaysShowZeroLevel = false; var axis_power = mainDiagram.SecondaryAxesY.GetAxisByName("SecondaryGL"); axis_power.CustomLabels.Clear(); axis_power.CustomLabels.AddRange(coord_powers.ToArray()); axis_power.NumericScaleOptions.AutoGrid = false; axis_power.VisualRange.Auto = false; axis_power.WholeRange.Auto = false; axis_power.WholeRange.SideMarginsValue = 0; axis_power.VisualRange.SideMarginsValue = 0; axis_power.WholeRange.AutoSideMargins = false; axis_power.VisualRange.AutoSideMargins = false; axis_power.WholeRange.SetMinMaxValues(coord_min_power, coord_min_power + (grid_num - 1) * coord_space_power); axis_power.VisualRange.SetMinMaxValues(coord_min_power, coord_min_power + (grid_num - 1) * coord_space_power); axis_power.WholeRange.AlwaysShowZeroLevel = false; } #endregion #region 运行区间 Chart private object _rightClickObj = null; private bool _isMoveQueryLine = false; private Point _clickLocation; 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; } } public Action OnRefreshTimeSpan = null; AnimationTipInfoDlg _tipDlg = null; private void tabbedControlGroup1_CustomHeaderButtonClick(object sender, DevExpress.XtraTab.ViewInfo.CustomHeaderButtonEventArgs e) { if (e.Button.Tag == null) return; if (e.Button.Tag.ToString() == "Setting") { if (OnRefreshTimeSpan != null) { OnRefreshTimeSpan.Invoke(this._anaPrj); } } if (e.Button.Tag.ToString() == "Export") { SaveFileDialog dlg = new SaveFileDialog(); dlg.Title = "导出信息列表"; dlg.FileName = "信息列表.xls"; dlg.Filter = "excel文件 (*.xls)|*.xls"; if (dlg.ShowDialog() == DialogResult.OK) this.gridControl运行列表.ExportToXls(dlg.FileName); } if (e.Button.Tag.ToString() == "ViewTip") { } if (e.Button.Tag.ToString() == "Animation") { ShowChartTipWindow(true); } } bool _isDispAnimationTip = false; private void ShowChartTipWindow(bool isShow) { if (_tipDlg != null) { if (isShow) { if (_isDispAnimationTip) return; _isDispAnimationTip = true; _tipDlg.SetBindingData(this._anaPrj); _tipDlg.SetRealTimeDataList(realTimeDataList); _tipDlg.Show(); } else { _isDispAnimationTip = false; _tipDlg.StopAnimation(); _tipDlg.Hide(); } return; } _tipDlg = new AnimationTipInfoDlg(); _tipDlg.TopMost = true; _tipDlg.Name = "AnimationTipInfoDlg"; _tipDlg.WindowState = FormWindowState.Normal; _tipDlg.SetPumpInfo(this._allPumpInfo); _tipDlg.OnStopAnimation += () => { _moveConstantLineIn实时数据.Visible = false; }; _tipDlg.OnStartAnimation += () => { _moveConstantLineIn实时数据.Visible = true; }; _tipDlg.OnRefreshAnimation += (t, d) => { _moveConstantLineIn实时数据.Title.Text = t.ToString("HH:mm"); _moveConstantLineIn实时数据.AxisValueSerializable = t.ToString(); //if (d == null || d.OpenPumpCount == 0) // return; //chartPumpCurveParalCtrl1.SetPumpRun(d); }; _isDispAnimationTip = true; _moveConstantLineIn实时数据.Title.Text = this._startTime.ToString("HH:mm"); _moveConstantLineIn实时数据.AxisValueSerializable = this._startTime.ToString(); _tipDlg.OnHide = () => { _isDispAnimationTip = false; _tipDlg.Hide(); }; _tipDlg.SetRealTimeDataList(realTimeDataList); _tipDlg.SetBindingData(this._anaPrj); _tipDlg.Show(); } #endregion #region Grid class CurrentGridViewModel { 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); } } private void InitialGrid运行时间() { List gridBidings = new List(); foreach (var item in this._anaPrj.BlockTimes) { List openTimeSpan = new List(); List closeTimeSpan = new List(); var pd = new CurrentGridViewModel(); pd.PumpName = string.Format("{0}台泵", item.OpenPumpCount); 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.SumFlow = item.SumFlow; pd.SumPower = item.SumPower; pd.SumMoney = item.SumMoney; pd.Round(); gridBidings.Add(pd); } this.bindingSourceGrid.DataSource = gridBidings; } 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运行时间(); //} } #endregion private void ChartControl实时数据_CustomPaint(object sender, CustomPaintEventArgs e) { if(_anaPrj == null || mainDiagram == null) return; Graphics g = e.Graphics; //g.SetClip(CalculateDiagramBounds()); g.SmoothingMode = SmoothingMode.AntiAlias; { foreach (var item in this._anaPrj.BlockTimes) { if ( item.OpenPumpCount <= 0) continue; var pump_count = item.OpenPumpCount; using (Font font = new Font("黑体", 9, FontStyle.Italic)) using (SolidBrush brushText = new SolidBrush(Color.Black)) using (SolidBrush brush = new SolidBrush(PumpCountColorHelper.GetColor(pump_count) )) { // var pt1 = mainDiagram.DiagramToPoint(item.StartTime, rang_down_flow); var pt2 = mainDiagram.DiagramToPoint(item.EndTime, rang_up_flow); g.FillRectangle(brush, pt1.Point.X, pt1.Point.Y, Math.Abs(pt1.Point.X - pt2.Point.X), Math.Abs(pt1.Point.Y - pt2.Point.Y)); g.DrawString(string.Format("{0}台", pump_count), font, brushText, new Point(pt1.Point.X, pt1.Point.Y+3)); } } } } private void tabbedControlGroup2_CustomHeaderButtonClick(object sender, DevExpress.XtraTab.ViewInfo.CustomHeaderButtonEventArgs e) { if (chartControl实时数据.Legend.Visibility == DevExpress.Utils.DefaultBoolean.True) { chartControl实时数据.Legend.Visibility = DevExpress.Utils.DefaultBoolean.False; chartControl累计数据.Legend.Visibility = DevExpress.Utils.DefaultBoolean.False; } else { chartControl实时数据.Legend.Visibility = DevExpress.Utils.DefaultBoolean.True; chartControl累计数据.Legend.Visibility = DevExpress.Utils.DefaultBoolean.True; } } } }