Parcourir la source

gr692_pva to master

Imagara il y a 2 ans
Parent
commit
0cdfb88a16

+ 1 - 1
MyTests/App.config

@@ -1,4 +1,4 @@
-<?xml version="1.0" encoding="utf-8"?>
+<?xml version="1.0" encoding="utf-8" ?>
 <configuration>
   <configSections>
     <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->

+ 2 - 1
MyTests/App.xaml

@@ -2,7 +2,8 @@
              xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
              xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
              xmlns:local="clr-namespace:MyTests"
-             StartupUri="MainWindow.xaml">
+             StartupUri="RegAuth.xaml">
+
     <Application.Resources>
         <ResourceDictionary Source="Styles/Style.xaml"/>
     </Application.Resources>

+ 16 - 0
MyTests/Authorization.xaml

@@ -0,0 +1,16 @@
+<Page x:Class="MyTests.Authorization"
+      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"
+      mc:Ignorable="d" 
+      d:DesignHeight="450" d:DesignWidth="800"
+      Height="475" Width="475">
+    <Grid>
+        <Button Content="Войти" Margin="0,250,15,0" VerticalAlignment="Top" Width="93" Click="Auth" Height="26" FontSize="18"/>
+        <TextBox x:Name="Login" LostFocus="LostLogin" GotFocus="LoginFocus" Margin="0,150,15,0" TextWrapping="Wrap" Text ="Логин" VerticalAlignment="Top" Width="145" Height="25" FontSize="16" />
+        <PasswordBox x:Name="Password" LostFocus="LostPassword" GotFocus="PasswordFocus" Margin="0,210,15,0" Password ="Password" VerticalAlignment="Top" Width="126"/>
+    </Grid>
+</Page>
+ 

+ 85 - 0
MyTests/Authorization.xaml.cs

@@ -0,0 +1,85 @@
+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
+{
+    public partial class Authorization : Page
+    {
+        public Authorization()
+        {
+            InitializeComponent();
+        }
+
+        private void Auth(object sender, RoutedEventArgs e)
+        {
+            if (!emptiness(Login.Text, Password.Password))
+                MessageBox.Show("Поля не могут быть пустыми.");
+            else if (Connection.db.Users.Select(item => item.Login + item.Password).Contains(Login.Text + Password.Password))
+            {
+                Session.UserId = Connection.db.Users.First(item => item.Login == Login.Text).IdUsers;
+                MessageBox.Show("КУКУ");
+            }
+            else
+                MessageBox.Show("Неверный логин или пароль");
+        }
+
+        private void LoginFocus(object sender, RoutedEventArgs e)
+        {
+            Login.Text = "";
+        }
+
+        private void LostLogin(object sender, RoutedEventArgs e)
+        {
+            if (Login.Text.Trim() == "")
+                Login.Text = "Логин";
+        }
+
+        private void PasswordFocus(object sender, RoutedEventArgs e)
+        {
+            Password.Password = "";
+        }
+
+        private void LostPassword(object sender, RoutedEventArgs e)
+        {
+            if(Password.Password.Trim() == "")
+            Password.Password = "123456";
+        }
+
+        public bool emptiness(string login, string password) //Проверка на пустоту
+        {
+            if (login == "" || password == "")
+                return false;
+            else
+                return true;
+        }
+
+        public bool LoginTestEptiness(string login) //Проверка на пустоту
+        {
+            if (login == "")
+                return false;
+            else
+                return true;
+        }
+
+        public bool PasswordTestEptiness(string password) //Проверка на пустоту
+        {
+            if (password == "")
+                return false;
+            else
+                return true;
+        }
+    }
+}

+ 13 - 0
MyTests/Connection.cs

@@ -0,0 +1,13 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace MyTests
+{
+    public class Connection
+    {
+        public static MyTestsEntities db = new MyTestsEntities();
+    }
+}

+ 5 - 5
MyTests/EDM.edmx

@@ -259,7 +259,7 @@
     </edmx:ConceptualModels>
     <!-- C-S mapping content -->
     <edmx:Mappings>
-    <Mapping Space="C-S" xmlns="http://schemas.microsoft.com/ado/2009/11/mapping/cs">
+      <Mapping Space="C-S" xmlns="http://schemas.microsoft.com/ado/2009/11/mapping/cs">
   <EntityContainerMapping StorageEntityContainer="MyTestsDataBaseModelStoreContainer" CdmEntityContainer="MyTestsDataBaseEntities">
     <EntitySetMapping Name="Questions">
       <EntityTypeMapping TypeName="IsTypeOf(MyTestsDataBaseModel.Questions)">
