Imports IntraSell_DLL

Public Class ArtikelMassenUpdate

    Property ArtikelListe As DataTable

    Private Sub Form_Verlassen() Handles MyBase.Verlassen
        Me.Close()
    End Sub

    Private Sub ArtikelMassenUpdate_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Try
            Me.ParentBindingNavigator.Visible = False

            FillComboBox(ComboBoxUrsprungsland, "select idnr, name from grLand order by name", "name", "idnr")
        Catch ex As Exception
            HandleAppError(ex, Silent:=True)
        End Try
    End Sub

    Private Sub ButtonSet_Click(sender As Object, e As EventArgs) Handles ButtonSet.Click
        Try
            Dim msg = $"Wollen Sie {ArtikelListe.Rows.Count} Artikel aktualisieren? Es werden nur Artikel aktualisiert wo Ursprungsland noch nicht gesetzt ist."
            If MsgBox(msg, vbYesNo) = vbYes Then
                For Each artikel In ArtikelListe.Rows

                    Dim sql As String = $"update statistik_austria_warengruppen set Ursprungsland=@Ursprungsland where ArtNr=@ArtNr and Ursprungsland is null"
                    Dim cmd As New MySql.Data.MySqlClient.MySqlCommand(sql)
                    cmd.Connection = CurrentDB
                    cmd.Parameters.AddWithValue("Ursprungsland", ComboBoxUrsprungsland.SelectedValue)
                    cmd.Parameters.AddWithValue("ArtNr", artikel("ArtNr"))
                    cmd.ExecuteNonQuery()

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

End Class