Преглед изворни кода

Another save for this project

-DSG пре 2 година
родитељ
комит
004a4b2782

+ 1 - 1
MyTests/EDM.Designer.cs

@@ -1,4 +1,4 @@
-// Создание кода T4 для модели "C:\Users\milic\source\repos\MyTests\MyTests\EDM.edmx" включено. 
+// Создание кода T4 для модели "C:\Users\pc\Source\Repos\StTest\MyTests\EDM.edmx" включено. 
 // Чтобы включить формирование кода прежних версий, измените значение свойства "Стратегия создания кода" конструктора
 // на "Legacy ObjectContext". Это свойство доступно в окне "Свойства", если модель
 // открыта в конструкторе.

+ 57 - 55
MyTests/EDM.edmx

@@ -4,7 +4,7 @@
   <edmx:Runtime>
     <!-- SSDL content -->
     <edmx:StorageModels>
-    <Schema Namespace="Хранилище MyTestsDataBaseModel" Provider="System.Data.SqlClient" ProviderManifestToken="2012" Alias="Self" xmlns:store="http://schemas.microsoft.com/ado/2007/12/edm/EntityStoreSchemaGenerator" xmlns:customannotation="http://schemas.microsoft.com/ado/2013/11/edm/customannotation" xmlns="http://schemas.microsoft.com/ado/2009/11/edm/ssdl">
+    <Schema Namespace="MyTestsDataBaseModel.Store" Provider="System.Data.SqlClient" ProviderManifestToken="2012" Alias="Self" xmlns:store="http://schemas.microsoft.com/ado/2007/12/edm/EntityStoreSchemaGenerator" xmlns:customannotation="http://schemas.microsoft.com/ado/2013/11/edm/customannotation" xmlns="http://schemas.microsoft.com/ado/2009/11/edm/ssdl">
         <EntityType Name="Answers">
           <Key>
             <PropertyRef Name="IdUserAnswer" />
@@ -33,6 +33,7 @@
           <Property Name="Image" Type="varbinary(max)" />
           <Property Name="IsAnswersVisible" Type="bit" Nullable="false" />
           <Property Name="IsVisible" Type="bit" Nullable="false" />
+          <Property Name="CanAgain" Type="bit" Nullable="false" />
         </EntityType>
         <EntityType Name="Users">
           <Key>
@@ -97,7 +98,7 @@
             </Dependent>
           </ReferentialConstraint>
         </Association>
-        <EntityContainer Name="Хранилище MyTestsDataBaseModelContainer">
+        <EntityContainer Name="MyTestsDataBaseModelStoreContainer">
           <EntitySet Name="Answers" EntityType="Self.Answers" Schema="dbo" store:Type="Tables" />
           <EntitySet Name="Questions" EntityType="Self.Questions" Schema="dbo" store:Type="Tables" />
           <EntitySet Name="Tests" EntityType="Self.Tests" Schema="dbo" store:Type="Tables" />
@@ -157,6 +158,7 @@
           <NavigationProperty Name="Users" Relationship="Self.FK_Tests_Users" FromRole="Tests" ToRole="Users" />
           <Property Name="IsAnswersVisible" Type="Boolean" Nullable="false" />
           <Property Name="IsVisible" Type="Boolean" Nullable="false" />
+          <Property Name="CanAgain" Type="Boolean" Nullable="false" />
         </EntityType>
         <EntityType Name="Users">
           <Key>
@@ -249,59 +251,59 @@
     </edmx:ConceptualModels>
     <!-- C-S mapping content -->
     <edmx:Mappings>
