Imports IntraSell_DLL
Imports IntraSell_Net_Base

Public Class ArtikelSet
    Inherits AbstractForm
    Private Sub ArtikelSet_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Try
            ds = DsArtikel
            ParentBindingNavigator.BindingSource = BuchsetartikelBindingSource
            GrArtikellisteTableAdapter.Fill(DsArtikel.grArtikelliste)

            'Daten korrektur 
            RunSQL("update grArtikel set setArtikel=0 where setArtikel<>0 and not ArtNr In (select artnr from buchSetArtikel)")
            RunSQL("update grArtikel set setArtikel=1 where setArtikel<>1 and ArtNr In (select artnr from buchSetArtikel)")
        Catch ex As Exception
            HandleAppError(ex)
        End Try
    End Sub

    Private Sub ArtikelControl1_ArtNrChanged(artnr As Integer) Handles ArtikelControl1.ArtNrChanged
        ShowArtNr(artnr)
    End Sub

    Public Sub ShowArtNr(artnr As Object)
        Try
            ArtikelControl1.ArtNr = artnr
            BuchsetartikelTableAdapter.FillBy(DsArtikel.buchsetartikel, artnr)
        Catch ex As Exception
            HandleAppError(ex)
        End Try
    End Sub


    Private Sub ButtonEinfuegen_Click(sender As Object, e As EventArgs) Handles ButtonEinfuegen.Click
        'AddUnterArtikel(ArtikelListeControl.ArtNrListe)
        ArtikelListeControl1.Uebernehmen()
    End Sub

    Private Sub ArtikelListeControl1_ArtikelUebernehmen(ArtNr As Integer, EAN As String, Bezeichnung As String) Handles ArtikelListeControl1.ArtikelUebernehmen
        AddUnterArtikel(ArtNr)
    End Sub

    Sub AddUnterArtikel(UnterArtNr As Integer())

    End Sub

    Sub AddUnterArtikel(UnterArtNr As Integer)
        Try
            If ArtikelControl1.ArtNr < 1 Then
                Exit Sub
            End If
            If UnterArtNr < 1 Then
                Exit Sub
            End If
            If Not IsNumeric(TextBoxStk.Text) Then
                Exit Sub
            End If
            If ArtikelControl1.ArtNr = UnterArtNr Then
                Exit Sub
            End If
            Dim neuesTeil = BuchsetartikelBindingSource.AddNew().row
            neuesTeil.ArtNr = ArtikelControl1.ArtNr
            neuesTeil.unterartnr = UnterArtNr
            neuesTeil.Stk = CDbl(TextBoxStk.Text)

        Catch ex As Exception
            HandleAppError(ex)
        End Try
    End Sub

    Private Sub ButtonDel_Click(sender As Object, e As EventArgs) Handles ButtonDel.Click
        For Each r As DataGridViewRow In DataGridView1.SelectedRows
            BuchsetartikelBindingSource.Remove(r.DataBoundItem)
        Next
    End Sub

    Private Sub GrartikelBindingNavigatorSaveItem_Click(sender As Object, e As System.EventArgs) Handles MyBase.Save
        Try
            Validate()
            BuchsetartikelBindingSource.EndEdit()
            BuchsetartikelTableAdapter.Update(DsArtikel)
        Catch ex As Exception
            HandleAppError(ex)
        End Try
    End Sub

    Private Sub DataGridView1_DataError(sender As Object, e As DataGridViewDataErrorEventArgs) Handles DataGridView1.DataError

    End Sub


    Private Sub LabelHilfe_MouseEnter(sender As Object, e As EventArgs) Handles LabelHilfe.MouseEnter
        LabelHilfe.Height = LabelHilfe.Height * 3
    End Sub

    Private Sub LabelHilfe_MouseLeave(sender As Object, e As EventArgs) Handles LabelHilfe.MouseLeave
        LabelHilfe.Height = LabelHilfe.Height / 3
    End Sub


    Private Sub RezepteÜbersichtToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles RezepteÜbersichtToolStripMenuItem.Click
        Try
            ArtikelSetListe.MdiParent = Main
            ArtikelSetListe.Show()
        Catch ex As Exception

        End Try
    End Sub
End Class