Jelajahi Sumber

TestPage rework

Imagara 2 tahun lalu
induk
melakukan
ba066a65ae

+ 0 - 24
MyTests/Answer.cs

@@ -1,24 +0,0 @@
-//------------------------------------------------------------------------------
-// <auto-generated>
-//     Этот код создан по шаблону.
-//
-//     Изменения, вносимые в этот файл вручную, могут привести к непредвиденной работе приложения.
-//     Изменения, вносимые в этот файл вручную, будут перезаписаны при повторном создании кода.
-// </auto-generated>
-//------------------------------------------------------------------------------
-
-namespace MyTests
-{
-    using System;
-    using System.Collections.Generic;
-    
-    public partial class Answer
-    {
-        public int IdAnswer { get; set; }
-        public int IdQuestion { get; set; }
-        public string Content { get; set; }
-        public bool isTrue { get; set; }
-    
-        public virtual Questions Questions { get; set; }
-    }
-}

+ 0 - 1
MyTests/EDM.Context.cs

@@ -25,7 +25,6 @@ namespace MyTests
             throw new UnintentionalCodeFirstException();
         }
     
-        public virtual DbSet<Answer> Answer { get; set; }
         public virtual DbSet<Questions> Questions { get; set; }
         public virtual DbSet<Tests> Tests { get; set; }
         public virtual DbSet<Users> Users { get; set; }

+ 5 - 70
MyTests/EDM.edmx

@@ -4,24 +4,15 @@
   <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">
-        <EntityType Name="Answer">
-          <Key>
-            <PropertyRef Name="IdAnswer" />
-          </Key>
-          <Property Name="IdAnswer" Type="int" Nullable="false" />
-          <Property Name="IdQuestion" Type="int" Nullable="false" />
-          <Property Name="Content" Type="nvarchar" MaxLength="150" Nullable="false" />
-          <Property Name="isTrue" Type="bit" Nullable="false" />
-        </EntityType>
+    <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">
         <EntityType Name="Questions">
           <Key>
             <PropertyRef Name="IdQuestion" />
           </Key>
           <Property Name="IdQuestion" Type="int" Nullable="false" />
           <Property Name="IdTest" Type="int" Nullable="false" />
-          <Property Name="QuestionNum" Type="int" />
           <Property Name="Content" Type="nvarchar" MaxLength="150" Nullable="false" />
+          <Property Name="Answer" Type="nvarchar" MaxLength="150" Nullable="false" />
         </EntityType>
         <EntityType Name="Tests">
           <Key>
@@ -43,18 +34,6 @@
           <Property Name="Info" Type="nvarchar" MaxLength="50" />
           <Property Name="Image" Type="varbinary(max)" />
         </EntityType>
-        <Association Name="FK_Answer_Questions">
-          <End Role="Questions" Type="Self.Questions" Multiplicity="1" />
-          <End Role="Answer" Type="Self.Answer" Multiplicity="*" />
-          <ReferentialConstraint>
-            <Principal Role="Questions">
-              <PropertyRef Name="IdQuestion" />
-            </Principal>
-            <Dependent Role="Answer">
-              <PropertyRef Name="IdQuestion" />
-            </Dependent>
-          </ReferentialConstraint>
-        </Association>
         <Association Name="FK_Questions_Tests">
           <End Role="Tests" Type="Self.Tests" Multiplicity="1" />
           <End Role="Questions" Type="Self.Questions" Multiplicity="*" />
@@ -80,14 +59,9 @@
           </ReferentialConstraint>
         </Association>
         <EntityContainer Name="Хранилище MyTestsDataBaseModelContainer">
-          <EntitySet Name="Answer" EntityType="Self.Answer" 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" />
           <EntitySet Name="Users" EntityType="Self.Users" Schema="dbo" store:Type="Tables" />
