Public Class frmProfileOverview

    Dim dataService As New PresentationServiceReference.UserServicesClient
    Public Event LoggedIn(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs)


    Private Sub frmProfileOverview_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Try

            AccountsDataGridView.RowHeadersDefaultCellStyle.SelectionBackColor = Color.Gray
            AccountsDataGridView.DefaultCellStyle.SelectionBackColor = Color.Gray
            RecipeHolderDatabaseDataSet.Merge(dataService.getAccountProfiles(False))
            AccountsDataGridView.DataSource = AccountsBindingSource

        Catch ex As DataException
            MessageBox.Show(ex.Message)
        Catch ex As SqlClient.SqlException
            MessageBox.Show(ex.Message)
        Catch ex As InvalidCastException
            MessageBox.Show(ex.Message)
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try

    End Sub

    Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
        Me.Close()
    End Sub

    Private Sub AccountsDataGridView_CellClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles AccountsDataGridView.CellClick
        Try

            'user clicks a profile
            'an accountID is saved 
            'this form is closed
            Dim accountId As Integer = 0
            accountId = CInt(AccountsDataGridView.CurrentRow.Cells("colAccountId").Value)
            dataService.setAccountID(accountId)
            modGlobals.CurrentAccountID = accountId
            modGlobals.IsLoggedIn = True
            RaiseEvent LoggedIn(sender, e)

            Me.Close()

        Catch ex As DataException
            MessageBox.Show(ex.Message)
        Catch ex As SqlClient.SqlException
            MessageBox.Show(ex.Message)
        Catch ex As InvalidCastException
            MessageBox.Show(ex.Message)
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub



End Class