Public Class frmOrder

    Dim _NWindDataKontext As NordwindEntities

    Public Sub New(ByVal DataKontext As NordwindEntities, ByVal OrderID As Integer)
        InitializeComponent()
        _intOrderID = OrderID
        txtOrderID.Text = OrderID
        _NWindDataKontext = DataKontext
    End Sub

#Region "Ereignisse"
    Private Sub frmOrder_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        cbxProdukte.DataSource = _NWindDataKontext.Products
        cbxProdukte.DisplayMember = "ProductName"
        cbxProdukte.ValueMember = "ProductID"

        butOK.Enabled = False
    End Sub

    Private Sub butOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles butOK.Click
        _intAnzahl = txtAnzahl.Text
        _intProduktID = CType(cbxProdukte.SelectedItem, Products).ProductID
        _pdProdukt = CType(cbxProdukte.SelectedItem, Products)

        Me.DialogResult = Windows.Forms.DialogResult.OK
        Me.Close()
    End Sub

    Private Sub cbxProdukte_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles cbxProdukte.SelectedIndexChanged
        txtPreis.Text = CType(cbxProdukte.SelectedItem, Products).UnitPrice
    End Sub

    Private Sub txtAnzahl_Validating(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtAnzahl.Validating
        If Not IsNumeric(txtAnzahl.Text) Then
            epvNumerisch.SetError(txtAnzahl, "Keine Zahl!")
            butOK.Enabled = False
        Else
            epvNumerisch.Clear()
            butOK.Enabled = True
        End If
    End Sub
#End Region

#Region "Properties"
    Private _intProduktID As Integer

    Public Property ProduktID() As Integer
        Get
            Return _intProduktID
        End Get
        Set(ByVal value As Integer)
            _intProduktID = value
        End Set
    End Property

    Private _pdProdukt As Products

    Public Property Produkt() As Products
        Get
            Return _pdProdukt
        End Get
        Set(ByVal value As Products)
            _pdProdukt = value
        End Set
    End Property

    Private _intAnzahl As Integer

    Public Property Anzahl()
        Get
            Return _intAnzahl
        End Get
        Set(ByVal value)
            _intAnzahl = value
        End Set
    End Property

    Private _intOrderID As Integer

    Public Property BestellID()
        Get
            Return _intOrderID
        End Get
        Set(ByVal value)
            _intOrderID = value
        End Set
    End Property
#End Region

End Class