16
DESARROLLO Y DISEÑO WEB MANTENIMIENTO DE DATOS CON FORMULARIO WEB & MICROSOFT ACCESS Crear Una Base De Datos En Access Que Permita Almacenar El Registro De Usuarios Web, Diseñar 3 Tablas (País, Provincia Y Usuarios). CREACIÓN DE LA BASE DE DATOS: Ingresar Al Microsoft Access Y Crear Una Base De Datos De Nombre: USUARIOSWEB.Mdb, Con La Versión De Access 2002 – 2003, Guardarlo En La Unidad D: Ahora Crear Las Siguientes Tablas: Ir A La Ficha Herramientas De Base De Datos Y Realizar Clic En Relaciones: Ahora Agregar Las 3 Tablas Creadas Al Diseñador: Y Relacionar Las Tablas Como Se Muestra En La Siguiente Figura: Expositor: Mañuico Flores, Roly Developer of Windows and Web Applications Móvil: 9-8508-4014 1 E-Mail: [email protected]

Clase 1 - ASP.net - Access & Estilos

Embed Size (px)

Citation preview

MANTENIMIENTO DE DATOS CON FORMULARIO WEB & MICROSOFT ACCESS

Crear Una Base De Datos En Access Que Permita Almacenar El Registro De Usuarios Web, Disear 3 Tablas (Pas, Provincia Y Usuarios).

CREACIN DE LA BASE DE DATOS:

Ingresar Al Microsoft Access Y Crear Una Base De Datos De Nombre: USUARIOSWEB.Mdb, Con La Versin De Access 2002 2003, Guardarlo En La Unidad D:

Ahora Crear Las Siguientes Tablas:

Ir A La Ficha Herramientas De Base De Datos Y Realizar Clic En Relaciones:

Ahora Agregar Las 3 Tablas Creadas Al Diseador:

Y Relacionar Las Tablas Como Se Muestra En La Siguiente Figura:

Luego Presionar CTRL + G, Para Guardar Los Cambios y Cerrar La Ventana De Relaciones. Ahora Ingresar A Las Tablas Creadas y Agregarle Los Siguientes Registros:

Cerrar El Programa De Microsoft Access.

CREACION DEL PROYECTO WEB:

Qu Necesitamos Para Nuestros Objetivos De Hoy?

1) Ingresar al Visual Studio.Net y Crear Un Nuevo Sito Web (ALT + SHIFT + N) Con El Nombre De: Clase 1 Registro De Usuarios Web - BDAccess y Guardarlo En La Unidad D.

2) Ahora Crear Los Siguientes Objetos En Nuestro Sitio Web y Mover La Base De Datos: USUARIOSWEB.Mdb, A La Carpeta De Nuestro Sitio Web.

3) Luego Realizar El Siguiente Diseo En El WebForm RegUsuarios.ASPXDISEO DE FORMULARIO WEB ASP.NET

Insertar Una Tabla Del Grupo HTML, De 11 Filas y 2 Columnas, Luego Insertar Los Siguientes Controles:

IMAGE

TXTIDUSUARIO

TXTNOMBRES

TXTCORREO

TXTCONTRASEA

DDLPAIS

DDLPROVINCIA

DGVDATOS

LBLTOTAL

Establecer los siguientes ID a los Button (BTNBUSCAR, BTNNUEVO, BTNCANCELAR, BTNREGISTRAR, BTNEDITAR y BTNELIMINAR)

CREACION DE LA HOJA DE ESTILO - CSS

1. Presionar las teclas CTRL + SHIFT + A, y agregar el objeto: Hoja De Estilos, Y Asignarle El Nombre De: MisEstilo.css2. Crear Los Siguientes Estilos:

DESARROLLO Y DISEO WEB

Expositor: Mauico Flores, RolyDeveloper of Windows and Web ApplicationsMvil: 9-8508-401413E-Mail: [email protected]/* Estilo Para El Contenido Web*/

body { background-image: url(Imagenes/Fondo26.GIF);}

/* Estilo Para Mis Tablas*/

.Estilo_Tabla{font-family: Calibri;font-size: 9pt;width: 575px;height: 63px;background: white;margin: 0 auto;}/* Estilo Para Los TextBox*/

