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