示例#1
0
        private void NovoRelatorioEntrega(DadosLog dados, List <Cliente> CliEntrega) //  Cria um pacote de dados para gerar o relatório de entregas
        {
            List <int>       idClientes = new List <int>();
            List <int>       pacote     = new List <int>();
            List <Encomenda> auxEnc     = new List <Encomenda>();
            List <Cliente>   cliAux     = new List <Cliente>();
            string           posicao    = "";

            try {
                posicao = "for(CliEntrega)";
                for (int i = 0; i < CliEntrega.Count; i++)
                {
                    idClientes.Add(CliEntrega[dados.rota[i]].getId());
                }

                posicao = "foreach(encomendas)";
                foreach (Encomenda e in encomendas)
                {
                    if (idClientes.IndexOf(e.getCliente()) != -1)
                    {
                        pacote.Add(e.getId());
                        auxEnc.Add(e);
                    }
                }

                posicao = "foreach(auxEnc)";
                foreach (Encomenda e in auxEnc)
                {
                    encomendas.Remove(e);
                    e.setStatusEntrega(true);
                }
                entregas.AddRange(auxEnc);

                posicao = "foreach(dados.rota)";
                foreach (int r in dados.rota)
                {
                    cliAux.Add(CliEntrega[r]);
                }
                dados.cliOrdem = cliAux;

                posicao = "salvar";
                Salvar();

                posicao        = "diarioEntregas";
                diarioEntregas = new Relatorio(idClientes, pacote, dados.distancia, dados.custo, dados.lucro);
                Console.WriteLine("Novo relatório de entrega gerado.\n");
            }
            catch (IndexOutOfRangeException e) {
                LogisticaException.ExceptionGrave("LE_IndexOutOfRangeException", e, "Distribuidora", "NovoRelatorioEntrega/" + posicao);
            }
            catch (ArgumentNullException e) {
                LogisticaException.ExceptionGrave("LE_Distribuidora_NovoRelatorioEntrega_DiarioEntrega", e, "Distribuidora", "NovoRelatorioEntrega/" + posicao, true);
            }
            catch (Exception e) {
                LogisticaException.ExceptionGrave("LE_ExceptionNaoTratada", e, "Distribuidora", "NovoRelatorioEntrega/" + posicao);
            }
        }
示例#2
0
 private void GuardarRelatorio(DadosLog dados)
 {
     try {
         using (StreamWriter Salvar = File.AppendText(fileRelatorio)) {
             foreach (string r in dados.relatorio)
             {
                 Salvar.Write(r);
             }
             foreach (string m in dados.mapa)
             {
                 Salvar.Write(m);
             }
         }
     }
     catch (Exception e) {
         LogisticaException.ExceptionGrave("LE_Save", e, "Save", "GuardarRelatorio");
     }
 }
