private void BtnAddFlight_Click(object sender, EventArgs e) { try { string[] res = tbTimeValue.Text.Replace(" ", "").Split('ч'); int hours = int.Parse(res[0] == "" ? "-1" : res[0]), minutes = int.Parse(res[1].Replace("мин", "") == "" ? "-1" : res[1].Replace("мин", "")); if (hours < 0 || hours > 23) { throw new Exception("В сутках всего 24 часа!"); } if (minutes < 0 || hours > 59) { throw new Exception("В часе всего 60 минут!"); } bool found = false; foreach (PlaneData planeData in planesForContract.GetPanel.Controls) { if (planeData.Check) { foreach (Flight flight in contract.ConnectedFlights) { if (!game.AssignPlaneToContract(planeData.Plane.ID, flight.Number)) { MessageBox.Show("Выбранный самолёт не удовлетворяет критериям контракта"); return; } } game.SetTimeForContract(flightID, new TimeSpan(hours, minutes, 0)); found = true; } } if (!found) { throw new Exception("Вы не выбрали самолет/самолеты!"); } else { Close(); IsSuccessful = true; } } catch (Exception ex) { MessageBox.Show(ex.Message); } }