-          <AssociationSet Name="FK_Answer_Questions" Association="Self.FK_Answer_Questions">
-            <End Role="Questions" EntitySet="Questions" />
-            <End Role="Answer" EntitySet="Answer" />
-          </AssociationSet>
           <AssociationSet Name="FK_Questions_Tests" Association="Self.FK_Questions_Tests">
             <End Role="Tests" EntitySet="Tests" />
             <End Role="Questions" EntitySet="Questions" />
@@ -97,31 +71,19 @@
             <End Role="Tests" EntitySet="Tests" />
           </AssociationSet>
         </EntityContainer>
-      </Schema>
-    </edmx:StorageModels>
+      </Schema></edmx:StorageModels>
     <!-- CSDL content -->
     <edmx:ConceptualModels>
       <Schema Namespace="MyTestsDataBaseModel" Alias="Self" annotation:UseStrongSpatialTypes="false" xmlns:annotation="http://schemas.microsoft.com/ado/2009/02/edm/annotation" xmlns:customannotation="http://schemas.microsoft.com/ado/2013/11/edm/customannotation" xmlns="http://schemas.microsoft.com/ado/2009/11/edm">
-        <EntityType Name="Answer">
-          <Key>
-            <PropertyRef Name="IdAnswer" />
-          </Key>
-          <Property Name="IdAnswer" Type="Int32" Nullable="false" />
-          <Property Name="IdQuestion" Type="Int32" Nullable="false" />
-          <Property Name="Content" Type="String" MaxLength="150" FixedLength="false" Unicode="true" Nullable="false" />
-          <Property Name="isTrue" Type="Boolean" Nullable="false" />
-          <NavigationProperty Name="Questions" Relationship="Self.FK_Answer_Questions" FromRole="Answer" ToRole="Questions" />
-        </EntityType>
         <EntityType Name="Questions">
           <Key>
             <PropertyRef Name="IdQuestion" />
           </Key>
           <Property Name="IdQuestion" Type="Int32" Nullable="false" />
           <Property Name="IdTest" Type="Int32" Nullable="false" />
-          <Property Name="QuestionNum" Type="Int32" />
           <Property Name="Content" Type="String" MaxLength="150" FixedLength="false" Unicode="true" Nullable="false" />
-          <NavigationProperty Name="Answer" Relationship="Self.FK_Answer_Questions" FromRole="Questions" ToRole="Answer" />
           <NavigationProperty Name="Tests" Relationship="Self.FK_Questions_Tests" FromRole="Questions" ToRole="Tests" />
+          <Property Name="Answer" Type="String" Nullable="false" MaxLength="150" FixedLength="false" Unicode="true" />
         </EntityType>
         <EntityType Name="Tests">
           <Key>
@@ -146,18 +108,6 @@
           <Property Name="Image" Type="Binary" MaxLength="Max" FixedLength="false" />
           <NavigationProperty Name="Tests" Relationship="Self.FK_Tests_Users" FromRole="Users" ToRole="Tests" />
         </EntityType>
-        <Association Name="FK_Answer_Questions">
-          <End Role="Questions" Type="Self.Questions" Multiplicity="1" />
-          <End Role="Answer" Type="Self.Answer" Multiplicity="*" />
-          <ReferentialConstraint>
-            <Principal Role="Questions">
-              <PropertyRef Name="IdQuestion" />
-            </Principal>
-            <Dependent Role="Answer">
-              <PropertyRef Name="IdQuestion" />
-            </Dependent>
-          </ReferentialConstraint>
-        </Association>
         <Association Name="FK_Questions_Tests">
           <End Role="Tests" Type="Self.Tests" Multiplicity="1" />
           <End Role="Questions" Type="Self.Questions" Multiplicity="*" />
@@ -183,14 +133,9 @@
           </ReferentialConstraint>
         </Association>
         <EntityContainer Name="MyTestsDataBaseEntities" annotation:LazyLoadingEnabled="true">
