|
'///////////////////////////////////////////
'Form to facilitate settings in the application.
'I am using built in vs 2005 settings for
'most of the settings in the application
'other than search providers and feeds.
'///////////////////////////////////////////
Imports System.Enum
Imports System.Data.OleDb
Public Class frmSettings
Private Sub frmSettings_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
LoadBlockedSites()
LoadSearchProviders()
LoadPopUpSettings()
LoadPopAllowed()
LoadAdditional()
End Sub
#Region " Popup Blocker Settings "
Private Sub LoadPopUpSettings()
chkAllowPop.Checked = My.Settings.PopUpBlockerEnabled
chkPopSound.Checked = My.Settings.PopSound
chkPopInfo.Checked = My.Settings.PopInfoBar
End Sub
Private Sub LoadPopAllowed()
lbPop.Items.Clear()
Dim li As ListItem
Dim s As String
For Each s In My.Settings.AllowedPopSites
li = New ListItem
li.Text = s
lbPop.Items.Add(li)
Next
End Sub
Private Sub chkAllowPop_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkAllowPop.CheckedChanged
My.Settings.PopUpBlockerEnabled = chkAllowPop.Checked
End Sub
Private Sub chkPopSound_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkPopSound.CheckedChanged
My.Settings.PopSound = chkPopSound.Checked
End Sub
Private Sub chkPopInfo_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkPopInfo.CheckedChanged
My.Settings.PopInfoBar = chkPopInfo.Checked
End Sub
Private Sub btnPopAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPopAdd.Click
If txtPop.Text = "" Then
'Do nothing
Else
My.Settings.AllowedPopSites.Add(AppManager.FixURL(txtPop.Text))
txtPop.Text = String.Empty
LoadPopAllowed()
End If
End Sub
Private Sub btnPopRemove_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPopRemove.Click
Dim li As ListItem
If lbPop.SelectedItems.Count > 0 Then
For Each li In lbPop.SelectedItems
My.Settings.AllowedPopSites.Remove(li.Text)
Next
LoadPopAllowed()
End If
End Sub
Private Sub btnPopRemoveAll_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPopRemoveAll.Click
My.Settings.AllowedPopSites.Clear()
lbPop.Items.Clear()
End Sub
#End Region
#Region " Blocked Sites "
Private Sub LoadBlockedSites()
lbBlocked.Items.Clear()
Dim s As String
For Each s In My.Settings.BlockedSites
lbBlocked.Items.Add(s)
Next
End Sub
Private Sub btnAddBlock_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAddBlock.Click
If txtBlock.Text = "" Then
'Do nothing
Else
My.Settings.BlockedSites.Add(AppManager.FixURL(txtBlock.Text))
LoadBlockedSites()
txtBlock.Text = String.Empty
End If
End Sub
Private Sub btnBlockRemoveAll_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBlockRemoveAll.Click
Dim s As String
For Each s In My.Settings.BlockedSites
My.Settings.BlockedSites.Remove(s)
Next
LoadBlockedSites()
End Sub
Private Sub btnRemoveBlock_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRemoveBlock.Click
If lbBlocked.SelectedIndices.Count > 0 Then
My.Settings.BlockedSites.Remove(lbBlocked.SelectedItem)
LoadBlockedSites()
End If
End Sub
#End Region
#Region " Search Providers "
Private Sub LoadSearchProviders()
lvSearchProviders.Items.Clear()
Dim strSQL As String = _
"Select ID, ProviderTitle, ProviderURL, IsDefault FROM SearchProviders ORDER BY ProviderTitle"
Dim oConn As New OleDb.OleDbConnection(AppManager.ConnString)
Dim oDa As New OleDb.OleDbDataAdapter(strSQL, oConn)
Dim dt As New DataTable
Dim dr As DataRow
Dim li As ListViewItem
Dim si As ListViewItem.ListViewSubItem
Try
oDa.Fill(dt)
For Each dr In dt.Rows
li = New ListViewItem
li.Tag = dr.Item("ID")
li.SubItems.Add(dr.Item("ProviderURL"))
si = New ListViewItem.ListViewSubItem
If dr.Item("IsDefault") = True Then
li.Text = dr.Item("ProviderTitle") & " - (Default)"
li.Checked = True
li.Font = New Font(li.Font.Name, li.Font.Size, FontStyle.Bold, li.Font.Unit)
Else
li.Text = dr.Item("ProviderTitle")
li.Checked = False
End If
'li.SubItems.Add(si)
lvSearchProviders.Items.Add(li)
Next
Catch ex As Exception
MsgBox(ex.Message.ToString)
Finally
End Try
End Sub
Private Sub cmSearch_Opening(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles cmSearch.Opening
If lvSearchProviders.Items.Count = 0 Then
cmSearchRemove.Enabled = False
Else
cmSearchRemove.Enabled = True
End If
End Sub
Private Sub cmSearchRemove_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmSearchRemove.Click
RemoveSearchProvider()
End Sub
Private Sub RemoveSearchProvider()
Dim strSQL As String = "DELETE FROM SearchProviders WHERE ID=" & _
CInt(lvSearchProviders.SelectedItems(0).Tag)
Dim oConn As New OleDb.OleDbConnection(AppManager.ConnString)
Dim oCmd As New OleDbCommand(strSQL, oConn)
Try
oConn.Open()
oCmd.ExecuteNonQuery()
oConn.Close()
LoadSearchProviders()
AppManager.MainForm.LoadSearchProviders()
Catch ex As Exception
Dim ofrm As New frmError
ofrm.err = ex
ofrm.ShowDialog(Me)
End Try
End Sub
Private Sub btnAddProvider_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAddProvider.Click
If chkSearchDefault.Checked Then
SetDefault()
End If
AddProvider()
End Sub
Private Sub AddProvider()
'In this example application, we do not care if a user adds more than 1
'of the same provider, so we will not check for that.
Dim oConn As New OleDbConnection(AppManager.ConnString)
Dim strSQL As String = _
"INSERT INTO SearchProviders (ProviderTitle, ProviderURL, IsDefault) VALUES " & _
"('" & txtSearchTitle.Text & _
"', '" & txtSearchURL.Text & _
"', " & chkSearchDefault.Checked & ")"
Dim oCmd As New OleDbCommand(strSQL, oConn)
Try
oConn.Open()
oCmd.ExecuteNonQuery()
oConn.Close()
AppManager.MainForm.LoadSearchProviders()
LoadSearchProviders()
Catch ex As Exception
MsgBox(ex.Message.ToString)
End Try
End Sub
Private Sub SetDefault()
Dim strSQL As String = "Update SearchProviders Set IsDefault=False"
Dim oConn As New OleDbConnection(AppManager.ConnString)
Dim oCmd As New OleDbCommand(strSQL, oConn)
Try
oConn.Open()
oCmd.ExecuteNonQuery()
oConn.Close()
Catch ex As Exception
MsgBox(ex.Message.ToString)
Finally
oConn.Dispose()
oCmd.Dispose()
End Try
End Sub
#End Region
#Region " Integrations "
Private Sub LoadAdditional()
chkInternal.Checked = My.Settings.UseInternalMenu
chkShowTags.Checked = My.Settings.ShowTags
chkSupress.Checked = My.Settings.SupressScriptErrs
End Sub
Private Sub chkInternal_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkInternal.CheckedChanged
My.Settings.UseInternalMenu = chkInternal.Checked
Dim ofrm As frmBrowser
Dim i As Integer
For i = 0 To AppManager.MainForm.tc1.TabPages.Count - 1
If TypeOf AppManager.MainForm.tc1.TabPages.Item(i).Form Is frmBrowser Then
ofrm = AppManager.MainForm.tc1.TabPages.Item(i).Form
ofrm.wb.IsWebBrowserContextMenuEnabled = Not (chkInternal.Checked)
End If
Next
End Sub
Private Sub chkShowTags_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkShowTags.CheckedChanged
My.Settings.ShowTags = chkShowTags.Checked
End Sub
Private Sub chkSupress_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkSupress.CheckedChanged
My.Settings.SupressScriptErrs = chkSupress.Checked
Dim ofrm As frmBrowser
Dim i As Integer
For i = 0 To AppManager.MainForm.tc1.TabPages.Count - 1
If TypeOf AppManager.MainForm.tc1.TabPages.Item(i).Form Is frmBrowser Then
ofrm = AppManager.MainForm.tc1.TabPages.Item(i).Form
ofrm.wb.ScriptErrorsSuppressed = chkInternal.Checked
End If
Next
End Sub
#End Region
Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click
Me.Close()
End Sub
Private Sub chkUseDLManager_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkUseDLManager.CheckedChanged
My.Settings.UseDLManager = chkUseDLManager.Checked
End Sub
End Class
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.
A list of licenses authors might use can be found here
I have played various roles in IT since around 1993 when I began writing commercial web pages. I then moved to mainly coding in Visual Basic around 1995, making point of sale and kiosk systems, more recently moving to e-commerce and crm applications. Since the release of .net I have been mainly working in .net focusing in vb.net although I have done several projects in c#. I have worked for various companies and have held the position of lead developer at several, recently (2005) leading the e-commerce team at a national retailer to a successful e-commerce implementation. I currently hold comptia a+, network plus, mcp, mcsa, mcse (server system 2003) and mcsd certifications. I enjoy sharing what I have learned as well as embracing new technologies as they are released.