예제 #1
0
        private async void MetroWindow_Loaded(object sender, RoutedEventArgs e)
        {
            MainFrame.Content = new DesktopPage();

            // Вход в систему

            while (true)
            {
                LoginDialogData resultLogin = await MessageService.MetroLoginDialog();

                if (resultLogin != null)
                {
                    ProgressDialogController controller = await this.ShowProgressAsync("Пожалуйста ожидайте", "Идет проверка данных...");

                    Staff staff = await Task <Staff> .Factory.StartNew(() => _databasenEtities.Staff.SingleOrDefault(a => a.Login == resultLogin.Username));

                    using (MD5 md5Hash = MD5.Create())
                    {
                        await controller.CloseAsync();

                        if (staff != null && HashMD5.VerifyMd5Hash(md5Hash, resultLogin.Password, staff.Password))
                        {
                            Application.Current.Properties["ID_User"] = _ID_User = staff.ID;
                            break;
                        }
                        else
                        {
                            await MessageService.MetroMessageDialog("Результат входа", "Вы ввели неверный логин или пароль!");
                        }
                    }
                }
                else
                {
                    Close();
                }
            }

            _dispatcherTimer.Interval = new TimeSpan(0, 5, 0);
            _dispatcherTimer.Tick    += dispatcherTimer_Tick;
            _dispatcherTimer.Start();
        }