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)
{
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();
}
}
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();
}
}
}
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";
if (ddlSupervisor.SelectedValue == "-1")
{
cmd.Parameters.AddWithValue("@strSupervisor", DBNull.Value);
}
else
{
cmd.Parameters.AddWithValue("@strSupervisor", Convert.ToString(ddlSupervisor.SelectedValue));
}
if (ddlRoute.SelectedValue == "-1")
{
cmd.Parameters.AddWithValue("@strgRoute", DBNull.Value);
}
else
{
cmd.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());
System.Data.SqlClient.SqlDataAdapter da = new System.Data.SqlClient.SqlDataAdapter(cmd);
DataTable dt = new DataTable("sp_RFSW0001");
try
{
da.Fill(dt);
}
catch (Exception)
{
}
rpdoc.Load(Server.MapPath("reports/RFSW0001.rpt"));
rpdoc.SetDatabaseLogon("sa", "ABC4RAK");
rpdoc.SetDataSource(dt);
}