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 static void SetSerialPortData(SerialPortType type, Dictionary <string, dynamic> data) { if (Instance == null) { Instance = GetInstance(); } if (type == SerialPortType.Recieving) { Instance.Settings["SerialPort"]["Recieving"] = data; } else if (type == SerialPortType.Sending) { Instance.Settings["SerialPort"]["Sending"] = data; } Instance.Save(); }
public static void SetSerialPort(SerialPortType type, bool open) { if (Instance == null) { Instance = GetInstance(); } if (type == SerialPortType.Recieving) { Instance.Settings["SerialPort"]["Recieving"]["Enable"] = open; } else if (type == SerialPortType.Sending) { Instance.Settings["SerialPort"]["Sending"]["Enable"] = open; } Instance.Save(); }
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 static Dictionary <string, dynamic> GetSerialPortData(SerialPortType type) { if (Instance == null) { Instance = GetInstance(); } Instance.LoadOrDefault(); if (type == SerialPortType.Recieving) { return(Instance.Settings["SerialPort"]["Recieving"]); } else if (type == SerialPortType.Sending) { return(Instance.Settings["SerialPort"]["Sending"]); } return(null); }
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(); } } } }