Imagara пре 2 година
родитељ
комит
1ec626775e

+ 11 - 8
RaspisKusach/EDM.edmx

@@ -85,10 +85,11 @@
           <Property Name="Login" Type="nvarchar" MaxLength="50" Nullable="false" />
           <Property Name="Password" Type="nvarchar" MaxLength="50" Nullable="false" />
           <Property Name="Email" Type="nvarchar" MaxLength="50" Nullable="false" />
-          <Property Name="Passport" Type="nvarchar" MaxLength="10" />
-          <Property Name="Surname" Type="nvarchar" MaxLength="50" />
-          <Property Name="Name" Type="nvarchar" MaxLength="50" />
-          <Property Name="Patronymic" Type="nvarchar" MaxLength="50" />
+          <Property Name="PhoneNum" Type="nvarchar" MaxLength="11" Nullable="false" />
+          <Property Name="Passport" Type="nvarchar" MaxLength="10" Nullable="false" />
+          <Property Name="Surname" Type="nvarchar" MaxLength="50" Nullable="false" />
+          <Property Name="Name" Type="nvarchar" MaxLength="50" Nullable="false" />
+          <Property Name="Patronymic" Type="nvarchar" MaxLength="50" Nullable="false" />
           <Property Name="Permissions" Type="int" Nullable="false" />
         </EntityType>
         <Association Name="FK_Carriages_Trains">
@@ -371,13 +372,14 @@
           <Property Name="IdUser" Type="Int32" Nullable="false" />
           <Property Name="Login" Type="String" Nullable="false" MaxLength="50" FixedLength="false" Unicode="true" />
           <Property Name="Password" Type="String" Nullable="false" MaxLength="50" FixedLength="false" Unicode="true" />
-          <Property Name="Passport" Type="String" MaxLength="10" FixedLength="false" Unicode="true" />
-          <Property Name="Surname" Type="String" MaxLength="50" FixedLength="false" Unicode="true" />
-          <Property Name="Name" Type="String" MaxLength="50" FixedLength="false" Unicode="true" />
-          <Property Name="Patronymic" Type="String" MaxLength="50" FixedLength="false" Unicode="true" />
+          <Property Name="Passport" Type="String" MaxLength="10" FixedLength="false" Unicode="true" Nullable="false" />
+          <Property Name="Surname" Type="String" MaxLength="50" FixedLength="false" Unicode="true" Nullable="false" />
+          <Property Name="Name" Type="String" MaxLength="50" FixedLength="false" Unicode="true" Nullable="false" />
+          <Property Name="Patronymic" Type="String" MaxLength="50" FixedLength="false" Unicode="true" Nullable="false" />
           <Property Name="Permissions" Type="Int32" Nullable="false" />
           <NavigationProperty Name="Tickets" Relationship="RouteScheduleDataBaseModel.FK_Tickets_Users" FromRole="Users" ToRole="Tickets" />
           <Property Name="Email" Type="String" Nullable="false" MaxLength="50" FixedLength="false" Unicode="true" />
+          <Property Name="PhoneNum" Type="String" Nullable="false" MaxLength="11" FixedLength="false" Unicode="true" />
         </EntityType>
         <Association Name="FK_Carriages_Trains">
           <End Type="RouteScheduleDataBaseModel.Trains" Role="Trains" Multiplicity="1" />
@@ -564,6 +566,7 @@
           <EntitySetMapping Name="Users">
             <EntityTypeMapping TypeName="RouteScheduleDataBaseModel.Users">
               <MappingFragment StoreEntitySet="Users">
+                <ScalarProperty Name="PhoneNum" ColumnName="PhoneNum" />
                 <ScalarProperty Name="Email" ColumnName="Email" />
                 <ScalarProperty Name="Permissions" ColumnName="Permissions" />
                 <ScalarProperty Name="Patronymic" ColumnName="Patronymic" />

+ 14 - 20
RaspisKusach/Functions.cs

@@ -52,17 +52,16 @@ namespace RaspisKusach
         // Получение количества свободных мест в вагоне
         public static int GetAvailableSeats(Carriages carriage)
         {
-            //temp
-            return 0;
+            return carriage.Places - cnt.db.Tickets.Where(item => item.IdCarriage == carriage.IdCarriage).Count();
         }
 
-        // Валидация номера телефона
-        public static bool IsPhoneNumberCorrect(string phoneNumber)
+        // Проверка на необходимую длину и содержание только цифр
+        public static bool IsOnlyDigitsAndLengthCorrect(string str, int length)
         {
-            foreach (char c in phoneNumber)
+            foreach (char c in str.Trim())
                 if (!char.IsDigit(c))
                     return false;
-            if (phoneNumber.Length != 11)
+            if (str.Length != length)
                 return false;
             return true;
         }
@@ -77,11 +76,6 @@ namespace RaspisKusach
         {
             return cnt.db.Users.Select(item => item.Email).Contains(Email);
         }
