-DSG 2 rokov pred
rodič
commit
d2cadcd47d

+ 1 - 5
MyTests/ConfirmationWindow.xaml

@@ -9,7 +9,7 @@
         MinHeight="120" 
         Height="120"
         Width="300" 
-        WindowStartupLocation="CenterScreen" 
+        WindowStartupLocation="CenterOwner" 
         WindowStyle="None" 
         ResizeMode="NoResize">
     <Border BorderBrush="Black"
@@ -34,15 +34,11 @@
                         HorizontalAlignment="Center"
                         VerticalAlignment="Center">
                     <Button Content="Да" 
-                VerticalAlignment="Bottom" 
-                HorizontalAlignment="Center" 
                 Height="30" 
                 Width="130" 
                         Margin="0,0,5,0"
                 Click="YesButton"/>
                     <Button Content="Нет" 
-                VerticalAlignment="Bottom" 
-                HorizontalAlignment="Center" 
                 Height="30" 
                 Width="130"
                         Margin="5,0,0,0"

+ 1 - 0
MyTests/ConfirmationWindow.xaml.cs

@@ -9,6 +9,7 @@ namespace MyTests
         public ConfirmationWindow(bool _answer = false)
         {
             InitializeComponent();
+            Owner = Application.Current.MainWindow;
             answer = _answer;
         }
         private void YesButton(object sender, RoutedEventArgs e)

+ 3 - 1
MyTests/ErrorWindow.xaml

@@ -9,10 +9,12 @@
         MinHeight="120" 
         Height="120"
         Width="300" 
-        WindowStartupLocation="CenterScreen" 
+        WindowStartupLocation="CenterOwner" 
         WindowStyle="None" 
         ResizeMode="NoResize">
     <Border Background="#FF2D2D2D"
+            BorderBrush="Black"
+            BorderThickness="1"
             MouseDown="Border_MouseDown">
         <StackPanel>
             <TextBlock Name="ErrorLabel" 

+ 1 - 0
MyTests/ErrorWindow.xaml.cs

@@ -8,6 +8,7 @@ namespace MyTests
         public ErrorWindow(string error)
         {
             InitializeComponent();
+            Owner = Application.Current.MainWindow;
             ErrorLabel.Text = error;
         }
         private void BackClick(object sender, RoutedEventArgs e)

+ 2 - 2
MyTests/Functions.cs

@@ -41,7 +41,7 @@ namespace MyTests
         // Проверка на уникальность логина
         public static bool IsLoginAlreadyTaken(string login)
         {
-            return cnt.db.Users.Select(item => item.Login).Contains(login);
+            return cdb.db.Users.Select(item => item.Login).Contains(login);
         }
         // Валидация электронной почты
         public static bool IsValidEmail(string email)
