This commit is contained in:
2026-04-04 09:48:25 +05:00
parent f8b8a17882
commit 4e5ad02b06
2 changed files with 44 additions and 4 deletions

View File

@@ -7,6 +7,7 @@ using System.Threading.Tasks;
using System.Windows;
using System.IO;
using System.Text.Json;
using System.Text.Json.Serialization;
@@ -52,15 +53,34 @@ 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;
}
@@ -69,6 +89,22 @@ namespace WpfApp1
MessageBox.Show("Номер абонемента должен состоять из 8 цифр!");
return false;
}
else
{
if (File.Exists(FilePath))
{
string jsonString = File.ReadAllText(FilePath);
List<Client> allClients = JsonSerializer.Deserialize<List<Client>>(jsonString);
if (allClients != null && allClients.Any(c => c.subscriptionNumber == txtSubscription.Text))
{
MessageBox.Show("Клиент с таким номером абонемента уже существует!");
return false;
}
}
}
return true;
}

View File

@@ -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,