.Estilo_TextBox{font-family: Calibri;font-size: 9pt;border: 1px solid Orange;width : 200px;height: 18px;}

/* Estilo Para Los DropDownList*/

.Estilo_ComboBox{font-family: Calibri;font-size: 9pt;border: 1px solid Orange;width: 205px;height: 20px;}

/* Estilo De Los Buttons */.Estilo_Button{background-color : orange;color : White;font-family: Calibri;font-size: 10pt;font-weight: bold ;border: solid 1px orange;width: 100px;height: 20px;cursor :pointer ;}

/* Estilo Para Los GridView */

.Estilo_Grid{ height: 35px;} .Estilo_Grid th{ background-color: Black; padding: 5px; border: hidden; color: White; }

3. Ahora Nos Enlazaremos Con Nuestra Hoja De Estilos, Ingresar A La Etapa de CODIGO y Ubicarse Debajo De las Etiquetas y Agregar La Siguiente Etiqueta :

4. Volver A La Etapa De DISEO y Vincular Los Estilo Creados, Mediante El Cambio De Propiedades De Los Controles, A continuacin Aplicar Los Siguientes Cambios:

CONTROLPROPIEDADVALOR

TXTIDALUMNOCssClassEstilo_TextBox

TXTNOMBRES

TXTCORREO

TXTCONTRASEA

DDLPAISCssClassEstilo_ComboBox

DDLPROVINCIA

DGVDATOSCssClassEstilo_Grid

BTNBUSCARCssClassEstilo_Button

BTNNUEVO

BTNCANCELAR

BTNREGISTRAR

BTNEDITAR

BTNELIMINAR

TABLAClassEstilo_Tabla

RESULTADO FINAL DEL DISEO DE TU REGISTRO WEB:

CODIGO FUENTE DEL FORMULARIO WEB

Librera A Importar Para La Conexin Con Access

Imports System.Data.OleDb

Cadena De Conexin Con La Base De Datos: UsuariosWeb.Mdb

Dim CN As New OleDbConnection("PROVIDER = MICROSOFT.JET.OLEDB.4.0 ; DATA SOURCE=" & Server.MAPPATH("UsuariosWeb.MDB") & "")

Variables A Nivel De Formulario Para Los Mensajes y Para Cargar El GridView (Utilizar Inner Join)

Dim Listado As String = "Select IdUsuario, Nombres_Apellidos, Correo, " & _ " Contrasea, Nombre_Pais, Nombre_Provincia " & _" From (Usuarios Inner Join Pais On Usuarios.IdPais=Pais.IdPais) " & _" Inner Join Provincia On Usuarios.IdProvincia=Provincia.IdProvincia " & _" Order By IdUsuario"

Dim MSJ As StringProcedimiento Para Cargar Los Pases En El Control DDLPAIS

Sub Cargar_Paises() TryDim Da As New OleDbDataAdapter("SELECT '0' AS IdPais," & _" '- Seleccione -' AS Nombre_Pais FROM Pais " & _ " UNION (SELECT IdPais,Nombre_Pais FROM Pais) ", CN) Dim Ds As New Data.DataSet Da.Fill(DS, 0)

With DDLPais .DataSource = Ds.Tables(0) .DataTextField = "Nombre_Pais" .DataValueField = "IdPais" .DataBind() End With

Catch ex As Exception MsgBox(Err.Description) End Try End Sub

Procedimiento Para Cargar Las Provincias En El Control DDLPROVINCIA, Que Depende Del Pais Seleccionado.

Sub Cargar_Provincias() TryDim Da As New OleDbDataAdapter("Select * From Provincia Where " & _" IdPais = " & DDLPais.SelectedValue & "", CN) Dim Ds As New Data.DataSet Da.Fill(Ds, 0)

With DDLProvincia .DataSource = Ds.Tables(0) .DataTextField = "Nombre_Provincia" .DataValueField = "IdProvincia" .DataBind() End With

DDLProvincia.Items.Add("- Seleccione -") DDLProvincia.SelectedValue = "- Seleccione -"

Catch ex As Exception MsgBox(Err.Description) End Try End Sub

Procedimiento Para Cargar Los Datos De La Tabla Usuarios Al GridView y Entregar El Total De Registros Dentro De Un Label.

Sub Cargar_Datos(ByVal Grid As GridView, ByVal Sql As String, ByVal ToReg As Label) Try Dim Da As New OleDbDataAdapter(Sql, CN) Dim Ds As New Data.DataSet Da.Fill(Ds, 0)

With Grid .DataSource = Ds.Tables(0) .DataBind() End With

Dim Total As Integer = Ds.Tables(0).Rows.Count

If Total = 0 Then ToReg.Text = "No Hay Usuarios Registrados...!" ElseIf Total = 1 Then ToReg.Text = "1 Usuario Registrado...!" ElseIf Total > 1 Then ToReg.Text = Total & " Usuarios Registrados...!" End If

Catch ex As Exception MsgBox(Err.Description) End Try End Sub

Procedimiento Para Bloquear Los Datos Del Formulario (TextBox y DropdownList)

Sub Bloquear_Datos(ByVal Id As Boolean, _ ByVal NomApe As Boolean, _ ByVal Correo As Boolean, _ ByVal Contra As Boolean, _ ByVal Pais As Boolean, _ ByVal Provincia As Boolean) TxtId.Enabled = Id TxtNombres.Enabled = NomApe TxtCorreo.Enabled = Correo TxtContra.Enabled = Contra DDLPais.Enabled = Pais DDLProvincia.Enabled = Provincia End Sub

Procedimiento Para Bloquear Los Botones De Mantenimiento (Nuevo, Cancelar, Registrar, Editar y Eliminar)

Sub Bloquear_Botones(ByVal BUSCAR As Boolean, _ ByVal NUEVO As Boolean, _ ByVal CANCEL As Boolean, _ ByVal REG As Boolean, _ ByVal EDITAR As Boolean, _ ByVal ELIMINAR As Boolean) BtnBuscar.Enabled = BUSCAR BtnNuevo.Enabled = NUEVO BtnCancelar.Enabled = CANCEL BtnRegistrar.Enabled = REG BtnEditar.Enabled = EDITAR BtnEliminar.Enabled = ELIMINAR End Sub

Procedimiento Para Limpiar Los Controles Del Formulario Web

Sub Limpiar() TxtId.Text = "" TxtNombres.Text = "" TxtCorreo.Text = "" TxtContra.Text = "" DDLPais.SelectedIndex = 0 DDLProvincia.Items.Clear() DDLProvincia.Items.Add("- Seleccione -") DDLProvincia.SelectedValue = "- Seleccione -" End Sub

Cdigo Dentro Del Formulario Web Evento: PageLoad

If Not Page.IsPostBack Then

Call Cargar_Paises() DDLProvincia.Items.Add("- Seleccione -") Call Cargar_Datos(DgvDatos, Listado, LblTotal)

Call Bloquear_Datos(1, 0, 0, 0, 0, 0) Call BLOQUEAR_BOTONES(1, 1, 1, 0, 0, 0)

End IfCdigo Dentro Del DDLPais Evento: SelectedIndexChanged

Call Cargar_Provincias()

Cdigo Dentro Del Botn: Buscar Evento: Click

Try

If Trim(TxtId.Text) = "" Then Limpiar() Return End If

Dim Buscar As String Buscar = "Select * From Usuarios Where IdUsuario= " & (TxtId.Text) & ""

Dim CMD As New OleDbCommand(Buscar, CN) Dim DR As OleDbDataReader CN.Open() DR = CMD.ExecuteReader

If DR.Read Then TxtNombres.Text = DR(1) TxtCorreo.Text = DR(2) TxtContra.Text = DR(3) DDLPais.Text = DR(4) Call Cargar_Provincias() DDLProvincia.SelectedValue = DR(5) MsgBox("Registro Ubicado Correctamente...!") Call BLOQUEAR_BOTONES(1, 0, 1, 0, 1, 1) CN.Close() Else MsgBox("Usuario No Registrado...!") Call Limpiar() Call BLOQUEAR_BOTONES(1, 1, 1, 0, 0, 0) CN.Close() End If

CN.Close() Catch ex As ExceptionMsgBox(err.description) End Try

Cdigo Dentro Del Botn: Nuevo Evento: Click

