Explorar o código

Починил результат + профили

Imagara %!s(int64=2) %!d(string=hai) anos
pai
achega
bb30d274a9

+ 1 - 1
MyTests/EDM.Designer.cs

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

+ 2 - 2
MyTests/MainWindow.xaml.cs

@@ -23,7 +23,7 @@ namespace MyTests
         public MainWindow()
         {
             InitializeComponent();
-            MainFrame.Content = new Pages.ProfilePage();
+            MainFrame.Content = new Pages.TestsCatalog();
         }
 
         private void Border_MouseDown(object sender, MouseButtonEventArgs e)
@@ -52,7 +52,7 @@ namespace MyTests
 
         private void ProfileClick(object sender, RoutedEventArgs e)
         {
-            MainFrame.Content = new Pages.ProfilePage();
+            MainFrame.Content = new Pages.ProfilePage(Session.User);
         }
 
         private void TestsCatalogClick(object sender, RoutedEventArgs e)

+ 2 - 2
MyTests/Pages/CurTestPage.xaml

@@ -16,11 +16,11 @@
             <RowDefinition Height="89*"/>
         </Grid.RowDefinitions>
         <TextBlock Name="QuestionBox"
-                   Text="{Binding Content}"
+                   Text="Тут типа вопрос"
                    VerticalAlignment="Center"
                    HorizontalAlignment="Center"
                    FontSize="40"
-                   TextWrapping="Wrap" Height="54" Width="0">
+                   TextWrapping="Wrap">
         </TextBlock>
         <StackPanel Grid.Row="1"
                     Orientation="Horizontal"

+ 8 - 4
MyTests/Pages/CurTestPage.xaml.cs

@@ -25,11 +25,15 @@ namespace MyTests.Pages
 
         private void NextButton_Click(object sender, RoutedEventArgs e)
         {
-            if (AnswerBox.Text == Session.Quest.Answer[Session.CurQuestion])
+            if (AnswerBox.Text.ToLower().Trim() == Session.Quest.Answer[Session.CurQuestion].ToLower().Trim())
                 Session.Points++;
-            //if(Session.CurQuestion-1 == Session.Quest.Answer.Length)
-                
-
+            if(Session.CurQuestion >= Session.OpenedTest.Questions.Count()-1)
+                NavigationService.Navigate(new Pages.ResultTestPage());
+            else
+            {
+                Session.CurQuestion++; 
+                NavigationService.Navigate(new Pages.CurTestPage());
+            }
         }
     }
 }

+ 61 - 13
MyTests/Pages/ProfilePage.xaml

@@ -24,11 +24,24 @@
                 <ColumnDefinition Width="143*"/>
             </Grid.ColumnDefinitions>
 
-            <Image Name="PartImage"
-                   Grid.Column="0"
-                   Margin="10"
-                   Source="/MyTests;component/Resources/StandartImage.png">
-            </Image>
+            <Grid Grid.Column="0">
+                <Grid.RowDefinitions>
+                    <RowDefinition Height="31"/>
+                    <RowDefinition/>
+                </Grid.RowDefinitions>
+                <Label Name="UserName"
+                       FontSize="16"
+                       Content="Имя"
+                       HorizontalAlignment="Center">
+                </Label>
+                <Image Name="ProfileImage"
+                   Grid.Row="1"
+                       Margin="10,0,10,10"
+                   Source="/MyTests;component/Resources/StandartImage.png"
+                   MouseDown="EditImage_Click">
+                </Image>
+            </Grid>
+
 
             <Grid Grid.Column="1"
                   Margin="10"
@@ -46,22 +59,57 @@
                          MinWidth="50">
                 </TextBox>
 
-                <Label Grid.Row="1"
-                       Content="Инфо: "
-                       FontSize="22">
-                </Label>
+                <TextBox Grid.Row="1"
+                       Text="Инфо: "
+                       FontSize="22"
+                         Background="{x:Null}"
+                         BorderBrush="{x:Null}">
+                </TextBox>
             </Grid>
         </Grid>
 
-        <ListBox Grid.Row="1"
-                 Background="{StaticResource color3}"
-                 BorderBrush="{StaticResource color3}">
+        <ListBox Name="TestsListBox"
+                 Grid.Row="1"
+                 Margin="10,0,10,0"
+                 Background="{StaticResource color1}"
+                 BorderBrush="{x:Null}">
+            <ScrollViewer VerticalScrollBarVisibility="Visible"/>
+            <ListBox.ItemTemplate>
+                <DataTemplate>
+                    <Border Width="{Binding Path=ActualWidth, ElementName=TestsListBox}"
+                            Margin="-10,0,0,0"
+                            Height="45"
+                            CornerRadius="10"
+                            Background="{StaticResource color2}"
+                            MouseDown="TestsListBox_Selected">
+                        <StackPanel Orientation="Horizontal">
+                            <Image Width="35"
+                               Height="35"
+                               Margin="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">
+                                    <Run Text="Вопросов: " Foreground="White"/>
+                                    <Run Text="{Binding Questions.Count, Mode=OneTime}" />
+                                </TextBlock>
+                            </StackPanel>
+                        </StackPanel>
+                    </Border>
+                </DataTemplate>
+            </ListBox.ItemTemplate>
         </ListBox>
 
         <Grid Grid.Row="2">
             <StackPanel Orientation="Horizontal" 
                         HorizontalAlignment="Center">
