Imagara 2 lat temu
rodzic
commit
79afb1f29d

+ 50 - 6
MyTests/Pages/CheckTestResults.xaml

@@ -5,10 +5,54 @@
       xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
       xmlns:local="clr-namespace:MyTests.Pages"
       mc:Ignorable="d" 
-      d:DesignHeight="450" d:DesignWidth="800"
-      Title="CheckTestResults">
-
-    <Grid>
-        
+      d:DesignHeight="450" 
+      d:DesignWidth="676">
+    <Grid Background="{StaticResource color1}">
+        <Grid.RowDefinitions>
+            <RowDefinition Height="50"/>
+            <RowDefinition/>
+        </Grid.RowDefinitions>
+        <StackPanel Orientation="Horizontal"
+                    HorizontalAlignment="Left">
+            <Image Name="TestImg"
+                   Source="/MyTests;component/Resources/Approval.png"
+                   Margin="7">
+            </Image>
+            <Label Name="TestName"
+                   Content="Название теста"
+                   FontSize="25">
+            </Label>
+        </StackPanel>
+        <ListBox Name="TestsListBox"
+                 Background="{StaticResource color1}"
+                 BorderBrush="{Binding TestsListBox}" 
+                 Grid.Row="1">
+            <ScrollViewer VerticalScrollBarVisibility="Visible"/>
+            <ListBox.ItemTemplate>
+                <DataTemplate>
+                    <Border Width="{Binding Path=ActualWidth, ElementName=TestsListBox}"
+                            Height="50"
+                            CornerRadius="10"
+                            Background="{StaticResource color2}">
+                        <StackPanel Orientation="Horizontal">
+                            <Label MinWidth="30"
+                                   Content="{Binding RelativeSource={RelativeSource Mode=TemplatedParent},
+                                      Path=(ItemsControl.AlternationIndex)}"
+                                   VerticalContentAlignment="Center"
+                                   HorizontalContentAlignment="Center">
+                            </Label>
+                            <StackPanel>
+                                <Label Content="{Binding Questions.Content}"/>
+                                <TextBlock>
+                                <Run Text="Ответ: " Foreground="LightGray"/>
+                                <Run Text="{Binding Answer}" Foreground="White"/>
+                                </TextBlock>
+                            </StackPanel>
+                        </StackPanel>
+                        
+                    </Border>
+                </DataTemplate>
+            </ListBox.ItemTemplate>
+        </ListBox>
     </Grid>
-</Page>
+</Page>

+ 5 - 4
MyTests/Pages/CheckTestResults.xaml.cs

@@ -15,14 +15,15 @@ using System.Windows.Shapes;
 
 namespace MyTests.Pages
 {
-    /// <summary>
-    /// Логика взаимодействия для CheckTestResults.xaml
-    /// </summary>
     public partial class CheckTestResults : Page
     {
-        public CheckTestResults()
+        public CheckTestResults(Tests _test, Users _user)
         {
             InitializeComponent();
+            TestName.Content = _test.Name;
+            TestsListBox.Items.Clear();
+            TestsListBox.ItemsSource = cnt.db.Answers.Where(item => item.Questions.IdTest == _test.IdTest &&
+            item.IdUser == Session.User.IdUser).ToList();
         }
     }
 }

+ 22 - 7
MyTests/Pages/CheckTestResultsCatalog.xaml

@@ -10,17 +10,26 @@
 
     <Grid Background="{StaticResource color1}">
         <Grid.RowDefinitions>
+            <RowDefinition Height="30"/>
             <RowDefinition/>
             <RowDefinition Height="50"/>
         </Grid.RowDefinitions>
 
+        <Label Name="ResultLabel"
+               Content="Результаты:"
+               FontSize="16">
+            
+        </Label>
+        
         <ListBox Name="AnswersListBox"
                  Background="{StaticResource color1}"
-                 BorderBrush="{x:Null}">
+                 BorderBrush="{x:Null}" 
+                 Grid.Row="1"
+                 SelectionChanged="AnswersListBox_SelectionChanged">
             <ScrollViewer VerticalScrollBarVisibility="Visible"/>
             <ListBox.ItemTemplate>
                 <DataTemplate>
-                    <Border Width="{Binding Path=ActualWidth, ElementName=TestsListBox}"
+                    <Border Width="{Binding Path=ActualWidth, ElementName=AnswersListBox}"
                             Margin="-7,0,0,0"
                             Height="45"
                             CornerRadius="10"
@@ -34,18 +43,18 @@
                             </Image>
                             <StackPanel>
                                 <StackPanel Orientation="Horizontal">
