Sei sulla pagina 1di 10

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

PROCEDIMIENTOS ALMACENADOS

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

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 dela 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 = 8Then _dni = value Else Throw New Exception("Ingrese 8 dgitos") End If End Set End Property Public Property apellidos() As String Get Return _apellido End Get Set (ByValvalueAs String) If value.Trim.Length > 3 Then _apellido = value Else Throw NewException("Ingrese 3 letras como mnimo enapellidos") 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 NewException("Ingrese fecha de nacimiento mnimo 6aos") 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 NewException("Vuelve a seleccionar la especialidad") End If End Set End Property End Class 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 clasesAgregar referencia a la CapaEntidad: Clic derecho en el proyecto CapaDatos

Seleccione la CapaEntidad en la pestaa Proyectos y clic Aceptar

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 com.CommandType = CommandType.StoredProcedure _com.CommandText ="nuevoalumno" _com.Parameters.Add(NewSqlParameter("@dni", objalu.dni)) _com.Parameters.Add(NewSqlParameter("@nombres", objalu.nombres)) _com.Parameters.Add(NewSqlParameter("@apellidos",objalu.apellidos)) _com.Parameters.Add(NewSqlParameter("@fecha_nac",objalu.fechanac)) _com.Parameters.Add(NewSqlParameter("@idespe",objalu.idespecialidad)) Dim nroexiste As NewSqlParameter("@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 Capa Lgica Negocios Hacer referencia a Capa datos y Capa entidad. Y crear la clase AlumnoLN

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 =NewAlumnoCE objalumnolognegocio =New AlumnoLN dgalumno.DataSource = objalumnolognegocio.verdata("select * from alumno") Utilitarios.LlenarCombo(cbespecialidad,"select*fromespecialidad","id","nomespe") End Sub Private Subbtgrabar_Click(ByVal sender AsSystem.Object, ByVal e As System.EventArgs) Handlesbtgrabar.Click Try objalumno.dni = txtdni.Text objalumno.nombres = txtnombres.Text objalumno.apellidos = txtapellidos.Text objalumno.fechanac = dtpfechanac.Value.Date.Date objalumno.idespecialidad = cbespecialidad.SelectedValue objalumnolognegocio.NUEVO_ALUMNO(objalumno) dgalumno.DataSource =objalumnolognegocio.verdata("selec t*f rom alumno") Catch ex As Exception MessageBox.Show(ex.Message) End Try End Sub End Class CLASE UTILITARIO: Imports CapaLogicaNegocios Public ClassUtilitarios

Public Shared SubLlenarCombo(ByVal CBAsComboBox,ByVal sql As String,ByVal valor As String,ByVal nombre As String) Dim objal As NewAlumnoLN CB.DataSource = objal.verdata(sql) CB.DisplayMember = nombre CB.ValueMember = valor End Sub End Class

Potrebbero piacerti anche