-          <EntitySet Name="Answer" EntityType="Self.Answer" />
           <EntitySet Name="Questions" EntityType="Self.Questions" />
           <EntitySet Name="Tests" EntityType="Self.Tests" />
           <EntitySet Name="Users" EntityType="Self.Users" />
-          <AssociationSet Name="FK_Answer_Questions" Association="Self.FK_Answer_Questions">
-            <End Role="Questions" EntitySet="Questions" />
-            <End Role="Answer" EntitySet="Answer" />
-          </AssociationSet>
           <AssociationSet Name="FK_Questions_Tests" Association="Self.FK_Questions_Tests">
             <End Role="Tests" EntitySet="Tests" />
             <End Role="Questions" EntitySet="Questions" />
@@ -206,22 +151,12 @@
     <edmx:Mappings>
       <Mapping Space="C-S" xmlns="http://schemas.microsoft.com/ado/2009/11/mapping/cs">
         <EntityContainerMapping StorageEntityContainer="Хранилище MyTestsDataBaseModelContainer" CdmEntityContainer="MyTestsDataBaseEntities">
-          <EntitySetMapping Name="Answer">
-            <EntityTypeMapping TypeName="MyTestsDataBaseModel.Answer">
-              <MappingFragment StoreEntitySet="Answer">
-                <ScalarProperty Name="IdAnswer" ColumnName="IdAnswer" />
-                <ScalarProperty Name="IdQuestion" ColumnName="IdQuestion" />
-                <ScalarProperty Name="Content" ColumnName="Content" />
-                <ScalarProperty Name="isTrue" ColumnName="isTrue" />
-              </MappingFragment>
-            </EntityTypeMapping>
-          </EntitySetMapping>
           <EntitySetMapping Name="Questions">
             <EntityTypeMapping TypeName="MyTestsDataBaseModel.Questions">
               <MappingFragment StoreEntitySet="Questions">
+                <ScalarProperty Name="Answer" ColumnName="Answer" />
                 <ScalarProperty Name="IdQuestion" ColumnName="IdQuestion" />
                 <ScalarProperty Name="IdTest" ColumnName="IdTest" />
-                <ScalarProperty Name="QuestionNum" ColumnName="QuestionNum" />
                 <ScalarProperty Name="Content" ColumnName="Content" />
               </MappingFragment>
             </EntityTypeMapping>

+ 0 - 2
MyTests/EDM.edmx.diagram

@@ -5,11 +5,9 @@
     <!-- Diagram content (shape and connector positions) -->
     <edmx:Diagrams>
       <Diagram DiagramId="a3a420bb96024b0f95a0dd865890e046" Name="Diagram1">
-        <EntityTypeShape EntityType="MyTestsDataBaseModel.Answer" Width="1.5" PointX="7.5" PointY="1.125" IsExpanded="true" />
         <EntityTypeShape EntityType="MyTestsDataBaseModel.Questions" Width="1.5" PointX="5.25" PointY="1" IsExpanded="true" />
         <EntityTypeShape EntityType="MyTestsDataBaseModel.Tests" Width="1.5" PointX="3" PointY="1" IsExpanded="true" />
         <EntityTypeShape EntityType="MyTestsDataBaseModel.Users" Width="1.5" PointX="0.75" PointY="1" IsExpanded="true" />
-        <AssociationConnector Association="MyTestsDataBaseModel.FK_Answer_Questions" ManuallyRouted="false" />
         <AssociationConnector Association="MyTestsDataBaseModel.FK_Questions_Tests" ManuallyRouted="false" />
         <AssociationConnector Association="MyTestsDataBaseModel.FK_Tests_Users" ManuallyRouted="false" />
       </Diagram>

+ 0 - 3
MyTests/MyTests.csproj

@@ -64,9 +64,6 @@
       <Generator>MSBuild:Compile</Generator>
       <SubType>Designer</SubType>
     </ApplicationDefinition>