-        // Валидация дня рождения
-        public static bool IsDateOfBirthdayCorrect(DateTime Date)
-        {
-            return Date <= DateTime.Now;
-        }
         // Валидация логина и пароля при входе
         public static bool IsLogAndPassCorrect(string login, string password)
         {
@@ -92,10 +86,10 @@ namespace RaspisKusach
         {
             return login != password;
         }
-        // Валидация логина и пароля
-        public static bool IsLengthCorrect(string str)
+        // Проверка на необходимую длину строки
+        public static bool IsMinLengthCorrect(string str, int minLength)
         {
-            return str.Trim().Length >= 5;
+            return str.Trim().Length >= minLength;
         }
         // Проверка на правильность введеных данных при входе
         public static bool LoginCheck(string login, string password)
@@ -109,7 +103,7 @@ namespace RaspisKusach
         }
         // Преобразует из "string" в "String"
         public static string ToUlower(string str)
-        { 
+        {
             return str.Substring(0, 1).ToUpper() + str.Substring(1, str.Length);
         }
         // Получение всех станций в маршруте в виде строки
@@ -121,11 +115,11 @@ namespace RaspisKusach
             return stationsList;
         }
 
-        //// Проверка на уникальность номера телефона
-        //public static bool IsPhoneNumberAlreadyTaken(string Phone)
-        //{
-        //    return cnt.db.Users.Select(item => item.).Contains(Phone);
-        //}
+        // Проверка на уникальность номера телефона
+        public static bool IsPhoneNumberAlreadyTaken(string Phone)
+        {
+            return cnt.db.Users.Select(item => item.PhoneNum).Contains(Phone);
+        }
 
         //Кодирование картинки
         public static byte[] BitmapSourceToByteArray(BitmapSource image)

+ 28 - 1
RaspisKusach/Pages/RegisterPage.xaml

@@ -65,7 +65,7 @@
                                  Width="240"
                                  FontSize="20"/>
                     </StackPanel>
-
+                    
                     <StackPanel Name="RegB"
                                 Visibility="Collapsed"
                                 Orientation="Vertical"
@@ -93,6 +93,33 @@
                                  FontSize="20"/>
                     </StackPanel>
                     
+                    <StackPanel Name="RegC"
+                                Visibility="Collapsed"
+                                Orientation="Vertical"
+                                Margin="10"
+                                VerticalAlignment="Center"
+                                HorizontalAlignment="Center">
+                        <Label Content="Номер телефона:" 
+                               HorizontalContentAlignment="Left"
+                               Height="40" 
+                               Width="240"
+                               FontSize="20"/>
+                        <TextBox Name="PhoneBox" 
+                             TextWrapping="Wrap" 
+                             Height="40" 
+                             Width="240"
+                             FontSize="20"/>
+                        <Label Content="Паспорт:"
+                           HorizontalContentAlignment="Left"
+                           Height="40" 
+                           Width="240"
+                           FontSize="20"/>
+                        <TextBox Name="PassportBox"
+                                 Height="40" 
+                                 Width="240"
+                                 FontSize="20"/>
+                    </StackPanel>
+                    
                     <StackPanel Orientation="Horizontal"
                                 Grid.Row="1"
                                 VerticalAlignment="Center"

+ 68 - 47
RaspisKusach/Pages/RegisterPage.xaml.cs

