using System;
using System.Collections.Generic;
using System.Globalization;
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 WpfApp1
{
    /// <summary>
    /// Логика взаимодействия для pgAuth.xaml
    /// </summary>
    public partial class pgAuth : Page
    {
        public pgAuth()
        {
            InitializeComponent();
            BaseConnect.BaseModel = new ToursEntities();
            Captha();
        }

        void Captha()
        {
            Random random = new Random();
            int num = random.Next(1000, 9999);
            var pixels = new byte[150 * 150 * 4];
            random.NextBytes(pixels);
            var visual = new DrawingVisual();
            BitmapSource bitmapSource = BitmapSource.Create(150, 150, 96, 96, PixelFormats.Pbgra32, null, pixels, 150 * 4);
            using (DrawingContext drawingContext = visual.RenderOpen())
            {
                drawingContext.DrawText(
                new FormattedText(num.ToString(), CultureInfo.CurrentCulture, FlowDirection.LeftToRight, new Typeface("Arial"), 100, System.Windows.Media.Brushes.Red),
                new System.Windows.Point(0, 150 / 2));

                drawingContext.DrawImage(bitmapSource, new Rect(0, 0, 256, 256));
            }
            var image = new DrawingImage(visual.Drawing);
            imgCaptcha.Source = image;
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            Auth auth = BaseConnect.BaseModel.Auth.FirstOrDefault(x => x.Login == tbLogin.Text && x.Password == tbPass.Text);
            if (auth != null)
            {
                MessageBox.Show("Auth");
            }
            else
                MessageBox.Show("Dis");
        }
    }
}
