Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- protected void Page_Load(object sender, EventArgs e)
- {
- carga();
- }
- private void carga()
- {
- datlogin dat = new datlogin();
- bool prueba = dat.veri;
- if(prueba == false)
- {
- Response.Redirect("login.aspx");
- }
- else { LBL_Nombre.Text = dat.nom; LBL_apellido.Text = dat.apel; }
- }
- protected void cerrar(object sender, EventArgs e)
- {
- datlogin dat = new datlogin();
- bool sesion = dat.veri;
- if(sesion==true)
- {
- dat.veri = false;
- dat.id = ""; dat.nom = ""; dat.apel = "";
- Response.Redirect("login.aspx");
- }
- }
- protected void Page_Load(object sender, EventArgs e)
- {
- }
- protected void btnIngresar_Click(object sender, EventArgs e)
- {
- comprobacion();
- }
- private void comprobacion()
- {
- string usua = TXT_Usuario.Text;
- string clav = TXT_clave.Text;
- datlogin dat = new datlogin();
- dat.usu = usua;
- dat.pas = clav;
- logindat log = new logindat();
- if (dat.veri == true) { alert.Visible = false; Response.Redirect("Default.aspx"); }
- else { alert.Visible = true; }
- }
- private static string Usuario = string.Empty;
- private static string Password = string.Empty;
- private static bool verifica = false;
- private static string Nombre = string.Empty;
- private static string Apellido = string.Empty;
- private static string ID = string.Empty;
- public string usu
- {get { return Usuario; } set { Usuario = value; }}
- public string pas
- {get { return Password; } set { Password = value; }}
- public bool veri
- {get { return verifica; } set { verifica = value; }}
- public string nom
- {get { return Nombre; }set { Nombre = value; }}
- public string apel
- {get { return Apellido; } set { Apellido = value; }}
- public string id
- {get { return ID; } set { ID = value; }}
- public logindat()
- {
- verificacion();
- }
- string usua;
- string clave;
- private void verificacion()
- {
- datlogin dat = new datlogin();
- usua = dat.usu;
- clave = dat.pas;
- Datos his = new Datos();
- DataTable tabla = new DataTable();
- string id = "";
- string nombre = "";
- string apellidos = "";
- try
- {
- tabla = his.iniciar("datosusu");
- id = tabla.Rows[0]["id_usuario"].ToString();
- nombre = tabla.Rows[0]["nombre"].ToString();
- apellidos = tabla.Rows[0]["apellidos"].ToString();
- }
- catch { }
- string id2 = "0";
- string nom = "No existe";
- string ape = "No existe";
- if (id != id2 && nombre!=nom && apellidos!=ape && id != "" && nombre != "" && apellidos != "")
- {
- dat.veri = true;
- dat.id = id;
- dat.nom = nombre;
- dat.apel = apellidos;
- }
- else { dat.veri = false; dat.id = ""; dat.nom = ""; dat.apel = ""; }
- }
- SqlConnection conn;
- public Datos()
- {
- SqlConnectionStringBuilder sb = new SqlConnectionStringBuilder();
- sb["Data Source"] = "10.0.0.77";
- sb["Initial Catalog"] = "BDprueba";
- sb["Persist Security Info"] = "True";
- sb["User ID"] = "sa";
- sb["Password"] = "123456";
- conn = new SqlConnection(sb.ConnectionString);
- }
- public DataTable iniciar(string tabla)
- {
- datlogin log = new datlogin();
- string usua = log.usu;
- string clav = log.pas;
- DataTable dt = new DataTable();
- string sql = "";
- switch (tabla)
- {
- case "datosusu":
- sql = "execute verificacion '"+usua+"','"+clav+"'";
- break;
- default:
- dt.Columns.Add("id_usuario");
- dt.Columns.Add("nombrer");
- dt.Columns.Add("apellidos");
- dt.Rows.Add("0", "No existe","No existe");
- break;
- }
- if (sql != "")
- {
- try
- {
- DataSet ds = new DataSet();//conjunto de tablas virtuales
- SqlDataAdapter da = new SqlDataAdapter(sql, conn);
- da.Fill(ds);
- if (ds.Tables.Count > 0)
- dt = ds.Tables[0];
- }
- catch
- {
- dt.Columns.Add("id_usuario");
- dt.Columns.Add("nombrer");
- dt.Columns.Add("apellidos");
- dt.Rows.Add("0", "No existe", "No existe");
- }
- }
- return dt;
- }
- ALTER PROCEDURE [dbo].[verificacion]
- @usuario nvarchar(50),
- @clave nvarchar(50)
- AS
- BEGIN
- SET NOCOUNT ON;
- if @clave=(select clave from tbl_usuarios where usuario=@usuario)
- begin
- select tbl_usuarios.id_usuario,tbl_empleados.nombre,tbl_empleados.apellidos from tbl_usuarios LEFT JOIN tbl_empleados on tbl_usuarios.empleado=tbl_empleados.id_empleado where usuario=@usuario and clave=@clave
- end
- END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement