예제 #1
0
        private void btnSalvar_Click(object sender, EventArgs e)
        {
            try
            {
                model      set = new model();
                DtoDestino d   = new DtoDestino();
                d.nome           = textBoxNome.Text;
                d.documento      = textBoxDocumento.Text;
                d.endereco       = textBoxEndereco.Text;
                d.latitude       = Convert.ToDouble(textBoxLatitude.Text, CultureInfo.InvariantCulture);
                d.longitude      = Convert.ToDouble(textBoxLongitude.Text, CultureInfo.InvariantCulture);
                d.transportadora = textBoxTransportadora.Text;
                d.bairro         = textBoxBairro.Text;
                d.duracao        = textBoxDuracao.Text;
                d.distancia      = Convert.ToDouble(textBoxDistancia.Text, CultureInfo.InvariantCulture);
                d.status         = "I";

                if (textBoxID.Text == "")
                {
                    set.setDestino(d);
                }
                else
                {
                    set.AlteraDestino(d);
                }
                MessageBox.Show("Registro salvo com sucesso");

                CarregaDestinos();
                limpaCampos();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
예제 #2
0
        private List <DtoDestino> Calcular(List <DtoDestino> listdestinos)
        {
            List <DtoDestino> list = new List <DtoDestino>();

            list.Add(listdestinos[0]);
            listdestinos.Remove(listdestinos[0]);
            int        tamanhoDaLista = listdestinos.Count;
            double     distanciamenor = 0;
            int        indice         = 0;
            DtoDestino menor          = new DtoDestino();

            while (indice < tamanhoDaLista)
            {
                var locA = new GeoCoordinate(list[indice].latitude, list[indice].longitude);
                for (int i = 0; i < listdestinos.Count; i++)
                {
                    var    locB     = new GeoCoordinate(listdestinos[i].latitude, listdestinos[i].longitude);
                    double distance = locA.GetDistanceTo(locB); // metros
                    if (i == 0)
                    {
                        menor          = listdestinos[i];
                        distanciamenor = distance;
                    }
                    else if (distance < distanciamenor)
                    {
                        menor          = listdestinos[i];
                        distanciamenor = distance;
                    }
                }
                list.Add(menor);
                listdestinos.Remove(menor);
                indice++;
            }
            return(list);
        }
예제 #3
0
        public void DeleteDestino(string text)
        {
            Context    db  = new Context();
            DtoDestino des = db.destino.FirstOrDefault(p => p.documento == text);

            db.destino.Remove(des);
            db.SaveChanges();
        }
예제 #4
0
        public void addRota(int id, int idRota, string status)
        {
            Context    db  = new Context();
            DtoDestino des = db.destino.FirstOrDefault(p => p.id == id);

            des.id_rota = idRota;
            des.status  = status;
            db.SaveChanges();
        }
예제 #5
0
        public void ArquivoTXT(string[] theLines)
        {
            progressBar1.Maximum = theLines.Count();
            progressBar1.Minimum = 0;
            for (int i = 0; i < theLines.Count(); i++)
            {
                progressBar1.Value = i;
                DtoDestino destino = new DtoDestino();
                destino.transportadora = theLines[0];
                if (theLines[i].Contains("NF:"))
                {
                    if (theLines[i].Substring(3).Length > 30)
                    {
                        destino.documento = theLines[i].Substring(3, 30);
                    }
                    else
                    {
                        destino.documento = theLines[i].Substring(3);
                    }
                    destino.nome = theLines[i + 1];
                    model   get             = new model();
                    Boolean existeDocumento = get.getDestinoDocumento(destino.documento, destino.transportadora);
                    if (!existeDocumento)
                    {
                        int    posicao      = theLines[i + 2].IndexOf("-");
                        string bairro       = theLines[i + 2].Substring(posicao + 2);
                        int    posicaofinal = bairro.IndexOf("-");
                        destino.bairro   = bairro.Substring(0, 7);
                        destino.endereco = theLines[i + 2].Replace('-', ',');

                        model      m       = new model();
                        DtoLatLong latlong = m.GetLatLongGoogle(destino.endereco);

                        try
                        {
                            destino.latitude  = double.Parse(latlong.latitude, CultureInfo.InvariantCulture);
                            destino.longitude = double.Parse(latlong.longitude, CultureInfo.InvariantCulture);
                            destino.distancia = Convert.ToDouble(latlong.distancia, CultureInfo.InvariantCulture);
                            destino.duracao   = latlong.duracao;
                        }
                        catch (Exception)
                        {
                            destino.status = "E";
                        }
                        destino.status = "I";
                        model post = new model();
                        post.set(destino);
                    }
                }
            }
        }
예제 #6
0
        public FrmDestino(string valor)
        {
            InitializeComponent();
            model      get = new model();
            DtoDestino d   = get.getDestinoDocumento(valor);

            textBoxID.Text             = d.id.ToString();
            textBoxNome.Text           = d.nome;
            textBoxDocumento.Text      = d.documento;
            textBoxEndereco.Text       = d.endereco;
            textBoxLatitude.Text       = d.latitude.ToString();
            textBoxLongitude.Text      = d.longitude.ToString();
            textBoxTransportadora.Text = d.transportadora;
            textBoxBairro.Text         = d.bairro;
        }
예제 #7
0
        public void AlteraDestino(DtoDestino d)
        {
            Context    db  = new Context();
            DtoDestino des = db.destino.FirstOrDefault(p => p.documento == d.documento);

            des.nome           = d.nome;
            des.documento      = d.documento;
            des.endereco       = d.endereco;
            des.latitude       = d.latitude;
            des.longitude      = d.longitude;
            des.bairro         = d.bairro;
            des.duracao        = d.duracao;
            des.distancia      = d.distancia;
            des.transportadora = d.transportadora;
            db.SaveChanges();
        }
예제 #8
0
 public void set(DtoDestino destino)
 {
     try
     {
         Context db = new Context();
         if (destino.endereco != null)
         {
             db.destino.Add(destino);
         }
         db.SaveChanges();
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
예제 #9
0
        private void dataGridView1_DoubleClick(object sender, EventArgs e)
        {
            int ID = (Int32)dataGridView1.CurrentRow.Cells[0].Value;

            model      get = new model();
            DtoDestino d   = get.getDestinoId(ID);

            textBoxID.Text             = d.id.ToString();
            textBoxNome.Text           = d.nome;
            textBoxDocumento.Text      = d.documento;
            textBoxEndereco.Text       = d.endereco;
            textBoxLatitude.Text       = d.latitude.ToString();
            textBoxLongitude.Text      = d.longitude.ToString();
            textBoxTransportadora.Text = d.transportadora;
            textBoxBairro.Text         = d.bairro;
        }
예제 #10
0
        public void setDestino(DtoDestino d)
        {
            Context    db  = new Context();
            DtoDestino des = new DtoDestino();

            des.nome           = d.nome;
            des.documento      = d.documento;
            des.endereco       = d.endereco;
            des.latitude       = d.latitude;
            des.longitude      = d.longitude;
            des.distancia      = d.distancia;
            des.duracao        = d.duracao;
            des.bairro         = d.bairro;
            des.status         = d.status;
            des.transportadora = d.transportadora;
            db.destino.Add(des);
            db.SaveChanges();
        }
예제 #11
0
        private void Jadlog(string[] theLines)
        {
            try
            {
                progressBar1.Maximum = theLines.Count();
                progressBar1.Minimum = 0;

                for (int i = 0; i < theLines.Count(); i++)
                {
                    progressBar1.Value = i;
                    if (theLines[i].Contains("Nome") && theLines[i].Contains("Cep"))
                    {
                        DtoDestino destino = new DtoDestino();
                        destino.transportadora = "JADLOG";
                        if (theLines[i].Contains("NomeNome"))
                        {
                            destino.documento = theLines[i].Substring(9, 14);
                        }
                        else
                        {
                            destino.documento = theLines[i].Substring(5, 14);
                        }
                        model   get             = new model();
                        Boolean existeDocumento = get.getDestinoDocumento(destino.documento, destino.transportadora);

                        if (!existeDocumento)
                        {
                            destino.nome = theLines[i + 1].Substring(0, 29);
                            int posicao       = theLines[i + 1].IndexOf("-");
                            int posicaobairro = (theLines[i - 1].IndexOf("-")) + 1;

                            string bairro = theLines[i - 1].Substring(posicaobairro);
                            destino.bairro   = bairro;
                            destino.endereco = theLines[i + 1].Substring(posicao + 1).Replace('/', ',') + "," + bairro + ",Toledo, PR";

                            model      m       = new model();
                            DtoLatLong latlong = m.GetLatLongGoogle(destino.endereco);

                            try
                            {
                                destino.latitude  = double.Parse(latlong.latitude, CultureInfo.InvariantCulture);
                                destino.longitude = double.Parse(latlong.longitude, CultureInfo.InvariantCulture);
                                destino.distancia = Convert.ToDouble(latlong.distancia, CultureInfo.InvariantCulture);
                                destino.duracao   = latlong.duracao;
                            }
                            catch (Exception)
                            {
                                destino.status = "E";
                            }
                            destino.status = "I";
                            model post = new model();
                            post.set(destino);
                        }
                    }
                }
                CarregarDestinos();
                progressBar1.Visible = false;
            }
            catch (Exception ex)
            {
            }
        }
예제 #12
0
        private void TotalExpress(string[] theLines)
        {
            try
            {
                progressBar1.Maximum = theLines.Count();
                progressBar1.Minimum = 0;
                int linha = 0;
                foreach (var l in theLines)
                {
                    linha++;
                    progressBar1.Value = linha;
                    if (linha >= 15 && linha < 48)
                    {
                        string     theLine = l.ToLower();
                        DtoDestino destino = new DtoDestino();
                        destino.transportadora = "TotalExpress";

                        string nrLinha = theLine.Substring(0, 2);
                        if (nrLinha.Trim().Length == 1)
                        {
                            destino.documento = theLine.Substring(20, 9);
                            destino.nome      = theLine.Substring(35);
                            int posicao = theLine.IndexOf("/") + 2;
                            if (theLine.Substring(posicao).Length > 30)
                            {
                                destino.bairro = theLine.Substring(posicao, 30).ToUpper();
                            }
                            else
                            {
                                destino.bairro = theLine.Substring(posicao).ToUpper();
                            }

                            model   get             = new model();
                            Boolean existeDocumento = get.getDestinoDocumento(destino.documento, destino.transportadora);

                            if (!existeDocumento)
                            {
                                if (theLine.Contains("avenida"))
                                {
                                    int posicaoAvenia = theLine.IndexOf("avenida");
                                    destino.endereco = theLine.Substring(posicaoAvenia).Replace('/', ',') + ",Toledo, PR";
                                }
                                else
                                if (theLine.Contains("rua"))
                                {
                                    int posicaoRua = theLine.IndexOf("rua");
                                    destino.endereco = theLine.Substring(posicaoRua).Replace('/', ',') + ",Toledo, PR";
                                }
                                else
                                {
                                    destino.endereco = theLine.Substring(61).Replace('/', ',') + ",Toledo, PR";
                                }
                                try
                                {
                                    model      getlatlng = new model();
                                    DtoLatLong latlong   = getlatlng.GetLatLongGoogle(destino.endereco);
                                    destino.latitude  = Convert.ToDouble(latlong.latitude, CultureInfo.InvariantCulture);
                                    destino.longitude = Convert.ToDouble(latlong.longitude, CultureInfo.InvariantCulture);
                                    destino.distancia = Convert.ToDouble(latlong.distancia, CultureInfo.InvariantCulture);
                                    destino.duracao   = latlong.duracao;
                                }
                                catch (Exception ex)
                                {
                                    destino.status = "E";
                                }
                            }
                        }
                        else
                        {
                            destino.documento = theLine.Substring(20, 9);
                            destino.nome      = theLine.Substring(36);
                            int posicao = theLine.IndexOf("/") + 2;
                            if (theLine.Substring(posicao).Length > 30)
                            {
                                destino.bairro = theLine.Substring(posicao, 30).ToUpper();
                            }

                            destino.documento = theLine.Substring(20, 9);
                            model   get             = new model();
                            Boolean existeDocumento = get.getDestinoDocumento(destino.documento, destino.transportadora);

                            if (!existeDocumento)
                            {
                                if (theLine.Contains("avenida"))
                                {
                                    int posicaoAvenia = theLine.IndexOf("avenida");
                                    destino.endereco = theLine.Substring(posicaoAvenia).Replace('/', ',') + ",Toledo, PR";
                                }
                                else
                                if (theLine.Contains("rua"))
                                {
                                    int posicaoRua = theLine.IndexOf("rua");
                                    destino.endereco = theLine.Substring(posicaoRua).Replace('/', ',') + ",Toledo, PR";
                                }
                                else if (theLine.Contains("rodovia"))
                                {
                                    int posicaoRua = theLine.IndexOf("rodovia");
                                    destino.endereco = theLine.Substring(posicaoRua).Replace('/', ',') + ",Toledo, PR";
                                }
                                else
                                {
                                    destino.endereco = theLine.Substring(61).Replace('/', ',') + ",Toledo, PR";
                                }
                                try
                                {
                                    model      getlatlng = new model();
                                    DtoLatLong latlong   = getlatlng.GetLatLongGoogle(destino.endereco);
                                    destino.latitude  = Convert.ToDouble(latlong.latitude, CultureInfo.InvariantCulture);
                                    destino.longitude = Convert.ToDouble(latlong.longitude, CultureInfo.InvariantCulture);
                                    destino.distancia = Convert.ToDouble(latlong.distancia, CultureInfo.InvariantCulture);
                                    destino.duracao   = latlong.duracao;
                                }
                                catch (Exception)
                                {
                                    destino.status = "E";
                                }
                            }
                        }

                        destino.status = "I";
                        model post = new model();
                        post.set(destino);
                    }
                }
                CarregarDestinos();
                progressBar1.Visible = false;
            }
            catch (Exception ex)
            {
                throw ex;;
            }
        }
예제 #13
0
        private void DIALOGO(string[] theLines)
        {
            try
            {
                progressBar1.Maximum = theLines.Count();
                progressBar1.Minimum = 0;
                for (int i = 0; i < theLines.Count(); i++)
                {
                    progressBar1.Value = i;
                    if (i >= 19)
                    {
                        DtoDestino destino = new DtoDestino();
                        destino.transportadora = "DIALOGO";
                        destino.documento      = Regex.Match(theLines[i].Substring(11, 9), @"\d+").Value;

                        if (theLines[i + 1].Contains("CENTRO"))
                        {
                            destino.bairro = "CENTRO";
                        }
                        else
                        if (theLines[i + 1].Contains("VILA INDUSTRIAL"))
                        {
                            destino.bairro = "VILA INDUSTRIAL";
                        }
                        else
                        if (theLines[i + 1].Contains("JARDIM PORTO ALEGRE"))
                        {
                            destino.bairro = "JARDIM PORTO ALEGRE";
                        }
                        else
                        if (theLines[i + 1].Contains("JARDIM POR"))
                        {
                            destino.bairro = "JARDIM PORTO ALEGRE";
                        }
                        else
                        if (theLines[i + 1].Contains("JD PTO ALEGRE"))
                        {
                            destino.bairro = "JARDIM PORTO ALEGRE";
                        }
                        else
                        if (theLines[i + 1].Contains("JD PORTO ALEGRE"))
                        {
                            destino.bairro = "JARDIM PORTO ALEGRE";
                        }
                        else
                        if (theLines[i + 1].Contains("SANTA CLARA 4"))
                        {
                            destino.bairro = "SANTA CLARA IV";
                        }
                        else
                        if (theLines[i + 1].Contains("SANTA CLARA IV"))
                        {
                            destino.bairro = "SANTA CLARA IV";
                        }
                        else
                        if (theLines[i + 1].Contains("JARDIM EUR"))
                        {
                            destino.bairro = "JARDIM EUROPA";
                        }
                        else
                        if (theLines[i + 1].Contains("JD EUROPA"))
                        {
                            destino.bairro = "JARDIM EUROPA";
                        }
                        else
                        if (theLines[i + 1].Contains("VILA PIONEIRO"))
                        {
                            destino.bairro = "VILA PIONEIRO";
                        }
                        else
                        if (theLines[i + 1].Contains("Vila Pioneiro"))
                        {
                            destino.bairro = "VILA PIONEIRO";
                        }
                        else
                        if (theLines[i + 1].Contains("VILA PIONE"))
                        {
                            destino.bairro = "VILA PIONEIRO";
                        }
                        else
                        if (theLines[i + 1].Contains("VL PIONEIRO"))
                        {
                            destino.bairro = "VILA PIONEIRO";
                        }
                        else
                        if (theLines[i + 1].Contains("JARDIM PAULISTA"))
                        {
                            destino.bairro = "JARDIM PAULISTA";
                        }
                        else
                        if (theLines[i + 1].Contains("JARDIM PAU"))
                        {
                            destino.bairro = "JARDIM PAULISTA";
                        }
                        else
                        if (theLines[i + 1].Contains("JARDIM PANORAMA"))
                        {
                            destino.bairro = "JARDIM PANORAMA";
                        }
                        else
                        if (theLines[i + 1].Contains("JARDIM PAN"))
                        {
                            destino.bairro = "JARDIM PANORAMA";
                        }
                        else
                        if (theLines[i + 1].Contains("JARDIM BRESSAN"))
                        {
                            destino.bairro = "JARDIM BRESSAN";
                        }
                        else
                        if (theLines[i + 1].Contains("JARDIM BRE"))
                        {
                            destino.bairro = "JARDIM BRESSAN";
                        }
                        else
                        if (theLines[i + 1].Contains("JARDIM PARIZZOTTO"))
                        {
                            destino.bairro = "JARDIM PARIZZOTTO";
                        }
                        else
                        if (theLines[i + 1].Contains("SAO FRANCISCO"))
                        {
                            destino.bairro = "SAO FRANCISCO";
                        }
                        else
                        if (theLines[i + 1].Contains("SAO FRANCI"))
                        {
                            destino.bairro = "SAO FRANCISCO";
                        }
                        else
                        if (theLines[i + 1].Contains("BOA ESPERANCA"))
                        {
                            destino.bairro = "BOA ESPERANCA";
                        }
                        else
                        if (theLines[i + 1].Contains("JARDIM CONCORDIA"))
                        {
                            destino.bairro = "JARDIM CONCORDIA";
                        }
                        else
                        if (theLines[i + 1].Contains("JARDIM CON"))
                        {
                            destino.bairro = "JARDIM CONCORDIA";
                        }
                        else
                        if (theLines[i + 1].Contains("JARDIM COOPAGRO"))
                        {
                            destino.bairro = "JARDIM COOPAGRO";
                        }
                        else
                        if (theLines[i + 1].Contains("MARACANA"))
                        {
                            destino.bairro = "MARACANA";
                        }
                        else
                        if (theLines[i + 1].Contains("INDEPENDENCIA"))
                        {
                            destino.bairro = "INDEPENDENCIA";
                        }
                        else
                        if (theLines[i + 1].Contains("VILA OPERARIA"))
                        {
                            destino.bairro = "VILA OPERARIA";
                        }
                        else
                        if (theLines[i + 1].Contains("JARDIM GISELA"))
                        {
                            destino.bairro = "JARDIM GISELA";
                        }
                        else
                        if (theLines[i + 1].Contains("VILA NOVA"))
                        {
                            destino.bairro = "VILA NOVA";
                        }
                        else
                        {
                            destino.bairro = "Não encontrado";
                        }

                        model   get             = new model();
                        Boolean existeDocumento = get.getDestinoDocumento(destino.documento, destino.transportadora);

                        if (!existeDocumento)
                        {
                            if (theLines[i + 1].Contains("-"))
                            {
                                int posicao = theLines[i + 1].IndexOf("-") + 3;
                                destino.nome = theLines[i + 1].Substring(posicao, 25);
                            }
                            else
                            {
                                destino.nome = theLines[i + 1].Substring(0, 30);
                            }
                            int posicaoDacte = theLines[i + 2].IndexOf("DACTE") - 5;
                            destino.endereco = theLines[i + 2].Substring(3, posicaoDacte).Replace('/', ',') + ",Toledo, PR";

                            try
                            {
                                model      m       = new model();
                                DtoLatLong latlong = m.GetLatLongGoogle(destino.endereco);
                                destino.latitude  = Convert.ToDouble(latlong.latitude, CultureInfo.InvariantCulture);
                                destino.longitude = Convert.ToDouble(latlong.longitude, CultureInfo.InvariantCulture);
                                destino.distancia = Convert.ToDouble(latlong.distancia, CultureInfo.InvariantCulture);
                                destino.duracao   = latlong.duracao;
                            }
                            catch (Exception)
                            {
                                destino.status = "E";
                            }
                            destino.status = "I";
                            model post = new model();
                            post.set(destino);
                            i++;
                        }
                        i++;
                    }
                }
                CarregarDestinos();
                progressBar1.Visible = false;
            }
            catch (Exception ex)
            { }
        }