Esempio n. 1
0
        protected virtual Rota LoadFromControls()
        {
            Rota rota = new Rota();

            if (!string.IsNullOrEmpty(txtId.Text))
            {
                rota.id = Convert.ToInt64(txtId.Text);
            }

            rota.id_transportadora = Convert.ToInt64(cbTransportadora.SelectedValue);
            rota.id_cidade         = Convert.ToInt32(cbCidade.SelectedValue);

            rotaBLL = new RotaBLL();

            List <Rota> RotaList = rotaBLL.getRota(p => p.id_transportadora == rota.id_transportadora & p.id_cidade == rota.id_cidade);

            if (RotaList.Count > 0)
            {
                rota                   = RotaList.First();
                rota.id_cidade         = Convert.ToInt64(cbCidade.SelectedValue);
                rota.id_transportadora = Convert.ToInt64(cbTransportadora.SelectedValue);
                Id = rota.id;
            }

            return(rota);
        }
Esempio n. 2
0
        protected override void carregaConsulta()
        {
            rotaBLL = new RotaBLL();
            base.carregaConsulta();
            dgvDados.DataSource = null;
            List <Rota> RotaList = rotaBLL.getRota(p => p.id.ToString(), false, deslocamento, tamanhoPagina, out totalReg);

            dgvDados.DataSource = rotaBLL.ToList_RotaView(RotaList);
            colOrdem            = 0;
        }
Esempio n. 3
0
        public IActionResult NovaRota2(int?id)
        {
            Rota   rota = new Rota();
            string mensagemErro;

            if (id.HasValue && id > 0)
            {
                rota = RotaBLL.selectRotas((int)id, out mensagemErro).FirstOrDefault();
            }

            return(View(rota));
        }
Esempio n. 4
0
        public JsonResult AtualizarRotaManual(int codigoInstrutor, string arrayPedidosRota, string arrayPedidosAprovados, string observacaoRota)
        {
            RoteirizacaoBLL              roteirizacaoBLL    = new RoteirizacaoBLL();
            CabecalhoPedidoBLL           cabecalhoPedidoBLL = new CabecalhoPedidoBLL();
            NotificacoesBLL              notificacoesBLL    = new NotificacoesBLL();
            string                       mensagemErro;
            List <RotaComplexaViewModel> listaPedidos          = JsonConvert.DeserializeObject <List <RotaComplexaViewModel> >(arrayPedidosRota);
            List <RotaComplexaViewModel> listaPedidosAprovados = JsonConvert.DeserializeObject <List <RotaComplexaViewModel> >(arrayPedidosAprovados);

            var codigoUsuario = Convert.ToInt32(HttpContext.Request.Cookies["CODIGO_USUARIO"]);

            //INCLUIR CABECALHO ROTA
            Rota rota = new Rota();

            rota.Instrutor = new Funcionario()
            {
                Codigo = codigoInstrutor
            };
            rota.DataInicio = Convert.ToDateTime(listaPedidos.Min(x => x.dataInicioTreinamento));
            rota.DataFim    = Convert.ToDateTime(listaPedidos.Min(x => x.dataFimTreinamento));
            rota.Observacao = observacaoRota;

            rota.Codigo = RotaBLL.insertRota(rota, out mensagemErro);

            if (rota.Codigo <= 0)
            {
                return(Json(new { sucesso = false, mensagemErro = mensagemErro }));
            }

            //INCLUIR ITENS ROTA
            foreach (RotaComplexaViewModel pedido in listaPedidos)
            {
                ItemRota itemRota = new ItemRota();
                itemRota.Rota            = rota;
                itemRota.CabecalhoPedido = new CabecalhoPedido()
                {
                    Codigo = pedido.codigoPedido
                };
                itemRota.DataInicio = Convert.ToDateTime(pedido.dataFimTreinamento);
                itemRota.DataFim    = Convert.ToDateTime(pedido.dataFimTreinamento);
                itemRota.Aprovado   = (listaPedidosAprovados.Where(x => x.codigoPedido == pedido.codigoPedido).Count() > 0);

                if (ItemRotaBLL.insertItemRota(itemRota, out mensagemErro) <= 0)
                {
                    return(Json(new { sucesso = false, mensagemErro = mensagemErro }));
                }
            }

            TempData["mensagemSucesso"] = "Rota criada com sucesso!";

            return(Json(new { sucesso = true }));
        }
