/// <summary> /// Add/update geologic event in m_GeologicEventsDictionary and events list box /// </summary> private void btnEvtAccept_Click(object sender, EventArgs e) { /// <start> Validate the event inputs before save if (m_theWorkspace == null) { MessageBox.Show("Please open a working space!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (!validateEvtInputs()) { return; } if (txtAgeDisplay.Text == "") { MessageBox.Show("Please input Age Display value!", "Invalid Inputs", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } /// <end> GeologicEventsAccess thisGeologicEventsAccess = new GeologicEventsAccess(m_theWorkspace); string dataSrcID = commonFunctions.GetCurrentDataSourceID(); string thisKey; GeologicEventsAccess.GeologicEvents thisGeologicEvents = new GeologicEventsAccess.GeologicEvents(); if (isUpdate4AgeEvent) { GeologicEventsAccess.GeologicEvents selectedEvent = m_GeologicEventsDictionary[m_EvtListDictionary[liEvts.SelectedItem.ToString()]]; /// Remove the old age display text from the age tab liEvts.Items.Remove(selectedEvent.AgeDisplay); /// Remove item from the evet list for this map unit if (liEvts4ThisUnit.Items.Contains(selectedEvent.AgeDisplay)) { liEvts4ThisUnit.Items.Remove(selectedEvent.AgeDisplay); string thisGeoEvtID = m_EvtListDictionary[selectedEvent.AgeDisplay]; List<string> listIds = new List<string>(); foreach (KeyValuePair<string, ExtendedAttributesAccess.ExtendedAttributes> anExtAttrEntry in m_ExtendedAttributesDictionary) { ExtendedAttributesAccess.ExtendedAttributes thisExtAttr = anExtAttrEntry.Value; if (thisExtAttr.ValueLinkID == thisGeoEvtID) { string thisID = anExtAttrEntry.Key; listIds.Add(thisID); } } for (int i = 0; i < listIds.Count; i++) { m_ExtendedAttributesDictionary.Remove(listIds[i]); } } /// Remove the old connection between list item and age m_EvtListDictionary.Remove(selectedEvent.AgeDisplay); selectedEvent.AgeDisplay = txtAgeDisplay.Text; selectedEvent.Event = cboEvt.SelectedItem.ToString(); selectedEvent.TimeScale = "http://resource.geosciml.org/classifierscheme/ics/ischart/2009"; selectedEvent.Notes = txtNotes.Text; selectedEvent.DataSourceID = commonFunctions.GetCurrentDataSourceID(); switch (cboEventType.SelectedItem.ToString()) { case "Single Age Event": selectedEvent.AgeYoungerTerm = cboSEra.SelectedItem.ToString(); selectedEvent.AgeOlderTerm = cboSEra.SelectedItem.ToString(); selectedEvent.AgeYoungerValue = txtSOlderAge.Text; selectedEvent.AgeOlderValue = txtSYoungerAge.Text; break; case "Age Range Event": selectedEvent.AgeYoungerTerm = cboRYoungerEra.SelectedItem.ToString(); selectedEvent.AgeOlderTerm = cboROlderEra.SelectedItem.ToString(); selectedEvent.AgeYoungerValue = txtROlderAge.Text; selectedEvent.AgeOlderValue = txtRYoungerAge.Text; break; } m_GeologicEventsDictionary.Remove(selectedEvent.GeologicEvents_ID); m_GeologicEventsDictionary.Add(selectedEvent.GeologicEvents_ID, selectedEvent); if (m_EvtListDictionary.ContainsKey(txtAgeDisplay.Text)) { MessageBox.Show("This age display already exists!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { /// Add text item into event list box liEvts.Items.Add(selectedEvent.AgeDisplay); /// Add the new item into list box dictionary m_EvtListDictionary.Add(selectedEvent.AgeDisplay, selectedEvent.GeologicEvents_ID); } } else { switch (cboEventType.SelectedItem.ToString()) { case "Single Age Event": thisGeologicEventsAccess.NewGeologicEvents(cboEvt.SelectedItem.ToString(), txtAgeDisplay.Text, cboSEra.SelectedItem.ToString(), cboSEra.SelectedItem.ToString(), "http://resource.geosciml.org/classifierscheme/ics/ischart/2009", txtSOlderAge.Text, txtSYoungerAge.Text, dataSrcID, txtNotes.Text); thisKey = thisGeologicEventsAccess.GeologicEventsDictionary.First().Key; thisGeologicEvents = thisGeologicEventsAccess.GeologicEventsDictionary.First().Value; /// Add the new event into the dictionary m_GeologicEventsDictionary.Add(thisKey, thisGeologicEvents); break; case "Age Range Event": thisGeologicEventsAccess.NewGeologicEvents(cboEvt.SelectedItem.ToString(), txtAgeDisplay.Text, cboRYoungerEra.SelectedItem.ToString(), cboROlderEra.SelectedItem.ToString(), "http://resource.geosciml.org/classifierscheme/ics/ischart/2009", txtROlderAge.Text, txtRYoungerAge.Text, dataSrcID, txtNotes.Text); thisKey = thisGeologicEventsAccess.GeologicEventsDictionary.First().Key; thisGeologicEvents = thisGeologicEventsAccess.GeologicEventsDictionary.First().Value; /// Add the new event into the dictionary m_GeologicEventsDictionary.Add(thisKey, thisGeologicEvents); break; } if (m_EvtListDictionary.ContainsKey(txtAgeDisplay.Text)) { MessageBox.Show("This age display already exists!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { /// Add text item into event list box liEvts.Items.Add(txtAgeDisplay.Text); /// Add the new item into list box dictionary m_EvtListDictionary.Add(txtAgeDisplay.Text, thisGeologicEvents.GeologicEvents_ID); } } /// Switch into event list tab tabEvtEditor.SelectedTab = tabAgeList; /// Clear the event editing tab initEmptyEventTab(); }
/// <summary> /// Set values for the age event tabs /// The values are from Extended Attributes table and Geologic Events table /// </summary> private void initAgeEventTab(string mapUnit) { m_initMapUnit = mapUnit; if (m_theWorkspace == null) { MessageBox.Show("Please open a working space!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } /// Connect with the Extended Attribute table ExtendedAttributesAccess extAttrAccess = new ExtendedAttributesAccess(m_theWorkspace); /// Search the extended attributes records for this map unit extAttrAccess.AddExtendedAttributes("OwnerID = '" + mapUnit + "'"); m_ExtendedAttributesDictionary = extAttrAccess.ExtendedAttributesDictionary; foreach (KeyValuePair<string, ExtendedAttributesAccess.ExtendedAttributes> anExtendedAttributeEntry in extAttrAccess.ExtendedAttributesDictionary) { ExtendedAttributesAccess.ExtendedAttributes thisExtendedAttribute = anExtendedAttributeEntry.Value; string vLinkId = thisExtendedAttribute.ValueLinkID; if (vLinkId != null) { /// Connect with Geologic Events table GeologicEventsAccess geoEvtsAccess = new GeologicEventsAccess(m_theWorkspace); geoEvtsAccess.AddGeologicEvents("GeologicEvents_ID = '" + vLinkId + "'"); if (geoEvtsAccess.GeologicEventsDictionary.Count != 0) { GeologicEventsAccess.GeologicEvents thisGeologicEvent = geoEvtsAccess.GeologicEventsDictionary.First().Value; liEvts4ThisUnit.Items.Add(thisGeologicEvent.AgeDisplay); } } } }
private void saveAge() { if (m_theWorkspace == null) { MessageBox.Show("Please open a working space!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (txtMapUnitAbbreviation.Text == "") { MessageBox.Show("Please select a valid map unit!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } /// --------------------------------------------------------------------------------------------------------- /// <start> Settings to save geologic events changes -------------------------------------------------------- /// Connect with the Geologic Events table GeologicEventsAccess geoEvtsAccess = new GeologicEventsAccess(m_theWorkspace); geoEvtsAccess.AddGeologicEvents(); Dictionary<string, GeologicEventsAccess.GeologicEvents> deleteGeologicEventsDictionary = new Dictionary<string, GeologicEventsAccess.GeologicEvents>(); foreach (KeyValuePair<string, GeologicEventsAccess.GeologicEvents> anOldGeologicEventsEntry in geoEvtsAccess.GeologicEventsDictionary) { /// Identify if the old record still exits in the new dictionary /// If not, delete this record if (!m_GeologicEventsDictionary.ContainsKey(anOldGeologicEventsEntry.Key)) { deleteGeologicEventsDictionary.Add(anOldGeologicEventsEntry.Key, anOldGeologicEventsEntry.Value); } } foreach (KeyValuePair<string, GeologicEventsAccess.GeologicEvents> anDeleteGeologicEventsEntry in deleteGeologicEventsDictionary) { GeologicEventsAccess.GeologicEvents thisGeoEvt = anDeleteGeologicEventsEntry.Value; /// Remove item from the evet list for this map unit if (liEvts4ThisUnit.Items.Contains(thisGeoEvt.AgeDisplay)) { liEvts4ThisUnit.Items.Remove(thisGeoEvt.AgeDisplay); string thisGeoEvtID = m_EvtListDictionary[thisGeoEvt.AgeDisplay]; foreach (KeyValuePair<string, ExtendedAttributesAccess.ExtendedAttributes> anExtAttrEntry in m_ExtendedAttributesDictionary) { ExtendedAttributesAccess.ExtendedAttributes thisExtAttr = anExtAttrEntry.Value; if (thisExtAttr.ValueLinkID == thisGeoEvtID) { string thisID = anExtAttrEntry.Key; m_ExtendedAttributesDictionary.Remove(thisID); } } } geoEvtsAccess.DeleteGeologicEvents(thisGeoEvt); } geoEvtsAccess.GeologicEventsDictionary = m_GeologicEventsDictionary; geoEvtsAccess.SaveGeologicEvents(); /// Reset variable m_GeologicEventsDictionary and m_EvtListDictionary geoEvtsAccess = new GeologicEventsAccess(m_theWorkspace); geoEvtsAccess.AddGeologicEvents(); m_GeologicEventsDictionary = geoEvtsAccess.GeologicEventsDictionary; m_EvtListDictionary.Clear(); foreach (KeyValuePair<string, GeologicEventsAccess.GeologicEvents> aGeologicEventsEntry in geoEvtsAccess.GeologicEventsDictionary) { m_EvtListDictionary.Add(aGeologicEventsEntry.Value.AgeDisplay, aGeologicEventsEntry.Key); } /// <end> --------------------------------------------------------------------------------------------------- /// --------------------------------------------------------------------------------------------------------- /// --------------------------------------------------------------------------------------------------------- /// <start> Settings to save extended attributes changes ---------------------------------------------------- /// connect with the Extended Attributes table ExtendedAttributesAccess extAttrAccess = new ExtendedAttributesAccess(m_theWorkspace); /// Search for the related record in the extended attribute table with the old map unit value extAttrAccess.AddExtendedAttributes(("OwnerID = '" + m_initMapUnit + "'")); Dictionary<string, ExtendedAttributesAccess.ExtendedAttributes> deleteExtendedAttributesDictionary = new Dictionary<string, ExtendedAttributesAccess.ExtendedAttributes>(); foreach (KeyValuePair<string, ExtendedAttributesAccess.ExtendedAttributes> anOldExtendedAttributesEntry in extAttrAccess.ExtendedAttributesDictionary) { /// Identify if the old record still exits in the new dictionary /// If not, delete this record if (!m_ExtendedAttributesDictionary.ContainsKey(anOldExtendedAttributesEntry.Key)) { deleteExtendedAttributesDictionary.Add(anOldExtendedAttributesEntry.Key, anOldExtendedAttributesEntry.Value); } } foreach (KeyValuePair<string, ExtendedAttributesAccess.ExtendedAttributes> anDeleteExtendedAttributesEntry in deleteExtendedAttributesDictionary) { ExtendedAttributesAccess.ExtendedAttributes thisExtAttr = anDeleteExtendedAttributesEntry.Value; extAttrAccess.DeleteExtendedAttributes(thisExtAttr); } extAttrAccess.ExtendedAttributesDictionary = m_ExtendedAttributesDictionary; extAttrAccess.SaveExtendedAttributes(); /// <end> --------------------------------------------------------------------------------------------------- /// --------------------------------------------------------------------------------------------------------- initEmptyAgeEventTab(); }
/// <summary> /// Add values to the Geologic Events Tab /// </summary> private void initAgeEventsListbox() { if (m_theWorkspace == null) { MessageBox.Show("Please open a working space!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } try { /// Pull out all the records from the Geologic Events table GeologicEventsAccess geoEvtsAccess = new GeologicEventsAccess(m_theWorkspace); /// Create a new geologic events access object geoEvtsAccess.AddGeologicEvents(); /// Search for all the events /// Clear the content of geologic events dictionary and event list dictionary m_GeologicEventsDictionary.Clear(); m_EvtListDictionary.Clear(); m_GeologicEventsDictionary = geoEvtsAccess.GeologicEventsDictionary; /// Replace the old geologic events dictionary /// Add the age displays into the list box foreach (KeyValuePair<string, GeologicEventsAccess.GeologicEvents> aGeologicEventEntry in m_GeologicEventsDictionary) { string ageDisplay = aGeologicEventEntry.Value.AgeDisplay; liEvts.Items.Add(ageDisplay); m_EvtListDictionary.Add(ageDisplay, aGeologicEventEntry.Key); /// Add new connection between age diaplay and event id } } catch (Exception e) { throw (e); } }