Ejemplo n.º 1
0
 public DataSet PlanoVendaContezino(PlanoController filtro, short contezinos, short parceiro, int TB013_Tipo)
 {
     try
     {
         return(new PlanoDao().PlanoVendaContezino(filtro, contezinos, parceiro, TB013_Tipo));
     }
     catch (Exception ex)
     {
         // ReSharper disable once PossibleIntendedRethrow
         throw ex;
     }
 }
Ejemplo n.º 2
0
        public PlanoControllerTest()
        {
            var options = new DbContextOptionsBuilder <PlanoDBContext>()
                          .UseInMemoryDatabase(databaseName: "PlanosDB").Options;

            var context = new PlanoDBContext(options);

            if (!context.Planos.Any())
            {
                CargaTeste.Populate(ref context);
            }

            _contextTest = context;
            var _repo = new PlanoRepository(context);

            _controller = new PlanoController(_repo, context);
        }
Ejemplo n.º 3
0
        public List <PlanoController> PlanosCorporativo()
        {
            var retorno = new List <PlanoController>();

            try
            {
                var con  = new SqlConnection(ParametrosDAO.StringConexao);
                var sSql = new StringBuilder();


                sSql.Append(" SELECT TB015_id, TB015_Plano, TB015_Corporativo, TB015_Status FROM dbo.TB015_Planos WHERE TB015_Corporativo = 1  AND(TB015_Status = 1)");

                var command = new SqlCommand(sSql.ToString(), con);
                command.CommandTimeout = 300;

                con.Open();
                var reader = command.ExecuteReader();

                var obj1 = new PlanoController();
                obj1.TB015_id    = 0;
                obj1.TB015_Plano = "<SELECIONE>";
                retorno.Add(obj1);

                while (reader.Read())
                {
                    var obj = new PlanoController();
                    obj.TB015_id    = Convert.ToInt64(reader["TB015_id"]);
                    obj.TB015_Plano = reader["TB015_Plano"].ToString().TrimEnd();
                    retorno.Add(obj);
                }

                con.Close();
            }
            catch (Exception ex)
            {
                // ReSharper disable once PossibleIntendedRethrow
                throw ex;
            }
            return(retorno);
        }