Try 'GENERANDO UN CODIGO Dim BUSCAR As String BUSCAR = "Select Max(IdUsuario) From Usuarios"

Dim CMD As New OleDbCommand(BUSCAR, CN) Dim DR As OleDbDataReader CN.Open() DR = CMD.ExecuteReader

If DR.Read Then TxtId.Text = DR(0) + 1 End If CN.Close()

Call Bloquear_Datos(0, 1, 1, 1, 1, 1) Call BLOQUEAR_BOTONES(0, 0, 1, 1, 0, 0) Catch ex As Exception MsgBox(Err.Description) End Try

Cdigo Dentro Del Botn: Cancelar Evento: Click

Call Limpiar() Call BLOQUEAR_BOTONES(1, 1, 1, 0, 0, 0) Call Bloquear_Datos(1, 0, 0, 0, 0, 0) BtnEditar.Text = "Editar"

Cdigo Dentro Del Botn: Registrar Evento: Click

Try

'CODIGO PARA NO REGISTRAR UN Usuario 2 VECES CON LA MISMA Cuenta Dim Buscar As String

Buscar = "Select * From Usuarios Where " & _ "Nombres_Apellidos = '" + StrConv(TxtNombres.Text, 3) + "' And " & _ "Correo = '" + StrConv(TxtCorreo.Text, 3) + "' "

Dim CMDBuscar As New OleDbCommand(Buscar, CN) Dim Dr As OleDbDataReader

CN.Open() Dr = CMDBuscar.ExecuteReader

If Dr.Read Then MsgBox("El Usuario: " & TxtNombres.Text & Chr(13) & "Ya Esta Registrado...!", _ MsgBoxStyle.Information, "Aviso") Return End If

CN.Close()

'''''''''''''''''''''''''' - REGISTRANDO USUARIO A LA BASE DE DATOS' Dim Registrar As String

Registrar = "Insert Into Usuarios Values " & _ "(" & (TxtId.Text) & "," & _ "'" + StrConv(TxtNombres.Text, 3) + "'," & _ "'" + StrConv(TxtCorreo.Text, 3) + "'," & _ "'" + (TxtContra.Text) + "'," & _ "" & (DDLPais.SelectedValue) & "," & _ "" & (DDLProvincia.SelectedValue) & ")" Dim CMDRegistrar As New OleDbCommand(Registrar, CN) CN.Open() CMDRegistrar.ExecuteNonQuery() CN.Close()

MsgBox("Usuario Registrado Correctamente...!", MsgBoxStyle.Information, "Confirmacin")

Call Limpiar() Call Bloquear_Datos(1, 0, 0, 0, 0, 0) Call BLOQUEAR_BOTONES(1, 1, 1, 0, 0, 0) Call Cargar_Datos(DgvDatos, Listado, LblTotal)

Catch ex As Exception

MsgBox(Err.Description)

End Try

End Sub

Cdigo Dentro Del Botn: Editar Evento: Click

Try If BtnEditar.Text = "Editar" Then BtnEditar.Text = "Actualizar" Call Bloquear_Datos(0, 1, 1, 1, 1, 1) Call BLOQUEAR_BOTONES(0, 0, 1, 0, 1, 0) Else Dim ACTUALIZAR As String

ACTUALIZAR = "UpDate Usuarios Set " & _ "Nombres_Apellidos= '" + StrConv(TxtNombres.Text, 3) + "'," & _ "Correo='" + StrConv(TxtCorreo.Text, 3) + "'," & _ "Contrasea='" + (TxtContra.Text) + "'," & _ "IdPais=" & (DDLPais.SelectedValue) & "," & _ "IdProvincia=" & (DDLProvincia.SelectedValue) & " " & _ "Where IdUsuario=" & (TxtId.Text) & ""

Dim CMDActualizar As New OleDbCommand(ACTUALIZAR, CN) CN.Open() CMDActualizar.ExecuteNonQuery() CN.Close()

MsgBox("Registro Actualizado Corretamente..!", MsgBoxStyle.Information, "Confirmacin")

Call Limpiar() Call Bloquear_Datos(1, 0, 0, 0, 0, 0) Call BLOQUEAR_BOTONES(1, 1, 1, 0, 0, 0) Call Cargar_Datos(DgvDatos, Listado, LblTotal)