-                                    <Label Content="{Binding surname}"/>
-                                    <Label Content="{Binding name}"/>
-                                    <Label Content="{Binding patronymic}"/>
+                                    <Label Content="{Binding User.Surname}"/>
+                                    <Label Content="{Binding User.Name}"/>
+                                    <Label Content="{Binding User.Patronymic}"/>
                                 </StackPanel>
                                 <TextBlock Margin="0,-7,0,0">
                                     <Run Text="Вопросов: " 
                                          Foreground="White"/>
-                                    <Run Text="{Binding correct}"
+                                    <Run Text="{Binding Correct}"
                                          Foreground="White"/>
                                     <Run Text="/" 
                                          Foreground="White"/>
-                                    <Run Text="{Binding count}"
+                                    <Run Text="{Binding Count}"
                                          Foreground="White"/>
                                 </TextBlock>
                             </StackPanel>
@@ -55,5 +64,11 @@
             </ListBox.ItemTemplate>
         </ListBox>
 
+        <Button Grid.Row="2"
+                Content="Назад"
+                Width="120"
+                Height="40"
+                FontSize="20" Margin="340,5">
+        </Button>
     </Grid>
 </Page>

+ 42 - 15
MyTests/Pages/CheckTestResultsCatalog.xaml.cs

@@ -20,36 +20,63 @@ namespace MyTests.Pages
     /// </summary>
     public partial class CheckTestResultsCatalog : Page
     {
+        Tests test;
         public CheckTestResultsCatalog(Tests _test)
         {
             InitializeComponent();
-
+            test = _test;
             AnswersListBox.Items.Clear();
 
             List<AnswerClass> answerList = new List<AnswerClass>();
 
-            foreach (Users user in cnt.db.Users)
+            foreach (Users user in cnt.db.Users.Where(item => item.Answers.Count() > 0))
             {
-                AnswerClass newUserAnswer = new AnswerClass();
-                newUserAnswer.surname = user.Surname;
-                newUserAnswer.name = user.Name;
-                newUserAnswer.patronymic = user.Patronymic;
-                newUserAnswer.correct = -1; //add count of correct answers
-                newUserAnswer.count = user.Tests.Where(item => item.Questions == _test.Questions).Count();
-
-                answerList.Add(newUserAnswer);
+                if(cnt.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();
+
+                    answerList.Add(newUserAnswer);
+                }
             }
 
             AnswersListBox.ItemsSource = answerList;
+            if (AnswersListBox.Items.Count == 0)
+                ResultLabel.Content = "На данный момент тест еще никто не прошел.";
+
+        }
+        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();
+            int value = 0;
+            for (int i = 0; i < Quest.Answer.Length; i++)
+                if (Quest.Answer[i] == Quest.UserAnswer[i])
+                    value++;
+            return value;
+        }
 
+        private void AnswersListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
+        {
+            if (((AnswerClass)AnswersListBox.SelectedItem) != null)
+            {
+                NavigationService.Navigate(new Pages.CheckTestResults(test, 
+                    cnt.db.Users.Where(item => item.IdUser == ((AnswerClass)AnswersListBox.SelectedItem).User.IdUser).FirstOrDefault()));
+            }
+        }
+
+        public static class Quest
+        {
+            public static string[] Answer;
+            public static string[] UserAnswer;
         }
         public class AnswerClass
         {
-            public string surname { get; set; }
-            public string name { get; set; }
-            public string patronymic { get; set; }
-            public int correct { get; set; }
-            public int count { get; set; }
+            public Users User { get; set; }
+            public int Correct { get; set; }
+            public int Count { get; set; }
         }
     }
 }

+ 0 - 20
MyTests/Pages/ProfilePage.xaml.cs

@@ -72,26 +72,6 @@ namespace MyTests.Pages
             }
 
         }
