using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using fatd_faturamento.DAL.Persistencia;
using fatd_faturamento.BLL.RegraNegocio;
using fatd_faturamento.ENTIDADE;

namespace fatd_faturamento.BLL.Repositorio
{
    public class repositorioConsum
    {
        public void Insert(entidadeConsum objConsum)
        {
            dalConsum dalConsum = null;

            try
            {
                dalConsum = new dalConsum();

                dalConsum.Insert(objConsum);
            }
            catch (Exception)
            {
                throw;
            }
        }

        public void Update(entidadeConsum objConsum)
        {
            dalConsum dalConsum = null;

            try
            {
                dalConsum = new dalConsum();

                dalConsum.Update(objConsum);
            }
            catch (Exception)
            {
                throw;
            }
        }

        public void Update_1(entidadeConsum objConsum)
        {
            dalConsum dalConsum = null;

            try
            {
                dalConsum = new dalConsum();

                dalConsum.Update_1(objConsum);
            }
            catch (Exception)
            {
                throw;
            }
        }

        public IList<entidadeConsum> Select(entidadeConsum objConsum)
        {
            dalConsum dalConsum = null;

            var lstConsum = new List<entidadeConsum>();

            regraNegocioGlobal regranegocioGlobal = null;

            DataTable dt = null;

            try
            {
                dalConsum = new dalConsum();
                dt = dalConsum.Select(objConsum);

                regranegocioGlobal = new regraNegocioGlobal();

                lstConsum = regraNegocioGlobal.ConvertDataTable<entidadeConsum>(dt);

                return lstConsum;
            }
            catch (Exception)
            {
                throw;
            }
        }

        public IList<entidadeConsum> Select_1(entidadeConsum objConsum)
        {
            dalConsum dalConsum = null;

            var lstConsum = new List<entidadeConsum>();

            regraNegocioGlobal regranegocioGlobal = null;

            DataTable dt = null;

            try
            {
                dalConsum = new dalConsum();
                dt = dalConsum.Select_1(objConsum);

                regranegocioGlobal = new regraNegocioGlobal();

                lstConsum = regraNegocioGlobal.ConvertDataTable<entidadeConsum>(dt);

                return lstConsum;
            }
            catch (Exception)
            {
                throw;
            }
        }

        public IList<entidadeConsum> Select_2(entidadeConsum objConsum)
        {
            dalConsum dalConsum = null;

            var lstConsum = new List<entidadeConsum>();

            regraNegocioGlobal regranegocioGlobal = null;

            DataTable dt = null;

            try
            {
                dalConsum = new dalConsum();
                dt = dalConsum.Select_2(objConsum);

                regranegocioGlobal = new regraNegocioGlobal();

                lstConsum = regraNegocioGlobal.ConvertDataTable<entidadeConsum>(dt);

                return lstConsum;
            }
            catch (Exception)
            {
                throw;
            }
        }

        public IList<entidadeConsum> SelectOthersTables(entidadeConsum objConsum)
        {
            dalConsum dalConsum = null;

            var lstConsum = new List<entidadeConsum>();
            DataTable dt = null;

            try
            {
                dalConsum = new dalConsum();
                dt = dalConsum.SelectOthersTables(objConsum);

                foreach (DataRow dr in dt.Rows)
                {
                    objConsum = new entidadeConsum();

                    if (!Convert.IsDBNull(dr["CONSREG"]))
                        objConsum.CONSREG = Convert.ToInt32(dr["CONSREG"]);

                    lstConsum.Add(objConsum);
                }
                return lstConsum;
            }
            catch (Exception)
            {
                throw;
            }
        }

        public IList<entidadeConsum> SelectOthersTables_1(entidadeConsum objConsum)
        {
            dalConsum dalConsum = null;

            var lstConsum = new List<entidadeConsum>();
            DataTable dt = null;

            try
            {
                dalConsum = new dalConsum();
                dt = dalConsum.SelectOthersTables_1(objConsum);

                foreach (DataRow dr in dt.Rows)
                {
                    objConsum = new entidadeConsum();

                    if (!Convert.IsDBNull(dr["CONSREG"]))
                        objConsum.CONSREG = Convert.ToInt32(dr["CONSREG"]);

                    if (!Convert.IsDBNull(dr["MATRICULA"]))
                        objConsum.MATRICULA = Convert.ToInt32(dr["MATRICULA"]);

                    if (!Convert.IsDBNull(dr["DT_NASCTO"]))
                        objConsum.DT_NASCTO = Convert.ToDateTime(dr["DT_NASCTO"]);

                    if (!Convert.IsDBNull(dr["TELEFONE"]))
                        objConsum.TELEFONE = dr["TELEFONE"].ToString();

                    if (!Convert.IsDBNull(dr["CEL"]))
                        objConsum.CEL = dr["CEL"].ToString();

                    if (!Convert.IsDBNull(dr["TELCONTATO"]))
                        objConsum.TELCONTATO = dr["TELCONTATO"].ToString();

                    if (!Convert.IsDBNull(dr["RG"]))
                        objConsum.RG = dr["RG"].ToString();

                    if (!Convert.IsDBNull(dr["INSC"]))
                        objConsum.INSC = dr["INSC"].ToString();

                    if (!Convert.IsDBNull(dr["NOME"]))
                        objConsum.NOME = dr["NOME"].ToString();

                    if (!Convert.IsDBNull(dr["UF"]))
                        objConsum.UF = dr["UF"].ToString();

                    if (!Convert.IsDBNull(dr["CIDADE"]))
                        objConsum.CIDADE = dr["CIDADE"].ToString();

                    if (!Convert.IsDBNull(dr["DISTRITO"]))
                        objConsum.DISTRITO = dr["DISTRITO"].ToString();

                    if (!Convert.IsDBNull(dr["CEP"]))
                        objConsum.CEP = dr["CEP"].ToString();

                    if (!Convert.IsDBNull(dr["END"]))
                        objConsum.END = dr["END"].ToString();

                    if (!Convert.IsDBNull(dr["NUMERO"]))
                        objConsum.NUMERO = dr["NUMERO"].ToString();

                    if (!Convert.IsDBNull(dr["COMPLEMENT"]))
                        objConsum.COMPLEMENT = dr["COMPLEMENT"].ToString();

                    if (!Convert.IsDBNull(dr["QUADRA"]))
                        objConsum.QUADRA = dr["QUADRA"].ToString();

                    if (!Convert.IsDBNull(dr["LOTE"]))
                        objConsum.LOTE = dr["LOTE"].ToString();

                    if (!Convert.IsDBNull(dr["BAIRRO"]))
                        objConsum.BAIRRO = dr["BAIRRO"].ToString();

                    if (!Convert.IsDBNull(dr["NOMEPAI"]))
                        objConsum.NOMEPAI = dr["NOMEPAI"].ToString();

                    if (!Convert.IsDBNull(dr["NOMEMAE"]))
                        objConsum.NOMEMAE = dr["NOMEMAE"].ToString();

                    if (!Convert.IsDBNull(dr["NOMECONTATO"]))
                        objConsum.NOMECONTATO = dr["NOMECONTATO"].ToString();

                    if (!Convert.IsDBNull(dr["FAX"]))
                        objConsum.FAX = dr["FAX"].ToString();

                    lstConsum.Add(objConsum);
                }
                return lstConsum;
            }
            catch (Exception)
            {
                throw;
            }
        }

        public IList<entidadeConsum> SelectOthersTables_2(entidadeConsum objConsum)
        {
            dalConsum dalConsum = null;

            var lstConsum = new List<entidadeConsum>();
            DataTable dt = null;

            try
            {
                dalConsum = new dalConsum();
                dt = dalConsum.SelectOthersTables_2(objConsum);

                foreach (DataRow dr in dt.Rows)
                {
                    objConsum = new entidadeConsum();

                    if (!Convert.IsDBNull(dr["NOMEUC"]))
                        objConsum.BAIRRO = dr["NOMEUC"].ToString();

                    lstConsum.Add(objConsum);
                }
                return lstConsum;
            }
            catch (Exception)
            {
                throw;
            }
        }

     

        public IList<entidadeConsum> SelectMax(entidadeConsum objConsum)
        {
            dalConsum dalConsum = null;

            var lstConsum = new List<entidadeConsum>();
            DataTable dt = null;

            try
            {
                dalConsum = new dalConsum();
                dt = dalConsum.SelectMax(objConsum);

                foreach (DataRow dr in dt.Rows)
                {
                    objConsum = new entidadeConsum();

                    if (!Convert.IsDBNull(dr["CONSREG"]))
                        objConsum.CONSREG = Convert.ToInt32(dr["CONSREG"]);


                    lstConsum.Add(objConsum);
                }
                return lstConsum;
            }
            catch (Exception)
            {
                throw;
            }
        }

    }
}
