IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> 大数据 -> sqlserver 字符串 日期处理(大坝项目) -> 正文阅读

[大数据]sqlserver 字符串 日期处理(大坝项目)

   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;
                //获取该月份    监测点名称  各监测点最大值  最小值z
                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;
                }
                //获取该周份    监测点名称  各监测点最大值  最小值z
                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++;
                }
            }
        }
  大数据 最新文章
实现Kafka至少消费一次
亚马逊云科技:还在苦于ETL?Zero ETL的时代
初探MapReduce
【SpringBoot框架篇】32.基于注解+redis实现
Elasticsearch:如何减少 Elasticsearch 集
Go redis操作
Redis面试题
专题五 Redis高并发场景
基于GBase8s和Calcite的多数据源查询
Redis——底层数据结构原理
上一篇文章      下一篇文章      查看所有文章
加:2021-09-30 11:59:57  更:2021-09-30 12:01:43 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年11日历 -2024/11/23 23:05:20-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码