MS Integrating ByteData to DB for SIG Documents

This commit is contained in:
2024-06-19 11:16:32 +02:00
parent 76d4151182
commit 67a8506a37
21 changed files with 522 additions and 106 deletions

View File

@@ -1,4 +1,5 @@
Imports DevExpress.LookAndFeel
Imports System.IO
Imports DevExpress.LookAndFeel
Imports DevExpress.Utils.Extensions
Imports DevExpress.XtraCharts
Imports DevExpress.XtraGrid
@@ -19,6 +20,8 @@ Public Class frmMain
Private State As State
Private Controller As EnvelopeListController
Private myFileData As Byte()
Private myResFileData As Byte()
Public Sub New(pState As State)
' Dieser Aufruf ist für den Designer erforderlich.
@@ -187,11 +190,13 @@ Public Class frmMain
btnDeleteEnvelope.Enabled = False
btnContactReceiver.Enabled = False
btnShowDocument.Enabled = False
bbtnitmEB.Enabled = True
Case 0
btnEditEnvelope.Enabled = True
btnDeleteEnvelope.Enabled = True
btnContactReceiver.Enabled = True
btnShowDocument.Enabled = True
bbtnitmEB.Enabled = False
End Select
End Sub
@@ -214,9 +219,31 @@ Public Class frmMain
btnEditEnvelope.Enabled = True
End If
End Sub
Private Sub bbtnitmEB_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles bbtnitmEB.ItemClick
If ViewEnvelopes.FocusedRowHandle < 0 Then
Exit Sub
End If
Me.Cursor = Cursors.WaitCursor
Dim oEnvelope As Envelope = ViewCompleted.GetRow(ViewCompleted.FocusedRowHandle)
GetResRepFileStreamByte(oEnvelope.Id)
Dim oTempFolder = TempFiles.TempPath
Dim oTempFilename = String.Concat(oTempFolder, "\", $"ViewEnvResReport_{oEnvelope.Id}.pdf")
If File.Exists(oTempFilename) Then
Try
File.OpenWrite(oTempFilename)
Catch ex As Exception
MsgBox("File might already be open?", MsgBoxStyle.Exclamation)
Exit Sub
End Try
File.Delete(oTempFilename)
End If
downloadResFile(oTempFilename)
Me.Cursor = Cursors.Default
End Sub
Private Sub ViewEnvelopes_CustomDrawCell(sender As Object, e As DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs) Handles ViewEnvelopes.CustomDrawCell
If e.RowHandle < 0 Then
If e.RowHandle < 0 Or XtraTabControl1.SelectedTabPageIndex = 1 Then
Exit Sub
End If
@@ -311,33 +338,142 @@ Public Class frmMain
End Sub
Private Sub btnShowDocument_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles btnShowDocument.ItemClick
If ViewEnvelopes.FocusedRowHandle < 0 Then
Exit Sub
End If
Dim oEnvelope As Envelope = ViewEnvelopes.GetRow(ViewEnvelopes.FocusedRowHandle)
Dim oDocument = oEnvelope.Documents.FirstOrDefault()
If oDocument Is Nothing Then
MsgBox(Resources.Envelope.The_envelope_does_not_contain_any_documents, MsgBoxStyle.Exclamation, Text)
Exit Sub
End If
Try
Process.Start(oDocument.Filepath)
If ViewEnvelopes.FocusedRowHandle < 0 Then
Exit Sub
End If
Me.Cursor = Cursors.WaitCursor
Dim oEnvelope As Envelope = ViewEnvelopes.GetRow(ViewEnvelopes.FocusedRowHandle)
Dim oDocument = oEnvelope.Documents.FirstOrDefault()
If oDocument Is Nothing Then
MsgBox(Resources.Envelope.The_envelope_does_not_contain_any_documents, MsgBoxStyle.Exclamation, Text)
Me.Cursor = Cursors.Default
Exit Sub
Else
If Not IsNothing(oDocument.Byte_Data) Then
Dim oTempFolder = TempFiles.TempPath
Dim oTempFilename = String.Concat(oTempFolder, "\", $"ViewEnvDoc_{oEnvelope.Id}.pdf")
If File.Exists(oTempFilename) Then
Try
File.OpenWrite(oTempFilename)
Catch ex As Exception
MsgBox("File might already be open?", MsgBoxStyle.Exclamation)
Me.Cursor = Cursors.Default
Exit Sub
End Try
File.Delete(oTempFilename)
End If
downloadFile(oTempFilename, oDocument.Byte_Data)
End If
End If
Catch ex As Exception
MsgBox(Resources.Envelope.Document_could_not_be_opened, MsgBoxStyle.Critical, Text)
Logger.Error(ex)
Logger.Error(ex)
End Try
Me.Cursor = Cursors.Default
End Sub
'Private Sub GetFileStreamByte(ByVal pEnvID As Long)
' Dim strSql As String
' 'For Document
' Try
' 'Get image data from gridview column.
' strSql = "Select [DOC1] from [TBSIG_ENVELOPE] WHERE GUID =" & pEnvID
' 'Get image data from DB
' Dim fileData As Byte() = DirectCast(DB_DD_ECM.GetScalarValue(strSql), Byte())
' If Not fileData Is Nothing Then
' myFileData = fileData
' Else
' myFileData = Nothing
' End If
' Catch ex As Exception
' MsgBox(ex.Message, MsgBoxStyle.Exclamation, "Error in GetFileStreamByte")
' myFileData = Nothing
' End Try
'End Sub
Private Sub GetResRepFileStreamByte(ByVal pEnvID As Long)
Dim strSql As String
'For Document
Try
'Get image data from gridview column.
strSql = "Select [DOC_RESULT] from [TBSIG_ENVELOPE] WHERE GUID = " & pEnvID
Dim obyteDB = DB_DD_ECM.GetScalarValue(strSql)
If Not IsDBNull(obyteDB) Then
'Get image data from DB
Dim fileData As Byte() = DirectCast(DB_DD_ECM.GetScalarValue(strSql), Byte())
If Not fileData Is Nothing Then
myResFileData = fileData
Else
myResFileData = Nothing
End If
Else
myResFileData = Nothing
End If
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Exclamation, "Error in GetResRepFileStreamByte")
myResFileData = Nothing
End Try
End Sub
Private Sub downloadFile(ByVal sFileName As String, pByte As Byte())
'For Document
Try
If Not pByte Is Nothing Then
'Read image data into a file stream
Using fs As New FileStream(sFileName, FileMode.OpenOrCreate, FileAccess.Write)
fs.Write(pByte, 0, pByte.Length)
'Set image variable value using memory stream.
fs.Flush()
fs.Close()
End Using
'Open File
Process.Start(sFileName)
End If
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Exclamation, "Error in downloadFile")
End Try
End Sub
Private Sub downloadResFile(ByVal sFileName As String)
Dim strSql As String
'For Document
Try
If Not myResFileData Is Nothing Then
'Read image data into a file stream
Using fs As New FileStream(sFileName, FileMode.OpenOrCreate, FileAccess.Write)
fs.Write(myResFileData, 0, myResFileData.Length)
'Set image variable value using memory stream.
fs.Flush()
fs.Close()
End Using
'Open File
Process.Start(sFileName)
Else
MsgBox("Could not get DocData from Database!", MsgBoxStyle.Exclamation, "Error in downloadResFile")
End If
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Exclamation, "Error in downloadResFile")
End Try
End Sub
Private Sub ViewCompleted_FocusedRowChanged(sender As Object, e As Views.Base.FocusedRowChangedEventArgs) Handles ViewCompleted.FocusedRowChanged
If ViewCompleted.FocusedRowHandle < 0 Then
Exit Sub
End If
Dim oEnvelope As Envelope = ViewCompleted.GetRow(ViewCompleted.FocusedRowHandle)
If oEnvelope.Status = Common.Constants.EnvelopeStatus.EnvelopeArchived Then
bbtnitmEB.Enabled = True
Else
bbtnitmEB.Enabled = False
End If
txtEnvelopeIdLabel.Caption = String.Format(txtEnvelopeIdLabel.Tag, oEnvelope.Id)
End Sub
@@ -370,4 +506,6 @@ Public Class frmMain
End If
RefreshTimer.Start()
End Sub
End Class