-                <Button Width="120"
+                <Button Visibility="Collapsed"
+                        Width="120"
                         Margin="5,0,5,0"
                         Content="Назад"
                         FontSize="20"

+ 38 - 35
MyTests/Pages/ProfilePage.xaml.cs

@@ -17,48 +17,37 @@ namespace MyTests.Pages
 {
     public partial class ProfilePage : Page
     {
-        public ProfilePage()
+        public static Users user;
+        public ProfilePage(Users _user)
         {
             InitializeComponent();
+            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);
             TestsLoading();
             //EmailBox.Content = cnt.db.Dispatcher.Where(item => item.IdDispatcher == profile.DispatcherId).Select(item => item.Email).FirstOrDefault();
             //PhoneNumBox.Content = "+7(" + phone.Substring(0, 3) + ")" + phone.Substring(3, 3) + "-" + phone.Substring(6, 2) + "-" + phone.Substring(8, 2);
         }
-        private void EditImageButton_Click(object sender, RoutedEventArgs e)
+        private void EditImage_Click(object sender, RoutedEventArgs e)
         {
-            //OpenFileDialog ofd = new OpenFileDialog();
-            //ofd.DefaultExt = ".png";
-            //ofd.Filter = "JPEG Files (*.jpeg)|*.jpeg|PNG Files (*.png)|*.png|JPG Files (*.jpg)|*.jpg";
-            //Nullable<bool> result = ofd.ShowDialog();
-            //if (result == true)
-            //{
-            //    string filename = ofd.FileName;
-            //    ProfileImg.Source = new BitmapImage(new Uri(filename));
-            //    Dispatcher dispatcher = cnt.db.Dispatcher.Where(item => item.IdDispatcher == profile.DispatcherId).FirstOrDefault();
-            //    dispatcher.ProfileImgSource = filename;
-            //    cnt.db.SaveChanges();
-            //}
-        }
-        private void TestsLoading()
-        {
-            foreach (Tests test in cnt.db.Tests.Where(item => item.IdUser == Session.UserId).ToList())
+            if(user == Session.User)
             {
-                try
-                {
-                    BitmapImage img = test.Image == null ?
-                        new BitmapImage(new Uri("../Resources/StandartProfile.png", UriKind.RelativeOrAbsolute)) :
-                        ImagesManip.NewImage(cnt.db.Users.Where(item => item.IdUser == Session.UserId).FirstOrDefault());
-                    AddTest(test.Name, img, cnt.db.Questions.Where(item => item.IdTest == test.IdTest).Count());
-                }
-                catch (Exception ex)
+                BitmapImage image = ImagesManip.SelectImage();
+                if (image != null)
                 {
-                    new ErrorWindow(ex.ToString()).ShowDialog();
+                    ProfileImage.Source = image;
+                    Session.User.Image = ImagesManip.BitmapSourceToByteArray((BitmapSource)ProfileImage.Source);
+                    cnt.db.SaveChanges();
                 }
             }
         }
-        private void AddTest(string name, BitmapImage image, int questCount)
+        private void TestsLoading()
         {
-            //MessageBox.Show($"{name}, quests:, {questCount}");
+            TestsListBox.Items.Clear();
+            TestsListBox.ItemsSource = cnt.db.Tests.Where(item => item.IdUser == user.IdUser).ToList();
         }
 
         private void SaveButton(object sender, RoutedEventArgs e)
@@ -70,11 +59,25 @@ namespace MyTests.Pages
         {
 
         }
-    }
-    class Test
-    {
-        public string Name { get; set; }
-        public Image Image { get; set; }
-        public int QuestionsCount { get; set; }
+        private void TestsListBox_Selected(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();
+            }
+        }
     }
 }

+ 8 - 6
MyTests/Pages/ResultTestPage.xaml

@@ -38,14 +38,16 @@
                     Height="40">
             <Button Content="Посмотреть мои ответы"
                     Width="150"
-                    Margin="10,0,0,0"
-                    Click="Button_Click"/>
-            <Button 
-                    Content="Выход"
+                    Margin="0,0,10,0"
+                    Click="AnswersButton_Click"/>
+            <Button Content="Профиль автора"
+                    Width="150"
+                    Margin="10,0,10,0"
+                    Click="ProfileButton_Click"/>
+            <Button Content="К тестам"
                     Width="150"
                     Margin="10,0,0,0"
-                    Click="NextButton_Click"/>
-
+                    Click="ExitButton_Click"/>
         </StackPanel>
     </Grid>
 </Page>

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

@@ -23,9 +23,18 @@ namespace MyTests.Pages
             ResultTB.Text = $"{Session.Points}/{Session.OpenedTest.Questions.Count}";
         }
 
-        private void Button_Click(object sender, RoutedEventArgs e)
+        private void AnswersButton_Click(object sender, RoutedEventArgs e)
         {
 
         }
