private void BackButton_Click(object sender, RoutedEventArgs e) { var CitiesWindow = new CitiesSelection(Country); CitiesWindow.Show(); Close(); }
private void Confirm_Click(object sender, RoutedEventArgs e) { bool correct = true; string pattern = @"^[a-zA-Zа-яА-ЯёЁ]+( ?-? ?[a-zA-Zа-яА-ЯёЁ]+)*$"; Regex regex = new Regex(pattern); if (String.IsNullOrEmpty(NameInput.Text)) { MessageBox.Show("Введите название"); correct = false; } else if (!int.TryParse(TotalInput.Text, out int res) || int.Parse(TotalInput.Text) <= 0) { MessageBox.Show("Население должно быть целым положительным числом"); TotalInput.Text = "0"; correct = false; } else if (!int.TryParse(IllInput.Text, out int res2) || int.Parse(IllInput.Text) < 0) { MessageBox.Show("Количество больных должно быть целым неотрицательным числом"); IllInput.Text = "0"; correct = false; } else if (!int.TryParse(ImmuneInput.Text, out int res3) || int.Parse(ImmuneInput.Text) < 0) { MessageBox.Show("Количество привитых должно быть целым неотрицательным числом"); ImmuneInput.Text = "0"; correct = false; } else if (int.Parse(IllInput.Text) + int.Parse(ImmuneInput.Text) > int.Parse(TotalInput.Text)) { MessageBox.Show("Количество больных + количество привитых не может быть больше общего населения"); correct = false; } else if (!regex.IsMatch(NameInput.Text.ToString())) { MessageBox.Show("Некорректное название города"); correct = false; } if (correct) { Country.Cities[Index].Name = NameInput.Text; Country.Cities[Index].People.Total = int.Parse(TotalInput.Text); Country.Cities[Index].People.Ill = int.Parse(IllInput.Text); Country.Cities[Index].People.ImmuneSchedule[2] = (int)Math.Round(Country.Cities[Index].People.Ill * 0.25, MidpointRounding.AwayFromZero); Country.Cities[Index].People.ImmuneSchedule[3] = (int)Math.Round(Country.Cities[Index].People.Ill * 0.65); Country.Cities[Index].People.ImmuneSchedule[4] = Country.Cities[Index].People.Ill - (int)Math.Round(Country.Cities[Index].People.Ill * 0.25, MidpointRounding.AwayFromZero) - (int)Math.Round(Country.Cities[Index].People.Ill * 0.65); Country.Cities[Index].People.Vaccinated = int.Parse(ImmuneInput.Text); Country.Cities[Index].People.Immune = int.Parse(ImmuneInput.Text); Country.Cities[Index].Traffic = (int)TrafficInput.Value; var CitiesWindow = new CitiesSelection(Country); CitiesWindow.Show(); Close(); } }
private void OkButton_Click(object sender, RoutedEventArgs e) { bool correct = true; string namePattern = @"^[a-zA-Zа-яА-ЯёЁ]+( ?-? ?[a-zA-Zа-яА-ЯёЁ]+)*$"; string deseasePattern = @"^[a-zA-Zа-яА-ЯёЁ0-9]+( ?-? ?[a-zA-Zа-яА-ЯёЁ0-9]+)*$"; Regex nameRegex = new Regex(namePattern); Regex deseaseRegex = new Regex(deseasePattern); if (string.IsNullOrEmpty(CountryNameInput.Text.ToString()) || string.IsNullOrEmpty(DiseaseNameInput.Text.ToString())) { MessageBox.Show("Введите название"); correct = false; } else if (MonthInput.SelectedIndex == -1) { MessageBox.Show("Выберите месяц"); correct = false; } else if (!int.TryParse(MoneyInput.Text, out int result) || int.Parse(MoneyInput.Text) <= 0) { MessageBox.Show("Размер денежного фонда должен быть целым положительным числом"); MoneyInput.Text = "0"; correct = false; } else if (!int.TryParse(VaccineInput.Text, out int result2) || int.Parse(VaccineInput.Text) <= 0) { MessageBox.Show("Стоимость прививки должна быть целым положительным числом"); VaccineInput.Text = "0"; correct = false; } else if (!nameRegex.IsMatch(CountryNameInput.Text.ToString())) { MessageBox.Show("Некорректное название страны"); correct = false; } else if (!deseaseRegex.IsMatch(DiseaseNameInput.Text.ToString())) { MessageBox.Show("Некорректное название заболевания"); correct = false; } if (correct) { Country = new Country(CountryNameInput.Text, DiseaseNameInput.Text, (int)PeriodInput.Value, MonthInput.SelectedIndex, int.Parse(MoneyInput.Text), int.Parse(VaccineInput.Text), (int)CitiesCountInput.Value); for (int i = 0; i < CitiesCountInput.Value; i++) { Country.Cities[i] = new City("", new Population(0, 0, 0, Country.Weeks), 1); } var CitiesWindow = new CitiesSelection(Country); CitiesWindow.Show(); Close(); } }