Пример #1
0
        private void addIngBnt_Click(object sender, EventArgs e)
        {
            try
            {
                if (string.IsNullOrEmpty(ingredientName.Text) || string.IsNullOrEmpty(ingredientCost.Text))
                {
                    throw new MissingValueException();
                }
                else if (ingredientCdH.Value == decimal.Zero && ingredientCdM.Value == decimal.Zero && ingredientCdS.Value == decimal.Zero)
                {
                    throw new MissingValueException();
                }
                else
                {
                    int intValue = 0;
                    if (!int.TryParse(ingredientCost.Text, out intValue) || !int.TryParse(ingredientCdH.Value.ToString(), out intValue) || !int.TryParse(ingredientCdM.Value.ToString(), out intValue) || !int.TryParse(ingredientCdS.Value.ToString(), out intValue))
                    {
                        throw new InvalidValueException();
                    }
                    else
                    {
                        dblib db = new dblib();
                        db.addNewIngredient(ingredientName.Text, ingredientCost.Text, ingredientCdH.Value.ToString(), ingredientCdM.Value.ToString(), ingredientCdS.Value.ToString());

                        MessageBox.Show("New ingredient added");
                        this.DialogResult = DialogResult.OK;
                    }
                }
            }
            catch (MissingValueException)
            {
                MessageBox.Show("Missing value(s)");
            }
            catch (InvalidValueException)
            {
                MessageBox.Show("Invalidate value(s)");
            }
            catch (SqlException)
            {
            }
        }
Пример #2
0
        private void loadScriptBnt_Click(object sender, EventArgs e)
        {
            try
            {
                if (!string.IsNullOrEmpty(cookwareScriptPath.Text))
                {
                    using (StreamReader file = new StreamReader(cookwareScriptPath.Text))
                    {
                        string line;
                        while ((line = file.ReadLine()) != null)
                        {
                            dblib db = new dblib();
                            db.addNewCookware(line.Trim());
                        }
                    }

                    MessageBox.Show("Cookware script loaded");
                }

                if (!string.IsNullOrEmpty(ingredientScriptPath.Text))
                {
                    using (StreamReader file = new StreamReader(ingredientScriptPath.Text))
                    {
                        string line;
                        while ((line = file.ReadLine()) != null)
                        {
                            string[] separator = { ", " };
                            string[] values    = line.Split(separator, StringSplitOptions.None);
                            string[] times     = values[2].Split(':');
                            dblib    db        = new dblib();
                            db.addNewIngredient(values[0].Trim(), values[1].Trim(), times[0].Trim(), times[1].Trim(), times[2].Trim());
                        }
                    }

                    MessageBox.Show("Ingredient script loaded");
                }

                if (!string.IsNullOrEmpty(recipeScriptPath.Text))
                {
                    using (StreamReader file = new StreamReader(recipeScriptPath.Text))
                    {
                        string line;
                        while ((line = file.ReadLine()) != null)
                        {
                            string[]      separator  = { ", " };
                            string[]      values     = line.Split(separator, StringSplitOptions.None);
                            string[]      times      = values[3].Split(':');
                            dblib         db         = new dblib();
                            string        cookwareId = db.findCookwareId(values[4]);
                            List <string> ingIds     = new List <string>();
                            List <string> ingAmounts = new List <string>();
                            for (int i = 5; i < values.Length; i++)
                            {
                                ingIds.Add(db.findIngredientId(values[i]));
                                i++;
                                ingAmounts.Add(values[i]);
                            }
                            string[] ingredientNames   = ingIds.ToArray();
                            string[] ingredientAmounts = ingAmounts.ToArray();
                            db.addNewRecipe(values[0].Trim(), values[1].Trim(), values[2].Trim(), times[0].Trim(), times[1].Trim(), times[2].Trim(), cookwareId, ingredientNames, ingredientAmounts);
                        }
                    }

                    MessageBox.Show("Recipe script loaded");
                }

                this.DialogResult = DialogResult.OK;
            }
            catch (SqlException)
            {
            }
            catch (FileNotFoundException)
            {
                MessageBox.Show("Cannot find the script file");
            }
        }