Imports System.Drawing.Printing

Public Class frmStammdatenverwaltung

    Private Sub TBKOMMCOLLI_MANDANTBindingNavigatorSaveItem_Click(sender As System.Object, e As System.EventArgs) Handles TBKOMMCOLLI_MANDANTBindingNavigatorSaveItem.Click
        Save_Mandant()
    End Sub
    Private Sub PopulateInstalledPrintersCombo()
        ' Add list of installed printers found to the combo box. 
        ' The pkInstalledPrinters string will be used to provide the display string. 
        Dim i As Integer
        Dim pkInstalledPrinters As String

        For i = 0 To PrinterSettings.InstalledPrinters.Count - 1
            pkInstalledPrinters = PrinterSettings.InstalledPrinters.Item(i)
            PRINTER_NAMEComboBox.Items.Add(pkInstalledPrinters)
        Next
    End Sub
    Private Sub frmStammdatenverwaltung_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        PopulateInstalledPrintersCombo()
        If My.Settings.Default_Mandant <> String.Empty Then
            tslblStandard.Text = "Standards - Mandant: '" & My.Settings.Default_Mandant & "'"
            If My.Settings.Default_Terminart <> String.Empty Then
                tslblStandard.Text = "Standards - Terminart: '" & My.Settings.Default_Terminart & "'"
            End If
        Else
            tslblStandard.Text = " Standards - Mandant: (Nicht angegeben)"
            If My.Settings.Default_Terminart <> String.Empty Then
                tslblStandard.Text = tslblStandard.Text & " - Terminart: '" & My.Settings.Default_Terminart & "'"
            End If
        End If
        Try
            Me.TBKOMMCOLLI_MANDANTTableAdapter.Connection.ConnectionString = My.Settings.ConfigConnectionString
            Me.TBWH_MANDANTTableAdapter.Connection.ConnectionString = My.Settings.ConfigConnectionString
        Catch ex As Exception
            MsgBox("Fehler bei Load ConnectionString: " & vbNewLine & ex.Message, MsgBoxStyle.Exclamation)
            Exit Sub
        End Try

        Try
            Me.TBKOMMCOLLI_MANDANTTableAdapter.Fill(Me.MyDataset.TBKOMMCOLLI_MANDANT)
            Refresh_Terminarten()
        Catch ex As Exception
            MsgBox("Fehler bei Load Stammdaten: " & vbNewLine & ex.Message, MsgBoxStyle.Exclamation)
        End Try
    End Sub

    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        Me.folderBrowserDialog.SelectedPath = Me.SPEICHERORTTextBox.Text
        If Me.folderBrowserDialog.ShowDialog = DialogResult.OK Then
            Me.SPEICHERORTTextBox.Text = Me.folderBrowserDialog.SelectedPath
        End If
    End Sub

    Private Sub TBKOMMCOLLI_MANDANTBindingSource_AddingNew(sender As Object, e As System.ComponentModel.AddingNewEventArgs) Handles TBKOMMCOLLI_MANDANTBindingSource.AddingNew
        MyDataset.TBKOMMCOLLI_MANDANT.ERFASSTWERColumn.DefaultValue = Environment.UserName
    End Sub
    Sub Save_Mandant()
        Try
            Me.Validate()
            Me.TBKOMMCOLLI_MANDANTBindingSource.EndEdit()
            If Me.MyDataset.TBKOMMCOLLI_MANDANT.GetChanges Is Nothing = False Then
                Me.GEANDERTWERTextBox.Text = Environment.UserName
                Me.TBKOMMCOLLI_MANDANTBindingSource.EndEdit()
                TBKOMMCOLLI_MANDANTTableAdapter.Update(MyDataset.TBKOMMCOLLI_MANDANT)
                MsgBox("Änderungen wurden erfolgreich gespeichert!", MsgBoxStyle.Information, "Erfolgsmeldung:")
            End If
        Catch ex As Exception
            MsgBox("Fehler bei Mandanten speichern: " & vbNewLine & ex.Message, MsgBoxStyle.Exclamation)
        End Try

    End Sub

    Private Sub btnStandard_Click(sender As System.Object, e As System.EventArgs) Handles btnStandard.Click
        tslblStandard.Text = "Standards - Mandant: '" & Me.KURZNAMETextBox.Text & "'"
        My.Settings.Default_Mandant = Me.KURZNAMETextBox.Text
        My.Settings.Save()
    End Sub

    Private Sub Refresh_Terminarten()
        Try
            If Me.GUIDTextBox.Text <> Nothing Then
                Me.TBWH_MANDANTTableAdapter.Fill(Me.MyDataset.TBWH_MANDANT)
                Me.TBKOMMCOLLI_TERMINARTTableAdapter.Fill(Me.MyDataset.TBKOMMCOLLI_TERMINART, Me.GUIDTextBox.Text)
            End If
        Catch ex As System.Exception
            MsgBox("Fehler bei Refresh_Terminarten: " & vbNewLine & ex.Message, MsgBoxStyle.Exclamation)
        End Try
    End Sub

    Private Sub TBKOMMCOLLI_MANDANTBindingSource_PositionChanged(sender As System.Object, e As System.EventArgs) Handles TBKOMMCOLLI_MANDANTBindingSource.PositionChanged
        Refresh_Terminarten()
    End Sub

    Private Sub TBKOMMCOLLI_TERMINARTBindingSource_AddingNew(sender As System.Object, e As System.ComponentModel.AddingNewEventArgs) Handles TBKOMMCOLLI_TERMINARTBindingSource.AddingNew
        MyDataset.TBKOMMCOLLI_TERMINART.ERFASSTWERColumn.DefaultValue = Environment.UserName
    End Sub

    Private Sub tsbtnStandardTerminart_Click(sender As System.Object, e As System.EventArgs) Handles tsbtnStandardTerminart.Click
        Try
            Dim i As Integer
            Dim KZ As String
            i = TBKOMMCOLLI_TERMINARTDataGridView.CurrentRow.Index
            KZ = TBKOMMCOLLI_TERMINARTDataGridView.Item(2, i).Value
            My.Settings.Default_Terminart = KZ
            My.Settings.Save()
            If My.Settings.Default_Mandant <> String.Empty Then
                tslblStandard.Text = "Standards - Mandant: '" & My.Settings.Default_Mandant & "'"
                If My.Settings.Default_Terminart <> String.Empty Then
                    tslblStandard.Text = "Standards - Terminart: '" & My.Settings.Default_Terminart & "'"
                End If
            Else
                tslblStandard.Text = " Standards - Mandant: (Nicht angegeben)"
                If My.Settings.Default_Terminart <> String.Empty Then
                    tslblStandard.Text = tslblStandard.Text & " - Terminart: '" & My.Settings.Default_Terminart & "'"
                End If
            End If
        Catch ex As System.Exception
            MsgBox("Fehler bei Standard Terminart: " & vbNewLine & ex.Message, MsgBoxStyle.Critical)
        End Try
    End Sub

    Private Sub tsbtnTerminartenSave_Click(sender As System.Object, e As System.EventArgs) Handles tsbtnTerminartenSave.Click
        Try
            Me.TBKOMMCOLLI_TERMINARTBindingSource.EndEdit()
            If MyDataset.TBKOMMCOLLI_TERMINART.GetChanges Is Nothing = False Then
                TBKOMMCOLLI_TERMINARTTableAdapter.Update(MyDataset.TBKOMMCOLLI_TERMINART)
                MsgBox("Änderungen wurden erfolgreich gespeichert!", MsgBoxStyle.Information, "Erfolgsmeldung:")

            End If
        Catch ex As Exception
            MsgBox("Fehler bei Speichern Terminarten:" & vbNewLine & ex.Message, MsgBoxStyle.Critical)
        End Try

    End Sub
End Class