Imagara 2 years ago
parent
commit
5f22e129fc

+ 11 - 2
MyTests/EDM.edmx

@@ -44,7 +44,10 @@
           <Property Name="Email" Type="nvarchar" MaxLength="50" Nullable="false" />
           <Property Name="Info" Type="nvarchar" MaxLength="50" />
           <Property Name="Image" Type="varbinary(max)" />
-          <Property Name="Post" Type="nvarchar" MaxLength="25" />
+          <Property Name="Post" Type="nvarchar" MaxLength="25" Nullable="false" />
+          <Property Name="Surname" Type="nvarchar" MaxLength="50" Nullable="false" />
+          <Property Name="Name" Type="nvarchar" MaxLength="50" Nullable="false" />
+          <Property Name="Patronymic" Type="nvarchar" MaxLength="50" Nullable="false" />
         </EntityType>
         <Association Name="FK_Answers_Questions">
           <End Role="Questions" Type="Self.Questions" Multiplicity="1" />
@@ -167,7 +170,10 @@
           <Property Name="Image" Type="Binary" MaxLength="Max" FixedLength="false" />
           <NavigationProperty Name="Answers" Relationship="Self.FK_Answers_Users" FromRole="Users" ToRole="Answers" />
           <NavigationProperty Name="Tests" Relationship="Self.FK_Tests_Users" FromRole="Users" ToRole="Tests" />
-          <Property Name="Post" Type="String" MaxLength="25" FixedLength="false" Unicode="true" />
+          <Property Name="Post" Type="String" MaxLength="25" FixedLength="false" Unicode="true" Nullable="false" />
+          <Property Name="Surname" Type="String" Nullable="false" MaxLength="50" FixedLength="false" Unicode="true" />
+          <Property Name="Name" Type="String" Nullable="false" MaxLength="50" FixedLength="false" Unicode="true" />
+          <Property Name="Patronymic" Type="String" Nullable="false" MaxLength="50" FixedLength="false" Unicode="true" />
         </EntityType>
         <Association Name="FK_Answers_Questions">
           <End Role="Questions" Type="Self.Questions" Multiplicity="1" />
@@ -280,6 +286,9 @@
           <EntitySetMapping Name="Users">
             <EntityTypeMapping TypeName="MyTestsDataBaseModel.Users">
               <MappingFragment StoreEntitySet="Users">
+                <ScalarProperty Name="Patronymic" ColumnName="Patronymic" />
+                <ScalarProperty Name="Name" ColumnName="Name" />
+                <ScalarProperty Name="Surname" ColumnName="Surname" />
                 <ScalarProperty Name="Post" ColumnName="Post" />
                 <ScalarProperty Name="IdUser" ColumnName="IdUser" />
                 <ScalarProperty Name="Login" ColumnName="Login" />

+ 2 - 2
MyTests/EDM.edmx.diagram

@@ -7,8 +7,8 @@
       <Diagram DiagramId="d43acb8abf174d81b935ee8c6a0e239d" Name="Diagram1">
         <EntityTypeShape EntityType="MyTestsDataBaseModel.Answers" Width="1.5" PointX="5.625" PointY="2.5" IsExpanded="true" />
         <EntityTypeShape EntityType="MyTestsDataBaseModel.Questions" Width="1.5" PointX="5.625" PointY="5.875" IsExpanded="true" />
-        <EntityTypeShape EntityType="MyTestsDataBaseModel.Tests" Width="1.5" PointX="2.875" PointY="5.5" IsExpanded="true" />
-        <EntityTypeShape EntityType="MyTestsDataBaseModel.Users" Width="1.5" PointX="2.625" PointY="2.125" IsExpanded="true" />
+        <EntityTypeShape EntityType="MyTestsDataBaseModel.Tests" Width="1.5" PointX="2.5" PointY="6" IsExpanded="true" />
+        <EntityTypeShape EntityType="MyTestsDataBaseModel.Users" Width="1.5" PointX="2.25" PointY="2.125" IsExpanded="true" />
         <AssociationConnector Association="MyTestsDataBaseModel.FK_Answers_Questions" ManuallyRouted="false" />
         <AssociationConnector Association="MyTestsDataBaseModel.FK_Answers_Users" ManuallyRouted="false" />
         <AssociationConnector Association="MyTestsDataBaseModel.FK_Questions_Tests" ManuallyRouted="false" />

