Beispiel #1
0
        public ActionResult NovoNoMaps([System.Web.Http.FromBody] DemandaStrandView demandaStrandView)
        {
            Cidade cidade = UnitOfWork.CidadeRepository.Get(c => c.IdCidade == demandaStrandView.IdCidade).FirstOrDefault();
            ConverterLatLonToUtm converter = null;

            if (cidade != null)
            {
                converter = new ConverterLatLonToUtm(cidade.Datum, cidade.NorteOuSul, cidade.Zona);


                OrdemDeServico ordemDeServico = UnitOfWork.OrdemDeServicoRepository.Get(or => or.NumeroOS == demandaStrandView.NumeroOs).FirstOrDefault();

                double x1 = Double.Parse(demandaStrandView.X1Texto, System.Globalization.CultureInfo.InvariantCulture);
                double y1 = Double.Parse(demandaStrandView.Y1Texto, System.Globalization.CultureInfo.InvariantCulture);
                double x2 = Double.Parse(demandaStrandView.X2Texto, System.Globalization.CultureInfo.InvariantCulture);
                double y2 = Double.Parse(demandaStrandView.Y2Texto, System.Globalization.CultureInfo.InvariantCulture);

                UTM utm1 = converter.Convert(x1, y1);
                UTM utm2 = converter.Convert(x2, y2);

                DemandaStrand demandaStrand = new DemandaStrand
                {
                    IdCidade         = demandaStrandView.IdCidade,
                    IdOrdemDeServico = ordemDeServico.IdOrdemDeServico,
                    X1           = utm1.X,
                    Y1           = utm1.Y,
                    X2           = utm2.X,
                    Y2           = utm2.Y,
                    DataInclusao = DateTime.Now
                };

                UnitOfWork.DemandaStrandRepository.Insert(demandaStrand);
                UnitOfWork.Save();

                DemandaStrand strand = UnitOfWork.DemandaStrandRepository.Get(d => d.ID == demandaStrand.ID).FirstOrDefault();

                return(Json(StrandPaginadoView.GenerateUnico(strand), JsonRequestBehavior.AllowGet));
            }
            else
            {
                return(Json(new { Status = Status.NotFound, Result = "Cidade nao encontrada!" }, JsonRequestBehavior.AllowGet));
            }
        }
Beispiel #2
0
        public ActionResult Novo(DemandaStrandView demandaStrandView)
        {
            Cidade cidade = UnitOfWork.CidadeRepository.Get(c => c.IdCidade == demandaStrandView.IdCidade).FirstOrDefault();
            ConverterLatLonToUtm converter = null;

            if (cidade != null)
            {
                converter = new ConverterLatLonToUtm(cidade.Datum, cidade.NorteOuSul, cidade.Zona);

                Poste poste1 = UnitOfWork.PosteRepository.Get(p1 => p1.IdPoste == demandaStrandView.IdPoste1).FirstOrDefault();
                Poste poste2 = UnitOfWork.PosteRepository.Get(p2 => p2.IdPoste == demandaStrandView.IdPoste2).FirstOrDefault();

                OrdemDeServico ordemDeServico = UnitOfWork.OrdemDeServicoRepository.Get(or => or.NumeroOS == demandaStrandView.NumeroOs).FirstOrDefault();

                /* UTM utm1 = converter.Convert(demandaStrandView.X1, demandaStrandView.Y1);
                 * UTM utm2 = converter.Convert(demandaStrandView.X2, demandaStrandView.Y2);*/

                DemandaStrand demandaStrand = new DemandaStrand
                {
                    IdCidade         = demandaStrandView.IdCidade,
                    IdOrdemDeServico = ordemDeServico.IdOrdemDeServico,
                    X1           = poste1.X,
                    Y1           = poste1.Y,
                    X2           = poste2.X,
                    Y2           = poste2.Y,
                    DataInclusao = DateTime.Now
                };

                UnitOfWork.DemandaStrandRepository.Insert(demandaStrand);
                UnitOfWork.Save();

                DemandaStrand strand = UnitOfWork.DemandaStrandRepository.Get(d => d.ID == demandaStrand.ID).FirstOrDefault();

                return(Json(StrandPaginadoView.GenerateUnico(strand), JsonRequestBehavior.AllowGet));
            }
            else
            {
                return(Json(new { Status = Status.NotFound, Result = "Cidade nao encontrada!" }, JsonRequestBehavior.AllowGet));
            }
        }
Beispiel #3
0
        public ActionResult ExcluirStrands(long id)
        {
            DemandaStrand demandaStrand = UnitOfWork.DemandaStrandRepository.Get(s => s.ID == id).FirstOrDefault();

            if (demandaStrand != null)
            {
                demandaStrand.DataExclusao = DateTime.Now;
                UnitOfWork.DemandaStrandRepository.Update(demandaStrand);
                UnitOfWork.Save();
                return(Json(new ResponseView()
                {
                    Status = Status.OK, Result = "OK"
                }, JsonRequestBehavior.AllowGet));
            }
            else
            {
                return(Json(new ResponseView()
                {
                    Status = Status.NotFound, Result = "Erro"
                }, JsonRequestBehavior.AllowGet));
            }
        }
Beispiel #4
0
        public static object GenerateUnico(DemandaStrand strands)
        {
            if (strands == null)
            {
                throw new ArgumentException("o paramêtro 'strands' não pode ser null.");
            }

            long IdCidade = -1;
            ConverterUtmToLatLon converter  = null;
            List <object>        StrandList = new List <object>();
            //  LatLon centro;
            //  double x = 0, y = 0, z = 0;
            //  int total = 0;
            string NomeCidade = string.Empty;


            if (converter == null)
            {
                converter = new ConverterUtmToLatLon(strands.Cidade.Datum, strands.Cidade.NorteOuSul, strands.Cidade.Zona);
            }
            if (IdCidade == -1)
            {
                IdCidade = strands.IdCidade;
            }
            if (NomeCidade == string.Empty)
            {
                NomeCidade = strands.Cidade.Nome;
            }

            LatLon LatiLong1 = converter.Convert(strands.X1, strands.Y1);
            LatLon LatiLong2 = converter.Convert(strands.X2, strands.Y2);

            ////Calculando o Centro do conjunto dos postes
            //double latitude = LatiLong1.Lat * Math.PI / 180;
            //double longitude = LatiLong1.Lon * Math.PI / 180;

            //x += Math.Cos(latitude) * Math.Cos(longitude);
            //y += Math.Cos(latitude) * Math.Sin(longitude);
            //z += Math.Sin(latitude);
            //total++;

            DemandaStrandView DemandaStrandView = new DemandaStrandView
            {
                ID = strands.ID,
                X1 = LatiLong1.Lat,
                Y1 = LatiLong1.Lon,
                X2 = LatiLong2.Lat,
                Y2 = LatiLong2.Lon
            };

            //x = x / total;
            //y = y / total;
            //z = z / total;

            //double centralLongitude = Math.Atan2(y, x);
            //double centralSquareRoot = Math.Sqrt(x * x + y * y);
            //double centralLatitude = Math.Atan2(z, centralSquareRoot);

            //centro = new LatLon() { Lat = centralLatitude * 180 / Math.PI, Lon = centralLongitude * 180 / Math.PI };

            return(new { DemandaStrand = DemandaStrandView });
        }