public static bool IsContains() { bool r = false; if (DataSettings.UseDatabase) { MySqlConnection conn = DataSettings.GetConnection(); using (MySqlCommand cmd = new MySqlCommand(null, conn)) { cmd.CommandText = "SELECT * FROM save_mission WHERE mission_date = @date"; cmd.Parameters.Clear(); cmd.Parameters.Add(new MySqlParameter("date", MySqlDbType.Date) { Value = DateTime.Now }); using (MySqlDataReader reader = cmd.ExecuteReader()) { if (reader.Read()) { r = true; Contains = true; MissionID = reader.GetInt32("mission_id"); } } } } else { r = true; } return(r); }
public void EditMarker(int ID, string Name, int Img_index, int Img_ID, double Lat, double Lng) { if (Markers.ContainsKey(ID)) { SymbolInfo sinfo = Markers[ID]; sinfo.Name = Name; sinfo.ImgIndex = Img_index; sinfo.ImgID = Img_ID; sinfo.Point = new PointLatLng(Lat, Lng); sinfo.Marker.ToolTipText = PositionConverter.ParsePointToString(new PointLatLng(Lat, Lng), PositionConverter.DefaultScale) + ", " + Name; if (DataSettings.UseDatabase) { MySqlConnection conn = DataSettings.GetConnection(); using (MySqlCommand cmd = new MySqlCommand(null, conn)) { cmd.CommandText = "UPDATE marker_info SET marker_name = @name, marker_imgindex = @img_index, marker_imgid = @img_id" + ", marker_lat = @lat, marker_lng = @lng, mission_id = @mission_id WHERE marker_id = @id"; cmd.Parameters.Clear(); cmd.Parameters.AddWithValue("id", sinfo.ID); cmd.Parameters.AddWithValue("name", sinfo.Name); cmd.Parameters.AddWithValue("img_index", sinfo.ImgIndex); cmd.Parameters.AddWithValue("img_id", sinfo.ImgID); cmd.Parameters.AddWithValue("lat", sinfo.Point.Lat); cmd.Parameters.AddWithValue("lng", sinfo.Point.Lng); cmd.Parameters.AddWithValue("mission_id", sinfo.Mission); cmd.ExecuteNonQuery(); } } } }
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 static int ForceMissionId(string mission_name) { int mission_id = -1; DateTime dt = DateTime.Now; MySqlConnection conn = DataSettings.GetConnection(); using (MySqlCommand cmd = new MySqlCommand(null, conn)) { cmd.CommandText = "SELECT * FROM save_mission WHERE mission_date = @date"; cmd.Parameters.Add(new MySqlParameter("date", MySqlDbType.Date) { Value = dt }); MySqlDataReader reader = cmd.ExecuteReader(); if (reader.Read()) { mission_id = reader.GetInt32("mission_id"); } reader.Close(); if (mission_id == -1) { cmd.CommandText = "INSERT INTO save_mission (mission_name, mission_date) " + "VALUES (@name, @date); SELECT LAST_INSERT_ID();"; cmd.Parameters.Clear(); cmd.Parameters.AddWithValue("name", mission_name); cmd.Parameters.Add(new MySqlParameter("date", MySqlDbType.Date) { Value = dt }); mission_id = Convert.ToInt32(cmd.ExecuteScalar()); } MissionID = mission_id; } return(mission_id); }
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); } }
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 void Save() { if (DataSettings.UseDatabase) { int mission_id = Mission.GetMissionId(); MySqlConnection conn = DataSettings.GetConnection(); using (MySqlCommand cmd = new MySqlCommand(null, conn)) { //Store real data Dictionary <int, FlightRadarData> CloneReal = new Dictionary <int, FlightRadarData>(realTrack); foreach (int id in CloneReal.Keys) { FlightRadarData fd = CloneReal[id]; cmd.CommandText = "INSERT INTO real_track VALUES (@id, @name, @iff, @lat, @lng, @dir, @speed, @mission) " + "ON DUPLICATE KEY UPDATE tk_name = @name, tk_iff = @iff, tk_lat = @lat, tk_lng = @lng, tk_dir = @dir, tk_speed = @speed"; cmd.Parameters.Clear(); cmd.Parameters.AddWithValue("id", fd.Id); cmd.Parameters.AddWithValue("name", fd.name); cmd.Parameters.AddWithValue("iff", fd.identification); cmd.Parameters.AddWithValue("lat", fd.point.Lat); cmd.Parameters.AddWithValue("lng", fd.point.Lng); cmd.Parameters.AddWithValue("dir", fd.bearing); cmd.Parameters.AddWithValue("speed", fd.speed); cmd.Parameters.AddWithValue("mission", mission_id); cmd.ExecuteNonQuery(); } //Store faker data Dictionary <int, FlightRadarData> CloneFaker = new Dictionary <int, FlightRadarData>(fakerTrack); foreach (int id in CloneFaker.Keys) { FlightRadarData fd = CloneFaker[id]; cmd.CommandText = "INSERT INTO faker_track VALUES (@id, @name, @iff, @lat, @lng, @dir, @speed, @auto, @mission) " + "ON DUPLICATE KEY UPDATE tk_name = @name, tk_iff = @iff, tk_lat = @lat, tk_lng = @lng, tk_dir = @dir, tk_speed = @speed, tk_auto = @auto"; cmd.Parameters.Clear(); cmd.Parameters.AddWithValue("id", fd.Id); cmd.Parameters.AddWithValue("name", fd.name); cmd.Parameters.AddWithValue("iff", fd.identification); cmd.Parameters.AddWithValue("lat", fd.point.Lat); cmd.Parameters.AddWithValue("lng", fd.point.Lng); cmd.Parameters.AddWithValue("dir", fd.bearing); cmd.Parameters.AddWithValue("speed", fd.speed); cmd.Parameters.AddWithValue("auto", fd.auto); cmd.Parameters.AddWithValue("mission", mission_id); cmd.ExecuteNonQuery(); } } } }
public static void testDoWork() { /* * for (int i = 0; i < flightSimulation.Count; i++) * { * FlightRadarData fd = flightSimulation[i]; * if (fd.auto) * { * DateTime now = DateTime.Now; * double intervalSecond = (fd.time != null) ? now.Subtract(fd.time.Value).TotalMilliseconds / 1000 : 0; * double distance = getDistanceFrom(ScaleConverter.ConvertSpeed(fd.speed, "kts", "km/h"), intervalSecond); * PointLatLng p = FindPointAtDistanceFrom(fd.point, DegreesToRadians(fd.bearing), distance); * FlightRadarData tempfd = new FlightRadarData(fd, p, now); * flightSimulation[i] = tempfd; * } * } */ Track track = Track.GetInstance(); foreach (int faker in track.Fakers) { FlightRadarData fd = track.GetFaker(faker); if (fd.auto) { DateTime now = DateTime.Now; double intervalSecond = (fd.time != null) ? now.Subtract(fd.time.Value).TotalMilliseconds / 1000 : 0; double distance = getDistanceFrom(ScaleConverter.ConvertSpeed(fd.speed, "kts", "km/h"), intervalSecond); PointLatLng p = FindPointAtDistanceFrom(fd.point, DegreesToRadians(fd.bearing), distance); fd.lastPoint = fd.point; fd.point = p; fd.time = now; if (DataSettings.UseDatabase) { MySqlConnection conn = DataSettings.GetConnection(); using (MySqlCommand cmd = new MySqlCommand(null, conn)) { cmd.CommandText = "INSERT INTO faker_track_point (point_lat, point_lng, faker_id) VALUES (@lat, @lng, @id)"; cmd.Parameters.AddWithValue("lat", fd.lastPoint.Lat); cmd.Parameters.AddWithValue("lng", fd.lastPoint.Lng); cmd.Parameters.AddWithValue("id", fd.Id); cmd.ExecuteNonQuery(); } } } } }
public bool LoadMarker(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("markersP"); foreach (int id in Markers.Keys) { var dat = Markers[id]; overlay.Markers.Remove(dat.Marker); } Markers.Clear(); //load symbol marker cmd.CommandText = "SELECT * FROM marker_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("marker_id"); string name = reader.GetString("marker_name"); int img_index = reader.GetInt32("marker_imgindex"); int img_id = reader.GetInt32("marker_imgid"); double lat = reader.GetDouble("marker_lat"); double lng = reader.GetDouble("marker_lng"); SymbolInfo sinfo = new SymbolInfo(mission_id, id, name); sinfo.ImgIndex = img_index; sinfo.ImgID = img_id; sinfo.Point = new PointLatLng(lat, lng); sinfo.Marker = MarkSymbol(img_id, name, sinfo.Point, id); Markers.Add(id, sinfo); } } } } return(result); }
public void AddMarker(PointLatLng Point, string Name, int Img_index, int Img_ID) { SymbolInfo sinfo; int mission_id, marker_id; if (DataSettings.UseDatabase) { mission_id = Mission.GetMissionId(); MySqlConnection conn = DataSettings.GetConnection(); using (MySqlCommand cmd = new MySqlCommand(null, conn)) { cmd.CommandText = "INSERT INTO marker_info (marker_name, marker_imgindex, marker_imgid, marker_lat, marker_lng, mission_id) " + "VALUES (@name, @img_index, @img_id, @lat, @lng, @mission_id); SELECT LAST_INSERT_ID();"; cmd.Parameters.Clear(); cmd.Parameters.AddWithValue("name", Name); cmd.Parameters.AddWithValue("img_index", Img_index); cmd.Parameters.AddWithValue("img_id", Img_ID); cmd.Parameters.AddWithValue("lat", Point.Lat); cmd.Parameters.AddWithValue("lng", Point.Lng); cmd.Parameters.AddWithValue("mission_id", mission_id); marker_id = Convert.ToInt32(cmd.ExecuteScalar()); sinfo = new SymbolInfo(mission_id, marker_id, Name); sinfo.ImgIndex = Img_index; sinfo.ImgID = Img_ID; sinfo.Point = Point; sinfo.Marker = MarkSymbol(Img_ID, Name, Point, marker_id); } } else { mission_id = 0; marker_id = simID++; sinfo = new SymbolInfo(mission_id, marker_id, Name); sinfo.ImgIndex = Img_index; sinfo.ImgID = Img_ID; sinfo.Point = Point; sinfo.Marker = MarkSymbol(Img_ID, Name, Point, marker_id); } Markers.Add(marker_id, sinfo); }
public void RemoveMarker(int ID) { if (Markers.ContainsKey(ID)) { SymbolInfo sinfo = Markers[ID]; GMapOverlay overlay = Main.GetOverlay("markersP"); overlay.Markers.Remove(sinfo.Marker); Markers.Remove(ID); if (DataSettings.UseDatabase) { MySqlConnection conn = DataSettings.GetConnection(); using (MySqlCommand cmd = new MySqlCommand(null, conn)) { cmd.CommandText = "DELETE FROM marker_info WHERE marker_id = @id"; cmd.Parameters.Clear(); cmd.Parameters.AddWithValue("id", ID); cmd.ExecuteNonQuery(); } } } }
public void CompareDict(Dictionary <int, RecievedTrackData> prev, Dictionary <int, RecievedTrackData> curr) { if (DataSettings.UseDatabase) { MySqlConnection conn = DataSettings.GetConnection(); List <int> keys = new List <int>(curr.Keys); using (MySqlCommand cmd = new MySqlCommand(null, conn)) { foreach (int id in curr.Keys) { RecievedTrackData track = curr[id]; FlightRadarData fd = GetReal(track.TrackNumber); cmd.CommandText = "INSERT INTO real_track_point (point_lat, point_lng, real_id) VALUES (@lat, @lng, @id)"; cmd.Parameters.Clear(); cmd.Parameters.AddWithValue("lat", fd.point.Lat); cmd.Parameters.AddWithValue("lng", fd.point.Lng); cmd.Parameters.AddWithValue("id", fd.Id); cmd.ExecuteNonQuery(); } if (keys.Count > 0) { cmd.CommandText = "DELETE FROM real_track WHERE tk_id NOT IN (" + string.Join(",", keys) + ")"; } else { cmd.CommandText = "DELETE FROM real_track"; } cmd.ExecuteNonQuery(); } } foreach (int id in prev.Keys) { if (!curr.ContainsKey(id)) { RecievedTrackData data = prev[id]; RemoveReal(data.TrackNumber); } } }
public void RemovePolygon(int ID) { if (Polygons.ContainsKey(ID)) { AreaInfo ainfo = Polygons[ID]; GMapOverlay overlay = Main.GetOverlay("polygons"); overlay.Markers.Remove((GmapMarkerWithLabel)ainfo.Polygon.Tag); overlay.Polygons.Remove(ainfo.Polygon); Polygons.Remove(ID); if (DataSettings.UseDatabase) { MySqlConnection conn = DataSettings.GetConnection(); using (MySqlCommand cmd = new MySqlCommand(null, conn)) { cmd.CommandText = "DELETE FROM polygon_info WHERE area_id = @id"; cmd.Parameters.Clear(); cmd.Parameters.AddWithValue("id", ID); cmd.ExecuteNonQuery(); } } } }
public void SaveMarker(DateTime dt) { if (DataSettings.UseDatabase) { int mission_id = -1; MySqlConnection conn = DataSettings.GetConnection(); using (MySqlCommand cmd = new MySqlCommand(null, conn)) { //get mission id cmd.CommandText = "SELECT * FROM save_mission WHERE mission_date = @date"; cmd.Parameters.Clear(); cmd.Parameters.AddWithValue("date", dt); using (MySqlDataReader reader = cmd.ExecuteReader()) { if (reader.Read()) { mission_id = reader.GetInt32("mission_id"); } } foreach (int id in Markers.Keys) { SymbolInfo sinfo = Markers[id]; cmd.CommandText = "INSERT INTO marker_info VALUES (@id, @name, @img_index, @img_id, @lat, @lng, @mission_id) " + "ON DUPLICATE KEY UPDATE marker_name = @name, marker_imgindex = @img_index, marker_imgid = @img_id, marker_lat = @lat, marker_lng = @lng"; cmd.Parameters.Clear(); cmd.Parameters.AddWithValue("id", sinfo.ID); cmd.Parameters.AddWithValue("name", sinfo.Name); cmd.Parameters.AddWithValue("img_index", sinfo.ImgIndex); cmd.Parameters.AddWithValue("img_id", sinfo.ImgID); cmd.Parameters.AddWithValue("lat", sinfo.Point.Lat); cmd.Parameters.AddWithValue("lng", sinfo.Point.Lng); cmd.Parameters.AddWithValue("mission_id", sinfo.Mission); cmd.ExecuteNonQuery(); } } } }