private void DriverLicDateTimePicker_ValueChanged(object sender, EventArgs e) { if ((DriverLicDateTimePicker.Value.Date >= DateTime.Today.Date && DriverLicDateTimePicker.Value.Date <= DateTime.Today.AddYears(10).Date)) { DriverLicErrorProvider.Clear(); } }
private void ReadyButton_Click(object sender, EventArgs e) { if (NameTextBox.TextLength != 0 && SurnameTextBox.TextLength != 0 && FathernameTextBox.TextLength != 0 && (MaleRadioButton.Checked || FemaleRadioButton.Checked) && (18 <= (DateTime.Today.Year - BirthdayDateTimePicker.Value.Year) && (DateTime.Today.Year - BirthdayDateTimePicker.Value.Year) <= 120) && (DriverLicDateTimePicker.Value.Date >= DateTime.Today.Date && DriverLicDateTimePicker.Value.Date <= DateTime.Today.Date.AddYears(10).Date)) { bool sex; if (MaleRadioButton.Checked) { sex = true; } else { sex = false; } Client client = new Client(NameTextBox.Text, SurnameTextBox.Text, FathernameTextBox.Text, sex, BirthdayDateTimePicker.Value.Date, PassportMaskedTextBox.Text, DriverLicDateTimePicker.Value.Date, false, CreationDateTimePicker.Value.Date, ClientListStorage.Clients.Count + 1); client.ID = (new ClientService(client)).generateID(); ClientListService.ClientRegistration(client); MessageBox.Show("Регистрация нового клиента успешно завершена", "", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Close(); } else { if (18 > (DateTime.Today.Year - BirthdayDateTimePicker.Value.Year) || (DateTime.Today.Year - BirthdayDateTimePicker.Value.Year) > 120) { BirthdayErrorProvider.SetError(BirthdayLabel, "Некорректный возраст"); } if (!MaleRadioButton.Checked && !FemaleRadioButton.Checked) { SexErrorProvider.SetError(SexLabel, "Выберете пол"); } if (DriverLicDateTimePicker.Value.Date < DateTime.Today.Date || DriverLicDateTimePicker.Value.Date > DateTime.Today.AddYears(10).Date) { DriverLicErrorProvider.SetError(DriverLicDateTimePicker, "Некорректный срок действия прав"); } } }