private void buttonSave_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(textBoxNumber.Text)) { MessageBox.Show("Введите номер комнаты", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (CategoryId == null) { MessageBox.Show("Выберите категорию", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } int number; if (!int.TryParse(textBoxNumber.Text, out number)) { MessageBox.Show("Номер комнаты - целое число", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } try { RoomBindingModel model = new RoomBindingModel { Categoryid = CategoryId.Value, Available = true, Number = number }; if (Id.HasValue) { model.Id = Id.Value; } logicR.CreateOrUpdate(model); Close(); } catch (Exception ex) { MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } }