public List <ContaTipoModel> Listar(ContaTipoModel obj) { try { return(Selecionar(obj)); } catch (Exception e) { throw e; } }
public ContaTipoModel Consultar(ContaTipoModel obj) { try { List <ContaTipoModel> lst = Selecionar(obj); return(lst.Count > 0 ? lst.FirstOrDefault() : null); } catch (Exception e) { throw e; } }
public List <ContaTipoModel> Listar(ContaTipoModel obj = null) { ContaTipoDAO contaTipoDAO = null; try { contaTipoDAO = new ContaTipoDAO(GetSqlCommand()); return(contaTipoDAO.Listar(obj)); } catch (Exception ex) { throw ex; } }
private List <ContaTipoModel> Selecionar(ContaTipoModel obj) { List <ContaTipoModel> lst = null; try { objSbSelect = new StringBuilder(); objSbSelect.AppendLine(@" SELECT ContaTipo.IdContaTipo , ContaTipo.Descricao , ContaTipo.Sigla FROM DBBanco.dbo.ContaTipo WHERE 1 = 1 "); if (obj != null) { GetSqlCommand().Parameters.Clear(); if (obj.Id > 0) { objSbSelect.AppendLine(@" AND ContaTipo.IdContaTipo = @IdContaTipo"); GetSqlCommand().Parameters.Add("IdContaTipo", SqlDbType.Int).Value = obj.Id; } if (!string.IsNullOrEmpty(obj.Descricao)) { objSbSelect.AppendLine(@" AND ContaTipo.Descricao LIKE '%@Descricao%'"); GetSqlCommand().Parameters.Add("Descricao", SqlDbType.VarChar).Value = obj.Descricao; } if (!string.IsNullOrEmpty(obj.Sigla)) { objSbSelect.AppendLine(@" AND ContaTipo.Descricao = @Sigla"); GetSqlCommand().Parameters.Add("Descricao", SqlDbType.VarChar).Value = obj.Sigla; } } GetSqlCommand().CommandText = ""; GetSqlCommand().CommandText = objSbSelect.ToString(); lst = new List <ContaTipoModel>(); while (GetSqlDataReader().Read()) { ContaTipoModel item = new ContaTipoModel(); if (!(GetSqlDataReader().IsDBNull(GetSqlDataReader().GetOrdinal("IdContaTipo")))) { item.Id = Convert.ToInt32(GetSqlDataReader()["IdContaTipo"]); } if (!(GetSqlDataReader().IsDBNull(GetSqlDataReader().GetOrdinal("Descricao")))) { item.Descricao = Convert.ToString(GetSqlDataReader()["Descricao"]); } if (!(GetSqlDataReader().IsDBNull(GetSqlDataReader().GetOrdinal("Sigla")))) { item.Sigla = Convert.ToString(GetSqlDataReader()["Sigla"]); } lst.Add(item); } return(lst); } catch (Exception ex) { throw ex; } finally { if (objSbSelect != null) { objSbSelect = null; } Close(); } }