@@ -54,7 +54,7 @@ namespace MyTests
         // Проверка на уникальность электронной почты
         public static bool IsEmailAlreadyTaken(string Email)
         {
-            return cnt.db.Users.Select(item => item.Email).Contains(Email);
+            return cdb.db.Users.Select(item => item.Email).Contains(Email);
         }
         public static string EncryptPassword(string password)
         {

+ 8 - 1
MyTests/MyTests.csproj

@@ -112,6 +112,9 @@
     <Compile Include="Pages\TestsCatalog.xaml.cs">
       <DependentUpon>TestsCatalog.xaml</DependentUpon>
     </Compile>
+    <Compile Include="QuestionAddToTestWindow.xaml.cs">
+      <DependentUpon>QuestionAddToTestWindow.xaml</DependentUpon>
+    </Compile>
     <Compile Include="Questions.cs">
       <DependentUpon>EDM.tt</DependentUpon>
     </Compile>
@@ -139,7 +142,7 @@
       <DependentUpon>App.xaml</DependentUpon>
       <SubType>Code</SubType>
     </Compile>
-    <Compile Include="cnt.cs" />
+    <Compile Include="cdb.cs" />
     <Compile Include="ConfirmationWindow.xaml.cs">
       <DependentUpon>ConfirmationWindow.xaml</DependentUpon>
     </Compile>
@@ -192,6 +195,10 @@
       <SubType>Designer</SubType>
       <Generator>MSBuild:Compile</Generator>
     </Page>
+    <Page Include="QuestionAddToTestWindow.xaml">
+      <SubType>Designer</SubType>
+      <Generator>MSBuild:Compile</Generator>
+    </Page>
     <Page Include="Styles\Style.xaml">
       <SubType>Designer</SubType>
       <Generator>MSBuild:Compile</Generator>

+ 1 - 1
MyTests/Pages/CheckTestResults.xaml.cs

@@ -36,7 +36,7 @@ namespace MyTests.Pages
 
             int counter = 1;
 
-            foreach (Answers answer in cnt.db.Answers.Where(item => item.Questions.IdTest == _test.IdTest &&
+            foreach (Answers answer in cdb.db.Answers.Where(item => item.Questions.IdTest == _test.IdTest &&
                                                             item.IdUser == Session.User.IdUser).ToList())
             {
                 AnswerClass ac = new AnswerClass();

+ 7 - 19
MyTests/Pages/CheckTestResultsCatalog.xaml.cs

@@ -1,23 +1,11 @@
-using System;
-using System.Collections.Generic;
+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 MyTests.Pages
 {
-    /// <summary>
-    /// Логика взаимодействия для CheckTestResultsCatalog.xaml
-    /// </summary>
     public partial class CheckTestResultsCatalog : Page
     {
         Tests test;
@@ -29,14 +17,14 @@ namespace MyTests.Pages
 
             List<AnswerClass> answerList = new List<AnswerClass>();
 
-            foreach (Users user in cnt.db.Users.Where(item => item.Answers.Count() > 0))
+            foreach (Users user in cdb.db.Users.Where(item => item.Answers.Count() > 0))
             {
-                if (cnt.db.Answers.Select(item => item.Questions.IdTest + " " + item.IdUser).Contains(_test.IdTest + " " + user.IdUser))
+                if (cdb.db.Answers.Select(item => item.Questions.IdTest + " " + item.IdUser).Contains(_test.IdTest + " " + user.IdUser))
                 {
                     AnswerClass newUserAnswer = new AnswerClass();
                     newUserAnswer.User = user;
                     newUserAnswer.Correct = CorrectAnswersCounter(_test, user);
-                    newUserAnswer.Count = cnt.db.Questions.Where(item => item.IdTest == _test.IdTest).Count();
+                    newUserAnswer.Count = cdb.db.Questions.Where(item => item.IdTest == _test.IdTest).Count();
 
                     answerList.Add(newUserAnswer);
                 }
@@ -49,8 +37,8 @@ namespace MyTests.Pages
         }
         public int CorrectAnswersCounter(Tests test, Users user)
         {
-            Quest.Answer = cnt.db.Questions.Where(item => item.IdTest == test.IdTest).Select(it => it.Answer).ToArray();
-            Quest.UserAnswer = cnt.db.Answers.Where(item => item.Users.IdUser == user.IdUser && item.Questions.IdTest == test.IdTest).Select(it => it.Answer).ToArray();
+            Quest.Answer = cdb.db.Questions.Where(item => item.IdTest == test.IdTest).Select(it => it.Answer).ToArray();
+            Quest.UserAnswer = cdb.db.Answers.Where(item => item.Users.IdUser == user.IdUser && item.Questions.IdTest == test.IdTest).Select(it => it.Answer).ToArray();
             int value = 0;
             if (Quest.Answer.Length == Quest.UserAnswer.Length)
                 for (int i = 0; i < Quest.Answer.Length; i++)
@@ -64,7 +52,7 @@ namespace MyTests.Pages
             if (((AnswerClass)AnswersListBox.SelectedItem) != null)
             {
                 NavigationService.Navigate(new Pages.CheckTestResults(test,
-                    cnt.db.Users.Where(item => item.IdUser == ((AnswerClass)AnswersListBox.SelectedItem).User.IdUser).FirstOrDefault()));
+                    cdb.db.Users.Where(item => item.IdUser == ((AnswerClass)AnswersListBox.SelectedItem).User.IdUser).FirstOrDefault()));
             }
         }
 

+ 7 - 16
MyTests/Pages/CurTestPage.xaml.cs

@@ -1,17 +1,8 @@
 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 MyTests.Pages
 {
@@ -29,23 +20,23 @@ namespace MyTests.Pages
             {
                 string strContent = Session.Quest.Content[Session.CurQuestion];
                 string strAnswer = Session.Quest.Answer[Session.CurQuestion];
-                if (cnt.db.Answers.Select(item => item.IdQuestion + " " + item.IdUser).Contains(cnt.db.Questions.Where(item => item.Content == strContent && item.Answer == strAnswer).Select(item => item.IdQuestion).FirstOrDefault() + " " + Session.User.IdUser))
+                if (cdb.db.Answers.Select(item => item.IdQuestion + " " + item.IdUser).Contains(cdb.db.Questions.Where(item => item.Content == strContent && item.Answer == strAnswer).Select(item => item.IdQuestion).FirstOrDefault() + " " + Session.User.IdUser))
                 {
-                    Answers answer = cnt.db.Answers.Where(item => item.IdQuestion == cnt.db.Questions.Where(i => i.Content == strContent && i.Answer == strAnswer).Select(i => i.IdQuestion).FirstOrDefault() && item.IdUser == Session.User.IdUser).FirstOrDefault();
+                    Answers answer = cdb.db.Answers.Where(item => item.IdQuestion == cdb.db.Questions.Where(i => i.Content == strContent && i.Answer == strAnswer).Select(i => i.IdQuestion).FirstOrDefault() && item.IdUser == Session.User.IdUser).FirstOrDefault();
                     answer.Answer = AnswerBox.Text;
-                    cnt.db.SaveChanges();
+                    cdb.db.SaveChanges();
                 }
                 else
                 {
                     Answers newAnswer = new Answers()
                     {
-                        IdUserAnswer = cnt.db.Answers.Select(p => p.IdUserAnswer).DefaultIfEmpty(0).Max() + 1,
-                        IdQuestion = cnt.db.Questions.Where(item => item.Content == strContent && item.Answer == strAnswer).Select(item => item.IdQuestion).FirstOrDefault(),
+                        IdUserAnswer = cdb.db.Answers.Select(p => p.IdUserAnswer).DefaultIfEmpty(0).Max() + 1,
+                        IdQuestion = cdb.db.Questions.Where(item => item.Content == strContent && item.Answer == strAnswer).Select(item => item.IdQuestion).FirstOrDefault(),
                         IdUser = Session.User.IdUser,
                         Answer = AnswerBox.Text
                     };
-                    cnt.db.Answers.Add(newAnswer);
-                    cnt.db.SaveChanges();
+                    cdb.db.Answers.Add(newAnswer);
+                    cdb.db.SaveChanges();
                 }
             }
             catch (Exception ex)

+ 1 - 1
MyTests/Pages/EditTestPage.xaml

@@ -35,7 +35,7 @@
                    Opacity="0.5">
             </Label>
         </StackPanel>
-        <ScrollViewer Grid.Row="1" Grid.RowSpan="2">
+        <ScrollViewer Grid.Row="1">
             <StackPanel>
                 <StackPanel Orientation="Horizontal">
                     <Label Content="Тест виден другим пользователям:"

+ 17 - 19
MyTests/Pages/EditTestPage.xaml.cs

@@ -1,17 +1,10 @@
 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 MyTests.Pages
 {
@@ -26,19 +19,19 @@ namespace MyTests.Pages
             {
                 try
                 {
-                    int testId = cnt.db.Tests.Select(p => p.IdTest).DefaultIfEmpty(0).Max() + 1;
+                    int testId = cdb.db.Tests.Select(p => p.IdTest).DefaultIfEmpty(0).Max() + 1;
                     Tests newTest = new Tests()
                     {
                         IdTest = testId,
                         IdUser = Session.User.IdUser,
-                        Name = $"Новый тест {cnt.db.Tests.Where(item => item.IdUser == Session.User.IdUser).Count() + 1}",
+                        Name = $"Новый тест {cdb.db.Tests.Where(item => item.IdUser == Session.User.IdUser).Count() + 1}",
                         IsAnswersVisible = false,
                         IsVisible = false,
                         CanAgain = false
                     };
-                    cnt.db.Tests.Add(newTest);
-                    cnt.db.SaveChanges();
-                    test = cnt.db.Tests.Where(item => item.IdTest == testId).FirstOrDefault();
+                    cdb.db.Tests.Add(newTest);
+                    cdb.db.SaveChanges();
+                    test = cdb.db.Tests.Where(item => item.IdTest == testId).FirstOrDefault();
                 }
                 catch (Exception ex)
                 {
@@ -55,14 +48,16 @@ namespace MyTests.Pages
 
 
             TestNameBox.Text = test.Name;
-            TestImg.Source = test.Image == null ? new BitmapImage(new Uri("../Resources/Approval.png", UriKind.RelativeOrAbsolute)) : ImagesFunctions.NewImage(_test);
+            TestImg.Source = test.Image == null ? 
+                new BitmapImage(new Uri("../Resources/Approval.png", UriKind.RelativeOrAbsolute)) :
+                ImagesFunctions.NewImage(_test);
 
             QuestionsListBox.Items.Clear();
             QuestionsUpdate();
         }
         private void QuestionsUpdate()
         {
-            QuestionsListBox.ItemsSource = cnt.db.Questions.Where(item => item.IdTest == test.IdTest).ToList();
+            QuestionsListBox.ItemsSource = cdb.db.Questions.Where(item => item.IdTest == test.IdTest).ToList();
         }
 
         private void QuestionsListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
@@ -72,7 +67,8 @@ namespace MyTests.Pages
 
         private void AddQuestionButton_Click(object sender, RoutedEventArgs e)
         {
-            //addQuestion here
+            new QuestionAddToTestWindow(test).ShowDialog();
+            QuestionsUpdate();
         }
         private void DeleteQuestionButton_Click(object sender, RoutedEventArgs e)
         {
@@ -84,8 +80,10 @@ namespace MyTests.Pages
                 {
                     try
                     {
-                        cnt.db.Questions.Remove(selected);
-                        cnt.db.SaveChanges();
+                        foreach (Answers answer in cdb.db.Answers.Where(item => item.IdQuestion == selected.IdQuestion))
+                            cdb.db.Answers.Remove(answer);
+                        cdb.db.Questions.Remove(selected);
+                        cdb.db.SaveChanges();
                     }
                     catch (Exception ex)
                     {
@@ -107,7 +105,7 @@ namespace MyTests.Pages
             {
                 TestImg.Source = image;
                 test.Image = ImagesFunctions.BitmapSourceToByteArray((BitmapSource)TestImg.Source);
-                cnt.db.SaveChanges();
+                cdb.db.SaveChanges();
             }
         }
 
@@ -121,7 +119,7 @@ namespace MyTests.Pages
             test.IsVisible = IsVisibleCB.IsChecked == true;
             test.IsAnswersVisible = IsAnswersVisibleCB.IsChecked == true;
             test.CanAgain = CanAgainCB.IsChecked == true;
-            cnt.db.SaveChanges();
+            cdb.db.SaveChanges();
         }
     }
 }

+ 13 - 23
MyTests/Pages/LoginPage.xaml.cs

@@ -1,5 +1,4 @@
-using System;
-using System.Linq;
+using System.Linq;
 using System.Windows;
 using System.Windows.Controls;
 using System.Windows.Navigation;
@@ -7,7 +6,6 @@ namespace MyTests.Pages
 {
     public partial class LoginPage : Page
     {
-        bool Test = true;
         public LoginPage()
         {
             InitializeComponent();
@@ -19,30 +17,22 @@ namespace MyTests.Pages
 
         private void LogButton_Click(object sender, RoutedEventArgs e)
         {
-            if (Test)
+            try
             {
-                Session.User = cnt.db.Users.Where(item => item.IdUser == 1).FirstOrDefault();
-                NavigationService.Navigate(new Pages.MainPage());
-            }
-            else
-            {
-                try
-                {
-                    if (!Functions.IsValidLogAndPass(LogBox.Text, PassBox.Password))
-                        new ErrorWindow("Поля не могут быть пустыми").Show();
-                    else if (!Functions.LoginCheck(LogBox.Text, PassBox.Password))
-                        new ErrorWindow("Неверный логин или пароль").Show();
-                    else
-                    {
-                        //Profile.userId = cnt.db.User.Where(item => item.NickName == LogBox.Text).Select(item => item.Id).FirstOrDefault();
-                        NavigationService.Navigate(new Pages.MainPage());
-                    }
-                }
-                catch
+                if (!Functions.IsValidLogAndPass(LogBox.Text, PassBox.Password))
+                    new ErrorWindow("Поля не могут быть пустыми").Show();
+                else if (!Functions.LoginCheck(LogBox.Text, PassBox.Password))
+                    new ErrorWindow("Неверный логин или пароль").Show();
+                else
                 {
-                    new ErrorWindow("Ошибка входа").ShowDialog();
+                    Session.User = cdb.db.Users.Where(item => item.Login == LogBox.Text).FirstOrDefault();
+                    NavigationService.Navigate(new Pages.MainPage());
                 }
             }
+            catch
+            {
+                new ErrorWindow("Ошибка входа").ShowDialog();
+            }
         }
     }
 }

+ 18 - 25
MyTests/Pages/ProfilePage.xaml

@@ -25,20 +25,11 @@
             </Grid.ColumnDefinitions>
 
             <Grid Grid.Column="0">
-                <Grid.RowDefinitions>
-                    <RowDefinition Height="31"/>
-                    <RowDefinition/>
-                </Grid.RowDefinitions>
-                <Label Name="UserName"
-                       FontSize="16"
-                       Content="Имя"
-                       HorizontalAlignment="Center">
-                </Label>
                 <Image Name="ProfileImage"
                        MinHeight="100"
                        MinWidth="100"
                        Grid.Row="1"
-                       Margin="10,0,10,10"
+                       Margin="10"
                    Source="/MyTests;component/Resources/StandartImage.png"
                    MouseDown="EditImage_Click">
                 </Image>
@@ -49,40 +40,42 @@
                   Grid.Column="1"
                   Margin="10"
                   Background="{StaticResource color3}">
-                <Grid.RowDefinitions>
-                    <RowDefinition Height="49"/>
-                    <RowDefinition/>
-                </Grid.RowDefinitions>
-                <StackPanel Grid.Row="0"
-                            Orientation="Horizontal">
-                    <Label Content="Email: "
+                <StackPanel Grid.Row="0">
+                    <Label Name="FIOLabel"
+                           Content="FIO"
+                           FontSize="22"
+                           FontWeight="Bold">
+                    </Label>
+                    <StackPanel Orientation="Horizontal">
+                        <Label Content="Email: "
                              Background="{x:Null}"
                              BorderBrush="{x:Null}"
                              FontSize="22"/>
-                    <TextBox Name="EmailBox"
+                        <TextBox Name="EmailBox"
                          Text=" "
                          FontSize="22"
                          Background="{x:Null}"
                          BorderBrush="{x:Null}"
                          Width="{Binding Path=ActualWidth, ElementName=UserInfoGrid}"
                               >
-                    </TextBox>
-                </StackPanel>
+                        </TextBox>
+                    </StackPanel>
 
-                <StackPanel Grid.Row="1"
+                    <StackPanel Grid.Row="1"
                             Orientation="Horizontal">
-                    <Label Content="Инфо: "
+                        <Label Content="Инфо: "
                          FontSize="22"
                          Background="{x:Null}"
                          BorderBrush="{x:Null}">
-                    </Label>
-                    <TextBox Name="InfoBox"
+                        </Label>
+                        <TextBox Name="InfoBox"
                          Text=""
                          FontSize="22"
                          Background="{x:Null}"
                          BorderBrush="{x:Null}"
                              Width="{Binding Path=ActualWidth, ElementName=UserInfoGrid}">
-                    </TextBox>
+                        </TextBox>
+                    </StackPanel>
                 </StackPanel>
             </Grid>
         </Grid>

+ 15 - 16
MyTests/Pages/ProfilePage.xaml.cs

@@ -15,7 +15,7 @@ namespace MyTests.Pages
             InitializeComponent();
             TestsListBox.Items.Clear();
             user = _user;
-            UserName.Content = user.Login;
+            FIOLabel.Content = user.Surname + " " + user.Name + " " + user.Patronymic; 
             ProfileImage.Source = user.Image == null ?
                 new BitmapImage(new Uri("../Resources/StandartImage.png", UriKind.RelativeOrAbsolute)) :
                 ProfileImage.Source = ImagesFunctions.NewImage(user);
@@ -41,32 +41,31 @@ namespace MyTests.Pages
                 {
                     ProfileImage.Source = image;
                     Session.User.Image = ImagesFunctions.BitmapSourceToByteArray((BitmapSource)ProfileImage.Source);
-                    cnt.db.SaveChanges();
+                    cdb.db.SaveChanges();
                 }
             }
         }
         private void TestsLoading()
         {
             if (user != Session.User)
-                TestsListBox.ItemsSource = cnt.db.Tests.Where(item => item.IdUser == user.IdUser && item.IsVisible == true).ToList();
+                TestsListBox.ItemsSource = cdb.db.Tests.Where(item => item.IdUser == user.IdUser && item.IsVisible == true).ToList();
             else
-                TestsListBox.ItemsSource = cnt.db.Tests.Where(item => item.IdUser == user.IdUser).ToList();
+                TestsListBox.ItemsSource = cdb.db.Tests.Where(item => item.IdUser == user.IdUser).ToList();
         }
 
         private void SaveButton_Click(object sender, RoutedEventArgs e)
         {
             if (!Functions.IsValidEmail(EmailBox.Text))
                 new ErrorWindow("Email введен неверно.").Show();
-            else if (Functions.IsEmailAlreadyTaken(EmailBox.Text))
+            else if (Functions.IsEmailAlreadyTaken(EmailBox.Text) && EmailBox.Text != user.Email)
                 new ErrorWindow("Данный email уже используется.").Show();
             else
             {
                 Session.User.Email = EmailBox.Text;
                 Session.User.Info = InfoBox.Text;
-                cnt.db.SaveChanges();
+                cdb.db.SaveChanges();
                 new ErrorWindow("Успешно.").ShowDialog();
             }
-
         }
 
         private void CheckResultsButton_Click(object sender, RoutedEventArgs e)
@@ -88,11 +87,11 @@ namespace MyTests.Pages
             {
                 if (((Tests)TestsListBox.SelectedItem) != null)
                 {
-                    Session.OpenedTest = cnt.db.Tests.Where(item => item.IdTest == ((Tests)TestsListBox.SelectedItem).IdTest).FirstOrDefault();
+                    Session.OpenedTest = cdb.db.Tests.Where(item => item.IdTest == ((Tests)TestsListBox.SelectedItem).IdTest).FirstOrDefault();
                     Session.Points = 0;
                     Session.CurQuestion = 0;
-                    Session.Quest.Content = cnt.db.Questions.Where(item => item.IdTest == Session.OpenedTest.IdTest).Select(item => item.Content).ToArray();
-                    Session.Quest.Answer = cnt.db.Questions.Where(item => item.IdTest == Session.OpenedTest.IdTest).Select(item => item.Answer).ToArray();
+                    Session.Quest.Content = cdb.db.Questions.Where(item => item.IdTest == Session.OpenedTest.IdTest).Select(item => item.Content).ToArray();
+                    Session.Quest.Answer = cdb.db.Questions.Where(item => item.IdTest == Session.OpenedTest.IdTest).Select(item => item.Answer).ToArray();
 
                     NavigationService.Navigate(new Pages.CurTestPage());
                 }
@@ -112,12 +111,12 @@ namespace MyTests.Pages
                 confWindow.ShowDialog();
                 if (confWindow.answer)
                 {
-                    foreach (Answers answer in cnt.db.Answers.Where(item => item.Questions.IdTest == ((Tests)btn.DataContext).IdTest))
-                        cnt.db.Answers.Remove(answer);
-                    foreach (Questions question in cnt.db.Questions.Where(item => item.IdTest == ((Tests)btn.DataContext).IdTest))
-                        cnt.db.Questions.Remove(question);
-                    cnt.db.Tests.Remove((Tests)btn.DataContext);
-                    cnt.db.SaveChanges();
+                    foreach (Answers answer in cdb.db.Answers.Where(item => item.Questions.IdTest == ((Tests)btn.DataContext).IdTest))
+                        cdb.db.Answers.Remove(answer);
+                    foreach (Questions question in cdb.db.Questions.Where(item => item.IdTest == ((Tests)btn.DataContext).IdTest))
+                        cdb.db.Questions.Remove(question);
+                    cdb.db.Tests.Remove((Tests)btn.DataContext);
+                    cdb.db.SaveChanges();
                     TestsLoading();
                 }
             }

+ 25 - 1
MyTests/Pages/RegistrationPage.xaml

@@ -15,7 +15,7 @@
         </Grid.ColumnDefinitions>
         <Grid.RowDefinitions>
             <RowDefinition/>
-            <RowDefinition Height="2.75*"/>
+            <RowDefinition Height="20*"/>
             <RowDefinition/>
         </Grid.RowDefinitions>
         <Border Grid.Row="1" 
@@ -28,6 +28,30 @@
                         Margin="10"
                         VerticalAlignment="Center"
                         HorizontalAlignment="Center">
+                <Label Content="Фамилия Имя Отчество:" 
+                       Foreground="{StaticResource TextColor}"
+                       Height="40" 
+                       Width="240"
+                       FontSize="20"/>
+                <TextBox Name="FIOBox" 
+                             Foreground="{StaticResource TextColor}"
+                             TextWrapping="Wrap" 
+                             VerticalAlignment="Top" 
+                             Height="40" 
+                             Width="240"
+                             FontSize="20"/>
+                <Label Content="Email:" 
+                       Foreground="{StaticResource TextColor}"
+                       Height="40" 
+                       Width="240"
+                       FontSize="20"/>
+                <TextBox Name="EmailBox" 
+                             Foreground="{StaticResource TextColor}"
+                             TextWrapping="Wrap" 
+                             VerticalAlignment="Top" 
+                             Height="40" 
+                             Width="240"
+                             FontSize="20"/>
                 <Label Content="Логин:" 
                        Foreground="{StaticResource TextColor}"
                        Height="40" 

+ 39 - 4
MyTests/Pages/RegistrationPage.xaml.cs

@@ -1,13 +1,11 @@
 using System;
+using System.Linq;
 using System.Windows;
 using System.Windows.Controls;
 using System.Windows.Navigation;
 
 namespace MyTests.Pages
 {
-    /// <summary>
-    /// Логика взаимодействия для RegistrationPage.xaml
-    /// </summary>
     public partial class RegistrationPage : Page
     {
         public RegistrationPage()
@@ -16,7 +14,44 @@ namespace MyTests.Pages
         }
         private void RegButton_Click(object sender, RoutedEventArgs e)
         {
-            //Регистрая тут
+            try
+            {
+                if (!Functions.IsValidEmail(EmailBox.Text))
+                    new ErrorWindow("Email введен неверно.").Show();
+                else if (Functions.IsEmailAlreadyTaken(EmailBox.Text))
+                    new ErrorWindow("Данный email уже используется.").Show();
+                else if (!Functions.IsValidLength(LogBox.Text.Trim()))
+                    new ErrorWindow("Поле «Логин» должно содержать не менее 5 символов.").Show();
+                else if (!Functions.IsValidLength(PassBox.Password.Trim()))
+                    new ErrorWindow("Поле «Пароль» должно содержать не менее 5 символов.").Show();
+                else if (!Functions.IsLogEqualPass(LogBox.Text, PassBox.Password))
+                    new ErrorWindow(" Поля «Логин» и «Пароль» не должны быть равны").Show();
+                else if (Functions.IsLoginAlreadyTaken(LogBox.Text))
+                    new ErrorWindow("Данный логин уже занят").Show();
+                else
+                {
+                    string[] fio = new string[3];
+                    fio = FIOBox.Text.Split(' ');
+                    Users newUser = new Users()
+                    {
+                        IdUser = cdb.db.Users.Select(p => p.IdUser).DefaultIfEmpty(0).Max() + 1,
+                        Login = LogBox.Text,
+                        Password = Functions.EncryptPassword(PassBox.Password),
+                        Email = EmailBox.Text,
+                        Post = "Пользователь",
+                        Surname = fio[0],
+                        Name = fio[1],
+                        Patronymic = fio[2]
+                    };
+                    cdb.db.Users.Add(newUser);
+                    cdb.db.SaveChanges(); ;
+                    new ErrorWindow("Успешная регистрация").ShowDialog();
+                }
+            }
+            catch
+            {
+                new ErrorWindow("Ошибка.").ShowDialog();
+            }
             NavigationService.Navigate(new Pages.LoginPage());
         }
 

+ 1 - 1
MyTests/Pages/ResultTestPage.xaml.cs

@@ -26,7 +26,7 @@ namespace MyTests.Pages
         }
         private void ProfileButton_Click(object sender, RoutedEventArgs e)
         {
-            NavigationService.Navigate(new Pages.ProfilePage(cnt.db.Users.Where(item => item.IdUser == Session.OpenedTest.IdUser).FirstOrDefault()));
+            NavigationService.Navigate(new Pages.ProfilePage(cdb.db.Users.Where(item => item.IdUser == Session.OpenedTest.IdUser).FirstOrDefault()));
         }
     }
 }

+ 20 - 18
MyTests/Pages/TestsCatalog.xaml.cs

@@ -1,17 +1,10 @@
 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 MyTests.Pages
 {
@@ -32,11 +25,14 @@ namespace MyTests.Pages
         }
         void LoadingTests()
         {
-            List<Tests> list = cnt.db.Tests.Where(item => item.IsVisible == true && item.Questions.Count > 0).ToList();
+            List<Tests> list = cdb.db.Tests.Where(item => item.IsVisible == true && item.Questions.Count > 0).ToList();
             if (TestNameBox.Text != "Название теста")
                 list = list.Where(item => item.Name.StartsWith(TestNameBox.Text)).ToList();
+
             if (AuthorTestBox.Text != "Преподаватель")
-                list = list.Where(item => item.Users.Login.StartsWith(AuthorTestBox.Text)).ToList();
+                list = list.Where(item => item.Users.Surname.StartsWith(AuthorTestBox.Text) 
+                || item.Users.Name.StartsWith(AuthorTestBox.Text) 
+                || item.Users.Patronymic.StartsWith(AuthorTestBox.Text)).ToList();
             TestsListBox.ItemsSource = list;
         }
 
@@ -47,7 +43,7 @@ namespace MyTests.Pages
 
         private void TestNameBox_PreviewMouseDown(object sender, MouseButtonEventArgs e)
         {
-            TestNameBox.Text = string.Empty;
+            ((TextBox)sender).Text = String.Empty;
         }
 
         private void TestNameBox_LostFocus(object sender, RoutedEventArgs e)
@@ -58,7 +54,7 @@ namespace MyTests.Pages
 
         private void AuthorTestBox_PreviewMouseDown(object sender, MouseButtonEventArgs e)
         {
-            AuthorTestBox.Text = string.Empty;
+            ((TextBox)sender).Text = String.Empty;
         }
 
         private void AuthorTestBox_LostFocus(object sender, RoutedEventArgs e)
@@ -73,13 +69,19 @@ namespace MyTests.Pages
             {
                 if (((Tests)TestsListBox.SelectedItem) != null)
                 {
-                    Session.OpenedTest = cnt.db.Tests.Where(item => item.IdTest == ((Tests)TestsListBox.SelectedItem).IdTest).FirstOrDefault();
-                    Session.Points = 0;
-                    Session.CurQuestion = 0;
-                    Session.Quest.Content = cnt.db.Questions.Where(item => item.IdTest == Session.OpenedTest.IdTest).Select(item => item.Content).ToArray();
-                    Session.Quest.Answer = cnt.db.Questions.Where(item => item.IdTest == Session.OpenedTest.IdTest).Select(item => item.Answer).ToArray();
-
-                    NavigationService.Navigate(new Pages.CurTestPage());
+                    Tests thisTest = cdb.db.Tests.Where(item => item.IdTest == ((Tests)TestsListBox.SelectedItem).IdTest).FirstOrDefault();
+
+                    if ((!thisTest.CanAgain && cdb.db.Answers.Where(item => item.Questions.Tests.IdTest == thisTest.IdTest).Select(item => item.IdUser).Contains(Session.User.IdUser)) && Session.User.IdUser != thisTest.IdUser) //true - может пройти снова
+                        new ErrorWindow("Этот тест не может быть пройден повторно.").ShowDialog();
+                    else
+                    {
+                        Session.OpenedTest = thisTest;
+                        Session.Points = 0;
+                        Session.CurQuestion = 0;
+                        Session.Quest.Content = cdb.db.Questions.Where(item => item.IdTest == Session.OpenedTest.IdTest).Select(item => item.Content).ToArray();
+                        Session.Quest.Answer = cdb.db.Questions.Where(item => item.IdTest == Session.OpenedTest.IdTest).Select(item => item.Answer).ToArray();
+                        NavigationService.Navigate(new Pages.CurTestPage());
+                    }   
                 }
             }
             catch

+ 60 - 0
MyTests/QuestionAddToTestWindow.xaml

@@ -0,0 +1,60 @@
+<Window x:Class="MyTests.QuestionAddToTestWindow"
+        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
+        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
+        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
+        xmlns:local="clr-namespace:MyTests"
+        mc:Ignorable="d"
+        Title="ConfirmationWindow" 
+        MinHeight="120" 
+        Height="120"
+        Width="360"
+        WindowStartupLocation="CenterOwner" 
+        WindowStyle="None" 
+        ResizeMode="NoResize">
+    <Border BorderBrush="Black"
+            BorderThickness="1"
+            MouseDown="Border_MouseDown">
+        <Grid Background="#FF2D2D2D">
+            <Grid.RowDefinitions>
+                <RowDefinition Height="27*"/>
+                <RowDefinition Height="13*"/>
+            </Grid.RowDefinitions>
+            <StackPanel Orientation="Horizontal"
+                        HorizontalAlignment="Center">
+                <TextBox x:Name="QuestionBox"
+                         Text="Вопрос"
+                         Width="150"
+                         Height="40"
+                         Margin="15,0,15,0"
+                         PreviewMouseDown="QuestionBox_PreviewMouseDown"
+                         LostFocus="QuestionBox_LostFocus">
+                </TextBox>
+                <TextBox Name="AnswerBox"
+                         Text="Ответ"
+                         Width="150"
+                         Height="40"
+                         Margin="15,0,15,0"
+                         PreviewMouseDown="AnswerBox_PreviewMouseDown"
+                         LostFocus="AnswerBox_LostFocus">
+                </TextBox>
+            </StackPanel>
+            <Grid Grid.Row="1">
+                <StackPanel Orientation="Horizontal"
+                        HorizontalAlignment="Center"
+                        VerticalAlignment="Center">
+                    <Button Content="Отмена" 
+                            Height="30" 
+                            Width="130" 
+                            Margin="0,0,5,0"
+                            Click="CloseButton_Click"/>
+                    <Button Content="Создать" 
+                            Height="30" 
+                            Width="130"
+                            Margin="5,0,0,0"
+                            Click="AddQuestionButton_Click"/>
+                </StackPanel>
+            </Grid>
+        </Grid>
+    </Border>
+</Window>

+ 77 - 0
MyTests/QuestionAddToTestWindow.xaml.cs

@@ -0,0 +1,77 @@
+using System;
+using System.Linq;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Input;
+
+namespace MyTests
+{
+    public partial class QuestionAddToTestWindow : Window
+    {
+        Tests test;
+        public QuestionAddToTestWindow(Tests _test)
+        {
+            InitializeComponent();
+            Owner = Application.Current.MainWindow;
+            test = _test;
+        }
+
+        private void CloseButton_Click(object sender, RoutedEventArgs e)
+        {
+            Close();
+        }
+        private void AddQuestionButton_Click(object sender, RoutedEventArgs e)
+        {
+            if (QuestionBox.Text != "Вопрос" || AnswerBox.Text != "Ответ")
+            {
+                try
+                {
+                    Questions newQuestion = new Questions
+                    {
+                        IdQuestion = cdb.db.Questions.Select(p => p.IdQuestion).DefaultIfEmpty(0).Max() + 1,
+                        IdTest = test.IdTest,
+                        Content = QuestionBox.Text,
+                        Answer = AnswerBox.Text
+                    };
+                    cdb.db.Questions.Add(newQuestion);
+                    cdb.db.SaveChanges();
+                    Close();
+                }
+                catch (Exception ex)
+                {
+                    new ErrorWindow(ex.Message).ShowDialog();
+                }
+            }
+            else
+                new ErrorWindow("Измените содержимое вопрос или ответа для сохранения.").ShowDialog();
+            
+        }
+
+        private void QuestionBox_PreviewMouseDown(object sender, MouseButtonEventArgs e)
+        {
+            ((TextBox)sender).Text = String.Empty;
+        }
+
+        private void QuestionBox_LostFocus(object sender, RoutedEventArgs e)
+        {
+            if (QuestionBox.Text.Trim() == "")
+                QuestionBox.Text = "Вопрос";
+        }
+
+        private void AnswerBox_PreviewMouseDown(object sender, MouseButtonEventArgs e)
+        {
+            ((TextBox)sender).Text = String.Empty;
+        }
+
+        private void AnswerBox_LostFocus(object sender, RoutedEventArgs e)
+        {
+            if (AnswerBox.Text.Trim() == "")
+                AnswerBox.Text = "Ответ";
+        }
+        private void Border_MouseDown(object sender, MouseButtonEventArgs e)
+        {
+            if (e.LeftButton == MouseButtonState.Pressed)
+                DragMove();
+        }
+    }
+}

+ 1 - 1
MyTests/cnt.cs

@@ -1,6 +1,6 @@
 namespace MyTests
 {
-    public class cnt
+    public class cdb
     {
         public static MyTestsDataBaseEntities db = new MyTestsDataBaseEntities();
     }

+ 20 - 0
UnitTestProject/App.config

@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="utf-8"?>
+<configuration>
+  <configSections>
+    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
+    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
+  </configSections>
+  <entityFramework>
+    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
+      <parameters>
+        <parameter value="mssqllocaldb" />
+      </parameters>
+    </defaultConnectionFactory>
+    <providers>
+      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
+    </providers>
+  </entityFramework>
+	<connectionStrings>
+		<add name="MyTestsDataBaseEntities" connectionString="metadata=res://*/EDM.csdl|res://*/EDM.ssdl|res://*/EDM.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=(localdb)\MSSQLLocalDB;initial catalog=MyTestsDataBase;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />
+	</connectionStrings>
+</configuration>

+ 6 - 11
UnitTestProject/UnitTest1.cs

@@ -1,5 +1,4 @@
 using Microsoft.VisualStudio.TestTools.UnitTesting;
-using System;
 using MyTests;
 namespace UnitTestProject
 {
@@ -9,7 +8,6 @@ namespace UnitTestProject
         [TestMethod]
         public void IsValidEmail()
         {
-            Assert.IsTrue(Functions.IsValidEmail("Matrix@gmail.com"));
             Assert.IsTrue(Functions.IsValidEmail("Imagine@mail.ru"));
             Assert.IsFalse(Functions.IsValidEmail("usermail.com"));
             Assert.IsFalse(Functions.IsValidEmail("usermailcom"));
@@ -25,15 +23,14 @@ namespace UnitTestProject
         [TestMethod]
         public void LoginTest()
         {
-            string login = "Matrix";
+            string login = "asdfkwet";
             string password = "meme3";
             Assert.IsTrue(Functions.LoginCheck(login, password));
         }
         [TestMethod]
         public void IsValidLoginAndPassword()
         {
-            Assert.IsTrue(Functions.IsValidLogAndPass("Matrix", "meme3"));
-            Assert.IsTrue(Functions.IsValidLogAndPass("Imagine", "pizza"));
+            Assert.IsTrue(Functions.IsValidLogAndPass("asdfkwet", "mEme3"));
             Assert.IsTrue(Functions.IsValidLogAndPass("Login???", "p@ssw0rd"));
             Assert.IsFalse(Functions.IsValidLogAndPass("", ""));
             Assert.IsFalse(Functions.IsValidLogAndPass("", "SimplePass"));
@@ -42,7 +39,6 @@ namespace UnitTestProject
         [TestMethod]
         public void IsLoginAlreadyTaken()
         {
-            Assert.IsTrue(Functions.IsLoginAlreadyTaken("Matrix"));
             Assert.IsTrue(Functions.IsLoginAlreadyTaken("Imagine"));
             Assert.IsFalse(Functions.IsLoginAlreadyTaken("SimpleLogin"));
             Assert.IsFalse(Functions.IsLoginAlreadyTaken("Login?"));
@@ -51,7 +47,6 @@ namespace UnitTestProject
         [TestMethod]
         public void IsEmailAlreadyTaken()
         {
-            Assert.IsTrue(Functions.IsEmailAlreadyTaken("Matrix@gmail.com"));
             Assert.IsTrue(Functions.IsEmailAlreadyTaken("Imagine@gmail.com"));
             Assert.IsFalse(Functions.IsEmailAlreadyTaken("user3@mail.ru"));
             Assert.IsFalse(Functions.IsEmailAlreadyTaken("user42@gmail.com"));
@@ -60,14 +55,14 @@ namespace UnitTestProject
         [TestMethod]
         public void IsLogEqualPass()
         {
-            Assert.IsFalse(Functions.IsLogEqualPass("Matrix", "Matrix"));
-            Assert.IsTrue(Functions.IsLogEqualPass("Matrix", "meme3"));
+            Assert.IsFalse(Functions.IsLogEqualPass("asdfkwet", "asdfkwet"));
+            Assert.IsTrue(Functions.IsLogEqualPass("asdfkwet", "mEme3"));
         }
         [TestMethod]
         public void IsValidLength()
         {
-            Assert.IsTrue(Functions.IsValidLength("Matrix"));
-            Assert.IsTrue(Functions.IsValidLength("Matrwerwewe"));
+            Assert.IsTrue(Functions.IsValidLength("mwerogf20"));
+            Assert.IsTrue(Functions.IsValidLength("srwerwewe"));
             Assert.IsFalse(Functions.IsValidLength("Ma"));
             Assert.IsFalse(Functions.IsValidLength(""));
         }

+ 8 - 0
UnitTestProject/UnitTestProject.csproj

@@ -39,6 +39,12 @@
     <WarningLevel>4</WarningLevel>
   </PropertyGroup>
   <ItemGroup>
+    <Reference Include="EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
+      <HintPath>..\packages\EntityFramework.6.2.0\lib\net45\EntityFramework.dll</HintPath>
+    </Reference>
+    <Reference Include="EntityFramework.SqlServer, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
+      <HintPath>..\packages\EntityFramework.6.2.0\lib\net45\EntityFramework.SqlServer.dll</HintPath>
+    </Reference>
     <Reference Include="Microsoft.VisualStudio.TestPlatform.TestFramework, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
       <HintPath>..\packages\MSTest.TestFramework.2.1.2\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.dll</HintPath>
     </Reference>
@@ -46,6 +52,7 @@
       <HintPath>..\packages\MSTest.TestFramework.2.1.2\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll</HintPath>
     </Reference>
     <Reference Include="System" />
+    <Reference Include="System.ComponentModel.DataAnnotations" />
     <Reference Include="System.Core" />
   </ItemGroup>
   <ItemGroup>
@@ -53,6 +60,7 @@
     <Compile Include="Properties\AssemblyInfo.cs" />
   </ItemGroup>
   <ItemGroup>
+    <None Include="App.config" />
     <None Include="packages.config" />
   </ItemGroup>
   <ItemGroup>

+ 2 - 0
UnitTestProject/packages.config

@@ -1,5 +1,7 @@
 <?xml version="1.0" encoding="utf-8"?>
 <packages>
+  <package id="EntityFramework" version="6.2.0" targetFramework="net472" />
+  <package id="EntityFramework.ru" version="6.2.0" targetFramework="net472" />
   <package id="MSTest.TestAdapter" version="2.1.2" targetFramework="net472" />
   <package id="MSTest.TestFramework" version="2.1.2" targetFramework="net472" />
 </packages>