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 MySql.Data.MySqlClient;
using MySql.Data;

namespace EjemploMysql
{
    public partial class frmPassServidor : Form
    {
       
        MySqlConnection conector;
        public frmPassServidor()
        {
            conexionBD();
            InitializeComponent();
        }
        public Boolean contrasena { get; set; }
        void conexionBD()
        {
            conector = new MySqlConnection();
            try
            {
                conector.ConnectionString = "Server=localhost;Port=3306;DataBase=ejemploMysql;Uid=root;Pwd=123";
                conector.Open();

            }
            catch (MySqlException e)
            {
                e.ErrorCode.ToString();
            }
        }
        
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                if (conector.State != ConnectionState.Open)
                {
                    conector.Open();
                }
                    MySqlCommand comando = conector.CreateCommand();
                    comando.CommandText = "select *from usuarios where usuario='admin' and password='" + txtPassword.Text + "';";
                    MySqlDataReader consulta = comando.ExecuteReader();
                    if (consulta.Read())
                    {
                        
                        contrasena = true;
                        DialogResult = DialogResult.OK;
                        this.Close();
                    }
                    else
                    {
                        
                        contrasena = false;
                        DialogResult = DialogResult.OK;
                        this.Close();
                    }
                
            }
            catch (MySqlException e1)
            {
                e1.ErrorCode.ToString();
            }

        }
    }
}
