/// <summary> /// This describes how to launch the form etc. /// </summary> /// <param name="context"></param> /// <param name="provider"></param> /// <param name="value"></param> /// <returns></returns> public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value) { _context = context; IWindowsFormsEditorService dialogProvider = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService)); SQLExpressionDialog dlgExpression = new SQLExpressionDialog(); string original = (string)value; dlgExpression.Expression = (string)value; // Try to find the Table IFeatureCategory category = context.Instance as IFeatureCategory; if (category != null) { IFeatureScheme scheme = category.GetParentItem() as IFeatureScheme; if (scheme != null) { IFeatureLayer layer = scheme.GetParentItem() as IFeatureLayer; if (layer != null) { dlgExpression.Table = layer.DataSet.DataTable; } } else { IFeatureLayer layer = category.GetParentItem() as IFeatureLayer; if (layer != null) { dlgExpression.Table = layer.DataSet.DataTable; } } } dlgExpression.ChangesApplied += DlgExpressionChangesApplied; return dialogProvider.ShowDialog(dlgExpression) != DialogResult.OK ? original : dlgExpression.Expression; }
private void DlgExpressionChangesApplied(object sender, EventArgs e) { SQLExpressionDialog dlg = sender as SQLExpressionDialog; if (dlg != null) { string exp = dlg.Expression; _context.PropertyDescriptor.SetValue(_context.Instance, exp); } }
/// <summary> /// Find a feature by query expression /// </summary> private void FindTool_Click(object sender, EventArgs e) { Map mainMap = App.Map as Map; List<ILayer> layers; if (mainMap != null) layers = mainMap.GetAllLayers(); else layers = mainMap.GetLayers(); IFeatureLayer fl = null; foreach (ILayer layer in layers) { if (layer.IsSelected) { fl = layer as IFeatureLayer; break; } } if (fl == null) { MessageBox.Show("Please select a feature layer."); return; } SQLExpressionDialog qd = new SQLExpressionDialog(); if (fl.DataSet.AttributesPopulated) qd.Table = fl.DataSet.DataTable; else qd.AttributeSource = fl.DataSet; // Note: User must click ok button to see anything. if (qd.ShowDialog() == DialogResult.Cancel) return; if (!String.IsNullOrWhiteSpace(qd.Expression)) { try { fl.SelectByAttribute(qd.Expression); } catch (SyntaxErrorException ex) { MessageBox.Show("The syntax of that query isn't quite right: " + ex.Message); } } }
/// <summary> /// This describes how to launch the form etc. /// </summary> /// <param name="context"></param> /// <param name="provider"></param> /// <param name="value"></param> /// <returns></returns> public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value) { _context = context; IWindowsFormsEditorService dialogProvider = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService)); SQLExpressionDialog dlgExpression = new SQLExpressionDialog(); string original = (string)value; dlgExpression.Expression = (string)value; // Try to find the Table IFeatureCategory category = context.Instance as IFeatureCategory; if (category != null) { IFeatureScheme scheme = category.GetParentItem() as IFeatureScheme; if (scheme != null) { IFeatureLayer layer = scheme.GetParentItem() as IFeatureLayer; if (layer != null) { dlgExpression.Table = layer.DataSet.DataTable; } } else { IFeatureLayer layer = category.GetParentItem() as IFeatureLayer; if (layer != null) { dlgExpression.Table = layer.DataSet.DataTable; } } } dlgExpression.ChangesApplied += DlgExpressionChangesApplied; var result = dialogProvider.ShowDialog(dlgExpression); dlgExpression.ChangesApplied -= DlgExpressionChangesApplied; return(result != DialogResult.OK ? original : dlgExpression.Expression); }
//User Click the Select Button private void BtnSelectClick(object sender, EventArgs e) { if (_enableUpdate) { if (((IndexParam)base.Param).Fs == null || ((IndexParam)base.Param).Fs.DataTable == null) return; if (((IndexParam)base.Param).Fs.DataTable.Rows.Count < 1) return; SQLExpressionDialog dlgExpression = new SQLExpressionDialog(); dlgExpression.Table = ((IndexParam)base.Param).Fs.DataTable; dlgExpression.ShowDialog(); if (dlgExpression.DialogResult == DialogResult.OK) { _expression = dlgExpression.Expression; textBox1.Text = _expression; base.Status = ToolStatus.Ok; _click = true; LightTipText = ModelingMessageStrings.FeaturesSelected; } } }
//Executes a query private void QueryExe() { var queryDialog = new SQLExpressionDialog(); queryDialog.ChangesApplied += QueryDialog_ChangesApplied; if (_featureLayer.DataSet.AttributesPopulated) { queryDialog.Table = _featureLayer.DataSet.DataTable; } else { queryDialog.AttributeSource = _featureLayer.DataSet; } queryDialog.ShowDialog(this); queryDialog.ChangesApplied -= QueryDialog_ChangesApplied; }