Partial Public Class winAddPersonalInfomation

    Private Sub winAddPersonalData_Loaded(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles MyBase.Loaded

        'add items in comboboxes and select the first item
        For Each item In [Enum].GetNames(GetType(PersonalProfile.enumGender))
            cbGender.Items.Add(item)
            cbGender.SelectedIndex = 0
        Next

        For Each item In [Enum].GetNames(GetType(PersonalProfile.enumEyeColor))
            cbEyeColor.Items.Add(item)
            cbEyeColor.SelectedIndex = 0
        Next

        For Each item In [Enum].GetNames(GetType(PersonalProfile.enumHairColor))
            cbHairColor.Items.Add(item)
            cbHairColor.SelectedIndex = 0
        Next

        For Each item In [Enum].GetNames(GetType(PersonalProfile.enumBloodType))
            Select Case item
                Case "Opositive"
                    cbBloodType.Items.Add("O Positive")
                Case "Onegative"
                    cbBloodType.Items.Add("O Negative")
                Case "Apositive"
                    cbBloodType.Items.Add("A Positive")
                Case "Anegative"
                    cbBloodType.Items.Add("A Negative")
                Case "Bpositive"
                    cbBloodType.Items.Add("B Positive")
                Case "Bnegative"
                    cbBloodType.Items.Add("B Negative")
                Case "ABpositive"
                    cbBloodType.Items.Add("AB Positive")
                Case "ABnegative"
                    cbBloodType.Items.Add("AB Negative")
                Case "DontKnow"
                    cbBloodType.Items.Add("Dont Know")
                Case "Other"
                    cbBloodType.Items.Add("Other")

            End Select
        Next
        cbBloodType.SelectedIndex = 0

    End Sub

    Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles btnSave.Click
        Dim profileToSave As New PersonalProfile
        Dim profilesToSave As New ArrayList

        'if the data entered is not blank then proceed
        If Not (msktxtBirthDate.Text = "" OrElse txtCity.Text = "" OrElse txtFirstName.Text = "" OrElse msktxtHeight.Text = "" OrElse txtLastName.Text = "" OrElse txtMedicalConditions.Text = "" _
        OrElse msktxtPhoneNumber.Text = "" OrElse txtState.Text = "" OrElse txtStreetName.Text = "" OrElse txtWeight.Text = "" OrElse msktxtZipCode.Text = "") Then

            'if the data is numeric for fields that apply then proceed
            If IsNumeric(txtWeight.Text) OrElse IsNumeric(msktxtZipCode.Text) OrElse IsNumeric(msktxtPhoneNumber.Text) OrElse _
            IsNumeric(msktxtHeight.Text) Then

                'if date field is a valid date then proceed
                If IsDate(msktxtBirthDate.Text) Then

                    'save entered data into a PersonalProfile class
                    profileToSave.FirstName = txtFirstName.Text
                    profileToSave.LastName = txtLastName.Text
                    profileToSave.StreetAddress = txtStreetName.Text
                    profileToSave.City = txtCity.Text
                    profileToSave.State = txtState.Text
                    profileToSave.ZipCode = CLng(msktxtZipCode.Text)
                    profileToSave.PhoneNumber = CLng(msktxtPhoneNumber.Text.Chars(1) & msktxtPhoneNumber.Text.Chars(2) & msktxtPhoneNumber.Text.Chars(3) _
                    & msktxtPhoneNumber.Text.Chars(6) & msktxtPhoneNumber.Text.Chars(7) & msktxtPhoneNumber.Text.Chars(8) & msktxtPhoneNumber.Text.Chars(10) _
                    & msktxtPhoneNumber.Text.Chars(11) & msktxtPhoneNumber.Text.Chars(12) & msktxtPhoneNumber.Text.Chars(13))
                    profileToSave.BirthDate = CDate(msktxtBirthDate.Text)
                    profileToSave.Weight = CDbl(txtWeight.Text)
                    profileToSave.Height = CInt(msktxtHeight.Text.Chars(0) & msktxtHeight.Text.Chars(2) & msktxtHeight.Text.Chars(3))
                    profileToSave.MedicalConditions = txtMedicalConditions.Text
                    profileToSave.Gender = cbGender.SelectedIndex
                    profileToSave.EyeColor = cbEyeColor.SelectedIndex
                    profileToSave.HairColor = cbHairColor.SelectedIndex
                    profileToSave.BloodType = cbBloodType.SelectedIndex

                    'add the profile to an array
                    profilesToSave.Add(profileToSave)
                    'serialize the array
                    modSerialization.serializeClass(profilesToSave, modGlobal.strXmlFilePath)
                    Dim winAddPro As New winAddedProfile
                    winAddPro.Show()
                    System.Threading.Thread.Sleep(400)
                    winAddPro.Close()
                    clearTextBoxes()
                    modGlobal.cApplicationWindows.winViewPersonalProfiles.setListViewBindings()
                    modGlobal.cApplicationWindows.winViewPersonalProfiles.refreshDataSource()
                Else
                    MessageBox.Show("Birth date has to be a valid date")
                End If
            Else
                MessageBox.Show("Numeric data has to be numerical")
            End If
        Else
            MessageBox.Show("Data can not be left empty")
        End If
    End Sub

    Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles btnCancel.Click
        Me.Close()
    End Sub

    Private Sub winAddPersonalInfomation_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles Me.Closing
        modGlobal.cApplicationWindows.winViewPersonalProfiles.setListViewBindings()
        modGlobal.cApplicationWindows.winViewPersonalProfiles.refreshDataSource()
        modGlobal.cApplicationWindows.winAddPersonalProfile = Nothing

    End Sub

    Public Sub clearTextBoxes()
        cbBloodType.SelectedIndex = 0
        cbEyeColor.SelectedIndex = 0
        cbGender.SelectedIndex = 0
        cbHairColor.SelectedIndex = 0
        txtFirstName.Focus()
        txtFirstName.Text = ""
        txtLastName.Text = ""
        txtStreetName.Text = ""
        txtCity.Text = ""
        txtState.Text = ""
        msktxtZipCode.Text = ""
        msktxtPhoneNumber.Text = ""
        msktxtBirthDate.Text = ""
        txtWeight.Text = ""
        msktxtHeight.Text = ""
        txtMedicalConditions.Text = ""
    End Sub

    Private Sub winAddPersonalData_Loaded_1(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles winAddPersonalData.Loaded

    End Sub
End Class
