Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Imports ADOX
- Imports System.IO
- Imports System.Data.OleDb
- Imports System.Text
- Imports System.Security.Cryptography
- Public Class LogIn
- Public ConnectionString As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=N:\TestDatabase.accdb;"
- Dim cat As Catalog = New Catalog()
- Dim SQLCommand As String
- Dim con As New OleDbConnection(ConnectionString)
- Dim cmd As New OleDbCommand
- Dim uname As String
- Dim pword As String
- 'This sub creates all the tables within the database
- Private Sub LogIn_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
- Dim cat As Catalog = New Catalog()
- Dim SQLCommand As String = "CREATE TABLE Staff(Username VarChar(255), Pword VarChar(255));"
- Dim con As New OleDbConnection(ConnectionString)
- Dim cmd As New OleDbCommand
- If File.Exists("N:\TestDatabase.accdb") = True Then
- MsgBox("already exists")
- Else
- cat.Create("Provider=Microsoft.Jet.OLEDB.4.0;" & _
- "Data Source=N:\TestDatabase.accdb;" & _
- "Jet OLEDB:Engine Type=5")
- MsgBox("Made")
- cat = Nothing
- End If
- con.Open()
- cmd.Connection = con
- cmd.CommandText = (SQLCommand)
- cmd.ExecuteNonQuery()
- uname = "Admin"
- pword = HashPass("pass1")
- cmd.CommandText = "INSERT INTO Staff(Username, Pword) VALUES ('" & uname & "','" & pword & "')"
- cmd.ExecuteNonQuery()
- con.Close()
- CreateAllTables()
- End Sub
- Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLogin.Click
- CheckLogIn()
- End Sub
- ' This sub checks if the password and login that have been entered are equal to the one in the Staff table.
- Private Sub CheckLogIn()
- Dim uname As String = "Admin"
- If txtpassword.Text = "pass1" Then
- pword = HashPass("pass1")
- End If
- Dim pass As String
- If txtusername.Text = "" Or txtpassword.Text = "" Then
- MsgBox("Please fill in all the provided fields to continue!")
- Else
- Dim querry As String = "Select pword From Staff where Username= '" & uname & "';"
- Dim dbsource As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=N:\TestDatabase.accdb"
- Dim conn = New OleDbConnection(dbsource)
- Dim cmd As New OleDbCommand(querry, conn)
- conn.Open()
- Try
- pass = cmd.ExecuteScalar().ToString
- Catch ex As Exception
- MsgBox("Username does not exit")
- End Try
- If (pword = pass) Then
- MsgBox("Login success")
- Main_Menu.Show()
- If Main_Menu.Visible Then
- Me.Hide()
- End If
- Else
- MsgBox("login Failed")
- txtusername.Clear()
- txtpassword.Clear()
- End If
- End If
- con.Close()
- End Sub
- ' Grade A Hashing Function
- Private Function HashPass(ByVal Content As String) As String
- Dim MoLeCuL3 As New Security.Cryptography.SHA1CryptoServiceProvider
- Dim ByteString() As Byte = System.Text.Encoding.ASCII.GetBytes(Content)
- ByteString = MoLeCuL3.ComputeHash(ByteString)
- Dim FinalString As String = Nothing
- For Each bt As Byte In ByteString
- FinalString &= bt.ToString("x2")
- Next
- Return FinalString
- End Function
- 'Grade A Using SQL
- ' This Sub creates all the tables within the database.
- Private Sub CreateAllTables()
- SQLCommand = "CREATE TABLE Supplier(SupplierID varchar(255) PRIMARY KEY, BusinessName VarChar(255), ContactName Varchar(255)," &
- "BusinessEmail Varchar(255), BusinessAddress Varchar(255), BusinessCity Varchar(255), BusinessPostcode Varchar(255));"
- con.Open()
- cmd.Connection = con
- cmd.CommandText = (SQLCommand)
- Try
- cmd.ExecuteNonQuery()
- Catch ex As Exception
- End Try
- con.Close()
- SQLCommand = "CREATE TABLE Customer(CustomerID varchar(255) PRIMARY KEY, FirstName VarChar(255), LastName Varchar(255), Email Varchar(255)," &
- "Address Varchar(255), City Varchar(255), Postcode Varchar(255));"
- con.Open()
- cmd.Connection = con
- cmd.CommandText = (SQLCommand)
- Try
- cmd.ExecuteNonQuery()
- Catch ex As Exception
- End Try
- con.Close()
- SQLCommand = "CREATE TABLE Inventory(ProductID varchar(255) PRIMARY KEY, ProductName VarChar(255), ItemCost varchar(255)," &
- "ItemPrice varchar(255), ItemQuantity varchar(255), SupplierID varchar(255), FOREIGN KEY (SupplierID) REFERENCES Supplier(SupplierID))"
- con.Open()
- cmd.Connection = con
- cmd.CommandText = (SQLCommand)
- Try
- cmd.ExecuteNonQuery()
- Catch ex As Exception
- End Try
- con.Close()
- SQLCommand = "CREATE TABLE Orders(OrderID varchar(255) PRIMARY KEY, ProductID varchar(255), FOREIGN KEY (ProductID) REFERENCES Inventory(ProductID)," &
- "CustomerID varchar(255), FOREIGN KEY (CustomerID) REFERENCES Customer(CustomerID), DateofPurchase varchar(255), TimeofPurchase varchar(255))"
- con.Open()
- cmd.Connection = con
- cmd.CommandText = (SQLCommand)
- Try
- cmd.ExecuteNonQuery()
- Catch ex As Exception
- End Try
- con.Close()
- End Sub
- End Class
- Imports ADOX
- Imports System.IO
- Imports System.Data.OleDb
- Public Class Suppliers
- Dim ConnectionString As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=N:\TestDatabase.accdb;"
- Dim cat As Catalog = New Catalog()
- Dim SQLCommand As String
- Dim con As New OleDbConnection(ConnectionString)
- Dim cmd As New OleDbCommand
- Private Sub Suppliers_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
- End Sub
- 'When the add button is clicked, the supplier table is updated and the datagrid view is updated too.
- Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
- AddSupplier()
- UpdatetableS()
- End Sub
- 'This sub puts the table in the database into the datagridview
- Private Sub UpdatetableS()
- Dim ConnString As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=N:\TestDatabase.accdb;"
- Dim MyConn As OleDbConnection
- Dim ds As DataSet
- Dim tables As DataTableCollection
- Dim source1 As New BindingSource
- Dim da As OleDbDataAdapter
- MyConn = New OleDbConnection
- MyConn.ConnectionString = ConnString
- ds = New DataSet
- tables = ds.Tables
- da = New OleDbDataAdapter("Select * from [Supplier]", MyConn)
- da.Fill(ds, "Supplier")
- Dim view As New DataView(tables(0))
- source1.DataSource = view
- DatagridviewSup.DataSource = view
- End Sub
- Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpdate.Click
- UpdatetableS()
- End Sub
- ' this sub allwows the user to go back to the main menu
- Private Sub btnCustback_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCustback.Click
- If Me.Visible() Then
- Me.Close()
- Main_Menu.Show()
- End If
- End Sub
- Private Sub SeachTable()
- Dim sqlsearch As String
- sqlsearch = "SELECT * FROM Supplier WHERE SupplierID = '" & SupID.Text & "'" & " OR BusinessName = '" & supbusinessname.Text & "'" & " OR ContactName = '" & SupContactName.Text & "'" & " OR BusinessEmail = '" & SupEmailAddress.Text & "'" & " OR BusinessAddress = '" & SupAddress.Text & "'" & " OR BusinessCity = '" & SupCity.Text & "'" & " OR BusinessPostcode = '" & SupPost.Text & "'"
- ' execute the SQL statements against the dataBase
- Dim adapter As New OleDbDataAdapter(sqlsearch, con)
- ' Shows the records and updates the DataGridView
- Dim dt As New DataTable("Supplier")
- adapter.Fill(dt)
- DatagridviewSup.DataSource = dt
- End Sub
- Private Sub btnsearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsearch.Click
- SeachTable()
- End Sub
- 'This sub adds the information typed into the textboxes into a table in the database
- Private Sub AddSupplier()
- Dim con As New OleDbConnection(ConnectionString)
- Dim cmd As New OleDbCommand
- If SupID.Text = "" Or supbusinessname.Text = "" Or SupContactName.Text = "" Or SupEmailAddress.Text = "" Or SupAddress.Text = "" Or SupCity.Text = "" Or SupPost.Text = "" Then
- MsgBox("Please fill in all given fields!")
- Else
- con.Open()
- cmd.Connection = con
- cmd.CommandText = "INSERT INTO Supplier(SupplierID,BusinessName,ContactName,BusinessEmail,BusinessAddress,BusinessCity,BusinessPostcode) VALUES ('" & SupID.Text & "','" & supbusinessname.Text & "', '" & SupContactName.Text & "', '" & SupEmailAddress.Text & "','" & SupAddress.Text & "','" & SupCity.Text & "', '" & SupPost.Text & "')"
- SupID.Clear()
- supbusinessname.Clear()
- SupContactName.Clear()
- SupEmailAddress.Clear()
- SupAddress.Clear()
- SupCity.Clear()
- SupPost.Clear()
- cmd.ExecuteNonQuery()
- ' UpdateTable()
- con.Close()
- End If
- End Sub
- End Class
- Imports ADOX
- Imports System.IO
- Imports System.Data.OleDb
- Public Class orders
- Public ConnectionString As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=N:\TestDatabase.accdb;"
- Dim cat As Catalog = New Catalog()
- Dim SQLCommand As String
- Dim con As New OleDbConnection(ConnectionString)
- Dim cmd As New OleDbCommand
- Private Sub btnBack_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBack.Click
- If Me.Visible() Then
- Me.Close()
- Main_Menu.Show()
- End If
- End Sub
- Private Sub orders_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
- End Sub
- 'This sub fills the combobox with information other tables.
- Private Sub FillComboProduct()
- Dim ConnString As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=N:\TestDatabase.accdb;"
- Dim MyConn As OleDbConnection
- Dim ds As DataSet
- Dim tables As DataTableCollection
- 'Dim source1 As New BindingSource
- Dim da As OleDbDataAdapter
- MyConn = New OleDbConnection
- MyConn.ConnectionString = ConnString
- ds = New DataSet
- tables = ds.Tables
- da = New OleDbDataAdapter("SELECT ProductID from Inventory", MyConn)
- da.Fill(ds, "Inventory")
- Dim view As New DataView(tables(0))
- Try
- With cmbProduct
- .DataSource = ds.Tables("Inventory")
- .DisplayMember = "ProductID"
- .ValueMember = "productID"
- .SelectedIndex = 0
- .AutoCompleteMode = AutoCompleteMode.SuggestAppend
- .AutoCompleteSource = AutoCompleteSource.ListItems
- End With
- Catch ex As Exception
- MsgBox("No ProductID has been created")
- End Try
- End Sub
- Private Sub btnGetIDs_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGetIDs.Click
- FillComboProduct()
- FillComboCustomer()
- End Sub
- Private Sub FillComboCustomer()
- Dim ConnString As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=N:\TestDatabase.accdb;"
- Dim MyConn As OleDbConnection
- Dim ds As DataSet
- Dim tables As DataTableCollection
- Dim da As OleDbDataAdapter
- MyConn = New OleDbConnection
- MyConn.ConnectionString = ConnString
- ds = New DataSet
- tables = ds.Tables
- da = New OleDbDataAdapter("SELECT CustomerID from Customer", MyConn)
- da.Fill(ds, "Customer")
- Dim view As New DataView(tables(0))
- Try
- With cmbCustomer
- .DataSource = ds.Tables("Customer")
- .DisplayMember = "CustomerID"
- .ValueMember = "CustomerID"
- .SelectedIndex = 0
- .AutoCompleteMode = AutoCompleteMode.SuggestAppend
- .AutoCompleteSource = AutoCompleteSource.ListItems
- End With
- Catch ex As Exception
- MsgBox("No CustomerID has been created")
- End Try
- End Sub
- Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpdate.Click
- UpdateOrders()
- End Sub
- Private Sub UpdateOrders()
- Dim ConnString As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=N:\TestDatabase.accdb;"
- Dim MyConn As OleDbConnection
- Dim ds As DataSet
- Dim tables As DataTableCollection
- Dim source1 As New BindingSource
- Dim da As OleDbDataAdapter
- MyConn = New OleDbConnection
- MyConn.ConnectionString = ConnString
- ds = New DataSet
- tables = ds.Tables
- da = New OleDbDataAdapter("Select * from [Orders]", MyConn)
- da.Fill(ds, "Orders")
- Dim view As New DataView(tables(0))
- source1.DataSource = view
- DataGridView1.DataSource = view
- End Sub
- Private Sub AddOrder()
- Dim con As New OleDbConnection(ConnectionString)
- Dim cmd As New OleDbCommand
- If txtOrderID.Text = "" Or txtDateOfP.Text = "" Or cmbCustomer.Text = "" Or cmbProduct.Text = "" Then
- MsgBox("Please fill in all given fields!")
- Else
- con.Open()
- cmd.Connection = con
- cmd.CommandText = "INSERT INTO Orders(OrderID,ProductID,CustomerID,DateofPurchase,TimeofPurchase) VALUES ('" & txtOrderID.Text & "','" & cmbProduct.Text & "','" & cmbCustomer.Text & "', '" & txtDateOfP.Text & "','" & txtTimeOfP.Text & "')"
- cmd.ExecuteNonQuery()
- ' UpdateTable()
- con.Close()
- End If
- End Sub
- Private Sub btnAddOrder_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAddOrder.Click
- AddOrder()
- UpdateOrders()
- End Sub
- 'This sub allows the user to search through the table and dispays the result
- Private Sub SearchTable()
- Dim sqlsearch As String
- sqlsearch = "SELECT * FROM Order WHERE OrderID = '" & txtOrderID.Text & "'" & " OR ProductID = '" & cmbProduct.Text & "'" & " OR CustomerID = '" & cmbCustomer.Text & "');" & " OR DateofPurchase = '" & txtDateOfP.Text & "'" & " OR TimeofPurchase = '" & txtTimeOfP.Text & "'"
- ' execute the SQL statements against the dataBase
- Dim adapter As New OleDbDataAdapter(sqlsearch, con)
- ' Shows the records and updates the DataGridView
- Dim dt As New DataTable("Order")
- adapter.Fill(dt)
- DataGridView1.DataSource = dt
- End Sub
- Private Sub btnSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSearch.Click
- SearchTable()
- End Sub
- Private Sub TimeDate()
- txtTimeOfP.Text = Now.ToShortDateString
- txtDateOfP.Text = Now.ToShortTimeString
- End Sub
- Private Sub txtDateOfP_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtDateOfP.TextChanged
- End Sub
- Private Sub TimenDate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TimenDate.Click
- TimeDate()
- End Sub
- 'Grade B (writing to a file)
- Private Sub PrintToFile()
- ' This goes through the rows and columns of the datagridview and then turns into string and tthen adds it the text file.
- Dim file As TextWriter = New StreamWriter("N:\Orders.txt")
- For i As Integer = 0 To DataGridView1.Rows.Count - 2 Step +1
- For j As Integer = 0 To DataGridView1.Columns.Count - 1 Step +1
- file.Write(vbTab & DataGridView1.Rows(i).Cells(j).Value.ToString() & vbTab & "|")
- Next
- file.WriteLine("")
- file.WriteLine("-----------------------------------------------------------------------------------------------------------")
- Next
- file.Close()
- MessageBox.Show("Data Exported")
- End Sub
- ' This sub checks whether the datagrid is empty and if it is, it will tell the user.
- Private Sub btnPrint_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrint.Click
- If DataGridView1.Rows.Count > 0 Then
- PrintToFile()
- Else
- MsgBox("Please fill/update the table to continue.")
- End If
- End Sub
- End Class
- Imports ADOX
- Imports System.IO
- Imports System.Data.OleDb
- Public Class Customer
- Dim ConnectionString As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=N:\TestDatabase.accdb;"
- Dim cat As Catalog = New Catalog()
- Dim SQLCommand As String
- Dim con As New OleDbConnection(ConnectionString)
- Dim cmd As New OleDbCommand
- Private Sub Customer_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
- End Sub
- Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
- Addrow()
- UpdateTable()
- End Sub
- Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpdate.Click
- UpdateTable()
- End Sub
- 'This sub gets the latest version of the table from te database and puts it into the datagrid view. It selects every column from the table.
- Private Sub UpdateTable()
- Dim ConnString As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=N:\TestDatabase.accdb;"
- Dim MyConn As OleDbConnection
- Dim ds As DataSet
- Dim tables As DataTableCollection
- Dim source1 As New BindingSource
- Dim da As OleDbDataAdapter
- MyConn = New OleDbConnection
- MyConn.ConnectionString = ConnString
- ds = New DataSet
- tables = ds.Tables
- da = New OleDbDataAdapter("Select * from [Customer]", MyConn)
- da.Fill(ds, "Customer")
- Dim view As New DataView(tables(0))
- source1.DataSource = view
- custdatagrid.DataSource = view
- End Sub
- Private Sub SearchTable()
- 'SQL Statement so our User can search for either CustomerID or FirstName
- Dim sqlsearch As String
- sqlsearch = "SELECT * FROM Customer WHERE CustomerID = '" & CustID.Text & "'" & " OR FirstName = '" & CustFirstName.Text & "'" & " OR LastName = '" & CustSecondName.Text & "'" & " OR Email = '" & CustEmailAddress.Text & "'" & " OR LastName = '" & CustSecondName.Text & "'" & " OR Address = '" & CustHomeAddress.Text & "'" & " OR City = '" & CustCity.Text & "'" & " OR Postcode = '" & CustPost.Text & "'"
- ' execute the SQL statements against the dataBase
- Dim adapter As New OleDbDataAdapter(sqlsearch, con)
- ' Shows the records and updates the DataGridView
- Dim dt As New DataTable("Customer")
- adapter.Fill(dt)
- custdatagrid.DataSource = dt
- End Sub
- Private Sub btnsearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsearch.Click
- SearchTable()
- End Sub
- Private Sub btnCustback_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCustback.Click
- If Me.Visible() Then
- Me.Close()
- Main_Menu.Show()
- End If
- End Sub
- 'This sub deletes the selected row from the datagrid view table and also deletes it from the table in the database.
- Private Sub DeleteRow()
- Dim con As New OleDbConnection(ConnectionString)
- Dim cmd As New OleDbCommand
- con.Open()
- cmd.Connection = con
- cmd.CommandText = "DELETE * from [Customer] where CustomerID = '" & custdatagrid.SelectedRows(0).Cells(0).Value.ToString() & "'"
- cmd.ExecuteNonQuery()
- UpdateTable()
- con.Close()
- End Sub
- Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
- DeleteRow()
- End Sub
- Private Sub Addrow()
- Dim con As New OleDbConnection(ConnectionString)
- Dim cmd As New OleDbCommand
- If CustFirstName.Text = "" Or CustSecondName.Text = "" Or CustEmailAddress.Text = "" Or CustHomeAddress.Text = "" Or CustCity.Text = "" Or CustPostcode.Text = "" Then
- MsgBox("Please fill in all given fields!")
- Else
- con.Open()
- cmd.Connection = con
- cmd.CommandText = "INSERT INTO Customer(CustomerID,FirstName,LastName,Email,Address,City,Postcode) VALUES ('" & CustID.Text & "','" & CustFirstName.Text & "', '" & CustSecondName.Text & "', '" & CustEmailAddress.Text & "','" & CustHomeAddress.Text & "','" & CustCity.Text & "', '" & CustPost.Text & "')"
- CustID.Clear()
- CustFirstName.Clear()
- CustSecondName.Clear()
- CustEmailAddress.Clear()
- CustHomeAddress.Clear()
- CustCity.Clear()
- CustPost.Clear()
- cmd.ExecuteNonQuery()
- UpdateTable()
- con.Close()
- End If
- End Sub
- ' This puts all the firstnames into an array and sorts it.
- Public Sub SortName()
- Dim n As Integer = 0
- Dim i As Integer = -1
- Dim Reader As OleDbDataReader
- SQLCommand = "SELECT FirstName FROM Customer"
- con.Open()
- cmd.Connection = con
- cmd.CommandText = (SQLCommand)
- Reader = cmd.ExecuteReader
- Do While Reader.Read()
- i = i + 1
- Loop
- con.Close()
- Dim ArrayFirstname(i) As String
- SQLCommand = "SELECT FirstName FROM Customer"
- con.Open()
- cmd.Connection = con
- cmd.CommandText = (SQLCommand)
- Reader = cmd.ExecuteReader
- Do While Reader.Read()
- ArrayFirstname = (Reader("FirstName"))
- n = n + 1
- Loop
- con.Close()
- MsgBox(ErrorToString)
- MergeSort(ArrayFirstname)
- For m = 0 To UBound(ArrayFirstname)
- custdatagrid.Rows.Item(m).Cells(i).Value = ArrayFirstname(m)
- Next
- For j = 0 To UBound(ArrayFirstname)
- SQLCommand = "SELECT CustomerID,LastName,Email,Address,City,Postcode FROM Customer WHERE FirstName = '" & ArrayFirstname(j) & "'"
- con.Open()
- cmd.Connection = con
- cmd.CommandText = (SQLCommand)
- Reader = cmd.ExecuteReader
- Do While Reader.Read()
- custdatagrid.Rows.Item(j).Cells(0).Value = (Reader("CustomerID"))
- custdatagrid.Rows.Item(j).Cells(0).Value = (Reader("LastName"))
- custdatagrid.Rows.Item(j).Cells(0).Value = (Reader("Email"))
- custdatagrid.Rows.Item(j).Cells(0).Value = (Reader("Address"))
- custdatagrid.Rows.Item(j).Cells(0).Value = (Reader("City"))
- custdatagrid.Rows.Item(j).Cells(0).Value = (Reader("Postcode"))
- Loop
- Next
- End Sub
- 'Grade A
- Public Sub MergeSort(ByRef data1 As String())
- Dim Csize As Integer
- Dim L As Integer
- Csize = 1
- While Csize <= data1.Length - 1
- L = 0
- While Left < data1.Length - 1
- Dim Mid As Integer = L + Csize - 1
- Dim Right As Integer = Math.Min(Left + 2 * Csize - 1, data1.Length - 1)
- Merge(data1, L, Mid, Right)
- L += 2 * Csize
- End While
- Csize = 2 * Csize
- End While
- End Sub
- Private Sub btnMergeSort_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMergeSort.Click
- SortName()
- End Sub
- ' Compares the items and outs them in order
- Private Sub Merge(ByRef data1 As String(), ByVal L As Integer, ByVal Mid As Integer, ByVal right As Integer)
- Dim i As Integer
- Dim j As Integer
- Dim k As Integer
- Dim Nom1 As String = Mid - L + 1
- Dim Nom2 As String = right - Mid
- Dim leftpointer As String() = New String(Nom1 - 1) {}
- Dim rightpointer As String() = New String(Nom2 - 1) {}
- For i = 0 To Nom1 - 1
- leftpointer(i) = data1(L - i)
- Next
- For j = 0 To Nom2 - 1
- rightpointer(j) = data1(Mid + 1 + j)
- Next
- i = 0
- j = 0
- k = L
- While i < Nom1 AndAlso j < Nom2
- If leftpointer(i) <= rightpointer(j) Then
- data1(k) = leftpointer(i)
- i += 1
- Else
- data1(k) = rightpointer(j)
- j += 1
- End If
- k += 1
- End While
- While i < Nom1
- data1(k) = leftpointer(i)
- i += 1
- k += 1
- End While
- While j < Nom2
- data1(k) = rightpointer(j)
- j += 1
- k += 1
- End While
- End Sub
- End Class
- Imports ADOX
- Imports System.IO
- Imports System.Data.OleDb
- Public Class Inventory
- Dim ConnectionString As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=N:\TestDatabase.accdb;"
- Dim cat As Catalog = New Catalog()
- Dim SQLCommand As String
- Dim con As New OleDbConnection(ConnectionString)
- Dim cmd As New OleDbCommand
- Private Sub Orders_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
- End Sub
- Private Sub btnCustback_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCustback.Click
- If Me.Visible Then
- Me.Hide()
- Main_Menu.Show()
- End If
- End Sub
- Private Sub ComboBoxsupplier_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBoxsupplier.SelectedIndexChanged
- End Sub
- Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
- UpdateTable()
- AddInventory()
- End Sub
- Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpdate.Click
- UpdateTable()
- End Sub
- Private Sub UpdateTable()
- Dim ConnString As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=N:\TestDatabase.accdb;"
- Dim MyConn As OleDbConnection
- Dim ds As DataSet
- Dim tables As DataTableCollection
- Dim source1 As New BindingSource
- Dim da As OleDbDataAdapter
- MyConn = New OleDbConnection
- MyConn.ConnectionString = ConnString
- ds = New DataSet
- tables = ds.Tables
- da = New OleDbDataAdapter("Select * from [Inventory]", MyConn)
- da.Fill(ds, "Inventory")
- Dim view As New DataView(tables(0))
- source1.DataSource = view
- Datagridview.DataSource = view
- End Sub
- Private Sub GetSupplierID_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GetSupplierID.Click
- FillCombo()
- End Sub
- Private Sub btnCreate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
- End Sub
- ' This sub fills the combo box/drop drop down
- Private Sub FillCombo()
- Dim ConnString As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=N:\TestDatabase.accdb;"
- Dim MyConn As OleDbConnection
- Dim ds As DataSet
- Dim tables As DataTableCollection
- 'Dim source1 As New BindingSource
- Dim da As OleDbDataAdapter
- MyConn = New OleDbConnection
- MyConn.ConnectionString = ConnString
- ds = New DataSet
- tables = ds.Tables
- da = New OleDbDataAdapter("SELECT SupplierID from Supplier", MyConn)
- da.Fill(ds, "Supplier")
- Dim view As New DataView(tables(0))
- Try
- With ComboBoxsupplier
- .DataSource = ds.Tables("Supplier")
- .DisplayMember = "SupplierID"
- .ValueMember = "SupplierID"
- .SelectedIndex = 0
- .AutoCompleteMode = AutoCompleteMode.SuggestAppend
- .AutoCompleteSource = AutoCompleteSource.ListItems
- End With
- Catch ex As Exception
- MsgBox("No SupplierID created")
- End Try
- End Sub
- Private Sub btnsearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsearch.Click
- searchtable()
- End Sub
- ' This sub searches for records in a table.
- Private Sub searchtable()
- Dim sqlsearch As String
- sqlsearch = "SELECT * FROM Inventory WHERE ProductID = '" & ItemID.Text & "'" & " OR ProductName = '" & ItemName.Text & "'" & " OR ItemPrice = '" & ProductPrice.Text & "'" & " OR ItemCost = '" & ProductCost.Text & "'" & " OR ItemQuantity = '" & ProductQuantity.Text & "'"
- ' execute the SQL statements against the dataBase
- Dim adapter As New OleDbDataAdapter(sqlsearch, con)
- ' Shows the records and updates the DataGridView
- Dim dt As New DataTable("Inventory")
- adapter.Fill(dt)
- Datagridview.DataSource = dt
- End Sub
- ' This sub adds data from the textbox into the table.
- Private Sub AddInventory()
- Dim con As New OleDbConnection(ConnectionString)
- Dim cmd As New OleDbCommand
- If ItemID.Text = "" Or ItemName.Text = "" Or ProductCost.Text = "" Or ProductPrice.Text = "" Or ProductQuantity.Text = "" Or ComboBoxsupplier.Text = "" Then
- MsgBox("Please fill in all given fields!")
- Else
- con.Open()
- cmd.Connection = con
- cmd.CommandText = "INSERT INTO Inventory(ProductID,ProductName,ItemCost,ItemPrice,ItemQuantity,SupplierID) VALUES ('" & ItemID.Text & "','" & ItemName.Text & "', '" & ProductCost.Text & "', '" & ProductPrice.Text & "','" & ProductQuantity.Text & "','" & ComboBoxsupplier.Text & "')"
- ItemID.Clear()
- ItemName.Clear()
- ProductCost.Clear()
- ProductPrice.Clear()
- ProductQuantity.Clear()
- cmd.ExecuteNonQuery()
- ' UpdateTable()
- con.Close()
- End If
- End Sub
- End Class
Add Comment
Please, Sign In to add comment