miércoles, 23 de junio de 2010

Ejercicio Clase 22/06/2010

'Option Explicit On

'Option Strict On

Public Class Form1

    'Declaro a nivel global los vectores para:

    'nombre, tipo iva, y la CUIT

    Dim Nom() As String

    Dim tipoiva() As String

    Dim cuit() As Double

    '''''''''''''''''''''''''''''''''''''''''''

 

    Function ValidarNumeroDeCuit(ByVal Digitos1 As String, _

                                 ByVal Digitos2 As String, _

                                 ByVal Digitos3 As String) As Boolean

        'El primer conjunto de dígitos está formado por 2 números

        'El segundo   "      "   "      "      "     "  8 números

        'El tercer   "      "   "      "      "     "  1 número

 

        Dim Dig1 As Int16

        Dim Dig2 As Int16

        Dim Dig3 As Int16

        Dim Dig4 As Int16

        Dim Dig5 As Int16

        Dim Dig6 As Int16

        Dim Dig7 As Int16

        Dim Dig8 As Int16

        Dim Dig9 As Int16

        Dim Dig10 As Int16

 

        Dim vectorDeCaracteres() As Char

 

        vectorDeCaracteres = Digitos1.ToCharArray()

 

        Dig1 = Convert.ToInt16(vectorDeCaracteres(0).ToString)

        Dig2 = Convert.ToInt16(vectorDeCaracteres(1).ToString)

 

        vectorDeCaracteres = Digitos2.ToCharArray()

        Dig3 = Convert.ToInt16(vectorDeCaracteres(0).ToString)

        Dig4 = Convert.ToInt16(vectorDeCaracteres(1).ToString)

        Dig5 = Convert.ToInt16(vectorDeCaracteres(2).ToString)

        Dig6 = Convert.ToInt16(vectorDeCaracteres(3).ToString)

        Dig7 = Convert.ToInt16(vectorDeCaracteres(4).ToString)

        Dig8 = Convert.ToInt16(vectorDeCaracteres(5).ToString)

        Dig9 = Convert.ToInt16(vectorDeCaracteres(6).ToString)

        Dig10 = Convert.ToInt16(vectorDeCaracteres(7).ToString)

 

        Dim digitoverificador As Double = 0

 

        digitoverificador = (Dig1 * 5) + (Dig2 * 4)

 

    End Function

 

 

    Sub LimpiarUnTexBox(ByRef txt As TextBox)

        txt.Text = ""

    End Sub

 

    Function AgregarElementosAlVector() As Boolean

        Dim cantidadDeElementos As Integer

        Dim banderaEsElPrimerElemento As Boolean = False

        'verifico si el objeto ha sido instanciado

        If Nom Is Nothing Then 'el vector no tiene ningún elemento

            ReDim Nom(0)

            ReDim cuit(0)

            ReDim tipoiva(0)

            banderaEsElPrimerElemento = True

        End If

 

        For indiceDelVector As Integer = 0 To Nom.Length - 1

            If Nom(indiceDelVector) = Me.Texto.Text Then

                MsgBox("El nombre ingresado ya existe")

                Return False

            End If

        Next

 

        'Acordarse de la concatenación:

        'Dim s as string

        'Dim j as string

        'Dim a As string

        'Dim b AS string

        'j="juan"

        'a="alberto"

        'b="Badía"

        's = j &  a & b

 

        If banderaEsElPrimerElemento Then

            Nom(0) = Me.Texto.Text

            If Me.Combo1.Text <> "Consumidor Final" Then

                'tenemos que guardar la CUIT

                If ValidarNumeroDeCuit(Text1.Text, Text2.Text, Text3.Text) Then

                    cuit(0) = Text1.Text & Text2.Text & Text3.Text

                End If

            End If

        Else

            cantidadDeElementos = Nom.Length

            ReDim Preserve Nom(cantidadDeElementos)

            Nom(cantidadDeElementos) = Texto.Text

        End If

 

 

    End Function

 

 

    Private Sub Combo1_SelectedIndexChanged(ByVal sender As System.Object, _

                                            ByVal e As System.EventArgs) Handles Combo1.SelectedIndexChanged

 

        If Combo1.Text = "Consumidor Final" Then

            LimpiarUnTexBox(Text1)

            Text1.Enabled = False

            Text1.BackColor = Color.Silver

 

            LimpiarUnTexBox(Text2)

            Text2.Text = ""

            Text2.Enabled = False

            Text2.BackColor = Color.Silver

 

            LimpiarUnTexBox(Text3)

            Text3.Text = ""

            Text3.Enabled = False

            Text3.BackColor = Color.Silver

 

        Else

            Text1.Enabled = True

            Text1.BackColor = Color.White

 

            Text2.Enabled = True

            Text2.BackColor = Color.White

 

            Text3.Enabled = True

            Text3.BackColor = Color.White

 

        End If

 

    End Sub

 

 

 

 

 

 

    Private Sub Text1_KeyPress(ByVal sender As System.Object, _

                               ByVal e As System.Windows.Forms.KeyPressEventArgs) _

                               Handles Text1.KeyPress

 

        If Asc(e.KeyChar) = 8 Then 'controlo si ha ingresado el BackSpace (codigo Ascii N°8)

            Exit Sub

        End If

 

        Dim auxIntAscciCode = Asc(e.KeyChar)

 

        If Not (auxIntAscciCode >= CInt(System.Windows.Forms.Keys.D0) _

                AndAlso auxIntAscciCode <= CInt(System.Windows.Forms.Keys.D9)) Then

            'cambio el valor de la letra, por vacío

            e.KeyChar = ""

        End If

 

    End Sub

 

    'Item 5 del ejercicio (al presionar Enter en "Texto"...)

    Private Sub Texto_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Texto.KeyPress

        If Asc(e.KeyChar) = 13 Then

            Combo1.Focus()

        End If

    End Sub

 

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        'Validar

        If String.IsNullOrEmpty(Texto.Text.Trim) Then

            MsgBox("Debe Ingresar un nombre")

            Texto.Focus()

            Exit Sub

        End If

 

        If Combo1.Text <> "Consumidor Final" Then

            'Verifico que haya ingresado el IVA

            If String.IsNullOrEmpty(Text1.Text.Trim) Then

                MsgBox("Debe Ingresar El primer dígito de la CUIL")

                Text1.Focus()

                Exit Sub

            ElseIf Text1.Text.Trim.Length < 2 Then

                MsgBox("Debe Ingresar los dos dígitos de la CUIL")

                Text1.Focus()

                Exit Sub

            End If

 

            If String.IsNullOrEmpty(Text2.Text.Trim) Then

                MsgBox("Debe Ingresar El segundo dígito de la CUIL")

                Text2.Focus()

                Exit Sub

            ElseIf Text2.Text.Trim.Length < 8 Then

 

                Dim cantidadDeCaracteresIngresados As Int16 = Text2.Text.Trim.Length

                Dim cantDeCerosAAgregar As Int16 = 8 - cantidadDeCaracteresIngresados

 

                Dim Relleno As String = "00000000"

 

                Text2.Text = Relleno.Substring(0, cantDeCerosAAgregar) & Text2.Text

            End If

 

 

            If String.IsNullOrEmpty(Text3.Text.Trim) Then

                MsgBox("Debe Ingresar El Tercer dígito de la CUIL")

                Text3.Focus()

                Exit Sub

            End If

        End If

 

        Dim retornoAgregar As Boolean = True

 

        retornoAgregar = AgregarElementosAlVector()

 

    End Sub

 

    'EJEMPLOS VARIOS EN CLASE

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

    '    Dim digitos1 As String = "Manuel Belgrano 2010"

 

 

    '    Dim vectorDeCaracteres() As Char

    '    vectorDeCaracteres = digitos1.ToCharArray()

 

    '    For i As Integer = 0 To vectorDeCaracteres.Length - 1

    '        Dim resultadodelmensaje As Microsoft.VisualBasic.MsgBoxResult

 

    '        resultadodelmensaje = MsgBox("Esta mostrando el caracter: " & _

    '                                     vectorDeCaracteres(i) & _

    '                                     "¿Desea Continuar?", _

    '                                     MsgBoxStyle.YesNo, "mensaje si/no")

    '        If resultadodelmensaje = MsgBoxResult.No Then

    '            Exit For

    '        End If

    '    Next

 

 

    '    'Dim rdo As String = digitos1.Substring(0, 1) '

 

    '    'MsgBox("parametros (0,1) = " & rdo)

 

    '    'rdo = digitos1.Substring(7, 4) '

 

    '    'MsgBox("parametros (7, 4) = " & rdo)

 

 

    'End Sub

End Class

 

No hay comentarios:

Publicar un comentario