Fecha Inicial : 11/04/2018
Fecha Final :  12/04/2018
Hora Inicio: 10:07 PM
Hora Final:  1:13AM
Horas invertidas(Minutos): 174  
Colaboradores: Oscar Cortés

Actividad:

Continuar con la página web (página de inicio y página de evaluaciones (pendiente))




using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using System.Data;
using System.Data.SqlClient;
using System.Configuration;

namespace ProyectoEvaluaciones_BDI
{
    public partial class LogIn : System.Web.UI.Page
    {
        String connection = "Data Source=.\\Backbone;Initial " + "Catalog=AlgoDePrueba;" + "Integrated Security=True";
        protected void Page_Load(object sender, EventArgs e)
        {
            Session["Tipo"] = "";
            Session["ID"] = "";
            Session["Nombre"] = "";

        }

        protected void realizarSP(String pStoredProc)
        {
            SqlConnection sqlConnection1 = new SqlConnection(connection);
            SqlCommand cmd = new SqlCommand();


            cmd.CommandText = pStoredProc;
            cmd.CommandType = CommandType.Text;
            cmd.Connection = sqlConnection1;

            sqlConnection1.Open();
            SqlDataReader reader;
            reader = cmd.ExecuteReader();

            reader.Read();

            reader.Close();

            sqlConnection1.Close();
        }

        protected bool loginProfesor()
        {
            bool flag = false;
            SqlConnection sqlConnection1 = new SqlConnection(connection);
            SqlCommand cmd = new SqlCommand();

            cmd.CommandType = CommandType.Text;
            cmd.Connection = sqlConnection1;
            cmd.CommandText = "validarUsuario_Profesor" + TB_User.Text + ", " + TB_Password.Text;

            sqlConnection1.Open();
            SqlDataReader reader;
            reader = cmd.ExecuteReader();

            reader.Read();

            if (reader.HasRows)
            {
                Session["Tipo"] = "Profesor";
                Session["ID"] = reader.GetInt32(0).ToString();
                flag = true;
            }

            reader.Close();
            sqlConnection1.Close();
            return flag;
        }

        protected bool loginEstudiante()
        {
            bool flag = false;
            SqlConnection sqlConnection1 = new SqlConnection(connection);
            SqlCommand cmd = new SqlCommand();

            cmd.CommandType = CommandType.Text;
            cmd.Connection = sqlConnection1;
            cmd.CommandText = "validarUsuario_Estudiante" + TB_User.Text + ", " + TB_Password.Text;


            sqlConnection1.Open();
            SqlDataReader reader;
            reader = cmd.ExecuteReader();

            reader.Read();

            if (reader.HasRows)
            {
                Session["Tipo"] = "Estudiante";
                Session["ID"] = reader.GetInt32(0).ToString();
                flag = true;
            }

            reader.Close();
            sqlConnection1.Close();
            return flag;
        }


        protected void Btn_IniciarSesion_Click(object sender, EventArgs e)
        {
            if (loginProfesor() || loginEstudiante())
                TB_User.Text = "Exito";
            else
            {
                TB_User.Text = "GG";
            }
        }
    }
}


Crear SP para validar Login para profesores y Estudiantes

use algoDePrueba
go


--Retorna una consulta a la tabla profesor

create procedure validarUsuario_Profesor
@pUsuario nvarchar(50),
@pContrasenna nvarchar(50)

as
begin
Select P.ID
from Profesor P
where RTRIM(P.Email) = @pUsuario and RTRIM(P.contrasenna) = @pContrasenna
end
go 

--Retorna una consulta a la tabla estudiante
create procedure validarUsuario_Estudiante
@pUsuario nvarchar(50),
@pContrasenna nvarchar(50)

as
begin
Select E.ID
from Estudiante E
where RTRIM(E.Email) = @pUsuario and RTRIM(E.Carne) = @pContrasenna
end
go 


Problemas:
Indecisión sobre cantidad de SP para validar los usuarios


No se detectan widgets en el script (Solucionado)





Fallo en la conexión de la BD con Visual (Pendiente)

https://dba.stackexchange.com/questions/190066/unable-to-connect-to-remote-sql-server-instance-after-thorough-troubleshooting
https://stackoverflow.com/questions/11425275/connecting-to-sql-server-express-what-is-my-server-name/36932237

Comentarios