Merge branch 'master' of http://git.dd:3000/AppStd/Monorepo
This commit is contained in:
@@ -492,12 +492,6 @@ Public Class DocumentViewer
|
||||
End Sub
|
||||
Private Function DoLoadFile(FilePath As String, Optional ViewOverride As String = "") As Boolean
|
||||
Try
|
||||
' Ensure the embedded GdViewer control exists before using it
|
||||
If Not EnsureViewerReady() Then
|
||||
_logger?.Warn("GdViewer control is not initialized yet. Delaying load.")
|
||||
Return False
|
||||
End If
|
||||
|
||||
lblInfo.Visible = False
|
||||
Dim oFileInfo = New FileInfo(FilePath)
|
||||
Dim oExtension As String = oFileInfo.Extension.ToUpper
|
||||
@@ -510,6 +504,14 @@ Public Class DocumentViewer
|
||||
SpreadsheetControl1.Dock = DockStyle.None
|
||||
RichEditControl1.Dock = DockStyle.None
|
||||
|
||||
Dim override_Spreadsheet As Boolean = False
|
||||
If oExtension.ToLower = ".xlsx" Then
|
||||
If oFileInfo.Length > 15000 Then
|
||||
_logger.Info("Override")
|
||||
override_Spreadsheet = True
|
||||
End If
|
||||
End If
|
||||
|
||||
If ViewOverride = "Richtext" Then
|
||||
RichEditControl1.LoadDocument(FilePath, GetDocumentFormat(oExtension))
|
||||
RichEditControl1.Visible = True
|
||||
@@ -519,6 +521,16 @@ Public Class DocumentViewer
|
||||
_ViewerMode = ViewerMode.Richtext
|
||||
lblInfo.Visible = True
|
||||
lblInfo.Text = "This docx-file contains a generic error and will be displayed in a reduced viewer. Please try to open the file in WORD"
|
||||
ElseIf override_Spreadsheet = True Then
|
||||
Dim oFormat = GetSpreadsheetFormat(oExtension)
|
||||
SpreadsheetControl1.LoadDocument(FilePath, oFormat)
|
||||
|
||||
Dim oRange = SpreadsheetControl1.ActiveWorksheet.GetUsedRange()
|
||||
oRange.AutoFitColumns()
|
||||
|
||||
SpreadsheetControl1.Visible = True
|
||||
GdViewer.Visible = False
|
||||
SpreadsheetControl1.Dock = DockStyle.Fill
|
||||
Else
|
||||
_ViewOverride = ""
|
||||
Select Case oExtension.ToUpper
|
||||
@@ -533,6 +545,12 @@ Public Class DocumentViewer
|
||||
GdViewer.Visible = False
|
||||
SpreadsheetControl1.Dock = DockStyle.Fill
|
||||
|
||||
'Case ".EML", ".DOC", ".DOCX", ".ODT", ".RTF", ".TXT"
|
||||
' RichEditControl1.LoadDocument(FilePath, GetDocumentFormat(oExtension))
|
||||
|
||||
' RichEditControl1.Visible = True
|
||||
' GdViewer.Visible = False
|
||||
' RichEditControl1.Dock = DockStyle.Fill
|
||||
Case Else
|
||||
Select Case oExtension.ToUpper
|
||||
Case ".EML", ".DOC", ".DOCX", ".XLS", ".XLSX", ".ODT", ".RTF", ".TXT"
|
||||
@@ -578,8 +596,111 @@ Public Class DocumentViewer
|
||||
Return False
|
||||
End Try
|
||||
End Function
|
||||
Private Function DoLoadFile(FilePath As String) As Boolean
|
||||
Try
|
||||
' Ensure the embedded GdViewer control exists before using it
|
||||
If Not EnsureViewerReady() Then
|
||||
_logger?.Warn("GdViewer control is not initialized yet. Delaying load.")
|
||||
Return False
|
||||
End If
|
||||
|
||||
lblInfo.Visible = False
|
||||
Dim oFileInfo = New FileInfo(FilePath)
|
||||
Dim oExtension As String = oFileInfo.Extension.ToUpper
|
||||
|
||||
lbFileNotLoaded.Visible = False
|
||||
|
||||
SpreadsheetControl1.Visible = False
|
||||
RichEditControl1.Visible = False
|
||||
|
||||
SpreadsheetControl1.Dock = DockStyle.None
|
||||
RichEditControl1.Dock = DockStyle.None
|
||||
Dim Override_SSheet_Filesize As Boolean = False
|
||||
If oExtension.ToLower = ".xlsx" Then
|
||||
If oFileInfo.Length > 100000 Then
|
||||
_logger.Info("Override Spreadsheet as xlsx is too big")
|
||||
Override_SSheet_Filesize = True
|
||||
End If
|
||||
End If
|
||||
If Override_SSheet_Filesize Then
|
||||
Dim oFormat = GetSpreadsheetFormat(oExtension)
|
||||
SpreadsheetControl1.LoadDocument(FilePath, oFormat)
|
||||
|
||||
Dim oRange = SpreadsheetControl1.ActiveWorksheet.GetUsedRange()
|
||||
oRange.AutoFitColumns()
|
||||
|
||||
If ViewOverride = "Richtext" Then
|
||||
RichEditControl1.LoadDocument(FilePath, GetDocumentFormat(oExtension))
|
||||
RichEditControl1.Visible = True
|
||||
GdViewer.Visible = False
|
||||
RichEditControl1.Dock = DockStyle.Fill
|
||||
_ViewOverride = "Richtext"
|
||||
_ViewerMode = ViewerMode.Richtext
|
||||
lblInfo.Visible = True
|
||||
lblInfo.Text = "This docx-file contains a generic error and will be displayed in a reduced viewer. Please try to open the file in WORD"
|
||||
Else
|
||||
_ViewOverride = ""
|
||||
Select Case oExtension.ToUpper
|
||||
Case ".CSV"
|
||||
Dim oFormat = GetSpreadsheetFormat(oExtension)
|
||||
SpreadsheetControl1.LoadDocument(FilePath, oFormat)
|
||||
|
||||
Dim oRange = SpreadsheetControl1.ActiveWorksheet.GetUsedRange()
|
||||
oRange.AutoFitColumns()
|
||||
|
||||
SpreadsheetControl1.Visible = True
|
||||
GdViewer.Visible = False
|
||||
SpreadsheetControl1.Dock = DockStyle.Fill
|
||||
Case ".EML", ".DOC", ".DOCX", ".ODT", ".RTF", ".TXT"
|
||||
RichEditControl1.LoadDocument(FilePath, GetDocumentFormat(oExtension))
|
||||
|
||||
RichEditControl1.Visible = True
|
||||
GdViewer.Visible = False
|
||||
RichEditControl1.Dock = DockStyle.Fill
|
||||
Case Else
|
||||
GdViewer.ZoomMode = ViewerZoomMode.ZoomModeWidthViewer
|
||||
GdViewer.DocumentAlignment = ViewerDocumentAlignment.DocumentAlignmentTopCenter
|
||||
GdViewer.ForceTemporaryMode = True
|
||||
GdViewer.DocumentAlignment = ViewerDocumentAlignment.DocumentAlignmentTopCenter
|
||||
If Viewer_ForceTemporaryMode = True Then
|
||||
GdViewer.ForceTemporaryMode = True
|
||||
End If
|
||||
|
||||
GdViewer.AnnotationDropShadow = True
|
||||
GdViewer.BackColor = Color.White
|
||||
|
||||
Dim oGDPState As GdPicture14.GdPictureStatus = GdViewer.DisplayFromFile(FilePath)
|
||||
If oGDPState <> GdPictureStatus.OK Then
|
||||
_logger.Warn($"GdPictureStatus is [{oGDPState}]")
|
||||
If oExtension.ToUpper = ".DOCX" And oGDPState = GdPictureStatus.GenericError Then
|
||||
DoLoadFile(FilePath, "Richtext")
|
||||
Else
|
||||
Dim oFileName = IO.Path.GetFileName(FilePath)
|
||||
lbFileNotLoaded.Text = String.Format("Datei konnte nicht geladen werden:{0}{1}", vbCrLf, oFileName)
|
||||
lbFileNotLoaded.Visible = True
|
||||
End If
|
||||
|
||||
Else
|
||||
If GdViewer.Visible = False Then
|
||||
GdViewer.Visible = True
|
||||
End If
|
||||
End If
|
||||
|
||||
End Select
|
||||
|
||||
|
||||
Return True
|
||||
Catch ex As Exception
|
||||
_logger.Error(ex)
|
||||
Return False
|
||||
End Try
|
||||
End Function
|
||||
|
||||
' Ensures the embedded GdViewer control exists and is added to the visual tree
|
||||
Private Function EnsureViewerReady() As Boolean
|
||||
Try
|
||||
' If the control field is Nothing (e.g., designer not yet created), try to lazy-create and add it
|
||||
If GdViewer Is Nothing Then
|
||||
Private Function EnsureViewerReady() As Boolean
|
||||
Try
|
||||
' If the control field is Nothing (e.g., designer not yet created), try to lazy-create and add it
|
||||
@@ -659,6 +780,41 @@ Public Class DocumentViewer
|
||||
Return False
|
||||
End Try
|
||||
End Function
|
||||
Private Function StreamFile(Stream As Stream, Extension As String) As Boolean
|
||||
Try
|
||||
|
||||
SpreadsheetControl1.Visible = False
|
||||
SpreadsheetControl1.Dock = DockStyle.None
|
||||
|
||||
Select Case Extension.ToUpper
|
||||
|
||||
Case ".CSV"
|
||||
SpreadsheetControl1.LoadDocument(Stream, GetSpreadsheetFormat(Extension))
|
||||
|
||||
Dim oRange = SpreadsheetControl1.ActiveWorksheet.GetUsedRange()
|
||||
oRange.AutoFitColumns()
|
||||
|
||||
SpreadsheetControl1.Visible = True
|
||||
SpreadsheetControl1.Dock = DockStyle.Fill
|
||||
|
||||
Case Else
|
||||
GdViewer.ZoomMode = ViewerZoomMode.ZoomModeWidthViewer
|
||||
GdViewer.DocumentAlignment = ViewerDocumentAlignment.DocumentAlignmentTopCenter
|
||||
GdViewer.ForceTemporaryMode = True
|
||||
GdViewer.AnnotationDropShadow = True
|
||||
|
||||
GdViewer.DisplayFromStream(Stream)
|
||||
|
||||
End Select
|
||||
|
||||
UpdateMainUi()
|
||||
|
||||
Return True
|
||||
Catch ex As Exception
|
||||
_logger.Error(ex)
|
||||
Return False
|
||||
End Try
|
||||
End Function
|
||||
|
||||
Private Function GetSpreadsheetFormat(Extension) As Spreadsheet.DocumentFormat
|
||||
Dim oFormat As Spreadsheet.DocumentFormat = Spreadsheet.DocumentFormat.Undefined
|
||||
|
||||
Reference in New Issue
Block a user