public Form2(MySqlConnection conn) { InitializeComponent(); this.conn = conn; bl = new BindingList <string>(Updates.getCatagories()); comboBox1.DataSource = bl; comboBox1.SelectedIndex = -1; comboBox2.DataSource = Updates.getStores(); comboBox2.SelectedIndex = -1; }
// Add category button private void button3_Click(object sender, EventArgs e) { foreach (string cat in Updates.getCatagories()) { if (cat == comboBox1.Text) { MessageBox.Show("This ingredient category is already in the list"); return; } } string theCmd = "INSERT INTO Category (name) VALUES (\'" + comboBox1.Text + "\');"; cmd = new MySqlCommand(theCmd, conn); cmd.ExecuteNonQuery(); Updates.updateCategory(conn); MessageBox.Show("This category is added to the list"); }
public void setCategory(string category) { bool check = false; foreach (string cat in Updates.getCatagories()) { if (category == cat) { check = true; } } if (check) { this.category = category; } else { this.category = 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(); }