Imports IntraSell_DLL
Imports IntraSell_Net_Base

Public Class Vars
    Inherits AbstractForm

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

    Private Sub OfvarsBindingNavigatorSaveItem_Click(sender As Object, e As System.EventArgs) Handles MyBase.Save
        Try
            Validate()
            OfvarsBindingSource.EndEdit()
            TableAdapterManager.UpdateAll(DsEinstellungen)
            IntraSell_DLL.ClearCache()
            IntraSell_DLL.BuildCache()
        Catch ex As Exception
            HandleAppError(ex)
        End Try
    End Sub

    Private Sub Vars_Load(sender As Object, e As System.EventArgs) Handles MyBase.Load
        Try
            ParentBindingNavigator.BindingSource = OfvarsBindingSource
            ds = DsEinstellungen

            OfvarsTableAdapter.Fill(DsEinstellungen.ofvars)
        Catch ex As Exception
            HandleAppError(ex)
        End Try
    End Sub

    Private Sub txtSuche_TextChanged(sender As Object, e As System.EventArgs) Handles txtSuche.TextChanged
        Try
            'filter dataset 
            If txtSuche.Text.Length > 0 Then
                OfvarsBindingSource.Filter = "Name like '%" + txtSuche.Text + "%' or Wert Like '%" + txtSuche.Text + "%'"
            Else
                OfvarsBindingSource.Filter = Nothing
            End If

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

    Sub Filter(filter As String)
        txtSuche.Text = filter
        txtSuche_TextChanged(Nothing, Nothing)
    End Sub

    Private Sub OfvarsDataGridView_DataError(sender As Object, e As DataGridViewDataErrorEventArgs) Handles OfvarsDataGridView.DataError
        'Do not remove
    End Sub

    Private Sub OfvarsDataGridView_CellFormatting(sender As Object, e As DataGridViewCellFormattingEventArgs) Handles OfvarsDataGridView.CellFormatting
        Try
            If e.ColumnIndex >= 2 Then
                Dim dr = OfvarsDataGridView.Rows(e.RowIndex)
                Dim cell As DataGridViewCell = OfvarsDataGridView(e.ColumnIndex, e.RowIndex)
                Dim Wert = dr.Cells(2).Value
                If Not IsDBNull(Wert) Then

                    Dim istBoolean As Boolean
                    istBoolean = Boolean.TryParse(Wert, istBoolean)
                    If e.ColumnIndex = 2 Then
                        If Not istBoolean Then
                            cell.Style.BackColor = Color.White
                        Else
                            cell.Style.BackColor = Color.LightGray 'Booleans nicht editieren als text
                            If Wert Then
                                cell.Style.ForeColor = Color.Green
                            Else
                                cell.Style.ForeColor = Color.Red
                            End If
                        End If
                    Else
                        If e.ColumnIndex = 3 Then
                            If Not istBoolean Then
                                cell.ReadOnly = True 'nicht erlauben text werte zu ändern 
                                cell.Style.BackColor = Color.LightGray
                            Else
                                If Wert Then
                                    cell.Style.ForeColor = Color.Green
                                Else
                                    cell.Style.ForeColor = Color.Red
                                End If
                            End If
                        End If
                    End If
                End If
            End If

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

    Sub SetTitle(title As String)
        Text = title
    End Sub

    Private Sub OfvarsDataGridView_CellEndEdit(sender As Object, e As DataGridViewCellEventArgs) Handles OfvarsDataGridView.CellEndEdit

    End Sub

    Private Sub OfvarsDataGridView_RowValidating(sender As Object, e As DataGridViewCellCancelEventArgs) Handles OfvarsDataGridView.RowValidating

    End Sub

    Private Sub OfvarsDataGridView_CellPainting(sender As Object, e As DataGridViewCellPaintingEventArgs) Handles OfvarsDataGridView.CellPainting

    End Sub
End Class