Передать параметр в вложенный отчет из основного отчета crystal программно
Привет Эксперты,
Я много пытался вызвать параметры грамматически для моего суб-отчета, но потерпел неудачу, мне нужны ваши предложения в этом отношении.
Требования таковы, что я не хочу добавлять crystal-viewer, когда пользователь нажмет на кнопку report, который будет непосредственно загружен локально на его машине, пример кода, как показано ниже:
Что я уже пробовал:
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); }