public void Vender() // Aceitar pedidos realizados pelos clientes { List <Produto> pacote = new List <Produto>(); List <int> ids = new List <int>(); bool venda = false; try{ foreach (Cliente c in clientes) // O processo é realizado pra cada cliente individualmente { pacote.Clear(); pacote.AddRange(c.Vender(produtos)); if (pacote.Count > 0) { double[] coord = new double[2]; coord = c.getCoord(); double frete = Caminhao.CalcularDistancia(0, coord[0], 0, coord[1]) * 0.60; int dist = (int)(Caminhao.CalcularDistancia(0, coord[0], 0, coord[1]) * 0.60); ids.Clear(); ids.Add(0); foreach (Encomenda e in encomendas) { ids.Add(e.getId()); } encomendas.Add(new Encomenda(ids.Max() + 1, pacote, getClientes(c.getNome()), coefLucro, frete, dist)); DownEstoque(pacote); // abater do estoque o que foi vendido venda = true; } } if (venda) { //OrganizarEncomendas(); // Otimizar encomendas, organizando em ordem decrescente por lucratividade Salvar(); Console.WriteLine("Pedidos aceitos!\nEncomendas geradas!\n"); } else { Console.WriteLine("Não há pedidos pendentes\n"); } } catch (IndexOutOfRangeException e) { LogisticaException.ExceptionGrave("LE_IndexOutOfRangeException", e, "Distribuidora", "Vender"); } catch (Exception e) { LogisticaException.ExceptionGrave("LE_ExceptionNaoTratada", e, "Distribuidora", "Vender"); } }
public double getDist(double la, double lo) { return(Caminhao.CalcularDistancia(lat, lon, la, lo)); }
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/>========== DIÁRIO DE ENTREGA =========="); 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"); } }
// 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); } }