-sistemato codice pdfeditor

This commit is contained in:
Demetrio Cassarino
2024-06-19 17:29:16 +02:00
parent 330a4d6238
commit 49ed63e2d4
4 changed files with 25 additions and 67 deletions
@@ -2,8 +2,6 @@
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:EgtWPFLib5="clr-namespace:EgtWPFLib5;assembly=EgtWPFLib5"
xmlns:EgtBEAMWALL="clr-namespace:EgtBEAMWALL.ViewerOptimizer"
xmlns:EgtBEAMWALLCORE="clr-namespace:EgtBEAMWALL.Core;assembly=EgtBEAMWALL.Core"
Style="{DynamicResource {x:Type EgtWPFLib5:EgtCustomWindow}}"
WindowStyle="None" ResizeMode="NoResize"
SizeToContent="WidthAndHeight"
@@ -131,7 +131,6 @@
Grid.Column="1"
Grid.RowSpan="2"
Style="{StaticResource GroupBox_PDFPreview}">
<!--<WebBrowser EgtBEAMWALL:WebBrowserUtility.BindableSource="{Binding WebAddress}"/>-->
<EgtBEAMWALL:PdfViewer PdfPath="{Binding WebAddress, Mode=TwoWay}" Visibility="{Binding PdfViewer_Visibility}"/>
</GroupBox>
</Grid>
@@ -25,26 +25,26 @@ Public Class PDFEditorVM
' PDF visualizzato come preview nella sezione PDF Editor
Private m_WebAddress As String
Public Property WebAddress As String
Public ReadOnly Property WebAddress As String
Get
Return m_WebAddress
End Get
Set(value As String)
m_WebAddress = value
NotifyPropertyChanged(NameOf(WebAddress))
End Set
End Property
Friend Sub SetWebAddress(value As String)
m_WebAddress = value
NotifyPropertyChanged(NameOf(WebAddress))
End Sub
Private m_PdfViewer_Visibility As Visibility
Public Property PdfViewer_Visibility As Visibility
Public ReadOnly Property PdfViewer_Visibility As Visibility
Get
Return m_PdfViewer_Visibility
End Get
Set(value As Visibility)
m_PdfViewer_Visibility = value
NotifyPropertyChanged(NameOf(PdfViewer_Visibility))
End Set
End Property
Friend Sub SetPdfViewer_Visibility(value As Visibility)
m_PdfViewer_Visibility = value
NotifyPropertyChanged(NameOf(PdfViewer_Visibility))
End Sub
' Definizione comandi
Private m_cmdCreatePDFPreviewVis As ICommand
@@ -62,8 +62,8 @@ Public Class PDFEditorVM
m_ExpanderList.Add(New ExpanderPDF(ListTypes.RAWPART)) ' RawPart List
m_ExpanderList.Add(New ExpanderPDF(ListTypes.PART_TOT)) ' Part Totals
m_ExpanderList.Add(New ExpanderPDF(ListTypes.PART)) ' Part List
m_WebAddress = "" ' Pagina vuota
m_PdfViewer_Visibility = Visibility.Hidden
SetWebAddress("") ' Pagina vuota
SetPdfViewer_Visibility(Visibility.Hidden)
Map.SetRefPDFEditorVM(Me)
End Sub
@@ -86,11 +86,9 @@ Public Class PDFEditorVM
''' Funzione per la visualizzazione della preview del PDF della sezione visualizzatore
''' </summary>
Public Sub CreatePreviewVis()
m_PdfViewer_Visibility = Visibility.Visible
SetPdfViewer_Visibility(Visibility.Visible)
Configuration.CreatePrintPDF(PDFPage.VIEW, True)
WebAddress = Map.refMainWindowVM.MainWindowM.sTempDir & "\Statistics.pdf"
NotifyPropertyChanged(NameOf(WebAddress))
NotifyPropertyChanged(NameOf(PdfViewer_Visibility))
SetWebAddress(Map.refMainWindowVM.MainWindowM.sTempDir & "\Statistics.pdf")
End Sub
#End Region ' CreatePreviewVis
@@ -110,11 +108,9 @@ Public Class PDFEditorVM
''' Funzione per la visualizzazione della preview del PDF della sezione ottimizzatore
''' </summary>
Public Sub CreatePreviewOtt()
m_PdfViewer_Visibility = Visibility.Visible
SetPdfViewer_Visibility(Visibility.Visible)
Configuration.CreatePrintPDF(PDFPage.MACHING, True)
WebAddress = Map.refMainWindowVM.MainWindowM.sTempDir & "\Statistics.pdf"
NotifyPropertyChanged(NameOf(WebAddress))
NotifyPropertyChanged(NameOf(PdfViewer_Visibility))
SetWebAddress(Map.refMainWindowVM.MainWindowM.sTempDir & "\Statistics.pdf")
End Sub
#End Region ' CreatePreviewOt
@@ -136,15 +132,12 @@ Public Class PDFEditorVM
Public Sub ClosePreview()
Try
File.Delete(Map.refMainWindowVM.MainWindowM.sTempDir & "\Statistics.pdf")
'File.Delete(Map.refMainWindowVM.MainWindowM.sTempDir & "\Statistics - Optimizer.pdf")
Catch ex As Exception
EgtOutLog("Errore! Cancellazione dei file pdf fallita")
End Try
m_PdfViewer_Visibility = Visibility.Hidden
WebAddress = ""
NotifyPropertyChanged(NameOf(WebAddress))
NotifyPropertyChanged(NameOf(PdfViewer_Visibility))
SetPdfViewer_Visibility(Visibility.Hidden)
SetWebAddress("")
End Sub
#End Region ' CreatePreviewVis
@@ -7,7 +7,6 @@ Imports EgtUILib
Imports System.Collections.ObjectModel
Imports PdfSharp.Drawing
Imports MigraDoc.DocumentObjectModel.Shapes
Imports System.Windows.Forms.VisualStyles.VisualStyleElement.Header
Imports System.IO
Module PDFHelper
@@ -27,8 +26,8 @@ Module PDFHelper
Public Function CreateStatReport(ActivePage As Pages, bPreview As Boolean) As Document
' creo nuovo documento MigraDoc
Dim document As Document = New Document()
Dim Project As ProjectFileVM = ProjectManagerVM.CurrProd
Dim document As New Document()
Dim Project As ProjectFileVM
If ActivePage = Pages.VIEW OrElse (ActivePage = Pages.ONLYPRODPAGE AndAlso Map.refInstrumentPanelVM.bVisOtt_Selected = False) Then
Project = ProjectManagerVM.CurrProj
@@ -146,7 +145,7 @@ Module PDFHelper
End Sub
Private Sub DefineItem(document As Document, nListType As ListTypes, bPreview As Boolean, sMachGroupList As ExpanderTable, sName As EgtDataGridColumn, sW As EgtDataGridColumn, sH As EgtDataGridColumn, sL As EgtDataGridColumn, sMaterial As EgtDataGridColumn, sUsage As EgtDataGridColumn, sWaste As EgtDataGridColumn, sUTime As EgtDataGridColumn, sQty As EgtDataGridColumn, sPDN As EgtDataGridColumn, sDesc As EgtDataGridColumn, sCNT As EgtDataGridColumn, sAdded As EgtDataGridColumn, sDone As EgtDataGridColumn, sUVolume As EgtDataGridColumn, sTVolume As EgtDataGridColumn, sTTime As EgtDataGridColumn, sINProd As EgtDataGridColumn, section As Section)
Dim countItemList As Integer = 0
Dim countItemList As Integer
Select Case nListType
Case ListTypes.PART
section.AddParagraph(EgtMsg(61733), "Heading2")
@@ -155,7 +154,7 @@ Module PDFHelper
Case ListTypes.RAWPART
section.AddParagraph(EgtMsg(61732), "Heading2")
End Select
Dim table As Table = New Table()
Dim table As New Table()
table.Borders.Width = 0.75
' ciclo sulle colonne per creare la tabella e riempirne i campi
' -2 -> creo colonne
@@ -538,13 +537,13 @@ Module PDFHelper
End Sub
Private Sub CreateRawPartPage(document As Document, sMachGroupList As ExpanderTable, sPDN As EgtDataGridColumn, sW As EgtDataGridColumn, sH As EgtDataGridColumn, sL As EgtDataGridColumn, sDesc As EgtDataGridColumn, sMaterial As EgtDataGridColumn, RawPart As MyMachGroupVM, bPreview As Boolean)
Dim countPartVMList As Integer = 0
Dim section As Section = document.AddSection()
' cambio orientamento a verticale
Dim pgSetup As PageSetup = document.DefaultPageSetup.Clone()
pgSetup.Orientation = Orientation.Landscape
section.PageSetup = pgSetup
Dim PartVMList As IEnumerable(Of Object)
Dim countPartVMList As Integer
If IsNothing(RawPart) Then
PartVMList = New List(Of Object)
CreateRawPartImage(section, sMachGroupList, 44143, 1, bPreview)
@@ -574,8 +573,7 @@ Module PDFHelper
' recupero elemento della riga
PartVM = PartVMList(PartIndex)
End If
Dim Columnlist As ObservableCollection(Of EgtDataGridColumn) = Nothing
Columnlist = sMachGroupList.RawPartColumns
Dim Columnlist As ObservableCollection(Of EgtDataGridColumn) = sMachGroupList.RawPartColumns
For ColumnIndex = 0 To Columnlist.Count - 1
Select Case Columnlist(ColumnIndex).Name
Case COL_PDN
@@ -667,7 +665,7 @@ Module PDFHelper
Private Sub CreateRawPartImage(section As Section, sMachGroupList As ExpanderTable, RawPartId As Integer, RawPartName As String, bPreview As Boolean)
' creo immagine
Dim sImagePath As String = String.Empty
Dim sImagePath As String
If File.Exists(Map.refMainWindowVM.MainWindowM.sTempDir & "\Image" & RawPartId & ".png") Then
sImagePath = Map.refMainWindowVM.MainWindowM.sTempDir & "\Image" & RawPartId & ".png"
Else
@@ -703,11 +701,6 @@ Module PDFHelper
Image.RelativeHorizontal = RelativeHorizontal.Margin
End Sub
Private Sub DrawImage(gfx As XGraphics, sImagePath As String)
Dim image As XImage = XImage.FromFile(sImagePath)
Dim x As Double = (250 - image.PixelWidth * 72 / image.HorizontalResolution) / 2
gfx.DrawImage(image, x, 0)
End Sub
''' <summary>
''' Defines the styles used in the document.
''' </summary>
@@ -810,31 +803,6 @@ Module PDFHelper
hyperlink.AddPageRefField("Charts")
End Sub
''' <summary>
''' Defines page setup, headers, and footers.
''' </summary>
Private Sub DefineContentSection(ByVal document As Document)
Dim section As Section = document.AddSection()
section.PageSetup.OddAndEvenPagesHeaderFooter = True
section.PageSetup.StartingNumber = 1
Dim header As HeaderFooter = section.Headers.Primary
header.AddParagraph(vbTab & "Odd Page Header")
header = section.Headers.EvenPage
header.AddParagraph("Even Page Header")
' Create a paragraph with centered page number. See definition of style "Footer".
Dim paragraph As Paragraph = New Paragraph()
paragraph.AddTab()
paragraph.AddPageField()
' Add paragraph to footer for odd pages.
section.Footers.Primary.Add(paragraph)
' Add clone of paragraph to footer for odd pages. Cloning is necessary because an object must
' not belong to more than one other object. If you forget cloning an exception is thrown.
section.Footers.EvenPage.Add(paragraph.Clone())
End Sub
#Region "Paragraphs"
Public Sub DefineParagraphs(ByVal document As Document)