Вы находитесь на странице: 1из 15

Imports MySql.Data.

MySqlClient
Public Class adminform
Dim sqladapter As New MySqlDataAdapter
Dim sqlcommand As New MySqlCommand
Dim table As New DataTable
Dim dr As MySqlDataReader
Public con As New MySqlConnection
'listview
Dim id As Integer

'Updating data
Friend ProductID As Integer
Friend pname As String
Friend ProductDescription As String
Friend Unit As Integer
Friend stocks As Integer
Friend ExpirationDate As String

'Form 'Declare the variables


Dim drag As Boolean
Dim mousex As Integer
Dim mousey As Integer

Private Sub Form1_MouseDown(sender As Object, e As MouseEventArgs) Handles


MyBase.MouseDown
'MouseDown
drag = True 'Sets the variable drag to true.
mousex = System.Windows.Forms.Cursor.Position.X - Me.Left 'Sets variable
mousex

mousey = System.Windows.Forms.Cursor.Position.Y - Me.Top 'Sets variable


mousey
End Sub

Private Sub Form1_MouseMove(sender As Object, e As MouseEventArgs) Handles


MyBase.MouseMove
'MouseMove
'If drag is set to true then move the form accordingly.
If drag Then
Me.Top = System.Windows.Forms.Cursor.Position.Y - mousey
Me.Left = System.Windows.Forms.Cursor.Position.X - mousex
End If
End Sub

Private Sub Form1_MouseUp(sender As Object, e As MouseEventArgs) Handles


MyBase.MouseUp

'MouseUp(ByVal sender As Object, ByVal e As


System.Windows.Forms.MouseEventArgs) Handles Me.MouseUp
drag = False 'Sets drag to false, so the form does not move according to the
code in MouseMove

End Sub
Private Sub Bminimized_Click(sender As Object, e As EventArgs) Handles
Bminimized.Click
Me.WindowState = FormWindowState.Minimized
End Sub
Private Sub Bminimized_MouseDown(sender As Object, e As MouseEventArgs)
Handles Bminimized.MouseDown
Bminimized.BackColor = Color.DarkSlateGray
End Sub

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


Bminimized.MouseEnter
Bminimized.BackColor = Color.Teal
End Sub

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


Bminimized.MouseLeave
Bminimized.BackColor = Color.DarkCyan
End Sub

Private Sub Lminimized_MouseUp(sender As Object, e As MouseEventArgs)


Handles Bminimized.MouseUp
Bminimized.BackColor = Color.Teal
End Sub

Private Sub back_MouseDown(sender As Object, e As MouseEventArgs) Handles


Back.MouseDown
Back.BackgroundImage = My.Resources.back2
End Sub

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


Back.MouseEnter
Back.BackgroundImage = My.Resources.back1
End Sub

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


Back.MouseLeave
Back.BackgroundImage = My.Resources.back1
End Sub

Private Sub back_MouseUp(sender As Object, e As MouseEventArgs) Handles


Back.MouseUp

Back.BackgroundImage = My.Resources.back1
End Sub

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


MyBase.Load
If con.State = ConnectionState.Closed Then
con.ConnectionString = "host=localhost; username=root; password=root;
database=farmacia_estabillo"
con.Open()
End If
LoadProduct()

Idnumber.Text = ProductID
ComboBox1.Text = pname
Pdescription.Text = ProductDescription
Punit.Text = Unit
Pquantity.Text = stocks
Pexpiration.Text = ExpirationDate
End Sub
''//// load product
Public Sub LoadProduct()
Dim sqlQuery As String = "SELECT * FROM tbl_product"
Dim sqladapter As New MySqlDataAdapter
Dim sqlcommand As New MySqlCommand
Dim table As New DataTable
Dim i As Integer

With sqlcommand
.CommandText = sqlQuery

.Connection = con
End With

With sqladapter
.SelectCommand = sqlcommand
.Fill(table)
End With

ListProduct.Items.Clear()

For i = 0 To table.Rows.Count - 1
With ListProduct
.Items.Add(table.Rows(i)("ProductID"))
With .Items(.Items.Count - 1).SubItems
.Add(table.Rows(i)("ProductName"))
.Add(table.Rows(i)("ProductDescription"))
.Add(table.Rows(i)("Unit"))
.Add(table.Rows(i)("Quantity"))
.Add(table.Rows(i)("price"))
.Add(table.Rows(i)("ExpirationDate"))
End With
End With
Next
End Sub

Private Sub ProductToolStripMenuItem_Click(sender As Object, e As EventArgs)


Handles ProductToolStripMenuItem.Click
FormPanel.Visible = True
End Sub

Private Sub Back_Click(sender As Object, e As EventArgs) Handles Back.Click


FormPanel.Visible = False
End Sub

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


