private void btnGravar_Click(object sender, EventArgs e) { try { Types.DepartamentoType type = new Types.DepartamentoType(); type.Descricao = txtDescricao.Text; DepartamentoBLL itemBLL = new DepartamentoBLL(); if (txtID.Text == "") { txtID.Text = Convert.ToString(itemBLL.insert(type)); } else { type.IdDepartamento = Convert.ToInt32(txtID.Text); itemBLL.alterar(type); } } catch (Exception erro) { MessageBox.Show("Erro ao gravar. Mensagem: " + erro.Message, "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error); } findAll(); }
public Types.DepartamentosType select() { MySqlConnection con = new MySqlConnection(Dados.StringConexao); string SQL = "SELECT * FROM DEPARTAMENTO"; MySqlCommand cmd = new MySqlCommand(SQL, con); con.Open(); MySqlDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection); Types.DepartamentosType types = new Types.DepartamentosType(); while (dr.Read()) { Types.DepartamentoType type = new Types.DepartamentoType(); type.Descricao = dr["DESCRICAO"].ToString(); type.IdDepartamento = Int32.Parse(dr["ID_DEPARTAMENTO"].ToString()); types.Add(type); } return types; }
public void delete(Types.DepartamentoType type) { MySqlConnection con = new MySqlConnection(Dados.StringConexao); string SQL = "DELETE FROM DEPARTAMENTO " + "WHERE ID_DEPARTAMENTO = @id"; MySqlCommand cmd = new MySqlCommand(SQL, con); cmd.Parameters.AddWithValue("@id", type.IdDepartamento); try { con.Open(); cmd.ExecuteNonQuery(); } finally { con.Close(); } }
public Types.DepartamentoType selectRecord(Types.DepartamentoType type) { MySqlConnection con = new MySqlConnection(Dados.StringConexao); string SQL = "SELECT U.* FROM DEPARTAMENTO U " + "WHERE ID_DEPARTAMENTO = @id"; MySqlCommand cmd = new MySqlCommand(SQL, con); cmd.Parameters.AddWithValue("@id", type.IdDepartamento); con.Open(); MySqlDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection); if (dr.Read()) { type.Descricao = dr["DESCRICAO"].ToString(); type.IdDepartamento = Int32.Parse(dr["ID_DEPARTAMENTO"].ToString()); } return(type); }
public Types.DepartamentosType select() { MySqlConnection con = new MySqlConnection(Dados.StringConexao); string SQL = "SELECT * FROM DEPARTAMENTO"; MySqlCommand cmd = new MySqlCommand(SQL, con); con.Open(); MySqlDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection); Types.DepartamentosType types = new Types.DepartamentosType(); while (dr.Read()) { Types.DepartamentoType type = new Types.DepartamentoType(); type.Descricao = dr["DESCRICAO"].ToString(); type.IdDepartamento = Int32.Parse(dr["ID_DEPARTAMENTO"].ToString()); types.Add(type); } return(types); }
public void update(Types.DepartamentoType type) { MySqlConnection con = new MySqlConnection(Dados.StringConexao); string SQL = "UPDATE DEPARTAMENTO " + "SET DESCRICAO = @descricao " + "WHERE ID_DEPARTAMENTO = @id"; MySqlCommand cmd = new MySqlCommand(SQL, con); cmd.Parameters.AddWithValue("@id", type.IdDepartamento); cmd.Parameters.AddWithValue("@descricao", type.Descricao); try { con.Open(); cmd.ExecuteNonQuery(); } finally { con.Close(); } }
public int insert(Types.DepartamentoType type) { MySqlConnection con = new MySqlConnection(Dados.StringConexao); string SQL = "INSERT INTO DEPARTAMENTO (descricao) " + "VALUES(@descricao)"; MySqlCommand cmd = new MySqlCommand(SQL, con); cmd.Parameters.AddWithValue("@descricao", type.Descricao); try { con.Open(); cmd.ExecuteNonQuery(); } finally { con.Close(); } return(int.Parse(cmd.LastInsertedId.ToString())); }
private void btnExcluir_Click(object sender, EventArgs e) { if (MessageBox.Show("Tem certeza que deseja excluir?", "Exclusão", MessageBoxButtons.YesNo, MessageBoxIcon.Error) == System.Windows.Forms.DialogResult.Yes) { try { Types.DepartamentoType type = new Types.DepartamentoType(); type.IdDepartamento = Convert.ToInt32(txtID.Text); DepartamentoBLL itemBLL = new DepartamentoBLL(); itemBLL.excluir(type); } catch (Exception erro) { MessageBox.Show("Erro ao excluir. Mensagem: " + erro.Message, "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error); } findAll(); LimparCampos(); } }
public void alterar(Types.DepartamentoType usuario) { DAL_MYSQL.DepartamentoDAL DepartamentoDAL = new DAL_MYSQL.DepartamentoDAL(); DepartamentoDAL.update(usuario); }
public void excluir(Types.DepartamentoType usuario) { DAL_MYSQL.DepartamentoDAL DepartamentoDAL = new DAL_MYSQL.DepartamentoDAL(); DepartamentoDAL.delete(usuario); }
public int insert(Types.DepartamentoType usuario) { DepartamentoDAL DepartamentoDAL = new DepartamentoDAL(); return(DepartamentoDAL.insert(usuario)); }
public Types.DepartamentoType selectRecord(Types.DepartamentoType usuario) { DAL_MYSQL.DepartamentoDAL DepartamentoDAL = new DAL_MYSQL.DepartamentoDAL(); return(DepartamentoDAL.selectRecord(usuario)); }