Вы находитесь на странице: 1из 13

INSTITUTO UNIVERSITARIO DE TECNOLOGIA JUAN PABLO PEREZ ALFONZO IUTEPAL DIVISION SAN CRISTOBAL

INFORME DE PROGRAMACION 1

Autor: Melo Marques, Fernando C.I. 14.179.223

Seccin: 4021

SAN CRISTOBAL, JUNIO 2012

Primer formulario, en el que se introducen los datos

Public Class Form1 Dim i As Integer = 0 Public vecid(100) As String Public vecci(100) As String Public veccedu(100) As Integer Public vecnom(100) As String Public vecdir(100) As String Public vectel1(100) As Integer Public vectel2(100) As Integer Public vecmail(100) As String Public vecdepa(100) As String Public veccargo(100) As String Dim vecfech(100) As Date Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load idemp.Focus() End Sub Private Sub nombre_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles nombre.KeyPress

If (Asc(e.KeyChar) >= 65 And Asc(e.KeyChar) <= 90) Or Asc(e.KeyChar) >= 97 And Asc(e.KeyChar) <= 122 Or Asc(e.KeyChar) = Keys.Back Or (Asc(e.KeyChar) = Keys.Space) Then e.Handled = False ' validar solo caracteres mayusculas y minusculas Else e.Handled = True End If End Sub Private Sub cedula_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles cedula.KeyPress If (Not Char.IsNumber(e.KeyChar) And e.KeyChar <> Microsoft.VisualBasic.ChrW(8)) Then e.Handled = True ' validar solo numeros y tecla backspace End If End Sub Private Sub listados_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles listados.Click My.Forms.Form2.Show() ' mostrar formulario con listado Hide() End Sub Private Sub tel1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles tel1.KeyPress If (Not Char.IsNumber(e.KeyChar) And e.KeyChar <> Microsoft.VisualBasic.ChrW(8)) Then e.Handled = True ' validar solo numeros y tecla backspace End If End Sub Private Sub tel2_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles tel2.KeyPress If (Not Char.IsNumber(e.KeyChar) And e.KeyChar <> Microsoft.VisualBasic.ChrW(8)) Then e.Handled = True ' validar solo numeros y tecla backspace End If End Sub Private Sub email_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles email.Leave Try ' validar formato del email usando funcion integrada en .net Dim mail As New System.Net.Mail.MailAddress(email.Text) Catch ex As Exception MessageBox.Show(ex.Message) email.Text = "" email.Focus() End Try End Sub Private Sub agregar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles agregar.Click Dim k As Integer = 0 ' Validar que todos los campos esten completos If (idemp.Text = "") Then

MsgBox("Debe colocar el ID del empleado", MsgBoxStyle.Exclamation) idemp.Focus() k = k + 1 End If If (ci.Text = "") Then MsgBox("Debe seleccionar la nacionalidad del empleado", MsgBoxStyle.Exclamation) ci.Focus() k = k + 1 End If If (cedula.Text = "") Then MsgBox("Debe colocar la cdula del empleado", MsgBoxStyle.Exclamation) cedula.Focus() k = k + 1 End If If (nombre.Text = "") Then MsgBox("Debe colocar el nombre del empleado", MsgBoxStyle.Exclamation) nombre.Focus() k = k + 1 End If If (tel1.Text = "") Then MsgBox("Debe colocar el telfono del empleado", MsgBoxStyle.Exclamation) tel1.Focus() k = k + 1 End If If (tel2.Text = "") Then MsgBox("Debe colocar el telfono del empleado", MsgBoxStyle.Exclamation) tel2.Focus() k = k + 1 End If If (email.Text = "") Then MsgBox("Debe colocar el email del empleado", MsgBoxStyle.Exclamation) email.Focus() k = k + 1 End If If k = 0 Then ' Para que solo llene los datos en los vectores si estan todos los campos llenos vecid(i) = idemp.Text ' llenar los vectores con los datos vecci(i) = ci.Text veccedu(i) = cedula.Text vecnom(i) = nombre.Text vecdir(i) = direccion.Text vectel1(i) = tel1.Text

vectel2(i) = tel2.Text vecmail(i) = email.Text vecdepa(i) = departamento.Text veccargo(i) = cargo.Text vecfech(i) = fecha.SelectionRange.Start i = i + 1 ' contador del indice de los vectores idemp.Text = "" ' limpiar campos para el proximo ingreso tel1.Text = "" tel2.Text = "" email.Text = "" nombre.Text = "" direccion.Text = "" cedula.Text = "" ci.Text = "" departamento.Text = "" cargo.Text = "" idemp.Focus() cant.Text = i End If End Sub Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing If MsgBox("Seguro que desea terminar la aplicacin?", MsgBoxStyle.YesNo, "Confirmar cierre") = MsgBoxResult.Yes Then End ' Confirmacion para cerrar programa Else e.Cancel = True End If End Sub End Class

Formulario para buscar los datos, modificar, agregar nuevos o eliminar alguno

