Beispiel #1
0
        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);
        }
Beispiel #2
0
        /// <summary>
        /// Runs a raster file dialog box with the specified owner.
        /// </summary>
        /// <returns></returns>
        public DialogResult ShowDialog()
        {
            fileName  = "";
            fileNames = null;

            switch (this.type)
            {
            case FileDialogType.Open:
                IEnumGxObject enumGxObject = new GxObjectArrayClass();
                if (dialog.DoModalOpen(0, out enumGxObject))
                {
                    IGxObjectArray gxObjectArray = (IGxObjectArray)enumGxObject;
                    fileName  = gxObjectArray.Item(0).FullName;
                    fileNames = new string[gxObjectArray.Count];
                    for (int i = 0; i < gxObjectArray.Count; i++)
                    {
                        fileNames[i] = gxObjectArray.Item(i).FullName;
                    }

                    return(DialogResult.OK);
                }
                break;

            case FileDialogType.Save:
                if (dialog.DoModalSave(0))
                {
                    fileName = dialog.Name;
                    string extension = GetExtension(dialog.ObjectFilter.Name);
                    if ((Path.GetExtension(fileName) != "") &&
                        (Path.GetExtension(fileName).ToLower() == extension.Substring(1)))
                    {
                        fileName = Path.GetFileNameWithoutExtension(fileName);
                    }

                    fileName = dialog.FinalLocation.FullName + "\\" + fileName + extension;
                    return(DialogResult.OK);
                }
                break;
            }

            return(DialogResult.Cancel);
        }
        /// <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);
                }
            }
        }