diff --git a/WpfApp1/WpfApp1/MainWindow.xaml.cs b/WpfApp1/WpfApp1/MainWindow.xaml.cs index b1f355c..2977bea 100644 --- a/WpfApp1/WpfApp1/MainWindow.xaml.cs +++ b/WpfApp1/WpfApp1/MainWindow.xaml.cs @@ -7,6 +7,7 @@ using System.Threading.Tasks; using System.Windows; using System.IO; using System.Text.Json; +using System.Text.Json.Serialization; @@ -52,23 +53,58 @@ namespace WpfApp1 private bool IsValid() { if (string.IsNullOrWhiteSpace(txtSurname.Text) || string.IsNullOrWhiteSpace(txtName.Text) || - string.IsNullOrWhiteSpace(txtPhone.Text) || string.IsNullOrWhiteSpace(txtAddress.Text)) + string.IsNullOrWhiteSpace(txtPhone.Text) || string.IsNullOrWhiteSpace(txtAddress.Text) || + string.IsNullOrWhiteSpace(txtPatronymic.Text)) { MessageBox.Show("Заполните все поля!"); return false; } + string result = char.ToUpper(txtSurname.Text[0]) + txtSurname.Text.Substring(1).ToLower(); + string result1 = char.ToUpper(txtName.Text[0]) + txtName.Text.Substring(1).ToLower(); + string result2 = char.ToUpper(txtPatronymic.Text[0]) + txtPatronymic.Text.Substring(1).ToLower(); - if (dpBirthday.SelectedDate >= DateTime.Now) + txtSurname.Text = result; + txtName.Text = result1; + txtPatronymic.Text = result2; + + DateTime maxAllowedDate = DateTime.Now.AddYears(-14); + if (dpBirthday.SelectedDate == null) { - MessageBox.Show("Дата рождения должна быть меньше текущей!"); + MessageBox.Show("Пожалуйста, выберите дату рождения!"); return false; } - + if (txtPhone.Text.Length != 12) + { + MessageBox.Show("Номер телефона должен состоять из 12 цифр!"); + return false; + } + if (dpBirthday.SelectedDate.Value.Year > maxAllowedDate.Year) + { + MessageBox.Show("Вход доступен только лицам достигших 14 лет!"); + return false; + } + if (!Regex.IsMatch(txtSubscription.Text, @"^\d{8}$")) { MessageBox.Show("Номер абонемента должен состоять из 8 цифр!"); return false; } + else + { + if (File.Exists(FilePath)) + { + string jsonString = File.ReadAllText(FilePath); + List allClients = JsonSerializer.Deserialize>(jsonString); + + + if (allClients != null && allClients.Any(c => c.subscriptionNumber == txtSubscription.Text)) + { + MessageBox.Show("Клиент с таким номером абонемента уже существует!"); + return false; + } + } + } + return true; } diff --git a/WpfApp1/WpfApp1/RecordWindow.xaml.cs b/WpfApp1/WpfApp1/RecordWindow.xaml.cs index 3f25d66..efff681 100644 --- a/WpfApp1/WpfApp1/RecordWindow.xaml.cs +++ b/WpfApp1/WpfApp1/RecordWindow.xaml.cs @@ -72,6 +72,10 @@ namespace WpfApp1 try { + if (!(DateTime.TryParse(txtTime.Text, out DateTime datetime) || datetime > DateTime.Now)) + { + return; + } Entry newEntry = new Entry { Client = _currentClient,