下面是代码部分:using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using USTC;
using DataMapper;
using System.Data.SqlClient;public partial class 变形监测_竖向位移量统计查询_SXWY : System.Web.UI.Page
{
private static string conString = ConfigurationSettings.AppSettings["ConnectionString"];
public int cdmcNum = 0; protected void Page_Load(object sender, EventArgs e)
{
//竖向位移考证表
BMSXWY_KZ bmsxwy_kz = new BMSXWY_KZ();
DataSet ds = bmsxwy_kz.getCDMC_BMSXWY(); //竖向位移录入表
BTCZWY_LR btczwy_lr = new BTCZWY_LR();
DataSet ds2 = btczwy_lr.getCertainValue(); //从ds中取得测点名称,放入一个集合中
ArrayList al = new ArrayList();
cdmcNum = ds.Tables[0].Rows.Count;
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
al.Add(ds.Tables[0].Rows[i][2]);
} //验证输出结果正确与否
//for (int j = 0; j < al.Count; j++)
//{
// Response.Write(al[j]+"\n");
//}
GridView1.DataSource = ds.Tables[0];
GridView1.DataBind(); GridView2.DataSource = ds2.Tables[0];
GridView2.DataBind(); CreateTable();
} /******************************************2009-5-15日修改部分*****************************************************************/
//数据库操作,返回一个SqlDataReader对象
public SqlDataReader getValues(string strSQL,SqlConnection con)
{
SqlDataReader data = null;
try
{
SqlCommand cmd = new SqlCommand(strSQL, con);
data = cmd.ExecuteReader();
return data;
}
catch (SqlException ex)
{
throw new Exception(ex.Message);
}
} //获取不同日期的总数量,返回一个整形数值
public int getDateNum()
{
SqlConnection con = new SqlConnection();
con.ConnectionString = conString;
con.Open();
string strSQL = "select count(distinct GCRQ) from BTCZWY_LR";
int result = 0;
SqlDataReader data = getValues(strSQL,con);
while (data.Read())
{
result = Convert.ToInt32(data.GetValue(0).ToString());
}
data.Close();
con.Close();
con.Dispose();
return result;
} //获取测点名称,并以一维数组的形式返回
public string[] getCDMC()
{
//竖向位移考证表
BMSXWY_KZ bmsxwy_kz = new BMSXWY_KZ();
DataSet ds = bmsxwy_kz.getCDMC_BMSXWY(); //从ds中取得测点名称,放入一个集合中
ArrayList al = new ArrayList();
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
al.Add(ds.Tables[0].Rows[i][2]);
}
//测点名称的一维数组
string[] cdmc = new string[al.Count];
for (int i = 0; i < al.Count; i++)
{
cdmc[i] = al[i].ToString();
}
return cdmc;
} //获取观测日期,传入的参数是测点名称,返回值是一个二维数组
public string[] getGCRQ()
{
SqlConnection con = new SqlConnection();
con.ConnectionString = conString;
con.Open();
SqlCommand cmd = new SqlCommand();
int dateNum = getDateNum();
string[] cdmc = getCDMC();
string strSQL = "";
ArrayList alGCRQ = new ArrayList();
strSQL = "select distinct GCRQ from BTCZWY_LR,BMSXWY_KZ where CDBH=BH_BMSXKZ and BTCZWY_LR.SKBM=BMSXWY_KZ.SKBM";
cmd.CommandText = strSQL;
cmd.Connection = con;
SqlDataReader data = cmd.ExecuteReader();
while (data.Read())
{
alGCRQ.Add(data.GetValue(0).ToString());
}
data.Close();
string[] gcrq = new string[alGCRQ.Count];
for (int i = 0; i < alGCRQ.Count; i++)
{
gcrq[i] = alGCRQ[i].ToString();
}
con.Close();
con.Dispose(); //验证输出结果正确与否
//for (int i = 0; i < alGCRQ.Count; i++)
//{
// Response.Write(alGCRQ[i]+" ");
//}
return gcrq;
} ////获取沉陷值,返回一个一维数组
public string[,] getCXZ()
{
SqlConnection con = new SqlConnection();
con.ConnectionString = conString;
con.Open();
string[] cdmc = getCDMC();
string[] gcrq = getGCRQ();
string[,] cxz = new string[gcrq.Length,cdmc.Length];
int dateNum = getDateNum(); for (int i = 0; i < dateNum; i++)
{
for (int j = 0; j < cdmc.Length; j++)
{
string strSQL = "select CXZ from BTCZWY_LR,BMSXWY_KZ where CDBH=BH_BMSXKZ and BTCZWY_LR.SKBM=BMSXWY_KZ.SKBM and GCRQ='" + gcrq[i] + "' and CDMC_BMSXKZ= '" + cdmc[j] + "'";
SqlDataReader data = getValues(strSQL, con);
while (data.Read())
{
cxz[i,j] = data.GetValue(0).ToString();
}
data.Close();
} }
//验证输出结果正确与否
//for (int i = 0; i < dateNum; i++)
//{
// for (int j = 0; j < cdmc.Length; j++)
// {
// Response.Write(cxz[i,j]+" ");
// }
//} return cxz;
} //创建页面表格
public void CreateTable()
{
SqlConnection con = new SqlConnection();
con.ConnectionString = conString;
con.Open();
SqlCommand cmd = new SqlCommand();
//测点名称的一维数组
string[] cdmc = getCDMC() ;
//获取观测日期总数
int dateNum = getDateNum();
string strSQL = "";
Response.Write("<table border=1 width=500 align=center><tr><td align=center><b>观测日期</b></td>");
for (int i = 0; i < cdmc.Length; i++)
{
Response.Write("<td align=center><b>" + cdmc[i].ToString()+ "</b></td>");
}
Response.Write("</tr>");
//填充页面表,观测日期以及对象沉陷值
string[] gcrq = getGCRQ();
string[,] cxz = getCXZ();
for (int i = 0; i < dateNum; i++)
{
Response.Write("<tr>");
Response.Write("<td align=center>" + gcrq[i] + "</td>");
for (int j = 0; j < cdmc.Length; j++)
{
Response.Write("<td align=center>" + cxz[i,j] + "</td>");
}
Response.Write("</tr>");
} Response.Write("</table>");
}
}页面显示效果如下:观测日期 aa bb cc . . . .(测点名称从数据库取得,呈水平方向排列)
2009-04-20 100 200 300 . . . .
2009-04-25 400 400 600 . . . .
2009-05-05 120 250 250 . . . .
2009-05-10 500 450 850 . . . .
2009-05-11 600 500 1000 . . . .
.
---------------------------------------
最大值 600 500 1000
日 期 05-11 05-11 05-11
最小值 100 200 300
日 期 05-20 05-20 05-05
变 幅 500 300 700
以上实现的页面显示的内容怎么分页啊,还有针对每页中的每列进行统计啊,实现像虚线下的那样的统计效果?
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using USTC;
using DataMapper;
using System.Data.SqlClient;public partial class 变形监测_竖向位移量统计查询_SXWY : System.Web.UI.Page
{
private static string conString = ConfigurationSettings.AppSettings["ConnectionString"];
public int cdmcNum = 0; protected void Page_Load(object sender, EventArgs e)
{
//竖向位移考证表
BMSXWY_KZ bmsxwy_kz = new BMSXWY_KZ();
DataSet ds = bmsxwy_kz.getCDMC_BMSXWY(); //竖向位移录入表
BTCZWY_LR btczwy_lr = new BTCZWY_LR();
DataSet ds2 = btczwy_lr.getCertainValue(); //从ds中取得测点名称,放入一个集合中
ArrayList al = new ArrayList();
cdmcNum = ds.Tables[0].Rows.Count;
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
al.Add(ds.Tables[0].Rows[i][2]);
} //验证输出结果正确与否
//for (int j = 0; j < al.Count; j++)
//{
// Response.Write(al[j]+"\n");
//}
GridView1.DataSource = ds.Tables[0];
GridView1.DataBind(); GridView2.DataSource = ds2.Tables[0];
GridView2.DataBind(); CreateTable();
} /******************************************2009-5-15日修改部分*****************************************************************/
//数据库操作,返回一个SqlDataReader对象
public SqlDataReader getValues(string strSQL,SqlConnection con)
{
SqlDataReader data = null;
try
{
SqlCommand cmd = new SqlCommand(strSQL, con);
data = cmd.ExecuteReader();
return data;
}
catch (SqlException ex)
{
throw new Exception(ex.Message);
}
} //获取不同日期的总数量,返回一个整形数值
public int getDateNum()
{
SqlConnection con = new SqlConnection();
con.ConnectionString = conString;
con.Open();
string strSQL = "select count(distinct GCRQ) from BTCZWY_LR";
int result = 0;
SqlDataReader data = getValues(strSQL,con);
while (data.Read())
{
result = Convert.ToInt32(data.GetValue(0).ToString());
}
data.Close();
con.Close();
con.Dispose();
return result;
} //获取测点名称,并以一维数组的形式返回
public string[] getCDMC()
{
//竖向位移考证表
BMSXWY_KZ bmsxwy_kz = new BMSXWY_KZ();
DataSet ds = bmsxwy_kz.getCDMC_BMSXWY(); //从ds中取得测点名称,放入一个集合中
ArrayList al = new ArrayList();
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
al.Add(ds.Tables[0].Rows[i][2]);
}
//测点名称的一维数组
string[] cdmc = new string[al.Count];
for (int i = 0; i < al.Count; i++)
{
cdmc[i] = al[i].ToString();
}
return cdmc;
} //获取观测日期,传入的参数是测点名称,返回值是一个二维数组
public string[] getGCRQ()
{
SqlConnection con = new SqlConnection();
con.ConnectionString = conString;
con.Open();
SqlCommand cmd = new SqlCommand();
int dateNum = getDateNum();
string[] cdmc = getCDMC();
string strSQL = "";
ArrayList alGCRQ = new ArrayList();
strSQL = "select distinct GCRQ from BTCZWY_LR,BMSXWY_KZ where CDBH=BH_BMSXKZ and BTCZWY_LR.SKBM=BMSXWY_KZ.SKBM";
cmd.CommandText = strSQL;
cmd.Connection = con;
SqlDataReader data = cmd.ExecuteReader();
while (data.Read())
{
alGCRQ.Add(data.GetValue(0).ToString());
}
data.Close();
string[] gcrq = new string[alGCRQ.Count];
for (int i = 0; i < alGCRQ.Count; i++)
{
gcrq[i] = alGCRQ[i].ToString();
}
con.Close();
con.Dispose(); //验证输出结果正确与否
//for (int i = 0; i < alGCRQ.Count; i++)
//{
// Response.Write(alGCRQ[i]+" ");
//}
return gcrq;
} ////获取沉陷值,返回一个一维数组
public string[,] getCXZ()
{
SqlConnection con = new SqlConnection();
con.ConnectionString = conString;
con.Open();
string[] cdmc = getCDMC();
string[] gcrq = getGCRQ();
string[,] cxz = new string[gcrq.Length,cdmc.Length];
int dateNum = getDateNum(); for (int i = 0; i < dateNum; i++)
{
for (int j = 0; j < cdmc.Length; j++)
{
string strSQL = "select CXZ from BTCZWY_LR,BMSXWY_KZ where CDBH=BH_BMSXKZ and BTCZWY_LR.SKBM=BMSXWY_KZ.SKBM and GCRQ='" + gcrq[i] + "' and CDMC_BMSXKZ= '" + cdmc[j] + "'";
SqlDataReader data = getValues(strSQL, con);
while (data.Read())
{
cxz[i,j] = data.GetValue(0).ToString();
}
data.Close();
} }
//验证输出结果正确与否
//for (int i = 0; i < dateNum; i++)
//{
// for (int j = 0; j < cdmc.Length; j++)
// {
// Response.Write(cxz[i,j]+" ");
// }
//} return cxz;
} //创建页面表格
public void CreateTable()
{
SqlConnection con = new SqlConnection();
con.ConnectionString = conString;
con.Open();
SqlCommand cmd = new SqlCommand();
//测点名称的一维数组
string[] cdmc = getCDMC() ;
//获取观测日期总数
int dateNum = getDateNum();
string strSQL = "";
Response.Write("<table border=1 width=500 align=center><tr><td align=center><b>观测日期</b></td>");
for (int i = 0; i < cdmc.Length; i++)
{
Response.Write("<td align=center><b>" + cdmc[i].ToString()+ "</b></td>");
}
Response.Write("</tr>");
//填充页面表,观测日期以及对象沉陷值
string[] gcrq = getGCRQ();
string[,] cxz = getCXZ();
for (int i = 0; i < dateNum; i++)
{
Response.Write("<tr>");
Response.Write("<td align=center>" + gcrq[i] + "</td>");
for (int j = 0; j < cdmc.Length; j++)
{
Response.Write("<td align=center>" + cxz[i,j] + "</td>");
}
Response.Write("</tr>");
} Response.Write("</table>");
}
}页面显示效果如下:观测日期 aa bb cc . . . .(测点名称从数据库取得,呈水平方向排列)
2009-04-20 100 200 300 . . . .
2009-04-25 400 400 600 . . . .
2009-05-05 120 250 250 . . . .
2009-05-10 500 450 850 . . . .
2009-05-11 600 500 1000 . . . .
.
---------------------------------------
最大值 600 500 1000
日 期 05-11 05-11 05-11
最小值 100 200 300
日 期 05-20 05-20 05-05
变 幅 500 300 700
以上实现的页面显示的内容怎么分页啊,还有针对每页中的每列进行统计啊,实现像虚线下的那样的统计效果?
·详情请访问:http://www.515dns.com
首先从数据库中取出测点名称,放在第一行,第一行第一列是观测日期,后几列是测点名称,
后面每行中第一列中显示观测日期,后面各列显示该观测日期下对应的测点名称下的竖直位移量。就看我的CreateTable()方法即可理解其意思。大家帮忙看看,谢谢!