Este es un login con timer lo que hace es que al ingresar muestra un cuadro por 3 segundos de bienvenido: NombreUsuario y despues de los 3 seg. se cierra el cuadro y muestra el menu principal.
Form1
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MySql.Data.MySqlClient;
namespace LoginSimple
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void btnAceptar_Click(object sender, EventArgs e)
{
try
{
string MiConexion = "datasource=localhost;port=3306;username=root;password=12345";
MySqlConnection MiConn = new MySqlConnection(MiConexion);
MySqlCommand SelectComand = new MySqlCommand("Select * from ProyectoLink.Usuarios where Usuario='" + this.txtUsuario.Text + "' and Contraseña='" + this.txtContraseña.Text + "' ;", MiConn);
MySqlDataReader MiReader;
MiConn.Open();
MiReader = SelectComand.ExecuteReader();
int Contador = 0;
while (MiReader.Read())
{
Contador = Contador + 1;
}
if (Contador == 1)
{
Timer timer = new Timer();
timer.Interval = 1000;
timer.Enabled = true;
timer.Tick += new EventHandler(timer1_Tick);
MessageBox.Show("Bienvenido:" + txtUsuario.Text);
this.Hide();
MenuPrincipal Abrir = new MenuPrincipal();
Abrir.ShowDialog();
}
else
{
Timer timer = new Timer();
timer.Interval = 2000;
timer.Enabled = true;
timer.Tick += new EventHandler(timer1_Tick);
MessageBox.Show("Acceso denegado");
txtUsuario.Clear();
txtContraseña.Clear();
txtUsuario.Focus();
}
}
catch (Exception Ex)
{
MessageBox.Show(Ex.Message);
}
}
private void timer1_Tick(object sender, EventArgs e)
{
Timer timer = new Timer();
timer.Enabled = false;
SendKeys.Send("{ESC}");
}
}
}
Si tienen alguna duda no duden en preguntar con toda confianza...........




No hay comentarios:
Publicar un comentario