Beispiel #1
0
        /// <summary>
        /// Import single XML file to database
        /// </summary>
        /// <param name="accessPath"></param>
        public void ImportSingleFIleFromXML(string accessPath)
        {
            try
            {
                foreach (var r in DbFunc <RecipesBase> .GetAll())
                {
                    NewId = r.Id;
                }

                _fs = new FileStream(accessPath, FileMode.Open, FileAccess.Read);
                _ls = (List <RecipesBase>)_xs.Deserialize(_fs);

                RecipesBase m = new RecipesBase();

                foreach (var r in _ls)
                {
                    m.Id = NewId + 1; m.RecipesName = r.RecipesName; m.Ingredients = r.Ingredients; m.AmountsMeal = r.AmountsMeal; m.ShortDescription = r.ShortDescription; m.LongDescription = r.LongDescription; m.NumberPortions = r.NumberPortions; m.CategoryCuisines = r.CategoryCuisines; m.CategoryRating = r.CategoryRating; m.CategoryDifficultLevel = r.CategoryDifficultLevel; m.CategoryPreparationTime = r.CategoryPreparationTime; m.SnackMeal = r.SnackMeal; m.DinnerMeal = r.DinnerMeal; m.SoupMeal = r.SoupMeal; m.DessertMeal = r.DessertMeal; m.DrinkMeal = r.DrinkMeal; m.PreservesMeal = r.PreservesMeal; m.SaladMeal = r.SaladMeal; m.IdFishIngredients = r.IdFishIngredients; m.IdPastaIngredients = r.IdPastaIngredients; m.IdFruitsIngredients = r.IdFruitsIngredients; m.IdMuschroomsIngredients = r.IdMuschroomsIngredients; m.IdBirdIngredients = r.IdBirdIngredients; m.IdMeatIngredients = r.IdMeatIngredients; m.IdEggsIngredients = r.IdEggsIngredients; m.PhotoLinkLocation = r.PhotoLinkLocation; m.Vegetarian = r.Vegetarian; m.Grams = r.Grams;
                    DbFunc <RecipesBase> .Add(m);
                }

                MessageBox.Show(m.RecipesName + "\n" + "został zaimportowany.", "PLIK ");
                _fs.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Import XML file to database
        /// </summary>
        /// <param name="accessPath"></param>
        public void ImportFileFromXML(string accessPath)
        {
            try
            {
                _fs = new FileStream(accessPath, FileMode.Open, FileAccess.Read);
                _ls = (List <RecipesBase>)_xs.Deserialize(_fs);

                RecipesBase m = new RecipesBase();

                if (DbFunc <RecipesBase> .GetCount() <= 0)
                {
                    foreach (var r in _ls)
                    {
                        m.Id = r.Id; m.RecipesName = r.RecipesName; m.Ingredients = r.Ingredients; m.AmountsMeal = r.AmountsMeal; m.ShortDescription = r.ShortDescription; m.LongDescription = r.LongDescription; m.NumberPortions = r.NumberPortions; m.CategoryCuisines = r.CategoryCuisines; m.CategoryRating = r.CategoryRating; m.CategoryDifficultLevel = r.CategoryDifficultLevel; m.CategoryPreparationTime = r.CategoryPreparationTime; m.SnackMeal = r.SnackMeal; m.DinnerMeal = r.DinnerMeal; m.SoupMeal = r.SoupMeal; m.DessertMeal = r.DessertMeal; m.DrinkMeal = r.DrinkMeal; m.PreservesMeal = r.PreservesMeal; m.SaladMeal = r.SaladMeal; m.IdFishIngredients = r.IdFishIngredients; m.IdPastaIngredients = r.IdPastaIngredients; m.IdFruitsIngredients = r.IdFruitsIngredients; m.IdMuschroomsIngredients = r.IdMuschroomsIngredients; m.IdBirdIngredients = r.IdBirdIngredients; m.IdMeatIngredients = r.IdMeatIngredients; m.IdEggsIngredients = r.IdEggsIngredients; m.PhotoLinkLocation = r.PhotoLinkLocation; m.Vegetarian = r.Vegetarian; m.Grams = r.Grams;
                        DbFunc <RecipesBase> .Add(m);
                    }

                    MessageBox.Show("Baza danych została zaimportowana");
                    _fs.Close();
                }
                else
                {
                    MessageBox.Show("Baza danych przed importem musi zostać wyczyszczona.");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Beispiel #3
0
        /// <summary>
        /// Export one selected file from database to XML
        /// </summary>
        /// <param name="accessPath"></param>
        /// <param name="IdFromDataGridView"></param>
        public void ExportDatabase(string accessPath, RecipesBase IdFromDataGridView)
        {
            try
            {
                _fs = new FileStream(accessPath, FileMode.Create, FileAccess.Write);

                _ls.Add(new RecipesBase(IdFromDataGridView.Id, IdFromDataGridView.RecipesName, IdFromDataGridView.Ingredients, IdFromDataGridView.AmountsMeal, IdFromDataGridView.ShortDescription, IdFromDataGridView.LongDescription, IdFromDataGridView.NumberPortions, IdFromDataGridView.CategoryCuisines, IdFromDataGridView.CategoryRating, IdFromDataGridView.CategoryDifficultLevel, IdFromDataGridView.CategoryPreparationTime, IdFromDataGridView.SnackMeal, IdFromDataGridView.DinnerMeal, IdFromDataGridView.SoupMeal, IdFromDataGridView.DessertMeal, IdFromDataGridView.DrinkMeal, IdFromDataGridView.PreservesMeal, IdFromDataGridView.SaladMeal, IdFromDataGridView.IdFishIngredients, IdFromDataGridView.IdPastaIngredients, IdFromDataGridView.IdFruitsIngredients, IdFromDataGridView.IdMuschroomsIngredients, IdFromDataGridView.IdBirdIngredients, IdFromDataGridView.IdMeatIngredients, IdFromDataGridView.IdEggsIngredients, IdFromDataGridView.PhotoLinkLocation, IdFromDataGridView.Vegetarian, IdFromDataGridView.Grams));

                _xs.Serialize(_fs, _ls);
                _fs.Close();

                MessageBox.Show("Eksport pliku zakończył się sukcesem.");
            }
            catch (IOException ex)
            {
                MessageBox.Show("Błąd podczas eksportu", ex.Message);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Błąd podczas eksportu", ex.Message);
            }
        }
Beispiel #4
0
 public void CompleteDataGridRow(RecipesBase r)
 {
     _dgGrid.Rows.Add(r.Id, r.RecipesName, r.Ingredients, r.AmountsMeal, r.ShortDescription, r.LongDescription, r.NumberPortions, r.CategoryCuisines, r.CategoryRating, r.CategoryDifficultLevel, r.CategoryPreparationTime, r.SnackMeal, r.DinnerMeal, r.SoupMeal, r.DessertMeal, r.DrinkMeal, r.PreservesMeal, r.SaladMeal, r.IdFishIngredients, r.IdPastaIngredients, r.IdFruitsIngredients, r.IdMuschroomsIngredients, r.IdBirdIngredients, r.IdMeatIngredients, r.IdEggsIngredients, r.PhotoLinkLocation, r.Vegetarian, r.Grams);
 }