-      <Mapping Space="C-S" xmlns="http://schemas.microsoft.com/ado/2009/11/mapping/cs">
-        <EntityContainerMapping StorageEntityContainer="Хранилище MyTestsDataBaseModelContainer" CdmEntityContainer="MyTestsDataBaseEntities">
-          <EntitySetMapping Name="Answers">
-            <EntityTypeMapping TypeName="MyTestsDataBaseModel.Answers">
-              <MappingFragment StoreEntitySet="Answers">
-                <ScalarProperty Name="IdUserAnswer" ColumnName="IdUserAnswer" />
-                <ScalarProperty Name="IdQuestion" ColumnName="IdQuestion" />
-                <ScalarProperty Name="IdUser" ColumnName="IdUser" />
-                <ScalarProperty Name="Answer" ColumnName="Answer" />
-              </MappingFragment>
-            </EntityTypeMapping>
-          </EntitySetMapping>
-          <EntitySetMapping Name="Questions">
-            <EntityTypeMapping TypeName="MyTestsDataBaseModel.Questions">
-              <MappingFragment StoreEntitySet="Questions">
-                <ScalarProperty Name="IdQuestion" ColumnName="IdQuestion" />
+    <Mapping Space="C-S" xmlns="http://schemas.microsoft.com/ado/2009/11/mapping/cs">
+  <EntityContainerMapping StorageEntityContainer="MyTestsDataBaseModelStoreContainer" CdmEntityContainer="MyTestsDataBaseEntities">
+    <EntitySetMapping Name="Answers">
+      <EntityTypeMapping TypeName="IsTypeOf(MyTestsDataBaseModel.Answers)">
+        <MappingFragment StoreEntitySet="Answers">
+          <ScalarProperty Name="IdUserAnswer" ColumnName="IdUserAnswer" />
+          <ScalarProperty Name="IdQuestion" ColumnName="IdQuestion" />
+          <ScalarProperty Name="IdUser" ColumnName="IdUser" />
+          <ScalarProperty Name="Answer" ColumnName="Answer" />
+        </MappingFragment>
+      </EntityTypeMapping>
+    </EntitySetMapping>
+    <EntitySetMapping Name="Questions">
+      <EntityTypeMapping TypeName="IsTypeOf(MyTestsDataBaseModel.Questions)">
+        <MappingFragment StoreEntitySet="Questions">
+          <ScalarProperty Name="IdQuestion" ColumnName="IdQuestion" />
+          <ScalarProperty Name="IdTest" ColumnName="IdTest" />
+          <ScalarProperty Name="Content" ColumnName="Content" />
+          <ScalarProperty Name="Answer" ColumnName="Answer" />
+        </MappingFragment>
+      </EntityTypeMapping>
+    </EntitySetMapping>
+    <EntitySetMapping Name="Tests">
+      <EntityTypeMapping TypeName="IsTypeOf(MyTestsDataBaseModel.Tests)">
+        <MappingFragment StoreEntitySet="Tests">
+          <ScalarProperty Name="CanAgain" ColumnName="CanAgain" />
                 <ScalarProperty Name="IdTest" ColumnName="IdTest" />
-                <ScalarProperty Name="Content" ColumnName="Content" />
-                <ScalarProperty Name="Answer" ColumnName="Answer" />
-              </MappingFragment>
-            </EntityTypeMapping>
-          </EntitySetMapping>
-          <EntitySetMapping Name="Tests">
-            <EntityTypeMapping TypeName="MyTestsDataBaseModel.Tests">
-              <MappingFragment StoreEntitySet="Tests">
-                <ScalarProperty Name="IsVisible" ColumnName="IsVisible" />
-                <ScalarProperty Name="IsAnswersVisible" ColumnName="IsAnswersVisible" />
-                <ScalarProperty Name="IdTest" ColumnName="IdTest" />
-                <ScalarProperty Name="IdUser" ColumnName="IdUser" />
-                <ScalarProperty Name="Name" ColumnName="Name" />
-                <ScalarProperty Name="Image" ColumnName="Image" />
-              </MappingFragment>
-            </EntityTypeMapping>
-          </EntitySetMapping>
-          <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" />
-                <ScalarProperty Name="Password" ColumnName="Password" />
-                <ScalarProperty Name="Email" ColumnName="Email" />
-                <ScalarProperty Name="Info" ColumnName="Info" />
-                <ScalarProperty Name="Image" ColumnName="Image" />
-              </MappingFragment>
-            </EntityTypeMapping>
-          </EntitySetMapping>
-        </EntityContainerMapping>
-      </Mapping>
-    </edmx:Mappings>
+          <ScalarProperty Name="IdUser" ColumnName="IdUser" />
+          <ScalarProperty Name="Name" ColumnName="Name" />
+          <ScalarProperty Name="Image" ColumnName="Image" />
+          <ScalarProperty Name="IsAnswersVisible" ColumnName="IsAnswersVisible" />
+          <ScalarProperty Name="IsVisible" ColumnName="IsVisible" />
+        </MappingFragment>
+      </EntityTypeMapping>
+    </EntitySetMapping>
+    <EntitySetMapping Name="Users">
+      <EntityTypeMapping TypeName="IsTypeOf(MyTestsDataBaseModel.Users)">
+        <MappingFragment StoreEntitySet="Users">
+          <ScalarProperty Name="IdUser" ColumnName="IdUser" />
+          <ScalarProperty Name="Login" ColumnName="Login" />
+          <ScalarProperty Name="Password" ColumnName="Password" />
+          <ScalarProperty Name="Email" ColumnName="Email" />
+          <ScalarProperty Name="Info" ColumnName="Info" />
+          <ScalarProperty Name="Image" ColumnName="Image" />
+          <ScalarProperty Name="Post" ColumnName="Post" />
+          <ScalarProperty Name="Surname" ColumnName="Surname" />
+          <ScalarProperty Name="Name" ColumnName="Name" />
+          <ScalarProperty Name="Patronymic" ColumnName="Patronymic" />
+        </MappingFragment>
+      </EntityTypeMapping>
+    </EntitySetMapping>
+  </EntityContainerMapping>
+</Mapping></edmx:Mappings>
   </edmx:Runtime>
   <!-- EF Designer content (DO NOT EDIT MANUALLY BELOW HERE) -->
   <Designer xmlns="http://schemas.microsoft.com/ado/2009/11/edmx">
