/// <summary> /// Конструктор без параметор. /// </summary> public Panel_AddRecipe() { InitializeComponent(); controllerRecipe = new ControllerRecipe(); controllerRecipe.recipes = SerializationOnJson.RecipeDeserializationJson(); SetUpList(); }
private void btn_SaveRecipe_Click(object sender, EventArgs e) { try { if (tb_TitleRecipe.Text == null || tb_TitleRecipe.Text == "") { ErrorMessage("Не заполено название рецепта."); logger.Error("btn_SaveRecipe_Click | Не заполено название рецепта."); return; } if (controllerRecipe.controllerIngredient.ingredients == null) { ErrorMessage("Список ингридиентов пуст."); logger.Error("btn_SaveRecipe_Click | Список ингридиентов пуст."); return; } if (rtb_DescriptionRecie.Text == null || rtb_DescriptionRecie.Text == "") { ErrorMessage("Незаполнено описание рецепта."); logger.Error("btn_SaveRecipe_Click | Незаполнено описание рецепта."); return; } Recipe recipe = new Recipe( tb_TitleRecipe.Text, rtb_DescriptionRecie.Text, new List <Ingredient>(controllerRecipe.controllerIngredient.ingredients) ); controllerRecipe.recipes.Add(recipe); SerializationOnJson.RecipeSerializationJson(controllerRecipe.recipes); SaveFile saveFile = new SaveFile(); saveFile.WriteInFile(recipe); //очищяем форму cbx_NameIngr.Items.Clear(); tb_TitleRecipe.Text = ""; rtb_DescriptionRecie.Text = ""; MessageBox.Show("Добавлен новый рецепт"); logger.Info("btn_SaveRecipe_Click | Добавлен новый рецепт."); } catch (Exception exp) { ErrorMessage("Заполните форму снова."); logger.Error("btn_SaveRecipe_Click | Заполните форму снова. Ошибка: " + exp); } }