-        private void TestsListBox_Selectedd(object sender, RoutedEventArgs e)
-        {
-            try
-            {
-                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());
-                }
-            }
-            catch
-            {
-                new ErrorWindow("Ошибка открытия теста.").ShowDialog();
-            }
-        }
 
         private void CheckResultsButton_Click(object sender, RoutedEventArgs e)
         {

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

@@ -17,7 +17,7 @@ namespace MyTests.Pages
 
         private void AnswersButton_Click(object sender, RoutedEventArgs e)
         {
-            NavigationService.Navigate(new Pages.TestPage(Session.OpenedTest.IdTest));
+            NavigationService.Navigate(new Pages.CheckTestResults(Session.OpenedTest, Session.User));
         }
 
         private void ExitButton_Click(object sender, RoutedEventArgs e)

+ 1 - 1
MyTests/Pages/TestPage.xaml

@@ -6,7 +6,7 @@
       xmlns:local="clr-namespace:MyTests.Pages"
       mc:Ignorable="d" 
       d:DesignHeight="450" 
-      d:DesignWidth="800">
+      d:DesignWidth="676">
     <Grid Background="{StaticResource color1}">
         <Grid.RowDefinitions>
             <RowDefinition Height="50"/>

+ 13 - 5
MyTests/Pages/TestsCatalog.xaml

@@ -32,13 +32,21 @@
                     <TextBox Name="TestNameBox"
                              Margin="5"
                              Width="200"
-                             Text="Название теста">
+                             FontSize="16"
+                             VerticalContentAlignment="Center"
+                             Text="Название теста"
+                             PreviewMouseDown="TestNameBox_PreviewMouseDown"
+                             LostFocus="TestNameBox_LostFocus">
                     </TextBox>
 
                     <TextBox Name="AuthorTestBox"
                              Margin="5"
                              Width="200"
-                             Text="Автор">
+                             FontSize="16"
+                             VerticalContentAlignment="Center"
+                             Text="Преподаватель"
+                             PreviewMouseDown="AuthorTestBox_PreviewMouseDown"
+                             LostFocus="AuthorTestBox_LostFocus">
                     </TextBox>
                 </StackPanel>
                 <Button Height="45"
@@ -53,7 +61,8 @@
         <ListBox Name="TestsListBox"
                  Grid.Row="1"
                  Background="{StaticResource color1}"
-                 BorderBrush="{x:Null}">
+                 BorderBrush="{x:Null}"
+                 SelectionChanged="TestsListBox_SelectionChanged">
             <ScrollViewer VerticalScrollBarVisibility="Visible"/>
             <ListBox.ItemTemplate>
                 <DataTemplate>
@@ -61,8 +70,7 @@
                             Margin="-10,0,0,0"
                             Height="45"
                             CornerRadius="10"
-                            Background="{StaticResource color2}"
-                            MouseDown="TestsListBox_Selected">
+                            Background="{StaticResource color2}">
                         <StackPanel Orientation="Horizontal">
                             <Image Width="30"
                                Height="30"

+ 27 - 4
MyTests/Pages/TestsCatalog.xaml.cs

@@ -31,11 +31,11 @@ namespace MyTests.Pages
 
         }
         void LoadingTests()
-        {            
-            List<Tests> list = cnt.db.Tests.Where(item => item.IsVisible == true).ToList();
+        {
+            List<Tests> list = cnt.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 != "Автор")
+            if (AuthorTestBox.Text != "Преподаватель")
                 list = list.Where(item => item.Users.Login.StartsWith(AuthorTestBox.Text)).ToList();
             TestsListBox.ItemsSource = list;
         }
@@ -44,7 +44,30 @@ namespace MyTests.Pages
         {
             LoadingTests();
         }
-        private void TestsListBox_Selected(object sender, RoutedEventArgs e)
+
+        private void TestNameBox_PreviewMouseDown(object sender, MouseButtonEventArgs e)
+        {
+            TestNameBox.Text = string.Empty;
+        }
+
+        private void TestNameBox_LostFocus(object sender, RoutedEventArgs e)
+        {
+            if (TestNameBox.Text.Trim() == "")
+                TestNameBox.Text = "Название теста";
+        }
+
+        private void AuthorTestBox_PreviewMouseDown(object sender, MouseButtonEventArgs e)
+        {
+            AuthorTestBox.Text = string.Empty;
+        }
+
+        private void AuthorTestBox_LostFocus(object sender, RoutedEventArgs e)
+        {
+            if (AuthorTestBox.Text.Trim() == "")
+                AuthorTestBox.Text = "Преподаватель";
+        }
+
+        private void TestsListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
         {
             try
             {

+ 1 - 1
MyTests/Session.cs

@@ -7,7 +7,7 @@
         public static int Points = 0;
         public static int CurQuestion = 0;
         public static class Quest
-    {
+        {
             public static string[] Content;
             public static string[] Answer;
         }

+ 2 - 1
MyTests/Styles/Style.xaml

@@ -64,7 +64,8 @@
                     <Border Name="Border" 
                             CornerRadius="15"
                             Background="#33363C"
-                            BorderBrush="White" 
+                            BorderBrush="Black" 
+                            BorderThickness="1.5"
                             MouseEnter="MouseEnter" 
                             MouseLeave="MouseLeave">
                         <ContentPresenter HorizontalAlignment="Center"