K Aung Yar Zar DiscAccounting YAccessLo - Bluephoenix

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

K:\Aung Yar Zar\DiscAccounting\yAccessLoader\AccLoader.

vb 1
Imports System
Imports System.Windows.Forms
Imports System.Data.OleDb
Imports System.IO

Public Class yAccessLoader


Dim conn As New OleDb.OleDbConnection
Dim DA As New OleDb.OleDbDataAdapter
Dim DS As New DataSet
Dim DT As New DataTable
Dim CMB As New OleDbCommandBuilder
Dim DGV As New Windows.Forms.DataGridView
Dim TbName, DtFile As String
Dim DBS As New BindingSource
Dim qDT As New DataTable
Dim cmd As String

#Region " loading database here"


'Public Sub DatabaseViewer(ByVal datafilepath As String, ByVal username As String,
ByVal password As String, ByVal tablename As String, ByVal datagrid As Windows.
Forms.DataGridView)
Public Function yDatabaseConnetion(ByVal DataFilePath As String) As OleDb.
OleDbConnection

DtFile = DataFilePath
' If username = "" Then
'username = "Admin"
' End If

'Dim conn_str As String = "Provider = Microsoft.jet.OleDB.4.0;Data Source = "


& datafilepath & ";User ID = " & username & ";Password = " & password
Dim conn_str As String = "Provider = Microsoft.jet.OleDB.4.0;Data Source = " &
DataFilePath
If Not File.Exists(DataFilePath) Then
MsgBox("Required File was not found ! ", MsgBoxStyle.Information)
Return Nothing
Exit Function
End If

conn = New OleDb.OleDbConnection(conn_str)


Return conn
End Function
Public Sub yDatabaseViewer(ByVal TableName As String, ByVal DataGridView As Windows
.Forms.DataGridView)
TbName = TableName
DGV = DataGridView
Call DV(DGV)
conn.Close()

End Sub
#End Region
Private Sub AllCall(ByVal TbName As String)
If conn.State = ConnectionState.Open Then conn.Close()

conn.Open()
DT.Clear()
Try
Dim DA As New OleDb.OleDbDataAdapter("select * from " & TbName, conn)

DA.Fill(DS)
DT = DS.Tables(0)
DBS.DataSource = DT
Catch ex As SystemException
MsgBox(ex.ToString)
End Try
End Sub

#Region "Viwer code here"


K:\Aung Yar Zar\DiscAccounting\yAccessLoader\AccLoader.vb 2
Private Sub DV(ByVal DataGridView As Windows.Forms.DataGridView)

Call AllCall(TbName)
If Not IsNothing(DT) Then
DGV.DataSource = DT
Else
MsgBox("Some Errors Occured")
End If
End Sub

#End Region
#Region "Saving user input code here"
' Public Sub DataBaseSaver(ByVal datafilepath As String, ByVal username As String,
ByVal password As String, ByVal tablename As String, ByVal datagrid As Windows.
Forms.DataGridView)
Private Sub SaverForAll(ByVal DT As DataTable)
' If username = "" Then
'username = "Admin"
' End If

DT.GetChanges()
If Not IsNothing(DT) Then

Try
'Dim conn_str As String = "Provider = Microsoft.jet.OleDB.4.0;Data
Source = " & datafilepath & ";User ID = " & username & ";Password = " & password &
";"
Dim conn_str As String = "Provider = Microsoft.jet.OleDB.4.0;Data
Source = " & DtFile
If Not File.Exists(DtFile) Then
MsgBox("Required File was not found ! ", MsgBoxStyle.Information)

Exit Sub
End If

conn = New OleDb.OleDbConnection(conn_str)


If conn.State = ConnectionState.Open Then conn.Close()
conn.Open()

Dim da = New OleDbDataAdapter("Select * from " & TbName, conn)


' MsgBox(TbName)
CMB = New OleDbCommandBuilder(da)
CMB.QuotePrefix = "["
CMB.QuoteSuffix = "]"
da.UpdateCommand = CMB.GetUpdateCommand
da.Update(DT)

da.Fill(DT)

Catch ex As Exception
MsgBox(ex.ToString)
End Try
conn.Close()
End If
End Sub
Public Sub yDataBaseSaver()
Call SaverForAll(DT)
Call DV(DGV)
End Sub
#End Region
Property yDBLoaderDataSet(ByVal TableName As String) As DataSet

Get
TbName = TableName
Call AllCall(TbName)
Return DS
End Get
Set(ByVal value As DataSet)
DS = value
K:\Aung Yar Zar\DiscAccounting\yAccessLoader\AccLoader.vb 3
End Set
End Property
Property yDBLoaderDataTable(ByVal TableName As String) As DataTable

Get
TbName = TableName
Call AllCall(TbName)
Return DT
End Get
Set(ByVal value As DataTable)
DT = value
End Set
End Property
Property yDBLoaderBindingSource(ByVal TableName As String) As Windows.Forms.
BindingSource

Get
TbName = TableName
Call AllCall(TbName)
Return DBS
End Get
Set(ByVal value As Windows.Forms.BindingSource)
DBS = value
End Set
End Property
Public Sub yBindindSourceSaver(ByVal DataTable As DataTable)
Call SaverForAll(DataTable)
End Sub
Public Sub yQueryViewer(ByVal Command As String, ByVal DGV As System.Windows.Forms.
DataGridView)

