﻿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;

namespace Sitema_Hotel_Harmonia
{
    public partial class frmLogIn : Form
    {
        SqlConnection ConexaoBD = new SqlConnection();

        public frmLogIn()
        {
            InitializeComponent();

        }

        private void frmLogIn_Load(object sender, EventArgs e)
        {
            ConexaoBD.ConnectionString = "Data Source=localhost\\SQLEXPRESS;Initial Catalog=HOTELBD;Integrated Security=True";
        }

        private void btnEntrar_Click(object sender, EventArgs e)
        {
            
            ConexaoBD.Open();
            SqlCommand ComandoBuscaUsuario = new SqlCommand(String.Format("SELECT * FROM USUARIOS WHERE ESTADO_USUARIO = 'ATIVO' AND NOME_USUARIO='{0}' AND SENHA_USUARIO='{1}'", txtUsuario.Text, Criptografa(txtSenha.Text)), ConexaoBD);
            SqlDataAdapter AdaptadorLogIn = new SqlDataAdapter(ComandoBuscaUsuario);
            DataTable DadosLogIn = new DataTable();
            AdaptadorLogIn.Fill(DadosLogIn);
            if (DadosLogIn.Rows.Count > 0)
            {
                Usuario.Inicializar(Convert.ToInt32(DadosLogIn.Rows[0][0]), Convert.ToString(DadosLogIn.Rows[0][1]), Convert.ToDateTime(DadosLogIn.Rows[0][3]), Convert.ToString(DadosLogIn.Rows[0][6])); 
                Form frmPrincipal = new frmdiPrincipal(ConexaoBD);
                frmPrincipal.Show();
                ConexaoBD.Close();
                this.Close();
            }
            else
                MessageBox.Show("Usuário Inválido");


            ConexaoBD.Close();
        }

        private string Criptografa(string senha)
        {
            return senha;
        }

        private void btnCancelar_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }


    }
}
