Sei sulla pagina 1di 10

COMPUTACIN E INFORMTICA PROGRAMACIN

DESARROLLO DE APLICACIN DE ESCRITORIO EN VISUAL.NET


DISEO DE BASE DE DATOS EN SQL SERVER 2008
MODELO DE ENTIDAD RELACIN

Autor: Vides Arroyo Galindo E-mail: videsarroyo@hotmail.com

Pgina 1

COMPUTACIN E INFORMTICA PROGRAMACIN


PROCEDIMIENTOS ALMACENADOS

PROGRAMACIN EN BASIC.NET
Crear un proyecto nuevo de tipo Aplicacin de Windows Form.(resultado)

Guardar el proyecto.

Autor: Vides Arroyo Galindo E-mail: videsarroyo@hotmail.com

Pgina 2

COMPUTACIN E INFORMTICA PROGRAMACIN

CAPA ENTIDAD
Agregar un proyecto Clic en Archivo/Agregar nuevo proyecto/Biblioteca de clases

Asigne el nombre con CapaEntidad y crear la clases para las tablas principales de la base de datos. Clase alumnoCE
Public Class AlumnoCE Private _dni As String Private _apellido As String Private _nombres As String Private _fecha_nac As Date Private _idespe As String Public Property dni() As String Get Return _dni End Get Set(ByVal value As String) If value.Trim.Length = 8 Then _dni = value Else Throw New Exception("Ingrese 8 dgitos") End If End Set End Property Public Property apellidos() As String Get

Autor: Vides Arroyo Galindo E-mail: videsarroyo@hotmail.com

Pgina 3

COMPUTACIN E INFORMTICA PROGRAMACIN


Return _apellido End Get Set(ByVal value As String) If value.Trim.Length > 3 Then _apellido = value Else Throw New Exception("Ingrese 3 letras como mnimo en apellidos") End If End Set End Property Public Property nombres() As String Get Return _nombres End Get Set(ByVal value As String) _nombres = value End Set End Property Public Property fechanac() As Date Get Return _fecha_nac End Get Set(ByVal value As Date) If value.Year + 5 < (Date.Now.Year) Then _fecha_nac = value Else Throw New Exception("Ingrese fecha de nacimiento mnimo 6 aos") End If End Set End Property Public Property idespecialidad() As String Get Return _idespe End Get Set(ByVal value As String) If value.Trim.Length = 3 Then _idespe = value Else Throw New Exception("Vuelve a seleccionar la especialidad") End If End Set End Property End Class

Autor: Vides Arroyo Galindo E-mail: videsarroyo@hotmail.com

Pgina 4

COMPUTACIN E INFORMTICA PROGRAMACIN


CAPA ACCESO A DATOS
Agregar un proyecto Clic en Archivo/Agregar nuevo proyecto/Biblioteca de clases

Asigne el nombre como CapaDatos y crear las siguientes clases Agregar referencia a la CapaEntidad: Clic derecho en el proyecto CapaDatos

Autor: Vides Arroyo Galindo E-mail: videsarroyo@hotmail.com

Pgina 5

COMPUTACIN E INFORMTICA PROGRAMACIN

Seleccione la CapaEntidad en la pestaa Proyectos y clic Aceptar

Autor: Vides Arroyo Galindo E-mail: videsarroyo@hotmail.com

Pgina 6

COMPUTACIN E INFORMTICA PROGRAMACIN


Clase conexin:

Clase consulta:

Clase alumno:
Imports CapaEntidad Imports System.Data.SqlClient Imports System.Data Public Class alumnoCD Private _con As New conexion Private _com As New SqlCommand Sub New() _com.Connection = _con.abrir End Sub Public Function grabar_alumno(ByVal objalu As AlumnoCE) As String _com.Parameters.Clear() _com.Connection = _con.abrir

Autor: Vides Arroyo Galindo E-mail: videsarroyo@hotmail.com

Pgina 7

COMPUTACIN E INFORMTICA PROGRAMACIN


_com.CommandType = CommandType.StoredProcedure _com.CommandText = "nuevoalumno" _com.Parameters.Add(New SqlParameter("@dni", objalu.dni)) _com.Parameters.Add(New SqlParameter("@nombres", objalu.nombres)) _com.Parameters.Add(New SqlParameter("@apellidos", objalu.apellidos)) _com.Parameters.Add(New SqlParameter("@fecha_nac", objalu.fechanac)) _com.Parameters.Add(New SqlParameter("@idespe", objalu.idespecialidad)) Dim nroexiste As New SqlParameter("@existe", 0) nroexiste.Direction = ParameterDirection.Output _com.Parameters.Add(nroexiste) _com.ExecuteNonQuery() _con.cerrar() If _com.Parameters("@existe").Value = 0 Then Return "Se Actualiz los datos" Else Return "Se Insert los datos" End If End Function End Class

CAPA LGICA DE NEGOCIOS


Agregar un proyecto con nombre de CapaLogicaNegocios Hacer referencia a Capadatos y Capaentidad. Y crear la clase AlumnoLN

Autor: Vides Arroyo Galindo E-mail: videsarroyo@hotmail.com

Pgina 8

COMPUTACIN E INFORMTICA PROGRAMACIN

PROYECTO PRINCIPAL.
DISEO DEL FORMULARIO

CDIGO EN EL FORMULARIO:
Imports CapaEntidad Imports CapaLogicaNegocios Public Class frmalumno Dim objalumno As AlumnoCE Dim objalumnolognegocio As AlumnoLN Private Sub frmalumno_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load objalumno = New AlumnoCE objalumnolognegocio = New AlumnoLN dgalumno.DataSource = objalumnolognegocio.verdata("select*from alumno") Utilitarios.LlenarCombo(cbespecialidad, "select*from especialidad", "id", "nomespe") End Sub Private Sub btgrabar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btgrabar.Click Try objalumno.dni = txtdni.Text objalumno.nombres = txtnombres.Text objalumno.apellidos = txtapellidos.Text objalumno.fechanac = dtpfechanac.Value.Date.Date objalumno.idespecialidad = cbespecialidad.SelectedValue

Autor: Vides Arroyo Galindo E-mail: videsarroyo@hotmail.com

Pgina 9

COMPUTACIN E INFORMTICA PROGRAMACIN


objalumnolognegocio.NUEVO_ALUMNO(objalumno) dgalumno.DataSource = objalumnolognegocio.verdata("select*from alumno") Catch ex As Exception MessageBox.Show(ex.Message) End Try End Sub End Class

CLASE UTILITARIO:
Imports CapaLogicaNegocios Public Class Utilitarios Public Shared Sub LlenarCombo(ByVal CB As ComboBox, ByVal sql As String, ByVal valor As String, ByVal nombre As String) Dim objal As New AlumnoLN CB.DataSource = objal.verdata(sql) CB.DisplayMember = nombre CB.ValueMember = valor End Sub End Class

RESULTADO

Autor: Vides Arroyo Galindo E-mail: videsarroyo@hotmail.com

Pgina 10

Potrebbero piacerti anche