Imports System.Data.OleDb
Imports Microsoft.Win32
Public Class Service

    Private Sub Panel3_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Panel3.Paint

    End Sub

    Private Sub Service_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim conn As OleDbConnection
        Dim SQL As OleDbCommand
        Dim RSet As OleDbDataReader
        Try
           
            Dim regKey As RegistryKey
            Dim RegRead As String = ""
            regKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\Run", True)
            If Not regKey Is Nothing Then
                RegRead = (regKey.GetValue("DDNS-Enterprise"))
            End If
            regKey.Close()

            If RegRead = Functions.App_Path + "DDNS.exe" Then CheckBox1.Checked = True
            If Not RegRead = Functions.App_Path + "DDNS.exe" Then CheckBox2.Checked = True




            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
                If RSet("Minimize").ToString = True Then CheckBox3.Checked = True
                If RSet("Minimize").ToString = False Then CheckBox4.Checked = True
            End While
            RSet.Close()
            conn.Close()




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

    Private Sub GroupBox2_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GroupBox2.Enter

    End Sub

    Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
        If CheckBox1.Checked = True Then CheckBox2.Checked = False
    End Sub

    Private Sub CheckBox2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox2.CheckedChanged
        If CheckBox2.Checked = True Then CheckBox1.Checked = False
    End Sub

    Private Sub CheckBox3_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox3.CheckedChanged
        If CheckBox3.Checked = True Then CheckBox4.Checked = False
    End Sub

    Private Sub CheckBox4_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox4.CheckedChanged
        If CheckBox4.Checked = True Then CheckBox3.Checked = False
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        ServiceController1.Start()

    End Sub



    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        ServiceController1.Stop()

    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
                Label3.Text = "Running"
                Button1.Enabled = False
                Label6.Visible = False
                Button3.Enabled = True
            ElseIf ServiceController1.Status.ToString = "Stopped" Then
                Label3.Text = "Stopped"
                Button1.Enabled = True
                Label6.Visible = True
                Button3.Enabled = False
            End If
            If ServiceController1.Status.ToString = "StartPending" Then
                Label3.Text = "Start Pending"
                Button1.Enabled = False
                Label6.Visible = True
                Button3.Enabled = False
            ElseIf ServiceController1.Status.ToString = "StopPending" Then
                Label3.Text = "Stop Pending"
                Button1.Enabled = False
                Label6.Visible = True
                Button3.Enabled = False
            End If
        Catch
        End Try
    End Sub




    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        Dim conn As OleDbConnection
        Dim SQL As OleDbCommand
        Dim RSet As OleDbDataReader
        Dim MinorNot As Boolean

        Try
            Dim regKey As RegistryKey
            Dim RegRead As String = ""
            regKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\Run", True)
            If Not regKey Is Nothing Then
                RegRead = regKey.GetValue("DDNS-Enterprise")
                If CheckBox1.Checked = True Then regKey.SetValue("DDNS-Enterprise", Functions.App_Path + "DDNS.exe")
                If CheckBox2.Checked = True And Not RegRead = "" Then regKey.DeleteValue("DDNS-Enterprise")
            End If
            regKey.Close()
            If CheckBox3.Checked = True Then MinorNot = True
            If CheckBox4.Checked = True Then MinorNot = False
            conn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App_Path() & "progdb.mdb;")
            conn.Open()
            SQL = New OleDbCommand("UPDATE Settings SET Minimize = " & MinorNot.ToString & "", conn)
            RSet = SQL.ExecuteReader

            RSet.Close()
            conn.Close()
        Catch
            MsgBox(Err.Description + " " + Err.Source, Err.Number)
        End Try
    End Sub
End Class
