Imports System.Runtime.InteropServices
Imports System.Text
Imports System.Xml
Imports DevExpress.XtraBars.ToastNotifications

Public Class frmMDIParent

    Private Sub CompanyDetails_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles CompanyDetails.ItemClick

        frmCompanyProfile1.MdiParent = Me
        frmCompanyProfile1.Show()
    End Sub

    Private Sub ShiftManagement_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles ShiftManagement.ItemClick
        frmWorkingHours1.MdiParent = Me
        frmWorkingHours1.Show()
    End Sub

    Private Sub DepartmentInformation_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles DepartmentInformation.ItemClick
        frmDepartment1.MdiParent = Me
        frmDepartment1.Show()
    End Sub

    Private Sub DesignationInformation_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles DesignationInformation.ItemClick
        frmDesignation1.MdiParent = Me
        frmDesignation1.Show()
    End Sub

    Private Sub BarButtonItem1_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItem1.ItemClick
        frmEmployeeDetails1.MdiParent = Me
        frmEmployeeDetails1.Show()
    End Sub

    Private Sub BarButtonItem2_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItem2.ItemClick
        frmEmployeeList.MdiParent = Me
        frmEmployeeList.Show()
    End Sub

    Private Sub BarButtonItem3_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItem3.ItemClick
        For Each ChildForm As Form In Me.MdiChildren
            ChildForm.Close()
        Next
    End Sub

    Private Sub BarButtonItem4_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItem4.ItemClick
        For Each ChildForm As Form In Me.MdiChildren
            ChildForm.Close()
        Next
    End Sub

    Private Sub frmMDIParent_Load(sender As Object, e As EventArgs) Handles MyBase.Load

        BarStaticItem1.Caption = "Welcome " + My.Settings.userlevel

        If My.Settings.userlevel = "Admin" Then
            BackgroundWorker1.RunWorkerAsync()
        End If
    End Sub

    Private Sub BackgroundWorker1_DoWork(sender As Object, e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork
        ExecuteSQLQuery(" SELECT  qid.EMPLOYEE_ID, qid.QIDNumber, qid.QIDExpiry, employee_information.EmployeesName FROM qid RIGHT OUTER JOIN employee_information ON qid.EMPLOYEE_ID =employee_information.EMPLOYEE_ID where qid.QIDExpiry <= '" & Format(Today.AddDays(30), "yyyy-MM-dd") & "'")
        If sqlDT.Rows.Count > 0 Then
            Dim c As Integer = 0
            For Each row In sqlDT.Rows

                ToastNotificationsManager1.Notifications(0).Body = "Employee name = " & sqlDT.Rows(c)("EmployeesName") & ""
                ToastNotificationsManager1.Notifications(0).Body2 = "QataID Expiry On " & sqlDT.Rows(c)("QIDExpiry") & ""
                ToastNotificationsManager1.Notifications(0).Header = "QataID Expiry Alart"
                ToastNotificationsManager1.ShowNotification(ToastNotificationsManager1.Notifications(0))
                c = c + 1
            Next
        End If
        'ToastNotificationsManager1.Notifications(0).Body = "Body"
        'ToastNotificationsManager1.Notifications(0).Body2 = "Body2"
        'ToastNotificationsManager1.Notifications(0).Header = "test"
        'ToastNotificationsManager1.ShowNotification(ToastNotificationsManager1.Notifications(0))
    End Sub


    Private Sub ToastNotificationsManager1_Activated(sender As Object, e As ToastNotificationEventArgs) Handles ToastNotificationsManager1.Activated
        Dim args As ToastNotificationActivatedEventArgs = TryCast(e, ToastNotificationActivatedEventArgs)
        Select Case (e.NotificationID.ToString())
            Case "be08f7ec-0cfa-41b0-bfc3-c8e2f3682453"
                MessageBox.Show(String.Format("The {0} button is clicked", args.Arguments))
                Exit Select
            Case "66501f90-ac6b-440d-bf73-483c5ab22143"
                MessageBox.Show("Notification #2 Clicked")
                Exit Select
        End Select
    End Sub

    Private Sub ToastNotificationsManager1_UpdateToastContent(sender As Object, e As UpdateToastContentEventArgs) Handles ToastNotificationsManager1.UpdateToastContent

        Dim content As XmlDocument = e.ToastContent
        Dim toastElement As XmlElement = content.GetElementsByTagName("toast").OfType(Of XmlElement)().FirstOrDefault()
        toastElement.SetAttribute("launch", "performAction")
        Dim actions As XmlElement = content.CreateElement("actions")
        toastElement.AppendChild(actions)



        Dim action As XmlElement = content.CreateElement("action")
        'Send button
        actions.AppendChild(action)
        action.SetAttribute("content", "Send")
        action.SetAttribute("arguments", "Send")
        'Snooze button
        action = content.CreateElement("action")
        actions.AppendChild(action)
        action.SetAttribute("content", "Snooze")
        action.SetAttribute("arguments", "snooze")

    End Sub
    <Guid("74437357-e0bd-4a5b-8949-d5b02b0a92f6"), ComVisible(True)>
    Public Class ToastNotificationActivatorCustom
        Inherits DevExpress.XtraBars.ToastNotifications.ToastNotificationActivator

        Public Overrides Sub OnActivate(ByVal arguments As String, ByVal data As Dictionary(Of String, String))
            Dim sb As New StringBuilder()
            sb.AppendLine(arguments)
            For Each key As String In data.Keys
                sb.AppendLine(String.Format("{0} = {1}", key, data(key)))
            Next key
            MessageBox.Show(sb.ToString())
        End Sub
    End Class

    Private Sub BarButtonItem6_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItem6.ItemClick
        frmAttendanceCard1.MdiParent = Me
        frmAttendanceCard1.Show()
    End Sub

    Private Sub BarButtonItem7_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItem7.ItemClick
        frmAttendanceList1.MdiParent = Me
        frmAttendanceList1.Show()
    End Sub

    Private Sub BarButtonItem8_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItem8.ItemClick
        frmLeave1.MdiParent = Me
        frmLeave1.Show()
    End Sub

    Private Sub BarButtonItem9_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItem9.ItemClick
        frmListOfAvailedLeave1.MdiParent = Me
        frmListOfAvailedLeave1.Show()
    End Sub

    Private Sub BarButtonItem10_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItem10.ItemClick
        frmOvertime1.MdiParent = Me
        frmOvertime1.Show()
    End Sub

    Private Sub BarButtonItem11_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItem11.ItemClick
        frmListOfOvertimeEarnings1.MdiParent = Me
        frmListOfOvertimeEarnings1.Show()
    End Sub

    Private Sub BarButtonItem12_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItem12.ItemClick
        frmPayroll1.MdiParent = Me
        frmPayroll1.Show()
    End Sub

    Private Sub btyPayslip_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles btyPayslip.ItemClick
        frmPayslip1.MdiParent = Me
        frmPayslip1.Show()
    End Sub

    Private Sub RibbonControl_Click(sender As Object, e As EventArgs) Handles RibbonControl.Click

    End Sub

    Private Sub BarButtonItem5_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItem5.ItemClick
        frmSetting.MdiParent = Me
        frmSetting.Show()
    End Sub
End Class