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!"); } }
private void btnCadastrar_Click(object sender, EventArgs e) { try { if (!(textBox1.Text == "" || textBox2.Text == "" || comboBox1.Text == "")) { string nome = textBox1.Text; string descricao = textBox2.Text; string problema = Hash.md5(comboBox1.Text); string id = Hash.md5(nome); SolucaoController solC = new SolucaoController(); Model.Solucao sol = new Model.Solucao(id, nome, descricao); string msg = ""; if (solC.add(sol)) { msg += "Solução cadastrada com sucesso"; Limpar.limpar(this); dataGridView1.DataSource = null; Grid.grid(dataGridView1, "select id as 'Id', nome as 'Nome', descricao as 'Descrição' from solucao where id = '" + id + "'"); if (solC.problemaSolucao(problema, id)) { MessageBox.Show(msg + " e devidamente associada ao problema!"); } else { MessageBox.Show(msg + ", mas não devidamente associada ao problema!"); } } else { MessageBox.Show("Solução não pôde ser cadastrada!"); } } else { MessageBox.Show("Informe tudo que for necessário!"); } } catch (Exception) { MessageBox.Show("Solução não pôde ser cadastrada!"); } }
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); }
private void btnExcluir_Click(object sender, EventArgs e) { textBox1.ReadOnly = true; textBox2.ReadOnly = true; if (textBox1.Text != "") { try { string id = dataGridView1.Rows[dataGridView1.SelectedRows[0].Index].Cells[0].Value.ToString(); try { SolucaoController pc = new SolucaoController(); if (pc.delete(id)) { MessageBox.Show("Solução excluída com sucesso!"); Grid.grid(dataGridView1, "select id as 'Id', nome as 'Nome', descricao as 'Descrição' from solucao"); Limpar.limpar(this); } else { MessageBox.Show("Solução não pôde ser excluída!"); } } catch (Exception) { MessageBox.Show("Selecione alguma solução para ser excluída!"); } } catch (Exception) { MessageBox.Show("Selecione uma solução para ser excluída!"); } } else { MessageBox.Show("Selecione alguma solução para ser excluída!"); } }