private void button1_Click(object sender, EventArgs e)
{
String dbid=treeView1.SelectedNode.Tag.ToString();
if (dbid == "") {
MessageBox.Show("请选择大坝");
return;
}
dataGridView1.Rows.Clear();
if (this.year.Checked) {
String year=this.n_year.Text.ToString();
if (year == "") {
return;
}
treeView1.SelectedNode.Tag.ToString();
List<Db_shljcd_t> listParent = new List<Db_shljcd_t>();
using (SqlDataReader dataReader = DBConn.queryData("SELECT a.jcdid,MAX(a.jcsj),MIN(a.jcsj) FROM db_shljcd_t as a LEFT JOIN db_jcd_t as b on a.jcdid = b.id LEFT JOIN db_db_t as c on b.dbid = c.id WHERE a.jcrq like '%" + year + "%' and c.id = " + dbid + " GROUP BY a.jcdid", new SqlParameter[0]))
{
Db_shljcd_t obj_ = new Db_shljcd_t();
while (dataReader.Read())
{
listParent.Add(obj_.getYTzzObject(dataReader));
}
}
if (listParent.Count <= 0)
{
MessageBox.Show("无数据");
return;
}
dataGridView1.Rows.Add(listParent.Count);
int i = 0;
foreach (Db_shljcd_t obj in listParent)
{
List<Db_shljcd_t> listmax = new List<Db_shljcd_t>();
using (SqlDataReader dataReader = DBConn.queryData("SELECT db1.cdbh, db0.jcrq, db0.jcsj FROM db_shljcd_t AS db0 LEFT JOIN db_jcd_t AS db1 ON db0.jcdid= db1.id WHERE db0.jcrq LIKE '%" + year + "%' AND db0.jcsj = " + obj.maxjcsj + " AND db0.jcdid = " + obj.jcdid, new SqlParameter[0]))
{
Db_shljcd_t obj_ = new Db_shljcd_t();
while (dataReader.Read())
{
listmax.Add(obj_.getMaxMinTzzObject(dataReader));
}
}
List<Db_shljcd_t> listmin = new List<Db_shljcd_t>();
using (SqlDataReader dataReader = DBConn.queryData("SELECT db1.cdbh, db0.jcrq, db0.jcsj FROM db_shljcd_t AS db0 LEFT JOIN db_jcd_t AS db1 ON db0.jcdid= db1.id WHERE db0.jcrq LIKE '%" + year + "%' AND db0.jcsj = " + obj.minjcsj + " AND db0.jcdid = " + obj.jcdid , new SqlParameter[0]))
{
Db_shljcd_t obj_ = new Db_shljcd_t();
while (dataReader.Read())
{
listmin.Add(obj_.getMaxMinTzzObject(dataReader));
}
}
List<Db_shljcd_t> listavg = new List<Db_shljcd_t>();
using (SqlDataReader dataReader = DBConn.queryData("SELECT AVG(jcsj ) AS pj,SUBSTRING ( jcrq, 1, 4 ) AS rq FROM db_shljcd_t WHERE jcdid = " + obj.jcdid + " GROUP BY SUBSTRING ( jcrq, 1, 4 ) ORDER BY pj", new SqlParameter[0]))
{
Db_shljcd_t obj_ = new Db_shljcd_t();
while (dataReader.Read())
{
listavg.Add(obj_.getMaxMinAvgTzzObject(dataReader));
}
}
Decimal maxchange=0.0M;
String maxchangerq="";
Decimal minchange = 999999999.0M;
String minchangerq="";
for (int m = 0; m < listavg.Count-1; m++) {
Decimal change = System.Math.Abs(listavg[m + 1].jcsj - listavg[m].jcsj);
if (m == 0) {
maxchange = change;
maxchangerq= listavg[m + 1].jcrq;
minchange = change;
minchangerq = listavg[m + 1].jcrq;
}
if (change > maxchange) {
maxchange = change;
maxchangerq = listavg[m + 1].jcrq;
}
if (change < minchange) {
minchange = change;
minchangerq = listavg[m + 1].jcrq;
}
}
String cdbh = listmax[0].cdbh;
Decimal maxjcsj = listmax[0].jcsj;
String maxrq = listmax[0].jcrq;
Decimal minjcsj = listmin[0].jcsj;
String minrq = listmin[0].jcrq;
Decimal maxavg = listavg[listavg.Count - 1].jcsj;
String maxavgrq = listavg[listavg.Count - 1].jcrq;
Decimal minavg = listavg[0].jcsj;
String minavgrq = listavg[0].jcrq;
DataGridViewRow r1 = dataGridView1.Rows[i];
int j = 0;
r1.Cells[j++].Value = cdbh;
r1.Cells[j++].Value = maxjcsj;
r1.Cells[j++].Value = maxrq;
r1.Cells[j++].Value = minjcsj;
r1.Cells[j++].Value = minrq;
r1.Cells[j++].Value = maxchange;
r1.Cells[j++].Value = maxchangerq;
r1.Cells[j++].Value = minchange;
r1.Cells[j++].Value = minchangerq;
r1.Cells[j++].Value = maxavg;
r1.Cells[j++].Value = maxavgrq;
r1.Cells[j++].Value = minavg;
r1.Cells[j++].Value = minavgrq;
i++;
}
}
if (this.month.Checked) {
String year = this.y_year.Text.ToString();
String month = y_month.SelectedValue.ToString();
if (year == "" || month == "")
{
return;
}
String yearmonth = year + month;
List<Db_shljcd_t> listParent = new List<Db_shljcd_t>();
using (SqlDataReader dataReader = DBConn.queryData("SELECT a.jcdid,MAX(a.jcsj),MIN(a.jcsj) FROM db_shljcd_t as a LEFT JOIN db_jcd_t as b on a.jcdid = b.id LEFT JOIN db_db_t as c on b.dbid = c.id WHERE a.jcrq like '%" + yearmonth + "%' and c.id = " + dbid + " GROUP BY a.jcdid", new SqlParameter[0]))
{
Db_shljcd_t obj_ = new Db_shljcd_t();
while (dataReader.Read())
{
listParent.Add(obj_.getYTzzObject(dataReader));
}
}
if (listParent.Count <= 0)
{
MessageBox.Show("无数据");
return;
}
dataGridView1.Rows.Add(listParent.Count);
int i = 0;
foreach (Db_shljcd_t obj in listParent)
{
List<Db_shljcd_t> listmax = new List<Db_shljcd_t>();
using (SqlDataReader dataReader = DBConn.queryData("SELECT db1.cdbh, db0.jcrq, db0.jcsj FROM db_shljcd_t AS db0 LEFT JOIN db_jcd_t AS db1 ON db0.jcdid= db1.id WHERE db0.jcrq LIKE '%" + yearmonth + "%' AND db0.jcsj = " + obj.maxjcsj + " AND db0.jcdid = " + obj.jcdid, new SqlParameter[0]))
{
Db_shljcd_t obj_ = new Db_shljcd_t();
while (dataReader.Read())
{
listmax.Add(obj_.getMaxMinTzzObject(dataReader));
}
}
List<Db_shljcd_t> listmin = new List<Db_shljcd_t>();
using (SqlDataReader dataReader = DBConn.queryData("SELECT db1.cdbh, db0.jcrq, db0.jcsj FROM db_shljcd_t AS db0 LEFT JOIN db_jcd_t AS db1 ON db0.jcdid= db1.id WHERE db0.jcrq LIKE '%" + yearmonth + "%' AND db0.jcsj = " + obj.minjcsj + " AND db0.jcdid = " + obj.jcdid, new SqlParameter[0]))
{
Db_shljcd_t obj_ = new Db_shljcd_t();
while (dataReader.Read())
{
listmin.Add(obj_.getMaxMinTzzObject(dataReader));
}
}
List<Db_shljcd_t> listavg = new List<Db_shljcd_t>();
using (SqlDataReader dataReader = DBConn.queryData("SELECT AVG(jcsj ) AS pj,SUBSTRING ( jcrq, 1, 7 ) AS rq FROM db_shljcd_t WHERE jcdid = " + obj.jcdid + "and jcrq LIKE '%" + year + "%' GROUP BY SUBSTRING ( jcrq, 1, 7 ) ORDER BY pj", new SqlParameter[0]))
{
Db_shljcd_t obj_ = new Db_shljcd_t();
while (dataReader.Read())
{
listavg.Add(obj_.getMaxMinAvgTzzObject(dataReader));
}
}
List<Db_shljcd_t> listavgbyrq = new List<Db_shljcd_t>();
using (SqlDataReader dataReader = DBConn.queryData("SELECT AVG(jcsj ) AS pj,SUBSTRING ( jcrq, 1, 7 ) AS rq FROM db_shljcd_t WHERE jcdid = " + obj.jcdid + "and jcrq LIKE '%" + year + "%' GROUP BY SUBSTRING ( jcrq, 1, 7 ) ORDER BY SUBSTRING( jcrq, 1, 7 )", new SqlParameter[0]))
{
Db_shljcd_t obj_ = new Db_shljcd_t();
while (dataReader.Read())
{
listavgbyrq.Add(obj_.getMaxMinAvgTzzObject(dataReader));
}
}
Decimal maxchange = 0.0M;
String maxchangerq = "";
Decimal minchange = 999999999.0M;
String minchangerq = "";
for (int m = 0; m < listavgbyrq.Count - 1; m++)
{
Decimal change = System.Math.Abs(listavgbyrq[m + 1].jcsj - listavgbyrq[m].jcsj);
if (m == 0)
{
maxchange = change;
maxchangerq = listavgbyrq[m + 1].jcrq;
minchange = change;
minchangerq = listavgbyrq[m + 1].jcrq;
}
if (change > maxchange)
{
maxchange = change;
maxchangerq = listavgbyrq[m + 1].jcrq;
}
if (change < minchange)
{
minchange = change;
minchangerq = listavgbyrq[m + 1].jcrq;
}
}
String cdbh = listmax[0].cdbh;
Decimal maxjcsj = listmax[0].jcsj;
String maxrq = listmax[0].jcrq;
Decimal minjcsj = listmin[0].jcsj;
String minrq = listmin[0].jcrq;
Decimal maxavg = listavg[listavg.Count - 1].jcsj;
String maxavgrq = listavg[listavg.Count - 1].jcrq;
Decimal minavg = listavg[0].jcsj;
String minavgrq = listavg[0].jcrq;
DataGridViewRow r1 = dataGridView1.Rows[i];
int j = 0;
r1.Cells[j++].Value = cdbh;
r1.Cells[j++].Value = maxjcsj;
r1.Cells[j++].Value = maxrq;
r1.Cells[j++].Value = minjcsj;
r1.Cells[j++].Value = minrq;
r1.Cells[j++].Value = maxchange;
r1.Cells[j++].Value = maxchangerq;
r1.Cells[j++].Value = minchange;
r1.Cells[j++].Value = minchangerq;
r1.Cells[j++].Value = maxavg;
r1.Cells[j++].Value = maxavgrq;
r1.Cells[j++].Value = minavg;
r1.Cells[j++].Value = minavgrq;
i++;
}
}
if (this.week.Checked) {
String rq = z_rq.Text.ToString();
String year = rq.Substring(0, 4);
if (year == "" || rq == "")
{
MessageBox.Show("请填写范围");
return;
}
List<Db_shljcd_t> listParent = new List<Db_shljcd_t>();
using (SqlDataReader dataReader = DBConn.queryData("SELECT a.jcdid,MAX(a.jcsj),MIN(a.jcsj) FROM db_shljcd_t as a LEFT JOIN db_jcd_t as b on a.jcdid = b.id LEFT JOIN db_db_t as c on b.dbid = c.id WHERE SUBSTRING ( a.jcrq, 1, 4 )='" + year + "' and datepart(week, a.jcrq)=datepart(week,'" + rq + "') and c.id = " + dbid + " GROUP BY a.jcdid", new SqlParameter[0]))
{
Db_shljcd_t obj_ = new Db_shljcd_t();
while (dataReader.Read())
{
listParent.Add(obj_.getYTzzObject(dataReader));
}
}
if (listParent.Count <= 0) {
MessageBox.Show("无数据");
return;
}
MessageBox.Show(listParent.Count.ToString());
dataGridView1.Rows.Add(listParent.Count);
int i = 0;
foreach (Db_shljcd_t obj in listParent)
{
MessageBox.Show(obj.jcdid.ToString());
List<Db_shljcd_t> listmax = new List<Db_shljcd_t>();
using (SqlDataReader dataReader = DBConn.queryData("SELECT db1.cdbh, db0.jcrq, db0.jcsj FROM db_shljcd_t AS db0 LEFT JOIN db_jcd_t AS db1 ON db0.jcdid= db1.id WHERE SUBSTRING ( jcrq, 1, 4 )='" + year + "' AND datepart(week, jcrq)=datepart(week,'" + rq + "') AND db0.jcsj = " + obj.maxjcsj + " AND db0.jcdid = " + obj.jcdid, new SqlParameter[0]))
{
Db_shljcd_t obj_ = new Db_shljcd_t();
while (dataReader.Read())
{
listmax.Add(obj_.getMaxMinTzzObject(dataReader));
}
}
List<Db_shljcd_t> listmin = new List<Db_shljcd_t>();
using (SqlDataReader dataReader = DBConn.queryData("SELECT db1.cdbh, db0.jcrq, db0.jcsj FROM db_shljcd_t AS db0 LEFT JOIN db_jcd_t AS db1 ON db0.jcdid= db1.id WHERE SUBSTRING ( jcrq, 1, 4 )='" + year + "' AND datepart(week, jcrq)=datepart(week,'" + rq + "') AND db0.jcsj = " + obj.minjcsj + " AND db0.jcdid = " + obj.jcdid, new SqlParameter[0]))
{
Db_shljcd_t obj_ = new Db_shljcd_t();
while (dataReader.Read())
{
listmin.Add(obj_.getMaxMinTzzObject(dataReader));
}
}
List<Db_shljcd_t> listavg = new List<Db_shljcd_t>();
using (SqlDataReader dataReader = DBConn.queryData("SELECT AVG(jcsj ) AS pj,'第'+convert(varchar(50),datepart(week, jcrq))+'周' AS rq FROM db_shljcd_t WHERE jcdid =" + obj.jcdid+ " and SUBSTRING(jcrq, 1, 4 )='"+year+"' GROUP BY datepart(week, jcrq) ORDER BY PJ", new SqlParameter[0]))
{
Db_shljcd_t obj_ = new Db_shljcd_t();
while (dataReader.Read())
{
listavg.Add(obj_.getMaxMinAvgTzzObject(dataReader));
}
}
List<Db_shljcd_t> listavgbyrq = new List<Db_shljcd_t>();
using (SqlDataReader dataReader = DBConn.queryData("SELECT AVG(jcsj) AS pj, '第' + convert(varchar(50), datepart(week, jcrq)) + '周' AS rq FROM db_shljcd_t WHERE jcdid = " + obj.jcdid+ " and SUBSTRING(jcrq, 1, 4) = '"+year+"' GROUP BY datepart(week, jcrq) ORDER BY rq", new SqlParameter[0]))
{
Db_shljcd_t obj_ = new Db_shljcd_t();
while (dataReader.Read())
{
listavgbyrq.Add(obj_.getMaxMinAvgTzzObject(dataReader));
}
}
Decimal maxchange = 0.0M;
String maxchangerq = "";
Decimal minchange = 999999999.0M;
String minchangerq = "";
for (int m = 0; m < listavgbyrq.Count - 1; m++)
{
Decimal change = System.Math.Abs(listavgbyrq[m + 1].jcsj - listavgbyrq[m].jcsj);
if (m == 0)
{
maxchange = change;
maxchangerq = listavgbyrq[m + 1].jcrq;
minchange = change;
minchangerq = listavgbyrq[m + 1].jcrq;
}
if (change > maxchange)
{
maxchange = change;
maxchangerq = listavgbyrq[m + 1].jcrq;
}
if (change < minchange)
{
minchange = change;
minchangerq = listavgbyrq[m + 1].jcrq;
}
}
String cdbh = listmax[0].cdbh;
Decimal maxjcsj = listmax[0].jcsj;
String maxrq = listmax[0].jcrq;
Decimal minjcsj = listmin[0].jcsj;
String minrq = listmin[0].jcrq;
Decimal maxavg = listavg[listavg.Count - 1].jcsj;
String maxavgrq = listavg[listavg.Count - 1].jcrq;
Decimal minavg = listavg[0].jcsj;
String minavgrq = listavg[0].jcrq;
DataGridViewRow r1 = dataGridView1.Rows[i];
int j = 0;
r1.Cells[j++].Value = cdbh;
r1.Cells[j++].Value = maxjcsj;
r1.Cells[j++].Value = maxrq;
r1.Cells[j++].Value = minjcsj;
r1.Cells[j++].Value = minrq;
r1.Cells[j++].Value = maxchange;
r1.Cells[j++].Value = maxchangerq;
r1.Cells[j++].Value = minchange;
r1.Cells[j++].Value = minchangerq;
r1.Cells[j++].Value = maxavg;
r1.Cells[j++].Value = maxavgrq;
r1.Cells[j++].Value = minavg;
r1.Cells[j++].Value = minavgrq;
i++;
}
}
}
|