Sunteți pe pagina 1din 9

Public Class Form1

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles


btnconnect.Click

objconn.ConnectionString = "Server=" & txtserver.Text & ";" _

& "User ID=" & txtuserid.Text & ";" _

& "Password=" & txtpassword.Text & ";" _

& "database=db_gino"

Try

objconn.Open()

MsgBox("You Are Connected!")

objconn.Close()

Catch ex As Exception

MsgBox(ex.Message)

End Try

Form2.Show()

Me.Hide()

End Sub

End Class
Public Class Form2

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles


btnlogin.Click

strsql = "SELECT Username, Password FROM tbl_login WHERE Username= @field1


AND Password= @field2"

objcmd = New MySql.Data.MySqlClient.MySqlCommand(strsql, objconn)

With objcmd

.Parameters.AddWithValue("@field1", txtusername.Text)

.Parameters.AddWithValue("@field2", txtpassword.Text)

End With

objconn.Open()

objcmd.ExecuteNonQuery()

objdr = objcmd.ExecuteReader

If (objdr.Read()) Then

MsgBox("You Have Successfully Login !")

objcmd.Dispose()

objdr.Close()

Form3.Show()

Me.Close()

Else

MsgBox("Error Username or Password !")

End If

objcmd.Dispose()
objdr.Close()

End Sub

End Class

Public Class Form3

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles


Button1.Click

Form4.Show()

End Sub

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles


Button2.Click

Form5.Show()

End Sub

Private Sub Button3_Click(sender As Object, e As EventArgs) Handles


Button3.Click

Form6.Show()
End Sub

Private Sub Button4_Click(sender As Object, e As EventArgs) Handles


Button4.Click

Form7.Show()

End Sub

Private Sub Button6_Click(sender As Object, e As EventArgs) Handles


Button6.Click

Form8.Show()

End Sub

Private Sub Button5_Click(sender As Object, e As EventArgs) Handles


Button5.Click

Application.Exit()

End Sub

End Class
Public Class Form4

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles


Button1.Click

strsql = "INSERT INTO tbl_product (Product,Price) VALUES (@field1,@field2)"

objcmd = New MySql.Data.MySqlClient.MySqlCommand(strsql, objconn)

With objcmd

.Parameters.AddWithValue("@field1", TextBox1.Text)

.Parameters.AddWithValue("@field2", TextBox2.Text)

End With

objcmd.ExecuteNonQuery()

objcmd.Dispose()

MsgBox("Record Added!")

Me.filllistview()
Dim ab = MsgBox("Register another one?", vbYesNo)

If ab = vbYes Then

TextBox1.Text = ""

TextBox2.Text = ""

TextBox1.Focus()

Else

TextBox1.Text = ""

TextBox2.Text = ""

End If

End Sub

Sub filllistview()

Try

ListView1.Items.Clear()

strsql = "SELECT * FROM tbl_product ORDER BY Product ASC"

objcmd = New MySql.Data.MySqlClient.MySqlCommand(strsql, objconn)

objdr = objcmd.ExecuteReader

While (objdr.Read())

With ListView1.Items.Add(objdr("Product"))

.subitems.add(objdr("Price"))

End With

End While

objcmd.Dispose()

objdr.Close()

Catch ex As Exception

MsgBox(ex.Message)

Me.filllistview()

End Try

End Sub

Private Sub Form4_Load(sender As Object, e As EventArgs) Handles MyBase.Load

Me.filllistview()

ListView1.View = View.Details

End Sub
Private Sub ListView1_MouseClick(sender As Object, e As MouseEventArgs) Handles
ListView1.MouseClick

With ListView1.SelectedItems(0)

TextBox1.Text = .SubItems(0).Text

TextBox2.Text = .SubItems(1).Text

End With

End Sub

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles


Button2.Click

objcmd = objconn.CreateCommand()

objcmd.CommandText = "UPDATE tbl_product SET Price=@field2 WHERE


Product=@field1"

With objcmd

.Parameters.AddWithValue("@field1", TextBox1.Text)

.Parameters.AddWithValue("@field2", TextBox2.Text)

objcmd.ExecuteNonQuery()

filllistview()

MsgBox("Update Record!")

TextBox1.Text = ""

TextBox2.Text = ""

TextBox1.Focus()

End With

End Sub

Private Sub Button3_Click(sender As Object, e As EventArgs) Handles


Button3.Click

objcmd = objconn.CreateCommand()

objcmd.CommandText = "DELETE FROM tbl_product WHERE Product=@field1"

With objcmd

.Parameters.AddWithValue("@field1", TextBox1.Text)

objcmd.ExecuteNonQuery()

filllistview()

MsgBox("Delete Record!")

TextBox1.Text = ""

TextBox2.Text = ""
TextBox1.Focus()

End With

End Sub

Private Sub TextBox3_TextChanged(sender As Object, e As EventArgs) Handles


TextBox3.TextChanged

Try

ListView1.Refresh()

ListView1.Items.Clear()

strsql = "SELECT * FROM tbl_product WHERE Product LIKE @field1 '%'"

objcmd = New MySql.Data.MySqlClient.MySqlCommand(strsql, objconn)

With objcmd

.Parameters.AddWithValue("@field1", TextBox3.Text)

End With

objdr = objcmd.ExecuteReader

While (objdr.Read())

With ListView1.Items.Add(objdr("Product"))

.subitems.add(objdr("Price"))

End With

End While

objcmd.Dispose()

objdr.Close()

Catch ex As Exception

MsgBox(ex.Message)

Me.filllistview()

End Try

End Sub

Private Sub Button4_Click(sender As Object, e As EventArgs) Handles


Button4.Click

Form3.Show()

Me.Hide()

End Sub
End Class

S-ar putea să vă placă și