cmd = Command
If Command = "" Then
MsgBox("You must Discribe specific SQL Command String")

Exit Sub
End If
If conn.State = ConnectionState.Open Then conn.Close()

conn.Open()
'DT.Clear()
qDT.Clear()
Try
Dim qDA As New OleDb.OleDbDataAdapter(Command, conn)

qDA.Fill(qDT)
'DT = qDT
DGV.DataSource = qDT
Catch ex As SystemException
MsgBox(ex.ToString)
End Try

End Sub
Public Function yQueryDataTable(ByVal Command As String) As DataTable
Dim qDT As New DataTable
cmd = Command
If Command = "" Then
MsgBox("You must Discribe specific SQL Command String")
Return Nothing
Exit Function
End If
If conn.State = ConnectionState.Open Then conn.Close()

conn.Open()
'DT.Clear()
qDT.Clear()
Try
Dim qDA As New OleDb.OleDbDataAdapter(Command, conn)

qDA.Fill(qDT)
'DT = qDT
Catch ex As SystemException
K:\Aung Yar Zar\DiscAccounting\yAccessLoader\AccLoader.vb 4
MsgBox(ex.ToString)
End Try
Return qDT
End Function
Public Function yQueryDataSet(ByVal Command As String) As DataSet
Dim qDS As New DataSet
cmd = Command
If Command = "" Then
MsgBox("You must Discribe specific SQL Command String")
Return Nothing
Exit Function
End If
If conn.State = ConnectionState.Open Then conn.Close()

conn.Open()
'DT.Clear()
qDS.Clear()
Try
Dim qDA As New OleDb.OleDbDataAdapter(Command, conn)

qDA.Fill(qDS)

Catch ex As SystemException
MsgBox(ex.ToString)
End Try
Return qDS
End Function
Public Function yQueryDataSet(ByVal tlbName As String, ByVal Command As String) As
DataSet
Dim qDS As New DataSet
cmd = Command
If Command = "" Then
MsgBox("You must Discribe specific SQL Command String")
Return Nothing
Exit Function
End If
If conn.State = ConnectionState.Open Then conn.Close()

conn.Open()
'DT.Clear()
qDS.Clear()
Try
Dim qDA As New OleDb.OleDbDataAdapter(Command, conn)

qDA.Fill(qDS)

Catch ex As SystemException
MsgBox(ex.ToString)
End Try
Return qDS
End Function
Public Sub yQuerySaver()
Call SaverForQuery(qDT)
yQueryViewer(cmd, DGV)
'DGV.DataSource = qDT
'Call DV(DGV)
End Sub
Private Sub SaverForQuery(ByVal qDT As DataTable)
' If username = "" Then
'username = "Admin"
' End If

qDT.GetChanges()
If Not IsNothing(qDT) Then

Try
'
'Dim conn_str As String = "Provider = Microsoft.jet.OleDB.4.0;Data
Source = " & datafilepath & ";User ID = " & username & ";Password = " & password &
";"
Dim conn_str As String = "Provider = Microsoft.jet.OleDB.4.0;Data
K:\Aung Yar Zar\DiscAccounting\yAccessLoader\AccLoader.vb 5
Source = " & DtFile
If Not File.Exists(DtFile) Then
MsgBox("Required File was not found ! ", MsgBoxStyle.Information)

Exit Sub
End If

conn = New OleDb.OleDbConnection(conn_str)


If conn.State = ConnectionState.Open Then conn.Close()
conn.Open()

Dim qDA As New OleDb.OleDbDataAdapter(cmd, conn)


CMB = New OleDbCommandBuilder(qDA)
CMB.QuotePrefix = "["
CMB.QuoteSuffix = "]"
qDA.UpdateCommand = CMB.GetUpdateCommand
qDA.Update(qDT)

qDA.Fill(qDT)

Catch ex As Exception
MsgBox(ex.ToString)
End Try
conn.Close()
End If
End Sub
Sub yDbDeleteAllFromTable(ByVal tblName As String)

'MsgBox(findstr) CurrentQuantity
Try
'Call formClear()
' MessageBox.Show(findstr & " + " & tblName)

If conn.State = ConnectionState.Open Then conn.Close()


conn.Open()
'Dim cmdstr As String = "UPDATE Softwares SET Code = 'yea' WHERE Title like
'%Adobe%' "
Dim cmdstr As String = "DELETE * FROM " & tblName
Dim cmd As New OleDbCommand(cmdstr, conn)
cmd.ExecuteNonQuery()
'MsgBox("Done!")
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Sub yDbDeleteItemsFromTable(ByVal tblName As String, ByVal sqlCommand As String)

If sqlCommand = "" Then Exit Sub


'MsgBox(findstr) CurrentQuantity
Try
'Call formClear()
' MessageBox.Show(findstr & " + " & tblName)

If conn.State = ConnectionState.Open Then conn.Close()


conn.Open()
'Dim cmdstr As String = "UPDATE Softwares SET Code = 'yea' WHERE Title like
'%Adobe%' "
Dim cmdstr As String = sqlCommand
Dim cmd As New OleDbCommand(cmdstr, conn)
cmd.ExecuteNonQuery()
'MsgBox("Done!")
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
End Class

You might also like