final
This commit is contained in:
@@ -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<Client> allClients = JsonSerializer.Deserialize<List<Client>>(jsonString);
|
||||
|
||||
|
||||
if (allClients != null && allClients.Any(c => c.subscriptionNumber == txtSubscription.Text))
|
||||
{
|
||||
MessageBox.Show("Клиент с таким номером абонемента уже существует!");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user