public ICadastro LocarizarPorNome(params object[] Keys) { ICadastro model = null; using (SqlCommand command = Conexao.GetInstancia().Buscar().CreateCommand()) { command.CommandType = CommandType.Text; command.CommandText = $"Select {Colunas} from {type} Where Nome=@Nome;"; command.Parameters.Add("@Nome", SqlDbType.VarChar).Value = Keys[0]; using (SqlDataReader reader = command.ExecuteReader()) { if (reader.HasRows) { model = FactoryCadastros.GetCadastro(CadastrosType.Equipe); reader.Read(); model.SetId(reader.GetInt32(0)); model.SetNome(reader.GetString(1)); } } } return(model); }
public IEnumerable <ICadastro> ListarPorParametros(params object[] Keys) { List <ICadastro> colecoes = new List <ICadastro>(); using (SqlCommand command = Conexao.GetInstancia().Buscar().CreateCommand()) { command.CommandType = CommandType.Text; command.CommandText = $"Select {Colunas} from {type} Where Nome LIKE ('%'+ @Nome +'%');"; command.Parameters.Clear(); command.Parameters.Add("@Nome", SqlDbType.VarChar).Value = Keys[0]; using (SqlDataAdapter adapter = new SqlDataAdapter(command)) { DataTable tabela = new DataTable(); adapter.Fill(tabela); foreach (DataRow row in tabela.Rows) { ICadastro model = FactoryCadastros.GetCadastro(type); model.SetId(int.Parse(row["Id"].ToString())); model.SetNome(row["Nome"].ToString()); colecoes.Add(model); } } } return(colecoes.AsEnumerable()); }
private void btn_Deletar_Click(object sender, EventArgs e) { ICadastro model = FactoryCadastros.GetCadastro(type); erro = false; try { model.SetId(int.Parse(dataGridCadastro.CurrentRow.Cells[0].Value.ToString())); model.SetNome(dataGridCadastro.CurrentRow.Cells[0].Value.ToString()); } catch (Exception) { MessageBox.Show($"Erro!!!\nCadastre um {type} para poder Deletar", $"Cadastro de {type}"); erro = true; } if (erro == false) { try { cadastoSimplesDao.Remover(model); CarregarGrind(); } catch (Exception ex) { MessageBox.Show("Erro ao tentar Deletar Item!!!\nVerifique se ele esta sendo usado", $"Cadastro de {type}"); } } }
public IEnumerable <ICadastro> ListarTudo() { List <ICadastro> colecoes = new List <ICadastro>(); using (SqlCommand command = Conexao.GetInstancia().Buscar().CreateCommand()) { command.CommandType = CommandType.Text; command.CommandText = $"Select {Colunas} from {type};"; using (SqlDataAdapter adapter = new SqlDataAdapter(command)) { DataTable tabela = new DataTable(); adapter.Fill(tabela); foreach (DataRow row in tabela.Rows) { ICadastro model = FactoryCadastros.GetCadastro(type); model.SetId(int.Parse(row["Id"].ToString())); model.SetNome(row["Nome"].ToString()); colecoes.Add(model); } } } return(colecoes.AsEnumerable()); }
private void btn_Salvar_Click(object sender, EventArgs e) { ICadastro model = FactoryCadastros.GetCadastro(type); if (!txt_Nome.Text.Equals("")) { if (novo) { model.SetNome(txt_Nome.Text); try { cadastoSimplesDao.Inserir(model); } catch (Exception ex) { MessageBox.Show($"Erro ao incluir {type}\n Mensagem de erro: " + ex, $"Cadastro de {type}"); } } else { model.SetId(int.Parse(txt_Id.Text)); model.SetNome(txt_Nome.Text); try { cadastoSimplesDao.Atualizar(model); } catch (Exception ex) { MessageBox.Show($"Erro ao alterar {type}\n Mensagem de erro: " + ex, $"Cadastro de {type}"); } } CarregarGrind(); bloquear(); } else { MessageBox.Show($"Erro!!!\nCampo Nome Inválido!!!", $"Cadastro de {type}"); } }