コード例 #1
0
        private void FillDropDownList()
        {
            if (mealsList == null)
            {
                mealsList = new List <Meal>();
            }

            mealsList = SQLProcedures.GetMeals();

            List <string> numberList;

            if (mealsList.Count > 8)
            {
                numberList = new List <string>(mealNumberList);
                ddlBrojObroka.DataSource = numberList;
                ddlBrojObroka.DataBind();
            }
            else
            {
                int availableMeals = mealsList.Count(m => m.IsValid == true);
                numberList = new List <string>();
                for (int i = 0; i < availableMeals + 1; i++)
                {
                    numberList.Add(mealNumberList[i]);
                }
                ddlBrojObroka.DataSource = numberList;
                ddlBrojObroka.DataBind();
            }
        }
コード例 #2
0
 private void FillObrociDDL()
 {
     mealsList = SQLProcedures.GetMeals();
     for (int i = 0; i < gvCombinations.Rows.Count; i++)
     {
         DropDownList ddl = gvCombinations.Rows[i].FindControl("ddlObroci") as DropDownList;
         HiddenField  hf  = gvCombinations.Rows[i].FindControl("hfIDObrok") as HiddenField;
         ddl.DataSource     = mealsList;
         ddl.DataTextField  = "Name";
         ddl.DataValueField = "IDMeal";
         if (string.IsNullOrEmpty(txtStartDate.Text))
         {
             ddl.SelectedIndex = mealsList.FindIndex(m => m.IDMeal == (i + 1));
         }
         else
         {
             ddl.SelectedIndex = mealsList.FindIndex(m => m.IDMeal == int.Parse(hf.Value));
         }
         ddl.DataBind();
     }
 }
コード例 #3
0
        protected void btnSpremi_Click(object sender, EventArgs e)
        {
            int numberOfMeals = int.Parse(ddlBrojObroka.SelectedValue);
            int combID;

            if (!string.IsNullOrEmpty(txtStartDate.Text))
            {
                lblError.Text = string.Empty;
                DateTime startDate = DateTime.Parse(txtStartDate.Text);
                DateTime endDate;

                if (!string.IsNullOrEmpty(txtEndDate.Text))
                {
                    endDate = DateTime.Parse(txtEndDate.Text);
                    if (endDate < DateTime.Now)
                    {
                        lblError.Text = "Uneseni datum isteka je već prošao";
                        return;
                    }
                    combID = SQLProcedures.InsertCombination(numberOfMeals, startDate, endDate);
                }
                else
                {
                    combID = SQLProcedures.InsertCombination(numberOfMeals, startDate, null);
                }

                mealsList = SQLProcedures.GetMeals();
                for (int i = 0; i < gvCombinations.Rows.Count; i++)
                {
                    MealRatio    mealRatio = new MealRatio();
                    DropDownList ddl       = gvCombinations.Rows[i].FindControl("ddlObroci") as DropDownList;
                    if (mealsList.Find(m => m.Name == ddl.SelectedItem.Text).IsValid)
                    {
                        mealRatio.Meal = mealsList.Find(m => m.Name == ddl.SelectedItem.Text);
                    }
                    else
                    {
                        lblError.Text = $"Odabran obrok u {i + 1}. redu nije dozvoljen - pogledati tablicu Obroci";
                        SQLProcedures.DeleteCombination(combID);
                        return;
                    }

                    var txtFat   = gvCombinations.Rows[i].FindControl("txtMasti") as TextBox;
                    var txtCarb  = gvCombinations.Rows[i].FindControl("txtUgljikohidrati") as TextBox;
                    var txtProt  = gvCombinations.Rows[i].FindControl("txtBjelancevine") as TextBox;
                    var txtTotal = gvCombinations.Rows[i].FindControl("txtUkupno") as TextBox;

                    if (int.TryParse(txtFat.Text, out int fat))
                    {
                        mealRatio.FatPortion = fat;
                    }
                    else
                    {
                        lblError.Text = $"Unesena vrijednost masti za obrok {mealRatio.Meal.Name} nije valjana";
                        SQLProcedures.DeleteCombination(combID);
                        return;
                    }

                    if (int.TryParse(txtCarb.Text, out int carb))
                    {
                        mealRatio.CarbPortion = carb;
                    }
                    else
                    {
                        lblError.Text = $"Unesena vrijednost ugljikohidrata za obrok {mealRatio.Meal.Name} nije valjana";
                        SQLProcedures.DeleteCombination(combID);
                        return;
                    }

                    if (int.TryParse(txtProt.Text, out int prot))
                    {
                        mealRatio.ProteinPortion = prot;
                    }
                    else
                    {
                        lblError.Text = $"Unesena vrijednost bjelancevina za obrok {mealRatio.Meal.Name} nije valjana";
                        SQLProcedures.DeleteCombination(combID);
                        return;
                    }

                    if (int.TryParse(txtTotal.Text, out int total))
                    {
                        mealRatio.TotalPortion = total;
                    }
                    else
                    {
                        lblError.Text = $"Unesena vrijednost ukupnog udjela za obrok {mealRatio.Meal.Name} nije valjana";
                        SQLProcedures.DeleteCombination(combID);
                        return;
                    }

                    newMealRatiosList.Add(mealRatio);
                }

                AddNewMealRatios(combID);
            }

            else
            {
                lblError.Text = "Početni datum nije definiran";
            }
        }