C#代码,查询
2017-04-12 16:25
169 查看
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using DevComponents.DotNetBar; using DDWaterAndRainfallSystem.common; using System.Collections; using DDWaterAndRainfallSystem.Common; using DDWaterAndRainfallSystem.WaterAndRainfall.WaterRegimenQuery; using Microsoft.Reporting.WinForms; //水情查询==多年水情查询==窗体文件 namespace DDWaterAndRainfallSystem { public partial class DuoNianShuiQingFrm : Office2007Form { DataBase db; public DuoNianShuiQingFrm() { db = new DataBase(); InitializeComponent(); TreeConstuctor ts = new TreeConstuctor(); ts.addSWTreeNode(treeViewStcd, "'RR','ZZ'"); treeViewStcd.ExpandAll(); } private void DuoNianShuiQingFrm_Load(object sender, EventArgs e) { //设置下拉列表年份,默认显示当前年份(2014)以及近20年年份 string Year = DateTime.Now.Date.Year.ToString(); int intYear = Convert.ToInt32(Year) + 1; int chaYear = intYear - 1990;//年数 string[] Yearlist; Yearlist = new string[chaYear]; for (int i = 0; i < chaYear; i++) { Yearlist[i] = (intYear-i-1).ToString(); } comboBox1.DataSource = Yearlist; comboBox1.SelectedIndex = 0; } //默认查询所有,点击按钮根据年份和水域名称查询 private void btnQuery_Click(object sender, EventArgs e) { string yearValue = this.comboBox1.SelectedValue.ToString(); ArrayList alStcd = TreeSelect.getTreeSelectStcd(treeViewStcd); this.onSearch(yearValue, alStcd); } private void onSearch(String yearValue, ArrayList waterName) { DataTable dt = this.fillData(yearValue, waterName); string rootpath = Application.StartupPath.Substring(0, Application.StartupPath.LastIndexOf("\\")); rootpath = rootpath.Substring(0, rootpath.LastIndexOf("\\")); reportViewer1.LocalReport.ReportPath = rootpath + "\\WaterAndRainfall\\WaterRegimenQuery\\yearsWaterReport.rdlc"; this.reportViewer1.LocalReport.DataSources.Clear(); this.reportViewer1.LocalReport.DataSources.Add(new Microsoft.Reporting.WinForms.ReportDataSource("DataSet1", dt)); ReportParameter rp = new ReportParameter("title", " 测站多年水位"); this.reportViewer1.LocalReport.SetParameters(new ReportParameter[] { rp }); this.reportViewer1.RefreshReport(); this.reportViewer1.Visible = true; } //根据查询条件(年份和水域名称)获得查询结果 private DataTable fillData(String yearValue, ArrayList waterName) { String yearValue2 =Convert.ToString( Convert.ToInt32(yearValue) + 1); String waterStcds = "'" + "0" + "',"; if (null != waterName && waterName.Count > 0) { for (int i = 0; i < waterName.Count; i++) { waterStcds += "'"+waterName[i]+"'" + ","; } } waterStcds = waterStcds.Trim().Substring(0, waterStcds.Length - 1); // MessageBox.Show(waterStcds); DataTable dt = new DataTable(); dt.Columns.Add(new DataColumn("year"));//年份 dt.Columns.Add(new DataColumn("water"));//测站名称 dt.Columns.Add(new DataColumn("avg"));//年平均水位 dt.Columns.Add(new DataColumn("max"));//年最高水位 dt.Columns.Add(new DataColumn("min"));//年最低水位 db.open(); try { string sql = "select rtrim(b.stnm) as water, " + " (select top 1 DatePart(YEAR,t0.tm) from st_rsvr_r t0 where t0.stcd=b.stcd and t0.tm>='" + yearValue + "/1/1" + "' and t0.tm<='" + yearValue2 + "/1/1" + "' ) as year," + " (select cast(round(avg(t1.rz),2) as decimal(10,2)) from st_rsvr_r t1 where t1.stcd=b.stcd and t1.tm>='" + yearValue + "/1/1" + "' and t1.tm<='" + yearValue2 + "/1/1" + "' ) as avg," + " (select cast(round(max(t2.rz),2) as decimal(10,2)) from st_rsvr_r t2 where t2.stcd=b.stcd and t2.tm>='" + yearValue + "/1/1" + "' and t2.tm<='" + yearValue2 + "/1/1" + "' ) as max," + " (select cast(round(min(t3.rz),2) as decimal(10,2)) from st_rsvr_r t3 where t3.stcd=b.stcd and t3.tm>='" + yearValue + "/1/1" + "' and t3.tm<='" + yearValue2 + "/1/1" + "' ) as min " + " from st_stbprp_b b where b.sttp in('RR','ZZ') and b.stcd in(" + waterStcds + ") "; dt = db.getDataTable(sql); return dt; } catch (Exception e) { MessageBox.Show(e.Message); throw; } finally { if (db.connection.State == ConnectionState.Open) db.close(); } } private void treeViewStcd_AfterCheck(object sender, TreeViewEventArgs e) { TreeSelect.afterCheck(sender, e); } } }
相关文章推荐
- c#查询QQ状态是否在线查询代码
- c#查询QQ状态是否在线查询代码
- C#代码利用MongoDB中Group聚合函数查询
- C#中,带关键字的按页获取查询,这是部份代码,但可以看出大概实现方式
- 编写高质量代码改善C#程序的157个建议——建议31:在LINQ查询中避免不必要的迭代
- C#查询Whois代码
- .net下所有DLL(API)查询,转换C#代码
- 一段后台C#查询SQL Server数据库代码
- 发票查询代码c# by赤峰
- c# GridControl的模糊查询实现代码
- C# 一个简单分词程序的思路和代码(四) 键树 查询记录
- C# 跟查询有关的代码
- C#域名查询代码
- C#代码 利用MongoDB中Group聚合函数查询
- C#访问Oracle查询通用代码总结
- c#查询QQ状态是否在线查询代码
- 分享C#域名查询代码!
- C#利用Linq对DataTable过滤查询代码
- 编写高质量代码改善C#程序的157个建议——建议27:在查询中使用Lambda表达式
- C#链接SQLServer实现插入和查询数据源代码