Beispiel #1
0
        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;
            }
        }
Beispiel #2
0
        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());
        }
Beispiel #3
0
        private void addButton_Click(object sender, System.EventArgs e)
        {
            AddIngredientForm formIngr = new AddIngredientForm(_storage.GetIngredient());

            formIngr.ShowDialog();

            if (formIngr.DialogResult == System.Windows.Forms.DialogResult.OK)
            {
                if (formIngr.Ingredient != null)
                {
                    _ingredient.Add(formIngr.Ingredient);
                }
            }
        }