Connection was broken or closed
Hi There
Am getting the attached error and then Jiwa crashes while I'm trying to send an email via the plugin. The error doesnt come up straight away but it takes sometime trying to send the email and then errors and crashes if I say OK. The code chunk is as below
Am getting the attached error and then Jiwa crashes while I'm trying to send an email via the plugin. The error doesnt come up straight away but it takes sometime trying to send the email and then errors and crashes if I say OK. The code chunk is as below
- Code: Select all
Private Sub EmailInvoice(ByRef SalesOrderForm As JiwaSalesUI.SalesOrder.SalesOrderEntryForm, candidateReportsToEmail As JiwaApplication.JiwaCollection(Of JiwaApplication.PrintGroup.SalesOrderReports.SalesOrderReport), Optional ByVal ExportFormatType As CrystalDecisions.Shared.ExportFormatType = CrystalDecisions.Shared.ExportFormatType.PortableDocFormat)
Try
' SalesOrderForm.Save()
If salesOrderForm.GetAbstractPermission("sales order - email invoices") <> JiwaApplication.Security.UserGroup.AccessLevels.Allow Then
Throw New System.Exception("You do not have sufficient priveleges to email an invoice.")
End If
If salesOrderForm.SalesOrder.SalesOrderReports.Count = 0 Then
If Microsoft.VisualBasic.Interaction.MsgBox("No sales order reports have been defined." & System.Environment.NewLine & System.Environment.NewLine & "Would you like to set some up now ?", Microsoft.VisualBasic.MsgBoxStyle.YesNo , "No Sales Order Reports Configured") = Microsoft.VisualBasic.MsgBoxResult.Yes Then
salesOrderForm.PrinterSetup()
Else
Throw New JiwaApplication.Exceptions.ClientCancelledException
End If
End If
If candidateReportsToEmail.Count = 0 Then
Throw New System.Exception("There are no reports that are applicable to this particular invoice. Are there lines to deliver?")
End If
' load print selection dialog
Dim emailReportDialog As JiwaSalesUI.SalesOrder.EmailReport = JiwaApplication.Manager.Instance.DialogFactory.CreateDialog(Of JiwaSalesUI.SalesOrder.EmailReport)(New Object() {candidateReportsToEmail}, SalesOrderForm, "Sales Order Entry")
emailReportDialog.Visible = False
emailReportDialog.NameToGiveAttachment = "Your invoice-" & salesOrderForm.SalesOrder.InvoiceNo '<- You may want to change this attachment name
emailReportDialog.EmailTo = GetEmailAddress(salesOrderForm.SalesOrder.Debtor.RecID, "Email Invoice")
emailReportDialog.CC = GetEmailAddress(salesOrderForm.SalesOrder.Debtor.RecID, "CC Email Invoice")
' emailReportDialog.BCC = "[email protected]"
emailReportDialog.From = Microsoft.VisualBasic.Strings.Chr(34) & Microsoft.VisualBasic.Strings.Replace(JiwaApplication.Manager.Instance.Staff.EmailDisplayName, "@", " ") & Microsoft.VisualBasic.Strings.Chr(34) & " <" & JiwaApplication.Manager.Instance.Staff.EmailAddress & ">"
emailReportDialog.Subject = "Your invoice - " & salesOrderForm.SalesOrder.OrderNo '<- You may want to change the Subject text
emailReportDialog.SelectedReport = candidateReportsToEmail(1) '<--- This selects which report to email from the list of CandidateReports passed into the Sub.
emailReportDialog.Message = "Dear customer," & System.Environment.NewLine _
& "Please find your invoice attached." & System.Environment.NewLine _
& System.Environment.NewLine _
& "Sent on Processing Sales Order, " & System.Environment.NewLine _
& "The Sales Team"
If emailReportDialog.ShowDialog(salesOrderForm) = System.Windows.Forms.DialogResult.OK Then
' salesOrderForm.SalesOrder.Email(emailReportDialog.SelectedReport, emailReportDialog.NameToGiveAttachment, emailReportDialog.From, emailReportDialog.EmailTo, emailReportDialog.RequestReadReceipt, emailReportDialog.Subject, emailReportDialog.CC, emailReportDialog.BCC, emailReportDialog.Message, ExportFormatType)
End If
Catch ex As System.Exception
MessageBox.Show(ex.Message+ex.StackTrace)
End Try
End Sub