Imagara 2 anos atrás
pai
commit
855c6e8e3a

+ 16 - 2
RaspisKusach/Functions.cs

@@ -49,6 +49,7 @@ namespace RaspisKusach
         {
             return cnt.db.RoutesStations.Where(item => item.IdRoute == route.IdRoute).Select(item => item.Stations.Location).FirstOrDefault();
         }
+        // Получение количества свободных мест в вагоне
         public static int GetAvailableSeats(Carriages carriage)
         {
             //temp
@@ -94,7 +95,7 @@ namespace RaspisKusach
         // Валидация логина и пароля
         public static bool IsLengthCorrect(string str)
         {
-            return str.Length >= 5;
+            return str.Trim().Length >= 5;
         }
         // Проверка на правильность введеных данных при входе
         public static bool LoginCheck(string login, string password)
@@ -106,8 +107,21 @@ namespace RaspisKusach
         {
             return cnt.db.Users.Select(item => item.Login).Contains(login);
         }
+        // Преобразует из "string" в "String"
+        public static string ToUlower(string str)
+        { 
+            return str.Substring(0, 1).ToUpper() + str.Substring(1, str.Length);
+        }
+        // Получение всех станций в маршруте в виде строки
+        public static string GetDirection(Routes route)
+        {
+            string stationsList = "";
+            foreach (RoutesStations rs in cnt.db.RoutesStations.Where(item => item.IdRoute == route.IdRoute))
+                stationsList += rs.Stations.Location == GetDepartureStationLocation(route) ? rs.Stations.Name : $"{rs.Stations.Name} → ";
+            return stationsList;
+        }
 
-        //// Проверка на уникальность электронной почты
+        //// Проверка на уникальность номера телефона
         //public static bool IsPhoneNumberAlreadyTaken(string Phone)
         //{
         //    return cnt.db.Users.Select(item => item.).Contains(Phone);

+ 2 - 3
RaspisKusach/Pages/AdministrationPage.xaml

@@ -4,8 +4,8 @@
       xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
       xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
       xmlns:local="clr-namespace:RaspisKusach.Pages"
-      mc:Ignorable="d" 
-      d:DesignHeight="367" 
+      mc:Ignorable="d"
+      d:DesignHeight="367"
       d:DesignWidth="792"
       Title="Администратор">
 
@@ -27,7 +27,6 @@
             
             <Button Width="120"
                     Height="40"
-                    
                     Margin="10,0,10,0">
                 <StackPanel Orientation="Horizontal">
                     <Image Width="15" Height="15" Source="/RaspisKusach;component/Resources/Train.png"></Image>

+ 33 - 23
RaspisKusach/Pages/LoginPage.xaml

@@ -8,7 +8,8 @@
       d:DesignHeight="367" 
       d:DesignWidth="792"
       Title="Вход">
-    
+
+
     <Grid>
         <Grid.ColumnDefinitions>
             <ColumnDefinition/>
@@ -30,42 +31,51 @@
                 BorderThickness="2">
             <Grid Style="{x:Null}" 
                   Background="{x:Null}">
-                <Grid Background="Gray"
-                      Opacity="0.85"/>
-                <StackPanel Orientation="Vertical"
-                        Margin="10"
-                        VerticalAlignment="Center"
-                        HorizontalAlignment="Center">
-                    <Label Content="Логин:" 
-                       HorizontalContentAlignment="Left"
-                       Height="40" 
-                       Width="240"
-                       FontSize="20"/>
-                    <TextBox Name="LogBox" 
-                             TextWrapping="Wrap"
+                <Grid Background="#a0a0a0"
+                      Opacity="0.85">
+                </Grid>
+                <Grid>
+                    <Grid.RowDefinitions>
+                        <RowDefinition Height="108*"/>
+                        <RowDefinition Height="37*"/>
+                    </Grid.RowDefinitions>
+
+                    <StackPanel Orientation="Vertical"
+                                Margin="10"
+                                VerticalAlignment="Center"
+                                HorizontalAlignment="Center">
+                        <Label Content="Логин:" 
+                               HorizontalContentAlignment="Left"
+                               Height="40" 
+                               Width="240"
+                               FontSize="20"/>
+                        <TextBox Name="LogBox" 
+                             TextWrapping="Wrap" 
                              Height="40" 
                              Width="240"
                              FontSize="20"/>
-                    <Label Content="Пароль:"
+                        <Label Content="Пароль:"
                            HorizontalContentAlignment="Left"
                            Height="40" 
                            Width="240"
                            FontSize="20"/>
-                    <PasswordBox Name="PassBox"
+                        <PasswordBox Name="PassBox"
                                  Height="40" 
                                  Width="240"
                                  FontSize="20"/>
+                    </StackPanel>
+
                     <StackPanel Orientation="Horizontal"
-                                Margin="0,20,0,0">
-                        <Button Name="RegButton" 
-                                Content="Регистрация"
+                                Grid.Row="1"
+                                VerticalAlignment="Center"
+                                HorizontalAlignment="Center">
+                        <Button Content="Регистрация"
                                 Height="40" 
                                 Width="150" 
                                 Margin="0,0,30,0"
                                 FontSize="20"
                                 Click="RegButton_Click"/>
-                        <Button x:Name="LogButton" 
-                                Content="Вход"
+                        <Button Content="Вход"
                                 Height="40" 
                                 Width="150"
                                 FontSize="20"
@@ -73,8 +83,8 @@
                                 Click="LogButton_Click">
                         </Button>
                     </StackPanel>
-                </StackPanel>
+                </Grid>
             </Grid>
         </Border>
     </Grid>
-</Page>
+</Page>

+ 2 - 16
RaspisKusach/Pages/LoginPage.xaml.cs

@@ -1,23 +1,10 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
+using System.Linq;
 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 RaspisKusach.Pages
 {
-    /// <summary>
-    /// Логика взаимодействия для LoginPage.xaml
-    /// </summary>
     public partial class LoginPage : Page
     {
         bool Test = true;
@@ -36,7 +23,6 @@ namespace RaspisKusach.Pages
             if (Test)
             {
                 Session.User = cnt.db.Users.Where(item => item.IdUser == 1).FirstOrDefault();
-                
                 NavigationService.Navigate(new ProfilePage());
             }
             else
@@ -49,7 +35,7 @@ namespace RaspisKusach.Pages
                         new ErrorWindow("Неверный логин или пароль").Show();
                     else
                     {
-                        //Profile.userId = cnt.db.User.Where(item => item.NickName == LogBox.Text).Select(item => item.Id).FirstOrDefault();
+                        Session.User = cnt.db.Users.Where(item => item.Login == LogBox.Text).FirstOrDefault();
                         NavigationService.Navigate(new MenuPage());
                     }
                 }

+ 1 - 16
RaspisKusach/Pages/MenuPage.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 RaspisKusach.Pages
 {
-    /// <summary>
-    /// Логика взаимодействия для MenuPage.xaml
-    /// </summary>
     public partial class MenuPage : Page
     {
         public MenuPage()

+ 0 - 3
RaspisKusach/Pages/ProfilePage.xaml.cs

@@ -15,9 +15,6 @@ using System.Windows.Shapes;
 
 namespace RaspisKusach.Pages
 {
-    /// <summary>
-    /// Логика взаимодействия для ProfilePage.xaml
-    /// </summary>
     public partial class ProfilePage : Page
     {
         public ProfilePage()

+ 13 - 23
RaspisKusach/Pages/RegisterPage.xaml.cs

@@ -1,23 +1,10 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
+using System.Linq;
 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 RaspisKusach.Pages
 {
-    /// <summary>
-    /// Логика взаимодействия для RegisterPage.xaml
-    /// </summary>
     public partial class RegisterPage : Page
     {
         byte registerStage = 1;
@@ -37,9 +24,9 @@ namespace RaspisKusach.Pages
             {
                 if (registerStage == 1)
                 {
-                    if (!Functions.IsLengthCorrect(LogBox.Text.Trim()))
+                    if (!Functions.IsLengthCorrect(LogBox.Text))
                         new ErrorWindow("Поле «Логин» должно содержать не менее 5 символов.").Show();
-                    else if (!Functions.IsLengthCorrect(PassBox.Password.Trim()))
+                    else if (!Functions.IsLengthCorrect(PassBox.Password))
                         new ErrorWindow("Поле «Пароль» должно содержать не менее 5 символов.").Show();
                     else if (!Functions.IsLogEqualPass(LogBox.Text, PassBox.Password))
                         new ErrorWindow("Поля «Логин» и «Пароль» не должны быть равны.").Show();
@@ -55,29 +42,32 @@ namespace RaspisKusach.Pages
                 }
                 else
                 {
+                    string[] fio = new string[3];
+                    fio = FIOBox.Text.Split(' ');
                     if (!Functions.IsEmailCorrect(EmailBox.Text))
                         new ErrorWindow("Email введен неверно.").Show();
                     else if (Functions.IsEmailAlreadyTaken(EmailBox.Text))
                         new ErrorWindow("Данный email уже используется.").Show();
+                    else if (!Functions.IsLengthCorrect(fio[0])
+                        || !Functions.IsLengthCorrect(fio[1])
+                        || !Functions.IsLengthCorrect(fio[2]))
+                        new ErrorWindow("Поле ФИО введено неверно.").Show();
                     else
-                    {
-                        string[] fio = new string[3];
-                        fio = FIOBox.Text.Split(' ');
+                    {  
                         Users newUser = new Users()
                         {
                             IdUser = cnt.db.Users.Select(p => p.IdUser).DefaultIfEmpty(0).Max() + 1,
                             Login = LogBox.Text,
                             Password = Encrypt.GetHash(PassBox.Password),
                             Email = EmailBox.Text,
-                            Surname = fio[0],
-                            Name = fio[1],
-                            Patronymic = fio[2],
+                            Surname = Functions.ToUlower(fio[0]),
+                            Name = Functions.ToUlower(fio[1]),
+                            Patronymic = Functions.ToUlower(fio[2]),
                             Permissions = cnt.db.Users.Count() == 0 ? 1 : 0,
                         };
                         cnt.db.Users.Add(newUser);
                         cnt.db.SaveChanges();
                         new ErrorWindow("Успешная регистрация").ShowDialog();
-
                         Session.User = cnt.db.Users.Max();
                         NavigationService.Navigate(new ProfilePage());
                     }

+ 1 - 11
RaspisKusach/Pages/SchedulePage.xaml.cs

@@ -1,18 +1,8 @@
 using System;
 using System.Collections.Generic;
-using System.Linq;
 using System.Globalization;
 using System.Threading;
-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 RaspisKusach.Pages
 {
@@ -21,7 +11,7 @@ namespace RaspisKusach.Pages
         public SchedulePage()
         {
             InitializeComponent();
-            TripsListBox.Items.Clear(); // temp
+            TripsListBox.Items.Clear();
             Thread th = new Thread(ThreadUpdate);
             th.Start();
         }

+ 0 - 9
RaspisKusach/Pages/SearchForTicketsPage.xaml.cs

@@ -2,17 +2,9 @@
 using System.Collections.Generic;
 using System.Globalization;
 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 RaspisKusach.Pages
 {
@@ -54,7 +46,6 @@ namespace RaspisKusach.Pages
                     rt.stationArrival = StationArrivalComboBox.Text;
                     rt.timeArrival = Functions.GetArrivalTime(arrivalStation, trip).ToString(new CultureInfo("ru-RU"));
                     rt.timeDeparture = Functions.GetDepartureTime(departureStation, trip).ToString(new CultureInfo("ru-RU"));
-
                     rt.timeBetween = Functions.GetArrivalTime(arrivalStation, trip) - Functions.GetDepartureTime(departureStation, trip);
 
                     routeList.Add(rt);

+ 2 - 20
RaspisKusach/Pages/TripInfoPage.xaml.cs

@@ -1,18 +1,6 @@
-using System;
-using System.Collections.Generic;
-using System.Globalization;
+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 RaspisKusach.Pages
 {
@@ -24,13 +12,7 @@ namespace RaspisKusach.Pages
             InitializeComponent();
             trip = _trip;
 
-            string stationsList = "";
-
-            foreach (RoutesStations rs in cnt.db.RoutesStations.Where(item => item.IdRoute == trip.IdRoute))
-                stationsList += rs.Stations.Location == Functions.GetDepartureStationLocation(trip.Routes) ? rs.Stations.Name : $"{rs.Stations.Name} → ";
-
-            Direction.Content = stationsList;
-
+            Direction.Content = Functions.GetDirection(trip.Routes);
 
             CarriageListBox.Items.Clear();
             UpdateCarriagesList();