// Auslagern der After Select Funktionalität, um direkten Zugriff zu gewährleisten private void afterSelect(TreeNode node) { Cursor.Current = Cursors.WaitCursor; if (node != null) { TreeViewNodeData data = node.Tag as TreeViewNodeData; if (data == null) { Cursor.Current = Cursors.Default; MessageBox.Show("While selecting a node a Display Error occured!", "Display Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1); pictureBoxHome_Click(null, null); return; } TreeNode represent; try { switch (data.NodeType) { case TreeViewNodeTypes.EventSeriesNode: CollectionEventSeries es = null; if (data.ID != null) { if (EventSeriess.Instance.Find((int)data.ID)) { es = EventSeriess.Instance.Current; this._events = EventSeriess.Instance.CollectionEvents; } else throw new ArgumentOutOfRangeException("EventSeries not found"); } else { EventSeriess.Instance.Current = null; this._events = new CollectionEvents(null); } this.labelPosition.Text = EventSeriess.Instance.Position; this._actualLvl = TreeViewNodeTypes.EventSeriesNode; represent = this._tvOperations.findRepresentantOfType(node); if (represent.Text.Equals("-1")) { displayEventSeries(es); } else if (represent != this._tvOperations.findRepresentantOfType(this._lastSelection)) { try { displayEventSeries(es); } catch (Exception e) { Cursor.Current = Cursors.Default; MessageBox.Show(e.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1); pictureBoxHome_Click(null, null); return; } } this._lastSelection = this.treeViewFieldData.SelectedNode; break; case TreeViewNodeTypes.EventNode: CollectionEvent ce = DataFunctions.Instance.RetrieveCollectionEvent((int)data.ID); if (ce != null) { int? serID = ce.SeriesID; this._events = new CollectionEvents(serID); this._events.Find(ce.CollectionEventID); ce = this._events.Current; } else { Cursor.Current = Cursors.Default; MessageBox.Show("DisplayError", "DisplayError", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1); pictureBoxHome_Click(null, null); return; } //Absichern, dass das Event über "+" gefunden wurde. //Absichern, dass das event nicht gefunden wird //Absichern, dass die EventSeries korrekt ist //Absichern, dass specimen belegt ist this._specimen = this._events.Specimen; this.labelPosition.Text = this._events.Position; this._actualLvl = TreeViewNodeTypes.EventNode; represent = this._tvOperations.findRepresentantOfType(node); if (represent.Text.Equals("-1")) { displayEvent(ce); } else if (represent != this._tvOperations.findRepresentantOfType(this._lastSelection)) { try { displayEvent(ce); } catch (Exception e) { Cursor.Current = Cursors.Default; MessageBox.Show(e.Message, "DisplayError", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1); pictureBoxHome_Click(null, null); return; } } this._lastSelection = this.treeViewFieldData.SelectedNode; break; case TreeViewNodeTypes.SpecimenNode: CollectionSpecimen spec = DataFunctions.Instance.RetrieveCollectionSpecimen((int)data.ID);//Wárum DataFunctions? //Absichern, dass das Event über "+" gefunden wurde. //Absichern, dass das event nicht gefunden wird //Absichern, dass die EventSeries korrekt ist //Absichern, dass specimen belegt ist if (spec != null) { int? serID = spec.CollectionEvent.SeriesID; CollectionEvent ev = spec.CollectionEvent; this._events = new CollectionEvents(serID); this._events.Find(ev.CollectionEventID); try { this._specimen = this._events.Specimen; } catch (DataFunctionsException ex) { Cursor.Current = Cursors.Default; MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1); pictureBoxHome_Click(null, null); return; } if (!this._specimen.Find(spec.CollectionSpecimenID)) { Cursor.Current = Cursors.Default; MessageBox.Show("Data of selected Specimen couldn't be retrieved.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1); pictureBoxHome_Click(null, null); return; } this._iu = this._specimen.IdentificationUnits; spec = this._specimen.Current;//Durch Find erledigt, oder this.labelPosition.Text = this._specimen.Position; this._actualLvl = TreeViewNodeTypes.SpecimenNode; represent = this._tvOperations.findRepresentantOfType(node); if (represent.Text.Equals("-1")) { displaySpecimen(spec); } else if (represent != this._tvOperations.findRepresentantOfType(this._lastSelection)) { try { displaySpecimen(spec); } catch (Exception e) { Cursor.Current = Cursors.Default; MessageBox.Show(e.Message, "DisplayError", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1); pictureBoxHome_Click(null, null); return; } } } else { Cursor.Current = Cursors.Default; MessageBox.Show("DisplayError", "DisplayError", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1); pictureBoxHome_Click(null, null); return; } this._lastSelection = this.treeViewFieldData.SelectedNode; break; case TreeViewNodeTypes.IdentificationUnitNode: IdentificationUnit iu = DataFunctions.Instance.RetrieveIdentificationUnit((int)data.ID); //Absichern, dass das Event über "+" gefunden wurde. //Absichern, dass das event nicht gefunden wird //Absichern, dass die EventSeries korrekt ist //Absichern, dass specimen belegt ist if (iu != null) { int? sID = iu.CollectionSpecimen.CollectionEvent.SeriesID; CollectionEvent evIu = iu.CollectionSpecimen.CollectionEvent; this._events = new CollectionEvents(sID); this._events.Find(evIu.CollectionEventID); try { this._specimen = this._events.Specimen; } catch (DataFunctionsException ex) { Cursor.Current = Cursors.Default; MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1); pictureBoxHome_Click(null, null); return; } if (!this._specimen.Find(iu.CollectionSpecimenID)) { Cursor.Current = Cursors.Default; MessageBox.Show("Data of selected Specimen couldn't be retrieved.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1); pictureBoxHome_Click(null, null); return; } this._iu = this._specimen.IdentificationUnits; if (this._iu == null) { Cursor.Current = Cursors.Default; MessageBox.Show("Data of associated Identification Units couldn't be retrieved.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1); pictureBoxHome_Click(null, null); return; } this._iu.FindTopLevelIU(this.findIUTopLevelID(iu)); this._actualLvl = TreeViewNodeTypes.IdentificationUnitNode; this.labelPosition.Text = this._iu.Position; represent = this._tvOperations.findRepresentantOfType(node); if (represent.Text.Equals("-1")) { displayIdentificationUnit(iu); } else if (represent != this._tvOperations.findRepresentantOfType(this._lastSelection)) { try { displayIdentificationUnit(iu); } catch (Exception e) { Cursor.Current = Cursors.Default; MessageBox.Show(e.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1); pictureBoxHome_Click(null, null); return; } } } else { Cursor.Current = Cursors.Default; MessageBox.Show("DisplayError", "DisplayError", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1); pictureBoxHome_Click(null, null); return; } this._lastSelection = this.treeViewFieldData.SelectedNode; break; case TreeViewNodeTypes.AnalysisNode: this._actualLvl = TreeViewNodeTypes.AnalysisNode; this.labelPosition.Text = String.Empty; break; case TreeViewNodeTypes.GeographyNode: this._actualLvl = TreeViewNodeTypes.GeographyNode; this.labelPosition.Text = String.Empty; break; case TreeViewNodeTypes.LocalisationNode: this._actualLvl = TreeViewNodeTypes.LocalisationNode; this.labelPosition.Text = String.Empty; break; case TreeViewNodeTypes.AgentNode: this._actualLvl = TreeViewNodeTypes.AgentNode; this.labelPosition.Text = String.Empty; break; case TreeViewNodeTypes.SitePropertyNode: this._actualLvl = TreeViewNodeTypes.SitePropertyNode; this.labelPosition.Text = String.Empty; break; default: this._actualLvl = TreeViewNodeTypes.Unknown; break; } } catch (ConnectionCorruptedException ex) { Cursor.Current = Cursors.Default; MessageBox.Show(ex.Message, "Exception", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1); pictureBoxHome_Click(null, null); return; } Cursor.Current = Cursors.Default; enableDisableToolbarButtons(_actualLvl); enableDisableButtons(_actualLvl); } }
/// <summary> /// Handles the Click event of the pictureBoxNewSpecimen control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> private void pictureBoxNewSpecimen_Click(object sender, EventArgs e) { if (this.treeViewFieldData.Nodes.Count == 0 || this.treeViewFieldData.SelectedNode == null) { return; } Cursor.Current = Cursors.WaitCursor; TreeNode eventNode = this.treeViewFieldData.SelectedNode; TreeViewNodeData eventData = eventNode.Tag as TreeViewNodeData; if (eventData == null) return; if (eventData.NodeType != TreeViewNodeTypes.EventNode) return; TreeNode seriesNode = eventNode.Parent; TreeViewNodeData seriesData = seriesNode.Tag as TreeViewNodeData; int? seriesID = seriesData.ID; try { if (seriesData.ID != null) { EventSeriess.Instance.Find((int)seriesData.ID); this._events = EventSeriess.Instance.CollectionEvents; } else this._events = new CollectionEvents(null); } catch (ConnectionCorruptedException ex) { MessageBox.Show(ex.Message, "Exception", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1); return; } this._events.Find((int)eventData.ID); this._specimen = this._events.Specimen; if (this._specimen != null) { CollectionSpecimen cs; try { cs = this._specimen.CreateSpecimen(); this._iu = this._specimen.IdentificationUnits; } catch (DataFunctionsException ex) { Cursor.Current = Cursors.Default; MessageBox.Show("Specimen couldn't be created. (" + ex.Message + ")", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1); this.treeViewFieldData.EndUpdate(); return; } this.treeViewFieldData.BeginUpdate(); TreeNode specNode = new TreeNode(); this._tvOperations.parametrizeOnlySpecimenNode(cs, specNode); this.labelPosition.Text = this._specimen.Position; this.treeViewFieldData.SelectedNode.Nodes.Add(specNode); this.treeViewFieldData.SelectedNode = specNode; if (!this.treeViewFieldData.SelectedNode.IsExpanded) { this._expandTrigger = false; this.treeViewFieldData.SelectedNode.ExpandAll(); this._expandTrigger = true; } this.enableDisableButtons(TreeViewNodeTypes.SpecimenNode); this._actualLvl = TreeViewNodeTypes.SpecimenNode; this.enableDisableToolbarButtons(_actualLvl); this.treeViewFieldData.EndUpdate(); } Cursor.Current = Cursors.Default; }
private void pictureBoxNewLocalisation_Click(object sender, EventArgs e) { if (this.treeViewFieldData.Nodes.Count == 0 || this.treeViewFieldData.SelectedNode == null || this.treeViewFieldData.SelectedNode.Tag == null) { return; } SelectLocalisationSystemDialog dlg = new SelectLocalisationSystemDialog(); dlg.Location = new Point((this.Size.Width) / 2 - (dlg.Size.Width) / 2, this.Location.Y); if (dlg.ShowDialog() != DialogResult.OK) return; try { TreeNode eventNode = this.treeViewFieldData.SelectedNode; TreeViewNodeData eventData = eventNode.Tag as TreeViewNodeData; if (eventData == null) return; if (eventData.NodeType != TreeViewNodeTypes.EventNode) return; TreeNode seriesNode = eventNode.Parent; TreeViewNodeData seriesData = seriesNode.Tag as TreeViewNodeData; int? seriesID = seriesData.ID; try { if (seriesData.ID != null) { EventSeriess.Instance.Find((int)seriesData.ID); this._events = EventSeriess.Instance.CollectionEvents; } else this._events = new CollectionEvents(null); } catch (ConnectionCorruptedException ex) { MessageBox.Show(ex.Message, "Exception", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1); return; } this._events.Find((int)eventData.ID); if (dlg.selection.Equals("GPS")) { if (eventData.NodeType == TreeViewNodeTypes.EventNode) { bool updateLocAlt = false; bool updateLocGPS = false; CollectionEventLocalisation locAlt = DataFunctions.Instance.RetrieveCollectionEventLocalisation(4, this._events.Current.CollectionEventID); CollectionEventLocalisation locGPS = DataFunctions.Instance.RetrieveCollectionEventLocalisation(8, this._events.Current.CollectionEventID); //Prüft ob dem Event bereits ein Localisatiobnsystem mit WGS84 Koordinaten und einer Höhe //angelegt sind. Wenn mehrere existieren, wird das erste genommen. if (locAlt != null) { updateLocAlt = true; } else { try { locAlt = DataFunctions.Instance.CreateCollectionEventLocalisation(4, this._events.Current); } catch (DataFunctionsException ex) { Cursor.Current = Cursors.Default; MessageBox.Show(ex.Message + " (Type: Altitude)", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1); return; } } if (locGPS != null) { updateLocGPS = true; } else { try { locGPS = DataFunctions.Instance.CreateCollectionEventLocalisation(8, this._events.Current); } catch (DataFunctionsException ex) { Cursor.Current = Cursors.Default; MessageBox.Show(ex.Message + " (Type: GPS)", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1); return; } } NewGPSLocalisationForm gpsForm = null; try { gpsForm = new NewGPSLocalisationForm(locAlt, locGPS); if (gpsForm == null) return; } catch (ContextCorruptedException ex) { Cursor.Current = Cursors.Default; MessageBox.Show(ex.Message, "Context Exception", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1); return; } // Dialog zentrieren gpsForm.Location = new Point((this.Size.Width) / 2 - (gpsForm.Size.Width) / 2, this.Location.Y); if (gpsForm.ShowDialog() == DialogResult.OK) { Cursor.Current = Cursors.WaitCursor; this.treeViewFieldData.BeginUpdate(); // Localisation einbinden try { DataFunctions.Instance.Update(locGPS); DataFunctions.Instance.Update(locAlt); } catch (DataFunctionsException ex) { Cursor.Current = Cursors.Default; MessageBox.Show(ex.Message + " (Type: GPS / Altitude)", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1); this.afterSelect(this.treeViewFieldData.SelectedNode); this.treeViewFieldData.EndUpdate(); return; } if (!updateLocGPS) { TreeNode nodeGPS = new TreeNode(); this._tvOperations.parameterizeCollectionEventLocalisationNode(locGPS, nodeGPS); this.treeViewFieldData.SelectedNode.Nodes.Insert(0, nodeGPS); if (!this.treeViewFieldData.SelectedNode.IsExpanded) { this._expandTrigger = false; this.treeViewFieldData.SelectedNode.Expand(); this._expandTrigger = true; } } else { foreach (TreeNode item in this.treeViewFieldData.SelectedNode.Nodes) { if (item != null) { if ((item.Tag as TreeViewNodeData).NodeType == TreeViewNodeTypes.LocalisationNode) { if ((item.Tag as TreeViewNodeData).ID == locGPS.LocalisationSystemID) { this._tvOperations.parameterizeCollectionEventLocalisationNode(locGPS, item); this.treeViewFieldData.Refresh(); } } } } } if (!updateLocAlt) { TreeNode nodeAlt = new TreeNode(); this._tvOperations.parameterizeCollectionEventLocalisationNode(locAlt, nodeAlt); this.treeViewFieldData.SelectedNode.Nodes.Insert(0, nodeAlt); if (!this.treeViewFieldData.SelectedNode.IsExpanded) { this._expandTrigger = false; this.treeViewFieldData.SelectedNode.Expand(); this._expandTrigger = true; } } else { foreach (TreeNode item in this.treeViewFieldData.SelectedNode.Nodes) { if (item != null) { if ((item.Tag as TreeViewNodeData).NodeType == TreeViewNodeTypes.LocalisationNode) { if ((item.Tag as TreeViewNodeData).ID == locAlt.LocalisationSystemID) { this._tvOperations.parameterizeCollectionEventLocalisationNode(locAlt, item); this.treeViewFieldData.Refresh(); } } } } } Cursor.Current = Cursors.Default; this.treeViewFieldData.EndUpdate(); } } } if (dlg.selection.Equals("SamplingPlot")) { Cursor.Current = Cursors.WaitCursor; bool update = false; CollectionEventLocalisation ceLoc = DataFunctions.Instance.RetrieveCollectionEventLocalisation(13, this._events.Current.CollectionEventID); if (ceLoc != null) { update = true; } IList<SamplingPlots> plots = DataFunctions.Instance.RetrieveAllSamplingPlots(); List<String> list = new List<string>(); foreach (SamplingPlots plot in plots) { if (plot != null) list.Add(plot.Name); } if (list.Count < 1) { MessageBox.Show("There are no selectable SamplingPlots!"); Cursor.Current = Cursors.Default; return; } SelectDialog sdl = new SelectDialog("Select Sampling Plot", list); Cursor.Current = Cursors.Default; if (sdl.ShowDialog() != DialogResult.OK) return; Cursor.Current = Cursors.WaitCursor; if (update == false) { try { ceLoc = DataFunctions.Instance.CreateCollectionEventLocalisation(13, this._events.Current); } catch (DataFunctionsException ex) { Cursor.Current = Cursors.Default; MessageBox.Show(ex.Message + " (Type: Sampling Plot)", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1); return; } } if (ceLoc != null) { SamplingPlots selected = DataFunctions.Instance.RetrieveSamplingPlot(sdl.Value); if (selected != null) { ceLoc.Location1 = selected.Name; ceLoc.Location2 = selected.URI; try { DataFunctions.Instance.Update(ceLoc); } catch (DataFunctionsException ex) { Cursor.Current = Cursors.Default; MessageBox.Show(ex.Message + " (Type: Sampling Plot)", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1); this.afterSelect(this.treeViewFieldData.SelectedNode); return; } } this.treeViewFieldData.BeginUpdate(); TreeNode nodePlot = new TreeNode(); this._tvOperations.parameterizeCollectionEventLocalisationNode(ceLoc, nodePlot); TreeViewNodeData plotData = nodePlot.Tag as TreeViewNodeData; if (update == false) this.treeViewFieldData.SelectedNode.Nodes.Insert(0, nodePlot); else { foreach (TreeNode tn in this.treeViewFieldData.SelectedNode.Nodes) { if (tn != null) { TreeViewNodeData childData = tn.Tag as TreeViewNodeData; if (childData.ID == plotData.ID && childData.NodeType == TreeViewNodeTypes.LocalisationNode) { int index = tn.Index; this.treeViewFieldData.SelectedNode.Nodes.Remove(tn); this.treeViewFieldData.SelectedNode.Nodes.Insert(index, nodePlot); break; } } } } if (!this.treeViewFieldData.SelectedNode.IsExpanded) { this._expandTrigger = false; this.treeViewFieldData.SelectedNode.Expand(); this._expandTrigger = true; } } } } catch (ConnectionCorruptedException ex) { Cursor.Current = Cursors.Default; MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1); this.pictureBoxHome_Click(null, null); return; } this._actualLvl = TreeViewNodeTypes.LocalisationNode; this.enableDisableToolbarButtons(_actualLvl); this.treeViewFieldData.EndUpdate(); Cursor.Current = Cursors.Default; }
/// <summary> /// Handles the Click event of the pictureBoxNewIdentificationUnit control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> private void pictureBoxNewIdentificationUnit_Click(object sender, EventArgs e) { if (this.treeViewFieldData.Nodes.Count == 0 || this.treeViewFieldData.SelectedNode == null) { return; } Cursor.Current = Cursors.WaitCursor; TreeNode parentNode = this.treeViewFieldData.SelectedNode; NewIdentificationUnitDialog dlg; TreeViewNodeData data = this.treeViewFieldData.SelectedNode.Tag as TreeViewNodeData; if (data == null) return; // if parent Node is also IdentificationUnit then set some default data int? seriesID = null; CollectionEvent ev = null; CollectionSpecimen cs = null; IdentificationUnit parentIU = null; if (data.NodeType == TreeViewNodeTypes.IdentificationUnitNode) { try { parentIU = DataFunctions.Instance.RetrieveIdentificationUnit((int)data.ID); } catch (ConnectionCorruptedException ex) { Cursor.Current = Cursors.Default; MessageBox.Show("Data of parent Identification Unit couldn't be retrieved. ("+ex.Message+")", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1); return; } if (parentIU != null) { cs = parentIU.CollectionSpecimen; ev = cs.CollectionEvent; seriesID = ev.SeriesID; try { if (seriesID != null) { EventSeriess.Instance.Find((int)seriesID); this._events = EventSeriess.Instance.CollectionEvents; } else this._events = new CollectionEvents(null); } catch (ConnectionCorruptedException ex) { MessageBox.Show(ex.Message, "Exception", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1); return; } this._events.Find((int)ev.CollectionEventID); this._specimen = this._events.Specimen; this._specimen.Find((int)cs.CollectionSpecimenID); this._iu = this._specimen.IdentificationUnits; try { dlg = new NewIdentificationUnitDialog(cs, parentIU, this._iu); } catch (ContextCorruptedException ex) { Cursor.Current = Cursors.Default; MessageBox.Show(ex.Message, "Context Exception", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1); return; } } else { Cursor.Current = Cursors.Default; MessageBox.Show("Data of parent Identification Unit couldn't be retrieved.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1); return; } } else if (data.NodeType == TreeViewNodeTypes.SpecimenNode) { try { TreeNode eventNode = parentNode.Parent; TreeViewNodeData eventData = eventNode.Tag as TreeViewNodeData; TreeNode seriesNode = eventNode.Parent; TreeViewNodeData seriesData = seriesNode.Tag as TreeViewNodeData; seriesID = seriesData.ID; if (seriesID != null) { EventSeriess.Instance.Find((int)seriesID); this._events = EventSeriess.Instance.CollectionEvents; } else this._events = new CollectionEvents(null); this._events.Find((int)eventData.ID); ev = this._events.Current; this._specimen = this._events.Specimen; } catch (ConnectionCorruptedException ex) { MessageBox.Show(ex.Message, "Exception", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1); return; } if (this._specimen.Find((int)data.ID)) { cs = this._specimen.Current; this._iu = this._specimen.IdentificationUnits; try { dlg = new NewIdentificationUnitDialog(cs, this._iu); } catch (ConnectionCorruptedException ex) { Cursor.Current = Cursors.Default; MessageBox.Show("Associated IdentificationUnits with selected Specimen couldn't be retrieved. (" + ex.Message + ")", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1); return; } catch (ContextCorruptedException ex) { Cursor.Current = Cursors.Default; MessageBox.Show("Associated IdentificationUnits with selected Specimen couldn't be retrieved. (" + ex.Message + ")", "Context Exception", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1); return; } } else { Cursor.Current = Cursors.Default; MessageBox.Show("Data of selected Specimen couldn't be retrieved.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1); return; } } else { Cursor.Current = Cursors.Default; MessageBox.Show("Wrong node selected.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1); return; } // center dialog dlg.Location = new Point((this.Size.Width) / 2 - (dlg.Size.Width) / 2, this.Location.Y); Cursor.Current = Cursors.Default; dlg.ShowDialog(); moveTaxonomicGroupToFront(dlg.TaxonomicGroup); if (dlg.Current != null) { IdentificationUnit iu = dlg.Current; TreeViewNodeData parentData = parentNode.Tag as TreeViewNodeData; this.treeViewFieldData.BeginUpdate(); treeViewFieldData.SuspendLayout(); if (parentData.NodeType == TreeViewNodeTypes.SpecimenNode) { displaySpecimen(cs); } if (parentData.NodeType == TreeViewNodeTypes.IdentificationUnitNode) { displayIdentificationUnit(parentIU); } foreach (TreeNode node in treeViewFieldData.SelectedNode.Nodes) { TreeViewNodeData nodeData = node.Tag as TreeViewNodeData; if (nodeData.NodeType == TreeViewNodeTypes.IdentificationUnitNode && nodeData.ID == iu.IdentificationUnitID) { this.treeViewFieldData.SelectedNode = node; break; } } if (!this.treeViewFieldData.SelectedNode.IsExpanded && this._tvOperations.expandLvl <= ExpandLevel.IdentificationUnit) { this._expandTrigger = false; this.treeViewFieldData.SelectedNode.ExpandAll(); this._expandTrigger = true; } this.treeViewFieldData.SelectedNode.EnsureVisible(); this._actualLvl = TreeViewNodeTypes.IdentificationUnitNode; this.enableDisableToolbarButtons(_actualLvl); this.enableDisableButtons(_actualLvl); treeViewFieldData.ResumeLayout(); this.treeViewFieldData.EndUpdate(); } }
private void pictureBoxNewEvent_Click(object sender, EventArgs e) { if (this.treeViewFieldData.SelectedNode == null || this.treeViewFieldData.SelectedNode.Tag == null) { MessageBox.Show("Error, EventSeriesNode has to be selected"); return; } TreeNode seriesNode = this.treeViewFieldData.SelectedNode; TreeViewNodeData data = this.treeViewFieldData.SelectedNode.Tag as TreeViewNodeData; if (data.NodeType != TreeViewNodeTypes.EventSeriesNode) { MessageBox.Show("Error, EventSeriesNode has to be selected!"); return; } int? seriesID = data.ID; try { if (data.ID != null) { EventSeriess.Instance.Find((int) data.ID); this._events = EventSeriess.Instance.CollectionEvents; } else this._events = new CollectionEvents(null); } catch (ConnectionCorruptedException ex) { MessageBox.Show(ex.Message, "Exception", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1); return; } NewEventDialog dlg = null; try { dlg = new NewEventDialog(true); if(dlg == null) return; } catch (ContextCorruptedException ex) { Cursor.Current = Cursors.Default; MessageBox.Show(ex.Message, "Context Exception", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1); return; } dlg.Location = new Point((this.Size.Width) / 2 - (dlg.Size.Width) / 2, this.Location.Y); if (dlg.ShowDialog() == DialogResult.OK) { Cursor.Current = Cursors.WaitCursor; if (this._events != null) { try { if (StaticGPS.isOpened()) { if (StaticGPS.position != null) { double altitude = StaticGPS.position.SeaLevelAltitude; double latitude = float.Parse(StaticGPS.position.Latitude.ToString()); double longitude = float.Parse(StaticGPS.position.Longitude.ToString()); this._events.CreateNewEvent(seriesID, altitude, longitude, latitude, StaticGPS.position.SatelliteCount, StaticGPS.position.PositionDilutionOfPrecision); } else { this._events.CreateNewEvent(seriesID); } } else { this._events.CreateNewEvent(seriesID); } } catch (ConnectionCorruptedException ex) { MessageBox.Show("New CollectionEvent couldn't be created. ("+ex.Message+")", "Exception", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1); return; } catch (DataFunctionsException ex) { MessageBox.Show(ex.Message, "Exception", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1); return; } if (dlg.EventNumber != null) this._events.Current.CollectorsEventNumber = dlg.EventNumber; if (dlg.Notes != null) this._events.Current.Notes = dlg.Notes; if (dlg.DateSupplement != null) this._events.Current.CollectionDateSupplement = dlg.DateSupplement; try { DataFunctions.Instance.Update(this._events.Current); } catch (ConnectionCorruptedException ex) { Cursor.Current = Cursors.Default; MessageBox.Show("Collection Event Data (Event Number, Notes, Date Supplement) couldn't be saved. (" + ex.Message + ")", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1); } catch (DataFunctionsException ex) { Cursor.Current = Cursors.Default; MessageBox.Show("Collection Event Data (Event Number, Notes, Date Supplement) couldn't be saved. ("+ex.Message+")", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1); } TreeNode evNode = new TreeNode(); this.treeViewFieldData.BeginUpdate(); this._tvOperations.parametrizeEventNode(this._events.Current, evNode); this.treeViewFieldData.SelectedNode.Nodes.Add(evNode); this.treeViewFieldData.SelectedNode = evNode; if (!this.treeViewFieldData.SelectedNode.IsExpanded) { this._expandTrigger = false; this.treeViewFieldData.SelectedNode.ExpandAll(); this._expandTrigger = true; } // create automatically CollectionSpecimen CollectionSpecimen spec = null; try { this._specimen = this._events.Specimen; spec = this._specimen.CreateSpecimen(); this._iu = this._specimen.IdentificationUnits; } catch (Exception ex) { String errorMsg = ""; Cursor.Current = Cursors.Default; if (spec != null) { try { DataFunctions.Instance.Remove(spec); } catch (ConnectionCorruptedException except) { errorMsg = "Specimen couldn't be automatically assigned to new Collection Event. (" + except.Message + ")"; } } if (errorMsg.Equals(String.Empty)) { errorMsg = "Specimen couldn't be automatically assigned to new Collection Event. (" + ex.Message + ")"; } MessageBox.Show(errorMsg, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1); this.treeViewFieldData.EndUpdate(); return; } TreeNode specNode = new TreeNode(); this._tvOperations.parametrizeOnlySpecimenNode(spec, specNode); this.labelPosition.Text = this._specimen.Position; this.treeViewFieldData.SelectedNode.Nodes.Add(specNode); this.treeViewFieldData.SelectedNode = specNode; if (!this.treeViewFieldData.SelectedNode.IsExpanded) { this._expandTrigger = false; this.treeViewFieldData.SelectedNode.ExpandAll(); this._expandTrigger = true; } this.enableDisableButtons(TreeViewNodeTypes.SpecimenNode); this._actualLvl = TreeViewNodeTypes.SpecimenNode; enableDisableToolbarButtons(_actualLvl); this.treeViewFieldData.EndUpdate(); } } Cursor.Current = Cursors.Default; }
private void pictureBoxNewEventProperty_Click(object sender, EventArgs e) { if (this.treeViewFieldData.Nodes.Count == 0 || this.treeViewFieldData.SelectedNode == null) { return; } TreeNode eventNode = this.treeViewFieldData.SelectedNode; TreeViewNodeData eventData = eventNode.Tag as TreeViewNodeData; if (eventData == null) return; if (eventData.NodeType != TreeViewNodeTypes.EventNode) return; TreeNode seriesNode = eventNode.Parent; TreeViewNodeData seriesData = seriesNode.Tag as TreeViewNodeData; int? seriesID = seriesData.ID; try { if (seriesData.ID != null) { EventSeriess.Instance.Find((int)seriesData.ID); this._events = EventSeriess.Instance.CollectionEvents; } else this._events = new CollectionEvents(null); } catch (ConnectionCorruptedException ex) { MessageBox.Show(ex.Message, "Exception", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1); return; } this._events.Find((int)eventData.ID); try { NewSitePropertyDialog dlg = new NewSitePropertyDialog(true); // Dialog zentrieren dlg.Location = new Point((this.Size.Width) / 2 - (dlg.Size.Width) / 2, this.Location.Y); dlg.PropertyList = DataFunctions.Instance.RetrievePossibleProperty((int)this._events.Current.CollectionEventID); if (dlg.ShowDialog() == DialogResult.OK) { Cursor.Current = Cursors.WaitCursor; this.treeViewFieldData.BeginUpdate(); // SiteProperty einbinden string propertyText = dlg.DisplayText; int propertyID = dlg.PropertyID; CollectionEventProperty ceProp; try { ceProp = DataFunctions.Instance.CreateCollectionEventProperty(propertyID, propertyText, this._events.Current); } catch (DataFunctionsException ex) { Cursor.Current = Cursors.Default; MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1); return; } TreeNode node = new TreeNode(); this._tvOperations.parameterizeCollectionEventPropertyNode(ceProp, node); this.treeViewFieldData.SelectedNode.Nodes.Insert(0, node);//Erst Properties, dann LocalisationSystems this.treeViewFieldData.SelectedNode = node; if (!this.treeViewFieldData.SelectedNode.IsExpanded) { this._expandTrigger = false; this.treeViewFieldData.SelectedNode.Expand(); this._expandTrigger = true; } this._actualLvl = TreeViewNodeTypes.SitePropertyNode; this.enableDisableToolbarButtons(_actualLvl); this.enableDisableButtons(_actualLvl); this.treeViewFieldData.EndUpdate(); Cursor.Current = Cursors.Default; } } catch (ConnectionCorruptedException ex) { this.treeViewFieldData.EndUpdate(); Cursor.Current = Cursors.Default; MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1); pictureBoxHome_Click(null, null); return; } catch (ContextCorruptedException ex) { this.treeViewFieldData.EndUpdate(); Cursor.Current = Cursors.Default; MessageBox.Show(ex.Message, "Context Exception", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1); pictureBoxHome_Click(null, null); return; } }
private void pictureBoxHome_Click(object sender, EventArgs e) { Cursor.Current = Cursors.WaitCursor; try { EventSeriess.Instance.Current = null; this._events = null; this._specimen = null; this._iu = null; //this.resetTreeView(); Anzeige wird nicht aktualisert. Warum? this.displayAllEventSeries(); this.labelPosition.Text = String.Empty; this.enableDisableButtons(TreeViewNodeTypes.Root); this._actualLvl = TreeViewNodeTypes.Root; this.enableDisableToolbarButtons(_actualLvl); } catch (ConnectionCorruptedException ex) { Cursor.Current = Cursors.Default; MessageBox.Show("Severe Program Exception (" + ex.Message + "). Program will be closed.", "Severe Exception", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1); this.Close(); } Cursor.Current = Cursors.Default; }