-    <Compile Include="Answer.cs">
-      <DependentUpon>EDM.tt</DependentUpon>
-    </Compile>
     <Compile Include="EDM.Context.cs">
       <AutoGen>True</AutoGen>
       <DesignTime>True</DesignTime>

+ 56 - 1
MyTests/Pages/TestPage.xaml

@@ -8,6 +8,61 @@
       d:DesignHeight="450" 
       d:DesignWidth="800">
     <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">
+            </Label>
+        </StackPanel>
+        <ListBox Name="TestsListBox"
+                 Background="{StaticResource color1}"
+                 BorderBrush="{Binding TestsListBox}" 
+                 Grid.Row="1">
+            <ScrollViewer VerticalScrollBarVisibility="Visible"/>
+            <ListBox.ItemTemplate>
+                <DataTemplate>
+                    <Border Width="640"
+                            Height="50"
+                            CornerRadius="10"
+                            Background="{StaticResource color2}">
+                        <StackPanel Orientation="Horizontal">
+                            <Image Width="35"
+                               Height="35"
+                               Margin="5"
+                               HorizontalAlignment="Left"
+                               Source="/MyTests;component/Resources/approval.png">
+                            </Image>
+                            <StackPanel>
+                                <Label Content="{Binding Content}"/>
+                                <TextBox Text="Ответ:"/>
+                            </StackPanel>
+                        </StackPanel>
+                    </Border>
+                </DataTemplate>
+            </ListBox.ItemTemplate>
+        </ListBox>
     </Grid>
 </Page>

+ 11 - 4
MyTests/Pages/TestPage.xaml.cs

@@ -15,14 +15,21 @@ using System.Windows.Shapes;
 
 namespace MyTests.Pages
 {
-    /// <summary>
-    /// Логика взаимодействия для TestPage.xaml
-    /// </summary>
     public partial class TestPage : Page
     {
-        public TestPage()
+        int testId;
+        Tests test;
+        public TestPage(int id)
         {
             InitializeComponent();
+            testId = cnt.db.Tests.Where(item => item.IdTest == id).Select(item => item.IdTest).FirstOrDefault();
+            test = cnt.db.Tests.Where(item => item.IdTest == id).FirstOrDefault();
+            LoadingQuestions();
+        }
+        void LoadingQuestions()
+        {
+            TestsListBox.Items.Clear();
+            TestsListBox.ItemsSource = cnt.db.Questions.Where(item=>item.IdTest == testId).ToList(); ;
         }
     }
 }

+ 4 - 3
MyTests/Pages/TestsCatalog.xaml

@@ -58,7 +58,8 @@
                     <Border Width="785"
                             Height="45"
                             CornerRadius="10"
-                          Background="{StaticResource color2}">
+                            Background="{StaticResource color2}"
+                            MouseDown="TestsListBox_Selected">
                         <StackPanel Orientation="Horizontal">
                             <Image Width="35"
                                Height="35"
@@ -68,8 +69,8 @@
                             </Image>
                             <StackPanel>
                                 <StackPanel Orientation="Horizontal">
-                                    <Label Content="{Binding TestName}"/>
-                                    <Label Content="{Binding TestAuthor}"/>
+                                    <Label Content="{Binding Name}"/>
+                                    <Label Content="{Binding Users.Login}"/>
                                 </StackPanel>
                                 <Label Content="Вопросов: 15"
                                    Margin="0,-7,0,0">

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

@@ -23,83 +23,39 @@ namespace MyTests.Pages
         public TestsCatalog()
         {
             InitializeComponent();
-            //LoadingTests();
+            LoadingTests();
         }
 
         private void AddTest_Click(object sender, RoutedEventArgs e)
         {
 
         }
