Exemplo n.º 1
0
        private void btnOk_Click(object sender, EventArgs e)
        {
            IngredientType ingredientType;
            string         name;

            name = tbName.Text;

            if (rbIndependentType.Checked)
            {
                ingredientType = new IndependentType(name);
            }
            else if (rbCookingDepType.Checked)
            {
                int cookingType;
                int additionalCalories;

                try
                {
                    cookingType        = int.Parse(tbCookingType.Text);
                    additionalCalories = int.Parse(tbAdditional.Text);
                }
                catch
                {
                    MessageBox.Show("Data is incorrect! Try again!");
                    return;
                }

                ingredientType = new CookingDependentType(name, additionalCalories, cookingType);
            }
            else
            {
                int additionalPerTenDegrees;

                try
                {
                    additionalPerTenDegrees = int.Parse(tbAdditional.Text);
                }
                catch
                {
                    MessageBox.Show("Data is incorrect! Try again!");
                    return;
                }

                ingredientType = new TemperatureDependentType(name, additionalPerTenDegrees);
            }

            del.Invoke(ingredientType);
            Close();
        }
Exemplo n.º 2
0
        private List <IngredientType> DeserializeIngTypes(out Dictionary <string, IngredientType> dict, IEnumerator <string> lines)
        {
            string ln, link;
            var    ingTypes = new List <IngredientType>();

            dict = new Dictionary <string, IngredientType>();

            while (lines.MoveNext() && ((ln = lines.Current) != ""))
            {
                int i1 = ln.IndexOf('=') + 1;
                int i2 = ln.IndexOf('{') - i1;

                string stType = ln.Substring(i1, i2);

                i1 = ln.IndexOf('{') + 1;
                i2 = ln.IndexOf('}') - i1;

                string[] args = ln.Substring(i1, i2).Split(',');

                IngredientType ingType;

                switch (stType)
                {
                case "IndependentType":
                    ingType = new IndependentType(args[0]);
                    break;

                case "CookingDependentType":
                    ingType = new CookingDependentType(args[0], float.Parse(args[1]), int.Parse(args[2]));
                    break;

                case "TemperatureDependentType":
                    ingType = new TemperatureDependentType(args[0], float.Parse(args[1]));
                    break;

                default:
                    throw new Exception();
                }
                ;

                link = ln.Substring(0, ln.IndexOf('='));

                dict.Add(link, ingType);
                ingTypes.Add(ingType);
            }

            return(ingTypes);
        }