Public Class Form2 Private Sub eliminar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles eliminar.Click If MsgBox("Seguro que desea eliminar datos?", MsgBoxStyle.YesNo) = MsgBoxResult.Yes Then final.Form5.Show() End If End Sub Private Sub agregar2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles agregar2.Click If MsgBox("Agregar otro registro?", MsgBoxStyle.YesNo) = MsgBoxResult.Yes Then final.Form1.Show() Hide() End If End Sub Private Sub modificar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles modificar.Click If MsgBox("Seguro que desea modificar los datos?", MsgBoxStyle.YesNo) = MsgBoxResult.Yes Then final.Form4.Show() End If End Sub

Private Sub buscedula_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles buscedula.KeyPress If (Not Char.IsNumber(e.KeyChar) And e.KeyChar <> Microsoft.VisualBasic.ChrW(8)) Then e.Handled = True ' validar solo numeros y tecla backspace End If End Sub Private Sub Form2_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing If MsgBox("Seguro que desea terminar la aplicacin?", MsgBoxStyle.YesNo, "Confirmar cierre") = MsgBoxResult.Yes Then End Else e.Cancel = True End If End Sub Private Sub buscar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles buscar.Click Dim j As Integer = DataGridView1.RowCount If buscedula.Text = "" Then MsgBox("Introduzca una cdula a buscar", MsgBoxStyle.Information) buscedula.Focus() Else For i As Integer = 0 To final.Form1.cant.Text If buscedula.Text = My.Forms.Form1.veccedu(i) Then DataGridView1.Rows.Add() DataGridView1.Item(0, j).Value = final.Form1.vecid(i) DataGridView1.Item(1, j).Value = final.Form1.veccedu(i) DataGridView1.Item(2, j).Value = final.Form1.vecnom(i) End If buscedula.Focus() Next End If End Sub Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load buscedula.Focus() End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim ruta As String ' Guardar archivo con los datos de ID empleado, cedula y nombre Dim archivo As Long Dim g As Integer = DataGridView1.RowCount SaveFileDialog1.Filter = "Archivo de texto(*.txt)|*.txt" SaveFileDialog1.ShowDialog() ruta = SaveFileDialog1.FileName() If ruta <> "" Then

archivo = FreeFile() FileOpen(archivo, ruta, OpenMode.Output) PrintLine(archivo, "ARCHIVO DE PRUEBA DE ESCRITURA, INCLUYE EL CONTENIDO DEL DATAGRIDVIEW1") PrintLine(archivo, " ") PrintLine(archivo, "ID Empleado Cdula Nombre") For k As Integer = 0 To g - 1 PrintLine(archivo, DataGridView1.Item(0, k).Value, "", DataGridView1.Item(1, k).Value, "", DataGridView1.Item(2, k).Value) Next FileClose(archivo) End If End Sub End Class

Formulario de peticin de datos a modificar

Public Class Form4 Private Sub aceptar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles aceptar.Click If ced.Text = "" Then MsgBox("Introduzca una cdula a modificar", MsgBoxStyle.Information) ced.Focus() Else For i As Integer = 0 To final.Form1.cant.Text If ced.Text = My.Forms.Form1.veccedu(i) Then final.Form3.idemp.Text = final.Form1.vecid(i) final.Form3.ci.Text = final.Form1.vecci(i) final.Form3.cedula.Text = final.Form1.veccedu(i) final.Form3.nombre.Text = final.Form1.vecnom(i) final.Form3.direccion.Text = final.Form1.vecdir(i) final.Form3.tel1.Text = final.Form1.vectel1(i) final.Form3.tel2.Text = final.Form1.vectel2(i) final.Form3.email.Text = final.Form1.vecmail(i) final.Form3.tel1.Text = final.Form1.vectel1(i) final.Form3.departamento.Text = final.Form1.vecdepa(i) final.Form3.cargo.Text = final.Form1.veccargo(i) final.Form3.Show()

End If Next ced.Text = "" Hide() End If End Sub Private Sub cancelar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cancelar.Click ced.Text = "" Hide() End Sub Private Sub ced_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles ced.KeyPress If (Not Char.IsNumber(e.KeyChar) And e.KeyChar <> Microsoft.VisualBasic.ChrW(8)) Then e.Handled = True ' validar solo numeros y tecla backspace End If End Sub End Class

Formulario para introducir los datos a modificar

