Imports System.Data.OleDb
Public Class Domains


    Private Sub Domains_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
        If Label6.Text = "*URL*" Then Label6.Text = ""
        Try
            ListView1.View = View.Details
            ListView1.SmallImageList = ImageList1
            Dim lSingleItem As ListViewItem

            conn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App_Path() & "progdb.mdb;")
            conn.Open()
            SQL = New OleDbCommand("select URL, IP, Method From Domains", conn)


            RSet = SQL.ExecuteReader
            'If RSet.HasRows = False Then
            'End If
            While RSet.Read

                lSingleItem = ListView1.Items.Add(RSet("URL").ToString, 0)
                lSingleItem.SubItems.Add(RSet("IP").ToString)
                lSingleItem.SubItems.Add(RSet("Method").ToString)

            End While
            RSet.Close()
            conn.Close()
        Catch
            Functions.CreateError(Err.Description + " " + Err.Source, Err.Number)
        End Try

        Try


            conn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App_Path() & "progdb.mdb;")
            conn.Open()
            SQL = New OleDbCommand("select Hours, Minutes From Settings", conn)


            RSet = SQL.ExecuteReader
            If RSet.HasRows = False Then
            End If
            While RSet.Read

                ComboBox1.Text = RSet("Hours").ToString
                ComboBox2.Text = RSet("Minutes").ToString


            End While
            RSet.Close()
            conn.Close()
        Catch
            Functions.CreateError(Err.Description + " " + Err.Source, Err.Number)
        End Try
        Try


            conn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App_Path() & "progdb.mdb;")
            conn.Open()
            SQL = New OleDbCommand("select Ident From IP_Detection", conn)


            RSet = SQL.ExecuteReader
            If RSet.HasRows = False Then
            End If
            While RSet.Read

                ComboBox3.Text = "Default Detection Method"
                ComboBox3.Items.Add(RSet("Ident").ToString)



            End While
            RSet.Close()
            conn.Close()
            If ListView1.Items.Count = 0 Then
                LinkLabel2.Visible = True
            Else
                LinkLabel2.Visible = False
            End If
        Catch
            Functions.CreateError(Err.Description + " " + Err.Source, Err.Number)
        End Try


    End Sub

    Private Sub ListView1_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ListView1.MouseClick
        Dim Entry As String = ""
        Entry = ListView1.SelectedItems(0).Text.ToString
        If ListView1.SelectedItems.Count <= 0 Then
            Exit Sub
        End If
        DetMeth(Entry)
    End Sub
    Private Function DetMeth(ByVal URL As String) As Boolean
        Dim conn As OleDbConnection
        Dim SQL As OleDbCommand
        Dim RSet As OleDbDataReader
        Try


            conn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App_Path() & "progdb.mdb;")
            conn.Open()
            SQL = New OleDbCommand("select Method From Domains Where URL = '" + URL + "'", conn)


            RSet = SQL.ExecuteReader
            If RSet.HasRows = False Then
            End If
            While RSet.Read

                Label6.Text = URL
                ComboBox3.Text = RSet("Method").ToString
                ComboBox3.Refresh()


            End While
            RSet.Close()
            conn.Close()
        Catch
            Functions.CreateError(Err.Description + " " + Err.Source, Err.Number)
        End Try
    End Function

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim conn As OleDbConnection
        Dim SQL As OleDbCommand
        Dim RSet As OleDbDataReader
        Try
            conn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App_Path() & "progdb.mdb;")
            conn.Open()
            SQL = New OleDbCommand("UPDATE Settings SET Hours = '" + ComboBox1.Text + "', Minutes = '" + ComboBox2.Text + "'", conn)
            RSet = SQL.ExecuteReader
            RSet.Close()
            conn.Close()
        Catch
            Functions.CreateError(Err.Description + " " + Err.Source, Err.Number)
        End Try
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

        If Not My.Computer.Network.IsAvailable = True Then
            MsgBox("This feature is not available offline.", MsgBoxStyle.Information)
            Exit Sub
        End If

        Dim conn As OleDbConnection
        Dim SQL As OleDbCommand
        Dim RSet As OleDbDataReader
        Try
            Me.Cursor = Cursors.WaitCursor
            conn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App_Path() & "progdb.mdb;")
            conn.Open()
            SQL = New OleDbCommand("UPDATE Domains SET Method = '" + ComboBox3.Text + "' Where URL = '" + Label6.Text + "'", conn)
            RSet = SQL.ExecuteReader
            RSet.Close()
            conn.Close()
        Catch
            Functions.CreateError(Err.Description + " " + Err.Source, Err.Number)
            Me.Cursor = Cursors.Arrow
        End Try
        ListView1.Items.Clear()


        Try
            Send_Updates()
            ReadDoms()
            Dim lSingleItem As ListViewItem

            conn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App_Path() & "progdb.mdb;")
            conn.Open()
            SQL = New OleDbCommand("select URL, IP, Method From Domains", conn)


            RSet = SQL.ExecuteReader
            'If RSet.HasRows = False Then
            'End If
            While RSet.Read

                lSingleItem = ListView1.Items.Add(RSet("URL").ToString, 0)
                lSingleItem.SubItems.Add(RSet("IP").ToString)
                lSingleItem.SubItems.Add(RSet("Method").ToString)

            End While
            RSet.Close()
            conn.Close()
            ListView1.Refresh()
            Me.Cursor = Cursors.Arrow
        Catch
            Me.Cursor = Cursors.Arrow
            Functions.CreateError(Err.Description + " " + Err.Source, Err.Number)
        End Try
    End Sub

    Private Sub LinkLabel1_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles LinkLabel1.LinkClicked
        Dim conn As OleDbConnection
        Dim SQL As OleDbCommand
        Dim RSet As OleDbDataReader

        Try


            conn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App_Path() & "progdb.mdb;")
            conn.Open()
            SQL = New OleDbCommand("select Server, UserID From Settings", conn)


            RSet = SQL.ExecuteReader
            If RSet.HasRows = False Then
            End If
            While RSet.Read

                Process.Start(RSet("Server").ToString + "/logon.asp?user=" + RSet("UserID").ToString)

            End While
            RSet.Close()
            conn.Close()
        Catch
            Functions.CreateError(Err.Description + " " + Err.Source, Err.Number)
        End Try



    End Sub

    Private Sub LinkLabel2_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles LinkLabel2.LinkClicked
        If Not My.Computer.Network.IsAvailable = True Then
            MsgBox("This feature is not available offline.", MsgBoxStyle.Information)
            Exit Sub
        End If

        Dim conn As OleDbConnection
        Dim SQL As OleDbCommand
        Dim RSet As OleDbDataReader

        Try
            Me.Cursor = Cursors.WaitCursor
            Send_Updates()
            ReadDoms()
            Dim lSingleItem As ListViewItem

            conn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App_Path() & "progdb.mdb;")
            conn.Open()
            SQL = New OleDbCommand("select URL, IP, Method From Domains", conn)


            RSet = SQL.ExecuteReader
            'If RSet.HasRows = False Then
            'End If
            While RSet.Read

                lSingleItem = ListView1.Items.Add(RSet("URL").ToString, 0)
                lSingleItem.SubItems.Add(RSet("IP").ToString)
                lSingleItem.SubItems.Add(RSet("Method").ToString)

            End While
            RSet.Close()
            conn.Close()
            ListView1.Refresh()
            If ListView1.Items.Count = 0 Then
                LinkLabel2.Visible = True
            Else
                LinkLabel2.Visible = False
            End If
            Me.Cursor = Cursors.Arrow
        Catch
            Me.Cursor = Cursors.Arrow
            Functions.CreateError(Err.Description + " " + Err.Source, Err.Number)
        End Try
    End Sub

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

    End Sub
End Class