@@ -315,7 +317,7 @@
         <DesignerProperty Name="ValidateOnBuild" Value="true" />
         <DesignerProperty Name="EnablePluralization" Value="false" />
         <DesignerProperty Name="IncludeForeignKeysInModel" Value="true" />
-        <DesignerProperty Name="UseLegacyProvider" Value="false" />
+        <DesignerProperty Name="UseLegacyProvider" Value="False" />
         <DesignerProperty Name="CodeGenerationStrategy" Value="Нет" />
       </DesignerInfoPropertySet>
     </Options>

+ 64 - 2
MyTests/EDM.edmx.sql

@@ -2,8 +2,8 @@
 -- --------------------------------------------------
 -- Entity Designer DDL Script for SQL Server 2005, 2008, 2012 and Azure
 -- --------------------------------------------------
+-- Date Created: 08/09/2022 06:03:40
+-- Generated from EDMX file: C:\Users\pc\source\repos\StTest\MyTests\EDM.edmx
 -- --------------------------------------------------
 
 SET QUOTED_IDENTIFIER OFF;
@@ -17,6 +17,12 @@ GO
 -- Dropping existing FOREIGN KEY constraints
 -- --------------------------------------------------
 
+IF OBJECT_ID(N'[dbo].[FK_Answers_Questions]', 'F') IS NOT NULL
+    ALTER TABLE [dbo].[Answers] DROP CONSTRAINT [FK_Answers_Questions];
+GO
+IF OBJECT_ID(N'[dbo].[FK_Answers_Users]', 'F') IS NOT NULL
+    ALTER TABLE [dbo].[Answers] DROP CONSTRAINT [FK_Answers_Users];
+GO
 IF OBJECT_ID(N'[dbo].[FK_Questions_Tests]', 'F') IS NOT NULL
     ALTER TABLE [dbo].[Questions] DROP CONSTRAINT [FK_Questions_Tests];
 GO
@@ -28,6 +34,9 @@ GO
 -- Dropping existing tables
 -- --------------------------------------------------
 
+IF OBJECT_ID(N'[dbo].[Answers]', 'U') IS NOT NULL
+    DROP TABLE [dbo].[Answers];
+GO
 IF OBJECT_ID(N'[dbo].[Questions]', 'U') IS NOT NULL
     DROP TABLE [dbo].[Questions];
 GO
@@ -42,6 +51,15 @@ GO
 -- Creating all tables
 -- --------------------------------------------------
 
