示例#1
0
        public static void AddNewNutrition(NutritionData item, string typeString)
        {
            TypeFood type = (TypeFood)Enum.Parse(typeof(TypeFood), typeString);

            switch (type)
            {
            case TypeFood.Meat: meat.AddNewNutrution(item);
                break;

            case TypeFood.Fruit: fruit.AddNewNutrution(item);
                break;

            case TypeFood.Nuts: nuts.AddNewNutrution(item);
                break;

            case TypeFood.Vegetables: vegetables.AddNewNutrution(item);
                break;

            case TypeFood.Fish: fish.AddNewNutrution(item);
                break;

            case TypeFood.Cereals: cereals.AddNewNutrution(item);
                break;

            case TypeFood.Bread: bread.AddNewNutrution(item);
                break;

            case TypeFood.Alchohol: alchohol.AddNewNutrution(item);
                break;

            case TypeFood.SoftDrinks: softDrinks.AddNewNutrution(item);
                break;
            }
        }
        public ActionResult DeleteConfirmed(int id)
        {
            TypeFood typeFood = db.TypeFoods.Find(id);

            db.TypeFoods.Remove(typeFood);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
示例#3
0
 public NutritionData(string name, decimal calories, decimal carbohydrates, decimal fat, decimal protein)
 {
     this.name          = name;
     this.calories      = calories;
     this.carbohydrates = carbohydrates;
     this.fat           = fat;
     this.protein       = protein;
     this.type          = TypeFood.Meat;
 }
 public ActionResult Edit([Bind(Include = "Id,Type")] TypeFood typeFood)
 {
     if (ModelState.IsValid)
     {
         db.Entry(typeFood).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(typeFood));
 }
        public ActionResult Create([Bind(Include = "Id,Type")] TypeFood typeFood)
        {
            if (ModelState.IsValid)
            {
                db.TypeFoods.Add(typeFood);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(typeFood));
        }
示例#6
0
 public void SetFood(TypeFood food, float value) // Добавить еду в амбар
 {
     if (StockResouces.ContainsKey((int)food))
     {
         StockResouces[(int)food] += value;
     }
     else
     {
         StockResouces[(int)food] = value;
     }
 }
        // GET: AdminArea/TypeFoods/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            TypeFood typeFood = db.TypeFoods.Find(id);

            if (typeFood == null)
            {
                return(HttpNotFound());
            }
            return(View(typeFood));
        }
示例#8
0
        internal static List <String> LoadProducts(TypeFood typeFood)
        {
            if (dbCon.State == ConnectionState.Closed)
            {
                dbCon.Open();
            }

            string sqGetAllProductsFromType = @"SELECT ProductName, Category FROM Products
                WHERE  (Category = N'" + typeFood.ToString() + "')";

            SqlCeCommand    cmd    = new SqlCeCommand(sqGetAllProductsFromType, dbCon);
            SqlCeDataReader reader = cmd.ExecuteReader();
            List <string>   result = new List <string>();

            while (reader.Read())
            {
                result.Add((string)reader["ProductName"]);
            }

            dbCon.Close();
            return(result);
        }
示例#9
0
 private void WriteDataType(TypeFood type)
 {
     this.type.Text = type.ToString();
 }
示例#10
0
        private void AddToListClick(object sender, EventArgs e)
        {
            NutritionData item = new NutritionData();

            if (string.IsNullOrWhiteSpace(addProductName.Text))
            {
                MessageBox.Show("Wrong input! Enter product name.");
                return;
            }
            else
            {
                item.name = addProductName.Text;
            }

            if (string.IsNullOrWhiteSpace(addCalories.Text))
            {
                MessageBox.Show("Wrong input! Enter calories.");
                return;
            }
            else
            {
                int calories;

                if (!int.TryParse(addCalories.Text, out calories) || calories < 0)
                {
                    MessageBox.Show("Wrong input! Enter calories in correct format.");
                    return;
                }
                else
                {
                    item.calories = calories;
                }
            }

            if (!string.IsNullOrWhiteSpace(addCarbo.Text))
            {
                decimal carbohydrates;

                if (!decimal.TryParse(addCarbo.Text, out carbohydrates) || carbohydrates < 0)
                {
                    MessageBox.Show("Wrong input! Enter carbohydrates in correct format.");
                    return;
                }
                else
                {
                    item.carbohydrates = carbohydrates;
                }
            }

            if (!string.IsNullOrWhiteSpace(addFat.Text))
            {
                decimal fat;

                if (!decimal.TryParse(addFat.Text, out fat) || fat < 0)
                {
                    MessageBox.Show("Wrong input! Enter fats in correct format.");
                    return;
                }
                else
                {
                    item.fat = fat;
                }
            }

            if (!string.IsNullOrWhiteSpace(addProteins.Text))
            {
                decimal protein;

                if (!decimal.TryParse(addProteins.Text, out protein) || protein < 0)
                {
                    MessageBox.Show("Wrong input! Enter proteins in correct format.");
                    return;
                }
                else
                {
                    item.protein = protein;
                }
            }
            TypeFood type = (TypeFood)Enum.Parse(typeof(TypeFood), this.type.Text);

            item.type = type;
            DBManager.AddNewFood(item);

            //ApplicationLogic.AddNewNutrition(item, this.type.Text); old, aleady using DBManager

            HideAddProcutMenu();
        }