BtnEditar.Text = "Editar"

End If Catch ex As Exception MsgBox(Err.Description) End Try

Cdigo Dentro Del Botn: Eliminar Evento: Clic

Try MSJ = MsgBox("Desea Retirar Al Usuario: " & TxtNombres.Text, _ MsgBoxStyle.Question + vbYesNo, "Confirmacin")

If MSJ = vbYes Then Dim Eliminar As String Eliminar = "Delete From Usuarios Where IdUsuario=" & (TxtId.Text) & "" Dim CMDEliminar As New OleDbCommand(Eliminar, CN) CN.Open() CMDEliminar.ExecuteNonQuery() CN.Close()

MsgBox("Usuario Retirado...!", MsgBoxStyle.Information, "Confirmacin")

Call Limpiar() Call Bloquear_Datos(1, 0, 0, 0, 0, 0) Call BLOQUEAR_BOTONES(1, 1, 1, 0, 0, 0) Call Cargar_Datos(DgvDatos, Listado, LblTotal)

End If Catch ex As Exception MsgBox(Err.Description) End Try

Finalmente Ejecutar Su Aplicacin Web Y Realizar 5 Registros, Adems Probar La Funcionalidad De Los Botones, Cualquier Validacin Faltante Adicionarlo y Mejorar Su Presentacin.PROPUESTO N 1: DISEO DE REGISTROS WEB

En La Misma Base De Datos Crear Las Siguientes Tablas: (HAPPYLAND y HOROSCOPOFREE)

Adicionarle Los Siguientes Registros A Las Tablas:

DISEO DEL FORMULARIO WEB HAPPYLAND

VALIDACIONES DE FORM - HAPPYLAND: Al Iniciar El Formulario De Registro, Se Tendr Que Mostrar Las Siguientes Preguntas De Seguridad En El DDLPREGUNTA:

Cmo Se Llama Tu Mascota? Nombre De Tu Colegio En Primaria? Primer Apellido De Tu Padre? Cul Es Tu Signo Zodiacal? Cul Es Tu Plato Favorito? Nombre De Tu Mejor Amigo?

El Botn ENVIAR, Permitir Almacenar Los Datos Ingresados En Los Controles De Texto y Seleccin En La Tabla: HAPPYLAND. (EN MAYUSCULAS) Validar Los Controles De Texto y Seleccin, Utilizar Controles De Validacin (RequeriedFieldValidator, CompareValidator, RangeValidator, RegularExpressionValidator y ValidatorSummary) El Botn CANCELAR, Limpiara Todos Los Datos Ingresados En Los Controles De Texto y Seleccin.

DISEO DEL FORMULARIO WEB HOROSCOPOFREE

VALIDACIONES DE FORM - HOROSCOPOFREE: Al Iniciar El Formulario De Registro, Se Tendr Que Mostrar Las Siguientes Opciones En Los Controles De Seleccin:

DDLSEXO - Seleccione - Masculino Femenino

DDLPAIS Enlazar Los Datos Con La Tabla Pas De La Base De Datos.

DDLPROFESION - Seleccione - Profesor(a) Doctor(a) Secretaria Asistente Ama De Casa Otros

DDLTITULO - Seleccione - Primaria Secundaria Tcnico Superior Tcnico Universitario

DDLDIA Da Agregar Del 1 Hasta El 31

DDLMES Mes Agregar De Enero Hasta Diciembre

DDLAO Ao Agregar Desde 1950 Hasta El Ao De Hoy.

El Botn ENVIAR, Permitir Almacenar Los Datos Ingresados En Los Controles De Texto y Seleccin En La Tabla: HOROSCOPOFREE. (EN MAYUSCULAS) Validar Los Controles De Texto y Seleccin, Utilizar Controles De Validacin (RequeriedFieldValidator, CompareValidator, RangeValidator, RegularExpressionValidator y ValidatorSummary) El Botn CANCELAR, Limpiara Todos Los Datos Ingresados En Los Controles De Texto y Seleccin.

NOTA:

Se Calificara La Buena Funcionalidad y Diseo De Los Formularios De Registro Web, Crear Nuevos Estilos Personalizados Para Tus Controles.