+-- Creating table 'Answers'
+CREATE TABLE [dbo].[Answers] (
+    [IdUserAnswer] int  NOT NULL,
+    [IdQuestion] int  NOT NULL,
+    [IdUser] int  NOT NULL,
+    [Answer] nvarchar(150)  NOT NULL
+);
+GO
+
 -- Creating table 'Questions'
 CREATE TABLE [dbo].[Questions] (
     [IdQuestion] int  NOT NULL,
@@ -56,7 +74,9 @@ CREATE TABLE [dbo].[Tests] (
     [IdTest] int  NOT NULL,
     [IdUser] int  NOT NULL,
     [Name] nvarchar(150)  NOT NULL,
-    [Image] varbinary(max)  NULL
+    [Image] varbinary(max)  NULL,
+    [IsAnswersVisible] bit  NOT NULL,
+    [IsVisible] bit  NOT NULL
 );
 GO
 
@@ -67,7 +87,11 @@ CREATE TABLE [dbo].[Users] (
     [Password] nvarchar(50)  NOT NULL,
     [Email] nvarchar(50)  NOT NULL,
     [Info] nvarchar(50)  NULL,
-    [Image] varbinary(max)  NULL
+    [Image] varbinary(max)  NULL,
+    [Post] nvarchar(25)  NOT NULL,
+    [Surname] nvarchar(50)  NOT NULL,
+    [Name] nvarchar(50)  NOT NULL,
+    [Patronymic] nvarchar(50)  NOT NULL
 );
 GO
 
@@ -75,6 +99,12 @@ GO
 -- Creating all PRIMARY KEY constraints
 -- --------------------------------------------------
 
+-- Creating primary key on [IdUserAnswer] in table 'Answers'
+ALTER TABLE [dbo].[Answers]
+ADD CONSTRAINT [PK_Answers]
+    PRIMARY KEY CLUSTERED ([IdUserAnswer] ASC);
+GO
+
 -- Creating primary key on [IdQuestion] in table 'Questions'
 ALTER TABLE [dbo].[Questions]
 ADD CONSTRAINT [PK_Questions]
@@ -97,6 +127,36 @@ GO
 -- Creating all FOREIGN KEY constraints
 -- --------------------------------------------------
 
+-- Creating foreign key on [IdQuestion] in table 'Answers'
+ALTER TABLE [dbo].[Answers]
+ADD CONSTRAINT [FK_Answers_Questions]
+    FOREIGN KEY ([IdQuestion])
+    REFERENCES [dbo].[Questions]
+        ([IdQuestion])
+    ON DELETE NO ACTION ON UPDATE NO ACTION;
+GO
+
+-- Creating non-clustered index for FOREIGN KEY 'FK_Answers_Questions'
+CREATE INDEX [IX_FK_Answers_Questions]
+ON [dbo].[Answers]
+    ([IdQuestion]);
+GO
+
+-- Creating foreign key on [IdUser] in table 'Answers'
+ALTER TABLE [dbo].[Answers]
+ADD CONSTRAINT [FK_Answers_Users]
+    FOREIGN KEY ([IdUser])
+    REFERENCES [dbo].[Users]
+        ([IdUser])
+    ON DELETE NO ACTION ON UPDATE NO ACTION;
+GO
+
+-- Creating non-clustered index for FOREIGN KEY 'FK_Answers_Users'
+CREATE INDEX [IX_FK_Answers_Users]
+ON [dbo].[Answers]
+    ([IdUser]);
+GO
+
 -- Creating foreign key on [IdTest] in table 'Questions'
 ALTER TABLE [dbo].[Questions]
 ADD CONSTRAINT [FK_Questions_Tests]

+ 18 - 1
MyTests/ImagesManip.cs

@@ -5,7 +5,7 @@ using System.Windows.Media.Imaging;
 
 namespace MyTests
 {
-    internal class ImagesManip
+    internal class ImagesFunctions
     {
         public static byte[] BitmapSourceToByteArray(BitmapSource image)
         {
@@ -54,5 +54,22 @@ namespace MyTests
             }
             
         }
+        public static BitmapImage NewImage(Tests test)
+        {
+            try
+            {
+                MemoryStream ms = new MemoryStream(test.Image);
+                BitmapImage image = new BitmapImage();
+                image.BeginInit();
+                image.StreamSource = ms;
+                image.EndInit();
+                return image;
+            }
+            catch
+            {
+                return new BitmapImage(new Uri("../Resources/StandartImage.png", UriKind.RelativeOrAbsolute));
+            }
+            
+        }
     }
 }

+ 2 - 8
MyTests/MyTests.csproj

@@ -109,9 +109,6 @@
     <Compile Include="Pages\ResultTestPage.xaml.cs">
       <DependentUpon>ResultTestPage.xaml</DependentUpon>
     </Compile>
-    <Compile Include="Pages\TestPage.xaml.cs">
-      <DependentUpon>TestPage.xaml</DependentUpon>
-    </Compile>
     <Compile Include="Pages\TestsCatalog.xaml.cs">
       <DependentUpon>TestsCatalog.xaml</DependentUpon>
     </Compile>
@@ -150,7 +147,7 @@
       <DependentUpon>ErrorWindow.xaml</DependentUpon>
     </Compile>
     <Compile Include="Functions.cs" />
