예제 #1
0
 public OpenFood(ObservableCollection <Home.Recipe> listFood, int getID, ObservableCollection <Home.previewFood> previewFoods, ObservableCollection <Home.previewFood> listFavorite)
 {
     InitializeComponent();
     this.newFood      = listFood[getID];
     this.getID        = getID;
     this._listFood    = listFood;
     this.previewFoods = previewFoods;
     this.listFavorite = listFavorite;
 }
예제 #2
0
 private void Button_Click(object sender, RoutedEventArgs e)
 {
     if (nameFood.Text.Trim() == "" || directions.Text.Trim() == "" || ingredients.Text.Trim() == "" || listImages.Items.Count == 0)
     {
         MessageBox.Show("Cần nhập đầy đủ thông tin món ăn", "Lỗi", MessageBoxButton.OK, MessageBoxImage.Error);
     }
     else
     {
         string[] entriesIngredients = Regex.Split(ingredients.Text, "\r\n");
         entriesIngredients = checkBreakLine(entriesIngredients);
         List <string> Ingredients = new List <string>();
         for (var i = 0; i < entriesIngredients.Length; i++)
         {
             Ingredients.Add(entriesIngredients[i]);
         }
         ;
         string[] entriesDirections = Regex.Split(directions.Text, "\r\n");
         entriesDirections = checkBreakLine(entriesDirections);
         List <string> Directions = new List <string>();
         for (var i = 0; i < entriesDirections.Length; i++)
         {
             Directions.Add(entriesDirections[i]);
         }
         ;
         // ------------------------------------------------------------------------
         List <string> Images = new List <string>();
         foreach (string item in listPathImage)
         {
             var    info   = new FileInfo(item);
             string folder = AppDomain.CurrentDomain.BaseDirectory; // "C:\Users\dev\"
             folder += "/data/img/imgFood/";
             string name = Guid.NewGuid().ToString();
             File.Copy(item, folder + name + info.Extension);
             Images.Add($"data/img/imgFood/{name}{info.Extension}");
         }
         ;
         // -------------------------------------------------------------------------
         newFood = new Home.Recipe()
         {
             ID           = _id + 1,
             _name        = nameFood.Text,
             _ingredients = Ingredients,
             _directions  = Directions,
             _images      = Images,
             _isFavorite  = false
         };
         DialogResult = true;
     }
 }
예제 #3
0
        private void homeButton_Click(object sender, RoutedEventArgs e)
        {
            foodReturn = new Home.Recipe()
            {
                _name        = newFood._name,
                _directions  = newFood._directions,
                _images      = newFood._images,
                _ingredients = newFood._ingredients,
                ID           = newFood.ID,
                _isFavorite  = newFood._isFavorite
            };


            DialogResult = true;
        }