Imports System.Data.SqlServerCe
Public Class APC
Private Dcn As SqlCeConnection
Private Drc As SqlCeCommand
Private Dse As SqlCeEngine
Private Sub APC_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
TextBox.PasswordChar = "*"
TextBox.Focus()
End Sub
Private Sub Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button.Click
Cursor.Current = Cursors.WaitCursor
If TextBox.PasswordChar = "*" Then
Dim dcn As New SqlCeConnection
Dim booNotFound As Boolean
dcn.ConnectionString = "DataSource=\My Documents\Business\APC.sdf; Password=" & TextBox.Text
Try
dcn.Open()
TextBox.PasswordChar = ""
Catch ex As SqlCeException
If ex.NativeError = 25046 Then
booNotFound = True
Else
MsgBox(ex.Message)
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
If booNotFound Then
Dim dse As New SqlCeEngine("DataSource=\My Documents\Business\APC.sdf; Password=" & TextBox.Text)
Try
dse.CreateDatabase()
If LoadDatabase() = False Then
System.IO.File.Delete("\My Documents\Business\APC.sdf")
Cursor.Current = Cursors.Default
MsgBox("Database did not sync!")
Me.Close()
Exit Sub
End If
TextBox.PasswordChar = ""
Catch ex As Exception
MsgBox(ex.Message)
End Try
End If
If TextBox.PasswordChar = "*" Then
TextBox.SelectAll()
TextBox.Focus()
Else
TextBox.Text = ""
Label.Text = "Last Name"
End If
End If
Cursor.Current = Cursors.Default
End Sub
Private Function LoadDatabase() As Boolean
LoadDatabase = False
' code goes here to sync database with network SQL server
End Function
Private Sub TextBox_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox.GotFocus
InputPanel.Enabled = True
End Sub
Private Sub TextBox_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox.LostFocus
InputPanel.Enabled = False
End Sub
End Class