Public Class frmQuittung
Dim dtProdukt As New DataTable
Dim bsProdukt As New BindingSource
Dim WithEvents dgvProdukt As New DataGridView With _
{.Parent = Me, .DataSource = bsProdukt, .Width = 300, .Height = 300}
Dim dtKunde As New DataTable
Dim bsKunde As New BindingSource
Dim dgvKunde As New DataGridView With _
{.Parent = Me, .DataSource = bsKunde, _
.Left = 310, .Width = 300, .Height = 300}
Dim dtQuittung As New DataTable
Dim bsQuittung As New BindingSource
Dim dgvQuittung As New DataGridView With _
{.Parent = Me, .DataSource = bsQuittung, _
.Top = 310, .Left = 310, .Width = 300, .Height = 300}
Dim lblStück As New Label With _
{.Parent = Me, .Text = "Stückzahl: ", .Top = 310, .Width = 100}
Dim WithEvents txtStück As New TextBox With _
{.Parent = Me, .Top = 310, .Left = 210}
Private Sub frmQuittung_Load(sender As System.Object, _
e As System.EventArgs) Handles MyBase.Load
Me.Width = 660 : Me.Height = 600
'Diese Daten kämen aus der Datenbank
With dtProdukt
With .Columns
.Add("ID", GetType(Integer))
.Add("Produkt", GetType(String))
.Add("Größe", GetType(String))
.Add("Preis", GetType(Decimal))
End With
.Rows.Add(1, "Firestone", "185 x 17", 120)
.Rows.Add(2, "Firestone", "195 x 17", 110.95)
.Rows.Add(3, "Firestone", "215 x 17", 167.5)
.Rows.Add(4, "Continatal", "185 x 17", 88.12)
.Rows.Add(5, "Continatal", "235 x 17", 95.2)
End With
'Diese Daten kämen aus der Datenbank
With dtKunde
.Columns.Add("ID", GetType(Integer))
.Columns.Add("Name", GetType(String))
With .Rows
.Add(1, "Hans Raser")
.Add(2, "Norman Quietsch")
.Add(3, "Schmidtchen Schleicher")
.Add(4, "Franz Daimler")
.Add(5, "Sebastian Zettel")
End With
End With
With dtQuittung
.Columns.Add("Kunde", GetType(String))
.Columns.Add("Produkt", GetType(String))
.Columns.Add("Stück", GetType(Integer))
.Columns.Add("Preis", GetType(Decimal))
End With
bsKunde.DataSource = dtKunde
bsProdukt.DataSource = dtProdukt
bsQuittung.DataSource = dtQuittung
End Sub
Private Sub dgvProdukt_CellDoubleClick(sender As Object, _
e As System.Windows.Forms.DataGridViewCellEventArgs) _
Handles dgvProdukt.CellDoubleClick
If e.RowIndex = -1 Then Exit Sub
If dgvKunde.SelectedRows.Count = 0 Then
MsgBox("Kein Kunde gewählt") : Exit Sub
End If
Dim stück As Integer
If Not Integer.TryParse(txtStück.Text, stück) OrElse _
stück < 1 Then
MsgBox("Keine Stückzahl gegeben") : Exit Sub
End If
Dim prow As DataRow = _
CType(bsProdukt.Current, DataRowView).Row
Dim qrow As DataRow = dtQuittung.NewRow
qrow("Kunde") = _
CType(bsKunde.Current, DataRowView).Row("Name")
qrow("Produkt") = prow("Produkt")
qrow("Stück") = stück
qrow("Preis") = stück * CDec(prow("Preis"))
dtQuittung.Rows.Add(qrow)
End Sub
End Class |