ListProduct.Click
'listview /add/update/delete
id = ListProduct.SelectedItems(0).Text
Idnumber.Text = ListProduct.SelectedItems.Item(0).SubItems(0).Text
ComboBox1.Text = ListProduct.SelectedItems.Item(0).SubItems(1).Text
Pdescription.Text = ListProduct.SelectedItems.Item(0).SubItems(2).Text
Punit.Text = ListProduct.SelectedItems.Item(0).SubItems(3).Text
Pquantity.Text = ListProduct.SelectedItems.Item(0).SubItems(4).Text
Pprice.Text = ListProduct.SelectedItems.Item(0).SubItems(5).Text
Pexpiration.Text = ListProduct.SelectedItems.Item(0).SubItems(6).Text

BCancel.Enabled = True
Badd.Enabled = False
BDelete.Enabled = True
Bupdate.Enabled = True
End Sub

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


BCancel.Click
Idnumber.Clear()
ComboBox1.Text = "Select"
Pdescription.Clear()
Punit.Clear()
Pquantity.Clear()

Pprice.Clear()
Pexpiration.Clear()

BCancel.Enabled = False
Badd.Enabled = True
BDelete.Enabled = True
Bupdate.Enabled = False
End Sub

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


Bupdate.Click
'Update()

If ComboBox1.Text = "" Then


ErrorProviderselect.SetError(Me.ComboBox1, "Select")

ElseIf Pdescription.Text = "" Then


ErrorProviderdes.SetError(Me.Pdescription, "Enter Description")

ElseIf Punit.Text = "" Then


ErrorProviderUnit.SetError(Me.Punit, "Enter the right Unit")

ElseIf Pquantity.Text = "" Then


ErrorProviderQtty.SetError(Me.Pquantity, "Enter Quantity")

ElseIf Pprice.Text = "" Then


ErrorProviderPrice.SetError(Me.Pprice, "Enter Price")

ElseIf Pexpiration.Text = "" Then


ErrorProviderExpiration.SetError(Me.Pexpiration, "Enter Expiration Date")

Else
Dim i As New Integer
With sqlcommand
.Connection = con
.CommandText = "Update tbl_product SET ProductName='" &
ComboBox1.Text & "' ,ProductDescription='" & Pdescription.Text &
"' ,Unit='" & Punit.Text & "' ,Quantity='" & Pquantity.Text & "' ,price='" &
Pprice.Text & "' ,ExpirationDate='" & Pexpiration.Text &
"' WHERE ProductID=" & id & ""
i = .ExecuteNonQuery()
End With
ErrorProviderselect.SetError(Me.ComboBox1, "")
ErrorProviderdes.SetError(Me.Pdescription, "")
ErrorProviderUnit.SetError(Me.Punit, "")
ErrorProviderQtty.SetError(Me.Pquantity, "")
ErrorProviderPrice.SetError(Me.Pprice, "")
ErrorProviderExpiration.SetError(Me.Pexpiration, "")
MsgBox("Update new Record")
LoadProduct()
End If
End Sub

Private Sub Badd_Click(sender As Object, e As EventArgs) Handles Badd.Click


'add product

If ComboBox1.Text = "" Then


ErrorProviderselect.SetError(Me.ComboBox1, "Select")

ElseIf Pdescription.Text = "" Then

ErrorProviderdes.SetError(Me.Pdescription, "Enter Description")

ElseIf Punit.Text = "" Then


ErrorProviderUnit.SetError(Me.Punit, "Enter the right Unit")

ElseIf Pquantity.Text = "" Then


ErrorProviderQtty.SetError(Me.Pquantity, "Enter Quantity")

ElseIf Pprice.Text = "" Then


ErrorProviderPrice.SetError(Me.Pprice, "Enter Price")

ElseIf Pexpiration.Text = "" Then