示例#3
0
        public void GerarRelatório(DadosLog dados)
        {
            List <string> impressao    = new List <string>();
            List <string> impressaoWeb = new List <string>();
            List <int>    idEnt        = new List <int>();
            List <int>    idCli        = new List <int>();

            int[] memoria = new int[2] {
                -1, -1
            };

            try {
                if (diarioEntregas.getClientes().Count > 0)
                {
                    foreach (Encomenda e in entregas)
                    {
                        idEnt.Add(e.getId());
                    }
                    foreach (Cliente c in clientes)
                    {
                        idCli.Add(c.getId());
                    }

                    impressao.Add("\n==========  DIÁRIO  DE  ENTREGA  ==========");
                    impressaoWeb.Add("<br/>==========&nbsp;&nbsp;DIÁRIO&nbsp;&nbsp;DE&nbsp;&nbsp;ENTREGA&nbsp;&nbsp;==========");

                    System.Threading.Thread.Sleep(20);
                    foreach (int c in diarioEntregas.getClientes())
                    {
                        if (memoria[1] != c)
                        {
                            if ((idCli.IndexOf(c) < 0) || (idCli.IndexOf(c) >= clientes.Count))
                            {
                                throw new LogisticaException("LE_Distribuidora_GerarRelatório_indexClientes");
                            }
                            double[] auxCoord = clientes[idCli.IndexOf(c)].getCoord();
                            impressao.Add("\n\nCliente: ");
                            impressaoWeb.Add("<br/><br/>Cliente: ");
                            impressao.Add(String.Format("{0}", clientes[idCli.IndexOf(c)].getNome()));
                            impressaoWeb.Add(String.Format("{0}", clientes[idCli.IndexOf(c)].getNome()));
                            impressao.Add(" - ID: ");
                            impressaoWeb.Add(" - ID: ");
                            impressao.Add(String.Format("{0}", clientes[idCli.IndexOf(c)].getId()));
                            impressaoWeb.Add(String.Format("{0}", clientes[idCli.IndexOf(c)].getId()));
                            impressao.Add(" | lat ");
                            impressaoWeb.Add(" | lat ");
                            impressao.Add(String.Format("{0}", auxCoord[0]));
                            impressaoWeb.Add(String.Format("{0}", auxCoord[0]));
                            impressao.Add(" - lon ");
                            impressaoWeb.Add(" - lon ");
                            impressao.Add(String.Format("{0}", auxCoord[1]));
                            impressaoWeb.Add(String.Format("{0}", auxCoord[1]));

                            foreach (int e in diarioEntregas.getEntregas())
                            {
                                System.Threading.Thread.Sleep(20);
                                if ((idEnt.IndexOf(e) >= 0) && (entregas[idEnt.IndexOf(e)].getCliente() == c))
                                {
                                    impressao.Add("\nLote ID: ");
                                    impressaoWeb.Add("<br/>Lote ID: ");
                                    impressao.Add(String.Format("{0}", e));
                                    impressaoWeb.Add(String.Format("{0}", e));

                                    foreach (Produto p in entregas[idEnt.IndexOf(e)].getPacote())
                                    {
                                        System.Threading.Thread.Sleep(20);
                                        impressao.Add("\nProduto: ");
                                        impressaoWeb.Add("<br/>Produto: ");
                                        impressao.Add(String.Format("{0}", p.getTipo()));
                                        impressaoWeb.Add(String.Format("{0}", p.getTipo()));
                                        impressao.Add(" | quant: ");
                                        impressaoWeb.Add(" | quant: ");
                                        impressao.Add(String.Format("{0}", p.getQuantidade()));
                                        impressaoWeb.Add(String.Format("{0}", p.getQuantidade()));
                                        impressao.Add(" - preço: ");
                                        impressaoWeb.Add(" - preço: ");
                                        impressao.Add(String.Format("{0}", p.getCusto() * p.getQuantidade()));
                                        impressaoWeb.Add(String.Format("{0}", p.getCusto() * p.getQuantidade()));
                                        impressao.Add(" - peso: ");
                                        impressaoWeb.Add(" - peso: ");
                                        impressao.Add(String.Format("{0}", p.getPeso() * p.getQuantidade()));
                                        impressaoWeb.Add(String.Format("{0}", p.getPeso() * p.getQuantidade()));
                                        impressao.Add(" - vol: ");
                                        impressaoWeb.Add(" - vol: ");
                                        impressao.Add(String.Format("{0}", p.getVolume() * p.getQuantidade()));
                                        impressaoWeb.Add(String.Format("{0}", p.getVolume() * p.getQuantidade()));
                                    }
                                }
                            }
                        }
                        memoria[1] = c;
                    }
                    impressao.Add("\n\nPeso Total: ");
                    impressaoWeb.Add("<br/><br/>Peso Total: ");
                    impressao.Add(String.Format("{0:0.00}", dados.peso));
                    impressaoWeb.Add(String.Format("{0:0.00}", dados.peso));
                    impressao.Add(" kg  | ");
                    impressaoWeb.Add(" kg  | ");
                    impressao.Add(String.Format("{0:0.00}", Caminhao.pesoPercent(dados.peso, dados.containers)));
                    impressaoWeb.Add(String.Format("{0:0.00}", Caminhao.pesoPercent(dados.peso, dados.containers)));

                    impressao.Add("%\nVolume Total: ");
                    impressaoWeb.Add("<br/><br/>Volume Total: ");
                    impressao.Add(String.Format("{0:0.00}", dados.volume));
                    impressaoWeb.Add(String.Format("{0:0.00}", dados.volume));
                    impressao.Add(" m^3  | ");
                    impressaoWeb.Add(" m^3  | ");
                    impressao.Add(String.Format("{0:0.00}", Caminhao.volumePercent(dados.volume, dados.containers)));
                    impressaoWeb.Add(String.Format("{0:0.00}", Caminhao.volumePercent(dados.volume, dados.containers)));

                    impressao.Add("%\nDistância: ");
                    impressaoWeb.Add("<br/><br/>Distância: ");
                    impressao.Add(String.Format("{0:0.00}", diarioEntregas.getDistancia()));
                    impressaoWeb.Add(String.Format("{0:0.00}", diarioEntregas.getDistancia()));
                    impressao.Add("km\nCusto total da viagem: R$:");
                    impressaoWeb.Add("km<br/>Custo total da viagem: R$:");
                    impressao.Add(String.Format("{0:0.00}", diarioEntregas.getCusto()));
                    impressaoWeb.Add(String.Format("{0:0.00}", diarioEntregas.getCusto()));
                    impressao.Add("\nLucro total liquido: R$:");
                    impressaoWeb.Add("<br/>Lucro total liquido: R$:");
                    impressao.Add(String.Format("{0:0.00}", diarioEntregas.getLucro()));
                    impressaoWeb.Add(String.Format("{0:0.00}", diarioEntregas.getLucro()));
                    impressao.Add("\n");
                    impressaoWeb.Add("<br/>");
                }
                else
                {
                    Console.WriteLine("Não há relatório a relatar");
                }

                dados.relatorio    = impressao;
                dados.relatorioWeb = impressaoWeb;
                file.setRelatorio(dados);
                Console.WriteLine("Relatório Impresso!\n");
            }
            catch (LogisticaException) {}
            catch (Exception e) {
                LogisticaException.ExceptionGrave("LE_ExceptionNaoTratada", e, "Distribuidora", "GerarRelatório");
            }
        }
