コード例 #1
0
        public ActionResult GenerateMenuTwo(string submitButton, string txtCombinationDate)
        {
            if (submitButton == "Generiraj novi")
            {
                return(GenerateMenuTwo());
            }

            if (txtCombinationDate != string.Empty)
            {
                DateTime combinationDate = DateTime.Parse(txtCombinationDate);
                ViewBag.CombinationDate = txtCombinationDate;

                if (!SQLProcedures.CheckSavedMenuForDate(Session["username"].ToString(), combinationDate))
                {
                    User        user        = SQLProcedures.GetUser(Session["username"].ToString());
                    Combination combination = SQLProcedures.GetSavedCombination(int.Parse(Session["mealNumber"].ToString()));
                    double      totalKcal   = CalculateTotalKcal();

                    int menuID = SQLProcedures.InsertMenu(user.IDUser, combination.IDCombination, combinationDate, totalKcal);

                    List <MenuMealData> menuMealsList = (List <MenuMealData>)Session["menuMealsList"];
                    foreach (MenuMealData meal in menuMealsList)
                    {
                        SQLProcedures.InsertMealDataForMenu(menuID, meal.MealName, meal.CarbName, meal.CarbUnits, meal.FatName, meal.FatUnits, meal.ProteinName, meal.ProteinUnits);
                    }

                    Session["menuMealList"] = null;
                    return(RedirectToAction("GenerateMenuOne"));
                }
                else
                {
                    ViewBag.ShowError = true;
                    ViewBag.ErrorMsg  = "Jelovnik za odabrani datum već postoji!";
                    return(View());
                }
            }
            else
            {
                ViewBag.ShowError    = true;
                ViewBag.ErrorMessage = "Odaberite datum!";
                return(View());
            }
        }
コード例 #2
0
        protected void ddlBrojObroka_SelectedIndexChanged(object sender, EventArgs e)
        {
            lblError.Text = string.Empty;
            if (ddlBrojObroka.SelectedIndex != 0)
            {
                lblStartDate.Visible = true;
                txtStartDate.Visible = true;
                lblEndDate.Visible   = true;
                txtEndDate.Visible   = true;

                btnSpremi.Visible    = true;
                btnOdustani.Visible  = true;
                btnOnemoguci.Visible = false;

                if (mealRatioList == null)
                {
                    mealRatioList = new List <MealRatio>();
                }

                int selectedNumberOfMeals = int.Parse(ddlBrojObroka.SelectedValue);
                isActive = SQLProcedures.CheckForSavedCombination(selectedNumberOfMeals);
                if (isActive)
                {
                    btnSpremi.Visible    = false;
                    btnOdustani.Visible  = false;
                    btnOnemoguci.Visible = true;

                    mealCombination   = SQLProcedures.GetSavedCombination(selectedNumberOfMeals);
                    mealRatioList     = SQLProcedures.GetMealRatios(mealCombination.IDCombination);
                    txtStartDate.Text = mealCombination.StartDate.ToString(DATE_FORMAT);
                    if (mealCombination.EndDate != DateTime.MinValue)
                    {
                        txtEndDate.Text = mealCombination.EndDate.ToString(DATE_FORMAT);
                    }
                    gvCombinations.DataSource = mealRatioList;
                    gvCombinations.DataBind();
                }

                else
                {
                    txtStartDate.Text = string.Empty;
                    txtEndDate.Text   = string.Empty;
                    for (int i = 0; i < selectedNumberOfMeals; i++)
                    {
                        MealRatio mr = new MealRatio
                        {
                            Meal = new Meal {
                                IDMeal = 0, Name = string.Empty
                            },
                            FatPortion     = 0,
                            CarbPortion    = 0,
                            ProteinPortion = 0,
                            TotalPortion   = 0
                        };
                        mealRatioList.Add(mr);
                    }
                    gvCombinations.DataSource = mealRatioList;
                    gvCombinations.DataBind();
                }
            }
            else
            {
                lblStartDate.Visible      = false;
                txtStartDate.Visible      = false;
                lblEndDate.Visible        = false;
                txtEndDate.Visible        = false;
                btnSpremi.Visible         = false;
                btnOdustani.Visible       = false;
                btnOnemoguci.Visible      = false;
                gvCombinations.DataSource = null;
                gvCombinations.DataBind();
            }
            FillObrociDDL();
        }