using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Data.Common;
namespace SICPE
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void btnSubmit_Click(object sender, EventArgs e)
{
// 1 - Crear una instancia de la clase SqlConnection
string sCnn = "Data Source=" + textBox1.Text + ";Initial Catalog=" + textBox2.Text + ";Integrated Security=True";
using (SqlConnection Cnn
= new SqlConnection
(sCnn
)) {
try
{
//ahora compruebo que la conexion este abierta
if(Cnn.State == ConnectionState.Closed)
{
Cnn.Open();
// 3 - Crear un nuevo comando para login
SqlCommand login1
= new SqlCommand
("SELECT nombUsuario, contUsuario FROM dbo.usuario WHERE nombUsuario=' " + textBox3
.Text + " ' ", Cnn
); //Ahora para ejecutar la lectura de la bd creo un reader
SqlDataReader Reader1;
//asigno al reader el comando que escribi arriba
Reader1 = login1.ExecuteReader();
//ahora mientras se ejecuta comparo los datos
while (Reader1.Read())
{
if (Reader1.GetString(0) == textBox3.Text)
{
//verificar si la contraseña le pertenece a este nick
if (Reader1.GetString(1) == textBox4.Text)
{
//Codigo a realizar si el login es correcto
Form2 Form2
= new Form2
(); Form2.Show();
this.Hide();
}
else
{
MessageBox.Show("Error, la contraseña es incorrecta","", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
else
{
MessageBox.Show("Error, el usuario no existe", "", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}
catch
{
MessageBox.Show("Revise los datos introducidos", "Error en la conexion", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
private void btnCancel_Click(object sender, EventArgs e)
{
Application.Exit();
}
}
}