示例#4
0
        //  ENCOMENDAS
        ////////////////////////////////////////////////////////////////////////////////////////////////////////

        ////////////////////////////////////////////////////////////////////////////////////////////////////////
        //  LOGÍSTICA
        public void ComoViajar(int containers)
        {
            DadosLog       dados = new DadosLog();
            Mapeamento     mapa = new Mapeamento();
            List <Cliente> osClientes = new List <Cliente>();     //  Lista com os Clientes atendidos
            List <string>  nomeClientes = new List <string>();    //  Nome dos clientes atendidos
            List <double>  precoPorCliente = new List <double>(); //  Somatorio dos preços das encomendas por cliente
            double         precoTotal = 0;                        //  Valor bruto que vamos receber
            double         volumeTot = 0, pesoTot = 0;            //Peso e  Volume Tot das encomendas que irão na viagem
            bool           erro = false;

            Console.WriteLine("\nGERAR VIAGEM");

            Salvar();
            Carregar();

            try {
                if (!erro)
                {
                    foreach (Encomenda e in encomendas)
                    {
                        if ((e.getVolumeEnc() < ((Caminhao.volumeBau * containers) - volumeTot)) && (e.getPesoEnc() < ((Caminhao.pesoBau * containers) - pesoTot)))
                        {
                            volumeTot += e.getVolumeEnc();
                            pesoTot   += e.getPesoEnc();
                            foreach (Cliente c in clientes)
                            {
                                if (c.getId() == e.getCliente())
                                {
                                    nomeClientes.Add(c.getNome());
                                    osClientes.Add(c);
                                    precoPorCliente.Add(e.getPreco());
                                }
                            }
                        }
                        if (osClientes.Count >= 30)
                        {
                            break;
                        }
                    }
                }
            }
            catch (IndexOutOfRangeException e) {
                LogisticaException.ExceptionGrave("LE_IndexOutOfRangeException", e, "Distribuidora", "ComoViajar/foreach(encomendas)", true);
                erro = true;
            }
            catch (ArgumentOutOfRangeException e) {
                LogisticaException.ExceptionGrave("LE_ArgumentOutOfRangeException", e, "Distribuidora", "ComoViajar/foreach(encomendas)", true);
                erro = true;
            }
            catch (Exception e) {
                LogisticaException.ExceptionGrave("LE_ExceptionNaoTratada", e, "Distribuidora", "ComoViajar/foreach(encomendas)", true);
                erro = true;
            }

            try{
                if (!erro)
                {
                    foreach (double ppc in precoPorCliente)
                    {
                        precoTotal += ppc;
                    }
                }
            }
            catch (Exception e) {
                LogisticaException.ExceptionGrave("LE_ExceptionNaoTratada", e, "Distribuidora", "ComoViajar/foreach(precoPorCliente)", true);
                erro = true;
            }

            try {
                if (!erro)
                {
                    double[,] cliMapa = new double[2, osClientes.Count];
                    for (int i = 0; i < osClientes.Count; i++)
                    {
                        cliMapa[0, i] = osClientes[i].getLat();
                        cliMapa[1, i] = osClientes[i].getLon();
                    }
                    if (osClientes.Count > 0)
                    {
                        statusMapeamento = true;
                        dados            = mapa.Iniciar(cliMapa, osClientes.Count);
                        if (!statusMapeamento)
                        {
                            throw new LogisticaException("LE_Main_ErroMapeamento");
                        }
                        dados.custo      = (dados.distancia / (Caminhao.eficMotor * (1 - dados.containers / 10))) * 3.686 + Caminhao.CalcularDiariaMotorista(dados.distancia); //  preço do diesel 3,686
                        dados.lucro      = precoTotal - dados.custo;                                                                                                           //dados.custo - (dados.custo/1.4);
                        dados.containers = containers;
                        dados.peso       = pesoTot;
                        dados.volume     = volumeTot;
                        Salvar();

                        NovoRelatorioEntrega(dados, osClientes);
                        GerarRelatório(dados);
                        EnviarRelatorioEmail(dados.relatorioWeb);
                    }
                    else
                    {
                        if (encomendas.Count == 0)
                        {
                            Console.WriteLine("Não há encomendas pendentes no momento");
                        }
                        else
                        {
                            Console.WriteLine("Não é possivel fechar nenhuma encomenda no momento\nFavor verificar as condições de transporte do veiculo");
                        }
                    }
                }
            }
            catch (LogisticaException) {}
            catch (IndexOutOfRangeException e) {
                LogisticaException.ExceptionGrave("LE_IndexOutOfRangeException", e, "Distribuidora", "ComoViajar/dados", true);
            }
            catch (ArgumentOutOfRangeException e) {
                LogisticaException.ExceptionGrave("LE_ArgumentOutOfRangeException", e, "Distribuidora", "ComoViajar/dados", true);
            }
            catch (Exception e) {
                LogisticaException.ExceptionGrave("LE_ExceptionNaoTratada", e, "Distribuidora", "ComoViajar/dados", true);
            }
        }
示例#5
0
 public void setRelatorio(DadosLog dados)
 {
     System.IO.File.Delete(fileRelatorio);
     System.Threading.Thread.Sleep(5);
     GuardarRelatorio(dados);
 }