Imports System.Data.OleDb
Imports System.Threading
Public Class Form1

    Dim Count As Integer
    Dim BTune As Integer

    Private Sub Form1_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
        End
    End Sub

    Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        Try
            If e.CloseReason = CloseReason.UserClosing Then
                Dim Ans As String = ""
                Ans = MsgBox("Are you sure you want to close the DDNS Enterprise Client?", MsgBoxStyle.YesNo + MsgBoxStyle.Question)
                If Ans = vbYes Then

                    End
                Else

                    e.Cancel = True
                End If
            End If
        Catch
        End Try
    End Sub



    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
       
        NotifyIcon1.Icon = Me.Icon
        Dim mainwindow As New main
        Me.Panel3.Controls.Clear()
        Me.Panel3.Controls.Add(mainwindow)
        Hours = 0
        Minutes = 5
        Form2.Close()
 
    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Try



            ServiceController1.Refresh()
            If ServiceController1.Status.ToString = "Running" Then
                If BTune = 1 Then
                    NotifyIcon1.Icon = Me.Icon
                End If
                BTune = 0
                Count = 0
                ToolStripStatusLabel1.Image = ImageList1.Images.Item(0)
                ToolStripStatusLabel1.Text = "Client service active"
            ElseIf ServiceController1.Status.ToString = "Stopped" Then

                ToolStripStatusLabel1.Image = ImageList1.Images.Item(1)
                ToolStripStatusLabel1.Text = "Client service stopped"
                If Me.WindowState = FormWindowState.Minimized And Count = 0 Then
                    BTune = 1
                    Count = Count + 1
                    NotifyIcon1.Icon = Form2.Icon
                    NotifyIcon1.ShowBalloonTip(3, "DDNS Enterprise Client", "The DDNS Enterprise Windows Service has halted. Updates are suspended.", ToolTipIcon.None)
                End If
            End If
            If ServiceController1.Status.ToString = "StartPending" Then
                ToolStripStatusLabel1.Image = ImageList1.Images.Item(1)
                ToolStripStatusLabel1.Text = "Client service pending start"
            ElseIf ServiceController1.Status.ToString = "StopPending" Then
                ToolStripStatusLabel1.Image = ImageList1.Images.Item(1)
                ToolStripStatusLabel1.Text = "Client service pending stop"
            End If
        Catch
        End Try
     
    End Sub


    Private Sub Form1_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Resize
        If Me.WindowState = FormWindowState.Minimized Then
            NotifyIcon1.Visible = True
            Me.Hide()
        End If
        If Me.WindowState = FormWindowState.Normal Then
            NotifyIcon1.Visible = False

        End If
    End Sub

 
    Private Sub UnloadToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles UnloadToolStripMenuItem.Click
        Dim Ans As String = ""
        Ans = MsgBox("Are you sure you want to close the DDNS Enterprise Client?", MsgBoxStyle.YesNo + MsgBoxStyle.Question)
        If Ans = vbYes Then
            NotifyIcon1.Visible = False
            End
        End If


    End Sub

    Private Sub TestToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TestToolStripMenuItem.Click
        If Me.Visible = False Then
            Me.Visible = True
            Me.WindowState = FormWindowState.Normal
        End If
    End Sub

    Private Sub NotifyIcon1_MouseDoubleClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles NotifyIcon1.MouseDoubleClick
        If Me.Visible = False Then
            Me.Visible = True
            Me.WindowState = FormWindowState.Normal
        End If

    End Sub
 

    Private Sub Form1_Shown(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Shown

        Try
            Dim conn As OleDbConnection
            Dim SQL As OleDbCommand
            Dim RSet As OleDbDataReader
            Dim Res As String = ""
            conn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App_Path() & "progdb.mdb;")
            conn.Open()
            SQL = New OleDbCommand("select Minimize From Settings", conn)
            RSet = SQL.ExecuteReader
            If RSet.HasRows = False Then
            End If
            While RSet.Read
                Res = RSet("Minimize").ToString
            End While
            RSet.Close()
            conn.Close()
            If Res = True Then
                Form2.Close()
                Me.WindowState = FormWindowState.Minimized

            End If
        Catch
            MsgBox(Err.Description)
        End Try

    End Sub


    Private Sub LinkLabel6_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles LinkLabel6.LinkClicked
        
        Try


            

            Process.Start(Functions.App_Path + "/help.chm")

            
        Catch
            Functions.CreateError(Err.Description + " " + Err.Source, Err.Number)
        End Try
    End Sub

    Private Sub PictureBox2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox2.Click
        Dim domscreen As New Domains
        Me.Panel3.Controls.Clear()
        Me.Panel3.Controls.Add(domscreen)
    End Sub

    Private Sub PictureBox3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox3.Click
        Dim ipwindow As New IP
        Me.Panel3.Controls.Clear()
        Me.Panel3.Controls.Add(ipwindow)
    End Sub

    Private Sub PictureBox4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox4.Click
        Dim servicewindow As New Service
        Me.Panel3.Controls.Clear()
        Me.Panel3.Controls.Add(servicewindow)
    End Sub

    Private Sub PictureBox5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox5.Click
        Dim userwindow As New User
        Me.Panel3.Controls.Clear()
        Me.Panel3.Controls.Add(userwindow)
    End Sub

    Private Sub PictureBox6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox6.Click
        Dim mainwindow As New main
        Me.Panel3.Controls.Clear()
        Me.Panel3.Controls.Add(mainwindow)
    End Sub

    Private Sub PictureBox2_MouseHover(ByVal sender As Object, ByVal e As System.EventArgs) Handles PictureBox2.MouseHover
        Me.Cursor = Cursors.Hand
    End Sub

    Private Sub PictureBox2_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles PictureBox2.MouseLeave
        Me.Cursor = Cursors.Default
    End Sub

    Private Sub PictureBox3_MouseHover(ByVal sender As Object, ByVal e As System.EventArgs) Handles PictureBox3.MouseHover
        Me.Cursor = Cursors.Hand
    End Sub

    Private Sub PictureBox3_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles PictureBox3.MouseLeave
        Me.Cursor = Cursors.Default
    End Sub

    Private Sub PictureBox4_MouseHover(ByVal sender As Object, ByVal e As System.EventArgs) Handles PictureBox4.MouseHover
        Me.Cursor = Cursors.Hand
    End Sub

    Private Sub PictureBox4_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles PictureBox4.MouseLeave
        Me.Cursor = Cursors.Default
    End Sub

    Private Sub PictureBox5_MouseHover(ByVal sender As Object, ByVal e As System.EventArgs) Handles PictureBox5.MouseHover
        Me.Cursor = Cursors.Hand
    End Sub

    Private Sub PictureBox5_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles PictureBox5.MouseLeave
        Me.Cursor = Cursors.Default
    End Sub

    Private Sub PictureBox6_MouseHover(ByVal sender As Object, ByVal e As System.EventArgs) Handles PictureBox6.MouseHover
        Me.Cursor = Cursors.Hand
    End Sub

    Private Sub PictureBox6_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles PictureBox6.MouseLeave
        Me.Cursor = Cursors.Default
    End Sub
End Class
