/// <summary> /// Attempts to expand a domain lookup value /// </summary> /// <param name="shortValue">The short lookup string</param> /// <param name="columnName">The name of the column the lookup value was obtained from</param> /// <param name="table">The table containing the column</param> /// <returns>The expanded value in the domain associated with the column. If the column is /// not associated with a domain table, or the lookup string cannot be found, you get back /// the supplied <paramref name="shortValue"/>.</returns> /// <remarks>There is some scope for efficiency improvement here. Rather than doing this /// every time some RowTextGeometry is drawn, it would make sense to hold something like /// a <c>PreparedTemplate</c> object that holds a parsed template that points more directly /// to any domains involved.</remarks> static string GetDomainValue(string shortValue, string columnName, ITable table) { // Attempt to locate the column in question IColumnDomain[] cds = table.ColumnDomains; IColumnDomain cd = Array.Find <IColumnDomain>(cds, t => String.Compare(t.ColumnName, columnName, true) == 0); if (cd == null) { return(shortValue); } // Obtain the database server IDataServer ds = EditingController.Current.DataServer; if (ds == null) { return(shortValue); } // Perform a lookup on the domain IDomainTable dt = cd.Domain; string longValue = dt.Lookup(ds.ConnectionString, shortValue); // If it's not there, it SHOULD be blank if (String.IsNullOrEmpty(longValue)) { return(shortValue); } else { return(longValue); } }
private void domainsListBox_DoubleClick(object sender, EventArgs e) { IDomainTable dt = GetSelectedDomainTable(); DataGridViewRow c = GetSelectedColumn(); if (dt != null && c != null) { c.Cells["dgcDomain"].Value = dt; } }
/// <summary> /// Initializes a new instance of the <see cref="ColumnDomainConverter"/> class. /// </summary> /// <param name="ds">The database holding domain data</param> /// <param name="cd">The column domain that is being converted (not null)</param> public ColumnDomainConverter(IDataServer ds, IColumnDomain cd) { if (ds == null || cd == null) { throw new ArgumentNullException(); } m_DataServer = ds; m_ColumnDomain = cd; IDomainTable dt = cd.Domain; string[] lookups = dt.GetLookupValues(ds.ConnectionString); m_Values = new StandardValuesCollection(lookups); }
private void setDomainLinkLabel_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) { IDomainTable dt = GetSelectedDomainTable(); DataGridViewRow c = GetSelectedColumn(); if (dt == null) { MessageBox.Show("You must select the domain table you want to assign"); } else if (c == null) { MessageBox.Show("You must select the database column the domain should apply to"); } else { c.Cells["dgcDomain"].Value = dt; } }
private void columnsPage_CloseFromNext(object sender, Gui.Wizard.PageEventArgs e) { // Ensure ID column has been defined string idColumnName = (idColumnComboBox.SelectedItem == null ? String.Empty : idColumnComboBox.SelectedItem.ToString()); if (idColumnName.Length == 0) { MessageBox.Show("You must specify the name of the column that holds the feature ID"); idColumnComboBox.Focus(); e.Page = columnsPage; return; } m_Edit.IdColumnName = idColumnName; // Ensure column domains are up to date. // For the time being, we do NOT establish or remove foreign keys in the // database - if that is considered desirable, bear in mind that the changes // being saved here may ultimately be discarded by the user (on exit from the // application). List <IColumnDomain> cds = new List <IColumnDomain>(); IEnvironmentFactory factory = EnvironmentContainer.Factory; foreach (DataGridViewRow row in columnsGrid.Rows) { IDomainTable dt = (row.Cells["dgcDomain"].Value as IDomainTable); if (dt != null) { IEditColumnDomain cd = factory.CreateColumnDomain(); cd.ParentTable = m_Edit; cd.ColumnName = row.Cells["dgcColumnName"].FormattedValue.ToString(); cd.Domain = dt; cds.Add(cd); } } m_Edit.ColumnDomains = cds.ToArray(); m_Edit.FinishEdit(); this.DialogResult = DialogResult.OK; Close(); }
private void grid_SelectionChanged(object sender, EventArgs e) { domainGrid.Tag = null; domainGrid.Rows.Clear(); domainGrid.Enabled = false; if (!grid.Enabled) { return; } DataGridViewRow row = GetSelectedGridRow(); if (row == null) { return; } // Show the data type DataColumn dc = (DataColumn)row.Tag; dataTypeLabel.Text = dc.DataType.Name; if (!dc.AllowDBNull) { dataTypeLabel.Text += " not null"; } if (dc.DataType == typeof(string)) { if (dc.MaxLength == 1) { dataTypeLabel.Text += " (1 character)"; } else { dataTypeLabel.Text += String.Format(" (up to {0} characters)", dc.MaxLength); } } // Show any domain values IColumnDomain cd = FindColumnDomain(dc.ColumnName); domainValuesLabel.Enabled = (cd != null); if (cd != null) { // Note the currently defined value string currentValue = row.Cells["dgcValue"].FormattedValue.ToString(); DataGridViewCell currentCell = null; IDomainTable domainTable = cd.Domain; string[] lookups = domainTable.GetLookupValues(m_DataServer.ConnectionString); domainGrid.RowCount = lookups.Length; for (int i = 0; i < lookups.Length; i++) { string shortValue = lookups[i]; DataGridViewRow r = domainGrid.Rows[i]; r.Tag = shortValue; r.Cells["dgcShortValue"].Value = shortValue; r.Cells["dgcLongValue"].Value = domainTable.Lookup(m_DataServer.ConnectionString, shortValue); // If we have just defined the current data value, remember the cell so // that we can set it once the grid has been loaded. if (shortValue == currentValue) { currentCell = r.Cells["dgcShortValue"]; } } domainGrid.CurrentCell = currentCell; domainGrid.Enabled = true; domainGrid.Tag = domainTable; } }