Imports System.Text
Imports IntraSell_DLL

Public Class FormSQL

    Private Sub ButtonRunSQL_Click(sender As Object, e As EventArgs) Handles ButtonRunSQL.Click
        Try

            Dim result As New StringBuilder
            Try
                Dim sql As String
                For Each sql In TextBoxSQL.Text.Split(";")
                    If sql <> "" AndAlso Len(sql) > 6 Then
                        sql = Trim(sql)
                        result.Append("Run SQL: " & sql & vbNewLine)
                        result.Append("Result: " & CStr(RunSQL(sql)) & vbNewLine)
                    End If
                Next

            Catch ex As Exception
                result.Append(ex.Message)
            End Try

            TextBoxResult.Text = result.ToString

        Catch ex As Exception
            HandleAppError(ex)
        End Try
    End Sub

    Private Sub OpenToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles OpenToolStripMenuItem.Click
        Try
            Dim ofd = New OpenFileDialog With {
                .InitialDirectory = GetAppPath()
            }
            Dim file As DialogResult = ofd.ShowDialog
            If file = Windows.Forms.DialogResult.OK Then
                TextBoxSQL.Text = IO.File.ReadAllText(ofd.FileName.ToString)
            End If
        Catch ex As Exception
            HandleAppError(ex)
        End Try
    End Sub

End Class