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.Navigation;
using System.Windows.Shapes;

namespace Agency
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        private void JumpMainWindows_Click(object sender, RoutedEventArgs e)
        {
            gr606_midvlContext context = new gr606_midvlContext();
            var users = context.Persons;
            Person user = users.SingleOrDefault(x => x.Login == LoginBox.Text && x.Password == PasswordBox.Password);
            if (user == null)
            {
                MessageBox.Show("Пользователь не найден!");
            }
            else
            {
                PersonSave.Id = user.IdPerson;
                PersonSave.Login = user.Login;
                PersonSave.Password = user.Password;
                PersonSave.LastName = user.LastName;
                PersonSave.Name = user.FirstName;
                PersonSave.MidleName = user.MidleName;
                PersonSave.PhoneNumber = user.PhoneNumber;
                Windows.HomeWindow homeWindow = new Windows.HomeWindow();
                homeWindow.Show();
                this.Hide();
            }
        }

        private void HideText(object sender, MouseEventArgs e)
        {
            LoginBox.Text = ""; // При навидении на LoginBox делает его пустым
            LoginBox.IsReadOnly = false;
        }

        private void LeaveCursor(object sender, MouseEventArgs e)
        {
            if (LoginBox.Text == "")
            {
                LoginBox.Text = "Введите логин!";
                LoginBox.IsReadOnly = true;
            }
        }

        private void Label_MouseDown(object sender, MouseButtonEventArgs e)
        {
            Windows.CreateAc reg = new Windows.CreateAc();
            reg.Show();
            this.Hide();
        }
    }
}