+
+        private void ExitButton_Click(object sender, RoutedEventArgs e)
+        {
+            NavigationService.Navigate(new Pages.TestsCatalog());
+        }
+        private void ProfileButton_Click(object sender, RoutedEventArgs e)
+        {
+            NavigationService.Navigate(new Pages.ProfilePage( cnt.db.Users.Where(item => item.IdUser == Session.OpenedTest.IdUser).FirstOrDefault()));
+        }
     }
 }

+ 0 - 1
MyTests/Pages/TestPage.xaml.cs

@@ -42,7 +42,6 @@ namespace MyTests.Pages
                 if (((Questions)TestsListBox.SelectedItem) != null)
                 {
                     MessageBox.Show(((Questions)TestsListBox.SelectedItem).IdQuestion.ToString());
-                    MessageBox.Show($"{(ListBox)TestsListBox.FindName("Testing")}");
                 }
             }
             catch

+ 7 - 6
MyTests/Pages/TestsCatalog.xaml

@@ -9,8 +9,8 @@
       d:DesignWidth="800">
     <Grid Background="{StaticResource color1}">
         <Grid.RowDefinitions>
-            <RowDefinition Height="32*"/>
-            <RowDefinition Height="193*"/>
+            <RowDefinition Height="64"/>
+            <RowDefinition/>
         </Grid.RowDefinitions>
 
         <Border CornerRadius="15" 
@@ -51,7 +51,7 @@
         <ListBox Name="TestsListBox"
                  Grid.Row="1"
                  Background="{StaticResource color1}"
-                 BorderBrush="{Binding TestsListBox}">
+                 BorderBrush="{x:Null}">
             <ScrollViewer VerticalScrollBarVisibility="Visible"/>
             <ListBox.ItemTemplate>
                 <DataTemplate>
@@ -73,9 +73,10 @@
                                     <Label Content="{Binding Name}"/>
                                     <Label Content="{Binding Users.Login}"/>
                                 </StackPanel>
-                                <Label Content="Вопросов: 15"
-                                   Margin="0,-7,0,0">
-                                </Label>
+                                <TextBlock Margin="0,-7,0,0">
+                                    <Run Text="Вопросов: " Foreground="White"/>
+                                    <Run Text="{Binding Questions.Count, Mode=OneTime}" />
+                                </TextBlock>
                             </StackPanel>
                         </StackPanel>
                     </Border>

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

@@ -15,9 +15,6 @@ using System.Windows.Shapes;
 
 namespace MyTests.Pages
 {
-    /// <summary>
-    /// Логика взаимодействия для TestsCatalog.xaml
-    /// </summary>
     public partial class TestsCatalog : Page
     {
         public TestsCatalog()
@@ -32,12 +29,12 @@ namespace MyTests.Pages
         }
         void LoadingTests()
         {
+            TestsListBox.Items.Clear();
             var list = cnt.db.Tests.ToList();
             if (TestNameBox.Text != "Название теста")
                 list = list.Where(item => item.Name == TestNameBox.Text).ToList();
             if (AuthorTestBox.Text != "Автор")
                 list = list.Where(item => item.Users.Login == AuthorTestBox.Text).ToList();
-            TestsListBox.Items.Clear();
             TestsListBox.ItemsSource = list;
         }
 
@@ -52,11 +49,12 @@ namespace MyTests.Pages
                 if (((Tests)TestsListBox.SelectedItem) != null)
                 {
                     Session.OpenedTest = cnt.db.Tests.Where(item => item.IdTest == ((Tests)TestsListBox.SelectedItem).IdTest).FirstOrDefault();
-                    NavigationService.Navigate(new Pages.TestPage(Session.OpenedTest.IdTest));
                     Session.Points = 0;
                     Session.CurQuestion = 0;
-                    Session.Quest.Answer = cnt.db.Questions.Where(item => item.IdTest == Session.OpenedTest.IdTest).Select(item => item.Answer).ToArray();
                     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

+ 5 - 5
MyTests/Session.cs

@@ -8,14 +8,14 @@ namespace MyTests
 {
     class Session
     {
-        public static int UserId = 1; //{ get; set; }
+        public static Users User = cnt.db.Users.Where(item => item.IdUser == 1).FirstOrDefault(); //{ get; set; }
         public static Tests OpenedTest { get; set; }
         public static int Points = 0;
-        public static int CurQuestion = 1;
-        public class Quest
+        public static int CurQuestion = 0;
+        public static class Quest
         {
-            public static string[] Content = new string[OpenedTest.Questions.Count];
-            public static string[] Answer = new string[OpenedTest.Questions.Count];
+            public static string[] Content;
+            public static string[] Answer;
         }
     }
 }

+ 4 - 0
MyTests/Styles/Style.xaml

@@ -21,6 +21,10 @@
     <Style TargetType="Label">
         <Setter Property="Foreground" Value="White"/>
     </Style>
+    
+    <Style TargetType="Run">
+        <Setter Property="Foreground" Value="White"/>
+    </Style>
 
     <Style TargetType="TextBox">
         <Setter Property="Foreground" Value="White"/>