ErrorProviderExpiration.SetError(Me.Pexpiration, "Enter Expiration Date")
Else
Dim i As New Integer
With sqlcommand
.Connection = con
.CommandText = "INSERT INTO tbl_product(ProductName,
PRoductDescription, Unit, Quantity, price, ExpirationDate) VALUES ('" &
ComboBox1.Text &
"','" & Pdescription.Text & "','" & Punit.Text & "','" & Pquantity.Text &
"','" & Pprice.Text & "','" & Pexpiration.Text & "')"
i = .ExecuteNonQuery()
End With
ErrorProviderselect.SetError(Me.ComboBox1, "")
ErrorProviderdes.SetError(Me.Pdescription, "")
ErrorProviderUnit.SetError(Me.Punit, "")
ErrorProviderQtty.SetError(Me.Pquantity, "")
ErrorProviderPrice.SetError(Me.Pprice, "")
ErrorProviderExpiration.SetError(Me.Pexpiration, "")
MsgBox("Add New Record", MsgBoxStyle.Information, "Success")

LoadProduct()
End If
End Sub

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


BDelete.Click
'delete
If id = IsNothing(id) Then
MsgBox("Select Item to Delete.")
Else
Dim i As New Integer
With sqlcommand
.Connection = con
.CommandText = "DELETE FROM tbl_product WHERE ProductID='" & id &
"'"
i = .ExecuteNonQuery()

End With
LoadProduct()
MsgBox("Item deleted successfully", MsgBoxStyle.Information)
End If
End Sub

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


Bsearch.Click
If Tsearch.Text = "" Then

Else

Dim sqlQuery As String = "SELECT * FROM tbl_product WHERE


ProductDescription LIKE '" & Tsearch.Text & "%' "

Dim sqladapter As New MySqlDataAdapter


Dim sqlcommand As New MySqlCommand
Dim table As New DataTable
Dim i As Integer

With sqlcommand
.CommandText = sqlQuery
.Connection = con
End With

With sqladapter
.SelectCommand = sqlcommand
.Fill(table)
End With

ListProduct.Items.Clear()

For i = 0 To table.Rows.Count - 1
With ListProduct
.Items.Add(table.Rows(i)("ProductID"))
With .Items(.Items.Count - 1).SubItems
.Add(table.Rows(i)("ProductName"))
.Add(table.Rows(i)("ProductDescription"))
.Add(table.Rows(i)("Unit"))
.Add(table.Rows(i)("Quantity"))
.Add(table.Rows(i)("price"))
.Add(table.Rows(i)("ExpirationDate"))
End With
End With
Next

End If
End Sub

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


Tsearch.TextChanged
Dim sqlQuery As String = "SELECT * FROM tbl_product WHERE
ProductDescription LIKE '" & Tsearch.Text & "%' "
Dim sqladapter As New MySqlDataAdapter
Dim sqlcommand As New MySqlCommand
Dim table As New DataTable
Dim i As Integer

With sqlcommand
.CommandText = sqlQuery
.Connection = con
End With

With sqladapter
.SelectCommand = sqlcommand
.Fill(table)
End With

ListProduct.Items.Clear()

For i = 0 To table.Rows.Count - 1
With ListProduct
.Items.Add(table.Rows(i)("ProductID"))
With .Items(.Items.Count - 1).SubItems
.Add(table.Rows(i)("ProductName"))
.Add(table.Rows(i)("ProductDescription"))

.Add(table.Rows(i)("Unit"))
.Add(table.Rows(i)("Quantity"))
.Add(table.Rows(i)("price"))
.Add(table.Rows(i)("ExpirationDate"))
End With
End With
Next
End Sub

Private Sub logout_Click(sender As Object, e As EventArgs) Handles logout.Click


Me.Close()
Login.Show()
End Sub

Private Sub ListProduct_MouseClick(sender As Object, e As MouseEventArgs)


Handles ListProduct.MouseClick
id = ListProduct.SelectedItems(0).Text
End Sub

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


Pdescription.TextChanged
'button and text validation
If (Pdescription.Text Is Nothing Or Pdescription.Text().Length < 1) Then
BCancel.Enabled = False
ElseIf (Not System.IO.Directory.Exists(Pdescription.Text)) Then
BCancel.Enabled = True
ErrorProviderdes.SetError(Me.Pdescription, "")
Tsearch.BackColor = Color.White
Bsearch.BackColor = Color.White
ElseIf (System.IO.Directory.Exists(Pdescription.Text)) Then

BCancel.Enabled = True
ErrorProviderdes.SetError(Me.Pdescription, "")
Tsearch.BackColor = Color.White
Bsearch.BackColor = Color.White
End If
End Sub

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


ComboBox1.TextChanged
If (ComboBox1.Text Is Nothing Or ComboBox1.Text().Length < 1) Then
BCancel.Enabled = False
ElseIf (Not System.IO.Directory.Exists(Pdescription.Text)) Then
BCancel.Enabled = True
ErrorProviderselect.SetError(Me.ComboBox1, "")
ElseIf (System.IO.Directory.Exists(ComboBox1.Text)) Then
BCancel.Enabled = True
ErrorProviderselect.SetError(Me.ComboBox1, "")
End If
End Sub

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


Punit.TextChanged
If (Punit.Text Is Nothing Or Punit.Text().Length < 1) Then
BCancel.Enabled = False
ElseIf (Not System.IO.Directory.Exists(Punit.Text)) Then
BCancel.Enabled = True
ErrorProviderUnit.SetError(Me.Punit, "")
ElseIf (System.IO.Directory.Exists(Punit.Text)) Then
BCancel.Enabled = True
ErrorProviderUnit.SetError(Me.Punit, "")

End If
End Sub
End Class

Вам также может понравиться