Public Class FrmMain

    Private Sub btnBrowser_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBrowser.Click
        If Me.openFileDialog1.ShowDialog(Me) = System.Windows.Forms.DialogResult.OK Then
            Me.textBox1.Text = Me.openFileDialog1.FileName
            Me.textBox2.Text = System.IO.Path.GetDirectoryName(Me.textBox1.Text)
        End If
    End Sub

    Private Sub btnSelect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSelect.Click
        Me.folderBrowserDialog1.SelectedPath = Me.textBox2.Text
        If Me.folderBrowserDialog1.ShowDialog(Me) = System.Windows.Forms.DialogResult.OK Then
            Me.textBox2.Text = Me.folderBrowserDialog1.SelectedPath
        End If
    End Sub

    Private Sub btnEncrypt_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEncrypt.Click

        If Me.textBox1.Text.Length = 0 And Me.textBox2.Text.Length = 0 Then
            Return
        End If
        Dim encCmd As String = System.IO.Path.Combine(Application.StartupPath, "tools\UdPdfTools.exe")
        Dim args As String = String.Format("-input {0} -output {1} -password {2}", Me.textBox1.Text, Me.textBox2.Text, Me.tbxPassword.Text)
        Dim p As System.Diagnostics.Process = New System.Diagnostics.Process()
        p.StartInfo.FileName = encCmd
        p.StartInfo.Arguments = args
        p.StartInfo.UseShellExecute = False
        p.StartInfo.RedirectStandardOutput = True '由调用程序获取输出信息
        p.StartInfo.CreateNoWindow = True '不显示程序窗口
        p.Start()
        p.WaitForExit()

        Dim br As String = Chr(10) & Chr(13)
        Dim strOutput As String
        strOutput = p.StandardOutput.ReadToEnd()
        If p.ExitCode = 0 Then
            MessageBox.Show("加密成功:" & br & strOutput, "Success", MessageBoxButtons.OK, MessageBoxIcon.Information)

        Else
            MessageBox.Show("加密失败，错误码：" & p.ExitCode & br & strOutput, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
        End If

    End Sub

    Private Sub btnConfigEncrypt_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnConfigEncrypt.Click

        Dim encCmd As String = System.IO.Path.Combine(Application.StartupPath, "tools\UdPdfTools.exe")
        Dim args As String = String.Format("-encrypt {0}", Me.textBox3.Text)

        Dim p As System.Diagnostics.Process = New System.Diagnostics.Process()
        p.StartInfo.FileName = encCmd
        p.StartInfo.Arguments = args
        p.StartInfo.UseShellExecute = False
        p.StartInfo.RedirectStandardOutput = True '由调用程序获取输出信息
        p.StartInfo.CreateNoWindow = True '不显示程序窗口
        p.Start()
        p.WaitForExit()

        Dim strOutput As String
        strOutput = p.StandardOutput.ReadToEnd()
        Me.textBox4.Text = strOutput

    End Sub

    Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
        Me.Close()
    End Sub

End Class