@@ -281,15 +281,15 @@
         </MappingFragment>
       </EntityTypeMapping>
     </EntitySetMapping>
-    <EntitySetMapping Name="Users">
+          <EntitySetMapping Name="Users">
       <EntityTypeMapping TypeName="IsTypeOf(MyTestsDataBaseModel.Users)">
-        <MappingFragment StoreEntitySet="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="Image" ColumnName="Image" />
         </MappingFragment>
       </EntityTypeMapping>
     </EntitySetMapping>
@@ -314,7 +314,7 @@
               </MappingFragment>
             </EntityTypeMapping>
           </EntitySetMapping>
-  </EntityContainerMapping>
+        </EntityContainerMapping>
 </Mapping></edmx:Mappings>
   </edmx:Runtime>
   <!-- EF Designer content (DO NOT EDIT MANUALLY BELOW HERE) -->

+ 5 - 0
MyTests/MainWindow.xaml.cs

@@ -63,5 +63,10 @@ namespace MyTests
         {
             //MainFrame.Content = new СatalogPage();
         }
+
+        private void XEXE_TextChanged(object sender, TextChangedEventArgs e)
+        {
+
+        }
     }
 }

+ 25 - 0
MyTests/RegAuth.xaml

@@ -0,0 +1,25 @@
+<Window x:Class="MyTests.RegAuth"
+        ResizeMode="NoResize" WindowStyle="SingleBorderWindow"
+        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
+        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
+        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
+        xmlns:local="clr-namespace:MyTests"
+        mc:Ignorable="d"
+        Title="RegAuth" Height="475" Width="475">
+    <Grid>
+        <Grid.RowDefinitions>
+            <RowDefinition Height="50*"/>
+            <RowDefinition Height="25*"/>
+        </Grid.RowDefinitions>
+        <StackPanel Grid.Row="1" Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center">
+            <Button Content="Регистрация" Width="140" Height="75" FontSize="20" Margin="40, 0, 40, 0" Click="WindowRegistration"></Button>
+            <Button Content="Вход"  Width="140" Height="75" FontSize="25" Margin="40, 0, 40, 0" Click="WindowEntry"></Button>
+        </StackPanel>
+        <Frame
+            Name="MainFrame"
+            NavigationUIVisibility="Hidden"
+            Grid.Row="0">
+        </Frame>
+    </Grid>
+</Window>

+ 32 - 0
MyTests/RegAuth.xaml.cs

@@ -0,0 +1,32 @@
+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.Imaging;
+using System.Windows.Shapes;
+
+namespace MyTests
+{
+    public partial class RegAuth : Window
+    {
+        public RegAuth()
+        {
+            InitializeComponent();
+        }
+
+        private void WindowRegistration(object sender, RoutedEventArgs e) //Регистрация
+        {
+            MainFrame.Content = new Registration();
+        }
+        private void WindowEntry(object sender, RoutedEventArgs e) //Авторизация
+        {
+            MainFrame.Content = new Authorization();
+        }
+    }
+}

+ 18 - 0
MyTests/Registration.xaml

@@ -0,0 +1,18 @@
+<Page x:Class="MyTests.Registration"
+      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"
+      mc:Ignorable="d" 
+      d:DesignHeight="450" d:DesignWidth="800"
+      Title="Registration" Height="475" Width="475">
+
+    <Grid>
+        <TextBox x:Name="Login" LostFocus="LoginLostFocus" GotFocus="LoginFocus" HorizontalAlignment="Center" Height="30" Margin="174,19,175,0" TextWrapping="Wrap" Text="Логин" VerticalAlignment="Top" Width="126" TextAlignment="Center" FontSize="14"/>
+        <TextBox x:Name="Password" LostFocus="PasswordLostFocus" GotFocus="PasswordFocus" HorizontalAlignment="Center" Height="30" Margin="174,72,175,0" TextWrapping="Wrap" Text="Пароль" VerticalAlignment="Top" Width="126" TextAlignment="Center" FontSize="14"/>
+        <TextBox x:Name="Email" LostFocus="EmailLostFocus" GotFocus="EmailNameFocus" HorizontalAlignment="Center" Height="30" Margin="174,122,175,0" TextWrapping="Wrap" Text="Почта" VerticalAlignment="Top" Width="126" TextAlignment="Center" FontSize="14"/>
+        <TextBox x:Name="Info" LostFocus="InfoLostFocus" GotFocus="InfoNameFocus" HorizontalAlignment="Center" Height="43" Margin="174,171,175,0" TextWrapping="Wrap" Text="Личная информация" VerticalAlignment="Top" Width="126" TextAlignment="Center" FontSize="14"/>
+        <Button Content="Сохранить" HorizontalAlignment="Center" Margin="174,234,175,0" VerticalAlignment="Top" Width="126" Click="Save" Height="43" FontSize="15"/>
+    </Grid>
+</Page>

