WEB开发网
开发学院软件开发C语言 水晶报表:单击表头排序C#2.0版 阅读

水晶报表:单击表头排序C#2.0版

 2009-03-02 08:17:56 来源:WEB开发网   
核心提示: 图片看不清楚?请点击这里查看原图(大图),4 把该字添加到“排序字段”中,水晶报表:单击表头排序C#2.0版(2),提示:这一步较重要,其它字段排序时不用选了,按Loaction排序前 图片看不清楚?请点击这里查看原图(大图),按“Location&rd

水晶报表:单击表头排序C#2.0版

图片看不清楚?请点击这里查看原图(大图)。

4 把该字添加到“排序字段”中,提示:这一步较重要,其它字段排序时不用选了,选择这一个就可以了,如果多选的话,可能就不能排序了。

水晶报表:单击表头排序C#2.0版

这些基本的操作完成后,

先看一下预览的界面,按Loaction排序前

水晶报表:单击表头排序C#2.0版

图片看不清楚?请点击这里查看原图(大图)。

按“Location”排序后:

水晶报表:单击表头排序C#2.0版

图片看不清楚?请点击这里查看原图(大图)。

以下是源代码:

C# code

using System;
using System.Data;
using System.Configuration;
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 System.Data.SqlClient;
using CrystalDecisions.CrystalReports.Engine;
public partial class _Default : System.Web.UI.Page
{
public string g_MyConnection = System.Configuration.ConfigurationManager.ConnectionStrings["MyconnectionStrings"].ToString();
private static ReportDocument m_ReportDoc =new ReportDocument();
private static string m_strGetFldName = null;
private static bool m_FlagOrder = false;//用来判断排序的方式:AscendingOrder,DescendingOrder
  private static bool m_FlagOverPage = false;//控制是否是“IsPostBack”的翻页标志
  protected void Page_Load(object sender, EventArgs e)
{
}
protected override void OnPreRender(EventArgs e)
{
base.OnPreRender(e);
if (IsPostBack)
{
//获取缓存的报表
      m_ReportDoc = (ReportDocument)Session["Report"];
if (m_ReportDoc == null)
{
ReportDoc_Bind();
}
m_strGetFldName = null;
this.crystalReportViewer.ReportSource = m_ReportDoc;
m_FlagOverPage = true;
}
if (m_FlagOverPage)
{
m_FlagOverPage = false;
}
else
{
if (m_ReportDoc != null)
{
m_strGetFldName = Request.QueryString["FieldName"];
if (m_strGetFldName != null)
{
GetFieldName(m_strGetFldName);
}
}
}
}
/// <summary>
/// 获得要排序的字段
/// </summary>
/// <param name="strFieldName"></param>
  private void GetFieldName(string strFieldName)
{
try
{
FieldDefinition FieldDef = null;
FieldDef = m_ReportDoc.Database.Tables[0].Fields[strFieldName];//把从“数据库”中取的该字段赋给 FieldDef

m_ReportDoc.DataDefinition.SortFields[0].Field = FieldDef;//然后再赋给要排序的字段名称

if (m_FlagOrder == false)
{
m_ReportDoc.DataDefinition.SortFields[0].SortDirection = CrystalDecisions.Shared.SortDirection.AscendingOrder;
m_FlagOrder = true;
}
else
{
m_ReportDoc.DataDefinition.SortFields[0].SortDirection = CrystalDecisions.Shared.SortDirection.DescendingOrder;
m_FlagOrder = false;
}
crystalReportViewer.ReportSource = m_ReportDoc;
crystalReportViewer.ShowLastPage(); //获取页数
      crystalReportViewer.ShowFirstPage();
}
catch (Exception ee)
{
Response.Write("<b><font color='#FF0000'>Operate Error!</font></b>");
}
}
/// <summary>
/// 绑定报表
/// </summary>
  private void ReportDoc_Bind()
{
string sql = "select ct.XK_TEXT as Location, pt.XK_RECEIPT_DATE_TIME as DateStart, " +
" pt.XK_RECEIPT_DATE_TIME as DateEnd, pt.XK_PLU as Dept,  pt.XK_RECEIPT_NUM as Receipt#, " +
" p.XK_TEXT as Item#,  pt.XK_QUANTITY as Quantity,  pt.XK_AMOUNT as Amount  " +
" from XK_CASH_TERMINAL ct left outer join XK_POS_TRANSACTION pt on ct.XK_ID = pt.XK_CASH_TERMINAL_ID " +
" left outer join XK_PRODUCT p on pt.XK_PROD_CODE = p.XK_CODE where 1=1 and pt.XK_STATUS IS NULL ";
SqlConnection conn = new SqlConnection(g_MyConnection);
System.Data.SqlClient.SqlDataAdapter MyCommand = new SqlDataAdapter(sql, conn);
DataSet ds = new DataSet();
MyCommand.Fill(ds);
ReportDocument m_ReportDoc = new ReportDocument();
m_ReportDoc.Load(Server.MapPath("Crystalrpt.rpt"));
m_ReportDoc.SetDataSource(ds.Tables[0]);
Session["Report"] = m_ReportDoc;
conn.Close();
}
protected void btnOk_Click(object sender, EventArgs e)
{
ReportDoc_Bind();
this.crystalReportViewer.ReportSource = m_ReportDoc;//显示报表

}
}

===================================================================

转载请注明出处:

http://blog.csdn.net/flydragon0815/archive/2008/12/21/3568052.aspx

上一页  1 2 

Tags:水晶 报表 单击

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接