public Ingredient(string name, string category, string source, bool staple, int isle) { if (Updates.getIngredients().Count > 0) { setName(name); } else { this.name = name; } setCategory(category); setSource(source); this.staple = staple; this.isle = isle; }
public void setName(string name) { bool check = true; foreach (Ingredient ing in Updates.getIngredients()) { if (name == ing.name) { check = false; } } if (check) { this.name = name; } else { this.name = null; } }
// Adds ingredient private void button1_Click(object sender, EventArgs e) { foreach (Ingredient ing in Updates.getIngredients()) { if (ing.name == textBox1.Text) { MessageBox.Show("This ingredient is already in the list"); textBox1.Text = null; radioButton1.Checked = false; button1.Enabled = false; numericUpDown1.Value = 0; comboBox1.Text = ""; comboBox2.Text = ""; textBox1.Select(); return; } } if (comboBox1.Text != String.Empty) { bool inList = false; foreach (string s in Updates.getCatagories()) { if (s == comboBox1.Text) { inList = true; break; } } if (!inList) { category = null; MessageBox.Show("You must select a category from the list or add it."); comboBox1.Select(); return; } if (inList) { category = comboBox1.Text; } } else { category = null; } if (comboBox2.Text != String.Empty) { bool inList = false; foreach (string s in Updates.getStores()) { if (s == comboBox2.Text) { inList = true; break; } } if (!inList) { source = null; MessageBox.Show("You must select a store from the list or add it."); comboBox2.Select(); return; } if (inList) { source = comboBox2.Text; } } else { source = null; } if (radioButton1.Checked) { staple = "true"; } else { staple = "false"; } string cmdText = "SET TRANSACTION READ WRITE;"; cmd = new MySqlCommand(cmdText, conn); cmd.ExecuteNonQuery(); cmdText = "SET TRANSACTION ISOLATION LEVEL SERIALIZABLE;"; cmd = new MySqlCommand(cmdText, conn); cmd.ExecuteNonQuery(); cmdText = "START TRANSACTION;"; cmd = new MySqlCommand(cmdText, conn); cmd.ExecuteNonQuery(); string theCmd = "CALL addIngredient(\'" + textBox1.Text + "\', \'" + category + "\', \'" + source + "\', " + staple + ", " + numericUpDown1.Value.ToString() + ");"; cmd = new MySqlCommand(theCmd, conn); cmd.ExecuteNonQuery(); cmdText = "COMMIT;"; cmd = new MySqlCommand(cmdText, conn); cmd.ExecuteNonQuery(); Updates.updateIngredients(conn); MessageBox.Show("This ingredient is added to the list"); textBox1.Text = null; button1.Enabled = false; numericUpDown1.Value = 0; comboBox1.Text = ""; comboBox2.Text = ""; radioButton1.Checked = false; textBox1.Select(); }