Public Class Form3 Private Sub Form3_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load idemp.Focus() End Sub Private Sub nombre_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles nombre.KeyPress If (Asc(e.KeyChar) >= 65 And Asc(e.KeyChar) <= 90) Or Asc(e.KeyChar) >= 97 And Asc(e.KeyChar) <= 122 Or Asc(e.KeyChar) = Keys.Back Or (Asc(e.KeyChar) = Keys.Space) Then e.Handled = False ' validar solo caracteres mayusculas y minusculas Else e.Handled = True End If End Sub Private Sub cedula_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles cedula.KeyPress If (Not Char.IsNumber(e.KeyChar) And e.KeyChar <> Microsoft.VisualBasic.ChrW(8)) Then e.Handled = True ' validar solo numeros y tecla backspace End If End Sub Private Sub listados_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles listados.Click My.Forms.Form2.Show() ' mostrar formulario con listado Hide() End Sub Private Sub tel1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles tel1.KeyPress If (Not Char.IsNumber(e.KeyChar) And e.KeyChar <> Microsoft.VisualBasic.ChrW(8)) Then e.Handled = True ' validar solo numeros y tecla backspace End If End Sub Private Sub tel2_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles tel2.KeyPress If (Not Char.IsNumber(e.KeyChar) And e.KeyChar <> Microsoft.VisualBasic.ChrW(8)) Then e.Handled = True ' validar solo numeros y tecla backspace End If End Sub Private Sub email_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles email.Leave Try ' validar formato del email usando mtodo integrado en .net Dim mail As New System.Net.Mail.MailAddress(email.Text) Catch ex As Exception MessageBox.Show(ex.Message) email.Text = "" email.Focus()

End Try End Sub Private Sub agregar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles agregar.Click Dim k As Integer = 0 Dim i As Integer ' Validar que todos los campos esten completos If (idemp.Text = "") Then MsgBox("Debe colocar el ID del empleado", MsgBoxStyle.Exclamation) idemp.Focus() k = k + 1 End If If (ci.Text = "") Then MsgBox("Debe seleccionar la nacionalidad del empleado", MsgBoxStyle.Exclamation) ci.Focus() k = k + 1 End If If (cedula.Text = "") Then MsgBox("Debe colocar la cdula del empleado", MsgBoxStyle.Exclamation) cedula.Focus() k = k + 1 End If If (nombre.Text = "") Then MsgBox("Debe colocar el nombre del empleado", MsgBoxStyle.Exclamation) nombre.Focus() k = k + 1 End If If (tel1.Text = "") Then MsgBox("Debe colocar el telfono del empleado", MsgBoxStyle.Exclamation) tel1.Focus() k = k + 1 End If If (tel2.Text = "") Then MsgBox("Debe colocar el telfono del empleado", MsgBoxStyle.Exclamation) tel2.Focus() k = k + 1 End If If (email.Text = "") Then MsgBox("Debe colocar el email del empleado", MsgBoxStyle.Exclamation) email.Focus() k = k + 1

End If If k = 0 Then ' Para que solo llene los datos en los vectores si estan todos los campos llenos For i = 0 To final.Form1.cant.Text If cedula.Text = My.Forms.Form1.veccedu(i) Then final.Form1.vecid(i) = idemp.Text ' llenar los vectores con los datos final.Form1.vecci(i) = ci.Text final.Form1.veccedu(i) = cedula.Text final.Form1.vecnom(i) = nombre.Text final.Form1.vecdir(i) = direccion.Text final.Form1.vectel1(i) = tel1.Text final.Form1.vectel2(i) = tel2.Text final.Form1.vecmail(i) = email.Text final.Form1.vecdepa(i) = departamento.Text final.Form1.veccargo(i) = cargo.Text MsgBox("Datos modificados correctamente", MsgBoxStyle.Information) Hide() End If Next End If End Sub Private Sub Form3_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing If MsgBox("Seguro que desea terminar la aplicacin?", MsgBoxStyle.YesNo, "Confirmar cierre") = MsgBoxResult.Yes Then End ' Confirmacion para cerrar programa Else e.Cancel = True End If End Sub End Class

Formulario de eliminar registro

Public Class Form5 Private Sub ced_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles ced.KeyPress If (Not Char.IsNumber(e.KeyChar) And e.KeyChar <> Microsoft.VisualBasic.ChrW(8)) Then e.Handled = True ' validar solo numeros y tecla backspace End If End Sub Private Sub cancelar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cancelar.Click ced.Text = "" Hide() End Sub Private Sub aceptar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles aceptar.Click If ced.Text = "" Then MsgBox("Introduzca una cdula a eliminar", MsgBoxStyle.Information) ced.Focus() Else If MsgBox("Confirma que desea eliminar el registro del empleado?", MsgBoxStyle.YesNo) = MsgBoxResult.Yes Then For i As Integer = 0 To final.Form1.cant.Text - 1 If ced.Text = My.Forms.Form1.veccedu(i) Then final.Form1.vecid(i) = "" final.Form1.vecci(i) = "" final.Form1.veccedu(i) = "0" final.Form1.vecnom(i) = "" final.Form1.vecdir(i) = "" final.Form1.vectel1(i) = "0" final.Form1.vectel2(i) = "0" final.Form1.vecmail(i) = "" final.Form1.vecdepa(i) = "" final.Form1.veccargo(i) = "" MsgBox("Datos eliminados correctamente", MsgBoxStyle.Information) Hide() final.Form1.cant.Text = final.Form1.cant.Text - 1 End If Next ced.Text = "" Hide() End If End If End Sub End Class

Вам также может понравиться