Ejemplo n.º 4
0
        //public List<PlanoController> ListarPlanosPorTipo(int tipoContrato)
        //{
        //    var retorno = new List<PlanoController>();
        //    try
        //    {
        //        var con = new SqlConnection(ParametrosDAO.StringConexao);
        //        var sSql = new StringBuilder();

        //        sSql.Append(" SELECT TB015_id, TB015_Plano, TB015_Contezinos, TB015_Parceiros, TB015_Corporativo FROM dbo.TB015_Planos ");

        //        switch (tipoContrato)
        //        {
        //            case 1:
        //                sSql.Append(" WHERE TB015_Contezinos = 1");
        //                break;
        //            case 2:
        //                sSql.Append(" WHERE TB015_Parceiros = 1");
        //                break;
        //            case 3:
        //                sSql.Append(" WHERE TB015_Corporativo = 1");
        //                break;
        //            case 4:
        //                sSql.Append(" WHERE TB015_Contezinos = 1");
        //                break;
        //            case 5:
        //                sSql.Append(" WHERE TB015_Contezinos = 1");
        //                break;
        //        }

        //        sSql.Append(" ORDER BY TB015_Plano");



        //        SqlCommand command = new SqlCommand(sSql.ToString(), con);

        //        con.Open();
        //        var reader = command.ExecuteReader();

        //        while (reader.Read())
        //        {
        //            var obj = new PlanoController
        //            {
        //                TB015_id = Convert.ToInt64(reader["TB015_id"]),
        //                TB015_Plano = reader["TB015_Plano"].ToString().TrimEnd()
        //            };

        //            retorno.Add(obj);
        //        }

        //        con.Close();
        //    }
        //    catch (Exception ex)
        //    {
        //        // ReSharper disable once PossibleIntendedRethrow
        //        throw ex;
        //    }
        //    return retorno;
        //}


        public List <PlanoController> ListarPlanos()
        {
            var retorno = new List <PlanoController>();

            try
            {
                var con  = new SqlConnection(ParametrosDAO.StringConexao);
                var sSql = new StringBuilder();

                sSql.Append(" SELECT TB015_id, TB015_Plano, TB015_Contezinos, TB015_Parceiros, TB015_Corporativo FROM dbo.TB015_Planos ORDER BY TB015_Contezinos DESC, TB015_Parceiros DESC, TB015_Corporativo DESC, TB015_Plano ");

                SqlCommand command = new SqlCommand(sSql.ToString(), con);
                command.CommandTimeout = 300;

                con.Open();
                var reader = command.ExecuteReader();

                while (reader.Read())
                {
                    var obj = new PlanoController
                    {
                        TB015_id    = Convert.ToInt64(reader["TB015_id"]),
                        TB015_Plano = reader["TB015_Plano"].ToString().TrimEnd()
                    };

                    retorno.Add(obj);
                }

                con.Close();
            }
            catch (Exception ex)
            {
                // ReSharper disable once PossibleIntendedRethrow
                throw ex;
            }
            return(retorno);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Descrição:  Retorna plano de acordo com categoria de idade, local de cadastro, data validade, e status = Somente para Contezinos
        /// Autor:      Fabiano Gonçalves Elias
        /// Data:       01/30/2016
        /// **********************************************************************************************************
        /// Data Alteração      Autor       Descrição
        /// </summary>
        //public DataSet PlanoParceiros(long tb002Id, int tb015LiberadoCpf, int tb015LiberadoCnpj)
        //{
        //    DataSet dsRetorno = new DataSet();
        //    try
        //    {
        //        var sSql = new StringBuilder();

        //        sSql.Append(" SELECT dbo.TB015_Planos.TB015_id, dbo.TB015_Planos.TB015_Plano, dbo.TB015_Planos.TB015_ValorAdesao, SUM(dbo.TB014_Produtos.TB014_ValorUnitario) AS Mensalidade, dbo.TB002_PontosDeVenda.TB002_id,  ");
        //        sSql.Append(" dbo.TB002_PontosDeVenda.TB002_Ponto, dbo.TB015_Planos.TB015_LiberadoCPF, dbo.TB015_Planos.TB015_LiberadoCNPJ ");
        //        sSql.Append(" FROM  dbo.TB015_Planos INNER JOIN ");
        //        sSql.Append(" dbo.TB015_TB014 ON dbo.TB015_Planos.TB015_id = dbo.TB015_TB014.TB015_id INNER JOIN ");
        //        sSql.Append(" dbo.TB014_Produtos ON dbo.TB015_TB014.TB014_id = dbo.TB014_Produtos.TB014_id INNER JOIN ");
        //        sSql.Append(" dbo.TB015_TB002 ON dbo.TB015_Planos.TB015_id = dbo.TB015_TB002.TB015_id INNER JOIN ");
        //        sSql.Append(" dbo.TB002_PontosDeVenda ON dbo.TB015_TB002.TB002_id = dbo.TB002_PontosDeVenda.TB002_id ");
        //        sSql.Append(" WHERE ");
        //        sSql.Append(" dbo.TB015_Planos.TB015_Parceiros = 1 ");
        //        sSql.Append(" AND ");
        //        sSql.Append(" dbo.TB015_Planos.TB015_Status = 1 ");
        //        sSql.Append(" GROUP BY dbo.TB015_Planos.TB015_id, dbo.TB015_Planos.TB015_Plano, dbo.TB015_Planos.TB015_ValorAdesao, dbo.TB002_PontosDeVenda.TB002_id, dbo.TB002_PontosDeVenda.TB002_Ponto,  ");
        //        sSql.Append(" dbo.TB015_Planos.TB015_LiberadoCPF, dbo.TB015_Planos.TB015_LiberadoCNPJ ");
        //        sSql.Append(" HAVING ");
        //        sSql.Append(" dbo.TB002_PontosDeVenda.TB002_id = ");
        //        sSql.Append(tb002Id);
        //        sSql.Append(" AND ");
        //        sSql.Append(" dbo.TB015_Planos.TB015_LiberadoCPF = ");
        //        sSql.Append(tb015LiberadoCpf);
        //        sSql.Append(" AND ");
        //        sSql.Append(" dbo.TB015_Planos.TB015_LiberadoCNPJ =  ");
        //        sSql.Append(tb015LiberadoCnpj);
        //        SqlConnection con = new SqlConnection(ParametrosDAO.StringConexao);

        //        con.Open();
        //        SqlDataAdapter da = new SqlDataAdapter(sSql.ToString(), con);

        //        da.Fill(dsRetorno);
        //        da.Dispose();
        //        con.Dispose();

        //        con.Close();
        //    }
        //    catch (Exception ex)
        //    {
        //        // ReSharper disable once PossibleIntendedRethrow
        //        throw ex;
        //    }
        //    return dsRetorno;
        //}

        /// <summary>
        /// Descrição:  Retorna plano de acordo com categoria de idade, local de cadastro, data validade, e status = Somente para Contezinos
        /// Autor:      Fabiano Gonçalves Elias
        /// Data:       01/30/2016
        /// **********************************************************************************************************
        /// Data Alteração      Autor       Descrição
        /// </summary>
        //public DataSet PlanoContrato(long tb015Id)
        //{
        //    var dsRetorno = new DataSet();
        //    try
        //    {
        //        var sSql = new StringBuilder();

        //        sSql.Append(" SELECT ");
        //        sSql.Append(" TB015_id, ");
        //        sSql.Append(" TB015_Plano ");
        //        sSql.Append(" FROM ");
        //        sSql.Append(" dbo.TB015_Planos ");
        //        sSql.Append(" GROUP BY ");
        //        sSql.Append(" TB015_id, ");
        //        sSql.Append(" TB015_Plano ");
        //        sSql.Append(" HAVING ");
        //        sSql.Append(" TB015_id = ");
        //        sSql.Append(tb015Id);

        //        SqlConnection con = new SqlConnection(ParametrosDAO.StringConexao);

        //        con.Open();
        //        SqlDataAdapter da = new SqlDataAdapter(sSql.ToString(), con);

        //        da.Fill(dsRetorno);
        //        da.Dispose();
        //        con.Dispose();

        //        con.Close();
        //    }
        //    catch (Exception ex)
        //    {
        //        // ReSharper disable once PossibleIntendedRethrow
        //        throw ex;
        //    }
        //    return dsRetorno;
        //}

        public PlanoController PlanoVendaSelectId(long tb015Id, int maiores, int menores, int isentos)
        {
            PlanoController retorno = new PlanoController();

            try
            {
                var con  = new SqlConnection(ParametrosDAO.StringConexao);
                var sSql = new StringBuilder();
                sSql.Append(" SELECT ");
                sSql.Append(" * ");
                sSql.Append(" FROM ");
                sSql.Append(" TB015_Planos ");
                sSql.Append(" WHERE ");
                sSql.Append(" TB015_id = ");
                sSql.Append(tb015Id);

                var command = new SqlCommand(sSql.ToString(), con);
                command.CommandTimeout = 300;

                con.Open();
                var reader = command.ExecuteReader();

                while (reader.Read())
                {
                    retorno.TB015_id                  = Convert.ToInt64(reader["TB015_id"]);
                    retorno.TB015_Plano               = Convert.ToString(reader["TB015_Plano"]);
                    retorno.TB015_ValorAdesao         = Convert.ToDouble(reader["TB015_ValorAdesao"]);
                    retorno.TB015_PermiteAbonarAdesao = Convert.ToInt16(reader["TB015_PermiteAbonarAdesao"]);
                    retorno.TB015_Contezinos          = Convert.ToInt16(reader["TB015_Contezinos"]);
                    retorno.TB015_Parceiros           = Convert.ToInt16(reader["TB015_Parceiros"]);
                    retorno.TB015_Corporativo         = Convert.ToInt16(reader["TB015_Corporativo"]);
                    retorno.TB015_Inicio              = Convert.ToDateTime(reader["TB015_Inicio"]);
                    retorno.TB015_Fim                 = Convert.ToDateTime(reader["TB015_Fim"]);
                    retorno.TB015_Ciclo               = Convert.ToInt16(reader["TB015_Ciclo"]);
                    retorno.TB015_Descricao           = Convert.ToString(reader["TB015_Descricao"]);
                    retorno.TB015_Maiores             = Convert.ToInt16(reader["TB015_Maiores"]);
                    retorno.TB015_Menores             = Convert.ToInt16(reader["TB015_Menores"]);
                    retorno.TB015_Isentos             = Convert.ToInt16(reader["TB015_Isentos"]);
                    retorno.TB015_StatusS             = Convert.ToString(reader["TB015_Status"]);
                    retorno.TB015_EspecieDocumento    = Convert.ToString(reader["TB015_EspecieDocumento"]);
                    retorno.TB015_BoletoDesc1         = Convert.ToString(reader["TB015_BoletoDesc1"]);
                    retorno.TB015_BoletoDesc2         = Convert.ToString(reader["TB015_BoletoDesc2"]);
                    retorno.TB015_BoletoDesc3         = Convert.ToString(reader["TB015_BoletoDesc3"]);
                    retorno.TB015_BoletoDesc4         = Convert.ToString(reader["TB015_BoletoDesc4"]);
                    retorno.TB015_BoletoDesc5         = Convert.ToString(reader["TB015_BoletoDesc5"]);
                    retorno.TB015_TipoVencimento      = Convert.ToInt16(reader["TB015_TipoVencimento"]);
                    retorno.TB015_TipoVencimento      = Convert.ToInt16(reader["TB015_TipoVencimento"]);
                    retorno.TB015_IOF                 = Convert.ToDouble(reader["TB015_IOF"]);
                }
                con.Close();


                StringBuilder sProdutosDoPlano = new StringBuilder();


                sProdutosDoPlano.Append(" SELECT SUM(dbo.TB014_Produtos.TB014_ValorUnitario)AS ValorTotalProdutos,  ");
                sProdutosDoPlano.Append(" dbo.TB014_Produtos.TB014_ValorMultiplo,  ");
                sProdutosDoPlano.Append(" dbo.TB014_Produtos.TB014_Maiores, ");
                sProdutosDoPlano.Append(" dbo.TB014_Produtos.TB014_Menores, ");
                sProdutosDoPlano.Append(" dbo.TB014_Produtos.TB014_Isentos ");
                sProdutosDoPlano.Append(" FROM          ");
                sProdutosDoPlano.Append(" dbo.TB015_TB014 INNER JOIN ");
                sProdutosDoPlano.Append(" dbo.TB014_Produtos ON dbo.TB015_TB014.TB014_id = dbo.TB014_Produtos.TB014_id ");
                sProdutosDoPlano.Append(" GROUP BY dbo.TB015_TB014.TB015_id,  ");
                sProdutosDoPlano.Append(" dbo.TB014_Produtos.TB014_ValorMultiplo,  ");
                sProdutosDoPlano.Append(" dbo.TB014_Produtos.TB014_Maiores,  ");
                sProdutosDoPlano.Append(" dbo.TB014_Produtos.TB014_Menores,  ");
                sProdutosDoPlano.Append(" dbo.TB014_Produtos.TB014_Isentos ");
                sProdutosDoPlano.Append(" HAVING dbo.TB015_TB014.TB015_id =  ");
                sProdutosDoPlano.Append(tb015Id);

                command = new SqlCommand(sProdutosDoPlano.ToString(), con);
                command.CommandTimeout = 300;

                con.Open();
                reader = command.ExecuteReader();
                while (reader.Read())
                {
                    int multiplo = Convert.ToInt16(reader["TB014_ValorMultiplo"]);
                    if (multiplo > 0)
                    {
                        if (Convert.ToInt16(reader["TB014_Maiores"]) > 0)
                        {
                            retorno.ValorTotalProdutos = Convert.ToDouble(reader["ValorTotalProdutos"]) * maiores;
                        }
                        if (Convert.ToInt16(reader["TB014_Menores"]) > 0)
                        {
                            retorno.ValorTotalProdutos = Convert.ToDouble(reader["ValorTotalProdutos"]) * menores;
                        }
                    }
                    else
                    {
                        retorno.ValorTotalProdutos = Convert.ToDouble(reader["ValorTotalProdutos"]);
                    }
                }
                con.Close();
            }
            catch (Exception ex)
            {
                // ReSharper disable once PossibleIntendedRethrow
                throw ex;
            }
            return(retorno);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Descrição:  Retorna plano de acordo com categoria de idade, local de cadastro, data validade, e status = Somente para Contezinos
        /// Autor:      Fabiano Gonçalves Elias
        /// Data:       01/30/2016
        /// **********************************************************************************************************
        /// Data Alteração      Autor       Descrição
        /// </summary>
        public DataSet PlanoVendaContezino(PlanoController filtro, short contezinos, short parceiro, int TB013_Tipo)
        {
            var dsRetorno = new DataSet();

            try
            {
                var sSql = new StringBuilder();
                sSql.Append("SELECT  ");
                sSql.Append("dbo.TB015_Planos.TB015_id,  ");
                sSql.Append("SUM(dbo.TB014_Produtos.TB014_ValorUnitario) AS ValorPlano,  ");
                sSql.Append("dbo.TB015_Planos.TB015_Plano,  ");
                sSql.Append("dbo.TB015_Planos.TB015_Ciclo,  ");
                sSql.Append("dbo.TB015_Planos.TB015_IOF,  ");
                sSql.Append("dbo.TB015_Planos.TB015_LiberadoCPF,  ");
                sSql.Append("dbo.TB015_Planos.TB015_LiberadoCNPJ,  ");
                sSql.Append("dbo.TB015_Planos.TB015_TipoVencimento,  ");
                sSql.Append("dbo.TB015_Planos.TB015_EspecieDocumento, ");
                sSql.Append("dbo.TB015_Planos.TB015_BoletoDesc1,  ");
                sSql.Append("dbo.TB015_Planos.TB015_BoletoDesc2,  ");
                sSql.Append("dbo.TB015_Planos.TB015_BoletoDesc3,  ");
                sSql.Append("dbo.TB015_Planos.TB015_BoletoDesc4,  ");
                sSql.Append("dbo.TB015_Planos.TB015_BoletoDesc5, ");
                sSql.Append("dbo.TB015_Planos.TB015_Juros, ");
                sSql.Append("dbo.TB015_Planos.TB015_Multa ");
                sSql.Append("FROM ");
                sSql.Append("dbo.TB015_Planos ");
                sSql.Append("INNER JOIN ");
                sSql.Append("dbo.TB015_TB002 ON dbo.TB015_Planos.TB015_id = dbo.TB015_TB002.TB015_id  ");
                sSql.Append("INNER JOIN ");
                sSql.Append("dbo.TB015_TB014 ON dbo.TB015_Planos.TB015_id = dbo.TB015_TB014.TB015_id  ");
                sSql.Append("INNER JOIN ");
                sSql.Append("dbo.TB014_Produtos ON dbo.TB015_TB014.TB014_id = dbo.TB014_Produtos.TB014_id ");
                sSql.Append("GROUP BY dbo.TB015_Planos.TB015_id,  ");
                sSql.Append("dbo.TB015_Planos.TB015_Plano,  ");
                sSql.Append("dbo.TB015_Planos.TB015_Maiores, ");
                sSql.Append("dbo.TB015_Planos.TB015_Menores,  ");
                sSql.Append("dbo.TB015_Planos.TB015_Isentos,  ");
                sSql.Append("dbo.TB015_TB002.TB002_id,  ");
                sSql.Append("dbo.TB015_Planos.TB015_Fim, ");
                sSql.Append("dbo.TB015_Planos.TB015_Status, ");
                sSql.Append("dbo.TB015_Planos.TB015_Contezinos, ");
                sSql.Append("dbo.TB015_Planos.TB015_Parceiros, ");
                sSql.Append("dbo.TB015_Planos.TB015_Inicio,  ");
                sSql.Append("dbo.TB015_Planos.TB015_Ciclo,  ");
                sSql.Append("dbo.TB015_Planos.TB015_IOF,  ");
                sSql.Append("dbo.TB015_Planos.TB015_LiberadoCPF,  ");
                sSql.Append("dbo.TB015_Planos.TB015_LiberadoCNPJ,  ");
                sSql.Append("dbo.TB015_Planos.TB015_TipoVencimento, ");
                sSql.Append("dbo.TB015_Planos.TB015_EspecieDocumento, ");
                sSql.Append("dbo.TB015_Planos.TB015_BoletoDesc1,  ");
                sSql.Append("dbo.TB015_Planos.TB015_BoletoDesc2,  ");
                sSql.Append("dbo.TB015_Planos.TB015_BoletoDesc3,  ");
                sSql.Append("dbo.TB015_Planos.TB015_BoletoDesc4, ");
                sSql.Append("dbo.TB015_Planos.TB015_BoletoDesc5, ");
                sSql.Append("dbo.TB015_Planos.TB015_Juros, ");
                sSql.Append("dbo.TB015_Planos.TB015_Multa ");
                sSql.Append("HAVING ");
                sSql.Append("dbo.TB015_Planos.TB015_Maiores = ");
                sSql.Append(filtro.TB015_Maiores);
                sSql.Append("AND ");
                sSql.Append("dbo.TB015_Planos.TB015_Menores =  ");

                if (filtro.TB015_Menores > 0)
                {
                    sSql.Append(1);
                }
                else
                {
                    sSql.Append(0);
                }


                sSql.Append("AND ");
                sSql.Append("dbo.TB015_Planos.TB015_Isentos = ");

                if (filtro.TB015_Isentos > 0)
                {
                    sSql.Append(1);
                }
                else
                {
                    sSql.Append(0);
                }
                sSql.Append("AND ");
                sSql.Append("dbo.TB015_TB002.TB002_id =  ");
                sSql.Append(filtro.PontoDeVenda.TB002_id);

                sSql.Append("AND ");
                sSql.Append("dbo.TB015_Planos.TB015_Status = 1 "); //Somente Planos Ativos


                if (contezinos == 1)
                {
                    sSql.Append("AND ");
                    sSql.Append("dbo.TB015_Planos.TB015_Contezinos = 1 ");
                }
                if (parceiro == 1)
                {
                    sSql.Append("AND ");
                    sSql.Append("dbo.TB015_Planos.TB015_Parceiros = 1 ");
                }

                if (TB013_Tipo == 1)
                {
                    sSql.Append(" AND dbo.TB015_Planos.TB015_LiberadoCPF =  1 ");
                }
                else
                {
                    sSql.Append(" AND dbo.TB015_Planos.TB015_LiberadoCNPJ =  1 ");
                }

                SqlConnection con = new SqlConnection(ParametrosDAO.StringConexao);

                con.Open();
                SqlDataAdapter da = new SqlDataAdapter(sSql.ToString(), con);

                da.Fill(dsRetorno);
                da.Dispose();
                con.Dispose();

                con.Close();
            }
            catch (Exception ex)
            {
                // ReSharper disable once PossibleIntendedRethrow
                throw ex;
            }
            return(dsRetorno);
        }
Ejemplo n.º 7
0
        private void RenovarPlanoFamiliar()
        {
            try
            {
                txtMensagens.Focus();
                txtMensagens.Text = "Iniciando processo de renovação.";
                for (int y = 0; y < dgwLista.RowCount; y++)
                {
                    if (Convert.ToBoolean(dgwLista.Rows[y].Cells["Renovar"].Value) == true)
                    {
                        List <ParcelaController> Parcelas = new List <ParcelaController>();

                        /*Dados da Ultima Parcela*/
                        ParcelaNegocios   Parcela_N     = new ParcelaNegocios();
                        ParcelaController UltimaParcela = new ParcelaController();
                        UltimaParcela = Parcela_N.UltimaParcelaRenovacao(Convert.ToInt64(dgwLista.Rows[y].Cells["TB012_id"].Value.ToString()));


                        /****************************************************/
                        try
                        {
                            for (int i = 0; i < 12; i++)
                            {
                                ParcelaController Parcela  = new ParcelaController();
                                PlanoController   objPlano = new PlanoController();

                                Parcela.Plano = objPlano;

                                if (cnkExportarArquivo.Checked == true)
                                {
                                    Parcela.TB016_LoteExportacao = 0;
                                }
                                else
                                {
                                    Parcela.TB016_LoteExportacao = -1;
                                }



                                List <ParcelaProdutosController> ParcelaItens_L = new List <ParcelaProdutosController>();

                                //Recuperar Empresa Pelo Local de Cadastro
                                PontoDeVendaNegocios PontoDeVenda_N = new PontoDeVendaNegocios();

                                EmpresaNegocios Empresa_N = new EmpresaNegocios();



                                PontoDeVendaController Ponto = new PontoDeVendaNegocios().PontoDeVendaEmpresa(Convert.ToInt64(dgwLista.Rows[y].Cells["TB002_id"].Value.ToString()));



                                Parcela.Empresa = new EmpresaNegocios().Empresa(Ponto.Empresa.TB001_id);



                                PessoaNegocios Titular_N = new PessoaNegocios();

                                Parcela.Pessoa = Titular_N.pessoaSelectId(Convert.ToInt64(dgwLista.Rows[y].Cells["TB013_id"].Value.ToString()));

                                Parcela.Pessoa.Municipio.TB006_Municipio     = Parcela.Pessoa.Municipio.TB006_Municipio;
                                Parcela.Pessoa.Municipio.Estado.TB005_Estado = Parcela.Pessoa.Municipio.Estado.TB005_Estado;
                                Parcela.Pessoa.TB013_CPFCNPJ = dgwLista.Rows[y].Cells["TB013_CPFCNPJ"].Value.ToString().Replace(".", "").Replace(",", "").Replace("/", "").Replace("-", "").Trim();

                                Parcela.TB012_id      = Convert.ToInt64(dgwLista.Rows[y].Cells["TB012_id"].Value.ToString());
                                Parcela.TB016_Parcela = i + 1;
                                Parcela.TB016_Emissao = DateTime.Now;



                                Int32 Ano = Convert.ToInt32(cmbPesquisaCiclo.Text.Substring(cmbPesquisaCiclo.Text.Length - 4, 4));
                                Int16 Mes = Convert.ToInt16(cmbPesquisaCiclo.Text.Replace(Ano.ToString(), ""));
                                Ano++;
                                string Ciclo = Mes.ToString() + Ano.ToString();
                                Parcela.TB012_CicloContrato = Convert.ToInt32(Ciclo);

                                Parcela.TB016_FormaPagamentoS = "1";
                                Parcela.TB016_EmitirBoleto    = 1;


                                if (i == 0)
                                {
                                    Parcela.TB016_Vencimento = Convert.ToDateTime(UltimaParcela.TB016_Vencimento.Day + "/" + UltimaParcela.TB016_Vencimento.Month + "/" + UltimaParcela.TB016_Vencimento.Year).AddMonths(1);
                                }
                                else
                                {
                                    Parcela.TB016_Vencimento = Convert.ToDateTime(Parcelas[i - 1].TB016_Vencimento.Day + "/" + Parcelas[i - 1].TB016_Vencimento.Month + "/" + Parcelas[i - 1].TB016_Vencimento.Year).AddMonths(1);
                                }

                                Parcela.TB016_StatusS = "1";

                                //Filtrar Distribuição de major, menor e isento
                                PessoaNegocios Participantes_N = new PessoaNegocios();
                                List <CategoriaIdadeControler> Participantes_L = Participantes_N.MembrosAtivosDoConrato(Convert.ToInt64(dgwLista.Rows[y].Cells["TB012_id"].Value.ToString()), Parcela.TB016_Vencimento);

                                CategoriaIdadeNegocios  CategoriaIdade_N = new CategoriaIdadeNegocios();
                                CategoriaIdadeControler DadosFiltroIdade = CategoriaIdade_N.DistribuicaoIsencaoIdade(Participantes_L);
                                //Localiar Plano's conforme itens de filtro
                                PlanoController        filtro          = new PlanoController();
                                PontoDeVendaController ObjPontoDeVenda = new PontoDeVendaController();
                                filtro.PontoDeVenda = ObjPontoDeVenda;

                                filtro.TB015_Maiores         = DadosFiltroIdade.Maior;
                                filtro.TB015_Menores         = DadosFiltroIdade.Menor;
                                filtro.TB015_Isentos         = DadosFiltroIdade.Isento;
                                filtro.PontoDeVenda.TB002_id = Convert.ToInt64(Convert.ToInt64(dgwLista.Rows[y].Cells["TB002_id"].Value.ToString()));

                                PlanoNegocios Plano_N = new PlanoNegocios();
                                DataSet       Plano   = new DataSet();

                                Plano = Plano_N.PlanoVendaContezino(filtro, 1, 0, 1);

                                Parcela.Plano.TB015_Maiores = filtro.TB015_Maiores;
                                Parcela.Plano.TB015_Menores = filtro.TB015_Menores;
                                Parcela.Plano.TB015_Isentos = filtro.TB015_Isentos;

                                Parcela.Plano.TB015_IOF              = Convert.ToDouble(Plano.Tables[0].Rows[0]["TB015_IOF"].ToString());
                                Parcela.Plano.TB015_TipoVencimento   = Convert.ToInt16(Plano.Tables[0].Rows[0]["TB015_TipoVencimento"].ToString());
                                Parcela.Plano.TB015_EspecieDocumento = Plano.Tables[0].Rows[0]["TB015_EspecieDocumento"].ToString();
                                Parcela.Plano.TB015_BoletoDesc1      = Plano.Tables[0].Rows[0]["TB015_BoletoDesc1"].ToString();
                                Parcela.Plano.TB015_BoletoDesc2      = Plano.Tables[0].Rows[0]["TB015_BoletoDesc2"].ToString();
                                Parcela.Plano.TB015_BoletoDesc3      = Plano.Tables[0].Rows[0]["TB015_BoletoDesc3"].ToString();
                                Parcela.Plano.TB015_BoletoDesc4      = Plano.Tables[0].Rows[0]["TB015_BoletoDesc4"].ToString();
                                Parcela.Plano.TB015_BoletoDesc5      = Plano.Tables[0].Rows[0]["TB015_BoletoDesc5"].ToString();
                                Parcela.TB016_Juros         = Convert.ToDouble(Plano.Tables[0].Rows[0]["TB015_Juros"].ToString());
                                Parcela.TB016_Multa         = Convert.ToDouble(Plano.Tables[0].Rows[0]["TB015_Multa"].ToString());
                                Parcela.TB016_DiaVencimento = Parcela.TB016_Vencimento.Day;



                                //Incluir Planos Possiveis para cada Parcela
                                Parcela.TB016_Valor       = Convert.ToDouble(Plano.Tables[0].Rows[0]["ValorPlano"].ToString());
                                Parcela.TB015_id          = Convert.ToInt64(Plano.Tables[0].Rows[0]["TB015_id"].ToString());
                                Parcela.TB015_Plano       = Plano.Tables[0].Rows[0]["TB015_Plano"].ToString();
                                Parcela.TB016_Entrada     = 0;
                                Parcela.TB016_ValorAdesao = 0;

                                ProdutoNegocios          PlanoProduto_N = new ProdutoNegocios();
                                List <ProdutoController> PlanoProduto_L = PlanoProduto_N.ProdutoPlano(Parcela.TB015_id);

                                //*******************Inserir Parcela
                                foreach (ProdutoController Produto in PlanoProduto_L)
                                {
                                    ParcelaProdutosController ParcelaItem = new ParcelaProdutosController();
                                    ParcelaItem.TB017_id        = Produto.TB014_id;
                                    ParcelaItem.TB017_IdProteus = Produto.TB014_IdProtheus;
                                    ParcelaItem.TB017_Item      = Produto.TB014_Produto;
                                    ParcelaItem.TB017_Maior     = Produto.TB014_Maiores;
                                    ParcelaItem.TB017_Menor     = Produto.TB014_Menores;
                                    ParcelaItem.TB017_Isento    = Produto.TB014_Isentos;

                                    if (Produto.TB014_Menores > 0)
                                    {
                                        Produto.TB014_ValorUnitario = Produto.TB014_ValorUnitario * filtro.TB015_Menores;
                                        ParcelaItem.TB017_Item      = ParcelaItem.TB017_Item + "( * " + filtro.TB015_Menores + ")";
                                    }

                                    if (Produto.TB014_Isentos > 0)
                                    {
                                        ParcelaItem.TB017_Item      = ParcelaItem.TB017_Item + "( * " + filtro.TB015_Isentos + ")";
                                        Produto.TB014_ValorUnitario = Produto.TB014_ValorUnitario * filtro.TB015_Isentos;
                                    }

                                    ParcelaItem.TB017_ValorUnitario = Produto.TB014_ValorUnitario;
                                    if (Produto.TB014_ValorMultiplo == 1)
                                    {
                                        ParcelaItem.TB017_ValorUnitario = (ParcelaItem.TB017_ValorUnitario * ParcelaItem.TB017_Maior) + (ParcelaItem.TB017_ValorUnitario * ParcelaItem.TB017_Menor);
                                        Produto.TB014_ValorUnitario     = (Produto.TB014_ValorUnitario * ParcelaItem.TB017_Maior) + (Produto.TB014_ValorUnitario * ParcelaItem.TB017_Menor);
                                    }

                                    ParcelaItem.TB017_ValorDesconto = 0;

                                    ParcelaItem.TB017_ValorFinal = Produto.TB014_ValorUnitario - ParcelaItem.TB017_ValorDesconto;
                                    string[] vValor = ParcelaItem.TB017_ValorFinal.ToString().Split(',');

                                    string v1 = vValor[0];
                                    string v2 = "0";

                                    if (ParcelaItem.TB017_ValorFinal > 0.01)
                                    {
                                        if (vValor[1].Length > 1)
                                        {
                                            v2 = vValor[1].Substring(0, 2);
                                        }
                                        else
                                        {
                                            v2 = vValor[1];
                                        }
                                    }
                                    ParcelaItem.TB017_ValorFinal = Convert.ToDouble(v1 + "," + v2);

                                    ParcelaItens_L.Add(ParcelaItem);
                                }

                                double Valor = 0;
                                for (int p = 0; p < ParcelaItens_L.Count; p++)
                                {
                                    Valor = Valor + ParcelaItens_L[p].TB017_ValorFinal;
                                }
                                Parcela.TB016_Valor = Valor;

                                /*Inserir Produto da Parcela*/
                                Parcela.ParcelaProduto_L = ParcelaItens_L;

                                Parcelas.Add(Parcela);
                            }

                            Parcela_N.GerarCobrancasParcela(Parcelas, ParametrosInterface.objUsuarioLogado.TB011_Id);
                            /*Alterar Ciclo do contrato*/
                            ContratoNegocios Contrato_N = new ContratoNegocios();
                            Contrato_N.CicloContratoAtualizar(Convert.ToInt64(dgwLista.Rows[y].Cells["TB012_id"].Value.ToString()), Parcelas[0].TB012_CicloContrato, ParametrosInterface.objUsuarioLogado.TB011_Id, UltimaParcela.TB016_Vencimento.AddYears(1));


                            /*Gerar Boletos*/
                            List <ParcelaController> BoletosEmitidos = Parcela_N.ParcelasParaEmissaoBoleto(Convert.ToInt64(dgwLista.Rows[y].Cells["TB012_id"].Value.ToString()), ParametrosInterface.objUsuarioLogado.TB011_Id, 0);
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.Message, "Erro ao executar operação", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }

                        /*****************************************************/
                    }
                }

                /*Atualizar List*/
                PopularListaParaRenovacao();
                lblExportarTotalDeContratos.Text = "Boletos emitidos, pronto para exportar aquivo";
                mnuListaRenovar.Enabled          = true;

                MessageBox.Show("Operação Concluida", "Renovação", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Erro ao executar operação", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }