Imports IntraSell_DLL
Imports IntraSell_Net.dsAdressenProfil
Public Class AdressenProfil
    Private loaded As Boolean = False
    Private _IDNR As Integer
    'Dim PROFIL_EINZEHLHANDEL As String = "Sperrtag;Öffnungszeiten;Wasser;Strom;Anzahl EKW;Intervall;Turnus;LDF;Letzte Umsatz; Höchsts Umsatz;EK Sucht;EKW Verkauft;Stück;GS Länge;Name;Münzautomat;Hersteller;Raddurchmesser(mm);Marke;Nr;Liter;Farbe;Baujahr;Plastikfarbe;"
    Public Property IDNR() As Integer
        Get
            Return _IDNR
        End Get
        Set(value As Integer)
            _IDNR = value
            Ofadressen_profilTableAdapter.Fill(DsAdressenProfil._ofadressen_profil, _IDNR)
        End Set
    End Property

    Public Sub UpdateAll()
        Ofadressen_profilBindingNavigatorSaveItem_Click(Nothing, Nothing)
    End Sub


    Private Sub Ofadressen_profilBindingNavigatorSaveItem_Click(sender As Object, e As System.EventArgs) Handles Ofadressen_profilBindingNavigatorSaveItem.Click
        Try
            Validate()
            Ofadressen_profilBindingSource.EndEdit()
            TableAdapterManager.UpdateAll(DsAdressenProfil)
        Catch ex As Exception
            HandleAppError(ex)
        End Try
    End Sub

    Private Sub AdressenProfil_Load(sender As Object, e As System.EventArgs) Handles MyBase.Load
        FillComboBox(ComboBox1, "SELECT BrNr, Bezeichnung from grBranchen order by Bezeichnung", "Bezeichnung", "BrNR")
        loaded = True
    End Sub

    'Profil beim Kunden setzen
    Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As System.EventArgs) Handles ComboBox1.SelectedValueChanged

        Try
            If Not loaded Then Exit Sub
            'PROFIL_EINZEHLHANDEL = VarValue_Default("PROFIL_EINZEHLHANDEL", PROFIL_EINZEHLHANDEL)
            Dim sql As String = "select Keyword, DefaultValue from grbranchenkeywords where brNr=" & ComboBox1.SelectedValue & " order by Id"
            Dim nextID1 As Integer = NextId("`ofAdressen-Profil`", "ID")
            Dim rs = OpenRecordsetInMemory(sql)
            While rs.Rows.Count > 0
                Dim eigenschaft As String = rs.Rows(0)("Keyword")

                'For Each eigenschaft As String In Split(PROFIL_EINZEHLHANDEL, ";")
                Dim row As _ofadressen_profilRow = DsAdressenProfil._ofadressen_profil.New_ofadressen_profilRow()
                row.ID = nextID1
                row.IDNR = _IDNR
                row.Name = rs.Rows(0)("Keyword")
                If Not IsDBNull(rs("DefaultValue")) Then row.Wert = rs.Rows(0)("DefaultValue")
                row.AngelegtAm = Date.Now
                nextID1 += 1
                DsAdressenProfil._ofadressen_profil.Add_ofadressen_profilRow(row)
            End While

            'Neue Branche setzen 
            sql = "Update ofAdressen set Branche=" & ComboBox1.SelectedValue & _
                  " where IdNR=" & _IDNR
            RunSQL(sql)

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