Beispiel #1
0
        public ReportParams(ReportParam[] pArray)
        {
            _reportParam = new ReportParam[pArray.Length];

            for (int i = 0; i < pArray.Length; i++)
            {
                _reportParam[i] = pArray[i];
            }
        }
        protected void Button1_Click(object sender, EventArgs e)
        {
            //ReportParam[] reportParamsArray = new ReportParam[2]
            //{
            //  new ReportParam("divisionid",DropDownList1.SelectedValue),
            //  new ReportParam("employeeid",DropDownList2.SelectedValue),
            //};
            //Report rpt = new Report();

            //if (rpt.ShowReport(ReportViewer1, "DataSet1", "sp_getAssetsByEmployee", "Reports/Report Files/UserAssetsDivision.rdl", reportParamsArray))
            //{
            //    Label1.Visible = false;
            //}
            //else
            //{
            //    Label1.Text = "There were no records found for the search criteria you provided...";
            //    Label1.Visible = true;
            //}
            ReportParam[] reportParamsArray = new ReportParam[2]
            {
                new ReportParam("divisionid", DropDownList1.SelectedValue),
                new ReportParam("employeeid", DropDownList2.SelectedValue),
            };
            Report       rpt       = new Report();
            ReportViewer rptViewer = ReportViewer1;

            Connections.Connections conn = new Connections.Connections();
            string commandText           = "sp_getAssetsByEmployee";
            bool   r = rpt.ShowReport(rptViewer, "DataSet1", "Reports/Report Files/UserAssetsDivision.rdl", commandText, 2, conn.MainConnection(), reportParamsArray);

            if (r)
            {
                rptViewer.Visible             = true;
                rptViewer.SizeToReportContent = true;
                rptViewer.ZoomMode            = ZoomMode.FullPage;
            }
            else
            {
                rptViewer.Visible = false;
                Response.Write("No records were found.");
            }
        }
        protected void Button1_Click(object sender, EventArgs e)
        {
            //ReportParam[] reportParamsArray = new ReportParam[2]
            //{
            //  new ReportParam("divisionid",DropDownList1.SelectedValue),
            //  new ReportParam("employeeid",DropDownList2.SelectedValue),
            //};
            //Report rpt = new Report();

            //if (rpt.ShowReport(ReportViewer1, "DataSet1", "sp_getAssetsByEmployee", "Reports/Report Files/UserAssetsDivision.rdl", reportParamsArray))
            //{
            //    Label1.Visible = false;
            //}
            //else
            //{
            //    Label1.Text = "There were no records found for the search criteria you provided...";
            //    Label1.Visible = true;
            //}
            ReportParam[] reportParamsArray = new ReportParam[2]
            {
              new ReportParam("divisionid",DropDownList1.SelectedValue),
              new ReportParam("employeeid",DropDownList2.SelectedValue),
            };
            Report rpt = new Report();
            ReportViewer rptViewer = ReportViewer1;
            Connections.Connections conn = new Connections.Connections();
            string commandText = "sp_getAssetsByEmployee";
            bool r = rpt.ShowReport(rptViewer, "DataSet1", "Reports/Report Files/UserAssetsDivision.rdl", commandText, 2, conn.MainConnection(),reportParamsArray);

            if (r)
            {
                rptViewer.Visible = true;
                rptViewer.SizeToReportContent = true;
                rptViewer.ZoomMode = ZoomMode.FullPage;
            }
            else
            {
                rptViewer.Visible = false;
                Response.Write("No records were found.");
            }
        }
