Projeto

Sergii

Power Member
Boas tou com este projeto em mãos onde dinamicamente cria butoes conforme a data na database
Exemplo : Entradas -> Rissois -> que depois vai para uma datagrid view com as colunas

1= Produto
2= Quantidade
3= Preço

Eu tenho este pedaço de codigo que ele vai ver se o produto clickado existe na datagridview e vai aumentar +1 a quantidade e por si mesmo o preço :

Public Shared Sub btn_clicks(sender As Object, e As EventArgs)
Dim btn As Button = CType(sender, Button)
Dim dr As OleDb.OleDbDataReader
Dim cm As New OleDb.OleDbCommand
Dim cj As New OleDb.OleDbConnection
Dim texto As String = btn.Text


With cj
.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & Application.StartupPath & "\bddacess.accdb"
.Open()

End With



Try
With cm
.Connection = cj
.CommandType = CommandType.Text
.CommandText = "SELECT * FROM TblProd where (Descrição) ='" & texto & "'"
dr = .ExecuteReader

While dr.Read()

Dim Found As Boolean = False
Dim total As Double = (Convert.ToDouble(dr("Preço")))

If (Form1.DataGridView1.Rows.Count > 0) Then
'Check if the product Name exists with the same Price
For Each row As DataGridViewRow In Form1.DataGridView1.Rows
If ((Convert.ToString(row.Cells(0).Value) = texto) _
AndAlso (Convert.ToString(row.Cells(2).Value) = dr("Preço"))) Then
'Update the Quantity of the found row
row.Cells(1).Value = Convert.ToString((x + Convert.ToInt16(row.Cells(1).Value)))
row.Cells(3).Value = (Convert.ToDouble(row.Cells(1).Value) * Convert.ToDouble(row.Cells(2).Value))
Found = True
End If

Next
If Not Found Then
'Add the row to DataGridView if data not present
Form1.DataGridView1.Rows.Add(texto, 1, dr("Preço"), total)
End If

Else
'Add the first row to DataGridView if there is no row
Form1.DataGridView1.Rows.Add(texto, 1, dr("Preço"), total)
End If


End While



End With

Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub



Depois se me puderem ajudar nisto e noutra coisa que é transformar os dados da datagridview em uma recibo/fatura .
Obrigado a todos que responderem
 
Back
Topo