VS2010 水晶报表不能翻页

u011093377 2013-07-06 08:44:24
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using CrystalDecisions.CrystalReports.Engine;


public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//CrystalReportViewer1.Visible = false;

if (!Page.IsPostBack)
{
this.Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('您已登陆生产管理网站')</script>");

}

}
////产量所有显示
protected void Button2_Click(object sender, EventArgs e)
{
ReportDocument optDoc = new ReportDocument();
optDoc.Load(Server.MapPath("~\\CrystalReport.rpt"));
optDoc.SetDataSource(chanliang.GetCheckData());
CrystalReportViewer1.ReportSource = optDoc;
CrystalReportViewer1.Visible = true;
//btnShowAll.Enable=false;

}


//以线体名称产量查询
public string pointid { get { return pointid; } set { pointid = value; } }

protected void Button1_Click1(object sender, EventArgs e)
{
Boolean flag = true;
if (TextBox1.Text.Trim() == "")
{
this.Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('您还没有输入查询内容,请确认输入查询内容后再操作')</script>");
TextBox1.Focus();

}
else
{
DataTable dataTable = chanliang.GetCheckData();
for (int index = 0; index < dataTable.Rows.Count; index++)
{

if ((string)dataTable.Rows[index]["point_id"] == this.TextBox1.Text.Trim())
{

ReportDocument optDoc = new ReportDocument();
optDoc.Load(Server.MapPath("~\\CrystalReport.rpt"));
optDoc.SetDataSource(chanliang.GetCheckData(this.TextBox1.Text.Trim()));

CrystalReportViewer1.ReportSource = optDoc;
CrystalReportViewer1.Visible = true;
flag = true;
break;

}
else
flag = false;
}
if (flag == false)
{
this.Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('没有您收索的内容')</script>");

}


}




}


//以时间查询产量
protected void Button3_Click(object sender, EventArgs e)
{

if (Btime.Text.Trim() != "" && Etime.Text.Trim() != "")
{
ReportDocument optDoc = new ReportDocument();
optDoc.Load(Server.MapPath("~\\CrystalReport.rpt"));
optDoc.SetDataSource(chanliang.GetCheckData1(Btime.Text.Trim(), Etime.Text.Trim()));

CrystalReportViewer1.ReportSource = optDoc;
CrystalReportViewer1.Visible = true;




}
else
{
Response.Write("<script>alert('请选择时间!')</script>");

}

}

protected void Button4_Click(object sender, EventArgs e)
{
Response.Redirect("default3.aspx");
}
protected void Button5_Click(object sender, EventArgs e)
{
Response.Redirect("default2.aspx");
}
}





类代码如下


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;



public class chanliang
{

//产量所有显示
public static DataTable GetCheckData()
{

string strConn = "Data Source=WINDOWS-123456789;Initial Catalog=SQ_bb;Persist Security Info=True;User ID=sa;Password=296267280@qq.com";

using (SqlConnection conn = new SqlConnection(strConn))
{
string connStr = "select timestamp,point_id,description,_VAL from V_chanliang";
SqlDataAdapter da = new SqlDataAdapter(connStr, conn);
DataSet ds = new DataSet();
da.Fill(ds, "V_chanliang");

return ds.Tables[0];
}

}

//以线体名称产量查询
public static DataTable GetCheckData(string pointid)
{
string strConn = "Data Source=WINDOWS-123456789;Initial Catalog=SQ_bb;Persist Security Info=True;User ID=sa;Password=296267280@qq.com";
SqlConnection conn = new SqlConnection(strConn);
SqlCommand selCmd = new SqlCommand();

selCmd.Connection = conn;

selCmd.Parameters.Add("@point_id", SqlDbType.VarChar, 55);
selCmd.CommandText = "select timestamp,point_id,description,_VAL from V_chanliang where point_id=@point_id";

selCmd.Parameters[0].Value = pointid;
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = selCmd;
DataSet ds = new DataSet();
da.Fill(ds, "V_chanliang");


return ds.Tables[0];

}
//以时间查询产量
public static DataTable GetCheckData1(string time1, string time2)
{
string strConn = "Data Source=WINDOWS-123456789;Initial Catalog=SQ_bb;Persist Security Info=True;User ID=sa;Password=296267280@qq.com";
SqlConnection conn = new SqlConnection(strConn);
SqlCommand selCmd = new SqlCommand();

selCmd.Connection = conn;


selCmd.CommandText = "select timestamp,point_id,description,_VAL from V_chanliang where timestamp>='" + time1 + "'and timestamp<='" + time2 + "' ";


SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = selCmd;
DataSet ds = new DataSet();
da.Fill(ds, "V_chanliang");


return ds.Tables[0];

}
//显示所有报警信息
public static DataTable GetCheckData2()
{

string strConn = "Data Source=WINDOWS-123456789;Initial Catalog=SQ_bb;Persist Security Info=True;User ID=sa;Password=296267280@qq.com";

using (SqlConnection conn = new SqlConnection(strConn))
{
string connStr = "select timestamp,alarm_id,alarm_message,prev_state from ALARM_LOG";
SqlDataAdapter da = new SqlDataAdapter(connStr, conn);
DataSet ds = new DataSet();
da.Fill(ds, "ALARM_LOG");

return ds.Tables[0];
}

}
//以线体名称查询报警
public static DataTable GetCheckData3(string alarmid)
{
string strConn = "Data Source=WINDOWS-123456789;Initial Catalog=SQ_bb;Persist Security Info=True;User ID=sa;Password=296267280@qq.com";
SqlConnection conn = new SqlConnection(strConn);
SqlCommand selCmd = new SqlCommand();

selCmd.Connection = conn;

selCmd.Parameters.Add("@alarm_id", SqlDbType.VarChar, 55);
selCmd.CommandText = "select timestamp,alarm_id,alarm_message,prev_state from ALARM_LOG where alarm_id=@alarm_id";

selCmd.Parameters[0].Value = alarmid;
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = selCmd;
DataSet ds = new DataSet();
da.Fill(ds, "ALARM_LOG");


return ds.Tables[0];

}

//以时间查询报警信息
public static DataTable GetCheckData4(string time1, string time2)
{
string strConn = "Data Source=WINDOWS-123456789;Initial Catalog=SQ_bb;Persist Security Info=True;User ID=sa;Password=296267280@qq.com";
SqlConnection conn = new SqlConnection(strConn);
SqlCommand selCmd = new SqlCommand();

selCmd.Connection = conn;


selCmd.CommandText = "select timestamp,alarm_id,alarm_message,prev_state from ALARM_LOG where timestamp>='" + time1 + "'and timestamp<='" + time2 + "' ";


SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = selCmd;
DataSet ds = new DataSet();
da.Fill(ds, "ALARM_LOG");


return ds.Tables[0];

}



}








...全文
301 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
u011093377 2013-07-07
  • 打赏
  • 举报
回复
以解决,结贴
u011093377 2013-07-06
  • 打赏
  • 举报
回复
图片如下
u011093377 2013-07-06
  • 打赏
  • 举报
回复

17,741

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 .NET Framework
社区管理员
  • .NET Framework社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