Formularios

Anuncio
UNIVERSIDAD FEMENINA DEL SAGRADO CORAZÓN
FACULTAD DE INGENIERIA DE SISTEMAS
Curso : Taller de Computación
Tema : “Formularios”
Profesora :
Gladys Hortencia, Garcia Vilcapoma
Alumnas:
Pastor Humpiri, Fanny Rosana
2006-1
Problema Adicional: Contruir un catalogo de Biblioteca, en el que ingresando como login
“Administrador”, muestre una pantalla donde se puedan agregar y eliminar registros de libros
de la biblioteca. Y si se ingresa como login “Usuario”, muestre una pantalla donde se pueda
buscar libros por código, autor y titulo del libro, y muestre los resultados en tres listas (codigo,
autor y titulo).
Formulario 1:
Public Class Form1
Inherits System.Windows.Forms.Form
Private Sub BtnAceptar_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles BtnAceptar.Click
If Me.TxtLogin.Text = "Administrador" And Me.TxtPassword.Text = "Administrador" Then
' Si la clave es administrador, ingresa al formulario 2
Me.Hide()
f2.Show()
ElseIf Me.TxtLogin.Text = "Usuario" And Me.TxtPassword.Text = "Usuario" Then
' Si la clave es usuario, ingresa al formulario 2
Me.Hide()
f3.Show()
End If
End Sub
Private Sub BtnCancelar_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles BtnCancelar.Click
Me.Close()
End Sub
End Class
Formulario 2:
Public Class Form2
Inherits System.Windows.Forms.Form
Dim Codigo As Integer
Dim Titulo As String
Dim Autor As String
Dim j As Integer
Dim k As Integer
Private Sub BtnAgregar_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles BtnAgregar.Click
Codigo = Val(InputBox("Ing. Código: "))
Titulo = UCase(InputBox("Ing. Titulo:"))
Autor = UCase(InputBox("Ing. Autor:"))
ACodigo(i) = Codigo
ATitulo(i) = Titulo
AAutor(i) = Autor
Me.ListBox1.Items.Add(ACodigo(i))
Me.ListBox2.Items.Add(ATitulo(i))
Me.ListBox3.Items.Add(AAutor(i))
i=i+1
NE = i
End Sub
Private Sub BtnSalir_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles BtnSalir.Click
Me.Close()
f1.Close()
f2.Close()
f3.Close()
End Sub
Private Sub BtnLogin_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles BtnLogin.Click
Me.Hide()
f1.Show()
End Sub
Private Sub BtnEliminar_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles BtnEliminar.Click
Dim CodBusca As Integer
CodBusca = Val(InputBox("Ing. Codigo a Buscar :"))
j=0
' Busca el Codigo a Buscar
While (j < NE) And (CodBusca <> ACodigo(j))
j=j+1
End While
If (j = NE) Then
MessageBox.Show("No se encuentra registrado")
End If
' Elimina el registro buscado y actualiza los arreglos
For k = j To NE Step 1
ACodigo(k) = ACodigo(k + 1)
ATitulo(k) = ATitulo(k + 1)
AAutor(k) = AAutor(k + 1)
Next k
'Como se elimino un registro, se disminuye en uno el numero
' total de elementos
NE = NE - 1
i=i-1
ListBox1.Items.Clear()
ListBox2.Items.Clear()
ListBox3.Items.Clear()
For k = 0 To NE - 1
ListBox1.Items.Add(ACodigo(k))
ListBox2.Items.Add(ATitulo(k))
ListBox3.Items.Add(AAutor(k))
Next
End Sub
End Class
Formulario 3:
Public Class Form3
Inherits System.Windows.Forms.Form
Dim j As Integer
Private Sub BtnSalir_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles BtnSalir.Click
Me.Close()
End Sub
Private Sub BtnBuscar_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles BtnBuscar.Click
Dim ABusca As String
Dim TBusca As String
Dim Codigo As Integer
j=0
If Me.RbnCodigo.Checked Then
'Busca por Código
Codigo = Val(Me.TxtItem.Text)
While (j < NE) And (Codigo <> ACodigo(j))
j=j+1
End While
If (j = NE) Then
MessageBox.Show("No se encuentra registrado")
End If
If j <> NE Then
Me.ListBox1.Items.Add(ACodigo(j))
Me.ListBox2.Items.Add(ATitulo(j))
Me.ListBox3.Items.Add(AAutor(j))
End If
ElseIf Me.RbnAutor.Checked Then
'Busca por Autor
ABusca = UCase(Me.TxtItem.Text)
While (j < NE) And (ABusca <> AAutor(j))
j=j+1
End While
If (j = NE) Then
MessageBox.Show("No se encuentra registrado")
End If
If j <> NE Then
Me.ListBox1.Items.Add(ACodigo(j))
Me.ListBox2.Items.Add(ATitulo(j))
Me.ListBox3.Items.Add(AAutor(j))
End If
ElseIf Me.RbnTitulo.Checked Then
'Busca por titulo
TBusca = UCase(Me.TxtItem.Text)
While (j < NE) And (TBusca <> ATitulo(j))
j=j+1
End While
If (j = NE) Then
MessageBox.Show("No se encuentra registrado")
End If
If j <> NE Then
Me.ListBox1.Items.Add(ACodigo(j))
Me.ListBox2.Items.Add(ATitulo(j))
Me.ListBox3.Items.Add(AAutor(j))
End If
End If
End Sub
Private Sub BtnLogin_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles BtnLogin.Click
Me.Hide()
f1.Show()
End Sub
End Class
PROBLEMA DE CLASE:
Formulario 1:
Public Class Form1
Inherits System.Windows.Forms.Form
Dim codigo() As Integer = {10, 17, 12, 25, 18, 24, 16, 20}
Dim Precio() As String = {15.2, 10.5, 17.2, 20.15, 13.1, 12.2,
19.5, 21.15}
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim i As Integer
For i = 0 To Precio.Length - 1
ListBox1.Items.Add(Precio(i))
ListBox2.Items.Add(codigo(i))
Next
Me.BtnAceptar.Enabled = False
End Sub
Private Sub BtnOrdenar_Click(ByVal sender As System.Object, ByVal
e As System.EventArgs)
Dim i, j, k, aux As Integer
Dim auxN As String
For k = 0 To Precio.Length - 2
For j = 0 To Precio.Length - 2 - k
If codigo(j) > codigo(j + 1) Then
aux = codigo(j)
codigo(j) = codigo(j + 1)
codigo(j + 1) = aux
auxN = Precio(j)
Precio(j) = Precio(j + 1)
Precio(j + 1) = auxN
End If
Next
Next
For i = 0 To Precio.Length - 1
ListBox3.Items.Add(Precio(i))
ListBox4.Items.Add(codigo(i))
Next
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles Button1.Click
Dim i, j, k As Integer
Dim aux As Integer
Dim auxN As String
For k = 0 To Precio.Length - 2
For j = 0 To Precio.Length - 2 - k
If Precio(j) > Precio(j + 1) Then
aux = codigo(j)
codigo(j) = codigo(j + 1)
codigo(j + 1) = aux
auxN = Precio(j)
Precio(j) = Precio(j + 1)
Precio(j + 1) = auxN
End If
Next
Next
For i = 0 To Precio.Length - 1
ListBox3.Items.Add(Precio(i))
ListBox4.Items.Add(codigo(i))
Next
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles Button3.Click
Me.ListBox3.Items.Clear()
Me.ListBox4.Items.Clear()
End Sub
Private Sub TxtPasword_KeyDown(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyEventArgs) Handles TxtPasword.KeyDown
If e.KeyCode = Keys.Enter Then
If Me.TxtPasword.Text = "gladys" Then
Me.BtnAceptar.Enabled = True
End If
End If
End Sub
End Class
Formulario 2:
Public Class Form2
Inherits System.Windows.Forms.Form
Dim NomProd As String
Dim precioProd As Single
Dim cantidad As Integer
Private Sub BtnCalcular_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles BtnCalcular.Click
Dim tasa, igv, montoparcial, total, aumento As Single
Dim descuento = 0.07
NomProd = Me.TxtProducto.Text
precioProd = Val(Me.TxtPrecio.Text)
cantidad = Val(Me.TxtCantidad.Text)
montoparcial = precioProd * cantidad
Me.TxtPrecioAcum.Text = montoparcial
Select Case CboTiempo.SelectedIndex
Case 0
tasa = 0.03
Case 1
tasa = 0.04
Case 2
tasa = 0.06
Case 3
tasa = 0.08
End Select
aumento = tasa * montoparcial
descuento = 0.01 * montoparcial
igv = 0.19 * Me.TxtPrecioAcum.Text
total = montoparcial + aumento - descuento
Me.LblAumento.Text = aumento
Me.LblDescuento.Text = descuento
Me.LblIGV.Text = igv
Me.LblTotal.Text = total
End Sub
Private Sub BtnNuevo_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles BtnNuevo.Click
Me.TxtCantidad.Clear()
Me.TxtPrecio.Clear()
Me.TxtPrecioAcum.Clear()
Me.TxtProducto.Clear()
Me.BtnVer.Enabled = False
Me.BtnLista.Enabled = False
End Sub
Private Sub BtnLista_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles BtnLista.Click
NomProd = Me.TxtProducto.Text
precioProd = Val(Me.TxtPrecio.Text)
cantidad = Val(Me.TxtCantidad.Text)
AProd(i) = NomProd
APrecio(i) = precioProd
ACantidad(i) = cantidad
i = i + 1
NE = i
Me.Hide()
f3.Show()
End Sub
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Me.BtnCalcular.Enabled = False
Me.BtnLista.Enabled = False
End Sub
Private Sub BtnVer_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles BtnVer.Click
Me.BtnCalcular.Enabled = True
Me.BtnLista.Enabled = True
End Sub
End Class
FORMULARIO 3:
Public Class Form3
Inherits System.Windows.Forms.Form
Dim j As Integer
Private Sub BtnMostrar_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles BtnMostrar.Click
Me.ListBox1.Items.Clear()
Me.ListBox2.Items.Clear()
Me.ListBox3.Items.Clear()
For j = 0 To NE - 1
Me.ListBox1.Items.Add(AProd(j))
Me.ListBox2.Items.Add(APrecio(j))
Me.ListBox3.Items.Add(ACantidad(j))
Next
End Sub
Private Sub BtnRegresar_Click(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles BtnRegresar.Click
Me.Hide()
f2.Show()
End Sub
Private Sub BtnSalir_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles BtnSalir.Click
Me.Close()
End Sub
End Class
Descargar