Как изменить текст текстового поля в отчетах RDLC на основе условия? - PullRequest
0 голосов
/ 06 февраля 2019

У меня есть RDLC Отчет.В этом отчете есть один TextBox с именем TextBox2, который отображает текст типа All Employees Record.Теперь я хочу изменить текст этого текстового поля на основе некоторого условия.Например, когда я нажимаю кнопку Hired Employees, текст TextBox2 должен измениться на «Запись наемного сотрудника» вместо All Employees Record, а когда я нажимаю кнопку Rejected Employees, текст TextBox2 должен измениться.в «Отклоненный отчет сотрудника».Вот условия для события загрузки страницы отчета, которую я отправляю

 protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (EmployeeID.PrintAllEmployees == "ALL EMPLOYEES")
            {
                PrintAllEmployeesMethod();
            }
            else if (EmployeeID.PrintAllEmployees == "HIRED EMPLOYEES")
            {
                PrintHiredEmployeesMethod();
            }
            else if (EmployeeID.PrintAllEmployees == "REJECTED EMPLOYEES")
            {
                PrintRejectedEmployeesMethod();
            }
            else if (EmployeeID.PrintAllEmployees == "UNVERIFIED EMPLOYEES")
            {
                PrintUnverifiedEmployeesMethod();
            }
            else
            {
                //SOMETHING
            }
        }
    }

Вот картинка enter image description here

Когда второе условие возвращает true, тогдатекст texbox изменился на Hired Employees Record и т. д. *

Мой второй вопрос заключается в том, что в отчете только на первой странице был текст заголовка, на остальных страницах текст заголовка отсутствует.Как этого добиться?Пожалуйста, помогите мне.

1 Ответ

0 голосов
/ 07 февраля 2019

Я задал вопрос здесь пару дней назад, но у меня нет ответа.Поэтому я продолжаю поиск и решил свою проблему.Поэтому я хочу дать ответ на это, надеясь, что если кто-то застрянет здесь, то кто-то получит помощь от моего ответа.Ведь мы должны помогать друг другу.Итак, шаг за шагом.

1) Я добавляю Parameter из Report Data панели инструментов, щелкнув правой кнопкой мыши, добавив параметр и назвав его paramHeader.enter image description here

enter image description here

enter image description here 2) Я добавляю Textbox в Report .rdlc Design и Drag and Drop paramHeader в Textbox.

3) Затем я добавляю следующий C# код в мой PrintReport метод.

ReportViewer1.LocalReport.ReportPath = Server.MapPath("~/Reports/rptAllEmployeeRecord.rdlc");
        //Passing Parameter
        ReportParameterCollection reportParameters = new ReportParameterCollection();
        reportParameters.Add(new ReportParameter("paramHeader", "HIRED EMPLOYEES REPORT"));
        this.ReportViewer1.LocalReport.SetParameters(reportParameters);

Здесь ParamHeader - это имя параметра, которое я добавил на первом шаге, а HIRED EMPLOYEES REPORT - это строковое значение, которое я хочу показать в TextBox, который я добавил на втором шаге.

Так что мой общий метод будет

public void PrintHiredEmployeesMethod()
    {

        //set Processing Mode of Report as Local  
        ReportViewer1.ProcessingMode = ProcessingMode.Local;
        //set path of the Local report  
        ReportViewer1.LocalReport.ReportPath = Server.MapPath("~/Reports/rptAllEmployeeRecord.rdlc");
        //Passing Parameter
        ReportParameterCollection reportParameters = new ReportParameterCollection();
        reportParameters.Add(new ReportParameter("paramHeader", "HIRED EMPLOYEES REPORT"));
        this.ReportViewer1.LocalReport.SetParameters(reportParameters);
        //creating object of DataSet dsEmployee and filling the DataSet using SQLDataAdapter  
        DataSetAllEmployee dsemp = new DataSetAllEmployee();
        using (SqlConnection con = new SqlConnection(Base.GetConnection))
        {
            SqlCommand cmd = new SqlCommand(@"SELECT * FROM TableEmployee WHERE Status=@Status", con);
            cmd.CommandType = System.Data.CommandType.Text;
            cmd.Parameters.AddWithValue("@Status","HIRED");
            con.Open();
            SqlDataAdapter adapt = new SqlDataAdapter(cmd);
            adapt.Fill(dsemp, "dtAllEmployeeRecord");
        }
        //Providing DataSource for the Report  
        ReportDataSource rds = new ReportDataSource("DataSetAllEmployee", dsemp.Tables[0]);
        ReportViewer1.LocalReport.DataSources.Clear();
        //Add ReportDataSource  
        ReportViewer1.LocalReport.DataSources.Add(rds);
    }

и мое Page_Load событие будет выглядеть так

 protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (EmployeeID.PrintAllEmployees == "ALL EMPLOYEES")
            {
                PrintAllEmployeesMethod();
            }
            else if (EmployeeID.PrintAllEmployees == "HIRED EMPLOYEES")
            {
                PrintHiredEmployeesMethod();
            }
            else if (EmployeeID.PrintAllEmployees == "REJECTED EMPLOYEES")
            {
                PrintRejectedEmployeesMethod();
            }
            else if (EmployeeID.PrintAllEmployees == "UNVERIFIED EMPLOYEES")
            {
                PrintUnverifiedEmployeesMethod();
            }
            else
            {
                //SOMETHING
            }
        }
    }

ПРИМЕЧАНИЕ , что у меня есть четыре разных метода, но я меняюHeader Раздел в соответствии с моими потребностями.Например, когда пользователь хочет напечатать HIRED EMPLOYEES REPORT, затем Header Section показать HIRED EMPLOYEES REPORT, если пользователь хочет сгенерировать ALL EMPLOYEES REPORT, тогда Header Section должен показать ALL EMPLOYEES REPORT и т. Д.

...