Kaynağa Gözat

Сделана авторизация

MeseryGG 5 ay önce
ebeveyn
işleme
a5a93f26b0

+ 2 - 2
DemoExam/DemoExam/Pages/AuthorizationUserControl.xaml

@@ -20,11 +20,11 @@
         <Label Content="Авторизация" HorizontalAlignment="Center" VerticalAlignment="Top" Margin="30"/>
 
         <GroupBox Grid.Row="2" Header="Логин" Margin="0 0 0 30">
-            <TextBox BorderThickness="0" VerticalContentAlignment="Center" Height="40"/>
+            <TextBox BorderThickness="0" VerticalContentAlignment="Center" Height="40" Name="LoginTB"/>
         </GroupBox>
 
         <GroupBox Grid.Row="3" Header="Пароль">
-            <TextBox BorderThickness="0" VerticalContentAlignment="Center" Height="40"/>
+            <TextBox BorderThickness="0" VerticalContentAlignment="Center" Height="40" Name="PasswordTB"/>
         </GroupBox>
 
         <Button Grid.Row="5" Width="400" Height="60" Margin="0 30 0 20" Click="AuthorizeButton_ClickHandler">

+ 14 - 1
DemoExam/DemoExam/Pages/AuthorizationUserControl.xaml.cs

@@ -32,7 +32,20 @@ namespace DemoExam.Pages
 
         private void AuthorizeButton_ClickHandler(object sender, RoutedEventArgs e)
         {
-            MainWindow.ShowingPage = new RepairListUserControl();
+            using (Entities db = new Entities())
+            {
+                Users user = db.Users.Where(a => a.UserLogin == LoginTB.Text && a.UserPassword == PasswordTB.Text).FirstOrDefault();
+                if(user != null)
+                {
+                    MessageBox.Show("Вы успешно авторизовались!", "Авторизация");
+                    MainWindow.ShowingPage = new RepairListUserControl();
+                }
+                else
+                {
+                    MessageBox.Show("Пользователя с таким логином и паролем несуществует", "Авторизация");
+                }
+            }
+            
         }
     }
 }