Esempio n. 5
0
        protected override void excluirRegistro(int Id)
        {
            base.excluirRegistro(Id);

            rotaBLL = new RotaBLL();

            if (Convert.ToInt32(dgvDados[0, dgvDados.CurrentRow.Index].Value) > 0)
            {
                Rota rota = rotaBLL.Localizar(Convert.ToInt32(dgvDados[0, dgvDados.CurrentRow.Index].Value));
                if (MessageBox.Show("Deseja realmente excluir o registro : " + rota.cliente.nome_fantasia + " - " + rota.cidade.cNome, Text, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    rotaBLL.ExcluirRota(rota);
                }
            }
        }
Esempio n. 6
0
        protected override void LoadToControls()
        {
            if (Id != null)
            {
                rotaBLL = new RotaBLL();

                Rota rota = rotaBLL.Localizar(Id);

                if (rota != null)
                {
                    txtId.Text = rota.id.ToString();
                    cbTransportadora.SelectedValue = rota.cliente.Id;
                    cbUF.Text = rota.cidade.cUF;
                    SetupCidade(rota.cidade.cUF);
                    cbCidade.SelectedValue = rota.cidade.Id;
                }
            }
        }
Esempio n. 7
0
        public IActionResult NovaRotaManual(int?codigoRota)
        {
            string mensagemErro;

            var vm = new RotaViewModel();

            if (codigoRota.HasValue && codigoRota > 0)
            {
                vm.Rota           = RotaBLL.selectRotas(Convert.ToInt32(codigoRota), out mensagemErro).FirstOrDefault();
                vm.listaItensRota = ItemRotaBLL.selectItensRota(Convert.ToInt32(codigoRota), out mensagemErro);

                return(View(vm));
            }
            else
            {
                return(View(vm));
            }
        }
Esempio n. 8
0
        public JsonResult CriarAtualizarNovaRota(int?codigoRota, int codigoInstrutor, string observacao)
        {
            string mensagemErro;

            Rota rota = new Rota();

            rota.Codigo    = codigoRota;
            rota.Instrutor = new Funcionario()
            {
                Codigo = codigoInstrutor
            };
            rota.DataInicio = DateTime.Now;
            rota.DataFim    = DateTime.Now;
            rota.Observacao = observacao;



            if (rota.Codigo.HasValue && rota.Codigo > 0)
            {
                var listaItensRota = ItemRotaBLL.selectItensRota((int)rota.Codigo, out mensagemErro);

                if (listaItensRota != null && listaItensRota.Count > 0)
                {
                    rota.DataInicio = listaItensRota.Min(x => x.DataInicio);

                    rota.DataFim = listaItensRota.Max(x => x.DataFim);
                }

                RotaBLL.updateRota(rota, out mensagemErro);
            }
            else
            {
                codigoRota = RotaBLL.insertRota(rota, out mensagemErro);
            }

            if (String.IsNullOrEmpty(mensagemErro))
            {
                return(Json(new { sucesso = true, codigoRota = codigoRota }));
            }
            else
            {
                return(Json(new { sucesso = false, mensagemErro = mensagemErro }));
            }
        }
Esempio n. 9
0
        public IActionResult ConsutarRotasInstrutor(int?txtCodigoRotaFiltro, int?ddlInstrutorFiltro, int?ddlCidadesFiltro, DateTime?dataInicioFiltro, DateTime?dataFinalFiltro)
        {
            string mensagemErro;

            List <Rota> listaRotas = RotaBLL.selectRotasByInstrutor(txtCodigoRotaFiltro, ddlInstrutorFiltro, ddlCidadesFiltro, dataInicioFiltro, dataFinalFiltro, out mensagemErro);

            if (!String.IsNullOrEmpty(mensagemErro))
            {
                TempData["mensagemErro"] = mensagemErro;
                return(View(new List <Rota>()));
            }

            if (listaRotas.Count == 0)
            {
                TempData["mensagemAlerta"] = "Nenhum registro encontrado para o filtro informado!";
            }

            return(View("RelatorioRotasCriadas", listaRotas));
        }
Esempio n. 10
0
        private void ComboBox_SelectionChangeCommitted(object sender, EventArgs e)
        {
            ComboBox cb = (ComboBox)sender;

            string value = string.Empty;

            value = cb.SelectedValue.ToString();

            Expression <Func <Rota, bool> > predicate = p => true;

            if (!string.IsNullOrEmpty(value))
            {
                predicate = predicate.And(p => p.cidade.cUF == value & p.cliente.cliente_tag.Any(c => c.tag == "Transportadora"));
            }

            rotaBLL = new RotaBLL();
            List <Rota> RotaList = rotaBLL.getRota(predicate.Expand(), t => t.id.ToString(), false, deslocamento, tamanhoPagina, out totalReg);

            dgvDados.DataSource = rotaBLL.ToList_RotaView(RotaList);
        }
Esempio n. 11
0
        protected override bool salvar(object sender, EventArgs e)
        {
            bool Retorno = epValidaDados.Validar(true);

            if (Retorno)
            {
                try
                {
                    rotaBLL = new RotaBLL();
                    rotaBLL.UsuarioLogado = Program.usuario_logado;

                    Rota rota = LoadFromControls();

                    if (Id != null)
                    {
                        rotaBLL.AlterarRota(rota);
                    }
                    else
                    {
                        rotaBLL.AdicionarRota(rota);
                    }

                    if (rota.id != 0)
                    {
                        Id         = rota.id;
                        txtId.Text = rota.id.ToString();
                    }

                    Retorno = true;
                }
                catch (Exception ex)
                {
                    Retorno = false;
                    throw ex;
                }
            }
            return(Retorno);
        }
Esempio n. 12
0
        protected override void executeCellEndEditChild(object sender, DataGridViewCellEventArgs e)
        {
            base.executeCellEndEditChild(sender, e);

            rotaBLL = new RotaBLL();

            int    id             = 0;
            string transportadora = string.Empty;
            string uf             = string.Empty;
            string cidade         = string.Empty;

            if (dgvFiltro[col_Id, e.RowIndex].Value != null)
            {
                if (!string.IsNullOrEmpty((string)dgvFiltro[col_Id, e.RowIndex].Value.ToString()))
                {
                    id = Convert.ToInt32(dgvFiltro[col_Id, e.RowIndex].Value);
                }
            }

            if (dgvFiltro[col_transportadora, e.RowIndex].Value != null)
            {
                if (!string.IsNullOrEmpty((string)dgvFiltro[col_transportadora, e.RowIndex].Value))
                {
                    transportadora = dgvFiltro[col_transportadora, e.RowIndex].Value.ToString();
                }
            }

            if (dgvFiltro[col_uf, e.RowIndex].Value != null)
            {
                if (!string.IsNullOrEmpty((string)dgvFiltro[col_uf, e.RowIndex].Value))
                {
                    uf = dgvFiltro[col_uf, e.RowIndex].Value.ToString();
                }
            }

            if (dgvFiltro[col_cidade, e.RowIndex].Value != null)
            {
                if (!string.IsNullOrEmpty((string)dgvFiltro[col_cidade, e.RowIndex].Value))
                {
                    cidade = dgvFiltro[col_cidade, e.RowIndex].Value.ToString();
                }
            }


            Expression <Func <Rota, bool> > predicate = p => true;


            if (id > 0)
            {
                predicate = predicate = p => p.id == id;
            }

            if (!string.IsNullOrEmpty(transportadora))
            {
                predicate = predicate.And(p => p.cliente.razao_social.Contains(transportadora) & p.cliente.cliente_tag.Any(c => c.tag == "Transportadora"));
            }

            if (!string.IsNullOrEmpty(uf))
            {
                predicate = predicate.And(p => p.cidade.cUF.Contains(uf));
            }

            if (!string.IsNullOrEmpty(cidade))
            {
                predicate = predicate.And(p => p.cidade.cNome.ToLower().Contains(cidade.ToLower()));
            }

            List <Rota> RotaList = rotaBLL.getRota(predicate.Expand(), t => t.id.ToString(), false, deslocamento, tamanhoPagina, out totalReg);

            dgvDados.DataSource = rotaBLL.ToList_RotaView(RotaList);
        }
Esempio n. 13
0
        protected override void ordenaCelula(object sender, DataGridViewCellMouseEventArgs e)
        {
            base.ordenaCelula(sender, e);

            rotaBLL = new RotaBLL();

            List <Rota> RotaList;

            DataGridViewColumn col    = dgvFiltro.Columns[e.ColumnIndex];
            DataGridViewColumn colAnt = dgvFiltro.Columns[colOrdem];

            ListSortDirection direction;

            switch (col.HeaderCell.SortGlyphDirection)
            {
            case SortOrder.None:
                direction = ListSortDirection.Ascending;
                break;

            case SortOrder.Ascending:
                direction = ListSortDirection.Ascending;
                break;

            case SortOrder.Descending:
                direction = ListSortDirection.Descending;
                break;

            default:
                direction = ListSortDirection.Ascending;
                break;
            }


            if (colOrdem == e.ColumnIndex)
            {
                if (direction == ListSortDirection.Ascending)
                {
                    direction = ListSortDirection.Descending;
                }
                else
                {
                    direction = ListSortDirection.Ascending;
                    col.HeaderCell.SortGlyphDirection = SortOrder.None;
                }
            }
            else
            {
                direction = ListSortDirection.Ascending;
                colAnt.HeaderCell.SortGlyphDirection = SortOrder.None;
            }

            switch (e.ColumnIndex)
            {
            case col_transportadora:
            {
                RotaList = rotaBLL.getRota(x => x.cliente.cliente_tag.Any(c => c.tag == "Transportadora"), p => p.cliente.razao_social, direction != ListSortDirection.Ascending, deslocamento, tamanhoPagina, out totalReg);
            }
            break;

            case col_uf:
            {
                RotaList = rotaBLL.getRota(x => x.cliente.cliente_tag.Any(c => c.tag == "Transportadora"), p => p.cidade.cUF, direction != ListSortDirection.Ascending, deslocamento, tamanhoPagina, out totalReg);
            }
            break;

            case col_cidade:
            {
                RotaList = rotaBLL.getRota(x => x.cliente.cliente_tag.Any(c => c.tag == "Transportadora"), p => p.cidade.cNome, direction != ListSortDirection.Ascending, deslocamento, tamanhoPagina, out totalReg);
            }
            break;

            //O default será executado quando o index for 0
            default:
            {
                RotaList = rotaBLL.getRota(x => x.cliente.cliente_tag.Any(c => c.tag == "Transportadora"), p => p.id.ToString(), direction != ListSortDirection.Ascending, deslocamento, tamanhoPagina, out totalReg);
            }
            break;
            }

            dgvDados.DataSource = rotaBLL.ToList_RotaView(RotaList);

            colOrdem = e.ColumnIndex;

            col.HeaderCell.SortGlyphDirection = direction == ListSortDirection.Ascending ?
                                                SortOrder.Ascending : SortOrder.Descending;
        }
Esempio n. 14
0
        private void LoadDadosCliente(long?id = null, string CodInteg = "")
        {
            clienteBLL = new ClienteBLL();
            Cliente cliente = new Cliente();

            if (id != null)
            {
                cliente = clienteBLL.Localizar(id);
            }
            else if (!string.IsNullOrEmpty(CodInteg))
            {
                if (CodInteg.Where(c => char.IsNumber(c)).Count() >= 11)
                {
                    string strCPF, strCNPJ = string.Empty;
                    strCPF  = Convert.ToInt64(CodInteg).ToString(@"000\.000\.000\-00");
                    strCNPJ = Convert.ToInt64(CodInteg).ToString(@"00\.000\.000\/0000\-00");
                    cliente = clienteBLL.getCliente(p => p.cnpj_cpf == strCPF || p.cnpj_cpf == strCNPJ).FirstOrDefault();
                }
                else if ((CodInteg.Where(c => char.IsNumber(c)).Count() > 0) && (CodInteg.Where(c => char.IsNumber(c)).Count() < 11))
                {
                    cliente = clienteBLL.getCliente(p => p.codigo_cliente_integracao == CodInteg).FirstOrDefault();
                }
            }

            if (cliente != null)
            {
                txtIdCliente.Text        = cliente.Id.ToString();
                txtCodCliIntegracao.Text = cliente.codigo_cliente_integracao;
                txtClienteNome.Text      = cliente.nome_fantasia;
                if (cliente.cliente_parcela.Count() > 0)
                {
                    cbCondPagamento.SelectedValue = cliente.cliente_parcela.FirstOrDefault().Id_parcela;
                }

                if (Id == null)
                {
                    txtDtEmissao.Text = DateTime.Now.ToShortDateString();
                }

                if (cliente.cliente_transportadora.Count() > 0)
                {
                    Cliente_Transportadora cliente_Transportadora = cliente.cliente_transportadora.First();
                    if (cliente_Transportadora != null)
                    {
                        cbTransportadora.SelectedValue = cliente_Transportadora.Id_transportadora;
                    }
                    else
                    {
                        //Vamos sugerir a transportadora pela localidade do cliente.
                        RotaBLL rotaBLL = new RotaBLL();
                        Rota    rota    = rotaBLL.getRota(p => p.cidade.cNome == cliente.cidade).First();
                        if (rota != null)
                        {
                            cbTransportadora.SelectedValue = rota.id_transportadora;
                        }
                    }
                }


                txtDtFechamento.Focus();
            }
        }
Esempio n. 15
0
        private void ExecutaPesquisaCliente()
        {
            frmPesquisaClientes pesquisa = new frmPesquisaClientes();

            if (pesquisa.ExibeDialogo(txtCodCliIntegracao.Text) == DialogResult.OK)
            {
                if (pesquisa.Id != null)
                {
                    clienteBLL = new ClienteBLL();
                    Cliente cliente = clienteBLL.Localizar(pesquisa.Id);
                    if (cliente != null)
                    {
                        txtCodCliIntegracao.Text = cliente.codigo_cliente_integracao;
                        txtClienteNome.Text      = cliente.nome_fantasia;
                        txtIdCliente.Text        = cliente.Id.ToString();

                        Cliente_Parcela cliente_Parcela = cliente.cliente_parcela.FirstOrDefault();
                        if (cliente_Parcela != null)
                        {
                            cbCondPagamento.SelectedValue = cliente_Parcela.Id_parcela;
                        }
                        if (Id == null)
                        {
                            txtDtEmissao.Text = DateTime.Now.ToShortDateString();
                        }

                        if (cliente.cliente_transportadora.Count() > 0)
                        {
                            Cliente_Transportadora cliente_Transportadora = cliente.cliente_transportadora.First();
                            if (cliente_Transportadora != null)
                            {
                                cbTransportadora.SelectedValue = cliente_Transportadora.Id_transportadora;
                            }
                        }
                        else
                        {
                            //Vamos sugerir a transportadora pela localidade do cliente.
                            RotaBLL      rotaBLL  = new RotaBLL();
                            IList <Rota> RotaList = rotaBLL.getRota(p => p.cidade.cCod == cliente.cidade);
                            if (RotaList.Count > 0)
                            {
                                cbTransportadora.SelectedValue = RotaList.First().id_transportadora;
                            }
                        }

                        if (cliente.cliente_vendedor.Count() > 0)
                        {
                            Cliente_Vendedor cliente_Vendedor = cliente.cliente_vendedor.First();
                            if (cliente_Vendedor != null)
                            {
                                cbVendedor.SelectedValue = cliente_Vendedor.Id_Vendedor;
                            }
                        }
                        else
                        {
                            //Vamos sugerir a transportadora pela localidade do cliente.
                            vendedor_LocalidadeBLL = new Vendedor_LocalidadeBLL();
                            IList <Vendedor_Localidade> vendlocList = vendedor_LocalidadeBLL.getVendedor_Localidade(p => p.cidade.cCod == cliente.cidade);

                            if (vendlocList.Count > 0)
                            {
                                cbVendedor.SelectedValue = vendlocList.First().Id_vendedor;
                            }
                        }


                        txtDtFechamento.Focus();
                    }
                }
                else
                {
                    MessageBox.Show("Cliente não localizado.", Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    txtCodCliIntegracao.Text = String.Empty;
                }
            }
            else
            {
                txtCodCliIntegracao.Focus();
            }
        }