private void ReadyButton_Click(object sender, EventArgs e) { try { Model.ThisAutoModel.Mark.Equals(""); if (ProductYearMaskedTextBox.MaskFull && ColorTextBox.TextLength != 0 && MileAgeTextBox.TextLength != 0 && Convert.ToInt32(ProductYearMaskedTextBox.Text.Remove(5, 2)) <= DateTime.Today.Date.Year && Convert.ToInt32(ProductYearMaskedTextBox.Text.Remove(5, 2)) >= 1700 && DescriptionTextBox.TextLength != 0) { String transmission; if (MechTrRadioButton.Checked) { transmission = "механическая"; } else if (VarTrRadioButton.Checked) { transmission = "вариативная"; } else if (AutTrRadioButton.Checked) { transmission = "автоматическая"; } else { transmission = "роботизированная"; } if (FlagFrom && Model.Automobiles.Count == Model.CarsAmount) { Model.CarsAmount++; } Auto autoautomobile = new Auto(Convert.ToInt32(ProductYearMaskedTextBox.Text.Remove(4, 3)), ColorTextBox.Text, MileAgeTextBox.Text, Model.Automobiles.Count + 1, PhotoPictureBox.Image, transmission, DescriptionTextBox.Text, Model.ThisAutoModel); AutoService service = new AutoService(Model); autoautomobile.ID = service.generateID(); service.automobileRegistration(autoautomobile); MessageBox.Show("Новый автомобиль успешно добавлен.", "", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Close(); } else { if (Convert.ToInt32(ProductYearMaskedTextBox.Text.Remove(5, 2)) > DateTime.Today.Date.Year || Convert.ToInt32(ProductYearMaskedTextBox.Text.Remove(5, 2)) <= 1700) { ErrorProvider.SetError(ProductYearMaskedTextBox, "проверьте введенный год"); } if (ColorTextBox.TextLength == 0) { ColorTextBox.BackColor = Color.IndianRed; } if (MileAgeTextBox.TextLength == 0) { MileAgeTextBox.BackColor = Color.IndianRed; } if (!ProductYearMaskedTextBox.MaskFull) { ProductYearMaskedTextBox.BackColor = Color.IndianRed; } if (PhotoPictureBox.Image == null) { PhotoPictureBox.BackColor = Color.IndianRed; } if (!MechTrRadioButton.Checked && !AutTrRadioButton.Checked && !VarTrRadioButton.Checked && !RobTrRadioButton.Checked) { TransmissionErrorProvider.SetError(TransmissiomLabel, "Выберите тип коробки передач"); } if (DescriptionTextBox.TextLength == 0) { DescriptionTextBox.BackColor = Color.IndianRed; } } } catch (NullReferenceException) { MessageBox.Show("Вы пытаетесь добавить автомобиль несуществующей модели", " ", MessageBoxButtons.OK, MessageBoxIcon.Error); this.Close(); } }