ZedGraph 画水位过程线,入库流量过程线,综合过程线

  
    
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace YNRBSYS.SysManage
{
public partial class FrmText : Form
{
string stcd = " 10911000 " ;
string dtStart = "" ;
string dtEnd = "" ;
string flag = "" ;
DataTable dt
= new DataTable();
int showCount = 0 ;

public FrmText()
{
InitializeComponent();
BindStcd();
this .comboBox1.SelectedIndexChanged += new EventHandler(comboBox1_SelectedIndexChanged);
}

/// <summary>
/// 设置选择项索引
/// </summary>
private void SetStcdIndex()
{
DataTable dt
= (DataTable) this .comboBox1.DataSource;
if (dt.Rows.Count > 0 )
{
for ( int i = 0 ; i < dt.Rows.Count; i ++ )
{
if (stcd.Trim().Equals(dt.Rows[i][ " stcd " ].ToString().Trim()))
{
this .comboBox1.SelectedIndex = i;
break ;
}
}
}
}

/// <summary>
/// 测站列表选择事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void comboBox1_SelectedIndexChanged( object sender, EventArgs e)
{
this .stcd = this .comboBox1.SelectedValue.ToString();
this .dtStart = this .dateTimePicker1.Value.ToString();
this .dtEnd = this .dateTimePicker2.Value.ToString();
LoadData();
if (flag == " rz " )
{
DrawSw();
}
else if (flag == " inq " )
{
DrawRk();
}
else if (flag == " otq " )
{
DrawCk();
}
else
{
DrawZh();
}
showCount
++ ;
}

/// <summary>
/// 邦定水库名称站码
/// </summary>
private void BindStcd()
{
string sql = " select stcd,stnm from st_stbprp_b where sttp='RR' " ;
DataSet ds
= SQLHelper.ExecuteDataset(SQLHelper.ConnCCSYQ, CommandType.Text, sql);
if (ds.Tables.Count > 0 && ds.Tables[ 0 ].Rows.Count > 0 )
{
this .comboBox1.DataSource = ds.Tables[ 0 ];
this .comboBox1.DisplayMember = " stnm " ;
this .comboBox1.ValueMember = " stcd " ;
}
}
/// <summary>
/// 初始化方法
/// </summary>
private void LoadData()
{

string sql = " select a.tm, a.rz,a.inq,a.w,a.otq from st_rsvr_r a inner join " +
" st_stbprp_b b on a.stcd=b.stcd where a.stcd=' " + stcd + " ' and a.tm>' " + dtStart + " ' and a.tm<' " + dtEnd + " ' " ;
DataSet ds
= SQLHelper.ExecuteDataset(SQLHelper.ConnCCSYQ, CommandType.Text, sql);
if (ds.Tables.Count > 0 && ds.Tables[ 0 ].Rows.Count > 0 )
{
dt
= ds.Tables[ 0 ];
this .dataGridViewX1.DataSource = dt.DefaultView;
}

this .dtStart = this .dateTimePicker1.Text;
this .dtEnd = this .dateTimePicker2.Text;

// string sql111 = "select drp, tm from st_pptn_r where stcd='10911000' and tm>'2010-8-19' and tm<'2010-8-26'";
// DataSet ds111 = SQLHelper.ExecuteDataset(SQLHelper.ConnCCSYQ, CommandType.Text, sql111);
// if (ds111.Tables.Count > 0 && ds111.Tables[0].Rows.Count > 0)
// {
// dt111 = ds111.Tables[0];
// }
}

/// <summary>
/// 设置参数
/// </summary>
private void SetDraw()
{
zed.LineItemList();
zed.Title
= this .comboBox1.Text + " 水库综合线图 " ;
zed.TitleColor
= Color.Red;
zed.IsShowPointValues(
true );
// zed.IsShowCursorValues(true);
}

/// <summary>
/// 画线
/// </summary>
private void Draw()
{
DateTime maxtime
= Convert.ToDateTime(dt.Rows[dt.Rows.Count - 1 ][ " tm " ]);
DateTime mintime
= Convert.ToDateTime(dt.Rows[ 0 ][ " tm " ]);


zed.Step_X
= 0.25 ; // 步长为6小时
zed.LongTime = true ;
zed.CreateChartLineItem(dt,
" tm " , " rz " , maxtime, mintime, " 水位 " , 1 , Color.Blue);
zed.CreateChartLineItem(dt,
" tm " , " inq " , maxtime, mintime, " 入库流量 " , 2 , Color.Red);

// zed.CreateChartLineItem(dt, "时间", "nr", 1, "出库流量", Color.Red);
// zed.CreateChartLineItem(dt, "时间", "出库流量", maxtime, mintime, "出库流量", 2, Color.Green);

// zed.IsSmooth = true;
// zed.CreateChartBarItem(dt111, "tm", "drp", maxtime, mintime, "降雨量", 3, Color.Green, Color.White, false, 0.2);

}

/// <summary>
/// 水位画法
/// </summary>
private void DrawSw()
{
if (showCount > 0 )
{
zed.LineItemList();
}
zed.Title
= this .comboBox1.Text + " 水库水位过程线图 " ;
this .Text = this .comboBox1.Text + " 水库水位过程线图 " ;
zed.TitleColor
= Color.Red;
zed.IsShowPointValues(
true );
zed.Y1Title
= " 水位(m) " ;

DateTime maxtime
= Convert.ToDateTime(dt.Rows[dt.Rows.Count - 1 ][ " tm " ]);
DateTime mintime
= Convert.ToDateTime(dt.Rows[ 0 ][ " tm " ]);

zed.Step_X
= 0.25 ; // 步长为6小时
zed.LongTime = true ;
zed.CreateChartLineItem(dt,
" tm " , " rz " , maxtime, mintime, " 水位 " , 1 , Color.Blue);

}

/// <summary>
/// 入库流量画法
/// </summary>
private void DrawRk()
{
if (showCount > 0 )
{
zed.LineItemList();
}
zed.Title
= this .comboBox1.Text + " 水库入库流量过程线图 " ;
this .Text = this .comboBox1.Text + " 水库入库流量过程线图 " ;
zed.TitleColor
= Color.Red;
zed.IsShowPointValues(
true );
zed.Y1Title
= " 入库流量(m3/s) " ;

DateTime maxtime
= Convert.ToDateTime(dt.Rows[dt.Rows.Count - 1 ][ " tm " ]);
DateTime mintime
= Convert.ToDateTime(dt.Rows[ 0 ][ " tm " ]);

zed.Step_X
= 0.25 ; // 步长为6小时
zed.LongTime = true ;
zed.CreateChartLineItem(dt,
" tm " , " inq " , maxtime, mintime, " 入库流量 " , 1 , Color.Red);
}

/// <summary>
/// 出库流量画法
/// </summary>
private void DrawCk()
{
if (showCount > 0 )
{
zed.LineItemList();
}
zed.Title
= this .comboBox1.Text + " 水库出库流量过程线图 " ;
this .Text = this .comboBox1.Text + " 水库出库流量过程线图 " ;
zed.TitleColor
= Color.Red;
zed.IsShowPointValues(
true );
zed.Y1Title
= " 出库流量(m3/s) " ;

DateTime maxtime
= Convert.ToDateTime(dt.Rows[dt.Rows.Count - 1 ][ " tm " ]);
DateTime mintime
= Convert.ToDateTime(dt.Rows[ 0 ][ " tm " ]);

// zed.Step_X = 0.25; // 步长为6小时
// zed.LongTime = true;
// zed.CreateChartLineItem(dt, "tm", "otq", maxtime, mintime, "出库流量", 1, Color.Red);

// zed.Step_X = 1;
zed.LongTime = true ;
zed.IsSmooth
= false ;
zed.CreateChartLineItem(dt,
" tm " , " otq " , maxtime, mintime, " 出库流量 " , 1 , Color.Red);

}

/// <summary>
/// 综合图画法
/// </summary>
private void DrawZh()
{
if (showCount > 0 )
{
zed.LineItemList();
}
zed.Title
= this .comboBox1.Text + " 水库综合过程线图 " ;
this .Text = this .comboBox1.Text + " 水库综合过程线图 " ;
zed.TitleColor
= Color.Red;
zed.IsShowPointValues(
true );
zed.Y1Title
= " 水位(m) " ;
zed.Y2Title
= " 流量(m3/s) " ;

DateTime maxtime
= Convert.ToDateTime(dt.Rows[dt.Rows.Count - 1 ][ " tm " ]);
DateTime mintime
= Convert.ToDateTime(dt.Rows[ 0 ][ " tm " ]);

zed.Step_X
= 0.25 ; // 步长为6小时
zed.LongTime = true ;
zed.CreateChartLineItem(dt,
" tm " , " rz " , maxtime, mintime, " 水位 " , 1 , Color.Blue);
zed.CreateChartLineItem(dt,
" tm " , " inq " , maxtime, mintime, " 入库流量 " , 2 , Color.Red);
}

/// <summary>
/// 画水位过程线
/// </summary>
public void DrawSwGcx( string stcd)
{
flag
= " rz " ;
this .stcd = stcd;
SetStcdIndex();
}

/// <summary>
/// 画入库流量过程线
/// </summary>
public void DrawRkLlGcx( string stcd)
{
flag
= " inq " ;
this .stcd = stcd;
SetStcdIndex();
}

/// <summary>
/// 画出库流量过程线
/// </summary>
public void DrawCkLlGcx( string stcd)
{
flag
= " otq " ;
this .stcd = stcd;
SetStcdIndex();
}

/// <summary>
/// 画综合过程线
/// </summary>
public void DrawZhGcx( string stcd)
{
flag
= " zh " ;
this .stcd = stcd;
SetStcdIndex();
}
}
}

你可能感兴趣的:(Graph)