CJYARLEQuE-SYSTEM

domingo, 10 de octubre de 2010

Estructuras y Arreglos en vb.net

Este es un tema de VisualBasic.net  almacenando datos sin necesidad de conectarse a una Base de datos

1.-En el Modulo programar lo siguiente:

Module Module1

    Public Structure regi
        Public Cliente As String
        Public pelicula As String
        Public f_ini As String
        Public dias As String
        Public f_fin As String
        Public costo As String
        Public total As String
    End Structure
---------------------------------------------
    Public sw As Boolean
    Public indice As Integer
    Public registro() As regi
    Public registros(0) As regi
End Module

2..-En el Form1

Public Class Form1

    'Dim alqui As alquiler
    Dim i As Integer = 0
    Dim a As Integer = 10
    Public cadena As String = "ABCDEFGHIJKLMNÑOPQRSTUVWXYZabcdefghijklmnñopqrstuvwxyzáíóúé "
    Public numeros As String = "0123456789"
    Private Structure datosalquiler
        Public Cliente As String
        Public pelicula As String
        Public f_ini As String
        Public dias As String
        Public f_fin As String
        Public costo As String
        Public total As String
    End Structure

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        sw = True
        TextBox1.Text = ""
        TextBox2.Text = ""
        TextBox3.Text = ""
        TextBox4.Text = ""
        TextBox5.Text = ""
        TextBox6.Text = ""
        DateTimePicker1.Text = ""
        DateTimePicker2.Text = ""
        TextBox1.Focus()
    End Sub

    Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
        End
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        If Trim(TextBox1.Text).Length = 0 Then
            MessageBox.Show("El cliente no es Nulo", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Exit Sub
        End If

        If Trim(TextBox2.Text).Length = 0 Then
            MessageBox.Show("La Pelicula no es Nulo", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Exit Sub
        End If

        'If Trim(TextBox3.Text).Length = 0 Then
        '    MessageBox.Show("Dias de alquiler no es Nulo", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
        '    Exit Sub
        'End If
        'If Trim(TextBox4.Text).Length = 0 Then
        '    MessageBox.Show("costo de alquiler no es Nulo", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
        '    Exit Sub
        'End If
        'If Trim(TextBox5.Text).Length = 0 Then
        '    MessageBox.Show("total de alquiler no es Nulo", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
        '    Exit Sub
        'End If

        'Dim f1, f2 As Date
        'Dim d As Integer
        'f1 = CDate(DateTimePicker1.Value)
        'f2 = CDate(DateTimePicker2.Value)
        Dim hoy As DateTime = DateTime.Now
        Dim diaFinal As DateTime = hoy.AddDays(TextBox3.Text)
        DateTimePicker2.Value = diaFinal
        'd = DateDiff(DateInterval.Day, f1, f2)

        TextBox4.Text = 12.5
        TextBox5.Text = TextBox3.Text * 12.5

    End Sub

    Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
        Dim validarcaracter As Integer = InStr(cadena, e.KeyChar)
        If validarcaracter = 0 And AscW(e.KeyChar) <> 8 Then e.KeyChar = ""
    End Sub

    Private Sub TextBox2_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox2.KeyPress
        Dim validarcaracter As Integer = InStr(cadena, e.KeyChar)
        If validarcaracter = 0 And AscW(e.KeyChar) <> 8 Then e.KeyChar = ""
    End Sub

    Private Sub TextBox3_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox3.KeyPress
        Dim validarnumeros As Integer = InStr(numeros, e.KeyChar)
        If validarnumeros = 0 And AscW(e.KeyChar) <> 8 Then e.KeyChar = ""
    End Sub

    Private Sub TextBox4_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox4.KeyPress
        Dim validarnumeros As Integer = InStr(numeros, e.KeyChar)
        If validarnumeros = 0 And AscW(e.KeyChar) <> 8 Then e.KeyChar = ""
    End Sub

    Private Sub TextBox5_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox5.KeyPress
        Dim validarnumeros As Integer = InStr(numeros, e.KeyChar)
        If validarnumeros = 0 And AscW(e.KeyChar) <> 8 Then e.KeyChar = ""
    End Sub


    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        TextBox6.Text = ""
        listaregistros()

    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
                Dim registro = New regi
        With registro
            .Cliente = TextBox1.Text
            .pelicula = TextBox2.Text
            .f_ini = DateTimePicker1.Value
            .dias = TextBox3.Text
            .f_fin = DateTimePicker2.Value
            .costo = TextBox4.Text
            .total = TextBox5.Text
        End With
        registros(UBound(registros)) = registro
        ' ReDim Preserve registros(UBound(registros) + 1)
        MessageBox.Show("Datos agregados...")



    End Sub
    Dim cadenar As String
    Private Sub listaregistros()
        For Each regsitro In registros
            With regsitro
                If .Cliente <> "" Then
                    cadenar &= "Cliente    : " & regsitro.Cliente & vbCrLf & _
                              "Pelicula   : " & regsitro.pelicula & vbCrLf & _
                              "F_Alquiler : " & regsitro.f_ini & vbCrLf & _
                              "Dias alqui : " & regsitro.dias & vbCrLf & _
                              "F_Entrega  : " & regsitro.f_fin & vbCrLf & _
                              "Costo alqui: " & regsitro.costo & vbCrLf & _
                              "Total alqui: " & regsitro.total & vbCrLf & vbCrLf & _
                              "------------------------------------------------------------------------------------------------" & vbCrLf
                End If
            End With
            TextBox6.Text = cadenar
        Next
    End Sub
End Class


No hay comentarios:

Publicar un comentario