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
        private void Form1_Load(object sender, EventArgs e)
        {
            RecipeManagerData data = null;

            if (!File.Exists($@"{filePath}"))
            {
                DialogResult res = MessageBox.Show($"File '{filePath}' was not found. Would you like to load data from different location?", "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
                if (res == DialogResult.Yes)
                {
                    OpenFileDialog openFile = new OpenFileDialog();
                    openFile.Filter      = "Xml (*.dat)|*.dat|All Files (*.*)|*.*";
                    openFile.FilterIndex = 1;
                    if (openFile.ShowDialog() == DialogResult.OK)
                    {
                        filePath = openFile.FileName;
                        data     = RecipeDataManager.LoadData(filePath);
                    }
                }
            }
            else
            {
                data = RecipeDataManager.LoadData(filePath);
            }

            _storage.SetData(data);
        }
Beispiel #3
0
        private void Form1_Load(object sender, EventArgs e)
        {
            RecipeManagerData data = null;

            if (!File.Exists($@"{filePath}"))
            {
                DialogResult res = MessageBox.Show($"Файл '{filePath}' не найден. Возможно файл поменял своё расположение?", "Подтверждение", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
                if (res == DialogResult.Yes)
                {
                    OpenFileDialog openFile = new OpenFileDialog();
                    openFile.Filter      = "Xml (*.dat)|*.dat|All Files (*.*)|*.*";
                    openFile.FilterIndex = 1;
                    if (openFile.ShowDialog() == DialogResult.OK)
                    {
                        filePath = openFile.FileName;
                        data     = RecipeDataManager.LoadData(filePath);
                    }
                }
            }
            else
            {
                data = RecipeDataManager.LoadData(filePath);
            }

            _storage.SetData(data);
        }