public void Delete(Gerente gerente) { try { //abrir a conexão this.abrirConexao(); //instrucao a ser executada string sql = "DELETE FROM Gerente where Nr_Gerente = @codigo;"; SqlCommand cmd = new SqlCommand(sql, this.sqlConn); cmd.Parameters.Add("@codigo", SqlDbType.Int); cmd.Parameters["@codigo"].Value = gerente.Codigo; //executando a instrucao cmd.ExecuteNonQuery(); //liberando a memoria cmd.Dispose(); //fechando a conexao this.fecharConexao(); } catch (Exception ex) { throw new Exception("Erro ao remover gerente: " + ex.Message); } }
public void Insert(Gerente gerente) { try { //abrir a conexão this.abrirConexao(); //instrucao a ser executada string sql = "INSERT INTO Gerente (Nr_Gerente, Nm_Gerente) VALUES (@codigo, @nome);"; SqlCommand cmd = new SqlCommand(sql, this.sqlConn); cmd.Parameters.Add("@codigo", SqlDbType.Int); cmd.Parameters["@codigo"].Value = gerente.Codigo; cmd.Parameters.Add("@nome", SqlDbType.VarChar); cmd.Parameters["@nome"].Value = gerente.Nome; //executando a instrucao cmd.ExecuteNonQuery(); //liberando a memoria cmd.Dispose(); //fechando a conexao this.fecharConexao(); } catch (Exception ex) { throw new Exception("Erro ao inserir gerente: " + ex.Message); } }
public void Update(Gerente gerente) { try { //abrir a conexão this.abrirConexao(); //instrucao a ser executada string sql = "UPDATE Gerente SET Nr_Gerente = @codigo, Nm_Gerente = @nome WHERE Nr_Gerente = @codigo;"; SqlCommand cmd = new SqlCommand(sql, this.sqlConn); cmd.Parameters.Add("@codigo", SqlDbType.Int); cmd.Parameters["@codigo"].Value = gerente.Codigo; cmd.Parameters.Add("@nome", SqlDbType.VarChar); cmd.Parameters["@nome"].Value = gerente.Nome; //executando a instrucao cmd.ExecuteNonQuery(); //liberando a memoria cmd.Dispose(); //fechando a conexao this.fecharConexao(); } catch (Exception ex) { throw new Exception("Erro ao atualizar gerente: " + ex.Message); } }
public void Remover(Gerente gerente) { try { //abrindo conexão this.abrirConexao(); string sql = "DELETE FROM gerente WHERE Nr_Gerente = @Nr_Gerente"; //instrução a ser executada SqlCommand cmd = new SqlCommand(sql, this.sqlConn); cmd.Parameters.Add("@Nr_Gerente", SqlDbType.Int); cmd.Parameters["@Nr_Gerente"].Value = gerente.Nr_Gerente; //executando a instrução cmd.ExecuteNonQuery(); //libernado espaço na memória cmd.Dispose(); //fechando conexão this.fecharConexao(); } catch (Exception ex) { throw new Exception("Erro ao conectar e remover " + ex.Message); } }
public bool VerificarDuplicidade(Gerente gerente) { bool retorno = false; try { this.abrirConexao(); //instrução a ser executada string sql = "SELECT Nr_Gerente, Nm_Gerente FROM Gerente WHERE Nr_Gerente = @Nr_Gerente"; SqlCommand cmd = new SqlCommand(sql, sqlConn); cmd.Parameters.Add("@Nr_Gerente", SqlDbType.Int); cmd.Parameters["@Nr_Gerente"].Value = gerente.Nr_Gerente; //executando a instrução SqlDataReader DbReader = cmd.ExecuteReader(); //lendo o resultado while (DbReader.Read()) { retorno = true; break; } //fechando o leitor de resultados DbReader.Close(); //liberando memório cmd.Dispose(); //fechando conexão this.fecharConexao(); } catch (Exception ex) { throw new Exception("Erro ao conectar e selecionar " + ex.Message); } return(retorno); }
public void Cadastrar(Gerente gerente) { try { //abrir a conexão this.abrirConexao(); string sql = "INSERT INTO Gerente (Nr_Gerente, Nm_Gerente) VALUES(@Nr_Gerente,@Nm_Gerente)"; //instrucao a ser executada SqlCommand cmd = new SqlCommand(sql, this.sqlConn); cmd.Parameters.Add("@Nr_Gerente", SqlDbType.Int); cmd.Parameters["@Nr_Gerente"].Value = gerente.Nr_Gerente; cmd.Parameters.Add("@Nm_Gerente", SqlDbType.VarChar); cmd.Parameters["@Nm_Gerente"].Value = gerente.Nm_Gerente; //executando a instrucao cmd.ExecuteNonQuery(); //liberando a memoria cmd.Dispose(); //fechando a conexao this.fecharConexao(); } catch (Exception ex) { throw new Exception("Erro ao conectar e inserir " + ex.Message); } }
public void Remover(Gerente gerente) { if (gerente.Nr_Gerente < 0) { throw new Exception(ERRO_NUMERO); } new GerenteDados().Remover(gerente); }
public bool VerificarDuplicidade(Gerente gerente) { if (gerente.Nr_Gerente < 0) { throw new Exception(ERRO_NUMERO); } return(new GerenteDados().VerificarDuplicidade(gerente)); }
public List <Gerente> Selecionar(Gerente filtro) { List <Gerente> retorno = new List <Gerente>(); try { this.abrirConexao(); //instrucao a ser executada string sql = "SELECT Nr_Gerente, Nm_Gerente FROM Gerente WHERE Nr_Gerente = Nr_Gerente"; //se foi passada uma matricula válida, esta matricula entrará como critério de filtro if (filtro.Nr_Gerente > 0) { sql += " AND Nr_Numero = @Nr_Gerente"; } //se foi passada um nome válido, este nome entrará como critério de filtro if (filtro.Nm_Gerente != null && filtro.Nm_Gerente.Trim().Equals("") == false) { sql += " AND Nm_Nome LIKE '%@Nm_Gerente%'"; } SqlCommand cmd = new SqlCommand(sql, sqlConn); //se foi passada uma matricula válida, esta matricula entrará como critério de filtro if (filtro.Nr_Gerente > 0) { cmd.Parameters.Add("@Nr_Gerente", SqlDbType.Int); cmd.Parameters["@Nr_Gerente"].Value = filtro.Nr_Gerente; } //se foi passada um nome válido, este nome entrará como critério de filtro if (filtro.Nm_Gerente != null && filtro.Nm_Gerente.Trim().Equals("") == false) { cmd.Parameters.Add("@Nm_Gerente", SqlDbType.VarChar); cmd.Parameters["@Nm_Gerente"].Value = filtro.Nm_Gerente; } //executando a instrucao e colocando o resultado em um leitor SqlDataReader DbReader = cmd.ExecuteReader(); //lendo o resultado da consulta while (DbReader.Read()) { Gerente gerente = new Gerente(); //acessando os valores das colunas do resultado gerente.Nr_Gerente = DbReader.GetInt32(DbReader.GetOrdinal("Nr_Gerente")); gerente.Nm_Gerente = DbReader.GetString(DbReader.GetOrdinal("Nm_Gerente")); retorno.Add(gerente); } //fechando o leitor de resultados DbReader.Close(); //liberando a memoria cmd.Dispose(); //fechando a conexao this.fecharConexao(); } catch (Exception ex) { throw new Exception("Erro ao conectar e selecionar " + ex.Message); } return(retorno); }
public void Delete(Gerente gerente) { if (gerente.Codigo < 0) { throw new Exception(ERRO_NUMERO); } new GerenteDados().Delete(gerente); }
public void Update(Gerente gerente) { if (gerente.Codigo < 0) { throw new Exception(ERRO_NUMERO); } if (gerente.Nome == null && gerente.Nome.Trim().Equals("")) { throw new Exception(ERRO_NOME); } new GerenteDados().Update(gerente); }
public void Atualizar(Gerente gerente) { if (gerente.Nr_Gerente < 0) { throw new Exception(ERRO_NUMERO); } if (gerente.Nm_Gerente.Trim().Equals("") || gerente.Nm_Gerente == null) { throw new Exception(ERRO_NUMERO); } if (VerificarDuplicidade(gerente) == false) { throw new Exception("Gerente não cadastrado no sistema!"); } new GerenteDados().Atualizar(gerente); }
public void Cadastrar(Gerente gerente) { if (gerente.Nr_Gerente <= 0) { throw new Exception(ERRO_NUMERO); } if (gerente.Nm_Gerente.Trim().Equals("") || gerente.Nm_Gerente == null) { throw new Exception(ERRO_NOME); } if (VerificarDuplicidade(gerente) != false) { throw new Exception("Gerente já cadastrado no sistema!"); } new GerenteDados().Cadastrar(gerente); }
public bool VerificaDuplicidade(Gerente gerente) { bool retorno = false; try { //abrir a conexão this.abrirConexao(); //instrucao a ser executada string sql = "SELECT Nr_Gerente, Nm_Gerente FROM Gerente WHERE Nr_Gerente = @codigo;"; SqlCommand cmd = new SqlCommand(sql, sqlConn); cmd.Parameters.Add("@codigo", SqlDbType.Int); cmd.Parameters["@codigo"].Value = gerente.Codigo; //executando a instrucao e colocando o resultado em um leitor SqlDataReader DbReader = cmd.ExecuteReader(); //lendo o resultado da consulta while (DbReader.Read()) { retorno = true; break; } //fechando o leitor de resultados DbReader.Close(); //liberando a memoria cmd.Dispose(); //fechando a conexao this.fecharConexao(); } catch (Exception ex) { throw new Exception("Erro ao verificar duplicidade: " + ex.Message); } return(retorno); }
public List <Gerente> Selecionar(Gerente filtro) { return(new GerenteDados().Selecionar(filtro)); }