public Boolean Insert(OleoModel _obj) { Boolean resultado = false; try { String SQL = String.Format("INSERT INTO oleo (" + "nome, " + "descricao) " + "VALUES ('{0}', '{1}')", _obj.Nome.ToString(), _obj.Descricao.ToString() ); int linhasAfetadas = Conexao.ExecutarIDU(SQL); if (linhasAfetadas > 0) { resultado = true; } return(resultado); } catch (Exception ex) { throw new Exception(ex.Message); } }
public Boolean Update(OleoModel _obj) { Boolean resultado = false; try { String SQL = String.Format("UPDATE oleo SET " + "nome = '{0}', " + "descricao = '{1}' WHERE oleoId = {2}", _obj.Nome.ToString(), _obj.Descricao.ToString(), _obj.OleoId.ToString() ); int linhasAfetadas = Conexao.ExecutarIDU(SQL); if (linhasAfetadas > 0) { resultado = true; } return(resultado); } catch (Exception ex) { throw new Exception(ex.Message); } }
public OleoModel GetForID(int _id) { OleoModel o = null; try { String SQL = String.Format("SELECT * FROM oleo WHERE usuarioId = {0};", _id); SqlDataReader data = Conexao.ExecutarSelect(SQL); if (data.Read()) { o = new OleoModel(); o.OleoId = Convert.ToInt32(data["OleoId"]); o.Nome = data["Nome"].ToString(); o.Descricao = data["Descricao"].ToString(); } data.Close(); Conexao.FecharConexao(); } catch (Exception ex) { throw new Exception(ex.Message); } return(o); }
public Dictionary <int, OleoModel> GetAll() { Dictionary <int, OleoModel> mapaOleos = new Dictionary <int, OleoModel>(); try { String SQL = "SELECT * FROM oleo;"; SqlDataReader data = Conexao.ExecutarSelect(SQL); while (data.Read()) { OleoModel o = new OleoModel(); o.OleoId = Convert.ToInt32(data["OleoId"]); o.Nome = data["Nome"].ToString(); o.Descricao = data["Descricao"].ToString(); mapaOleos.Add(o.OleoId, o); } data.Close(); Conexao.FecharConexao(); } catch (Exception ex) { throw new Exception(ex.Message); } return(mapaOleos); }
private void dgvDados_CellDoubleClick(object sender, DataGridViewCellEventArgs e) { int sintomaId = Convert.ToInt32(dataGridViewDados.SelectedRows[0].Cells[0].Value); OleoModel s = tabelaOleos[sintomaId]; OleoCadastroForm fp = new OleoCadastroForm(); fp.Tag = s; fp.ShowDialog(); }
private void CarregarOleoForm(OleoModel _oleo) { try { txtOleoId.Text = _oleo.OleoId.ToString(); txtNome.Text = _oleo.Nome; } catch (Exception ex) { MessageBox.Show("ERRO ao carregar dados do Oleo.", ex.Message); } }
private OleoModel CapturarOleo() { OleoModel sintoma = new OleoModel(); try { sintoma.OleoId = Convert.ToInt32(txtOleoId.Text); sintoma.Nome = txtNome.Text; } catch (Exception ex) { MessageBox.Show("ERRO ao capturar dados do Oleo.", ex.Message); } return(sintoma); }
//Adicionado para implementar as opções de filtro public Dictionary <int, OleoModel> BuscarListaFiltrada(String _filtros) { Dictionary <int, OleoModel> mapaOleos = new Dictionary <int, OleoModel>(); try { String SQL = "SELECT * FROM oleo WHERE "; int saida; if (int.TryParse(_filtros, out saida)) { SQL += String.Format("usuarioId = {0}", _filtros); } else { SQL += String.Format("nome LIKE '%{0}%'", _filtros); } SqlDataReader data = Conexao.ExecutarSelect(SQL); while (data.Read()) { OleoModel o = new OleoModel(); o.OleoId = Convert.ToInt32(data["OleoId"]); o.Nome = data["Nome"].ToString(); o.Descricao = data["Descricao"].ToString(); mapaOleos.Add(o.OleoId, o); } data.Close(); Conexao.FecharConexao(); } catch (Exception ex) { throw new Exception(ex.Message); } return(mapaOleos); }
private void btnSalvar_Click(object sender, EventArgs e) { try { OleoModel sintoma = CapturarOleo(); PessoaController control = new PessoaController(); if ((Boolean)control.BD('i', sintoma)) { MessageBox.Show("Cadastro efetuado com sucesso!!!"); } else { MessageBox.Show("Cadastro NÃO efetuado!!!"); } } catch (Exception ex) { MessageBox.Show("ERRO ao inserir Oleo.", ex.Message); } }
private void buttonAlterar_Click(object sender, EventArgs e) { try { OleoModel o = CapturarOleo(); OleoController control = new OleoController(); if ((Boolean)control.BD('o', o)) { MessageBox.Show("Cadastro alterado com sucesso!!!"); } else { MessageBox.Show("Cadastro NÃO alterado!!!"); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void CadastroOleoForm_Load(object sender, EventArgs e) { try { //CarregarComboEstados(); if (this.Tag != null) { buttonAlterar.Visible = true; buttonSalvar.Visible = false; txtOleoId.Enabled = false; OleoModel o = (OleoModel)this.Tag; CarregarOleoForm(o); } } catch (Exception ex) { MessageBox.Show("ERRO AO CARREGAR FORM", ex.Message); } }