public Form1() { InitializeComponent(); _storage = ObjectStorage.GetInstance(); _storage.GetRecipe().Changed += RecipeContainer_Changed; _storage.GetIngredient().Changed += IngredientContainer_Changed; _storage.GetIngredient().Changed += RecipeContainer_Changed; _storage.GetGroups().Changed += GroupContainer_Changed; _storage.GetGroups().Changed += RecipeContainer_Changed; mainListView.ItemSelectionChanged += mainListView_ItemSelectionChanged; lvIngredient.ItemSelectionChanged += lvIngredient_ItemSelectionChanged; lvGroup.ItemSelectionChanged += lvGroup_ItemSelectionChanged; RecipeContainer_Changed(this, new EventArgs()); IngredientContainer_Changed(this, new EventArgs()); GroupContainer_Changed(this, new EventArgs()); }
private void Form1_FormClosing(object sender, FormClosingEventArgs e) { DialogResult res = MessageBox.Show("Save this file?", "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); switch (res) { case DialogResult.Yes: var data = new RecipeManagerData { Ingredients = _storage.GetIngredient().ToList(), Recipes = _storage.GetRecipe().ToList(), Groups = _storage.GetGroups().ToList() }; if (!File.Exists(filePath)) { SaveFileDialog saveFile = new SaveFileDialog(); saveFile.Filter = "Xml (*.dat)|*.dat|All Files (*.*)|*.*"; if (saveFile.ShowDialog() == DialogResult.OK) { filePath = saveFile.FileName; RecipeDataManager.SaveData(filePath, data); } } else { RecipeDataManager.SaveData(filePath, data); } break; case DialogResult.No: break; } }