public void EditPolygonPoints(int ID, List <PointLatLng> Points) { if (Polygons.ContainsKey(ID)) { List <PointLatLng> np = new List <PointLatLng>(Points); AdjustPoints(np); AreaInfo ainfo = Polygons[ID]; if (DataSettings.UseDatabase) { MySqlConnection conn = DataSettings.GetConnection(); using (MySqlCommand cmd = new MySqlCommand(null, conn)) { Dictionary <int, PointLatLng> points = new Dictionary <int, PointLatLng>(); Dictionary <int, PointLatLng> op = ainfo.Points; foreach (int point_id in op.Keys) { cmd.CommandText = "DELETE FROM polygon_point WHERE point_id = @id"; cmd.Parameters.Clear(); cmd.Parameters.AddWithValue("id", point_id); cmd.ExecuteNonQuery(); } foreach (PointLatLng point in Points) { cmd.CommandText = "INSERT INTO polygon_point (point_lat, point_lng, area_id) " + "VALUES (@lat, @lng, @area_id); SELECT LAST_INSERT_ID();"; cmd.Parameters.Clear(); cmd.Parameters.AddWithValue("lat", point.Lat); cmd.Parameters.AddWithValue("lng", point.Lng); cmd.Parameters.AddWithValue("area_id", ID); int point_id = Convert.ToInt32(cmd.ExecuteScalar()); points.Add(point_id, point); } ainfo.SetPoints(points); ainfo.Polygon = CreatePolygon(ainfo.Name, Points, ainfo.Property); } } else { Dictionary <int, PointLatLng> points = new Dictionary <int, PointLatLng>(); for (int i = 0; i < Points.Count; i++) { points.Add(i, Points[i]); } ainfo.SetPoints(points); ainfo.Polygon = CreatePolygon(ainfo.Name, Points, ainfo.Property); } } }
public bool LoadPolygon(int mission_id) { bool result = false; if (DataSettings.UseDatabase) { DateTime dt = DateTime.Now; MySqlConnection conn = DataSettings.GetConnection(); using (MySqlCommand cmd = new MySqlCommand(null, conn)) { //clear old marker GMapOverlay overlay = Main.GetOverlay("polygons"); foreach (int id in Polygons.Keys) { var dat = Polygons[id]; overlay.Markers.Remove((GmapMarkerWithLabel)dat.Polygon.Tag); overlay.Polygons.Remove(dat.Polygon); } Polygons.Clear(); //load polygon area cmd.CommandText = "SELECT * FROM polygon_info WHERE mission_id = @mission_id"; cmd.Parameters.Clear(); cmd.Parameters.AddWithValue("mission_id", mission_id); using (MySqlDataReader reader = cmd.ExecuteReader()) { while (reader.Read()) { int id = reader.GetInt32("area_id"); string name = reader.GetString("area_name"); int property = reader.GetInt32("area_property"); AreaInfo ainfo = new AreaInfo(mission_id, id, name, property); Polygons.Add(id, ainfo); } } //load polygon point foreach (int id in Polygons.Keys) { AreaInfo ainfo = Polygons[id]; Dictionary <int, PointLatLng> points = new Dictionary <int, PointLatLng>(); cmd.CommandText = "SELECT * FROM polygon_point WHERE area_id = @id"; cmd.Parameters.Clear(); cmd.Parameters.AddWithValue("id", id); using (MySqlDataReader reader = cmd.ExecuteReader()) { while (reader.Read()) { int point_id = reader.GetInt32("point_id"); double lat = reader.GetDouble("point_lat"); double lng = reader.GetDouble("point_lng"); PointLatLng point = new PointLatLng(lat, lng); points.Add(point_id, point); } } ainfo.SetPoints(points); ainfo.Polygon = CreatePolygon(ainfo.Name, ainfo.GetPoints(), ainfo.Property); } } } return(result); }
public void AddPolygon(List <PointLatLng> Points, string Name, int Property) { AreaInfo ainfo; int mission_id, polygon_id; if (DataSettings.UseDatabase) { mission_id = Mission.GetMissionId(); MySqlConnection conn = DataSettings.GetConnection(); using (MySqlCommand cmd = new MySqlCommand(null, conn)) { cmd.CommandText = "INSERT INTO polygon_info (area_name, area_property, mission_id) " + "VALUES (@name, @property, @mission_id); SELECT LAST_INSERT_ID();"; cmd.Parameters.Clear(); cmd.Parameters.AddWithValue("name", Name); cmd.Parameters.AddWithValue("property", Property); cmd.Parameters.AddWithValue("mission_id", mission_id); polygon_id = Convert.ToInt32(cmd.ExecuteScalar()); Dictionary <int, PointLatLng> points = new Dictionary <int, PointLatLng>(); foreach (PointLatLng point in Points) { cmd.CommandText = "INSERT INTO polygon_point (point_lat, point_lng, area_id) " + "VALUES (@lat, @lng, @area_id); SELECT LAST_INSERT_ID();"; cmd.Parameters.Clear(); cmd.Parameters.AddWithValue("lat", point.Lat); cmd.Parameters.AddWithValue("lng", point.Lng); cmd.Parameters.AddWithValue("area_id", polygon_id); int point_id = Convert.ToInt32(cmd.ExecuteScalar()); points.Add(point_id, point); } ainfo = new AreaInfo(mission_id, polygon_id, Name, Property); ainfo.SetPoints(points); ainfo.Polygon = CreatePolygon(Name, Points, Property); Polygons.Add(polygon_id, ainfo); } } else { mission_id = 0; polygon_id = simID++; ainfo = new AreaInfo(mission_id, polygon_id, Name, Property); Dictionary <int, PointLatLng> points = new Dictionary <int, PointLatLng>(); for (int i = 0; i < Points.Count; i++) { points.Add(i, Points[i]); } ainfo.SetPoints(points); ainfo.Polygon = CreatePolygon(Name, Points, Property); Polygons.Add(polygon_id, ainfo); } }