Imports System.ComponentModel
Imports VERAG_PROG_ALLGEMEIN
'TEST
Public Class frmMain
    Public Shared ConnStr As String
    Public Shared ConnStrInfo As String
    Private Grid_aktiv As Boolean = False
    Private Anzahl As Integer
    Private locZeilen As Integer = -1
    Private Suche_freigegeben As Boolean = False
    Private DISPO As New cOptionenDAL
    ' Public Shared rowId As Integer
    Private hSQL As String
    Private nochange As Boolean = False



    Private Sub frmMain_Disposed(sender As Object, e As EventArgs) Handles Me.Disposed
        frmLogin.Close()
    End Sub

    Private Sub Main_Load(sender As Object, e As EventArgs) Handles Me.Load
        If Not frmLogin.USRNAME = "Andreas Luxbauer" Then btnHomepage.Visible = False
        '     If frmLogin.USRBER > 5 Then btnMitarbeiter.Enabled = False : btnProgramme.Enabled = False
        Grid_aktiv = True
        btnMitarbeiter.Enabled = False
        btnProgramme.Enabled = False
        btnSchulungen.Enabled = False
        btnDienstplan.Enabled = False
        Button1.Enabled = False
        btnAuditFlow.Enabled = False
        btnHomepage.Enabled = False
        Button6.Enabled = False
        btnAPIZugang.Enabled = False
        btnAPI.Enabled = False
        btnFehler.Enabled = False
        btnDatenarchiv.Enabled = False
        btnMailroutine.Enabled = False
        lblVersion.Text = "V " & Application.ProductVersion 'My.Resources.Version2

        Dim uniqueberechtigungDP = True
        If VERAG_PROG_ALLGEMEIN.cBerechtignunen.CHECK_BERECHTIGUNG_bool("AUDITFLOW", "ADMIN") Or VERAG_PROG_ALLGEMEIN.cBerechtignunen.CHECK_BERECHTIGUNG_bool("AUDITFLOW", "SDL") Then
            btnAuditFlow.Enabled = True
            uniqueberechtigungDP = False
        End If
        If VERAG_PROG_ALLGEMEIN.cBerechtignunen.CHECK_BERECHTIGUNG_bool("SCHULUNG", "ADMIN") Or VERAG_PROG_ALLGEMEIN.cBerechtignunen.CHECK_BERECHTIGUNG_bool("SCHULUNG", "SDL") Then
            btnSchulungen.Enabled = True
            uniqueberechtigungDP = False
        End If



        ' Me.berechtigung = VERAG_PROG_ALLGEMEIN.cBerechtignunen.CHECK_BERECHTIGUNG("ADMINFUNCTIONS", 1)
        ' If Me.berechtigung = 99 Then Me.Close() : Exit Sub

        If VERAG_PROG_ALLGEMEIN.cBerechtignunen.CHECK_BERECHTIGUNG("ADMINFUNCTIONS", 1) = 0 Then
            btnMitarbeiter.Enabled = True
            btnProgramme.Enabled = True
            btnSchulungen.Enabled = True
            btnMailroutine.Enabled = True
            btnDienstplan.Enabled = True
            Button1.Enabled = True
            btnAuditFlow.Enabled = True
            btnAPIZugang.Enabled = True
            btnAPI.Enabled = True
            btnFehler.Enabled = True
            btnHomepage.Enabled = True
            Button6.Enabled = True
            btnDatenarchiv.Enabled = True
            uniqueberechtigungDP = False
        End If

        If VERAG_PROG_ALLGEMEIN.cBerechtignunen.CHECK_BERECHTIGUNG_bool("frmDienstplan", Me) Then
            btnDienstplan.Enabled = True
            If uniqueberechtigungDP Then btnDienstplan.PerformClick()
        End If
        '  If frmLogin.USRBER >= 5 Then
        'btnDienstplan.Enabled = True
        '   End If




        Dim usrCntl As New usrCntlWelcome
        pnlMain.Controls.Add(usrCntl)
    End Sub


    Private Sub btnNew_Click(sender As Object, e As EventArgs) Handles btnMitarbeiter.Click
        clrPnlMain()
        Dim usrCntl As New usrCntlMitarbeiter
        pnlMain.Controls.Add(usrCntl)
        button_Click(sender)
    End Sub
    Private Sub clrPnlMain()
        While pnlMain.HasChildren
            pnlMain.Controls.RemoveAt(0)
        End While
    End Sub

    Private Sub PictureBox1_Click_1(sender As Object, e As EventArgs) Handles PictureBox1.Click
        clrPnlMain()
        Dim usrCntl As New usrCntlWelcome
        pnlMain.Controls.Add(usrCntl)
    End Sub

    Private Sub btnChange_Click(sender As Object, e As EventArgs) Handles btnProgramme.Click
        clrPnlMain()
        Dim usrCntl As New usrCntlProgramme
        pnlMain.Controls.Add(usrCntl)
        button_Click(sender)
    End Sub

    Private Sub Button3_Click_1(sender As Object, e As EventArgs) Handles btnDienstplan.Click
        clrPnlMain()
        Dim usrCntl As New usrCntlDienstplan
        pnlMain.Controls.Add(usrCntl)
        button_Click(sender)
    End Sub

    Private Sub Button4_Click(sender As Object, e As EventArgs) Handles btnSchulungen.Click
        clrPnlMain()
        Dim usrCntl As New usrCntlSeminare
        pnlMain.Controls.Add(usrCntl)
        button_Click(sender)
    End Sub

    Private Sub Button1_Click_1(sender As Object, e As EventArgs) Handles Button1.Click
        clrPnlMain()
        Dim usrCntl As New usrctlBuergschaft
        pnlMain.Controls.Add(usrCntl)
        button_Click(sender)
    End Sub

    Private Sub btnHomepage_Click_1(sender As Object, e As EventArgs) Handles btnHomepage.Click
        clrPnlMain()
        Dim usrCntl As New usrcntlHomepage
        pnlMain.Controls.Add(usrCntl)
        usrCntl.Dock = System.Windows.Forms.DockStyle.Fill
        button_Click(sender)
    End Sub

    Private Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click
        'frmTest.Show()
        clrPnlMain()
        Dim usrCntl As New usrctlProcedures
        pnlMain.Controls.Add(usrCntl)
        button_Click(sender)
    End Sub

    Private Sub Button7_Click(sender As Object, e As EventArgs) Handles Button7.Click
        Me.Close()
    End Sub

    Private Sub btnUpdate_Click(sender As Object, e As EventArgs) Handles btnUpdate.Click
        frmLogin.UpdateADMIN()

    End Sub

    Private Sub button_Click(sender As Object)
        Button6.BackColor = Color.White : Button6.ForeColor = SystemColors.ControlText
        Button1.BackColor = Color.White : Button1.ForeColor = SystemColors.ControlText
        btnSchulungen.BackColor = Color.White : btnSchulungen.ForeColor = SystemColors.ControlText
        btnDienstplan.BackColor = Color.White : btnDienstplan.ForeColor = SystemColors.ControlText
        btnProgramme.BackColor = Color.White : btnProgramme.ForeColor = SystemColors.ControlText
        btnMitarbeiter.BackColor = Color.White : btnMitarbeiter.ForeColor = SystemColors.ControlText
        btnAPI.BackColor = Color.White : btnAPI.ForeColor = SystemColors.ControlText
        btnFehler.BackColor = Color.White : btnFehler.ForeColor = SystemColors.ControlText

        sender.BackColor = System.Drawing.Color.FromArgb(0, 54, 128) 'Color.RoyalBlue
        sender.ForeColor = Color.White
    End Sub




    Private Sub Button1_Click(sender As Object, e As EventArgs)
        Dim c As New cProgramFunctions
        c.screenshot()
    End Sub

    Private WithEvents T As New Timers.Timer With {.Interval = 500, .Enabled = True, .AutoReset = True}
    Private FormCount As Integer = 1
    Private Sub SomeForm_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs)
        If e.KeyData = Keys.Escape Then
            Dim TheForm = DirectCast(DirectCast(sender, Control).TopLevelControl, Form)
            If Not TheForm Is Nothing Then
                TheForm.Close()
            End If
        End If
        If e.KeyData = Keys.PrintScreen Then
            Dim TheForm = DirectCast(DirectCast(sender, Control).TopLevelControl, Form)
            If Not TheForm Is Nothing Then
                Dim c As New cProgramFunctions
                c.screenshot()
            End If
        End If
    End Sub
    Private Sub HookControls(ByVal f As Control)
        For Each Control As Control In f.Controls
            AddHandler Control.KeyUp, AddressOf SomeForm_KeyUp
            If Control.Controls.Count <> 0 Then
                HookControls(Control)
            End If
        Next
    End Sub
    Private Sub T_Elapsed(ByVal sender As Object, ByVal e As System.Timers.ElapsedEventArgs) Handles T.Elapsed
        If FormCount = 0 Then FormCount = 1
        Dim FormOpened As Integer = My.Application.OpenForms.Count
        If FormCount <> FormOpened Then
            If FormOpened > FormCount Then
                For x As Integer = 1 To (FormOpened - FormCount)
                    Dim F As Form = My.Application.OpenForms.Item(FormOpened - x)
                    AddHandler F.KeyDown, AddressOf SomeForm_KeyUp
                    HookControls(F)
                    FormCount = My.Application.OpenForms.Count
                Next
            Else
                FormCount = My.Application.OpenForms.Count
            End If
        End If
    End Sub

    Private Sub btnAPI_Click(sender As Object, e As EventArgs) Handles btnAPI.Click
        clrPnlMain()
        Dim usrCntl As New usrCntlAPI
        pnlMain.Controls.Add(usrCntl)
        usrCntl.Dock = DockStyle.Fill
        button_Click(sender)
    End Sub

    Private Sub btnFehler_Click(sender As Object, e As EventArgs) Handles btnFehler.Click
        clrPnlMain()
        Dim usrCntl As New usrCntlERS
        pnlMain.Controls.Add(usrCntl)
        usrCntl.Dock = DockStyle.Fill
        button_Click(sender)
    End Sub

    Private Sub btnDatenarchiv_Click(sender As Object, e As EventArgs) Handles btnDatenarchiv.Click
        clrPnlMain()
        Dim usrCntl As New usrCntlDatenarchiv("tblPartnersystem_Paramter", "FMZOLL")
        pnlMain.Controls.Add(usrCntl)
        usrCntl.Dock = DockStyle.Fill
        button_Click(sender)
    End Sub

    Private Sub Button3_Click(sender As Object, e As EventArgs) Handles btnAPIZugang.Click
        Dim f = New frmAPIZugaenge("tblRESTAuthentication", "ADMIN")
        f.Show()
    End Sub

    Private Sub btnMailroutine_Click(sender As Object, e As EventArgs) Handles btnMailroutine.Click
        clrPnlMain()
        Dim usrCntl As New usrCntlMailsender_("tblMailsender", "ADMIN")
        pnlMain.Controls.Add(usrCntl)
        usrCntl.Dock = DockStyle.Fill
        button_Click(sender)
    End Sub

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles btnAuditFlow.Click
        Dim f As New frmAuditFlow
        f.Show(Me)
    End Sub



    Private Sub btnInterneBenachrichtigungen_Click(sender As Object, e As EventArgs) Handles btnInterneBenachrichtigungen.Click
        Dim f As New frminterneEmailBenachrichtigungen
        f.Show(Me)
    End Sub
End Class
