开发者

How do I call the following? [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 11 years ago.
    public class MyReportRenderer
    {

        private rs2005.ReportingService2005 rs;
        private rs2005Execution.ReportExecutionService rsExec;
        //string casenumberKey;

        public void RenderTest()
        {
            string HistoryID = null;
            string deviceInfo = null;
            string encoding = String.Empty;
            string mimeType = String.Empty;
            string extension = String.Empty;
            rs2005Execution.Warning[] warnings = null;
            string[] streamIDs = null;

            rs = new rs2005.ReportingService2005();
            rsExec = new rs2005Exec开发者_运维问答ution.ReportExecutionService();
            rs.Credentials = System.Net.CredentialCache.DefaultCredentials;
            rsExec.Credentials = System.Net.CredentialCache.DefaultCredentials;
            rs.Url = "http://216.40.232.82/ReportServer_DEVELOPMENT/ReportService2005.asmx";
            rsExec.Url = "http://216.40.232.82/ReportServer_DEVELOPMENT/ReportExecution2005.asmx";


            //// pass parameters

            try
            {
                // Get if any parameters needed.



                // Load the selected report.

                rsExec.LoadReport("/LawDept/LawDeptTIC", HistoryID);

                // Prepare report parameter.

                // Set the parameters for the report needed.

                rs2005Execution.ParameterValue[] parameters = new rs2005Execution.ParameterValue[3];
                parameters[0] = new rs2005Execution.ParameterValue();
                parameters[0].Name = "CaseNumberKey";
                parameters[0].Value = "000002";
                //parameters[1] = new rs2005Execution.ParameterValue();
                //parameters[1].Name = "ReportMonth";
                //parameters[1].Value = "6"; // June
                //parameters[2] = new rs2005Execution.ParameterValue();
                //parameters[2].Name = "ReportYear";
                //parameters[2].Value = "2004";
                rsExec.SetExecutionParameters(parameters, "en-us");

                // get pdf of report 
                Byte[] results = rsExec.Render("PDF", deviceInfo,
                out extension, out encoding,
                out mimeType, out warnings, out streamIDs);

                MailMessage message = new MailMessage("george.greiner@gmail.com", "george.greiner@gmail.com", "Hello", "This is a test");
                SmtpClient emailClient = new SmtpClient("localhost");
                message.Attachments.Add(new Attachment(new MemoryStream(results), String.Format("{0}_DocumentSavingsReport.pdf", "ReportName")));
                emailClient.Send(message);
            }

            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);

            }
        }
    }

I would I call this when I need it to be executed??


(new MyReportRenderer()).RenderTest();


If you're asking how to invoke the method RenderTest on the class MyReportRenderer, you'd need to instantiate an instance of MyReportRenderer and then call that method from the instantiated object:

namespace ReportProgram
{
  class Program
  {
    static void Main(string [] args)
    {
      var rr = new MyReportRenderer();
      rr.RenderTest();
    }
  }
}


I call it "a class named MyReportRenderer". If you mean "invoking a method", I think you need

var renderer = new MyrReportRenderer();
renderer.RenderTest();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