G
Guest
Hi
I am working on a C# Windows Application that builds an invoice (CR)
converts to PDF and attach to email one at a time.
This works untill my invoice count get over 40 to 50 invoices then I start
getting errors. The errors vairy. sometimes IO sometime "unable to load
report".
Has anyone here had a need to creat reports in mass?
Code:Example
// before the Form InitializeComponent
ReportDocument r = new ReportDocument();
//
// Get Invoice Emailing Data
DataSet ds = DataCalls.getInvoiceEmailList(val1, val2);
int rowcount = 0;
foreach (DataRow dr in dt.Rows)
{
BuildInvoiceReport(ds.Tables[0].Rows[rowcount][0].ToString(),
ds.Tables[0].Rows[rowcount][1].ToString()ds.Tables[0].Rows[rowcount][2].ToString()ds.Tables[0].Rows[rowcount][3].ToString());
EmailPDF();
}
//Get invoice data and build Report one at a time
private void BuildInvoiceReport(int CommodityID, int InvoiceNumber, string
OrderBy)
{
DataSet ds = DataCalls.getInvoiceDataSet(CommodityID, InvoiceNumber,
InvoiceNumber, OrderBy, 0);
r = null;
r = new Invoice();
r.SetDataSource(ds);
r.SetParameterValue(0, OrderBy);
r.SetParameterValue(1, comboBox.SelectedValue.ToString());
}
// email invoice
private void EmailPDF(int InvoiceNumber)
{
string ExportPath;
string emailFrom;
string subject;
string fName;
ExportPath = Application.StartupPath.ToString();
fName = ExportPath + "\\Invoice" + InvoiceNumber + ".pdf";
r.ExportToDisk(ExportFormatType.PortableDocFormat, fName);
emailFrom = "(e-mail address removed)";
subject = "Invoice#: " + InvoiceNumber + ".pdf";
emailTo = "(e-mail address removed)";
SmtpClient smtpclient = new SmtpClient();
MailMessage mailmsg = new MailMessage();
smtpclient.Host = ConfigurationManager.AppSettings["MailServer"];
MailAddress fromaddress = new MailAddress(emailFrom);
mailmsg.From = fromaddress;
mailmsg.To.Add(emailTo);
mailmsg.Subject = subject;
mailmsg.Body = body;
mailmsg.Attachments.Add(new Attachment(attachmentFilePath));
smtpclient.Send(mailmsg);
//Dispose attachment object so that file can get deleted
mailmsg.Attachments.Dispose();
File.Delete(attachmentFilePath);
}
Thanks for any help
Brian
I am working on a C# Windows Application that builds an invoice (CR)
converts to PDF and attach to email one at a time.
This works untill my invoice count get over 40 to 50 invoices then I start
getting errors. The errors vairy. sometimes IO sometime "unable to load
report".
Has anyone here had a need to creat reports in mass?
Code:Example
// before the Form InitializeComponent
ReportDocument r = new ReportDocument();
//
// Get Invoice Emailing Data
DataSet ds = DataCalls.getInvoiceEmailList(val1, val2);
int rowcount = 0;
foreach (DataRow dr in dt.Rows)
{
BuildInvoiceReport(ds.Tables[0].Rows[rowcount][0].ToString(),
ds.Tables[0].Rows[rowcount][1].ToString()ds.Tables[0].Rows[rowcount][2].ToString()ds.Tables[0].Rows[rowcount][3].ToString());
EmailPDF();
}
//Get invoice data and build Report one at a time
private void BuildInvoiceReport(int CommodityID, int InvoiceNumber, string
OrderBy)
{
DataSet ds = DataCalls.getInvoiceDataSet(CommodityID, InvoiceNumber,
InvoiceNumber, OrderBy, 0);
r = null;
r = new Invoice();
r.SetDataSource(ds);
r.SetParameterValue(0, OrderBy);
r.SetParameterValue(1, comboBox.SelectedValue.ToString());
}
// email invoice
private void EmailPDF(int InvoiceNumber)
{
string ExportPath;
string emailFrom;
string subject;
string fName;
ExportPath = Application.StartupPath.ToString();
fName = ExportPath + "\\Invoice" + InvoiceNumber + ".pdf";
r.ExportToDisk(ExportFormatType.PortableDocFormat, fName);
emailFrom = "(e-mail address removed)";
subject = "Invoice#: " + InvoiceNumber + ".pdf";
emailTo = "(e-mail address removed)";
SmtpClient smtpclient = new SmtpClient();
MailMessage mailmsg = new MailMessage();
smtpclient.Host = ConfigurationManager.AppSettings["MailServer"];
MailAddress fromaddress = new MailAddress(emailFrom);
mailmsg.From = fromaddress;
mailmsg.To.Add(emailTo);
mailmsg.Subject = subject;
mailmsg.Body = body;
mailmsg.Attachments.Add(new Attachment(attachmentFilePath));
smtpclient.Send(mailmsg);
//Dispose attachment object so that file can get deleted
mailmsg.Attachments.Dispose();
File.Delete(attachmentFilePath);
}
Thanks for any help
Brian