Imports System.ComponentModel

Public Class frmMitarbeiter

    Dim ConnStr As String
    Private UID As New cMitarbeiter
    Private cOptionenDAL As New cOptionenDAL
    Private Grid_aktiv As Boolean = False
    Private Anzahl As Integer
    Private locZeilen As Integer = -1
    Public mid As Integer = -1

    Private Sub LoadForm(sender As Object, e As EventArgs) Handles Me.Load
        Dim tmp As String
        tmp = "Provider=SQLOLEDB;Server=DEVELOPER\DEVSQL;Database=UID;"


        ConnStr = frmMain.ConnStr

        Try
            '  Me.Size = My.Settings.frmMainSize
            ' Me.Location = My.Settings.frmMainPosition
        Catch ex As Exception
            'nix tun - Standardgröße wird somit automatisch gesetzt
        End Try
        'Me.Dock = DockStyle.Fill
        ' Me.Width = frmMain.Width - frmMain.tsrcLeft.Width - 5
        ' Me.Height = frmMain.Height - (frmMain.tsrcTop.Height + frmMain.tstrBottom.Height) - 5

        Me.LayoutMdi(MdiLayout.Cascade)
        Dim l As Single = (frmMain.ClientSize.Width - Me.Width) / 2
        Dim t As Single = ((frmMain.ClientSize.Height - Me.Height) / 2) - 30
        Me.SetBounds(l, t, Me.Width, Me.Height)
        Me.MdiParent = frmMain

        ' MsgBox(frmMain.ClientSize.Height & " - " & frmMain.ClientSize.Width)

        FormBorderStyle = FormBorderStyle.None
        MaximizeBox = False
        MinimizeBox = False
        StartPosition = FormStartPosition.CenterScreen
        ' Remove the control box so the form will only display client area.
        ControlBox = False

        '   Me.Width = 1000
        Grid_aktiv = True
        Tabelle_anzeigen()

    End Sub

    Public Sub Tabelle_anzeigen()
        'Paint wieder reaktivieren
        locZeilen = -1
        If Not Grid_aktiv Then Exit Sub
        Dim sql As String = "SELECT mit_id,mit_username,mit_vname, mit_nname ,mit_niederlassung,mit_abteilung,mit_email,mit_durchwahl,mit_gekuendigt, cast (case when mit_timasId is null then 0 else 1 end as bit) mit_ze, cast (case when isnull([mit_DAKOSY_SB],'')<> '' and isnull([mit_DAKOSY_SBFull],'')<>'' then 1 else 0 end as bit) mit_DAKOSY FROM tblMitarbeiter "
        If txtSuche.Text <> "" Then
            sql &= " WHERE (mit_username LIKE '%" & txtSuche.Text & "%' OR mit_nname LIKE '%" & txtSuche.Text & "%' OR mit_vname LIKE '%" & txtSuche.Text & "%') "
        End If
        dgvUID.DataSource = UID.AnzeigeTabelle(sql)

       
        'Tabelle Kommt/Geht bereinigen
        If dgvUID.RowCount = 0 Then
            dgvUID.DataSource = Nothing
        Else
            Spalten_festlegen()
            'Eintraege_festlegen()
            'AL: Sortierung nach Ausfahrt (Zeit)
            dgvUID.Sort(dgvUID.Columns(4), ListSortDirection.Ascending)
        End If

        'Anzeige der Anzahl gewählter/aller Datensätze
        ' lblAnzahl.Text = Format(dgvUID.RowCount, "#,##0") & " ausgewählt"
        'lblAnzahl.Refresh()


    End Sub

    Private Sub Spalten_festlegen()
        With dgvUID
            .RowTemplate.Height = 20
            .RowTemplate.DefaultCellStyle.Alignment = DataGridViewContentAlignment.TopLeft
            .AllowUserToAddRows = False
            .AllowUserToDeleteRows = False
            .AllowUserToOrderColumns = False
            .AllowUserToResizeColumns = False
            .AllowUserToResizeRows = False
            .RowTemplate.ReadOnly = True
            .RowHeadersVisible = False
            .SelectionMode = DataGridViewSelectionMode.FullRowSelect

            .AllowUserToOrderColumns = True
            '.Columns("Info").DisplayIndex = 7
            .Columns(7).DisplayIndex = 6

            .Columns("mit_id").Visible = False     'ID nicht anzeigen
            .Columns(2).Visible = False     'PWD nicht anzeigen

            .Columns("mit_username").Width = 80
            .Columns("mit_username").HeaderText = "Kurzbezeichnung"
            .Columns("mit_username").DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter

            .Columns("mit_vname").Width = 150
            .Columns("mit_vname").HeaderText = "Vorname"

            .Columns("mit_nname").Width = 150
            .Columns("mit_nname").HeaderText = "Nachname"

            .Columns("mit_niederlassung").Width = 80
            .Columns("mit_niederlassung").HeaderText = "Sicherheitsstufe"

            .Columns("mit_niederlassung").Width = 175
            .Columns("mit_niederlassung").HeaderText = "Info"

            .Columns(7).Width = 80
            .Columns(7).HeaderText = "Niederlassung"


        End With
    End Sub


    Private Sub Button1_Click(sender As Object, e As EventArgs)
        Me.Close()
    End Sub

    Private Sub dgvUID_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles dgvUID.CellDoubleClick
        mid = dgvUID.CurrentRow.Cells(0).Value
        frmMitarbDetails.Show()

    End Sub

    Private Sub Panel1_Paint(sender As Object, e As PaintEventArgs)

    End Sub

    Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click

        frmMitarbDetails.Show()
    End Sub

    Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
        mid = dgvUID.CurrentRow.Cells(0).Value
        frmMitarbDetails.Show()
    End Sub

    Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click
        Select Case MsgBox("Soll der Eintrag Wirklich gelöscht werden?", vbQuestion Or vbYesNo Or vbDefaultButton2, "Löschen?")
            Case vbYes
                UID.delData(Convert.ToInt32(dgvUID.CurrentRow.Cells(0).Value))
                Tabelle_anzeigen()
            Case vbNo

        End Select
    End Sub

    Private Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click
        Dim l As IList(Of VERAG_PROG_ALLGEMEIN.cMitarbeiter)
        l = cOptionenDAL.getDataMitarb()
        frmPrintView.Show()
        frmPrintView.BefüllenMitarb(l)
    End Sub

    Private Sub Button1_Click_1(sender As Object, e As EventArgs) Handles Button1.Click
        Tabelle_anzeigen()
    End Sub

    Private Sub cbx_CheckedChanged(sender As Object, e As EventArgs)
        Tabelle_anzeigen()
    End Sub
End Class