Imports System.IO Imports System.Net.Mail Imports System.Reflection Imports System.Runtime.CompilerServices Imports System.Text Imports EgtBEAMWALL.Core Imports EgtUILib Imports MigraDoc.DocumentObjectModel Imports MigraDoc.Rendering Module Configuration ''' ''' tolgo eventuale indicazione solido rimasta da pezzo precedente ''' ''' Id pezzo ''' booleano visualizzazione solido Friend Sub DeselectSolid(Optional nPartId As Integer = 0, Optional bShowSolid As Boolean = False) If Map.refShowBeamPanelVM.ShowSolid_IsChecked Then ' tolgo eventuale indicazione solido rimasta da pezzo precedente Map.refShowBeamPanelVM.SetShowSolid(False) If bShowSolid Then Map.refProjectVM.BTLStructureVM.ShowSolid(nPartId, False, False) End If End Sub Public Sub CreatePrintPDF(ActivePage As Integer, bPreview As Boolean) LoadingWndHelper.OpenLoadingWnd(ActiveIds.CREATINGPDF, 1, "Creating PDF", "", 100) Try ' creo documento MigraDoc Dim document As Document = PDFHelper.CreateStatReport(ActivePage, bPreview) #If DEBUG Then Dim documentPath As String = Map.refMainWindowVM.MainWindowM.sTempDir & "\MigraDoc.mdddl" MigraDoc.DocumentObjectModel.IO.DdlWriter.WriteToFile(document, documentPath) #End If ' salvo il documento Dim sFileName As String = "" If ActivePage = Pages.VIEW AndAlso Not bPreview Then sFileName = ProjectManagerVM.CurrProd.sProdDirPath & "\" & "Statistics.pdf" ElseIf ActivePage = Pages.VIEW AndAlso bPreview Then sFileName = Map.refMainWindowVM.MainWindowM.sTempDir & "\Statistics.pdf" ' Se la pagina e' 0 e' bPreview e' True creo PDF Visualization ElseIf ActivePage = Pages.MACHINING AndAlso Not bPreview Then sFileName = ProjectManagerVM.CurrProd.sProdDirPath & "\" & ProjectManagerVM.CurrProd.sProdId & " - " & "Statistics.pdf" ElseIf ActivePage = Pages.MACHINING AndAlso bPreview Then ' Se la pagina e' 1 e' bPreview e' True creo PDF Optimizer sFileName = Map.refMainWindowVM.MainWindowM.sTempDir & "\Statistics.pdf" PrevSelect() End If Dim renderer As New PdfDocumentRenderer() With { .Document = document} renderer.RenderDocument() renderer.PdfDocument.Save(sFileName) If Not bPreview Then Process.Start(sFileName) Catch ex As Exception EgtOutLog("Error genereting pdf: " & ex.ToString()) Finally LoadingWndHelper.CloseLoadingWnd(ActiveIds.CREATINGPDF) End Try End Sub Private Sub PrevSelect() ' ripristino selezione precedente Dim nCurrMachGroupId As Integer = EgtGetCurrMachGroup() If Not IsNothing(Map.refProjectVM.MachGroupPanelVM.SelectedMachGroup) AndAlso nCurrMachGroupId <> Map.refProjectVM.MachGroupPanelVM.SelectedMachGroup.Id Then EgtSetCurrMachGroup(Map.refProjectVM.MachGroupPanelVM.SelectedMachGroup.Id) End If Core.ViewPanelVM.BWSetView(If(Core.ViewPanelVM.Type = BWType.BEAM, VT.ISO_SW, VT.TOP), False) EgtZoom(ZM.ALL, True) End Sub Public Sub SaveEml(message As MailMessage, filename As String) Dim boundary As String = "====BOUNDARY_" & Guid.NewGuid().ToString() & "====" Dim sb As New StringBuilder() ' Intestazioni principali sb.AppendLine("To: " & String.Join(";", message.To.Select(Function(t) t.Address))) If message.CC.Count > 0 Then sb.AppendLine("Cc: " & String.Join(";", message.CC.Select(Function(t) t.Address))) End If sb.AppendLine("Subject: " & message.Subject) sb.AppendLine("X-Unsent: 1") sb.AppendLine("MIME-Version: 1.0") sb.AppendLine("Content-Type: multipart/mixed; boundary=""" & boundary & """") sb.AppendLine() ' Corpo HTML sb.AppendLine("--" & boundary) sb.AppendLine("Content-Type: text/html; charset=utf-8") sb.AppendLine("Content-Transfer-Encoding: quoted-printable") sb.AppendLine() sb.AppendLine(message.Body) sb.AppendLine() ' Allegati For Each att As Attachment In message.Attachments Dim ms As New MemoryStream() att.ContentStream.Position = 0 att.ContentStream.CopyTo(ms) Dim bytes = ms.ToArray() Dim base64 = Convert.ToBase64String(bytes, Base64FormattingOptions.InsertLineBreaks) sb.AppendLine("--" & boundary) sb.AppendLine("Content-Type: " & att.ContentType.MediaType & "; name=""" & att.Name & """") sb.AppendLine("Content-Disposition: attachment; filename=""" & att.Name & """") sb.AppendLine("Content-Transfer-Encoding: base64") sb.AppendLine() sb.AppendLine(base64) sb.AppendLine() Next ' Fine MIME sb.AppendLine("--" & boundary & "--") ' Salvataggio file File.WriteAllText(filename, sb.ToString(), Encoding.UTF8) End Sub End Module