If I remove adding the attachment it works.
Any ideas on how to fix this?
- Code: Select all
private void ProcessSubscriptionInvoice(string invoice, DatabaseWorker dbWorker)
{
Debug.DoDebug();
var salesOrder = this._Manager.BusinessLogicFactory.CreateBusinessLogic<JiwaFinancials.Jiwa.JiwaSales.SalesOrder.SalesOrder >(null);
salesOrder.Read(invoice);
var lines = salesOrder.SalesOrderLines.Cast<JiwaFinancials.Jiwa.JiwaSales.SalesOrder.SalesOrderLine>().Where(l => l.CustomFieldValues.get_ItemFromSettingName("SubSales").Contents == "True" && l.CustomFieldValues.get_ItemFromSettingName("SubSent").Contents != "True" && l.QuantityThisDelivery > 0).ToList();
if(lines == null || lines.Count == 0)
{
return;
}
var message = CreateSubscriptionMessage(salesOrder, lines);
JiwaFinancials.Jiwa.JiwaApplication.JiwaEmail.EmailMessage email = this._Manager.BusinessLogicFactory.CreateBusinessLogic<JiwaFinancials.Jiwa.JiwaApplication.JiwaEmail.EmailMessage>(null);
email.CreateNew();
email.EmailFrom = this._Manager.Staff.EmailAddress;
email.BodyIsHTML = false;
email.EmailSubject = "Your RGS+ Subscription Purchase";
string emailAddress = salesOrder.CustomFieldValues.get_ItemFromSettingName("SubEmail").Contents;
if(emailAddress == null || emailAddress.Trim() == "" || !IsValidEmail(emailAddress))
{
return;
}
email.EmailTo = emailAddress;
email.EmailBody = message;
var docName = GenerateReport(salesOrder.SalesOrderHistorys[salesOrder.CurrentHistoryNo].RecID);
// Return the file
byte[] bytes = System.IO.File.ReadAllBytes(docName);
JiwaFinancials.Jiwa.JiwaApplication.Documents.Document doc = this._Manager.CollectionItemFactory.CreateCollectionItem<JiwaFinancials.Jiwa.JiwaApplication.Documents.Document>();
doc.PhysicalFileName = System.IO.Path.GetFileName(docName) ;
doc.FileBinary = bytes;
doc.Description = "Subscription Notice";
doc.DocumentType = email.Attachments.DocumentTypes.GetDefaultDocumentType();
email.Attachments.Add(doc);
email.Save();
SetOrdertoSubscriptionSent(salesOrder, email, doc);
salesOrder.Save();
}
- Code: Select all
public string GenerateReport(string historyID)
{
string parameterName = SettingsVault.ParameterName;
using (JiwaFinancials.Jiwa.JiwaApplication.Manager manager = this._Manager)
{
JiwaFinancials.Jiwa.JiwaApplication.Report.Configuration.ReportCollection m_Reports = manager.BusinessLogicFactory.CreateBusinessLogic<JiwaFinancials.Jiwa.JiwaApplication.Report.Configuration.ReportCollection>(null);
m_Reports.Read();
// find report with request.ReportID
JiwaFinancials.Jiwa.JiwaApplication.Report.Configuration.Report report = m_Reports[SettingsVault.ReportID];
if (report == null)
throw new JiwaFinancials.Jiwa.JiwaApplication.Exceptions.RecordNotFoundException("Report not found");
JiwaFinancials.Jiwa.JiwaApplication.JiwaPrintReport.JiwaPrintReport printReportObject = manager.BusinessLogicFactory.CreateBusinessLogic<JiwaFinancials.Jiwa.JiwaApplication.JiwaPrintReport.JiwaPrintReport>(null);
printReportObject.Setup();
printReportObject.LoadReport(report);
foreach (JiwaFinancials.Jiwa.JiwaApplication.JiwaPrintReport.JiwaReportRange jiwaReportRange in printReportObject.JiwaReportRangeCollection)
{
string formulaName = printReportObject.JiwaPrintFormulaCollection[jiwaReportRange.FormulaKey].Name.Replace("{", "").Replace("}", "").Replace("@", "").Trim().ToUpper();
string parameterCleaned = parameterName.Replace("{", "").Replace("}", "").Replace("@", "").Trim().ToUpper();
if (printReportObject.JiwaPrintFormulaCollection[jiwaReportRange.FormulaKey].Name.Replace("{", "").Replace("}", "").Replace("@", "").Trim().ToUpper() == parameterName.Replace("{", "").Replace("}", "").Replace("@", "").Trim().ToUpper())
{
jiwaReportRange.Value = historyID;
break;
}
}
printReportObject.UpdateReport();
// export report to PDF
string tempFolderPath = System.IO.Path.GetTempPath();
string fileName = report.Title;
// Make filename safe
foreach (char c in System.IO.Path.GetInvalidFileNameChars())
{
fileName = fileName.Replace(c.ToString(), "");
}
string fullFileName = System.IO.Path.Combine(tempFolderPath, fileName) + ".pdf";
if(System.IO.File.Exists(fullFileName))
{
System.IO.File.Delete(fullFileName);
}
printReportObject.CrystalReportObject.ExportToDisk(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat, fullFileName);
return fullFileName;
}
}