Beispiel #4
0
        //public bool ShowReport(ReportViewer rptViewer,
        //                        string dsName,
        //                        string strStoredProcedure,
        //                        string strReportPath,
        //                        ReportParam[] reportParamsArray)
        //{

        //    rptViewer.Visible = true;
        //    rptViewer.SizeToReportContent = true;
        //    rptViewer.ZoomMode = ZoomMode.PageWidth;

        //    SqlCommand cmd = new SqlCommand();
        //    SqlDataAdapter sqla = new SqlDataAdapter();
        //    DataTable dt = new DataTable();
        //    ReportDataSource rds = new ReportDataSource();
        //    List<ReportParameter> rptParams = new List<ReportParameter>();

        //    SqlConnection myConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["SAAssetManagement.Models.AssetContextConnectionString"].ConnectionString);
           
        //    cmd.Connection = myConnection;
        //    cmd.CommandText = strStoredProcedure;
        //    cmd.CommandType = CommandType.StoredProcedure;
            
        //    foreach (var p in reportParamsArray)
        //    {
        //        if (p.ParamValue.ToString() == "")
        //        {
        //            cmd.Parameters.AddWithValue(p.ParamName, System.DBNull.Value);
        //        }
        //        else
        //        {
        //            cmd.Parameters.AddWithValue(p.ParamName, p.ParamValue);
        //        }
        //    }

        //    sqla.SelectCommand = cmd;
        //    sqla.Fill(dt);
            
        //    rptViewer.LocalReport.ReportPath = strReportPath;
        //    rptViewer.LocalReport.DataSources.Clear();
        //    rds.Name = dsName;
        //    rds.Value = dt;
        //    rptViewer.LocalReport.DataSources.Add(rds);

        //    foreach (var p in reportParamsArray)
        //    {
        //        if (p.ParamValue.ToString() == "")
        //        {
        //            rptParams.Add(new ReportParameter(p.ParamName));
        //        }
        //        else
        //        {
        //            rptParams.Add(new ReportParameter(p.ParamName, p.ParamValue.ToString()));
        //        }
        //    }

        //    rptViewer.LocalReport.SetParameters(rptParams);

        //    if (dt.Rows.Count == 0)
        //    {
        //        rptViewer.Visible = false;
        //        return false;
        //    }
        //    else
        //    {
        //        rptViewer.LocalReport.Refresh();
        //        return true;
        //    }

        //}
        public bool ShowReport(ReportViewer rptViewer,
                                string dsName,
                                string strReportPath,
                                string commandText,
                                int commandType,
                                SqlConnection conn,
                                ReportParam[] reportParamsArray = null)
        {

            SqlCommand cmd = new SqlCommand();
            SqlDataAdapter sqlAdapter = new SqlDataAdapter();
            DataTable dtTable = new DataTable();
            ReportDataSource rds = new ReportDataSource();
            List<ReportParameter> rptParams = new List<ReportParameter>();

            cmd.Connection = conn;
            cmd.CommandText = commandText;
            cmd.CommandType = commandType == 1 ? CommandType.Text : CommandType.StoredProcedure;

            if (reportParamsArray != null)
            {
                foreach (var p in reportParamsArray)
                {
                    if (p.ParamValue.ToString() == "")
                    {
                        cmd.Parameters.AddWithValue(p.ParamName, System.DBNull.Value);
                    }
                    else
                    {
                        cmd.Parameters.AddWithValue(p.ParamName, p.ParamValue);
                    }
                }
            }

            sqlAdapter.SelectCommand = cmd;
            sqlAdapter.Fill(dtTable);

            rptViewer.LocalReport.ReportPath = strReportPath;
            rptViewer.LocalReport.DataSources.Clear();

            rds.Name = dsName;
            rds.Value = dtTable;
            rptViewer.LocalReport.DataSources.Add(rds);

            if (reportParamsArray != null)
            {
                foreach (var p in reportParamsArray)
                {
                    if (p.ParamValue.ToString() == "")
                    {
                        rptParams.Add(new ReportParameter(p.ParamName));
                    }
                    else
                    {
                        rptParams.Add(new ReportParameter(p.ParamName, p.ParamValue.ToString()));
                    }
                }
            }

            rptViewer.LocalReport.SetParameters(rptParams);

            if (dtTable.Rows.Count == 0)
            {
                rptViewer.Visible = false;
                return false;
            }
            else
            {
                rptViewer.LocalReport.Refresh();
                return true;
            }

        }
Beispiel #5
0
 public ReportParamsEnum(ReportParam[] list)
 {
     _reportParams = list;
 }