-        private void AddTest(string author, BitmapImage imageSource, int test)
-        {
-            Grid testGrid = new Grid
-            {
-                Background = new SolidColorBrush(Color.FromArgb(0xFF, 0x40, 0x44, 0x4B)),
-                Height = 45,
-                Width = 590,
-                Margin = new Thickness(10, 5, 10, 5)
-            };
-
-            Image testImage = new Image
-            {
-                Source = imageSource,
-                Width = 35,
-                Height = 35,
-                Margin = new Thickness(5),
-                HorizontalAlignment = HorizontalAlignment.Left
-            };
-
-            testGrid.Children.Add(testImage);
-
-            Label authorLabel = new Label();
-            authorLabel.Content = author;
-            authorLabel.Foreground = Brushes.White;
-            authorLabel.FontWeight = FontWeights.Bold;
-            authorLabel.HorizontalAlignment = HorizontalAlignment.Left;
-            authorLabel.VerticalAlignment = VerticalAlignment.Top;
-            authorLabel.Margin = new Thickness(40, 0, 0, 0);
-
-            testGrid.Children.Add(authorLabel);
-
-            Label testLabel = new Label();
-            testLabel.Content = test;
-            testLabel.Foreground = Brushes.White;
-            testLabel.HorizontalAlignment = HorizontalAlignment.Left;
-            testLabel.VerticalAlignment = VerticalAlignment.Bottom;
-            testLabel.Margin = new Thickness(40, 0, 0, 0);
-            testGrid.Children.Add(testLabel);
-
-            TestsListBox.Items.Add(testGrid);
-        }
         void LoadingTests()
         {
-            TestsListBox.Items.Clear();
-            var list = cnt.db.Tests.Where(item => item.IdUser == Session.userId).ToList();
-            if(TestNameBox.Text != "Название теста")
+            var list = cnt.db.Tests.ToList();
+            if (TestNameBox.Text != "Название теста")
                 list = list.Where(item => item.Name == TestNameBox.Text).ToList();
-            if(AuthorTestBox.Text != "Автор")
+            if (AuthorTestBox.Text != "Автор")
                 list = list.Where(item => item.Users.Login == AuthorTestBox.Text).ToList();
-
-            foreach (Tests test in list)
-            {
-                try
-                {
-                    BitmapImage img = test.Image == null ?
-                        new BitmapImage(new Uri("../Resources/Approval.png", UriKind.RelativeOrAbsolute)) :
-                        ImagesManip.NewImage(cnt.db.Users.Where(item => item.IdUser == Session.userId).FirstOrDefault());
-                    TestsListBox.ItemsSource = new[] { new { TestName = test.Name, TestAuthor = test.Users.Login } };
-                    //AddTest(test.Name, img, cnt.db.Questions.Where(item => item.IdTest == test.IdTest).Count());
-                }
-                catch (Exception ex)
-                {
-                    new ErrorWindow(ex.ToString()).ShowDialog();
-                }
-            }
+            TestsListBox.Items.Clear();
+            TestsListBox.ItemsSource = list;
         }
 
         private void FindTests_Click(object sender, RoutedEventArgs e)
         {
             LoadingTests();
         }
+        private void TestsListBox_Selected(object sender, RoutedEventArgs e)
+        {
+            try
+            {
+                if (((Tests)TestsListBox.SelectedItem) != null)
+                NavigationService.Navigate(new Pages.TestPage(((Tests)TestsListBox.SelectedItem).IdTest));
+            }
+            catch
+            {
+                new ErrorWindow("Ошибка открытия теста.").ShowDialog();
+            }
+        }
     }
 }

+ 1 - 9
MyTests/Questions.cs

@@ -14,19 +14,11 @@ namespace MyTests
     
     public partial class Questions
     {
-        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
-        public Questions()
-        {
-            this.Answer = new HashSet<Answer>();
-        }
-    
         public int IdQuestion { get; set; }
         public int IdTest { get; set; }
-        public Nullable<int> QuestionNum { get; set; }
         public string Content { get; set; }
+        public string Answer { get; set; }
     
-        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
-        public virtual ICollection<Answer> Answer { get; set; }
         public virtual Tests Tests { get; set; }
     }
 }