private void btnPesquisar_Click(object sender, EventArgs e) { ControllerCategoria controllerCategoria = new ControllerCategoria(); List <string> a1 = controllerCategoria.BuscarTodasNome(); auxiliar = false; foreach (string cate in a1) { if (cate == textBoxName.Text) { auxiliar = true; } } if (auxiliar == true) { MessageBox.Show("Esta categoria existe."); textBoxName.Text = ""; } if (auxiliar == false) { if (textBoxName.Text == "") { MessageBox.Show("Espaços vazios"); } else { MessageBox.Show("Esta categoria não existe..."); textBoxName.Text = ""; } } }
private void btnExluir_Click(object sender, EventArgs e) { ControllerCategoria controllerCategoria = new ControllerCategoria(); List <string> a1 = controllerCategoria.BuscarTodasNome(); foreach (string cate in a1) { if (cate == textBoxName.Text && textBoxName.Text != "") { auxiliar = true; } else if (cate != textBoxName.Text) { auxiliar = false; } } if (auxiliar == true) { controllerCategoria.ExcluirCategoria(textBoxName.Text); MessageBox.Show("Exclusão feita com sucesso!"); textBoxName.Text = ""; } if (auxiliar == false) { if (textBoxName.Text == "") { MessageBox.Show("Espaços vazios"); } else { MessageBox.Show("Esta categoria nao existe..."); textBoxName.Text = ""; } } }
public void Create(string nome, float preco, string descricao, string nomeCat) { List <string> Nome = controllerCategoria.BuscarTodasNome(); foreach (string nomes in Nome) { if (nomes == nomeCat) { auxiliar = true; } } if (auxiliar) { try { id_categoria = VerificarID(nomeCat); conexao.conectar_bd(); MySqlCommand cmd = new MySqlCommand { Connection = conexao.ObjetoConexao, CommandText = @"insert into produto values(null, @id_categoria ,@name, @preco, @descricao);" }; cmd.Parameters.AddWithValue("id_categoria", id_categoria.ToString()); cmd.Parameters.AddWithValue("name", nome.ToString()); cmd.Parameters.AddWithValue("preco", preco); cmd.Parameters.AddWithValue("descricao", descricao.ToString()); cmd.ExecuteNonQuery(); conexao.desconectar_bd(); } catch (MySqlException ex) { throw new Exception("Falha na operação Salvar " + ex.Message); } } }