1 / 18

ADO EN ASP.NET CON SQL SERVER

ADO EN ASP.NET CON SQL SERVER. Crear formulario de Autenticacion Crear página maestra Crear página de clientes Crear página de películas Crear página de consultas. Formulario de autenticación:. Para crear el formulario de Autenticación agregar los siguientes controles:

keita
Télécharger la présentation

ADO EN ASP.NET CON SQL SERVER

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. ADO EN ASP.NET CON SQL SERVER • Crear formulario de Autenticacion • Crear página maestra • Crear página de clientes • Crear página de películas • Crear página de consultas

  2. Formulario de autenticación:

  3. Para crear el formulario de Autenticación agregar los siguientes controles: • Un template con Header, Side y Footer. • Un control de Login con el nombre de logacceso. • Como encabezado en el Header del Template agregar una imagen de fondo llamada Header.jpg. • Una imagen llamada cerdossalvajesconunpardnw6.jpg.

  4. Crear una base de datos en SQL SERVER llamada Usuarios y una tabla Usuarios con los siguientes campos, declarando login_usu como llave primaria.

  5. Agregar un procedimiento almacenado a la base de datos:

  6. CÓDIGO DEL PROCEDIMIENTO ALMACENADO ALTER PROCEDURE dbo.usp_VerificarUsuario ( @user varchar(15), @pass varchar(15), @res bit OUTPUT ) AS SET NOCOUNT ON if (select top 1 count(*) from usuarios where cast(login_usu as varbinary) = cast(@user as varbinary) and cast(pass_usu as varbinary)=cast(@pass as varbinary)) = 1 set @res=1 else set @res=0 RETURN 0

  7. AGREGAR UNA CLASE LLAMADA APP_CODE CON EL SIGUIENTE CÓDIGO: Imports System.Web.Security Imports System.Web.UI Imports System.Web.UI.WebControls Imports system.web.ui.webcontrols.WebParts Imports System.Web.UI.HtmlControls Imports System.Data.SqlClient Public Class Dal_Acceso Public cnn As New SqlConnection(ConfigurationManager.ConnectionStrings("connectionstring").ConnectionString) Private autorizado1 As Boolean = False Public Function autorizado() As Boolean Return autorizado1 End Function Public Sub verificaracceso(ByValusuario As String, ByVal password As String) Try Dim cmd As New SqlCommand("usp_VerificarUsuario", cnn) cmd.CommandType = CommandType.StoredProcedure cmd.Parameters.Add("@user", SqlDbType.NVarChar, 15) cmd.Parameters("@user").Value = usuario cmd.Parameters.Add("@pass", SqlDbType.NVarChar, 15) cmd.Parameters("@pass").Value = password cmd.Parameters.Add("@res", SqlDbType.Bit) cmd.Parameters("@res").Direction = ParameterDirection.Output cnn.Open() cmd.ExecuteNonQuery() autorizado1 = Convert.ToBoolean(cmd.Parameters("@res").Value) cmd.Dispose() cnn.Close() Catch ex As Exception End Try End Sub End Class

  8. MODIFICAR EL WEBCONFIG DE SU APLICACIÓN AGREGANDO EL CÓDIGO CONTENIDO EN EL ARCHIVO DE TEXTO LLAMADO WEBCONFIG

  9. CÓDIGO DEL CONTROL LOGACCESO EN EL EVENTO Authenticate Dim x As New Dal_Acceso x.verificaracceso(Server.HtmlEncode(Logacceso.UserName), Server.HtmlEncode(Logacceso.Password)) e.Authenticated = x.autorizado

  10. CÓDIGO DEL EVENTO PAGE LOAD DEL FORMULARIO AUTENTICACION If (HttpContext.Current.User.Identity.IsAuthenticated) Then Response.Redirect("Default.aspx") End If

  11. FunctionSaveDatos Private Function savedatos() As Integer Dimnumerocliente As Integer = 0 Dim conexionstring As String = ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString Dim myconexion As New SqlConnection(conexionstring) Dim DatosDataSource As SqlDataSource = New SqlDataSource() Dimstrquery As String = "INSERT INTO [CLIENTES] ([clave], [nombre], [edad], [sexo], [lugar], [estadocivil], [nivelestudios], [ocupacion], [fecha], [sueldo]) VALUES (@clave, @nombre, @edad, @sexo, @lugar, @estadocivil, @nivelestudios, @ocupacion, @fecha, @sueldo)" Dim mycommand As New SqlCommand(strquery, myconexion) mycommand.Parameters.AddWithValue("@clave", txtclave.Text) mycommand.Parameters.AddWithValue("@nombre", txtnombre.Text) mycommand.Parameters.AddWithValue("@edad", txtedad.Text) mycommand.Parameters.AddWithValue("@sexo", dropsexo.Text) mycommand.Parameters.AddWithValue("@lugar", droplugar.Text) mycommand.Parameters.AddWithValue("@estadocivil", dropcivil.Text) mycommand.Parameters.AddWithValue("@nivelestudios", txtnivel.Text) mycommand.Parameters.AddWithValue("@ocupacion", txtocupacion.Text) mycommand.Parameters.AddWithValue("@fecha", txtfecha.Text) mycommand.Parameters.AddWithValue("@sueldo", txtsueldo.Text) myconexion.Open() numerocliente = Convert.ToInt32(mycommand.ExecuteScalar) myconexion.Close() Return (numerocliente) End Function

  12. Código Guardar Dimnumcliente As Integer = savedatos() If numcliente = -1 Then QueryResult.Text = "UN ERROR HA OCURRIDO=" Else QueryResult.Text = "LOS DATOS DEL ALUMNO FUERON GUARDADOS EXITOSAMENTE" End If txtnombre.Enabled = False txtfecha.Enabled = False txtclave.Enabled = False txtedad.Enabled = False dropsexo.Enabled = False droplugar.Enabled = False dropcivil.Enabled = False txtnivel.Enabled = False txtocupacion.Enabled = False txtsueldo.Enabled = False GridView1.DataBind() Button1.Enabled = False Button2.Enabled = True

  13. Código Agregar txtnombre.Enabled = True txtfecha.Enabled = True txtclave.Enabled = True txtedad.Enabled = True dropsexo.Enabled = True droplugar.Enabled = True Dropcivil.Enabled = True txtnivel.Enabled = True txtocupacion.Enabled = True txtsueldo.Enabled = True txtnombre.Text = "" txtfecha.Text = "" txtclave.Text = "" txtedad.Text = "" dropsexo.ClearSelection() droplugar.ClearSelection() Dropcivil.ClearSelection() txtnivel.Text = "" txtocupacion.Text = "" txtsueldo.Text = "" txtclave.Focus() txtfecha.Text = Now Button1.Enabled = True

  14. CONSULTAS • Crear formularios de consultas por Nombre de película.

  15. COMENTARIOS POR SU ATENCION GRACIAS

More Related