Aplicación Nº 7 (Ingreso de datos)

Elaborar una aplicación que permita ingresar los datos de una persona, guardar los datos en una lista y mostrarlos en un ListBox, Sobrescribiendo el método ToString de la clase Persona, los atributos de esta clase son:

Nombre, Apellido, edad, Sexo (enumerado) Y los atributos Intereses que son de tipo Booleano: Cine, Deportes E Internet, utilizar un ImputBox Para el ingreso de la edad, Y un Messagebox para confirmar la operación de cancelación. Realizar Un método estatico “Limpiar” que borrará los valores de todos los controles, este método se llamara después de cargar los datos en la lista y al cancelar la operación.

Septimo Programa

Public Class Form1

    Dim persona_Nueva As Persona_ = New Persona_()

    Private Sub RadioButton1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton1.CheckedChanged
        persona_Nueva.sexo = Persona_._sexo.Masculino
    End Sub

    Private Sub RadioButton2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton2.CheckedChanged
        persona_Nueva.sexo = Persona_._sexo.Femenino
    End Sub
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Persona_.Limpiar()
    End Sub
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        TextBox3.Text = InputBox("Ingrese edad")
    End Sub

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

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        persona_Nueva.Apellido = TextBox2.Text
        persona_Nueva.Nombre = TextBox1.Text
        If TextBox3.Text <> "" Then
            persona_Nueva.Edad = Byte.Parse(TextBox3.Text)
        End If

        persona_Nueva.Cine = CheckBox2.Checked
        persona_Nueva.Deporte = CheckBox3.Checked
        persona_Nueva.Internet = CheckBox1.Checked

        TextBox4.Text = (persona_Nueva.ToString()) 'mostar en listbox
    End Sub

    Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
        persona_Nueva.Internet = CheckBox1.Checked
    End Sub

    Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
        persona_Nueva.ocupacion = ComboBox1.SelectedItem.ToString
    End Sub

    Private Sub CheckBox3_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox3.CheckedChanged
        persona_Nueva.Cine = CheckBox2.Checked
    End Sub
End Class

--------------------------------------------------------------------------------------

Imports System.Text
Public Class Persona_

    Dim cadena As StringBuilder

    Enum _sexo
        Masculino
        Femenino
    End Enum
    Public sexo As _sexo

    Private _nombre As String
    Public Property Nombre() As String
        Get
            Return _nombre
        End Get
        Set(ByVal value As String)
            _nombre = value
        End Set
    End Property

    Private _apellido As String
    Public Property Apellido() As String
        Get
            Return _apellido
        End Get
        Set(ByVal value As String)
            _apellido = value
        End Set
    End Property

    Private _ocupacion As String
    Public Property ocupacion() As String
        Get
            Return _ocupacion
        End Get
        Set(ByVal value As String)
            _ocupacion = value
        End Set
    End Property

    Private _cine As Boolean
    Public Property Cine() As Boolean
        Get
            Return _cine
        End Get
        Set(ByVal value As Boolean)
            _cine = value
        End Set
    End Property

    Private _deporte As Boolean
    Public Property Deporte() As Boolean
        Get
            Return _deporte
        End Get
        Set(ByVal value As Boolean)
            _deporte = value
        End Set
    End Property

    Private _internet As Boolean
    Public Property Internet() As Boolean
        Get
            Return _internet
        End Get
        Set(ByVal value As Boolean)
            _internet = value
        End Set
    End Property

    Private _edad As Byte
    Public Property Edad() As Byte
        Get
            Return _edad
        End Get
        Set(ByVal value As Byte)
            _edad = value
        End Set
    End Property

    Public Shared Sub Limpiar() 'shared...metodo estatico

        Form1.TextBox1.Text = ""
        Form1.TextBox2.Text = ""
        Form1.TextBox3.Text = ""
        Form1.TextBox4.Text = ""

        Form1.RadioButton1.Checked = False
        Form1.RadioButton2.Checked = False

        Form1.CheckBox1.Checked = False
        Form1.CheckBox2.Checked = False
        Form1.CheckBox3.Checked = False

    End Sub

    Public Overrides Function ToString() As String
        Dim cadena As StringBuilder = New StringBuilder

        cadena.AppendLine("Nombre: " & Me.Nombre)
        cadena.AppendLine("Apellido: " & Me.Apellido)
        cadena.AppendLine("Ocupación: " & Me.ocupacion)
        cadena.AppendLine("Edad: " & Me.Edad)
        cadena.AppendLine("Sexo: " & Me.sexo.ToString)

        If Me.Internet = True Or Me.Cine = True Or Me.Deporte = True Then
            cadena.AppendLine("Intereses:")

            If Me.Internet = True Then
                cadena.AppendLine("Internet")
            End If
            If Me.Deporte = True Then
                cadena.AppendLine("Deporte")
            End If
            If Me.Cine = True Then
                cadena.AppendLine("Cine")
            End If

        End If

        Return cadena.ToString
    End Function

End Class

Septimo Programa - Parte 2

Septimo Programa - Parte 3

0 comentarios:

Publicar un comentario