Beispiel #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)
            {
            }
        }
        private void addRecBnt_Click(object sender, EventArgs e)
        {
            try
            {
                int intValue = 0;
                if (string.IsNullOrEmpty(recipeName.Text) || string.IsNullOrEmpty(recipeRevenue.Text) || string.IsNullOrEmpty(recipeServing.Text) || addIngTbl.RowCount == 0)
                {
                    throw new MissingValueException();
                }
                else if (recipeCdH.Value == decimal.Zero && recipeCdM.Value == decimal.Zero && recipeCdS.Value == decimal.Zero)
                {
                    throw new MissingValueException();
                }
                else if (!int.TryParse(recipeRevenue.Text, out intValue) || !int.TryParse(recipeServing.Text, out intValue) || !int.TryParse(recipeCdH.Value.ToString(), out intValue) || !int.TryParse(recipeCdM.Value.ToString(), out intValue) || !int.TryParse(recipeCdS.Value.ToString(), out intValue))
                {
                    throw new InvalidValueException();
                }
                else
                {
                    string[] ingIds     = new string[addIngTbl.RowCount];
                    string[] ingAmounts = new string[addIngTbl.RowCount];
                    for (int i = 0; i < addIngTbl.RowCount; i++)
                    {
                        string ingId     = addIngTbl.Rows[i].Cells[1].Value.ToString();
                        string ingAmount = addIngTbl.Rows[i].Cells[2].Value.ToString();
                        if (string.IsNullOrEmpty(ingId) || string.IsNullOrEmpty(ingAmount))
                        {
                            throw new MissingValueException();
                        }
                        else if (!int.TryParse(ingAmount, out intValue))
                        {
                            throw new InvalidValueException();
                        }
                        else
                        {
                            ingIds[i]     = ingId;
                            ingAmounts[i] = ingAmount;
                        }
                    }

                    dblib db = new dblib();
                    db.addNewRecipe(recipeName.Text, recipeRevenue.Text, recipeServing.Text, recipeCdH.Value.ToString(), recipeCdM.Value.ToString(), recipeCdS.Value.ToString(), recipeCookware.SelectedValue.ToString(), ingIds, ingAmounts);

                    MessageBox.Show("New recipe added");
                    this.DialogResult = DialogResult.OK;
                }
            }
            catch (MissingValueException)
            {
                MessageBox.Show("Missing value(s)");
            }
            catch (NullReferenceException)
            {
                MessageBox.Show("Missing value(s)");
            }
            catch (InvalidValueException)
            {
                MessageBox.Show("Invalidate value(s)");
            }
            catch (SqlException)
            {
            }
        }
Beispiel #3
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");
            }
        }