protected bool ShowSaveFileDialog(IGxDialog pGxDialog, out string path, out string name, out string genericName, out string datasetType) { path = ""; name = ""; genericName = ""; datasetType = ""; pGxDialog.Title = "Save File as:"; if (!pGxDialog.DoModalSave(0)) { return(false); } datasetType = pGxDialog.ObjectFilter.Name; // ' delete the existing shapefile if user wants to replace it. if (pGxDialog.ReplacingObject) { switch (datasetType) { case "Shapefiles": IWorkspaceFactory pWorkspaceFactory = new ShapefileWorkspaceFactory(); IFeatureWorkspace pFWS = (IFeatureWorkspace)pWorkspaceFactory.OpenFromFile(pGxDialog.FinalLocation.FullName, 0);// mFile(pGxDialullName, 0) IFeatureClass pFeatClass = pFWS.OpenFeatureClass(pGxDialog.Name); if (!DeleteShapefile(pFeatClass)) { MessageBox.Show("Please specify a different name for the output shapefile", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return(false); } break; } } if (!(pGxDialog.Name.IndexOf(".") == 0)) { genericName = pGxDialog.Name; } else { genericName = pGxDialog.Name.Substring(0, pGxDialog.Name.IndexOf(".")); } //if (sTelNo.IndexOf('/') >= 0) //{ // sTelNo = sTelNo.Substring(0, sTelNo.IndexOf('/')); //} switch (datasetType) { case "Shapefiles": name = genericName + ".shp"; break; case "Raster Datasets": name = genericName + ".img"; break; } path = pGxDialog.FinalLocation.FullName; return(true); }
public void ShowRasterDatasetBrowser(int handle, out IEnumGxObject ipSelectedObjects) { IGxObjectFilterCollection ipFilterCollection = new GxDialogClass(); IGxObjectFilter ipFilter1 = new GxFilterRasterDatasetsClass(); ipFilterCollection.AddFilter(ipFilter1, true); IGxDialog ipGxDialog = (IGxDialog)(ipFilterCollection); ipGxDialog.RememberLocation = true; ipGxDialog.Title = "Open"; ipGxDialog.AllowMultiSelect = false; ipGxDialog.RememberLocation = true; ipGxDialog.DoModalOpen((int)(Handle.ToInt32()), out ipSelectedObjects); return; }
/// <summary> /// Initialize the OpenRasterFileDialog. /// </summary> /// <param name="type">Type of the file dialog.</param> public RasterFileDialog(FileDialogType type) { dialog = new GxDialogClass(); IGxObjectFilterCollection filterCollection = (IGxObjectFilterCollection)dialog; IGxObjectFilter objectFilter = new RasterFormatTifFilter(); filterCollection.AddFilter(objectFilter, true); objectFilter = new RasterFormatBMPFilter(); filterCollection.AddFilter(objectFilter, false); objectFilter = new RasterFormatENVIFilter(); filterCollection.AddFilter(objectFilter, false); objectFilter = new RasterFormatBILFilter(); filterCollection.AddFilter(objectFilter, false); objectFilter = new RasterFormatBIPFilter(); filterCollection.AddFilter(objectFilter, false); objectFilter = new RasterFormatBSQFilter(); filterCollection.AddFilter(objectFilter, false); objectFilter = new RasterFormatGIFFilter(); filterCollection.AddFilter(objectFilter, false); objectFilter = new RasterFormatGridFilter(); filterCollection.AddFilter(objectFilter, false); objectFilter = new RasterFormatImgFilter(); filterCollection.AddFilter(objectFilter, false); objectFilter = new RasterFormatJP2Filter(); filterCollection.AddFilter(objectFilter, false); objectFilter = new RasterFormatJPGFilter(); filterCollection.AddFilter(objectFilter, false); objectFilter = new RasterFormatPNGFilter(); filterCollection.AddFilter(objectFilter, false); this.type = type; switch (type) { case FileDialogType.Save: this.Title = "Save Raster Layer as"; break; case FileDialogType.Open: this.Title = "Open Raster Layer"; break; } }
protected bool ShowOpenFileDialog(IGxDialog pGxDialog, out string path, out string name, out string genericName, out string datasetType) { IEnumGxObject pEnumGX; IGxObject pEnumGxObj; path = ""; name = ""; genericName = ""; datasetType = ""; pGxDialog.Title = "Save File as:"; if (!pGxDialog.DoModalOpen(0, out pEnumGX)) { return(false); } datasetType = pGxDialog.ObjectFilter.Name; pEnumGX.Reset(); pEnumGxObj = pEnumGX.Next(); genericName = pEnumGxObj.Name.Substring(0, pEnumGxObj.Name.IndexOf(".")); name = pEnumGxObj.Name; path = pGxDialog.FinalLocation.FullName; return(true); }
private void ConvertToGxObjectFilterCollection(IGxDialog gxDialog, string filter) { IGxObjectFilterCollection filterCollection = gxDialog as IGxObjectFilterCollection; if (filterCollection == null) { return; } if (filter.ToUpper().Contains(".MDB")) { IGxObjectFilter objectFilter = new GxFilterPersonalGeodatabasesClass(); filterCollection.AddFilter(objectFilter, true); } if (filter.ToUpper().Contains(".GDB")) { IGxObjectFilter objectFilter = new GxFilterFileGeodatabasesClass(); filterCollection.AddFilter(objectFilter, true); } }
private void btnSelect_Click(object sender, EventArgs e) { if (CheckGxObjectFilter(_filter)) { IGxDialog dialog = (GxDialog)Activator.CreateInstance(Type.GetTypeFromCLSID(new Guid("EAB9CE2A-E777-11D1-AEE7-080009EC734B"))); dialog.AllowMultiSelect = false; dialog.ButtonCaption = "选择数据库"; ConvertToGxObjectFilterCollection(dialog, _filter); IEnumGxObject selection = null; if (dialog.DoModalOpen(0, out selection)) { IGxObject obj = selection.Next(); if (obj != null) { _fileName = obj.FullName; string ext = obj.Name.Substring(obj.Name.Length - 4).ToUpper(); if (ext.ToUpper() == ".GDB") { _workspace = new FileGDBWorkspaceFactoryClass().OpenFromFile(_fileName, 0); } else if (ext.ToUpper() == ".MDB") { _workspace = new AccessWorkspaceFactoryClass().OpenFromFile(_fileName, 0); } } txtPath.Text = _fileName; } } else { OpenFileDialog dialog = new OpenFileDialog(); dialog.Multiselect = false; dialog.Title = @"请选择文件"; dialog.Filter = _filter; if (dialog.ShowDialog() == DialogResult.OK) { _fileName = dialog.FileName; txtPath.Text = _fileName; } } }
protected override void OnClick() { // set m_pApp = (IGxApplication)CustomGxFilter_CS.ArcCatalog.Application; IGxCatalog pCat = null; IGxFileFilter pFileFilter = null; IEnumGxObject pSelection = null; IGxDialog pDlg = null; IGxObjectFilter pFilter = null; try { pDlg = new GxDialog(); pCat = pDlg.InternalCatalog; pFileFilter = pCat.FileFilter; if (pFileFilter.FindFileType("py") < 0) { //enter the third parameter with the location of the icon as needed pFileFilter.AddFileType("PY", "Python file", ""); } pFilter = new CustomGxFilter_CS.CustomFilter(); pDlg.ObjectFilter = pFilter; pDlg.Title = "Please select a .Py file"; pDlg.AllowMultiSelect = true; pDlg.DoModalOpen(0, out pSelection); } catch (Exception ex) { System.Windows.Forms.MessageBox.Show(ex.ToString()); } finally { pCat = null; pFileFilter = null; pSelection = null; pDlg = null; pFilter = null; } }
private void btnBrowse_Click(object sender, System.EventArgs e) { try { IGxDialog dialog = GetGxDialog(); IEnumGxObject gxObjects; dialog.DoModalOpen(this.Handle.ToInt32(), out gxObjects); IGxDatabase gxDatabase = gxObjects.Next() as IGxDatabase; if (gxDatabase == null) { return; } connectionType = gxDatabase.IsRemoteDatabase ? ConnectionType.SDE : ConnectionType.PersonalGDB; _propSet = gxDatabase.WorkspaceName.ConnectionProperties; ReadNewConnectionProperties(_propSet); PopulateConnectionInfoLabel(); } catch (Exception exc) { Trace.WriteLine(exc.ToString()); } }
/// <summary> /// Prompts the user to save features /// /// Use "this.Handle.ToInt32()" as the parentWindow id /// </summary> /// <param name="iParentWindow">The window handle of the parent window</param> /// <returns>The path to selected output (fgdb/shapefile)</returns> public string PromptUserWithGxDialog(int iParentWindow) { //Prep the dialog if (m_ipSaveAsGxDialog == null) { m_ipSaveAsGxDialog = new GxDialog(); IGxObjectFilterCollection ipGxObjFilterCol = (IGxObjectFilterCollection)m_ipSaveAsGxDialog; ipGxObjFilterCol.RemoveAllFilters(); // Add the filters ipGxObjFilterCol.AddFilter(new GxFilterFGDBFeatureClasses(), false); ipGxObjFilterCol.AddFilter(new GxFilterShapefilesClass(), false); m_ipSaveAsGxDialog.AllowMultiSelect = false; m_ipSaveAsGxDialog.Title = "Select output"; m_ipSaveAsGxDialog.ButtonCaption = "OK"; m_ipSaveAsGxDialog.RememberLocation = true; } else { m_ipSaveAsGxDialog.Name = ""; m_ipSaveAsGxDialog.FinalLocation.Refresh(); } //Show the dialog and get the response if (m_ipSaveAsGxDialog.DoModalSave(iParentWindow) == false) return null; else { IGxObject ipGxObject = m_ipSaveAsGxDialog.FinalLocation; string nameString = m_ipSaveAsGxDialog.Name; bool replacingObject = m_ipSaveAsGxDialog.ReplacingObject; string path = m_ipSaveAsGxDialog.FinalLocation.FullName + "\\" + m_ipSaveAsGxDialog.Name; IGxObject ipSelectedObject = m_ipSaveAsGxDialog.InternalCatalog.SelectedObject; // user selected an existing featureclass if (ipSelectedObject != null && ipSelectedObject is IGxDataset) { IGxDataset ipGxDataset = (IGxDataset)ipSelectedObject; IDataset ipDataset = ipGxDataset.Dataset; // User will be prompted if they select an existing shapefile if ( ipDataset.Category.Equals("Shapefile Feature Class")) { return path; } while (DoesFeatureClassExist(ipDataset.Workspace.PathName, m_ipSaveAsGxDialog.Name)) { if (System.Windows.Forms.MessageBox.Show("You've selected a feature class that already exists. Do you wish to replace it?", "Overwrite Feature Class", System.Windows.Forms.MessageBoxButtons.OKCancel) == System.Windows.Forms.DialogResult.OK) { return m_ipSaveAsGxDialog.FinalLocation.FullName + "\\" + m_ipSaveAsGxDialog.Name; } if (m_ipSaveAsGxDialog.DoModalSave(iParentWindow) == false) { return null; } if (ipSelectedObject != null && ipSelectedObject is IGxDataset) { ipGxDataset = (IGxDataset)ipSelectedObject; ipDataset = ipGxDataset.Dataset; } } return m_ipSaveAsGxDialog.FinalLocation.FullName + "\\" + m_ipSaveAsGxDialog.Name; } else return path; } }
public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value) { // if (context == null) { return(null); } if (context.Instance == null) { return(null); } if (provider == null) { return(null); } // Cannot handle multiple objects if (context.Instance is object[]) { return(null); } // Do ArcGIS Desktop Test object dialog = null; try { dialog = new GxDialogClass(); } catch { } if (dialog == null) { MessageBox.Show( Resources.TEXT_NO_ARCGIS_DESKTOP, Resources.TEXT_APPLICATION, MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly); return(null); } // Create GxObjectFilter for GxDialog IGxObjectFilter gxObjectFilter = new GxFilterWorkspacesClass(); // Create GxDialog IGxDialog gxDialog = (IGxDialog)dialog; gxDialog.AllowMultiSelect = false; gxDialog.ButtonCaption = Resources.TEXT_SELECT; gxDialog.ObjectFilter = gxObjectFilter; gxDialog.RememberLocation = true; gxDialog.Title = Resources.TEXT_SELECT_EXISTING_GEODATABASE; // Declare Enumerator to hold selected objects IEnumGxObject enumGxObject = null; // Open Dialog if (!gxDialog.DoModalOpen(0, out enumGxObject)) { return(null); } if (enumGxObject == null) { return(null); } // Get Selected Object (if any) IGxObject gxObject = enumGxObject.Next(); if (gxObject == null) { return(null); } //if (!gxObject.IsValid) { return null; } // Get GxDatabase if (!(gxObject is IGxDatabase)) { return(null); } IGxDatabase gxDatabase = (IGxDatabase)gxObject; // Get IWorkspace ESRI.ArcGIS.Geodatabase.IWorkspaceName workspaceName = gxDatabase.WorkspaceName; // Return Arguments return(workspaceName); }
/// <summary> /// Prompts the user to save features /// /// Use "this.Handle.ToInt32()" as the parentWindow id /// </summary> /// <param name="iParentWindow">The window handle of the parent window</param> /// <returns>The path to selected output (fgdb/shapefile)</returns> public string PromptUserWithGxDialog(int iParentWindow) { //Prep the dialog if (m_ipSaveAsGxDialog == null) { m_ipSaveAsGxDialog = new GxDialog(); IGxObjectFilterCollection ipGxObjFilterCol = (IGxObjectFilterCollection)m_ipSaveAsGxDialog; ipGxObjFilterCol.RemoveAllFilters(); // Add the filters ipGxObjFilterCol.AddFilter(new GxFilterFGDBFeatureClasses(), false); ipGxObjFilterCol.AddFilter(new GxFilterShapefilesClass(), false); m_ipSaveAsGxDialog.AllowMultiSelect = false; m_ipSaveAsGxDialog.Title = "Select output"; m_ipSaveAsGxDialog.ButtonCaption = "OK"; m_ipSaveAsGxDialog.RememberLocation = true; } else { m_ipSaveAsGxDialog.Name = ""; m_ipSaveAsGxDialog.FinalLocation.Refresh(); } //Show the dialog and get the response if (m_ipSaveAsGxDialog.DoModalSave(iParentWindow) == false) { return(null); } else { IGxObject ipGxObject = m_ipSaveAsGxDialog.FinalLocation; string nameString = m_ipSaveAsGxDialog.Name; bool replacingObject = m_ipSaveAsGxDialog.ReplacingObject; string path = m_ipSaveAsGxDialog.FinalLocation.FullName + "\\" + m_ipSaveAsGxDialog.Name; IGxObject ipSelectedObject = m_ipSaveAsGxDialog.InternalCatalog.SelectedObject; // user selected an existing featureclass if (ipSelectedObject != null && ipSelectedObject is IGxDataset) { IGxDataset ipGxDataset = (IGxDataset)ipSelectedObject; IDataset ipDataset = ipGxDataset.Dataset; // User will be prompted if they select an existing shapefile if (ipDataset.Category.Equals("Shapefile Feature Class")) { return(path); } while (DoesFeatureClassExist(ipDataset.Workspace.PathName, m_ipSaveAsGxDialog.Name)) { if (System.Windows.Forms.MessageBox.Show("You've selected a feature class that already exists. Do you wish to replace it?", "Overwrite Feature Class", System.Windows.Forms.MessageBoxButtons.OKCancel) == System.Windows.Forms.DialogResult.OK) { return(m_ipSaveAsGxDialog.FinalLocation.FullName + "\\" + m_ipSaveAsGxDialog.Name); } if (m_ipSaveAsGxDialog.DoModalSave(iParentWindow) == false) { return(null); } if (ipSelectedObject != null && ipSelectedObject is IGxDataset) { ipGxDataset = (IGxDataset)ipSelectedObject; ipDataset = ipGxDataset.Dataset; } } return(m_ipSaveAsGxDialog.FinalLocation.FullName + "\\" + m_ipSaveAsGxDialog.Name); } else { return(path); } } }