Example #1
0
        private void btnSaveRecipe_Click(object sender, EventArgs e)
        {
            string name = textBoxRecipeName.Text;

            List <Component> components = new List <Component>();

            foreach (DataGridViewRow rows in this.dataGridView.Rows)
            {
                Ingredient ingredient = DBHandler.GetIngredient(rows.Cells[0].Value.ToString());
                components.Add(new Component(ingredient, scaleTo100Percentage(rows.Cells[1].Value), rows.Cells[2].Value.ToString()));
            }

            string desc = textDescription.Text;

            DBHandler.addRecipe(new Recipe(name, components, desc));

            loadRecipes();
        }
Example #2
0
        //Converts between g and ml or oz and cups
        private void convertUnit(DataGridViewRow dataGridViewRow)
        {
            decimal weight = DBHandler.GetIngredient(dataGridViewRow.Cells[0].Value.ToString()).weight / 100M;

            if (weight < 0.0001M)
            {
                return;
            }

            string unit          = (string)dataGridViewRow.Cells[2].Value;
            bool   systemChanged = false;

            if (unit == "cups" || unit == "oz")
            {
                convertSystem(dataGridViewRow);
                unit = (string)dataGridViewRow.Cells[2].Value;

                systemChanged = true;
            }

            decimal val = decimal.Parse(dataGridViewRow.Cells[1].Value.ToString());



            if (unit == "ml")
            {
                dataGridViewRow.Cells[2].Value = "g";
                dataGridViewRow.Cells[1].Value = Math.Round(weight * val, 2);
            }

            else if (unit == "g")
            {
                dataGridViewRow.Cells[2].Value = "ml";
                dataGridViewRow.Cells[1].Value = Math.Round(val * (1 / weight), 2);
            }

            if (systemChanged)
            {
                convertSystem(dataGridViewRow);
            }
        }
Example #3
0
 private void comboBoxIngredients_SelectedIndexChanged(object sender, EventArgs e)
 {
     labelWeight.Text = DBHandler.GetIngredient(comboBoxIngredients.SelectedItem.ToString()).weight.ToString();
 }
Example #4
0
 private void ItemDB_Shown(object sender, EventArgs e)
 {
     comboBoxIngredients.Items.Clear();
     comboBoxIngredients.Items.AddRange(DBHandler.getRange <Ingredient>().ToArray());
 }