+ 10 - 1
MyTests/Functions.cs

@@ -1,4 +1,6 @@
 using System.Linq;
+using System.Security.Cryptography;
+using System.Text;
 
 namespace MyTests
 {
@@ -7,7 +9,7 @@ namespace MyTests
         // Валидация логина и пароля при входе
         public static bool IsValidLogAndPass(string login, string password)
         {
-            if (login == "" || password == "")
+            if (login.Trim() == "" || password.Trim() == "")
                 return false;
             else
                 return true;
@@ -54,5 +56,12 @@ namespace MyTests
         {
             return cnt.db.Users.Select(item => item.Email).Contains(Email);
         }
+        public static string EncryptPassword(string password)
+        {
+            using (var hash = SHA1.Create())
+            {
+                return string.Concat(hash.ComputeHash(Encoding.UTF8.GetBytes(password)).Select(x => x.ToString("X2")));
+            }
+        }
     }
 }

+ 1 - 13
MyTests/MainWindow.xaml.cs

@@ -1,17 +1,5 @@
-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;
 using System.Windows.Input;
-using System.Windows.Media;
-using System.Windows.Media.Imaging;
-using System.Windows.Navigation;
-using System.Windows.Shapes;
 
 namespace MyTests
 {

+ 7 - 0
MyTests/MyTests.csproj

@@ -91,6 +91,9 @@
     <Compile Include="Pages\CurTestPage.xaml.cs">
       <DependentUpon>CurTestPage.xaml</DependentUpon>
     </Compile>
+    <Compile Include="Pages\EditTestPage.xaml.cs">
+      <DependentUpon>EditTestPage.xaml</DependentUpon>
+    </Compile>
     <Compile Include="Pages\MainPage.xaml.cs">
       <DependentUpon>MainPage.xaml</DependentUpon>
     </Compile>
@@ -164,6 +167,10 @@
       <SubType>Designer</SubType>
       <Generator>MSBuild:Compile</Generator>
     </Page>
+    <Page Include="Pages\EditTestPage.xaml">
+      <SubType>Designer</SubType>
+      <Generator>MSBuild:Compile</Generator>
+    </Page>
     <Page Include="Pages\MainPage.xaml">
       <SubType>Designer</SubType>
       <Generator>MSBuild:Compile</Generator>

+ 14 - 8
MyTests/Pages/CheckTestResultsCatalog.xaml

@@ -14,18 +14,17 @@
             <RowDefinition Height="50"/>
         </Grid.RowDefinitions>
 
-        <ListBox Name="TestsListBox"
+        <ListBox Name="AnswersListBox"
                  Background="{StaticResource color1}"
                  BorderBrush="{x:Null}">
             <ScrollViewer VerticalScrollBarVisibility="Visible"/>
             <ListBox.ItemTemplate>
                 <DataTemplate>
                     <Border Width="{Binding Path=ActualWidth, ElementName=TestsListBox}"
-                            Margin="-10,0,0,0"
+                            Margin="-7,0,0,0"
                             Height="45"
                             CornerRadius="10"
-                            Background="{StaticResource color2}"
-                            MouseDown="TestsListBox_Selected">
+                            Background="{StaticResource color2}">
                         <StackPanel Orientation="Horizontal">
                             <Image Width="30"
                                Height="30"
@@ -35,12 +34,19 @@
                             </Image>
                             <StackPanel>
                                 <StackPanel Orientation="Horizontal">
-                                    <Label Content="{Binding Name}"/>
-                                    <Label Content="{Binding Users.Login}"/>
+                                    <Label Content="{Binding surname}"/>
+                                    <Label Content="{Binding name}"/>
+                                    <Label Content="{Binding patronymic}"/>
                                 </StackPanel>
                                 <TextBlock Margin="0,-7,0,0">
-                                    <Run Text="Вопросов: " Foreground="White"/>
-                                    <Run Text="{Binding Questions.Count, Mode=OneTime}" />
+                                    <Run Text="Вопросов: " 
+                                         Foreground="White"/>
+                                    <Run Text="{Binding correct}"
+                                         Foreground="White"/>
+                                    <Run Text="/" 
+                                         Foreground="White"/>
+                                    <Run Text="{Binding count}"
+                                         Foreground="White"/>
                                 </TextBlock>
                             </StackPanel>
                         </StackPanel>

+ 28 - 1
MyTests/Pages/CheckTestResultsCatalog.xaml.cs

@@ -20,9 +20,36 @@ namespace MyTests.Pages
     /// </summary>
     public partial class CheckTestResultsCatalog : Page
     {
-        public CheckTestResultsCatalog()
+        public CheckTestResultsCatalog(Tests _test)
         {
             InitializeComponent();
+
+            AnswersListBox.Items.Clear();
+
+            List<AnswerClass> answerList = new List<AnswerClass>();
+
+            foreach (Users user in cnt.db.Users)
+            {
+                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);
+            }
+
+            AnswersListBox.ItemsSource = answerList;
+
+        }
+        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; }
         }
     }
 }

