Browse Source

добовление работы со временем и проверка полей

Smerdova Liza 6 months ago
parent
commit
24638c2a8d

+ 36 - 1
LibraryRDK/InputValidation.cs

@@ -35,6 +35,20 @@ namespace LibraryRDK
             else { return false; }
         }
 
+        public static bool PatternTimeNumbers(string text)
+        {
+            string pattern = @"\b\d{1,2}\.\d{2}\b|\b\d\.\d{2}\b";
+            Regex regex = new Regex(pattern);
+            if (regex.IsMatch(text))
+            {
+                return true;
+            }
+            else
+            {
+                return false;
+            }
+        }
+
         public static bool CheckAuthorization(string login, string password)
         {
             if (!string.IsNullOrWhiteSpace(login))
@@ -56,7 +70,28 @@ namespace LibraryRDK
             }
         }
 
-        public static bool CheckUsers(string name, string surname, string patronymis, string number, int power, int post)
+        public static bool CheckNumbers(string title, string time)
+        {
+            if (!string.IsNullOrWhiteSpace(title))
+            {
+                if (!string.IsNullOrWhiteSpace(time))
+                {
+                    return true;
+                }
+                else
+                {
+                    MessageBox.Show("Вы не ввели длительность номера", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
+                    return false;
+                }
+            }
+            else
+            {
+                MessageBox.Show("Вы не ввели название номера", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
+                return false;
+            }
+        }
+
+            public static bool CheckUsers(string name, string surname, string patronymis, string number, int power, int post)
         {
             if (!string.IsNullOrWhiteSpace(name))
             {

+ 1 - 1
PDK_Concert/ModelBD.Designer.cs

@@ -1,4 +1,4 @@
-// Создание кода T4 для модели "C:\Users\смердоваев\Source\Repos\RDK_Concert\PDK_Concert\ModelBD.edmx" включено. 
+// Создание кода T4 для модели "C:\Users\whiskas\Source\Repos\RDK_Concert\PDK_Concert\ModelBD.edmx" включено. 
 // Чтобы включить формирование кода прежних версий, измените значение свойства "Стратегия создания кода" конструктора
 // на "Legacy ObjectContext". Это свойство доступно в окне "Свойства", если модель
 // открыта в конструкторе.

+ 3 - 0
PDK_Concert/ModelBD.edmx

@@ -39,6 +39,7 @@
           <Property Name="IDUser" Type="int" Nullable="false" />
           <Property Name="Title" Type="nvarchar(max)" Nullable="false" />
           <Property Name="Description" Type="nvarchar(max)" />
+          <Property Name="TimeNumber" Type="nvarchar" MaxLength="5" />
         </EntityType>
         <EntityType Name="Post">
           <Key>
@@ -308,6 +309,7 @@
           <Property Name="IDUser" Type="Int32" Nullable="false" />
           <Property Name="Title" Type="String" Nullable="false" MaxLength="Max" FixedLength="false" Unicode="true" />
           <Property Name="Description" Type="String" MaxLength="Max" FixedLength="false" Unicode="true" />
+          <Property Name="TimeNumber" Type="String" MaxLength="5" FixedLength="false" Unicode="true" />
           <NavigationProperty Name="ConcertProgram" Relationship="sm_RDKModel.FK_ConcertProgram_Numbers" FromRole="Numbers" ToRole="ConcertProgram" />
           <NavigationProperty Name="Users" Relationship="sm_RDKModel.FK_Numbers_Users" FromRole="Numbers" ToRole="Users" />
         </EntityType>
@@ -499,6 +501,7 @@
           <EntitySetMapping Name="Numbers">
             <EntityTypeMapping TypeName="sm_RDKModel.Numbers">
               <MappingFragment StoreEntitySet="Numbers">
+                <ScalarProperty Name="TimeNumber" ColumnName="TimeNumber" />
                 <ScalarProperty Name="Description" ColumnName="Description" />
                 <ScalarProperty Name="Title" ColumnName="Title" />
                 <ScalarProperty Name="IDUser" ColumnName="IDUser" />

+ 3 - 3
PDK_Concert/ModelBD.edmx.diagram

@@ -8,11 +8,11 @@
         <EntityTypeShape EntityType="sm_RDKModel.Concert" Width="1.5" PointX="5.25" PointY="9.75" />
         <EntityTypeShape EntityType="sm_RDKModel.ConcertProgram" Width="1.5" PointX="7.5" PointY="6.625" />
         <EntityTypeShape EntityType="sm_RDKModel.Logined" Width="1.5" PointX="0.75" PointY="0.75" />
-        <EntityTypeShape EntityType="sm_RDKModel.Numbers" Width="1.5" PointX="5.25" PointY="6.625" />
+        <EntityTypeShape EntityType="sm_RDKModel.Numbers" Width="1.5" PointX="5.25" PointY="6.5" />
         <EntityTypeShape EntityType="sm_RDKModel.Post" Width="1.5" PointX="0.75" PointY="4" />
         <EntityTypeShape EntityType="sm_RDKModel.Power" Width="1.5" PointX="0.75" PointY="7.25" />
-        <EntityTypeShape EntityType="sm_RDKModel.RehearsalDate" Width="1.5" PointX="3" PointY="9" />
-        <EntityTypeShape EntityType="sm_RDKModel.RehearsalSchedule" Width="1.5" PointX="5.25" PointY="3.75" />
+        <EntityTypeShape EntityType="sm_RDKModel.RehearsalDate" Width="1.5" PointX="3" PointY="8" />
+        <EntityTypeShape EntityType="sm_RDKModel.RehearsalSchedule" Width="1.5" PointX="5.25" PointY="2.75" />
         <EntityTypeShape EntityType="sm_RDKModel.Users" Width="1.5" PointX="3" PointY="3.125" />
         <AssociationConnector Association="sm_RDKModel.FK_ConcertProgram_Concert" />
         <AssociationConnector Association="sm_RDKModel.FK_ConcertProgram_Numbers" />

+ 1 - 0
PDK_Concert/Numbers.cs

@@ -24,6 +24,7 @@ namespace PDK_Concert
         public int IDUser { get; set; }
         public string Title { get; set; }
         public string Description { get; set; }
+        public string TimeNumber { get; set; }
     
         [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
         public virtual ICollection<ConcertProgram> ConcertProgram { get; set; }

+ 3 - 0
PDK_Concert/Pages/NewNumberPage.xaml

@@ -14,6 +14,9 @@
             <GroupBox Header="Название номера">
                 <TextBox Name="tbTitle"/>
             </GroupBox>
+            <GroupBox Header="Время номера" ToolTip="00.00 или 0.00">
+                <TextBox Name="tbTime" ToolTip="00.00 или 0.00"/>
+            </GroupBox>
             <GroupBox Header="Описание номера" Height="300">
                 <TextBox TextWrapping="Wrap" Name="tbDescription"/>
             </GroupBox>

+ 19 - 9
PDK_Concert/Pages/NewNumberPage.xaml.cs

@@ -12,6 +12,7 @@ using System.Windows.Media;
 using System.Windows.Media.Imaging;
 using System.Windows.Navigation;
 using System.Windows.Shapes;
+using LibraryRDK;
 
 namespace PDK_Concert.Pages
 {
@@ -29,16 +30,25 @@ namespace PDK_Concert.Pages
 
         private void save_Click(object sender, RoutedEventArgs e)
         {
-            Numbers numbers = new Numbers() 
+            if(InputValidation.CheckNumbers(tbTitle.Text, tbTime.Text)) 
             { 
-                IDUser = logined.ID,
-                Title = tbTitle.Text,
-                Description = tbDescription.Text
-            };
-            Classes.DataBaseClass.connect.Numbers.Add(numbers);
-            Classes.DataBaseClass.connect.SaveChanges();
-            MessageBox.Show("Номер успешно добавлен","Информация", MessageBoxButton.OK, MessageBoxImage.Information);
-            Classes.FrameClass.menuFrame.Navigate(new NumberPage(logined));
+                if (InputValidation.PatternTimeNumbers(tbTime.Text))
+                {
+                    Numbers numbers = new Numbers()
+                    {
+                        IDUser = logined.ID,
+                        Title = tbTitle.Text,
+                        Description = tbDescription.Text,
+                        TimeNumber = tbTime.Text
+                    };
+                    Classes.DataBaseClass.connect.Numbers.Add(numbers);
+                    Classes.DataBaseClass.connect.SaveChanges();
+                    MessageBox.Show("Номер успешно добавлен", "Информация", MessageBoxButton.OK, MessageBoxImage.Information);
+                    Classes.FrameClass.menuFrame.Navigate(new NumberPage(logined));
+                }
+                
+            }
+            
         }
 
         private void back_Click(object sender, RoutedEventArgs e)

+ 4 - 1
PDK_Concert/Pages/UpdateNumberWindow.xaml

@@ -16,7 +16,10 @@
         </Grid.ColumnDefinitions>
         <StackPanel HorizontalAlignment="Center" VerticalAlignment="Center">
             <GroupBox Header="Название номера">
-                <TextBox Text="{Binding Title}"/>
+                <TextBox Text="{Binding Title}" Name="tbTitle"/>
+            </GroupBox>
+            <GroupBox Header="Время номера" ToolTip="00.00 или 0.00">
+                <TextBox Text="{Binding TimeNumber}" ToolTip="00.00 или 0.00" Name="tbTime"/>
             </GroupBox>
             <GroupBox Header="Описание номера" Height="150">
                 <TextBox TextWrapping="Wrap" Text="{Binding Description}"/>

+ 15 - 3
PDK_Concert/Pages/UpdateNumberWindow.xaml.cs

@@ -1,4 +1,5 @@
-using System;
+using LibraryRDK;
+using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Text;
@@ -11,6 +12,7 @@ using System.Windows.Input;
 using System.Windows.Media;
 using System.Windows.Media.Imaging;
 using System.Windows.Shapes;
+using static System.Windows.Forms.VisualStyles.VisualStyleElement.TaskbarClock;
 
 namespace PDK_Concert.Pages
 {
@@ -29,8 +31,18 @@ namespace PDK_Concert.Pages
 
         private void save_Click(object sender, RoutedEventArgs e)
         {
-            Classes.DataBaseClass.connect.SaveChanges();
-            this.Close();
+            if (InputValidation.CheckNumbers(tbTitle.Text, tbTime.Text))
+            {
+                if (InputValidation.PatternTimeNumbers(tbTime.Text))
+                {
+                    Classes.DataBaseClass.connect.SaveChanges();
+                    this.Close();
+                }
+                else
+                {
+                    MessageBox.Show("Вы ввели время номера не в том виде!\nВведите в формате 00.00 или 0.00", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
+                }
+            }
         }
 
         private void delete_Click(object sender, RoutedEventArgs e)

+ 4 - 1
PDK_Concert/Pages/UserPage.xaml.cs

@@ -66,7 +66,10 @@ namespace PDK_Concert.Pages
         {
             notU.Visibility = Visibility.Collapsed;
             Users users = listUsers.SelectedItem as Users;
-            Classes.FrameClass.userFrame.Navigate(new UpdateUsersPage(users.IDUser));
+            if (users != null)
+            {
+                Classes.FrameClass.userFrame.Navigate(new UpdateUsersPage(users.IDUser));
+            }
         }
 
         private void addUsers_Click(object sender, RoutedEventArgs e)