Imports IntraSell_DLL
Imports IntraSell_Net_Base

Public Class VorgangEinstellungen
    Inherits AbstractForm

    Private Sub VorgangEinstellungen_Load(sender As Object, e As System.EventArgs) Handles MyBase.Load
        Try
            ParentBindingNavigator.BindingSource = BuchvorgangtypBindingSource
            ds = DsVorgaenge
            BuchvorgaengeausdruckeTableAdapter.Fill(DsVorgaenge.buchvorgaengeausdrucke)
            BuchvorgangeigenschaftTableAdapter.Fill(DsVorgaenge.buchvorgangeigenschaft)
            BuchvorgaengestatusTableAdapter.Fill(DsVorgaenge.buchvorgaengestatus)
            BuchvorgangtypTableAdapter.Fill(DsVorgaenge.buchvorgangtyp)

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

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

    Private Sub BuchvorgangtypBindingNavigatorSaveItem_Click(sender As Object, e As System.EventArgs) Handles MyBase.Save
        Try
            Validate()
            BuchvorgangtypBindingSource.EndEdit()
            TableAdapterManager.UpdateAll(DsVorgaenge)
        Catch ex As Exception
            HandleAppError(ex)
        End Try
    End Sub

    Sub Filter(VorgangTyp As String)
        Try
            BuchvorgangtypBindingSource.Filter = "Typ='" & VorgangTyp & "'"
        Catch ex As Exception
            HandleAppError(ex)
        End Try
    End Sub

    'Format 
    Private Sub DataGridView1_CellFormatting(sender As Object, e As System.Windows.Forms.DataGridViewCellFormattingEventArgs) Handles BuchvorgaengestatusDataGridView.CellFormatting
        Try
            If e.ColumnIndex = 0 Then
                Dim dr = BuchvorgaengestatusDataGridView.Rows(e.RowIndex)
                Dim dbi = BuchvorgaengestatusDataGridView.Rows(e.RowIndex).DataBoundItem
                If dbi IsNot Nothing Then
                    Dim vorgang As dsVorgaenge.buchvorgaengestatusRow = dbi.row
                    e.CellStyle.BackColor = ColorTranslator.FromHtml(vorgang.Style)
                End If
            End If
        Catch ex As Exception

        End Try
    End Sub

    ''' <summary>
    ''' nicht löschen
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub BuchvorgaengestatusDataGridView_DataError(sender As Object, e As DataGridViewDataErrorEventArgs) Handles BuchvorgaengestatusDataGridView.DataError

    End Sub

    Private Sub BuchvorgaengestatusDataGridView_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) _
                                           Handles BuchvorgaengestatusDataGridView.CellContentClick
        Dim senderGrid = DirectCast(sender, DataGridView)

        If TypeOf senderGrid.Columns(e.ColumnIndex) Is DataGridViewButtonColumn AndAlso
           e.ColumnIndex = 7 AndAlso
           e.RowIndex >= 0 Then
            Dim s = BuchvorgaengestatusDataGridView.Rows(e.RowIndex).DataBoundItem.Row
            Dim cDialog As New ColorDialog()
            Try
                cDialog.Color = ColorTranslator.FromHtml(s.Style)
            Catch ex As Exception

            End Try

            If (cDialog.ShowDialog() = DialogResult.OK) Then
                'StylesheetTextBox.BackColor = cDialog.Color ' update with user selected color.
                s.Style = ColorTranslator.ToHtml(cDialog.Color)
            End If
        ElseIf TypeOf senderGrid.Columns(e.ColumnIndex) Is DataGridViewButtonColumn AndAlso
            e.ColumnIndex = 8 AndAlso
          e.RowIndex >= 0 Then
            Dim s = BuchvorgaengestatusDataGridView.Rows(e.RowIndex).DataBoundItem.Row
            DefiniereVorgangAktion(s.VorgangTyp, s.Status)
        End If

    End Sub

End Class