-    <Compile Include="ImagesManip.cs" />
+    <Compile Include="ImagesFunctions.cs" />
     <Compile Include="MainWindow.xaml.cs">
       <DependentUpon>MainWindow.xaml</DependentUpon>
       <SubType>Code</SubType>
@@ -191,10 +188,6 @@
       <SubType>Designer</SubType>
       <Generator>MSBuild:Compile</Generator>
     </Page>
-    <Page Include="Pages\TestPage.xaml">
-      <SubType>Designer</SubType>
-      <Generator>MSBuild:Compile</Generator>
-    </Page>
     <Page Include="Pages\TestsCatalog.xaml">
       <SubType>Designer</SubType>
       <Generator>MSBuild:Compile</Generator>
@@ -256,6 +249,7 @@
       <DependentUpon>EDM.edmx</DependentUpon>
       <LastGenOutput>EDM.cs</LastGenOutput>
     </Content>
+    <Resource Include="Resources\Question-mark.png" />
     <Resource Include="Resources\Approval.png" />
     <Resource Include="Resources\Ico.png" />
     <Resource Include="Resources\Search.png" />

+ 1 - 2
MyTests/Pages/CheckTestResults.xaml

@@ -12,8 +12,7 @@
             <RowDefinition Height="50"/>
             <RowDefinition/>
         </Grid.RowDefinitions>
-        <StackPanel Orientation="Horizontal"
-                    HorizontalAlignment="Left">
+        <StackPanel Orientation="Horizontal">
             <Image Name="TestImg"
                    Source="/MyTests;component/Resources/Approval.png"
                    Margin="7">

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

@@ -28,7 +28,7 @@ namespace MyTests.Pages
             if (_user.Image == null)
                 AuthorImg.Source = new BitmapImage(new Uri("../Resources/StandartImage.png", UriKind.RelativeOrAbsolute));
             else
-                AuthorImg.Source = ImagesManip.NewImage(_user);
+                AuthorImg.Source = ImagesFunctions.NewImage(_user);
 
             AnswersListBox.Items.Clear();
 

+ 2 - 1
MyTests/Pages/CheckTestResultsCatalog.xaml

@@ -68,7 +68,8 @@
                 Content="Назад"
                 Width="120"
                 Height="40"
-                FontSize="20" Margin="340,5">
+                FontSize="20"
+                Click="BackButton_Click">
         </Button>
     </Grid>
 </Page>

+ 11 - 5
MyTests/Pages/CheckTestResultsCatalog.xaml.cs

