private void btnAtualizar_Click(object sender, EventArgs e) { if (textBox1.Text != "" && textBox2.Text != "") { try { string id = dataGridView1.Rows[dataGridView1.SelectedRows[0].Index].Cells[0].Value.ToString(); string nome = textBox1.Text; string descricao = textBox2.Text; SolucaoController pc = new SolucaoController(); Model.Solucao sol = pc.search("id", id)[0]; sol.nome = nome; sol.descricao = descricao; try { if (pc.update(sol)) { MessageBox.Show("Solução atualizada com sucesso!"); Limpar.limpar(this); MySqlCommand sql = new MySqlCommand(); sql.CommandText = "select id as 'Id', nome as 'Nome', descricao as 'Descrição' from solucao where id = @id"; sql.Parameters.AddWithValue("@id", id); Grid.grid(dataGridView1, sql); } else { MessageBox.Show("Solução não pôde ser atualizada!"); } } catch (Exception) { MessageBox.Show("Preencha tudo corretamente!"); } } catch (Exception) { MessageBox.Show("Selecione uma solução para ser atualizada!"); } } else { MessageBox.Show("Preencha todos os campos!"); } }
public List <Solucao> listaSolucao(string problema) { ConnectionFactory cf = new ConnectionFactory(); MySqlConnection conex = cf.database(); MySqlCommand sql = new MySqlCommand("select solucao from problemaSolucao where problema = @problema", conex); sql.Parameters.AddWithValue("@problema", problema); DataTable data = new DataTable(); MySqlDataAdapter dta = new MySqlDataAdapter(sql); dta.Fill(data); List <Solucao> solucoes = new List <Solucao>(); SolucaoController solC = new SolucaoController(); for (int x = 0; x < data.Rows.Count; x++) { Solucao solucao = solC.search("id", data.Rows[x]["solucao"].ToString())[0]; solucoes.Add(solucao); } return(solucoes); }