我正在尝试将水晶报告转换为pdf,因为我需要将其邮寄。所以我看了几步,但无济于事。 我试过了:
RPTBanQoute printbanqoute = new RPTBanQoute();
printbanqoute.SetDataSource(ds);
printbanqoute.ExportToDisk(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat, @"E:\ASD.pdf");
这没有任何反应。
然后我尝试了:
try
{
// Export the Report to Response stream in PDF format and file name Customers
//printbanqoute.ExportToHttpResponse(ExportFormatType.PortableDocFormat, Response, true, "Customers");
printbanqoute.ExportToHttpResponse(ExportFormatType.PortableDocFormat, Response, true, "Quotation");
// There are other format options available such as Word, Excel, CVS, and HTML in the ExportFormatType Enum given by crystal reports
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
ex = null;
}
Response
上的The name 'Response' does not exist in the current context
我尝试使用Server.Mappath,但intellisense没有显示Mappath。我用过System.Web
以下是我如何在Crystal rert上填充数据:
MySqlCommand cmd = new MySqlCommand("SELECT tb.BookingID, BookingDate, Event, EventDate, EventTime, Pax, Service, ServiceTime, f.FoodMenu, f.ExtraItem FROM tblBookingDetails tb, tblMenu f WHERE tb.BookingID = @bookid AND tb.BookingID = f.BookingID", con.con);
cmd.Parameters.AddWithValue("@bookid", BLDashboard.bookingID);
MySqlDataAdapter adapter = new MySqlDataAdapter(cmd);
DataSet1 ds = new DataSet1();
adapter.Fill(ds, "BookingDetails");
if (ds.Tables["BookingDetails"].Rows.Count == 0)
{
MessageBox.Show("No Data Found", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
}
RPTBanQoute printbanqoute = new RPTBanQoute();
printbanqoute.SetDataSource(ds);
我也将参数值传递给此Crystal报表。
所以请建议如何转换为PDF和电子邮件
我也进一步搜索了这些代码:
cryRpt = new ReportDocument();
cryRpt.Load("E:\\Office\\Clients\\Bombay Restaurant\\Banquet New - MySql\\Banquet New\\RPTBanQoute.rpt");
crystalReportViewer1.ReportSource = cryRpt;
crystalReportViewer1.Refresh();
try
{
ExportOptions CrExportOptions;
DiskFileDestinationOptions CrDiskFileDestinationOptions = new DiskFileDestinationOptions();
PdfRtfWordFormatOptions CrFormatTypeOptions = new PdfRtfWordFormatOptions();
CrDiskFileDestinationOptions.DiskFileName = "c:\\csharp.net-informations.pdf";
CrExportOptions = cryRpt.ExportOptions;
{
CrExportOptions.ExportDestinationType = ExportDestinationType.DiskFile;
CrExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat;
CrExportOptions.DestinationOptions = CrDiskFileDestinationOptions;
CrExportOptions.FormatOptions = CrFormatTypeOptions;
}
cryRpt.Export();
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
答案 0 :(得分:0)
我能够解决我的问题。我在crystalviewer1_Load
事件中写了所有代码,即;导出和发送电子邮件以及将数据填充到水晶报告中。所以我必须创建一个按钮电子邮件来导出和发送电子邮件。
继承我导出和发送电子邮件的代码,Button1是crystalviewer上的电子邮件按钮:
private void button1_Click(object sender, EventArgs e)
{
try
{
billprint.ExportToDisk(ExportFormatType.PortableDocFormat, "E:\\" + filename);
}
catch(Exception ex)
{
MessageBox.Show(ex.ToString());
}
try
{
MailMessage mm = new MailMessage();
string toemail = BLDashboard.email;
string custnm = BLDashboard.custname;
mm.From = new MailAddress("operations@kaem.in", "Kashif Ahhmed");
mm.To.Add(new MailAddress(toemail, custnm));
mm.IsBodyHtml = true;
string name = BLDashboard.custname;
mm.Subject = "Bill from Indian Restaurant";
//mm.Body = "Testing Crsytel Report Attachment send via Email";
String Body = "<div>Hello " + name + ",<br> Thank you for considersing us for your next Party/Event, here is the Bill for the Party/Event.<br> If any queries you can reach us at 6096464445. <br> Thank You</div>";
mm.Body = Body;
//mm.Attachments.Add(new Attachment(rpt.ExportToStream(ExportFormatType.PortableDocFormat), fileName));
mm.Attachments.Add(new Attachment("E:\\" + filename));
SmtpClient sc = new SmtpClient("smtp.kaem.in");
sc.Credentials = new NetworkCredential("emailadd", "*********");
sc.Send(mm);
// MailMessage msg = mm.CreateMailMessage("mr.markwhite1@gmail.com", replacements, Body, new System.Web.UI.Control());
MessageBox.Show("Email successfully sent to " + toemail);
}
catch (Exception e1)
{
MessageBox.Show("Unable to send email to mr.markwhite1@gmail.com due to following error:\n\n" + e1.Message, "Email send error", MessageBoxButtons.OK, MessageBoxIcon.Error);
//{
// this.SendEmail(emailId, subject, body, rpt, fileName);
//}
}
}