@@ -31,7 +31,7 @@ namespace MyTests.Pages
 
             foreach (Users user in cnt.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 (cnt.db.Answers.Select(item => item.Questions.IdTest + " " + item.IdUser).Contains(_test.IdTest + " " + user.IdUser))
                 {
                     AnswerClass newUserAnswer = new AnswerClass();
                     newUserAnswer.User = user;
@@ -52,9 +52,10 @@ namespace MyTests.Pages
             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++;
+            if (Quest.Answer.Length == Quest.UserAnswer.Length)
+                for (int i = 0; i < Quest.Answer.Length; i++)
+                    if (Quest.Answer[i] == Quest.UserAnswer[i])
+                        value++;
             return value;
         }
 
@@ -62,11 +63,16 @@ namespace MyTests.Pages
         {
             if (((AnswerClass)AnswersListBox.SelectedItem) != null)
             {
-                NavigationService.Navigate(new Pages.CheckTestResults(test, 
+                NavigationService.Navigate(new Pages.CheckTestResults(test,
                     cnt.db.Users.Where(item => item.IdUser == ((AnswerClass)AnswersListBox.SelectedItem).User.IdUser).FirstOrDefault()));
             }
         }
 
+        private void BackButton_Click(object sender, RoutedEventArgs e)
+        {
+            NavigationService.GoBack();
+        }
+
         public static class Quest
         {
             public static string[] Answer;

+ 115 - 6
MyTests/Pages/EditTestPage.xaml

@@ -1,14 +1,123 @@
 <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: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">
+      mc:Ignorable="d"
+      d:DesignHeight="450"
+      d:DesignWidth="676"
+      Background="{StaticResource color1}">
 
     <Grid>
-        
+        <Grid.RowDefinitions>
+            <RowDefinition Height="50"/>
+            <RowDefinition/>
+            <RowDefinition Height="50"/>
+        </Grid.RowDefinitions>
+        <StackPanel Orientation="Horizontal">
+            <Image Name="TestImg"
+                   MinHeight="35"
+                   MinWidth="35"
+                   Source="/MyTests;component/Resources/Approval.png"
+                   Margin="7"
+                   MouseDown="TestImg_MouseDown">
+            </Image>
+            <TextBox Name="TestNameBox"
+                     Text="Тест"
+                     FontSize="25"
+                     BorderBrush="{x:Null}"
+                     LostFocus="TestNameBox_LostFocus">
+            </TextBox>
+            <Label Content=" - редактирование"
+                   FontSize="25"
+                   Foreground="LightGray"
+                   Opacity="0.5">
+            </Label>
+        </StackPanel>
+        <ScrollViewer Grid.Row="1" Grid.RowSpan="2">
+            <StackPanel>
+                <StackPanel Orientation="Horizontal">
+                    <Label Content="Тест виден другим пользователям:"
+                           FontSize="14"/>
+                    <CheckBox Name="IsVisibleCB"
+                              VerticalContentAlignment="Center"
+                              Click="SaveInfoCB">
+                    </CheckBox>
+                </StackPanel>
+
+                <StackPanel Orientation="Horizontal">
+                    <Label Content="Пользователь может посмотреть свои ответы:"
+                           FontSize="14"/>
+                    <CheckBox Name="IsAnswersVisibleCB"
+                              VerticalContentAlignment="Center"
+                              Click="SaveInfoCB">
+                    </CheckBox>
+                </StackPanel>
+
+                <StackPanel Orientation="Horizontal">
+                    <Label Content="Пользователь может пройти тест повторно:"
+                           FontSize="14"/>
+                    <CheckBox Name="CanAgainCB"
+                              VerticalContentAlignment="Center"
+                              Click="SaveInfoCB">
+                    </CheckBox>
+                </StackPanel>
+
+                <StackPanel Orientation="Horizontal"
+                            Height="30"
+                            Margin="0,10,0,10">
+                    <Button Content="Добавить вопрос"
+                            Width="300"
+                            Margin="15,0,15,0"
+                            Click="AddQuestionButton_Click"/>
+                    <Button Content="Удалить вопрос"
+                            Width="300"
+                            Margin="15,0,15,0"
+                            Click="DeleteQuestionButton_Click"/>
+                </StackPanel>
+
+
+                <ListBox Name="QuestionsListBox"
+                         Grid.Row="1"
+                         Background="{StaticResource color1}"
+                         BorderBrush="{x:Null}"
+                         SelectionChanged="QuestionsListBox_SelectionChanged"
+                         ScrollViewer.HorizontalScrollBarVisibility="Disabled"
+                         ScrollViewer.VerticalScrollBarVisibility="Hidden">
+                    <ListBox.ItemTemplate>
+                        <DataTemplate>
+                            <Border Width="{Binding Path=ActualWidth, ElementName=QuestionsListBox}"
+                                    Height="45"
+                                    CornerRadius="10"
+                                    Background="{StaticResource color2}">
+                                <StackPanel Orientation="Horizontal">
+                                    <Image Width="30"
+                                           Height="30"
+                                           Margin="10,5,5,5"
+                                           HorizontalAlignment="Left"
+                                           Source="/MyTests;component/Resources/Question-mark.png">
+                                    </Image>
+                                    <StackPanel>
+                                        <Label Content="{Binding Content}"/>
+                                        <TextBlock Margin="5,-6,0,0">
+                                            <Run Text="Ответ: " Foreground="LightGray"/>
+                                            <Run Text="{Binding Answer}" />
+                                        </TextBlock>
+                                    </StackPanel>
+                                </StackPanel>
+                            </Border>
+                        </DataTemplate>
+                    </ListBox.ItemTemplate>
+                </ListBox>
+            </StackPanel>
+        </ScrollViewer>
+        <Button Grid.Row="2"
+                Content="Назад"
+                Width="120"
+                Height="40"
+                FontSize="20"
+                Click="BackButton_Click">
+        </Button>
     </Grid>
 </Page>

+ 103 - 1
MyTests/Pages/EditTestPage.xaml.cs

@@ -17,9 +17,111 @@ namespace MyTests.Pages
 {
     public partial class EditTestPage : Page
     {
-        public EditTestPage(Tests _test)
+        Tests test;
+        Questions selected;
+        public EditTestPage(Tests _test = null)
         {
             InitializeComponent();
+            if (_test == null)
+            {
+                try
+                {
+                    int testId = cnt.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}",
+                        IsAnswersVisible = false,
+                        IsVisible = false,
+                        CanAgain = false
+                    };
+                    cnt.db.Tests.Add(newTest);
+                    cnt.db.SaveChanges();
+                    test = cnt.db.Tests.Where(item => item.IdTest == testId).FirstOrDefault();
+                }
+                catch (Exception ex)
+                {
+                    new ErrorWindow(ex.Message);
+                }
+            }
+            else
+            {
+                test = _test;
+                IsVisibleCB.IsChecked = test.IsVisible;
+                IsAnswersVisibleCB.IsChecked = test.IsAnswersVisible;
+                CanAgainCB.IsChecked = test.CanAgain;
+            }
+
+
+            TestNameBox.Text = test.Name;
+            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();
+        }
+
+        private void QuestionsListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
+        {
+            selected = ((Questions)QuestionsListBox.SelectedItem);
+        }
+
+        private void AddQuestionButton_Click(object sender, RoutedEventArgs e)
+        {
+            //addQuestion here
+        }
+        private void DeleteQuestionButton_Click(object sender, RoutedEventArgs e)
+        {
+            if (selected != null)
+            {
+                ConfirmationWindow confWindow = new ConfirmationWindow();
+                confWindow.ShowDialog();
+                if (confWindow.answer)
+                {
+                    try
+                    {
+                        cnt.db.Questions.Remove(selected);
+                        cnt.db.SaveChanges();
+                    }
+                    catch (Exception ex)
+                    {
+                        new ErrorWindow(ex.Message);
+                    }
+                }
+                QuestionsUpdate();
+            }
+        }
+        private void BackButton_Click(object sender, RoutedEventArgs e)
+        {
+            NavigationService.GoBack();
+        }
+
+        private void TestImg_MouseDown(object sender, MouseButtonEventArgs e)
+        {
+            BitmapImage image = ImagesFunctions.SelectImage();
+            if (image != null)
+            {
+                TestImg.Source = image;
+                test.Image = ImagesFunctions.BitmapSourceToByteArray((BitmapSource)TestImg.Source);
+                cnt.db.SaveChanges();
+            }
+        }
+
+        private void TestNameBox_LostFocus(object sender, RoutedEventArgs e)
+        {
+            test.Name = TestNameBox.Text;
+        }
+
+        private void SaveInfoCB(object sender, RoutedEventArgs e)
+        {
+            test.IsVisible = IsVisibleCB.IsChecked == true;
+            test.IsAnswersVisible = IsAnswersVisibleCB.IsChecked == true;
+            test.CanAgain = CanAgainCB.IsChecked == true;
+            cnt.db.SaveChanges();
         }
     }
 }

+ 1 - 2
MyTests/Pages/MainPage.xaml

@@ -5,8 +5,7 @@
       xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
       xmlns:local="clr-namespace:MyTests.Pages"
       mc:Ignorable="d" 
-      d:DesignHeight="450" d:DesignWidth="800"
-      Height="450" Width="800">
+      d:DesignHeight="425" d:DesignWidth="800">
     <Grid Background="{StaticResource color1}">
         <Grid.ColumnDefinitions>
             <ColumnDefinition Width="124"/>

+ 2 - 17
MyTests/Pages/MainPage.xaml.cs

@@ -1,23 +1,8 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using System.Windows;
+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>
-    /// Логика взаимодействия для MainPage.xaml
-    /// </summary>
     public partial class MainPage : Page
     {
         public MainPage()
@@ -37,7 +22,7 @@ namespace MyTests.Pages
         }
         private void CreateTestClick(object sender, RoutedEventArgs e)
         {
-            //MainContentFrame.Content = new СatalogPage();
+            MainContentFrame.Content = new EditTestPage();
         }
     }
 }

