Remove try-catch from Button1/2_Click event handlers

Refactored Button1_Click and Button2_Click to eliminate local try-catch blocks, allowing exceptions to propagate. Cleaned up redundant code and improved clarity by moving variable declarations outside of the previous try blocks. Core logic remains unchanged.
This commit is contained in:
2026-02-23 09:58:07 +01:00
parent f5f137396e
commit 511fad3950

View File

@@ -7,7 +7,6 @@ Imports GdPicture14
Imports Newtonsoft.Json.Linq
Imports EnvelopeGenerator.Infrastructure
Imports Microsoft.EntityFrameworkCore
Imports System.Text
Imports DigitalData.Core.Abstractions
Public Class frmFinalizePDF
@@ -93,56 +92,36 @@ Public Class frmFinalizePDF
End Function
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Try
Dim oTable = LoadAnnotationDataForEnvelope()
Dim oJsonList = oTable.Rows.
Cast(Of DataRow).
Select(Function(r As DataRow) r.Item("VALUE").ToString()).
ToList()
Dim oTable = LoadAnnotationDataForEnvelope()
Dim oJsonList = oTable.Rows.
Cast(Of DataRow).
Select(Function(r As DataRow) r.Item("VALUE").ToString()).
ToList()
Dim envelopeId As Integer = CInt(txtEnvelope.Text)
Dim oBuffer As Byte() = ReadEnvelope(envelopeId)
Dim oNewBuffer = PDFBurner.BurnAnnotsToPDF(oBuffer, oJsonList, envelopeId)
Dim desktopPath As String = Environment.GetFolderPath(Environment.SpecialFolder.Desktop)
Dim oNewPath = Path.Combine(desktopPath, $"E{txtEnvelope.Text}R{txtReceiver.Text}.burned.pdf")
Dim envelopeId As Integer = CInt(txtEnvelope.Text)
Dim oBuffer As Byte() = ReadEnvelope(envelopeId)
Dim oNewBuffer = PDFBurner.BurnAnnotsToPDF(oBuffer, oJsonList, envelopeId)
Dim desktopPath As String = Environment.GetFolderPath(Environment.SpecialFolder.Desktop)
Dim oNewPath = Path.Combine(desktopPath, $"E{txtEnvelope.Text}R{txtReceiver.Text}.burned.pdf")
File.WriteAllBytes(oNewPath, oNewBuffer)
Process.Start(oNewPath)
Catch ex As Exception
Dim exMsg As StringBuilder = New StringBuilder(ex.Message).AppendLine()
Dim innerEx = ex.InnerException
While (innerEx IsNot Nothing)
exMsg.AppendLine(innerEx.Message)
innerEx = innerEx.InnerException
End While
MsgBox(exMsg.ToString(), MsgBoxStyle.Critical)
End Try
File.WriteAllBytes(oNewPath, oNewBuffer)
Process.Start(oNewPath)
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Try
Dim oTable = LoadAnnotationDataForEnvelope()
Dim oJsonList = oTable.Rows.
Cast(Of DataRow).
Select(Function(r As DataRow) r.Item("VALUE").ToString()).
Select(Function(s As String) JObject.Parse(s)).
ToList()
Dim oTable = LoadAnnotationDataForEnvelope()
Dim oJsonList = oTable.Rows.
Cast(Of DataRow).
Select(Function(r As DataRow) r.Item("VALUE").ToString()).
Select(Function(s As String) JObject.Parse(s)).
ToList()
Dim oJObject1 = oJsonList.First()
Dim oJObject2 = oJsonList.ElementAt(1)
Dim oJObject1 = oJsonList.First()
Dim oJObject2 = oJsonList.ElementAt(1)
oJObject1.Merge(oJObject2)
oJObject1.Merge(oJObject2)
txtResult.Text = oJObject1.ToString()
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Critical)
End Try
txtResult.Text = oJObject1.ToString()
End Sub
End Class