예제 #1
0
 public List <ContaTipoModel> Listar(ContaTipoModel obj)
 {
     try
     {
         return(Selecionar(obj));
     }
     catch (Exception e)
     {
         throw e;
     }
 }
예제 #2
0
 public ContaTipoModel Consultar(ContaTipoModel obj)
 {
     try
     {
         List <ContaTipoModel> lst = Selecionar(obj);
         return(lst.Count > 0 ? lst.FirstOrDefault() : null);
     }
     catch (Exception e)
     {
         throw e;
     }
 }
예제 #3
0
        public List <ContaTipoModel> Listar(ContaTipoModel obj = null)
        {
            ContaTipoDAO contaTipoDAO = null;

            try
            {
                contaTipoDAO = new ContaTipoDAO(GetSqlCommand());
                return(contaTipoDAO.Listar(obj));
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
예제 #4
0
        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();
            }
        }