Helpers Folder

1.     On the AppToolBox.vb, type the following:
Module AppToolBox
    Function FieldsNotEmpty(ByVal c As Control) As Boolean
        FieldsNotEmpty = True

        Dim txbx As New TextBox
        For Each ctrl In c.Controls
            If ctrl.GetType.ToString = txbx.GetType.ToString Then
                If ctrl.text = "" Then
                    FieldsNotEmpty = False
                    MsgBox("Cannot continue, check for empty field.", MsgBoxStyle.Exclamation, "Message")
                    Exit For
                End If
            End If
        Next
    End Function

    Public Sub ClearTextBoxes(ByVal c As Control)
        Dim txbx As New TextBox
        For Each ctrl In c.Controls
            If ctrl.GetType.ToString = txbx.GetType.ToString Then
                ctrl.text = ""
            End If
        Next
    End Sub

    Public Sub Message(ByVal msg As String)
        MessageBox.Show(msg, "Message", MessageBoxButtons.OK, MessageBoxIcon.Information)
    End Sub
End Module

2.     On the dbs.vb, type the following:
Imports System.Data.OleDb
Public Class dbs
    Public Shared Function Connect() As OledbConnection
        Dim con As New OleDbConnection
        con.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;" _
        & "Data Source=" & Application.StartupPath & "\Database\SALES.MDB"
        con.Open()
        Return con
    End Function
End Class

3.     On the Transactions.vb, type the following:
Imports System.Data.OleDb
Public Class Transactions
    Private SQLArrayToExecute As New ArrayList
    Private db As OleDbConnection

    Public Sub New()
        db = dbs.Connect
    End Sub
    Public Sub add(ByVal sql As String)
        SQLArrayToExecute.Add(sql)
    End Sub

    Public Sub ExecuteSQLArray()
        Dim trans As OleDbTransaction = db.BeginTransaction()
        For Each sqlToEx In SQLArrayToExecute
            Dim cmd As New OleDbCommand(sqlToEx, db, trans)
            cmd.ExecuteNonQuery()
        Next
        trans.Commit()
    End Sub
End Class






No comments:

Post a Comment