+ 14 - 0
MyTests/Pages/EditTestPage.xaml

@@ -0,0 +1,14 @@
+<Page x:Class="MyTests.Pages.EditTestPage"
+      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
+      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+      xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
+      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="EditTestPage">
+
+    <Grid>
+        
+    </Grid>
+</Page>

+ 25 - 0
MyTests/Pages/EditTestPage.xaml.cs

@@ -0,0 +1,25 @@
+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
+{
+    public partial class EditTestPage : Page
+    {
+        public EditTestPage(Tests _test)
+        {
+            InitializeComponent();
+        }
+    }
+}

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

@@ -1,23 +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
 {
-    /// <summary>
-    /// Логика взаимодействия для RegistrationPage.xaml
-    /// </summary>
     public partial class LoginPage : Page
     {
         bool Test = true;

+ 30 - 14
MyTests/Pages/ProfilePage.xaml

@@ -89,7 +89,8 @@
                  Grid.Row="1"
                  Margin="10,0,10,0"
                  Background="{StaticResource color1}"
-                 BorderBrush="{x:Null}">
+                 BorderBrush="{x:Null}"
+                 SelectionChanged="TestsListBox_SelectionChanged">
             <ScrollViewer VerticalScrollBarVisibility="Visible"/>
             <ListBox.ItemTemplate>
                 <DataTemplate>
@@ -97,26 +98,41 @@
                             Margin="-10,0,0,0"
                             Height="45"
                             CornerRadius="10"
-                            Background="{StaticResource color2}"
-                            MouseDown="TestsListBox_Selected">
-                        <StackPanel Orientation="Horizontal">
-                            <Image Width="30"
+                            Background="{StaticResource color2}">
+                        <Grid>
+                            <StackPanel Orientation="Horizontal">
+                                <Image Width="30"
                                Height="30"
                                Margin="10,5,5,5"
                                HorizontalAlignment="Left"
                                Source="/MyTests;component/Resources/approval.png">
-                            </Image>
-                            <StackPanel>
-                                <StackPanel Orientation="Horizontal">
-                                    <Label Content="{Binding Name}"/>
-                                    <Label Content="{Binding Users.Login}"/>
-                                </StackPanel>
-                                <TextBlock Margin="0,-7,0,0">
+                                </Image>
+                                <StackPanel>
+                                    <StackPanel Orientation="Horizontal">
+                                        <Label Content="{Binding Name}"/>
+                                        <Label Content="{Binding Users.Login}"/>
+                                    </StackPanel>
+                                    <TextBlock Margin="0,-7,0,0">
                                     <Run Text="Вопросов: " Foreground="White"/>
                                     <Run Text="{Binding Questions.Count, Mode=OneTime}"/>
-                                </TextBlock>
+                                    </TextBlock>
+                                </StackPanel>
+                            </StackPanel>
+                            <StackPanel Orientation="Horizontal"
+                                        HorizontalAlignment="Right">
+                                <Button Width="30" Height="30"
+                                    Margin="0,0,5,0"
+                                    Content="✓"
+                                    Click="CheckResultsButton_Click">
+                                </Button>
+                                <Button Width="30" Height="30"
+                                    Margin="0,0,5,0"
+                                    Content="✎"
+                                    Click="EditTestButton_Click">
+                                </Button>
                             </StackPanel>
-                        </StackPanel>
+                            
+                        </Grid>
                     </Border>
                 </DataTemplate>
             </ListBox.ItemTemplate>

+ 43 - 6
MyTests/Pages/ProfilePage.xaml.cs

@@ -13,7 +13,7 @@ namespace MyTests.Pages
         public ProfilePage(Users _user)
         {
             InitializeComponent();
-            if(_user != null)
+            if (_user != null)
             {
                 user = _user;
                 UserName.Content = user.Login;
@@ -29,7 +29,7 @@ namespace MyTests.Pages
                     InfoBox.IsEnabled = false;
                     SaveButton.Visibility = Visibility.Collapsed;
                 }
-                if(user.Post == "Преподаватель")
+                if (user.Post == "Преподаватель")
                     TestsLoading();
                 else
                     TestsListBox.Visibility = Visibility.Collapsed;
@@ -37,7 +37,7 @@ namespace MyTests.Pages
         }
         private void EditImage_Click(object sender, RoutedEventArgs e)
         {
-            if(user == Session.User)
+            if (user == Session.User)
             {
                 BitmapImage image = ImagesManip.SelectImage();
                 if (image != null)
@@ -51,7 +51,10 @@ namespace MyTests.Pages
         private void TestsLoading()
         {
             TestsListBox.Items.Clear();
-            TestsListBox.ItemsSource = cnt.db.Tests.Where(item => item.IdUser == user.IdUser).ToList();
+            if(user != Session.User)
+            TestsListBox.ItemsSource = cnt.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();
         }
 
         private void SaveButton_Click(object sender, RoutedEventArgs e)
@@ -67,9 +70,43 @@ namespace MyTests.Pages
                 cnt.db.SaveChanges();
                 new ErrorWindow("Успешно.").ShowDialog();
             }
-            
+
         }
-        private void TestsListBox_Selected(object sender, RoutedEventArgs e)
+        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)
+        {
+            Button btn = (Button)sender;
+            if (btn.DataContext is Tests)
+                NavigationService.Navigate(new Pages.CheckTestResultsCatalog((Tests)btn.DataContext));
+        }
+        private void EditTestButton_Click(object sender, RoutedEventArgs e)
+        {
+            Button btn = (Button)sender;
+            if (btn.DataContext is Tests)
+                NavigationService.Navigate(new Pages.EditTestPage((Tests)btn.DataContext));
+        }
+
+        private void TestsListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
         {
             try
             {

+ 0 - 11
MyTests/Pages/RegistrationPage.xaml.cs

@@ -1,17 +1,7 @@
 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
 {
@@ -20,7 +10,6 @@ namespace MyTests.Pages
     /// </summary>
     public partial class RegistrationPage : Page
     {
-        bool Test = true;
         public RegistrationPage()
         {
             InitializeComponent();

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

@@ -32,7 +32,7 @@ namespace MyTests.Pages
         }
         void LoadingTests()
         {            
-            List<Tests> list = cnt.db.Tests.ToList();
+            List<Tests> list = cnt.db.Tests.Where(item => item.IsVisible == true).ToList();
             if (TestNameBox.Text != "Название теста")
                 list = list.Where(item => item.Name.StartsWith(TestNameBox.Text)).ToList();
             if (AuthorTestBox.Text != "Автор")

+ 1 - 7
MyTests/Session.cs

@@ -1,10 +1,4 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace MyTests
+namespace MyTests
 {
     class Session
     {

+ 1 - 0
MyTests/Tests.cs

@@ -25,6 +25,7 @@ namespace MyTests
         public string Name { get; set; }
         public byte[] Image { get; set; }
         public bool IsAnswersVisible { get; set; }
+        public bool IsVisible { get; set; }
     
         [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
         public virtual ICollection<Questions> Questions { get; set; }

+ 3 - 0
MyTests/Users.cs

@@ -28,6 +28,9 @@ namespace MyTests
         public string Info { get; set; }
         public byte[] Image { get; set; }
         public string Post { get; set; }
+        public string Surname { get; set; }
+        public string Name { get; set; }
+        public string Patronymic { get; set; }
     
         [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
         public virtual ICollection<Answers> Answers { get; set; }