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 rs2005Execution.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);
}
}
}
当我需要执行时,我会调用它吗?
答案 0 :(得分:7)
(new MyReportRenderer()).RenderTest();
答案 1 :(得分:1)
如果您询问如何在类RenderTest
上调用方法MyReportRenderer
,则需要实例化MyReportRenderer
的实例,然后从实例化对象中调用该方法:
namespace ReportProgram
{
class Program
{
static void Main(string [] args)
{
var rr = new MyReportRenderer();
rr.RenderTest();
}
}
}
答案 2 :(得分:0)
我将其称为“名为MyReportRenderer的类”。如果你的意思是“调用方法”,我认为你需要
var renderer = new MyrReportRenderer();
renderer.RenderTest();