using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Data.SqlClient;
using System.Data;
using System.Configuration;
using MySql.Data.MySqlClient;
namespace KursachMukha692gr
{

    /// <summary>
    /// Логика взаимодействия для Registration.xaml
    /// </summary>
    public partial class Registration : Window
    {
        public Registration()
        {
            InitializeComponent();

            /*DataTable dt_infoadmins = Select("select * from [dbo].[infoadmin]");//получаем данные из таблицы
            for(int i =0; i< dt_infoadmins.Rows.Count;i++)//перебираем данные
            {
                MessageBox.Show(dt_infoadmins.Rows[i][7] + " " + dt_infoadmins.Rows[i][8]);
            }*/
        }
        /*public bool Reg(string log,string pas)
        {
            if (string.IsNullOrEmpty(log) || string.IsNullOrEmpty(pas))
            {
                return false;
            }
            using (var db = new KURSACH1Entities2())
            {
                var uch = db.infoadmins
                    .AsNoTracking()
                    .FirstOrDefault(item => item.loginAdmin == Login.Text && item.passAdmin == pass1.Password);
                if (uch == null)
                {
                    return false;
                }
                return true;
            }
        }*/
        /*public bool Reg(string log,string pas)
        {
            log = Login.Text;
            pas = pass1.Password;
            if (log.Length > 0)
            {
                if (pas.Length > 0)
                {
                    DataTable dt_infoadmins = Select("select * from [dbo].[infoadmin] where [loginAdmin] = '" + Login.Text + "' and [passAdmin] = '" + pass1.Password + "'");
                    if (dt_infoadmins.Rows.Count > 0)
                    {
                        MessageBox.Show("Авторизация пройдена успешно");
                        KabinetAdmina kabinetAdmina = new KabinetAdmina();
                        kabinetAdmina.Show();
                        Close();
                        return true;
                    }
                    else
                    {

                        MessageBox.Show("Пользователь не найден");
                        return false;
                    }
                }
                else
                {
                    MessageBox.Show("Введите пароль");
                }
            }
            else
            {
                MessageBox.Show("Введите логин");
            }
        }*/
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            if(Login.Text.Length > 0)
            {
                if(pass1.Password.Length > 0)
                { 
                   DataTable dt_infoadmins = Select("select * from [dbo].[infoadmin] where [loginAdmin] = '" + Login.Text + "' and [passAdmin] = '" + pass1.Password + "'");
                   if (dt_infoadmins.Rows.Count > 0)
                    {
                       
                       MessageBox.Show("Авторизация пройдена успешно");
                       KabinetAdmina kabinetAdmina = new KabinetAdmina();
                       kabinetAdmina.Show();
                       Close();
                    }
                   else
                   {
                       
                        MessageBox.Show("Пользователь не найден");
                   }    
                }
                else 
                {
                    
                    MessageBox.Show("Введите пароль");
                    
                }
            }
            else
            {
                
                MessageBox.Show("Введите логин");
                
            }
        }
        private void Button_Click_Back(object sender, RoutedEventArgs e)
        {
            MainWindow main = new MainWindow();
            main.Show();
            Close();
        }
        public DataTable Select(string selectSQL)
        {
            DataTable dataTable = new DataTable("dataBase");
            SqlConnection sqlConnection = new SqlConnection("server=WIN-2CL665KE0ED; Trusted_Connection=YES;DataBase=KURSACH1;");
            sqlConnection.Open();
            SqlCommand sqlCommand = sqlConnection.CreateCommand();
            sqlCommand.CommandText = selectSQL;
            SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(sqlCommand);
            sqlDataAdapter.Fill(dataTable);
            sqlConnection.Close();
            return dataTable;
        }

        private void Button_Click_Smena(object sender, RoutedEventArgs e)
        {
            SmenaPassword smenaPassword = new SmenaPassword();
            smenaPassword.Show();
            Close();
        }
    }
}