+ 3 - 2
MyTests/Pages/ProfilePage.xaml

@@ -15,7 +15,7 @@
         <Grid.RowDefinitions>
             <RowDefinition Height="215*"/>
             <RowDefinition Height="173*"/>
-            <RowDefinition Height="42*"/>
+            <RowDefinition Height="50"/>
         </Grid.RowDefinitions>
 
         <Grid Grid.Row="0">
@@ -142,7 +142,7 @@
                                         Click="DeleteTestButton_Click">
                                 </Button>
                             </StackPanel>
-                            
+
                         </Grid>
                     </Border>
                 </DataTemplate>
@@ -152,6 +152,7 @@
         <Button Name="SaveButton"
                 Grid.Row="2"
                 Width="120"
+                Height="40"
                 Margin="5,0,5,0"
                 Content="Сохранить"
                 FontSize="20"

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

@@ -9,17 +9,16 @@ namespace MyTests.Pages
 {
     public partial class ProfilePage : Page
     {
-        public static Users user;
+        static Users user;
         public ProfilePage(Users _user)
         {
             InitializeComponent();
             TestsListBox.Items.Clear();
             user = _user;
             UserName.Content = user.Login;
-            if (user.Image == null)
-                ProfileImage.Source = new BitmapImage(new Uri("../Resources/StandartImage.png", UriKind.RelativeOrAbsolute));
-            else
-                ProfileImage.Source = ImagesManip.NewImage(user);
+            ProfileImage.Source = user.Image == null ?
+                new BitmapImage(new Uri("../Resources/StandartImage.png", UriKind.RelativeOrAbsolute)) :
+                ProfileImage.Source = ImagesFunctions.NewImage(user);
             EmailBox.Text = user.Email;
             InfoBox.Text = user.Info;
             if (user != Session.User)
@@ -37,11 +36,11 @@ namespace MyTests.Pages
         {
             if (user == Session.User)
             {
-                BitmapImage image = ImagesManip.SelectImage();
+                BitmapImage image = ImagesFunctions.SelectImage();
                 if (image != null)
                 {
                     ProfileImage.Source = image;
-                    Session.User.Image = ImagesManip.BitmapSourceToByteArray((BitmapSource)ProfileImage.Source);
+                    Session.User.Image = ImagesFunctions.BitmapSourceToByteArray((BitmapSource)ProfileImage.Source);
                     cnt.db.SaveChanges();
                 }
             }

+ 0 - 64
MyTests/Pages/TestPage.xaml

@@ -1,64 +0,0 @@
-<Page x:Class="MyTests.Pages.TestPage"
-      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="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>
-        <StackPanel Orientation="Horizontal"
-                    HorizontalAlignment="Right">
-            <Label Content="by"
-                   FontSize="25">
-            </Label>
-            <Image Name="AuthorImg"
-                   Source="/MyTests;component/Resources/StandartImage.png"
-                   Margin="7">
-            </Image>
-            <Label Name="AuthorName"
-                   Content="Автор"
-                   FontSize="25"
-                   MouseDown="AuthorName_MouseDown">
-            </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>
-                            <Label Content="{Binding Questions.Content}"/>
-                            <TextBlock>
-                                <Run Text="Ответ: " Foreground="LightGray"/>
-                                <Run Text="{Binding Answer}" Foreground="White"/>
-                            </TextBlock>
-                        </StackPanel>
-                    </Border>
-                </DataTemplate>
-            </ListBox.ItemTemplate>
-        </ListBox>
-    </Grid>
-</Page>

+ 1 - 1
MyTests/Pages/TestsCatalog.xaml

@@ -84,7 +84,7 @@
                                     <Label Content="{Binding Name}"/>
                                     <Label Content="{Binding Users.Login}"/>
                                 </StackPanel>
-                                <TextBlock Margin="0,-7,0,0">
+                                <TextBlock Margin="0,-6,0,0">
                                     <Run Text="Вопросов: " Foreground="White"/>
                                     <Run Text="{Binding Questions.Count, Mode=OneTime}" />
                                 </TextBlock>

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

@@ -28,7 +28,7 @@ namespace MyTests.Pages
 
         private void AddTest_Click(object sender, RoutedEventArgs e)
         {
-
+            NavigationService.Navigate(new EditTestPage());
         }
         void LoadingTests()
         {

BIN
MyTests/Resources/Question-mark.png


+ 2 - 0
MyTests/Styles/Style.xaml

@@ -31,12 +31,14 @@
         <Setter Property="Foreground" Value="White"/>
         <Setter Property="BorderBrush" Value="Black"/>
         <Setter Property="Background" Value="#33363C"/>
+        <Setter Property="VerticalContentAlignment" Value="Center"/>
     </Style>
 
     <Style TargetType="PasswordBox">
         <Setter Property="Foreground" Value="White"/>
         <Setter Property="BorderBrush" Value="Black"/>
         <Setter Property="Background" Value="#33363C"/>
+        <Setter Property="VerticalContentAlignment" Value="Center"/>
     </Style>
 
     <Style TargetType="TextBlock">

+ 1 - 0
MyTests/Tests.cs

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