private void btnGravar_Click(object sender, EventArgs e) { try { Types.CargoType type = new Types.CargoType(); type.Descricao = txtDescricao.Text; type.IdDepartamento = Int32.Parse(cmbDepartamento.SelectedValue.ToString()); CargoBLL itemBLL = new CargoBLL(); if (txtID.Text == "") { txtID.Text = Convert.ToString(itemBLL.insert(type)); } else { type.IdCargo = 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 void delete(Types.CargoType type) { MySqlConnection con = new MySqlConnection(Dados.StringConexao); string SQL = "DELETE FROM CARGO " + "WHERE ID_CARGO = @id"; MySqlCommand cmd = new MySqlCommand(SQL, con); cmd.Parameters.AddWithValue("@id", type.IdCargo); try { con.Open(); cmd.ExecuteNonQuery(); } finally { con.Close(); } }
public Types.CargosType select() { SqlConnection con = new SqlConnection(Dados.StringConexao); string SQL = "SELECT * FROM CARGO"; SqlCommand cmd = new SqlCommand(SQL, con); con.Open(); SqlDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection); Types.CargosType types = new Types.CargosType(); while (dr.Read()) { Types.CargoType type = new Types.CargoType(); type.IdCargo = Int32.Parse(dr["ID_CARGO"].ToString()); type.IdDepartamento = Int32.Parse(dr["ID_DEPARTAMENTO"].ToString()); type.Descricao = dr["DESCRICAO"].ToString(); types.Add(type); } return types; }
public Types.CargoType selectRecord(Types.CargoType type) { MySqlConnection con = new MySqlConnection(Dados.StringConexao); string SQL = "SELECT U.* FROM CARGO U " + "WHERE ID_CARGO = @id"; MySqlCommand cmd = new MySqlCommand(SQL, con); cmd.Parameters.AddWithValue("@id", type.IdCargo); con.Open(); MySqlDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection); if (dr.Read()) { type.IdCargo = Int32.Parse(dr["ID_CARGO"].ToString()); type.IdDepartamento = Int32.Parse(dr["ID_DEPARTAMENTO"].ToString()); type.Descricao = dr["DESCRICAO"].ToString(); } return(type); }
public int insert(Types.CargoType type) { MySqlConnection con = new MySqlConnection(Dados.StringConexao); string SQL = "INSERT INTO CARGO (id_departamento,descricao)" + "VALUES( @idDepartamento, @descricao)"; MySqlCommand cmd = new MySqlCommand(SQL, con); cmd.Parameters.AddWithValue("@idDepartamento", type.IdDepartamento); cmd.Parameters.AddWithValue("@descricao", type.Descricao); try { con.Open(); cmd.ExecuteNonQuery(); } finally { con.Close(); } return(int.Parse(cmd.LastInsertedId.ToString())); }
public void update(Types.CargoType type) { MySqlConnection con = new MySqlConnection(Dados.StringConexao); string SQL = "UPDATE CARGO " + "SET ID_DEPARTAMENTO = @idDepartamento, DESCRICAO = @descricao " + "WHERE ID_CARGO = @id"; MySqlCommand cmd = new MySqlCommand(SQL, con); cmd.Parameters.AddWithValue("@id", type.IdCargo); cmd.Parameters.AddWithValue("@idDepartamento", type.IdDepartamento); cmd.Parameters.AddWithValue("@descricao", type.Descricao); try { con.Open(); cmd.ExecuteNonQuery(); } finally { con.Close(); } }
public Types.CargosType select() { MySqlConnection con = new MySqlConnection(Dados.StringConexao); string SQL = "SELECT * FROM CARGO"; MySqlCommand cmd = new MySqlCommand(SQL, con); con.Open(); MySqlDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection); Types.CargosType types = new Types.CargosType(); while (dr.Read()) { Types.CargoType type = new Types.CargoType(); type.IdCargo = Int32.Parse(dr["ID_CARGO"].ToString()); type.IdDepartamento = Int32.Parse(dr["ID_DEPARTAMENTO"].ToString()); type.Descricao = dr["DESCRICAO"].ToString(); types.Add(type); } return(types); }
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.CargoType type = new Types.CargoType(); type.IdCargo = Convert.ToInt32(txtID.Text); CargoBLL itemBLL = new CargoBLL(); 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.CargoType usuario) { DAL_MYSQL.CargoDAL CargoDAL = new DAL_MYSQL.CargoDAL(); CargoDAL.update(usuario); }
public void excluir(Types.CargoType usuario) { DAL_MYSQL.CargoDAL CargoDAL = new DAL_MYSQL.CargoDAL(); CargoDAL.delete(usuario); }
public int insert(Types.CargoType usuario) { CargoDAL CargoDAL = new CargoDAL(); return(CargoDAL.insert(usuario)); }
public Types.CargoType selectRecord(Types.CargoType usuario) { DAL_MYSQL.CargoDAL CargoDAL = new DAL_MYSQL.CargoDAL(); return(CargoDAL.selectRecord(usuario)); }