Ejemplo n.º 1
0
        private void button2_Click(object sender, EventArgs e)
        {
            if (listBox1.Items != null)
            {
                AmountError.Clear();

                var oSelectedThings = from Things oThings in oThingsLists
                                      where oThings.Name == (string)listBox1.SelectedItem
                                      select oThings;

                if (listBox1.SelectedItem != null)
                {
                    AmountError.Clear();
                    foreach (var Things in oSelectedThings)
                    {
                        listBox1.Items.Remove(Things.Name);
                        nKcal             -= Things.Kcal;
                        Kcal.Text          = nKcal.ToString();
                        nSalt             -= Things.Salt;
                        Salt.Text          = nSalt.ToString();
                        nFat              -= Things.Fat;
                        Fat.Text           = nFat.ToString();
                        nCarbonhydrates   -= Things.Carbohydrates;
                        Carbohydrates.Text = nCarbonhydrates.ToString();
                        nProtein          -= Things.Protein;
                        Protein.Text       = nProtein.ToString();
                        nSugar            -= Things.Sugar;
                        Sugar.Text         = nSugar.ToString();
                        if (nKcal <= progressBar1.Maximum)
                        {
                            progressBar1.Value = nKcal;
                        }
                        else
                        {
                            progressBar1.Value = progressBar1.Maximum;
                        }
                    }
                }
                else
                {
                    AmountError.SetError(button2, "Not selected");
                }
            }
            else
            {
                AmountError.SetError(listBox1, "Empty list");
            }
        }
Ejemplo n.º 2
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (comboBox1.SelectedItem != null)
            {
                AmountError.Clear();

                var oSelectedThings = from Things oThings in oThingsLists
                                      where oThings.Name == (string)comboBox1.SelectedItem
                                      select oThings;


                for (int i = 0; i < numericAmount.Value; i++)
                {
                    foreach (var Things in oSelectedThings)
                    {
                        listBox1.Items.Add(Things.Name);
                        nKcal             += Things.Kcal;
                        Kcal.Text          = nKcal.ToString();
                        nSalt             += Things.Salt;
                        Salt.Text          = nSalt.ToString();
                        nFat              += Things.Fat;
                        Fat.Text           = nFat.ToString();
                        nCarbonhydrates   += Things.Carbohydrates;
                        Carbohydrates.Text = nCarbonhydrates.ToString();
                        nProtein          += Things.Protein;
                        Protein.Text       = nProtein.ToString();
                        nSugar            += Things.Sugar;
                        Sugar.Text         = nSugar.ToString();
                        if (nKcal <= progressBar1.Maximum)
                        {
                            progressBar1.Value = nKcal;
                        }
                        else
                        {
                            progressBar1.Value = progressBar1.Maximum;
                        }
                    }
                }
            }
            else
            {
                AmountError.SetError(comboBox1, "Not selected");
            }
        }
Ejemplo n.º 3
0
 private void button3_Click(object sender, EventArgs e)
 {
     if (!oThingsLists.Exists(Things => Things.Name.Equals(inputName.Text)))
     {
         AmountError.Clear();
         if (inputName.Text != null)
         {
             oThingsLists.Add(new Things(inputName.Text, (int)numericKcal.Value
                                         , (int)numericWeight.Value, (int)numericCarbohydrates.Value, (int)numericSugar.Value
                                         , (int)numericFat.Value, (int)numericSalt.Value, (int)numericProtein.Value
                                         , (int)numericCost.Value));
             comboBox1.Items.Add(inputName.Text);
         }
         else
         {
             AmountError.SetError(button3, "Empty name!");
         }
     }
     else
     {
         AmountError.SetError(button3, "There is that thing already!");
     }
     AddMeal(inputName.Text);
 }