+ 120 - 0
MyTests/Registration.xaml.cs

@@ -0,0 +1,120 @@
+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;
+using System.Text.RegularExpressions;
+
+namespace MyTests
+{
+    public partial class Registration : Page
+    {
+        public Registration()
+        {
+            InitializeComponent();
+        }
+
+        private void Save(object sender, RoutedEventArgs e)
+        {
+            try
+            {
+                if (Login.Text == "" || Password.Text == "")
+                    MessageBox.Show("Поля не могут быть пустыми.");
+                else if (RegistrLogin(Login.Text))
+                    MessageBox.Show("Данный логин уже занят");
+                else
+                {
+                    try
+                    {
+                        Users newUser = new Users()
+                        {
+                            IdUsers = Connection.db.Users.Select(p => p.IdUsers).DefaultIfEmpty(0).Max() + 1,
+                            Login = Login.Text,
+                            Password = Password.Text,
+                            Email = Email.Text,
+                            Info = Info.Text
+                        };
+                        Connection.db.Users.Add(newUser);
+                        Connection.db.SaveChanges();
+                        MessageBox.Show("Вы успешно зарегистрировались");
+                        Session.UserId = Connection.db.Users.Select(item => item.IdUsers).Max();
+                        MainWindow RegAuth = new MainWindow();
+                        RegAuth.Show();
+                    }
+                    catch (Exception ex)
+                    {
+                        MessageBox.Show(ex.ToString());
+                    }
+                }
+            }
+            catch (Exception ex)
+            {
+                MessageBox.Show(ex.ToString());
+            }
+
+        }
+
+        public bool RegistrLogin(string Login)
+        {
+            //if (Connection.db.Users.Select(item => item.Login).Contains(Login))
+            //    return true;
+            //else
+                return false;
+        }
+
+        #region  FOCUS 
+        private void LoginFocus(object sender, RoutedEventArgs e)
+        {
+            Login.Text = "";
+        }
+
+        private void LoginLostFocus(object sender, RoutedEventArgs e)
+        {
+            if (Login.Text.Trim() == "")
+                Login.Text = "Логин";
+        }
+
+        private void PasswordFocus(object sender, RoutedEventArgs e)
+        {
+            Password.Text = "";
+        }
+
+        private void PasswordLostFocus(object sender, RoutedEventArgs e)
+        {
+            if (Password.Text.Trim() == "")
+                Password.Text = "123456";
+        }
+
+        private void EmailNameFocus(object sender, RoutedEventArgs e)
+        {
+            Email.Text = "";
+        }
+
+        private void EmailLostFocus(object sender, RoutedEventArgs e)
+        {
+            if (Email.Text.Trim() == "")
+                Email.Text = "Почта";
+        }
+
+        private void InfoNameFocus(object sender, RoutedEventArgs e)
+        {
+            Info.Text = "";
+        }
+
+        private void InfoLostFocus(object sender, RoutedEventArgs e)
+        {
+            if (Info.Text.Trim() == "")
+                Info.Text = "Личная информация";
+        }
+        #endregion
+    }
+}

+ 1 - 1
MyTests/Session.cs

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

+ 4 - 4
MyTests/Styles/Style.xaml

@@ -5,11 +5,11 @@
     <SolidColorBrush x:Key="TextColor" 
                      Color="White">
     </SolidColorBrush>
-    
+
     <SolidColorBrush x:Key="color1" 
                      Color="#32353B">
     </SolidColorBrush>
-    
+
     <SolidColorBrush x:Key="color2" 
                      Color="#2F3136">
     </SolidColorBrush>
@@ -21,7 +21,7 @@
     <Style TargetType="Label">
         <Setter Property="Foreground" Value="White"/>
     </Style>
-    
+
     <Style TargetType="Run">
         <Setter Property="Foreground" Value="White"/>
     </Style>
@@ -42,7 +42,7 @@
         <Setter Property="Foreground" Value="White"/>
         <Setter Property="Background" Value="{x:Null}"/>
     </Style>
-    
+
 
     <Style TargetType="ComboBox">
         <Setter Property="Foreground" Value="White"/>