/// <summary> /// Load waypoints from a file to the Waypoints table. If a waypoint already exists (matched by name) for, /// this event it's either replaced or skipped depending on <paramref name="replaceExistingWaypoints"/> value. /// </summary> /// <param name="eventId"></param> /// <param name="fileUpload"></param> /// <param name="replaceExistingWaypoints">If true, existing waypoints (matched by name) replaced with values /// from the uploaded file. Otherwise it's skipped.</param> public static int LoadWaypoints(int eventId, FileUpload fileUpload, bool replaceExistingWaypoints) { int updatedRows = 0; if (!fileUpload.HasFile) { throw new ApplicationException("No file loaded."); } string fileExtension = Path.GetExtension(fileUpload.FileName).ToLower(); TrackerDataSetTableAdapters.WaypointTableAdapter adapter = new TrackerDataSetTableAdapters.WaypointTableAdapter(); TrackerDataSet.WaypointDataTable existingData = adapter.GetDataByEventId(eventId); TrackerDataSet.WaypointDataTable uploadedWaypoints; if (fileExtension == ".kml") uploadedWaypoints = LoadKml(fileUpload, eventId); else if (fileExtension == ".cup") uploadedWaypoints = LoadCup(fileUpload, eventId); else if (fileExtension == ".gpx") uploadedWaypoints = LoadGpx(fileUpload, eventId); else throw new ApplicationException( $"'{fileExtension}' files are not supported for waypoints upload. Use either Google Earth (*.KML), or SeeYou waypoints (*.CUP), or GPS Exchange Format (*.GPX) files"); if (uploadedWaypoints.Count > 0) { // At the moment uploadedWaypoints has negative values (-1, -2, ...) in Id column, // while existingData has real IDs from DB. To match them, use Name field as a key: uploadedWaypoints.SetNameKeyOnly(); existingData.SetNameKeyOnly(); existingData.Merge(uploadedWaypoints); } updatedRows = adapter.Update(existingData); return updatedRows; }
protected void deleteBtn_Click( object sender , EventArgs e ) { TrackerDataSetTableAdapters.WaypointTableAdapter waypointTableAdapter = new TrackerDataSetTableAdapters.WaypointTableAdapter( ); waypointTableAdapter.DeleteEventWaypoints( EventId ); this.DataBind( ); }
private void LoadAllWaypoints() { TrackerDataSetTableAdapters.WaypointTableAdapter waypointsAdapter = new TrackerDataSetTableAdapters.WaypointTableAdapter(); _allEventWaypoints = waypointsAdapter.GetDataByEventId(EventId); }