// Event handler: A marker, as defined in e.Marker, has been either added (if e.IsNew is true) or deleted (if it is false) // Depending on which it is, add or delete the tag from the current counter control's list of tags // If its deleted, remove the tag from the current counter control's list of tags // Every addition / deletion requires us to: // - update the contents of the counter control // - update the data held by the image // - update the list of markers held by that counter // - regenerate the list of markers used by the markableCanvas private void MarkableCanvas_RaiseMarkerEvent(object sender, MarkerEventArgs e) { // A marker has been added if (e.IsNew) { DataEntryCounter currentCounter = this.FindSelectedCounter(); // No counters are selected, so don't mark anything if (currentCounter == null) { return; } this.MarkableCanvas_AddMarker(currentCounter, e.Marker); return; } // An existing marker has been deleted. DataEntryCounter counter = (DataEntryCounter)this.DataEntryControls.ControlsByDataLabel[e.Marker.DataLabel]; // Decrement the counter only if there is a number in it string oldCounterData = counter.Content; string newCounterData = String.Empty; if (oldCounterData != String.Empty) { int count = Convert.ToInt32(oldCounterData); count = (count == 0) ? 0 : count - 1; // Make sure its never negative, which could happen if a person manually enters the count newCounterData = count.ToString(); } if (!newCounterData.Equals(oldCounterData)) { // Don't bother updating if the value hasn't changed (i.e., already at a 0 count) // Update the datatable and database with the new counter values this.dataHandler.IsProgrammaticControlUpdate = true; counter.SetContentAndTooltip(newCounterData); this.dataHandler.IsProgrammaticControlUpdate = false; this.dataHandler.FileDatabase.UpdateFile(this.dataHandler.ImageCache.Current.ID, counter.DataLabel, newCounterData); } // Remove the marker in memory and from the database MarkersForCounter markersForCounter = null; foreach (MarkersForCounter markers in this.markersOnCurrentFile) { if (markers.Markers.Count == 0) { continue; } if (markers.Markers[0].DataLabel == markers.DataLabel) { markersForCounter = markers; break; } } if (markersForCounter != null) { markersForCounter.RemoveMarker(e.Marker); this.Speak(counter.Content); // Speak the current count this.dataHandler.FileDatabase.SetMarkerPositions(this.dataHandler.ImageCache.Current.ID, markersForCounter); } this.MarkableCanvas_UpdateMarkers(); }
private void SendMarkerEvent(MarkerEventArgs e) { if (this.MarkerEvent != null) { this.MarkerEvent(this, e); } }