Browse Source

проверки на заполненногсть полей, сохранение данных - новый концерт, день репетиций

Liza Smerdova 7 months ago
parent
commit
58cd93fe2b

+ 64 - 0
LibraryRDK/InputValidation.cs

@@ -24,6 +24,17 @@ namespace LibraryRDK
             }
         }
 
+        public static bool PatternNumbers(string text) 
+        {
+            string pattern = @"8\d{10}$";
+            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))
@@ -44,5 +55,58 @@ namespace LibraryRDK
                 return false;
             }
         }
+
+        public static bool CheckUsers(string name, string surname, string patronymis, string number, int power, int post)
+        {
+            if (!string.IsNullOrWhiteSpace(name))
+            {
+                if (!string.IsNullOrWhiteSpace(surname))
+                {
+                    if (!string.IsNullOrWhiteSpace(patronymis))
+                    {
+                        if (!string.IsNullOrWhiteSpace(number))
+                        {
+                            if(power >= 0)
+                            {
+                                if(post >= 0)
+                                {
+                                    return true;
+                                }
+                                else
+                                {
+                                    MessageBox.Show("Выберите Должность", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
+                                    return false;
+                                }
+                            }
+                            else
+                            {
+                                MessageBox.Show("Выберите Права", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
+                                return false;
+                            }
+                        }
+                        else
+                        {
+                            MessageBox.Show("Заполните Номер", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
+                            return false;
+                        }
+                    }
+                    else
+                    {
+                        MessageBox.Show("Заполните Отчество", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
+                        return false;
+                    }
+                }
+                else
+                {
+                    MessageBox.Show("Заполните Фамилию", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
+                    return false;
+                }
+            }
+            else
+            {
+                MessageBox.Show("Заполните Имя", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
+                return false;
+            }
+        }
     }
 }

+ 1 - 1
PDK_Concert/App.config

@@ -8,7 +8,7 @@
     <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
   </startup>
   <connectionStrings>
-    <add name="sm_RDKEntities" connectionString="metadata=res://*/ModelBD.csdl|res://*/ModelBD.ssdl|res://*/ModelBD.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=ngknn.ru;initial catalog=sm_RDK;persist security info=True;user id=21P;password=12357;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />
+    <add name="sm_RDKEntities" connectionString="metadata=res://*/ModelBD.csdl|res://*/ModelBD.ssdl|res://*/ModelBD.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=sql.ngknn.local;initial catalog=sm_RDK;persist security info=True;user id=21P;password=12357;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />
   </connectionStrings>
   <entityFramework>
     <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">

+ 31 - 3
PDK_Concert/Pages/AddConcertPage.xaml.cs

@@ -29,17 +29,45 @@ namespace PDK_Concert.Pages
 
         private void plis_Click(object sender, RoutedEventArgs e)
         {
-
+            int numUpdate;
+            if(tbNumbers.Text=="")
+            {
+                numUpdate = 0;
+            }
+            else
+            {
+                numUpdate = Int32.Parse(tbNumbers.Text);
+            }
+            numUpdate++;
+            tbNumbers.Text = numUpdate.ToString();
         }
 
         private void minus_Click(object sender, RoutedEventArgs e)
         {
-
+            int numUpdate;
+            if (tbNumbers.Text == "")
+            {
+                numUpdate = 0;
+            }
+            else
+            {
+                numUpdate = Int32.Parse(tbNumbers.Text);
+                numUpdate--;
+                tbNumbers.Text = numUpdate.ToString();
+            }
+            
         }
 
         private void add_Click(object sender, RoutedEventArgs e)
         {
-
+            Concert concert = new Concert() 
+            {
+                ConcertDate = (DateTime)dpDate.SelectedDate,
+                Titlee = tbTitle.Text,
+                NumderOfRooms = Int32.Parse(tbNumbers.Text)
+            };
+            Classes.DataBaseClass.connect.Concert.Add(concert);
+            Classes.DataBaseClass.connect.SaveChanges();
         }
 
         private void back_Click(object sender, RoutedEventArgs e)

+ 2 - 2
PDK_Concert/Pages/AddUserPage.xaml

@@ -36,8 +36,8 @@
             <GroupBox Header="Номер телефона">
                 <TextBox Name="tbNunber"/>
             </GroupBox>
-            <GroupBox Header="Должность">
-                <ComboBox FontSize="20" Name="cbPost"/>
+            <GroupBox Header="Должность" ToolTip="89999999999">
+                <ComboBox FontSize="20" Name="cbPost" ToolTip="89999999999"/>
             </GroupBox>
             <GroupBox Header="Права">
                 <ComboBox FontSize="20" Name="cbPower"/>

+ 31 - 17
PDK_Concert/Pages/AddUserPage.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
 {
@@ -31,24 +32,37 @@ namespace PDK_Concert.Pages
 
         private void save_Click(object sender, RoutedEventArgs e)
         {
-            Logined logined = new Logined() 
+            if(InputValidation.CheckAuthorization(tbLogin.Text, psPassword.Password))
             {
-                Login = tbLogin.Text,
-                Password = psPassword.Password.GetHashCode()
-            };
-            Classes.DataBaseClass.connect.Logined.Add(logined);
-            Users users = new Users() 
-            {
-                IDUser = logined.ID,
-                Name = tbName.Text,
-                Surname = tbSurname.Text,
-                Patronymic = tbPatronymic.Text,
-                Number = tbNunber.Text,
-                IDPower=cbPower.SelectedIndex+1,
-                IDPost=cbPost.SelectedIndex+1,
-            };
-            Classes.DataBaseClass.connect.Users.Add(users);
-            Classes.DataBaseClass.connect.SaveChanges();
+                if (InputValidation.CheckUsers(tbName.Text, tbSurname.Text, tbPatronymic.Text, tbNunber.Text, cbPower.SelectedIndex, cbPost.SelectedIndex))
+                {
+                    if (InputValidation.PatternNumbers(tbNunber.Text))
+                    {
+                        Logined logined = new Logined()
+                        {
+                            Login = tbLogin.Text,
+                            Password = psPassword.Password.GetHashCode()
+                        };
+                        Classes.DataBaseClass.connect.Logined.Add(logined);
+                        Users users = new Users()
+                        {
+                            IDUser = logined.ID,
+                            Name = tbName.Text,
+                            Surname = tbSurname.Text,
+                            Patronymic = tbPatronymic.Text,
+                            Number = tbNunber.Text,
+                            IDPower = cbPower.SelectedIndex + 1,
+                            IDPost = cbPost.SelectedIndex + 1,
+                        };
+                        Classes.DataBaseClass.connect.Users.Add(users);
+                        Classes.DataBaseClass.connect.SaveChanges();
+                    }
+                    else
+                    {
+                        MessageBox.Show("Вы ввели номер телефона не в том виде!\nВведите в формате 89999999999", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
+                    }
+                }
+            }
         }
 
         private void back_Click(object sender, RoutedEventArgs e)

+ 1 - 1
PDK_Concert/Pages/ConcertPage.xaml.cs

@@ -43,7 +43,7 @@ namespace PDK_Concert.Pages
         private void listConcent_SelectionChanged(object sender, SelectionChangedEventArgs e)
         {
             Concert concertProgram = listConcent.SelectedItem as Concert;
-            Classes.FrameClass.menuFrame.Navigate(new ConcertProgramPage(concertProgram.IDConcert, logined,1));
+            Classes.FrameClass.menuFrame.Navigate(new ConcertProgramPage(concertProgram.IDConcert, logined,1,this));
         }
 
         private void btConcert_Click(object sender, RoutedEventArgs e)

+ 11 - 4
PDK_Concert/Pages/ConcertProgramPage.xaml.cs

@@ -26,13 +26,14 @@ namespace PDK_Concert.Pages
         Logined logined;
         int ID;
         int index = 1;
-        public ConcertProgramPage(int IDConcert, Logined logined, int access)
+        Page page;
+        public ConcertProgramPage(int IDConcert, Logined logined, int access, Page page)
         {
             InitializeComponent();
             this.ID = IDConcert;
             numberTitle.ItemsSource = Classes.DataBaseClass.connect.Numbers.Where(x => x.IDUser == logined.ID).ToList();
             numberTitle.DisplayMemberPath = "Title";
-            concertProgramList = Classes.DataBaseClass.connect.ConcertProgram.Where(x => x.IDConcert == IDConcert).OrderBy(x=> x.IndexNumber).ToList();
+            concertProgramList = Classes.DataBaseClass.connect.ConcertProgram.Where(x => x.IDConcert == IDConcert).OrderBy(x => x.IndexNumber).ToList();
             listNumber.ItemsSource = concertProgramList;
             program = Classes.DataBaseClass.connect.Concert.FirstOrDefault(x => x.IDConcert == IDConcert);
             DataContext = program;
@@ -41,12 +42,18 @@ namespace PDK_Concert.Pages
                 not.Visibility = Visibility.Visible;
                 listNumber.Visibility = Visibility.Collapsed;
             }
-            if(access == 0)
+            if (access == 0)
+            {
+                notAccess.Visibility = Visibility.Visible;
+                yesAccess.Visibility = Visibility.Collapsed;
+            }
+            if (logined.Users.IDPower == 1)
             {
                 notAccess.Visibility = Visibility.Visible;
                 yesAccess.Visibility = Visibility.Collapsed;
             }
             this.logined = logined;
+            this.page = page;
         }
 
         private void addNumder_Click(object sender, RoutedEventArgs e)
@@ -97,7 +104,7 @@ namespace PDK_Concert.Pages
 
         private void pastBack_Click(object sender, RoutedEventArgs e)
         {
-            Classes.FrameClass.menuFrame.Navigate(new PastConcertPage(logined));
+            Classes.FrameClass.menuFrame.Navigate(page);
         }
     }
 }

+ 1 - 1
PDK_Concert/Pages/NewDayPehearsalPage.xaml.cs

@@ -35,7 +35,7 @@ namespace PDK_Concert.Pages
                 //сделать проверу на имеющийся элемент
                 RehearsalDate rehearsalDate = new RehearsalDate()
                 {
-                    //RehearsalDate1 = (DateTime)date.Text,
+                    RehearsalDate1 = (DateTime)date.SelectedDate,
                 };
                 Classes.DataBaseClass.connect.RehearsalDate.Add(rehearsalDate);
                 Classes.DataBaseClass.connect.SaveChanges();

+ 1 - 1
PDK_Concert/Pages/PastConcertPage.xaml.cs

@@ -33,7 +33,7 @@ namespace PDK_Concert.Pages
         private void listConcent_SelectionChanged(object sender, SelectionChangedEventArgs e)
         {
             Concert concertProgram = listConcent.SelectedItem as Concert;
-            Classes.FrameClass.menuFrame.Navigate(new ConcertProgramPage(concertProgram.IDConcert, logined,0));
+            Classes.FrameClass.menuFrame.Navigate(new ConcertProgramPage(concertProgram.IDConcert, logined,0, this));
         }
 
         private void back_Click(object sender, RoutedEventArgs e)

+ 2 - 2
PDK_Concert/Pages/ProfilePage.xaml

@@ -20,8 +20,8 @@
             <GroupBox Header="Фамилия">
                 <TextBox Text="{Binding Users.Surname}"/>
             </GroupBox>
-            <GroupBox Header="Номер телефона">
-                <TextBox Text="{Binding Users.Number}"/>
+            <GroupBox Header="Номер телефона" ToolTip="89999999999">
+                <TextBox Text="{Binding Users.Number}" ToolTip="89999999999" Name="tbNumbers"/>
             </GroupBox>
             <GroupBox Header="Должность">
                 <TextBlock Padding="2" Foreground="Black" Background="White" Text="{Binding Users.Post.Title}"/>

+ 10 - 2
PDK_Concert/Pages/ProfilePage.xaml.cs

@@ -13,6 +13,7 @@ using System.Windows.Media;
 using System.Windows.Media.Imaging;
 using System.Windows.Navigation;
 using System.Windows.Shapes;
+using LibraryRDK;
 
 namespace PDK_Concert.Pages
 {
@@ -33,8 +34,15 @@ namespace PDK_Concert.Pages
 
         private void save_Click(object sender, RoutedEventArgs e)
         {
-            MessageBox.Show("Личные данные успешно обновлены", "Информация", MessageBoxButton.OK, MessageBoxImage.Information);
-            DataBaseClass.connect.SaveChanges();
+            if (InputValidation.PatternNumbers(tbNumbers.Text))
+            {
+                MessageBox.Show("Личные данные успешно обновлены", "Информация", MessageBoxButton.OK, MessageBoxImage.Information);
+                DataBaseClass.connect.SaveChanges();
+            }
+            else
+            {
+                MessageBox.Show("Вы ввели номер телефона не в том виде!\nВведите в формате 89999999999", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
+            }
         }
 
         private void back_Click(object sender, RoutedEventArgs e)