@@ -22,55 +22,76 @@ namespace RaspisKusach.Pages
         {
             try
             {
-                if (registerStage == 1)
-                {
-                    if (!Functions.IsLengthCorrect(LogBox.Text))
-                        new ErrorWindow("Поле «Логин» должно содержать не менее 5 символов.").Show();
-                    else if (!Functions.IsLengthCorrect(PassBox.Password))
-                        new ErrorWindow("Поле «Пароль» должно содержать не менее 5 символов.").Show();
-                    else if (!Functions.IsLogEqualPass(LogBox.Text, PassBox.Password))
-                        new ErrorWindow("Поля «Логин» и «Пароль» не должны быть равны.").Show();
-                    else if (Functions.IsLoginAlreadyTaken(LogBox.Text))
-                        new ErrorWindow("Данный логин уже занят").Show();
-                    else
-                    {
-                        RegA.Visibility = Visibility.Collapsed;
-                        RegB.Visibility = Visibility.Visible;
-                        registerStage = 2;
-                        RegisterButton.Content = "Регистрация";
-                    }
-                }
-                else
+                string[] fio = new string[3];
+
+                switch (registerStage)
                 {
-                    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
-                    {  
-                        Users newUser = new Users()
+                    case 1:
+                        if (!Functions.IsMinLengthCorrect(LogBox.Text, 5))
+                            new ErrorWindow("Поле «Логин» должно содержать не менее 5 символов.").Show();
+                        else if (!Functions.IsMinLengthCorrect(PassBox.Password, 5))
+                            new ErrorWindow("Поле «Пароль» должно содержать не менее 5 символов.").Show();
+                        else if (!Functions.IsLogEqualPass(LogBox.Text, PassBox.Password))
+                            new ErrorWindow("Поля «Логин» и «Пароль» не должны быть равны.").Show();
+                        else if (Functions.IsLoginAlreadyTaken(LogBox.Text))
+                            new ErrorWindow("Данный логин уже занят").Show();
+                        else
+                        {
+                            RegA.Visibility = Visibility.Collapsed;
+                            RegB.Visibility = Visibility.Visible;
+                            RegC.Visibility = Visibility.Collapsed;
+                            registerStage = 2;
+                        }
+                        break;
+                    case 2:
+                        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.IsMinLengthCorrect(fio[0], 2)
+                            || !Functions.IsMinLengthCorrect(fio[1], 2)
+                            || !Functions.IsMinLengthCorrect(fio[2], 2))
+                            new ErrorWindow("Поле ФИО введено неверно.").Show();
+                        else
+                        {
+                            RegA.Visibility = Visibility.Collapsed;
+                            RegB.Visibility = Visibility.Collapsed;
+                            RegC.Visibility = Visibility.Visible;
+                            registerStage = 3;
+                            RegisterButton.Content = "Регистрация";
+                        }
+                        break;
+                    case 3:
+                        if (!Functions.IsOnlyDigitsAndLengthCorrect(PhoneBox.Text, 11))
+                            new ErrorWindow("Номер телефона введен неверно.").Show();
+                        else if (!Functions.IsPhoneNumberAlreadyTaken(PhoneBox.Text))
+                            new ErrorWindow("Номер телефона уже используется.").Show();
+                        else if (!Functions.IsOnlyDigitsAndLengthCorrect(PassportBox.Text, 10))
+                            new ErrorWindow("Паспорт введен неверно.").Show();
+                        else
                         {
-                            IdUser = cnt.db.Users.Select(p => p.IdUser).DefaultIfEmpty(0).Max() + 1,
-                            Login = LogBox.Text,
-                            Password = Encrypt.GetHash(PassBox.Password),
-                            Email = EmailBox.Text,
-                            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());
-                    }
+                            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 = 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());
+                        }
+                        break;
+                    default:
+                        new ErrorWindow("Ошибка.").Show();
+                        break;
                 }
             }
             catch

+ 1 - 1
RaspisKusach/Pages/TripInfoPage.xaml

@@ -116,7 +116,7 @@
                                 </Grid.ColumnDefinitions>
                                 <StackPanel>
                                     <Label Content="Свободно мест: "/>
-                                    <Label Content="10"/>
+                                    <Label Content="{Binding AvailableSeats}"/>
                                 </StackPanel>
                                 <StackPanel Grid.Column="1">
                                     <Label Content="Класс: "/>

+ 3 - 1
RaspisKusach/Pages/TripInfoPage.xaml.cs

@@ -26,7 +26,8 @@ namespace RaspisKusach.Pages
                 routeList.Add(new CarriageClass()
                 {
                     Carriage = item,
-                    CarriageNum = carrNum
+                    CarriageNum = carrNum,
+                    AvailableSeats = Functions.GetAvailableSeats(item)
                 });
                 carrNum++;
             }
@@ -37,6 +38,7 @@ namespace RaspisKusach.Pages
         {
             public Carriages Carriage { get; set; }
             public int CarriageNum { get; set; }
+            public int AvailableSeats { get; set; }
         }
 
     }

+ 2 - 4
RaspisKusach/Styles/Style.xaml

@@ -1,7 +1,7 @@
 <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
     
-    <SolidColorBrush x:Key="TextColor" 
+    <SolidColorBrush x:Key="ButtonTextColor" 
                      Color="Black">
     </SolidColorBrush>
 
@@ -99,9 +99,7 @@
                 </ControlTemplate>
             </Setter.Value>
         </Setter>
-        <Setter Property="Foreground" Value="{StaticResource TextColor}"/>
+        <Setter Property="Foreground" Value="{StaticResource ButtonTextColor}"/>
     </Style>
     
-    
-
 </ResourceDictionary>

+ 1 - 0
RaspisKusach/Users.cs

@@ -29,6 +29,7 @@ namespace RaspisKusach
         public string Patronymic { get; set; }
         public int Permissions { get; set; }
         public string Email { get; set; }
+        public string PhoneNum { get; set; }
     
         [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
         public virtual ICollection<Tickets> Tickets { get; set; }

+ 3 - 3
RaspisKusach/todo.txt

@@ -1,6 +1,6 @@
-Подредактировать регистрацию + вход
-Добавить проверку на фио
-Добавить авто форматирование фио
+Подредактировать регистрацию + вход
+Добавить проверку на фио
+Добавить авто форматирование фио
 ✘Добавить возможность покупки билетов
 ✘Добавить Админ меню(?)
 ✘Сделать юнит тесты