public ActionResult Index(Geocerca model, string[] zonas) { InicializarEdit(); model.Zonas = GetZonaListDetail(zonas); try { var idZonas = model.Zonas.Select(p => p.IdZona).ToArray <int>(); var geoZonas = DataBase.Zonas.Get(p => p.Tipo == Rp3.AgendaComercial.Models.Constantes.TipoZona.Geocerca && p.Estado == Rp3.AgendaComercial.Models.Constantes.Estado.Activo && idZonas.Contains(p.IdZona), includeProperties: "ZonaGeocercas").ToList(); model.GeoZonas = geoZonas; return(View(model)); } catch { this.AddDefaultErrorMessage(); } model.GeoZonas = new List <Zona>(); return(View(model)); }
public Geocerca FindGeocerca(ReferenciaGeografica rg) { var geo = new Geocerca(rg); LogicCache.Store(typeof(Geocerca), GetGeocercaByIdKey(rg.Id), geo, DateTime.UtcNow.AddMinutes(Config.Dispatcher.DispatcherGeocercasRefreshRate)); return(geo); }
private int StoreInNode(Geocerca geocerca) { if (Depth > MaxDepth) { return(-1); } var centerY = (Top + Bottom) / 2.0; var centerX = (Left + Right) / 2.0; var top = geocerca.MaxY >= centerY; var bottom = geocerca.MinY < centerY; var right = geocerca.MaxX >= centerX; var left = geocerca.MinX < centerX; if ((top && bottom) || (right && left)) { return(-1); } if (top) { return(left ? 0 : 1); } return(left ? 2 : 3); }
public static bool ActualizaGeocerca(Geocerca geocerca) { using (SqlConnection sqlConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["connectionStringBD"].ConnectionString)) { sqlConnection.Open(); using (SqlCommand sqlCommand = new SqlCommand("GEOCERCA_INSERT_UPDATE", sqlConnection)) { try { sqlCommand.CommandType = CommandType.StoredProcedure; sqlCommand.Parameters.AddWithValue("@ID_GEOCERCA", geocerca.GeocercaID); sqlCommand.Parameters.AddWithValue("@ACTIVADA", geocerca.Activada); sqlCommand.Parameters.AddWithValue("@CIUDAD", geocerca.Ciudad); sqlCommand.Parameters.AddWithValue("@CLIENTE", geocerca.Cliente); sqlCommand.Parameters.AddWithValue("@DESCRIPCION", geocerca.Descripcion); sqlCommand.Parameters.AddWithValue("@NOMBRE", geocerca.Nombre.ToUpper()); sqlCommand.Parameters.AddWithValue("@TIPO", geocerca.Tipo); sqlCommand.Parameters.AddWithValue("@ZONA", geocerca.Zona); sqlCommand.Parameters.AddWithValue("@CORREOE", geocerca.CorreoElectronico); sqlCommand.ExecuteNonQuery(); return true; } catch (Exception e) { return false; throw; } } } }
public IHttpActionResult actualizarGeocerca([FromBody] Geocerca geocerca) { try { if (geocerca == null) { return(BadRequest()); } var msgCodes = new List <string>(); var deviceId = GetDeviceId(Request); if (deviceId == null) { return(Unauthorized()); } DateTime horaentrada = DateTime.ParseExact(geocerca.horaentrada.ToString(), "yyyy-MM-dd-HH.mm.ss.fff", System.Globalization.CultureInfo.InvariantCulture); DateTime horasalida = DateTime.ParseExact(geocerca.horariosalida.ToString(), "yyyy-MM-dd-HH.mm.ss.fff", System.Globalization.CultureInfo.InvariantCulture); EmpleadoDAO empleado = new EmpleadoDAO(); // emple //fecha DispositivoDAO dispositivo = new DispositivoDAO(); PuertaAccesoDAO puertas = new PuertaAccesoDAO(); // puerta var device = dispositivo.FindByImei(deviceId); var employee = empleado.FindEmpleadoByDevice(device); List <int> empresas = new List <int>(); empresas.Add(employee.Empresa.Id); var lineas = new int[] { }; PuertaAcceso puerta = puertas.GetList(empresas, lineas).Where(x => x.Id.ToString().Equals(geocerca.idpuerta)).First(); if (puerta != null) { EventoAcceso entrada = new EventoAcceso(); entrada.Empleado = employee; entrada.Alta = DateTime.UtcNow; entrada.Entrada = true; entrada.Fecha = horaentrada.ToUniversalTime(); entrada.Puerta = puerta; EventoAccesoDAO eventos = new EventoAccesoDAO(); eventos.Save(entrada); EventoAcceso salida = new EventoAcceso(); salida.Empleado = employee; salida.Alta = DateTime.UtcNow; salida.Entrada = false; salida.Fecha = horasalida.ToUniversalTime(); salida.Puerta = puerta; eventos.Save(salida); } return(Ok(msgCodes.ToArray())); } catch (Exception error) { LogicTracker.App.Web.Api.Providers.LogWritter.writeLog(error); return(BadRequest()); } }
public ActionResult Index() { InicializarEdit(); var model = new Geocerca(); model.GeoZonas = new List <Zona>(); model.Zonas = GetZonaListDetail(((List <Zona>)ViewBag.Zonas).Select(p => p.IdZona.ToString()).ToArray <string>());//new List<UbicacionAgenteDetalle>(); return(View(model)); }
public Geocerca GetGeocercaById(int id) { var rg = Session.CreateCriteria <ReferenciaGeografica>("rg") .Add(Restrictions.Eq("Id", id)) .UniqueResult <ReferenciaGeografica>(); var geo = new Geocerca(rg); LogicCache.Store(typeof(Geocerca), GetGeocercaByIdKey(rg.Id), geo, DateTime.UtcNow.AddMinutes(Config.Dispatcher.DispatcherGeocercasRefreshRate)); return(geo); }
private static EstadoGeocerca GetEstadoGeocercaDentro(Coche vehiculo, Geocerca geocerca) { return(new EstadoGeocerca { EnExcesoVelocidad = (bool)(Retrieve(vehiculo, geocerca.Id, "enexceso") ?? false), Estado = EstadosGeocerca.Dentro, Geocerca = geocerca, PosicionInicioExceso = Retrieve(vehiculo, geocerca.Id, "posicionexceso") as GPSPoint, VelocidadMaxima = (int)(Retrieve(vehiculo, geocerca.Id, "velomaxima") ?? 0), VelocidadPico = (int)(Retrieve(vehiculo, geocerca.Id, "velopico") ?? 0) }); }
public MobilePoi(LogUltimaPosicionVo posicion, Geocerca referencia, Empleado chofer) { IdVehiculo = posicion.IdCoche; Interno = posicion.Coche; TipoVehiculo = posicion.TipoCoche; Distancia = Distancias.Loxodromica(posicion.Latitud, posicion.Longitud, referencia.Latitude, referencia.Longitude); Latitud = posicion.Latitud; Longitud = posicion.Longitud; PuntoDeInteres = referencia.Descripcion; Velocidad = posicion.Velocidad; Responsable = posicion.Responsable; Chofer = chofer != null ? chofer.Entidad.Descripcion : string.Empty; }
public static EstadoGeocerca GetEstadoGeocerca(Coche vehiculo, Geocerca geocerca) { var key = string.Format("device[{0}].geocercas", vehiculo.Dispositivo.Id); var dentro1 = LogicCache.Retrieve <int[]>(key); if (dentro1 == null) { return(null); } var dentro = dentro1; return(dentro.Contains(geocerca.Id) ? GetEstadoGeocercaDentro(vehiculo, geocerca) : null); }
public string actualizarGeocerca(Geocerca geocerca) { HttpCookie Cookie = HttpContext.Current.Request.Cookies.Get("Usuario"); if (Cookie != null && AutentificacionBD.VerificarToken(Cookie.Values.Get("Token"))) { string cliente = new Codificador().Desencriptar(Cookie.Values.Get("Cliente")); cliente = cliente.Replace("\0", string.Empty); geocerca.Cliente = cliente; if (geocerca.Zona == 0 && geocerca.Puntos.Count > 0) { geocerca.Zona = geocerca.Zona = ConversionesGeograficas.GetZoneLatLon(geocerca.Puntos[0].Longitud); } if (GeocercasBD.ActualizaGeocerca(geocerca)) { return "ok"; } return "errorBD"; } else return "error404"; }
public int GetVehiclesInside(IEnumerable <int> vehicles, Geocerca geocerca, DateTime fecha) { var count = 0; foreach (var vehicleId in vehicles) { var position = GetFirstPositionOlderThanDate(vehicleId, fecha, 1); if (position != null) { var latitud = position.Latitud; var longitud = position.Longitud; var point = new PointF((float)longitud, (float)latitud); var inside = geocerca.IsInBounds(point) && geocerca.Contains(latitud, longitud); if (inside) { count++; } } } return(count); }
public void AddValue(Geocerca geocerca) { var node = StoreInNode(geocerca); if (node == -1) { if (Data == null) { Data = new List <Geocerca> { geocerca } } ; else { Data.Add(geocerca); } } else { var quad = GetQuadrant(node) ?? AddQuadrant(node); quad.AddValue(geocerca); } }
public static bool Guardar_Visual_Geopoligono(Geocerca geocerca) { using (SqlConnection sqlConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["connectionStringBD"].ConnectionString)) { sqlConnection.Open(); using (SqlTransaction sqlTransaction = sqlConnection.BeginTransaction()) { try { using (SqlCommand sqlCommand = new SqlCommand("VISUAL_DATOSGEO_INSERT_UPDATE", sqlConnection)) { sqlCommand.CommandType = CommandType.StoredProcedure; sqlCommand.Transaction = sqlTransaction; int color = -1 * ((0xFFFFFF ^ Int32.Parse(geocerca.visual.Color, System.Globalization.NumberStyles.HexNumber)) + 1); //parametros Visual sqlCommand.Parameters.AddWithValue("@ID_GEOCERCA", geocerca.GeocercaID); sqlCommand.Parameters.AddWithValue("@COLOR", color); sqlCommand.Parameters.AddWithValue("@GROSOR", geocerca.visual.Grosor); sqlCommand.Parameters.AddWithValue("@TRANSPARENCIA", geocerca.visual.Transparencia); //Parametros geopoligono sqlCommand.Parameters.AddWithValue("@SUBTIPO", geocerca.geoPoligono.Subtipo); sqlCommand.Parameters.AddWithValue("@XMAX", geocerca.geoPoligono.XMax); sqlCommand.Parameters.AddWithValue("@XMIN",geocerca.geoPoligono.XMin); sqlCommand.Parameters.AddWithValue("@YMAX", geocerca.geoPoligono.YMax); sqlCommand.Parameters.AddWithValue("@YMIN", geocerca.geoPoligono.YMin); sqlCommand.Parameters.AddWithValue("@SUR", geocerca.Puntos[0].Latitud >= 0 ? 0 : 1); sqlCommand.ExecuteNonQuery(); sqlTransaction.Commit(); return true; } } catch (Exception) { throw; } } } return false; }
public static bool GuardarVisualGeopoligono(Geocerca geocerca) { using (SqlConnection sqlConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["connectionStringBD"].ConnectionString)) { sqlConnection.Open(); string sp = geocerca.Tipo == "GeoRuta" ? "SP_CMW_UPDATE_VISUAL_GEOPOLIGONO_GEORUTA" : "SP_CMW_UPDATE_VISUAL_GEOPOLIGONO"; using (SqlCommand sqlCommand = new SqlCommand(sp, sqlConnection)) { try { int color = -1 * ((0xFFFFFF ^ Int32.Parse(geocerca.visual.Color, System.Globalization.NumberStyles.HexNumber)) + 1); sqlCommand.CommandType = CommandType.StoredProcedure; sqlCommand.Parameters.AddWithValue("@ID_GEOCERCA", geocerca.GeocercaID); sqlCommand.Parameters.AddWithValue("@COLOR", color); sqlCommand.Parameters.AddWithValue("@GROSOR", geocerca.visual.Grosor); sqlCommand.Parameters.AddWithValue("@TRANSPARENCIA", geocerca.visual.Transparencia); sqlCommand.Parameters.AddWithValue("@SUR", geocerca.Puntos[0].Latitud >= 0 ? 0 : 1); sqlCommand.Parameters.AddWithValue("@ZONA", geocerca.Zona = ConversionesGeograficas.GetZoneLatLon(geocerca.Puntos[0].Longitud)); if (sp == "SP_CMW_UPDATE_VISUAL_GEOPOLIGONO_GEORUTA") { sqlCommand.Parameters.AddWithValue("@XMAX", geocerca.geoPoligono.XMax); sqlCommand.Parameters.AddWithValue("@XMIN", geocerca.geoPoligono.XMin); sqlCommand.Parameters.AddWithValue("@YMAX", geocerca.geoPoligono.YMax); sqlCommand.Parameters.AddWithValue("@YMIN", geocerca.geoPoligono.YMin); } sqlCommand.ExecuteNonQuery(); return true; } catch (Exception) { return false; throw; } } } }
/// <summary> /// Inserta o Actualiza en la Tabla "visual" los datos (color,grosor y transparencia) de una geocerca /// </summary> /// <param name="geocerca"></param> /// <returns></returns> public static bool GuardarVisual(Geocerca geocerca) { using (SqlConnection sqlConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["connectionStringBD"].ConnectionString)) { sqlConnection.Open(); using (SqlCommand sqlCommand = new SqlCommand("VISUAL_INSERT_UPDATE",sqlConnection)) { try { int color = -1 *( (0xFFFFFF ^ Int32.Parse(geocerca.visual.Color, System.Globalization.NumberStyles.HexNumber))+1); sqlCommand.CommandType = CommandType.StoredProcedure; sqlCommand.Parameters.AddWithValue("@ID_GEOCERCA", geocerca.GeocercaID); sqlCommand.Parameters.AddWithValue("@COLOR", color); sqlCommand.Parameters.AddWithValue("@GROSOR", geocerca.visual.Grosor); sqlCommand.Parameters.AddWithValue("@TRANSPARENCIA", geocerca.visual.Transparencia); sqlCommand.Parameters.AddWithValue("@OUT", SqlDbType.Int).Direction = ParameterDirection.Output; sqlCommand.ExecuteNonQuery(); int output = (int)sqlCommand.Parameters["@OUT"].Value; if (output < 1) { throw new InvalidProgramException(); } return true; } catch (Exception) { return false; throw; } } } }
private void btnAceptar_Click(object sender, EventArgs e) { if (poligono != null) { if (poligono.Puntos.Count() > 0) { if (((GrupoCombo)cmbCelula.SelectedItem).IdGrupo != 0 && ((RutaCombo)cmbRuta.SelectedItem).IdRuta != 0) { if (MessageBox.Show("¿Esta seguro de remplazar la geocerca de la célula: " + ((GrupoCombo)cmbCelula.SelectedItem).Descripcion.Trim() + "\ny ruta: " + ((RutaCombo)cmbRuta.SelectedItem).Descripcion.Trim() + "?", "Mensaje del sistema", MessageBoxButtons.YesNo) == DialogResult.Yes) { if (MessageBox.Show("Confirme operación!!", "Mensaje del sistema", MessageBoxButtons.YesNo) == DialogResult.Yes) { try { List <Geocerca> lista = new List <Geocerca>(); int grupo = ((GrupoCombo)cmbCelula.SelectedItem).IdGrupo; int ruta = ((RutaCombo)cmbRuta.SelectedItem).IdRuta; DateTime fecha = DateTime.Now; int poli = 1; int vertice = 1; foreach (UbicacionGeografica punto in poligono.Puntos) { Geocerca g = new Geocerca(); g.Grupo = grupo; g.Ruta = ruta; g.Fecha = fecha; g.Poligono = poli; g.Vertice = vertice; vertice++; double latitud = punto.Latitud; double longitud = punto.Longitud; g.Latitud = (decimal)latitud; g.Longitud = (decimal)longitud; lista.Add(g); } bool resultado = InsertarGeocercas(lista); if (resultado) { MessageBox.Show("Se han exportado las ubicaciones correctamente.", "Información", MessageBoxButtons.OK, MessageBoxIcon.Information); if (cmbCelula.Items.Count > 0) { cmbCelula.SelectedIndex = 0; } if (cmbRuta.Items.Count > 0) { cmbRuta.SelectedIndex = 0; } } else { MessageBox.Show("A ocurrido un error en la exportacion de las ubicaciones.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } catch (Exception ex) { MessageBox.Show("A ocurrido un error en la exportacion de las ubicaciones: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } } else { MessageBox.Show("Favor de seleccionar Célula y Ruta.", "Información", MessageBoxButtons.OK, MessageBoxIcon.Information); } } else { MessageBox.Show("No hay ubicaciones que insertar.", "Información", MessageBoxButtons.OK, MessageBoxIcon.Information); } } else { MessageBox.Show("Debe leer el archivo kml.", "Información", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
/// <summary> /// Consulta las geocercas de un cliente en la base de datos y solo regresa el id y el nombre /// </summary> /// <param name="Cliente">Nombre del Cliente</param> /// <returns>Lista de Geocercas sin Datos Visuales ni Puntos</returns> public static List<Geocerca> getGeocercasNombre(string Cliente) { List<Geocerca> Geocercas = new List<Geocerca>(); string query = "SELECT id_geocerca, nombre " + "FROM geocerca "+ "WHERE cliente = @cliente ORDER BY nombre ASC"; using (SqlConnection sqlConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["connectionStringBD"].ConnectionString)) { sqlConnection.Open(); using (SqlCommand sqlCommand = new SqlCommand(query, sqlConnection)) { sqlCommand.Parameters.AddWithValue("@cliente", Cliente); using (SqlDataReader sqlDataReader = sqlCommand.ExecuteReader()) { while (sqlDataReader.Read()) { Geocerca geo = new Geocerca(); geo.GeocercaID = (string)sqlDataReader["id_geocerca"]; geo.Nombre = (string)sqlDataReader["nombre"]; Geocercas.Add(geo); } } } } return Geocercas; }
/// <summary> /// Determines if two givenn mobile route fragments have the same driving caracteristics. /// </summary> /// <param name="route"></param> /// <returns></returns> public bool EqualState(MobileRoutes route) { return(Driver.Equals(route.Driver) && Geocerca.Equals(route.Geocerca) && EngineStatus.Equals(route.EngineStatus) && VehicleStatus.Equals(route.VehicleStatus)); }
/// <summary> /// Consulta las geocercas de un cliente en la base de datos, obteniendo los Puntos de cada geocerca en la lista /// </summary> /// <param name="geoLista">Lista de Geocercas con sus datos visuales</param> /// <returns>Geocercas con sus respectivos puntos</returns> public static List<Geocerca> ConsultarPuntosGeocercaBD(List<Geocerca> geoLista) { if (geoLista.Count > 0) { /*string query = "SELECT dg.geocerca_id,dg.x,dg.y,dg.ky,d.sur " + "FROM datosGeoPoligono dg INNER JOIN geopoligono d " + "ON dg.geocerca_id = d.id_geocerca "+ "WHERE(d.geocerca_id IN(";*/ string query = "SELECT dg.geocerca_id, dg.x, dg.y, dg.ky, d.sur " + "FROM datosGeoPoligono dg INNER JOIN geopoligono d " + "ON dg.geocerca_id = d.id_geocerca " + "WHERE(dg.geocerca_id IN( "; foreach (Geocerca geocerca in geoLista) { query += "'" + geocerca.GeocercaID + "', "; } query = query.Remove(query.Length - 2); query += ")) ORDER BY ky ASC"; using (SqlConnection sqlConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["connectionStringBD"].ConnectionString)) { sqlConnection.Open(); using (SqlCommand sqlCommand = new SqlCommand(query, sqlConnection)) { using (SqlDataReader sqlDataReader = sqlCommand.ExecuteReader()) { string geoID = ""; List<Punto> puntos = new List<Punto>(); Geocerca geoMerge = new Geocerca(); while (sqlDataReader.Read()) { Punto punto = new Punto(); punto.GeocercaID = (string)sqlDataReader["geocerca_id"]; punto.x = (float)((Double)sqlDataReader["x"]); punto.y = (float)((Double)sqlDataReader["y"]); int isSur = (int)sqlDataReader["sur"]; //comparamos si se tiene un punto con diferente id de geocerca if (geoID != punto.GeocercaID) { geoID = punto.GeocercaID; //se asigna el nuevo id puntos = new List<Punto>(); //nueva lista de puntos geoMerge = geoLista.Find(b => b.GeocercaID == geoID); geoMerge.Puntos = puntos; } double[] latlon = ConversionesGeograficas.UTMXYToLatLon(punto.x - 80, punto.y + 196, geoMerge.Zona, isSur == 1?true:false); punto.Latitud = latlon[0]; punto.Longitud = latlon[1]; puntos.Add(punto); } } } } } return geoLista; }
/// <summary> /// Consulta las geocercas de un cliente en la base de datos /// </summary> /// <param name="Cliente">Nombre del Cliente</param> /// <returns>Lista de Geocercas sin Datos Visuales ni Puntos</returns> public static List<Geocerca> ConsultarGeocercasBD(string Cliente) { List<Geocerca> Geocercas = new List<Geocerca>(); /*string query = "SELECT ciudad, cliente, descripcion, id_geocerca, nombre, tipo, zona, correoe, activada" + " FROM geocerca" + " WHERE (cliente = @cliente)";*/ string query = "SELECT a.ciudad, a.cliente, a.descripcion, a.id_geocerca, a.nombre, a.tipo, a.zona, a.correoe, a.activada,b.sur, " + "b.id_geocerca,b.subtipo,b.xmax,b.xmin,b.ymax,b.ymin " + "FROM geocerca a " + "INNER JOIN geoPoligono b ON a.id_geocerca = b.id_geocerca " + "WHERE cliente = @cliente ORDER BY a.nombre ASC"; using (SqlConnection sqlConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["connectionStringBD"].ConnectionString)) { sqlConnection.Open(); using (SqlCommand sqlCommand = new SqlCommand(query, sqlConnection)) { sqlCommand.Parameters.AddWithValue("@cliente", Cliente); using (SqlDataReader sqlDataReader = sqlCommand.ExecuteReader()) { while (sqlDataReader.Read()) { Geocerca geo = new Geocerca(); geo.GeocercaID = (string)sqlDataReader["id_geocerca"]; geo.Nombre = (string)sqlDataReader["nombre"]; geo.Cliente = (string)sqlDataReader["cliente"]; geo.Descripcion = (string)sqlDataReader["descripcion"]; geo.Tipo = (string)sqlDataReader["tipo"]; geo.Zona = (int)sqlDataReader["zona"]; geo.CorreoElectronico = (sqlDataReader["correoe"] == DBNull.Value) ? string.Empty : (string)sqlDataReader["correoe"]; geo.Activada = (bool)sqlDataReader["activada"]; geo.Ciudad = (string)sqlDataReader["ciudad"]; double xmin = (double)sqlDataReader["xmin"]; double xmax = (double)sqlDataReader["xmax"]; double ymin = (double)sqlDataReader["ymin"]; double ymax = (double)sqlDataReader["ymax"]; if (geo.Tipo == "GeoRuta") { int isSur = (int)sqlDataReader["sur"]; double[] latlon1 = ConversionesGeograficas.UTMXYToLatLon(xmin - 80, ymin + 196, geo.Zona, isSur == 0?false:true); double[] latlon2 = ConversionesGeograficas.UTMXYToLatLon(xmax - 80, ymax + 196, geo.Zona, isSur == 0?false:true); geo.geoPoligono = new GeoRutaDatos(); geo.geoPoligono.YMin = latlon1[0]; geo.geoPoligono.XMin = latlon1[1]; geo.geoPoligono.YMax = latlon2[0]; geo.geoPoligono.XMax = latlon2[1]; geo.geoPoligono.Subtipo = (int)sqlDataReader["subtipo"]; } Geocercas.Add(geo); } } } } return Geocercas; }
public string GuardarPuntosGeocerca(Geocerca geocerca, int accion) { HttpCookie cookie = HttpContext.Current.Request.Cookies.Get("Usuario"); if (cookie != null && AutentificacionBD.VerificarToken(cookie.Values.Get("Token"))) { string cookieval = cookie.Values.Get("Cliente"); string cliente = new Codificador().Desencriptar(cookie.Values.Get("Cliente")); cliente = cliente.Replace("\0", string.Empty); //Simplificamos vertices para georuta if (geocerca.Tipo == "GeoRuta") geocerca.QuitaVertices(); //Nueva geocerca if (accion == 0) { geocerca.GeocercaID = Util.GenerarNombreGeocerca(cliente); geocerca.Cliente = cliente; geocerca.Zona = ConversionesGeograficas.GetZoneLatLon(geocerca.Puntos[0].Longitud); geocerca.geoPoligono = geocerca.geoMaxMin(); foreach (Punto punto in geocerca.Puntos) { Double[] xy = ConversionesGeograficas.LatLonToUTMXY(punto.Latitud, punto.Longitud); } if (GeocercasBD.GuardarGeocerca(geocerca)) { if (GeocercasBD.GuardarPuntos(geocerca)) return geocerca.GeocercaID; } } //Editar Visual else if(accion == 1) { if (GeocercasBD.GuardarVisual(geocerca)) return geocerca.GeocercaID; } //Editar Visual y Geopoligono else if (accion == 2) { geocerca.Cliente = cliente; geocerca.Zona = ConversionesGeograficas.GetZoneLatLon(geocerca.Puntos[0].Longitud); geocerca.geoPoligono = geocerca.geoMaxMin(); if (GeocercasBD.GuardarVisualGeopoligono(geocerca)) { if (GeocercasBD.GuardarPuntos(geocerca)) { //GeoRutaDatos rutaDatos = GeocercasBD.ConsultarRutaDatos(geocerca.GeocercaID); return geocerca.GeocercaID; } else { return "errorBD"; } } else { return "errorBD"; } } else { return "errorBD"; } } return "error404"; }
/// <summary> /// /// </summary> /// <param name="geocerca"></param> /// <returns></returns> public static bool GuardarGeocerca(Geocerca geocerca) { using (SqlConnection sqlConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["connectionStringBD"].ConnectionString)) { sqlConnection.Open(); using (SqlTransaction sqlTransaction= sqlConnection.BeginTransaction()) { try { using (SqlCommand sqlCommand = new SqlCommand("NUEVA_GEOCERCA",sqlConnection)) { sqlCommand.Transaction = sqlTransaction; sqlCommand.CommandType = CommandType.StoredProcedure; sqlCommand.Parameters.AddWithValue("@ID_GEOCERCA", geocerca.GeocercaID); sqlCommand.Parameters.AddWithValue("@ACTIVADA", geocerca.Activada); sqlCommand.Parameters.AddWithValue("@CIUDAD", geocerca.Ciudad); sqlCommand.Parameters.AddWithValue("@CLIENTE", geocerca.Cliente); sqlCommand.Parameters.AddWithValue("@DESCRIPCION", geocerca.Descripcion); sqlCommand.Parameters.AddWithValue("@NOMBRE", geocerca.Nombre.ToUpper()); sqlCommand.Parameters.AddWithValue("@TIPO", geocerca.Tipo); sqlCommand.Parameters.AddWithValue("@ZONA", geocerca.Zona); sqlCommand.Parameters.AddWithValue("@CORREOE", geocerca.CorreoElectronico); //geopoligono sqlCommand.Parameters.AddWithValue("@SUBTIPO", geocerca.geoPoligono.Subtipo); sqlCommand.Parameters.AddWithValue("@XMAX", geocerca.geoPoligono.XMax); sqlCommand.Parameters.AddWithValue("@XMIN", geocerca.geoPoligono.XMin); sqlCommand.Parameters.AddWithValue("@YMAX", geocerca.geoPoligono.YMax); sqlCommand.Parameters.AddWithValue("@YMIN", geocerca.geoPoligono.YMin); sqlCommand.Parameters.AddWithValue("@SUR", geocerca.Puntos[0].Latitud >= 0 ? 0:1); //visual //int color = Int32.Parse(geocerca.visual.Color, System.Globalization.NumberStyles.HexNumber); int color = -1 * ((0xFFFFFF ^ Int32.Parse(geocerca.visual.Color, System.Globalization.NumberStyles.HexNumber)) + 1); sqlCommand.Parameters.AddWithValue("@COLOR", color); sqlCommand.Parameters.AddWithValue("@GROSOR", 0); sqlCommand.Parameters.AddWithValue("@TRANSPARENCIA", 0); //int isSur = geocerca.Puntos[0].Latitud > 0 ? 0 : 1; //sqlCommand.Parameters.AddWithValue("@SUR", isSur); //execute query sqlCommand.ExecuteNonQuery(); sqlTransaction.Commit(); return true; } } catch (Exception) { sqlTransaction.Rollback(); throw; } } } }
public static bool IsInside(Geocerca geocerca, double latitud, double longitud) { var point = new PointF((float)longitud, (float)latitud); return(geocerca.IsInBounds(point) && geocerca.Contains(latitud, longitud)); }
public static bool GuardarPuntos(Geocerca geocerca) { if (GeocercasBD.EliminarPuntos(geocerca.GeocercaID)) { using (SqlConnection sqlConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["connectionStringBD"].ConnectionString)) { sqlConnection.Open(); using (SqlTransaction sqlTransaction = sqlConnection.BeginTransaction()) { try { using (SqlCommand sqlCommand = new SqlCommand("PUNTO_ANADIR",sqlConnection)) { sqlCommand.Transaction = sqlTransaction; sqlCommand.CommandType = CommandType.StoredProcedure; sqlCommand.Parameters.AddWithValue("@ID_GEOCERCA", SqlDbType.VarChar); sqlCommand.Parameters.AddWithValue("@X", SqlDbType.Float); sqlCommand.Parameters.AddWithValue("@Y", SqlDbType.Float); foreach (Punto punto in geocerca.Puntos) { Double[] xy = ConversionesGeograficas.LatLonToUTMXY(punto.Latitud, punto.Longitud); sqlCommand.Parameters["@ID_GEOCERCA"].Value = geocerca.GeocercaID; sqlCommand.Parameters["@X"].Value = xy[0] + 80; sqlCommand.Parameters["@Y"].Value = xy[1] - 196; sqlCommand.ExecuteNonQuery(); } sqlTransaction.Commit(); return true; } } catch (Exception) { sqlTransaction.Rollback(); throw; } } } } return false; }