以编程方式从主晶体报告传递参数到子报告 [英] Pass parameter to subreport from main crystal report programatically

查看:70
本文介绍了以编程方式从主晶体报告传递参数到子报告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨专家,



我已经尝试了很多语法为我的子报告调用参数但是失败了,在这方面需要你的建议。



要求就像是我不想添加水晶查看器,当用户点击按钮报告将直接在他的机器上本地下载,示例代码如下:



我的尝试:



Hi Experts,

I have tried a lot to call parameters grammatically for my sub report but failed badly, Need your suggestions in this regards.

Requirements are like that i don't want to add crystal-viewer, When user will click on Button report will directly download locally on his machine, Sample code as below:

What I have tried:

public partial class RFSW0001 : System.Web.UI.Page
{
    public string query, constr;
    public SqlConnection con;

    SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["FoodRepConnectionString"].ConnectionString);
    ReportDocument rpdoc = new ReportDocument();

    ReportDocument sub_rpdoc = new ReportDocument();

    public void connection()
    {
        constr = ConfigurationManager.ConnectionStrings["FoodRepConnectionString"].ToString();
        con = new SqlConnection(constr);
        con.Open();
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        //--------------Start Bind Supervisor
        if (!IsPostBack)
        {
            ddlSupervisor.AppendDataBoundItems = true;
            connection();
            String strSupQuery = "SELECT DISTINCT Parent_Code FROM Users WHERE Parent_Code !='' ORDER BY Parent_Code ASC";
            SqlConnection con = new SqlConnection(constr);
            SqlCommand cmd = new SqlCommand();
            cmd.CommandType = CommandType.Text;
            cmd.CommandText = strSupQuery;
            cmd.Connection = con;

            try
            {
                con.Open();
                ddlSupervisor.DataSource = cmd.ExecuteReader();
                ddlSupervisor.DataTextField = "Parent_Code";
                ddlSupervisor.DataValueField = "Parent_Code";
                ddlSupervisor.DataBind();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                con.Close();
                con.Dispose();
            }
        }
        //--------------End Bind Supervisor
        //--------------Start Bind Route
        if (!IsPostBack)
        {
            ddlRoute.AppendDataBoundItems = true;
            connection();
            String strSupQuery = "SELECT DISTINCT User_Code ,(User_Code + ' - ' + User_Description) as UsersCode FROM Users WHERE User_Type = '0' and Is_Blocked = '0' ORDER BY User_Code ASC";
            SqlConnection con = new SqlConnection(constr);
            SqlCommand cmd = new SqlCommand();
            cmd.CommandType = CommandType.Text;
            cmd.CommandText = strSupQuery;
            cmd.Connection = con;

            try
            {
                con.Open();
                ddlRoute.DataSource = cmd.ExecuteReader();
                ddlRoute.DataTextField = "UsersCode";
                ddlRoute.DataValueField = "User_Code";
                ddlRoute.DataBind();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                con.Close();
                con.Dispose();
            }
        }
    }
        //--------------End Bind Route

        protected void btnRFSW0001Pdf_Click(object sender, EventArgs e)
        {

            conn.Open();

            RFSW0001Search();

            rpdoc.ExportToHttpResponse(ExportFormatType.PortableDocFormat, Response, true, "RFSW0001");

            conn.Close();

        }
        int dayOfWeek;
        public void RFSW0001Search()
        {
            System.Data.SqlClient.SqlCommand cmd1 = new System.Data.SqlClient.SqlCommand();
            cmd.CommandTimeout = 120;
            cmd.Connection = conn;
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.CommandText = "sp_RFSW0001";
			/*
            System.Data.SqlClient.SqlCommand cmd2 = new System.Data.SqlClient.SqlCommand();
            cmd2.CommandTimeout = 120;
            cmd2.Connection = conn;
            cmd2.CommandType = CommandType.StoredProcedure;
            cmd2.CommandText = "sp_RFSW0001_CTBV";
			*/

            if (ddlSupervisor.SelectedValue == "-1")
            {
                cmd.Parameters.AddWithValue("@strSupervisor", DBNull.Value);
                
				//These are the SubReport Parameters
				//cmd2.Parameters.AddWithValue("@strSupervisor", DBNull.Value);
            }
            else
            {
                cmd.Parameters.AddWithValue("@strSupervisor", Convert.ToString(ddlSupervisor.SelectedValue));
                
				//These are the SubReport Parameters
				//cmd2.Parameters.AddWithValue("@strSupervisor", Convert.ToString(ddlSupervisor.SelectedValue));
            }
            if (ddlRoute.SelectedValue == "-1")
            {
                cmd.Parameters.AddWithValue("@strgRoute", DBNull.Value);
                
				//These are the SubReport Parameters
				//cmd2.Parameters.AddWithValue("@strgRoute", DBNull.Value);
            }
            else
            {
                cmd.Parameters.AddWithValue("@strgRoute", Convert.ToString(ddlRoute.SelectedValue));
                
				//These are the SubReport Parameters
				//cmd2.Parameters.AddWithValue("@strgRoute", Convert.ToString(ddlRoute.SelectedValue));
            }

            DateTime tempDate = System.Convert.ToDateTime(txtDate.Value.ToString());
            DateTime startOfMonth = new DateTime(tempDate.Year, tempDate.Month, 1);
            DateTime endOfMonth = new DateTime(tempDate.Year, tempDate.Month, DateTime.DaysInMonth(tempDate.Year, tempDate.Month));

            cmd.Parameters.AddWithValue("@dtpFirstDate", startOfMonth);
            cmd.Parameters.AddWithValue("@dtpLastDate", endOfMonth);

            cmd.Parameters.AddWithValue("@dtpFrom", txtDate.Value.ToString());
            cmd.Parameters.AddWithValue("@dtpTo", txtDate.Value.ToString());
			
			/* These are the SubReport Parameters
            DateTime dateInput = Convert.ToDateTime(txtDate.Value);
            DayOfWeek today = dateInput.DayOfWeek;

            string weekDay = Convert.ToString(today);

            if (weekDay == "Saturday")
            {
                dayOfWeek = 1;
            }
            else if (weekDay == "Sunday")
            {
                dayOfWeek = 2;
            }
            else if (weekDay == "Monday")
            {
                dayOfWeek = 3;
            }
            else if (weekDay == "Tuesday")
            {
                dayOfWeek = 4;
            }
            else if (weekDay == "Wednesday")
            {
                dayOfWeek = 5;
            }
            else if (weekDay == "Thursday")
            {
                dayOfWeek = 6;
            }
            else
            {
                dayOfWeek = 7;
            }

            //datecount.Text = Convert.ToString(dayOfWeek);

            cmd2.Parameters.AddWithValue("@dayNumber", Convert.ToString(dayOfWeek));
            */

            System.Data.SqlClient.SqlDataAdapter da = new System.Data.SqlClient.SqlDataAdapter(cmd);

            DataTable dt = new DataTable("sp_RFSW0001");
            try
            {
                da.Fill(dt);
            }
            catch (Exception)
            {
                //Page.Response.Redirect("NetworkError.aspx");
            }

            rpdoc.Load(Server.MapPath("reports/RFSW0001.rpt"));
            
            rpdoc.SetDatabaseLogon("sa", "ABC4RAK");
			
            rpdoc.SetDataSource(dt);
        }

推荐答案

看到我不知道您的问题的确切解决方案,但当您尝试在水晶报表中显示某些内容时不要使用将数据传递给晶体报告而不是数据集或数据表的参数。你将内置公式来获得这个要求的关键。这个答案我有关于参数传递的问题。

和下载水晶报告直接你将有自动打印选项会有一个代码触发它
see i dont know exact solution for your question but when you are trying to display something in crystal reports so do not use parameters which passes its data to crystal report other than datasets or datatables .you will inbuilt formulas to gain this kine of requirement .this answer i have for your question regarding parameters passing.
and to download crystal report directly you will have print option automatically there will a code to trigger it


这篇关于以编程方式从主晶体报告传递参数到子报告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