Option Explicit On
Imports Microsoft.Office.Interop
Imports Microsoft.Office.Tools.Ribbon

Public Class rbnMailItem
    Dim LOGIN_OK As Boolean = False
    Dim LoadInspector As Outlook.Inspector
    Public Shared Event bla()
    Public Shared WithEvents ThisMail As Outlook.MailItem
    Dim currentexplorer As Outlook.Explorer

    Private Sub rbnMailItem_Load(ByVal sender As System.Object, ByVal e As RibbonUIEventArgs) Handles MyBase.Load
        VERAG_PROG_ALLGEMEIN.cAllgemein.TESTSYSTEM = False
        VERAG_PROG_ALLGEMEIN.cAllgemein.SQLGUIDE01_USED = True

        Group1.Label = "VERAG"
        btnAVISOUnleashed.Visible = False

        VERAG_PROG_ALLGEMEIN.cAllgemein.TESTSYSTEM = True

        LOGIN_OK = AVISO_Mail_Functions.initFirmaUser()
        currentexplorer = ThisAddIn.SharedExplorer

        Dim selObject As Object = currentexplorer.Selection(1)
        ThisMail = (TryCast(selObject, Outlook.MailItem))
    End Sub


    Private Function CreateRibbonDropDownItem() As RibbonDropDownItem
        Return Me.Factory.CreateRibbonDropDownItem()
    End Function

    Private Function CreateRibbonMenu() As RibbonMenu
        Return Me.Factory.CreateRibbonMenu()
    End Function

    Private Sub Button1_Click(sender As Object, e As RibbonControlEventArgs) Handles Button1.Click
        If LOGIN_OK Then
            Try
                Dim INSPECTOR As Outlook.Inspector = e.Control.Context
                AVISO_Mail_Functions.NewAviso(INSPECTOR.CurrentItem)
            Catch ex As Exception
                VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, ex.StackTrace, System.Reflection.MethodInfo.GetCurrentMethod.Name)
            End Try
        End If
    End Sub

    Private Sub Button2_Click(sender As Object, e As RibbonControlEventArgs) Handles btnAvisoMail2.Click
        If LOGIN_OK Then
            Try
                Dim INSPECTOR As Outlook.Inspector = e.Control.Context
                AVISO_Mail_Functions.addMailToAviso(INSPECTOR.CurrentItem, sender)
                'Me.Context
            Catch ex As Exception
                VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, ex.StackTrace, System.Reflection.MethodInfo.GetCurrentMethod.Name)
            End Try
        End If
    End Sub

    Private Sub btnInfo_Click(sender As Object, e As RibbonControlEventArgs) Handles btnInfo.Click
        ' MsgBox(VERAG_PROG_ALLGEMEIN.cAllgemein.USRKURZNAME)
        Try
            Dim INSPECTOR As Outlook.Inspector = e.Control.Context

            MsgBox(INSPECTOR.CurrentItem.FormDescription.Comment)
        Catch ex As Exception
            VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, ex.StackTrace, System.Reflection.MethodInfo.GetCurrentMethod.Name)
        End Try
    End Sub

    Private Sub btnUnsichtbar_Click(sender As Object, e As RibbonControlEventArgs) Handles btnUnsichtbar.Click
        LoadInspector = e.Control.Context
        ThisMail = LoadInspector.CurrentItem
    End Sub

    Public Shared Sub MailChanged(sender As System.Object) Handles ThisMail.PropertyChange
        If ThisAddIn.SelectedMail.ConversationIndex = ThisMail.ConversationIndex Then
            Exit Sub
        Else
            ThisAddIn.MailChanged(sender, ThisMail)
        End If
    End Sub

    Private Sub Button3_Click(sender As Object, e As RibbonControlEventArgs) Handles btnVollmachten.Click, btnGestellungsgarantien.Click, btnVertraege.Click
        If LOGIN_OK Then
            Try
                Dim INSPECTOR As Outlook.Inspector = e.Control.Context
                AVISO_Mail_Functions.addMailToAviso(INSPECTOR.CurrentItem, sender)
                'Me.Context
            Catch ex As Exception
                VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, ex.StackTrace, System.Reflection.MethodInfo.GetCurrentMethod.Name)
            End Try
        End If

    End Sub

End Class
